Skip to content

Commit f9504eb

Browse files
committed
separate scene prepare and render
1 parent b4f9758 commit f9504eb

7 files changed

Lines changed: 500 additions & 321 deletions

File tree

sources/include/cage-core/swapBufferGuard.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ namespace cage
4444
public:
4545
SwapBufferLock();
4646
explicit SwapBufferLock(SwapBufferGuard *controller, uint32 index);
47-
SwapBufferLock(SwapBufferLock &&other);
47+
SwapBufferLock(SwapBufferLock &&other) noexcept;
4848
~SwapBufferLock();
49-
SwapBufferLock &operator=(SwapBufferLock &&other);
50-
explicit operator bool() const { return !!controller_; }
49+
SwapBufferLock &operator=(SwapBufferLock &&other) noexcept;
50+
explicit operator bool() const noexcept { return !!controller_; }
5151
uint32 index() const
5252
{
5353
CAGE_ASSERT(!!controller_);

sources/include/cage-engine/sceneCustomDraw.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ namespace cage
88
class Entity;
99
class GraphicsEncoder;
1010
class GraphicsAggregateBuffer;
11-
struct SceneRenderConfig;
11+
struct ScenePrepareConfig;
12+
struct SceneCameraConfig;
1213

1314
struct CAGE_ENGINE_API CustomDrawConfig
1415
{
15-
const SceneRenderConfig *renderConfig = nullptr;
16+
const ScenePrepareConfig *sceneConfig = nullptr;
17+
const SceneCameraConfig *cameraConfig = nullptr;
1618
GraphicsEncoder *encoder = nullptr;
1719
GraphicsAggregateBuffer *aggregate = nullptr;
1820
Entity *entity = nullptr;

sources/include/cage-engine/sceneRender.h

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,37 @@ namespace cage
1212
class AssetsOnDemand;
1313
class EntityManager;
1414

15-
struct CAGE_ENGINE_API SceneRenderConfig
15+
struct CAGE_ENGINE_API ScenePrepareConfig
1616
{
17-
ScreenSpaceEffectsComponent effects;
18-
Mat4 projection;
19-
CameraCommonProperties camera;
20-
Transform transform;
21-
LodSelection lodSelection;
2217
uint64 currentTime = 0;
2318
uint64 elapsedTime = 1'000'000 / 60; // microseconds since last frame
24-
Vec2i resolution;
2519
GraphicsDevice *device = nullptr;
2620
AssetsManager *assets = nullptr;
2721
AssetsOnDemand *onDemand = nullptr;
2822
EntityManager *scene = nullptr;
29-
Texture *target = nullptr;
3023
uint32 frameIndex = 0;
31-
uint32 cameraSceneMask = 1;
3224
Real interpolationFactor = 1;
3325
};
3426

35-
CAGE_ENGINE_API Holder<PointerRange<Holder<GraphicsEncoder>>> sceneRender(const SceneRenderConfig &config);
27+
struct CAGE_ENGINE_API SceneCameraConfig
28+
{
29+
Mat4 projection;
30+
ScreenSpaceEffectsComponent effects;
31+
CameraCommonProperties camera;
32+
Transform transform;
33+
LodSelection lodSelection;
34+
Vec2i resolution;
35+
Texture *target = nullptr;
36+
uint32 cameraSceneMask = 1;
37+
};
38+
39+
struct CAGE_ENGINE_API PreparedScene
40+
{
41+
const ScenePrepareConfig config;
42+
};
43+
44+
CAGE_ENGINE_API Holder<PreparedScene> scenePrepare(const ScenePrepareConfig &config);
45+
CAGE_ENGINE_API Holder<PointerRange<Holder<GraphicsEncoder>>> sceneRender(const PreparedScene *scene, const SceneCameraConfig &config);
3646
}
3747

3848
#endif // guard_sceneRender_h_4hg1s8596drfh4

sources/libcore/swapBufferGuard.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ namespace cage
136136
CAGE_ASSERT(impl->states[index] == StateEnum::Reading || impl->states[index] == StateEnum::Writing);
137137
}
138138

139-
SwapBufferLock::SwapBufferLock(SwapBufferLock &&other) : controller_(nullptr), index_(m)
139+
SwapBufferLock::SwapBufferLock(SwapBufferLock &&other) noexcept : controller_(nullptr), index_(m)
140140
{
141141
std::swap(controller_, other.controller_);
142142
std::swap(index_, other.index_);
@@ -150,7 +150,7 @@ namespace cage
150150
impl->finished(index_);
151151
}
152152

153-
SwapBufferLock &SwapBufferLock::operator=(SwapBufferLock &&other)
153+
SwapBufferLock &SwapBufferLock::operator=(SwapBufferLock &&other) noexcept
154154
{
155155
if (controller_)
156156
{

sources/libengine/graphics/device.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ namespace cage
261261
"vulkan_use_dynamic_rendering", //
262262
"wait_is_thread_safe", // just to be sure
263263
};
264-
if (!config.vsync)
265-
toggles.push_back("turn_off_vsync");
264+
//if (!config.vsync)
265+
// toggles.push_back("turn_off_vsync");
266266
#ifdef CAGE_DEPLOY
267267
toggles.push_back("disable_robustness");
268268
toggles.push_back("skip_validation");
@@ -361,16 +361,27 @@ namespace cage
361361
if (!context->surface.GetCapabilities(adapter, &capabilities))
362362
CAGE_THROW_ERROR(Exception, "failed to retrieve surface capabilities");
363363

364-
bool relaxed = false;
364+
//bool relaxed = false;
365+
bool mailbox = false;
366+
bool immediate = false;
365367
for (uint32 i = 0; i < capabilities.presentModeCount; i++)
366-
if (capabilities.presentModes[i] == wgpu::PresentMode::FifoRelaxed)
367-
relaxed = true;
368+
{
369+
//if (capabilities.presentModes[i] == wgpu::PresentMode::FifoRelaxed)
370+
// relaxed = true;
371+
if (capabilities.presentModes[i] == wgpu::PresentMode::Mailbox)
372+
mailbox = true;
373+
if (capabilities.presentModes[i] == wgpu::PresentMode::Immediate)
374+
immediate = true;
375+
}
368376

369377
wgpu::SurfaceConfiguration cfg = {};
370378
cfg.device = device;
371379
cfg.width = resolution[0];
372380
cfg.height = resolution[1];
373-
cfg.presentMode = relaxed ? wgpu::PresentMode::FifoRelaxed : wgpu::PresentMode::Fifo;
381+
if (config.vsync)
382+
cfg.presentMode = wgpu::PresentMode::Fifo;
383+
else
384+
cfg.presentMode = mailbox ? wgpu::PresentMode::Mailbox : immediate ? wgpu::PresentMode::Immediate : wgpu::PresentMode::Fifo;
374385
cfg.format = wgpu::TextureFormat::BGRA8Unorm; // this should be guaranteed to work everywhere
375386
cfg.usage = wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc;
376387
context->surface.Configure(&cfg);

0 commit comments

Comments
 (0)