Light Culling still doesn't work properly
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
target_sources(SeeleEngine
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
Asset.h
|
||||
Asset.cpp
|
||||
|
||||
@@ -27,12 +27,12 @@ void MaterialLoader::importAsset(const std::filesystem::path& name)
|
||||
import(name, asset);
|
||||
}
|
||||
|
||||
Job MaterialLoader::import(std::filesystem::path, PMaterialAsset asset)
|
||||
void MaterialLoader::import(std::filesystem::path, PMaterialAsset asset)
|
||||
{
|
||||
asset->load();
|
||||
graphics->getShaderCompiler()->registerMaterial(asset);
|
||||
AssetRegistry::get().registerMaterial(asset);
|
||||
co_return;
|
||||
//co_return;
|
||||
}
|
||||
|
||||
PMaterialAsset MaterialLoader::getPlaceHolderMaterial()
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
void importAsset(const std::filesystem::path& name);
|
||||
PMaterialAsset getPlaceHolderMaterial();
|
||||
private:
|
||||
Job import(std::filesystem::path filePath, PMaterialAsset asset);
|
||||
void import(std::filesystem::path filePath, PMaterialAsset asset);
|
||||
Gfx::PGraphics graphics;
|
||||
List<std::future<void>> futures;
|
||||
PMaterialAsset placeholderMaterial;
|
||||
|
||||
@@ -38,7 +38,7 @@ PTextureAsset TextureLoader::getPlaceholderTexture()
|
||||
return placeholderAsset;
|
||||
}
|
||||
|
||||
Job TextureLoader::import(std::filesystem::path path, PTextureAsset textureAsset)
|
||||
void TextureLoader::import(std::filesystem::path path, PTextureAsset textureAsset)
|
||||
{
|
||||
int x, y, n;
|
||||
unsigned char* data = stbi_load(path.string().c_str(), &x, &y, &n, 4);
|
||||
@@ -70,5 +70,5 @@ Job TextureLoader::import(std::filesystem::path path, PTextureAsset textureAsset
|
||||
|
||||
textureAsset->load();
|
||||
textureAsset->setStatus(Asset::Status::Ready);
|
||||
co_return;
|
||||
//co_return;
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
void importAsset(const std::filesystem::path& filePath);
|
||||
PTextureAsset getPlaceholderTexture();
|
||||
private:
|
||||
Job import(std::filesystem::path path, PTextureAsset asset);
|
||||
void import(std::filesystem::path path, PTextureAsset asset);
|
||||
Gfx::PGraphics graphics;
|
||||
List<std::future<void>> futures;
|
||||
PTextureAsset placeholderAsset;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
target_sources(SeeleEngine
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
EngineTypes.h
|
||||
MinimalEngine.h
|
||||
|
||||
@@ -320,7 +320,7 @@ public:
|
||||
{
|
||||
remove(it - beginIt, keepOrder);
|
||||
}
|
||||
constexpr void remove(int index, bool keepOrder = true)
|
||||
constexpr void remove(size_type index, bool keepOrder = true)
|
||||
{
|
||||
if (keepOrder)
|
||||
{
|
||||
@@ -333,7 +333,7 @@ public:
|
||||
{
|
||||
_data[index] = std::move(_data[arraySize - 1]);
|
||||
}
|
||||
arraySize--;
|
||||
std::allocator_traits<allocator_type>::destroy(allocator, &_data[--arraySize]);
|
||||
markIteratorDirty();
|
||||
}
|
||||
constexpr void resize(size_type newSize)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
target_sources(SeeleEngine
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
Array.h
|
||||
Map.h
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
target_sources(SeeleEngine
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
GraphicsResources.h
|
||||
GraphicsResources.cpp
|
||||
|
||||
@@ -134,6 +134,7 @@ MainJob BasePass::beginFrame()
|
||||
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
|
||||
//std::cout << "BasePass beginFrame()" << std::endl;
|
||||
co_return;
|
||||
}
|
||||
|
||||
@@ -163,11 +164,13 @@ MainJob BasePass::render()
|
||||
//co_await Job::all(jobs);
|
||||
graphics->executeCommands(processor->getRenderCommands());
|
||||
graphics->endRenderPass();
|
||||
//std::cout << "BasePass render()" << std::endl;
|
||||
co_return;
|
||||
}
|
||||
|
||||
MainJob BasePass::endFrame()
|
||||
{
|
||||
//std::cout << "BasePass endFrame()" << std::endl;
|
||||
co_return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
target_sources(SeeleEngine
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
BasePass.h
|
||||
BasePass.cpp
|
||||
|
||||
@@ -115,6 +115,7 @@ MainJob DepthPrepass::beginFrame()
|
||||
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
|
||||
//std::cout << "DepthPrepass beginFrame()" << std::endl;
|
||||
co_return;
|
||||
}
|
||||
|
||||
@@ -134,11 +135,13 @@ MainJob DepthPrepass::render()
|
||||
//co_await Job::all(jobs);
|
||||
graphics->executeCommands(processor->getRenderCommands());
|
||||
graphics->endRenderPass();
|
||||
//std::cout << "DepthPrepass render()" << std::endl;
|
||||
co_return;
|
||||
}
|
||||
|
||||
MainJob DepthPrepass::endFrame()
|
||||
{
|
||||
//std::cout << "DepthPrepass endFrame()" << std::endl;
|
||||
co_return;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ MainJob LightCullingPass::beginFrame()
|
||||
lightEnvDescriptorSet->updateBuffer(2, pointLightBuffer);
|
||||
lightEnvDescriptorSet->updateBuffer(3, numPointLightBuffer);
|
||||
lightEnvDescriptorSet->writeChanges();
|
||||
//std::cout << "Finished light culling beginFrame()" << std::endl;
|
||||
//std::cout << "LightCulling beginFrame()" << std::endl;
|
||||
co_return;
|
||||
}
|
||||
|
||||
@@ -103,11 +103,13 @@ MainJob LightCullingPass::render()
|
||||
graphics->executeCommands(commands);
|
||||
depthAttachment->changeLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||
depthAttachment->transferOwnership(Gfx::QueueType::GRAPHICS);
|
||||
//std::cout << "LightCulling render()" << std::endl;
|
||||
co_return;
|
||||
}
|
||||
|
||||
MainJob LightCullingPass::endFrame()
|
||||
{
|
||||
//std::cout << "LightCulling endFrame()" << std::endl;
|
||||
co_return;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
|
||||
private:
|
||||
void setupFrustums();
|
||||
static constexpr uint32 BLOCK_SIZE = 8;
|
||||
static constexpr uint32 BLOCK_SIZE = 32;
|
||||
static constexpr uint32 INDEX_LIGHT_ENV = 1;
|
||||
struct DispatchParams
|
||||
{
|
||||
@@ -39,9 +39,6 @@ private:
|
||||
{
|
||||
Vector n;
|
||||
float d;
|
||||
Vector p0;
|
||||
Vector p1;
|
||||
Vector p2;
|
||||
};
|
||||
struct Frustum
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
target_sources(SeeleEngine
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
NsightAftermathGpuCrashTracker.h
|
||||
NsightAftermathGpuCrashTracker.cpp
|
||||
|
||||
@@ -146,7 +146,7 @@ public:
|
||||
private:
|
||||
enum
|
||||
{
|
||||
MemoryBlockSize = 64 * 1024 * 1024 // 64MB
|
||||
MemoryBlockSize = 16 * 1024 * 1024 // 16MB
|
||||
};
|
||||
struct HeapInfo
|
||||
{
|
||||
|
||||
@@ -332,7 +332,7 @@ PCommandBufferManager Graphics::getTransferCommands()
|
||||
}
|
||||
PCommandBufferManager Graphics::getDedicatedTransferCommands()
|
||||
{
|
||||
if(dedicatedTransferCommands == dedicatedTransferCommands)
|
||||
if(dedicatedTransferCommands == nullptr)
|
||||
{
|
||||
dedicatedTransferCommands = new CommandBufferManager(this, dedicatedTransferQueue);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
target_sources(SeeleEngine
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
BRDF.h
|
||||
BRDF.cpp
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
target_sources(SeeleEngine
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
Math.h
|
||||
Matrix.h
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
target_sources(SeeleEngine
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
Actor.cpp
|
||||
Actor.h
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
target_sources(SeeleEngine
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
Util.h
|
||||
Scene.cpp
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
target_sources(SeeleEngine
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
CameraComponent.h
|
||||
CameraComponent.cpp
|
||||
|
||||
@@ -4,7 +4,7 @@ using namespace Seele;
|
||||
|
||||
Job MyOtherComponent::tick(float deltaTime) const
|
||||
{
|
||||
std::cout << *data << std::endl;
|
||||
//std::cout << *data << std::endl;
|
||||
co_return;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,13 +19,13 @@ Scene::Scene(Gfx::PGraphics graphics)
|
||||
lightEnv.directionalLights[0].intensity = Vector4(1, 1, 1, 1);
|
||||
lightEnv.numDirectionalLights = 1;
|
||||
srand((unsigned int)time(NULL));
|
||||
for(uint32 i = 0; i < 16; ++i)
|
||||
for(uint32 i = 0; i < 256; ++i)
|
||||
{
|
||||
lightEnv.pointLights[i].colorRange = Vector4(frand(), frand(), frand(), frand() * 30);
|
||||
lightEnv.pointLights[i].colorRange = Vector4(frand(), frand(), frand(), frand() * 300);
|
||||
lightEnv.pointLights[i].positionWS = Vector4(frand() * 100-50, frand(), frand() * 100-50, 1);
|
||||
}
|
||||
lightEnv.numPointLights = 16;
|
||||
lightEnv.pointLights[0].colorRange = Vector4(1, 1, 1, 1000);
|
||||
lightEnv.numPointLights = 256;
|
||||
lightEnv.pointLights[0].colorRange = Vector4(1, 0, 1, 1000);
|
||||
lightEnv.pointLights[0].positionWS = Vector4(0, 10, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ struct DirectionalLight
|
||||
struct PointLight
|
||||
{
|
||||
Vector4 positionWS;
|
||||
Vector4 positionVS;
|
||||
Vector4 colorRange;
|
||||
};
|
||||
|
||||
@@ -46,7 +45,7 @@ public:
|
||||
|
||||
const std::vector<PPrimitiveComponent>& getPrimitives() const { return primitives; }
|
||||
const std::vector<StaticMeshBatch>& getStaticMeshes() const { return staticMeshes; }
|
||||
const LightEnv& getLightBuffer() const { return lightEnv; }
|
||||
LightEnv& getLightBuffer() { return lightEnv; }
|
||||
private:
|
||||
std::vector<StaticMeshBatch> staticMeshes;
|
||||
std::vector<PActor> rootActors;
|
||||
|
||||
+10
-13
@@ -4,6 +4,7 @@
|
||||
#include "MinimalEngine.h"
|
||||
#include "Containers/List.h"
|
||||
#include "Concepts.h"
|
||||
#include <source_location>
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -66,11 +67,11 @@ struct JobPromiseBase
|
||||
EXECUTING,
|
||||
DONE
|
||||
};
|
||||
JobPromiseBase()
|
||||
JobPromiseBase(const std::source_location& location = std::source_location::current())
|
||||
{
|
||||
handle = std::coroutine_handle<JobPromiseBase<MainJob>>::from_promise(*this);
|
||||
id = globalCounter++;
|
||||
finishedEvent = Event(std::format("Job {}", id));
|
||||
finishedEvent = Event(std::string(location.file_name()).append(": ").append(location.function_name()));
|
||||
}
|
||||
~JobPromiseBase()
|
||||
{}
|
||||
@@ -101,6 +102,7 @@ struct JobPromiseBase
|
||||
finishedEvent.raise();
|
||||
if(continuation)
|
||||
{
|
||||
std::scoped_lock lock(continuation->promiseLock);
|
||||
getGlobalThreadPool().scheduleJob(continuation);
|
||||
continuation->removeRef();
|
||||
}
|
||||
@@ -108,6 +110,7 @@ struct JobPromiseBase
|
||||
void setContinuation(JobPromiseBase* cont)
|
||||
{
|
||||
std::scoped_lock lock(promiseLock, cont->promiseLock);
|
||||
assert(cont->ready());
|
||||
continuation = cont;
|
||||
cont->state = State::SCHEDULED;
|
||||
cont->addRef();
|
||||
@@ -148,12 +151,12 @@ struct JobPromiseBase
|
||||
}
|
||||
void schedule()
|
||||
{
|
||||
//dont lock here, as it is already locked from outside
|
||||
std::scoped_lock lock(promiseLock);
|
||||
if(!handle || done() || !ready())
|
||||
{
|
||||
return;
|
||||
}
|
||||
state = State::SCHEDULED;
|
||||
getGlobalThreadPool().scheduleJob(this);
|
||||
}
|
||||
void addRef()
|
||||
@@ -243,6 +246,7 @@ public:
|
||||
JobBase&& then(JobBase&& continuation)
|
||||
{
|
||||
promise->setContinuation(continuation.promise);
|
||||
promise->schedule();
|
||||
return std::move(continuation);
|
||||
}
|
||||
bool done()
|
||||
@@ -253,19 +257,12 @@ public:
|
||||
{
|
||||
promise->finalize();
|
||||
}
|
||||
Event operator co_await()
|
||||
Event operator co_await() const
|
||||
{
|
||||
Event result = promise->finishedEvent;
|
||||
// if we schedule the promise now, it might finish and self destruct
|
||||
// but there is no way for us to know that
|
||||
// but as the co_await operator keeps a reference to this, we it won't
|
||||
// the co_await operator keeps a reference to this, we it won't
|
||||
// be scheduled from the destructor
|
||||
promise->schedule();
|
||||
// so we reset the promise so we don't schedule it when this destructs
|
||||
promise->removeRef();
|
||||
promise = nullptr;
|
||||
// but we still have to provide with the event, so we get that first
|
||||
return result;
|
||||
return promise->finishedEvent;
|
||||
}
|
||||
static JobBase all() = delete;
|
||||
template<iterable Iterable>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
target_sources(SeeleEngine
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
HorizontalLayout.h
|
||||
HorizontalLayout.cpp
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
target_sources(SeeleEngine
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
Element.h
|
||||
Element.cpp)
|
||||
@@ -1,4 +1,4 @@
|
||||
target_sources(SeeleEngine
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
InspectorView.h
|
||||
InspectorView.cpp
|
||||
|
||||
@@ -41,11 +41,9 @@ void InspectorView::prepareRender()
|
||||
|
||||
MainJob InspectorView::render()
|
||||
{
|
||||
co_await uiPass.beginFrame();
|
||||
co_await uiPass.render();
|
||||
co_await uiPass.endFrame();
|
||||
renderFinishedEvent.raise();
|
||||
co_return;
|
||||
return uiPass.beginFrame()
|
||||
.then(uiPass.render())
|
||||
.then(uiPass.endFrame());
|
||||
}
|
||||
|
||||
void InspectorView::keyCallback(KeyCode, InputAction, KeyModifier)
|
||||
|
||||
@@ -34,7 +34,7 @@ Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const Viewpo
|
||||
PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka"));
|
||||
ayaka->addWorldTranslation(Vector(0, 0, 0));
|
||||
ayaka->setWorldScale(Vector(10, 10, 10));
|
||||
scene->addPrimitiveComponent(ayaka);
|
||||
//scene->addPrimitiveComponent(ayaka);
|
||||
|
||||
PPrimitiveComponent plane = new PrimitiveComponent(AssetRegistry::findMesh("plane"));
|
||||
plane->setWorldScale(Vector(100, 100, 100));
|
||||
@@ -97,17 +97,19 @@ void SceneView::prepareRender()
|
||||
|
||||
MainJob SceneView::render()
|
||||
{
|
||||
co_await depthPrepass.beginFrame();
|
||||
co_await lightCullingPass.beginFrame();
|
||||
co_await basePass.beginFrame();
|
||||
co_await depthPrepass.render();
|
||||
co_await lightCullingPass.render();
|
||||
co_await basePass.render();
|
||||
co_await depthPrepass.endFrame();
|
||||
co_await lightCullingPass.endFrame();
|
||||
co_await basePass.endFrame();
|
||||
renderFinishedEvent.raise();
|
||||
co_return;
|
||||
return MainJob::all(
|
||||
depthPrepass.beginFrame(),
|
||||
lightCullingPass.beginFrame(),
|
||||
basePass.beginFrame())
|
||||
.then(depthPrepass.render())
|
||||
.then(lightCullingPass.render())
|
||||
.then(basePass.render())
|
||||
.then(
|
||||
MainJob::all(
|
||||
depthPrepass.endFrame(),
|
||||
lightCullingPass.endFrame(),
|
||||
basePass.endFrame())
|
||||
);
|
||||
}
|
||||
|
||||
void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier)
|
||||
|
||||
@@ -8,7 +8,6 @@ View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &vi
|
||||
: graphics(graphics)
|
||||
, owner(window)
|
||||
, name(name)
|
||||
, renderFinishedEvent(std::format("{}RenderFinished", name))
|
||||
{
|
||||
viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo);
|
||||
}
|
||||
|
||||
@@ -24,15 +24,12 @@ public:
|
||||
virtual MainJob render() = 0;
|
||||
void applyArea(URect area);
|
||||
void setFocused();
|
||||
Event renderFinished() { return renderFinishedEvent; }
|
||||
void resetRender() { renderFinishedEvent.reset(); }
|
||||
|
||||
protected:
|
||||
Gfx::PGraphics graphics;
|
||||
Gfx::PViewport viewport;
|
||||
PWindow owner;
|
||||
std::string name;
|
||||
Event renderFinishedEvent;
|
||||
|
||||
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) = 0;
|
||||
virtual void mouseMoveCallback(double xPos, double yPos) = 0;
|
||||
|
||||
@@ -27,21 +27,16 @@ void Window::addView(PView view)
|
||||
MainJob Window::render()
|
||||
{
|
||||
gfxHandle->beginFrame();
|
||||
Array<MainJob> jobs;
|
||||
for(auto& windowView : views)
|
||||
{
|
||||
co_await windowView->updateFinished;
|
||||
windowView->updateFinished.reset();
|
||||
{
|
||||
std::scoped_lock lock(windowView->workerMutex);
|
||||
windowView->view->prepareRender();
|
||||
}
|
||||
windowView->view->render();
|
||||
}
|
||||
for(auto& windowView : views)
|
||||
{
|
||||
co_await windowView->view->renderFinished();
|
||||
windowView->view->resetRender();
|
||||
jobs.add(windowView->view->render());
|
||||
}
|
||||
co_await MainJob::all(jobs);
|
||||
gfxHandle->endFrame();
|
||||
if(owner->isActive())
|
||||
{
|
||||
@@ -82,8 +77,11 @@ Job Window::viewWorker(size_t viewIndex)
|
||||
windowView->view->commitUpdate();
|
||||
}
|
||||
//std::cout << "Update completed" << std::endl;
|
||||
windowView->updateFinished.raise();
|
||||
//windowView->updateFinished.raise();
|
||||
// enqueue next frame update
|
||||
viewWorker(viewIndex);
|
||||
if(owner->isActive())
|
||||
{
|
||||
viewWorker(viewIndex);
|
||||
}
|
||||
co_return;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ void WindowManager::notifyWindowClosed(PWindow window)
|
||||
windows.remove(windows.find(window));
|
||||
if(windows.empty())
|
||||
{
|
||||
std::scoped_lock lock(windowsLock);
|
||||
windowsCV.notify_all();
|
||||
getGlobalThreadPool().cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,16 +22,9 @@ public:
|
||||
{
|
||||
return windows.size();
|
||||
}
|
||||
void waitForCompletion()
|
||||
{
|
||||
std::unique_lock lock(windowsLock);
|
||||
windowsCV.wait(lock);
|
||||
}
|
||||
|
||||
private:
|
||||
Array<PWindow> windows;
|
||||
std::mutex windowsLock;
|
||||
std::condition_variable windowsCV;
|
||||
static Gfx::PGraphics graphics;
|
||||
};
|
||||
DEFINE_REF(WindowManager)
|
||||
|
||||
Reference in New Issue
Block a user