Rendering works now

This commit is contained in:
Dynamitos
2021-12-27 15:04:53 +01:00
parent 79ced0a30f
commit b2718dde70
15 changed files with 324 additions and 278 deletions
+1 -1
View File
@@ -504,7 +504,7 @@ namespace Seele
// As well as default initialize the others // As well as default initialize the others
for(size_type i = arraySize; i < newSize; ++i) for(size_type i = arraySize; i < newSize; ++i)
{ {
std::allocator_traits<allocator_type>::construct(allocator, &_data[i], std::move(value)); std::allocator_traits<allocator_type>::construct(allocator, &newData[i], std::move(value));
} }
deallocateArray(_data, allocated); deallocateArray(_data, allocated);
arraySize = newSize; arraySize = newSize;
+5 -4
View File
@@ -20,7 +20,7 @@ BasePassMeshProcessor::~BasePassMeshProcessor()
{ {
} }
Job BasePassMeshProcessor::processMeshBatch( void BasePassMeshProcessor::processMeshBatch(
const MeshBatch& batch, const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent, // const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass& renderPass, const Gfx::PRenderPass& renderPass,
@@ -65,7 +65,7 @@ Job BasePassMeshProcessor::processMeshBatch(
} }
std::unique_lock lock(commandLock); std::unique_lock lock(commandLock);
renderCommands.add(renderCommand); renderCommands.add(renderCommand);
co_return; //co_return;
} }
BasePass::BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source) BasePass::BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
@@ -156,9 +156,10 @@ MainJob BasePass::render()
List<Job> jobs; List<Job> jobs;
for (auto &&meshBatch : passData.staticDrawList) for (auto &&meshBatch : passData.staticDrawList)
{ {
jobs.add(processor->processMeshBatch(meshBatch, renderPass, basePassLayout, primitiveLayout, descriptorSets)); //jobs.add(
processor->processMeshBatch(meshBatch, renderPass, basePassLayout, primitiveLayout, descriptorSets);
} }
co_await Job::all(jobs); //co_await Job::all(jobs);
graphics->executeCommands(processor->getRenderCommands()); graphics->executeCommands(processor->getRenderCommands());
graphics->endRenderPass(); graphics->endRenderPass();
co_return; co_return;
+1 -1
View File
@@ -11,7 +11,7 @@ public:
BasePassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass); BasePassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass);
virtual ~BasePassMeshProcessor(); virtual ~BasePassMeshProcessor();
virtual Job processMeshBatch( virtual void processMeshBatch(
const MeshBatch& batch, const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent, // const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass& renderPass, const Gfx::PRenderPass& renderPass,
@@ -18,7 +18,7 @@ DepthPrepassMeshProcessor::~DepthPrepassMeshProcessor()
{ {
} }
Job DepthPrepassMeshProcessor::processMeshBatch( void DepthPrepassMeshProcessor::processMeshBatch(
const MeshBatch& batch, const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent, // const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass& renderPass, const Gfx::PRenderPass& renderPass,
@@ -27,7 +27,7 @@ Job DepthPrepassMeshProcessor::processMeshBatch(
Array<Gfx::PDescriptorSet> descriptorSets, Array<Gfx::PDescriptorSet> descriptorSets,
int32 /*staticMeshId*/) int32 /*staticMeshId*/)
{ {
std::cout << "Depth job started" << std::endl; //std::cout << "Depth job started" << std::endl;
PMaterialAsset material = batch.material; PMaterialAsset material = batch.material;
//const Gfx::MaterialShadingModel shadingModel = material->getShadingModel(); //const Gfx::MaterialShadingModel shadingModel = material->getShadingModel();
@@ -63,8 +63,8 @@ Job DepthPrepassMeshProcessor::processMeshBatch(
} }
std::unique_lock lock(commandLock); std::unique_lock lock(commandLock);
renderCommands.add(renderCommand); renderCommands.add(renderCommand);
std::cout << "Finished depth job" << std::endl; //std::cout << "Finished depth job" << std::endl;
co_return; //co_return;
} }
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source) DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
@@ -127,10 +127,11 @@ MainJob DepthPrepass::render()
List<Job> jobs; List<Job> jobs;
for (auto &&meshBatch : passData.staticDrawList) for (auto &&meshBatch : passData.staticDrawList)
{ {
jobs.add(processor->processMeshBatch(meshBatch, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets)); //jobs.add(
processor->processMeshBatch(meshBatch, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets);
} }
co_await Job::all(jobs); //co_await Job::all(jobs);
std::cout << "Finished waiting depth jobs " << std::endl; //std::cout << "Finished waiting depth jobs " << std::endl;
graphics->executeCommands(processor->getRenderCommands()); graphics->executeCommands(processor->getRenderCommands());
graphics->endRenderPass(); graphics->endRenderPass();
co_return; co_return;
@@ -11,7 +11,7 @@ public:
DepthPrepassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics); DepthPrepassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics);
virtual ~DepthPrepassMeshProcessor(); virtual ~DepthPrepassMeshProcessor();
virtual Job processMeshBatch( virtual void processMeshBatch(
const MeshBatch& batch, const MeshBatch& batch,
const Gfx::PRenderPass& renderPass, const Gfx::PRenderPass& renderPass,
Gfx::PPipelineLayout pipelineLayout, Gfx::PPipelineLayout pipelineLayout,
@@ -75,7 +75,7 @@ MainJob LightCullingPass::beginFrame()
lightEnvDescriptorSet->updateBuffer(2, pointLightBuffer); lightEnvDescriptorSet->updateBuffer(2, pointLightBuffer);
lightEnvDescriptorSet->updateBuffer(3, numPointLightBuffer); lightEnvDescriptorSet->updateBuffer(3, numPointLightBuffer);
lightEnvDescriptorSet->writeChanges(); lightEnvDescriptorSet->writeChanges();
std::cout << "Finished light culling beginFrame()" << std::endl; //std::cout << "Finished light culling beginFrame()" << std::endl;
co_return; co_return;
} }
@@ -17,7 +17,7 @@ public:
protected: protected:
PScene scene; PScene scene;
Gfx::PGraphics graphics; Gfx::PGraphics graphics;
virtual Job processMeshBatch( virtual void processMeshBatch(
const MeshBatch& batch, const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent, // const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass& renderPass, const Gfx::PRenderPass& renderPass,
@@ -74,7 +74,7 @@ void CmdBuffer::beginRenderPass(PRenderPass newRenderPass, PFramebuffer newFrame
beginInfo.framebuffer = framebuffer->getHandle(); beginInfo.framebuffer = framebuffer->getHandle();
vkCmdBeginRenderPass(handle, &beginInfo, renderPass->getSubpassContents()); vkCmdBeginRenderPass(handle, &beginInfo, renderPass->getSubpassContents());
state = State::RenderPassActive; state = State::RenderPassActive;
std::cout << "Beginning renderPass" << std::endl; //std::cout << "Beginning renderPass" << std::endl;
} }
void CmdBuffer::endRenderPass() void CmdBuffer::endRenderPass()
@@ -82,7 +82,7 @@ void CmdBuffer::endRenderPass()
std::unique_lock lock(handleLock); std::unique_lock lock(handleLock);
vkCmdEndRenderPass(handle); vkCmdEndRenderPass(handle);
state = State::InsideBegin; state = State::InsideBegin;
std::cout << "Ending renderPass" << std::endl; //std::cout << "Ending renderPass" << std::endl;
} }
void CmdBuffer::executeCommands(const Array<Gfx::PRenderCommand>& commands) void CmdBuffer::executeCommands(const Array<Gfx::PRenderCommand>& commands)
@@ -270,6 +270,10 @@ DescriptorAllocator::~DescriptorAllocator()
{ {
vkDestroyDescriptorPool(graphics->getDevice(), poolHandle, nullptr); vkDestroyDescriptorPool(graphics->getDevice(), poolHandle, nullptr);
graphics = nullptr; graphics = nullptr;
if(nextAlloc)
{
delete nextAlloc;
}
} }
void DescriptorAllocator::allocateDescriptorSet(Gfx::PDescriptorSet &descriptorSet) void DescriptorAllocator::allocateDescriptorSet(Gfx::PDescriptorSet &descriptorSet)
@@ -305,7 +309,12 @@ void DescriptorAllocator::allocateDescriptorSet(Gfx::PDescriptorSet &descriptorS
//Found set, stop searching //Found set, stop searching
return; return;
} }
throw std::logic_error("Out of descriptor sets"); if(nextAlloc == nullptr)
{
nextAlloc = new DescriptorAllocator(graphics, layout);
}
nextAlloc->allocateDescriptorSet(descriptorSet);
//throw std::logic_error("Out of descriptor sets");
} }
void DescriptorAllocator::reset() void DescriptorAllocator::reset()
@@ -318,4 +327,8 @@ void DescriptorAllocator::reset()
} }
cachedHandles[i]->free(); cachedHandles[i]->free();
} }
if(nextAlloc != nullptr)
{
nextAlloc->reset();
}
} }
@@ -145,6 +145,7 @@ private:
const static int maxSets = 64; const static int maxSets = 64;
StaticArray<PDescriptorSet, maxSets> cachedHandles; StaticArray<PDescriptorSet, maxSets> cachedHandles;
VkDescriptorPool poolHandle; VkDescriptorPool poolHandle;
DescriptorAllocator* nextAlloc = nullptr;
}; };
DEFINE_REF(DescriptorAllocator) DEFINE_REF(DescriptorAllocator)
} // namespace Vulkan } // namespace Vulkan
+5 -3
View File
@@ -3,6 +3,8 @@
using namespace Seele; using namespace Seele;
std::atomic_uint64_t Seele::globalCounter;
Event::Event() Event::Event()
: flag(new std::atomic_bool()) : flag(new std::atomic_bool())
{ {
@@ -54,7 +56,6 @@ ThreadPool::~ThreadPool()
void ThreadPool::enqueueWaiting(Event &event, Promise* job) void ThreadPool::enqueueWaiting(Event &event, Promise* job)
{ {
assert(!job->done()); assert(!job->done());
assert(job->schedulable);
if(event == nullptr) if(event == nullptr)
{ {
std::unique_lock lock(jobQueueLock); std::unique_lock lock(jobQueueLock);
@@ -72,8 +73,7 @@ void ThreadPool::enqueueWaiting(Event &event, Promise* job)
void ThreadPool::enqueueWaiting(Event &event, MainPromise* job) void ThreadPool::enqueueWaiting(Event &event, MainPromise* job)
{ {
assert(!job->done()); assert(!job->done());
assert(job->schedulable); if(event == nullptr || event)
if(event == nullptr)
{ {
std::unique_lock lock(mainJobLock); std::unique_lock lock(mainJobLock);
//std::cout << "Queueing job " << job->finishedEvent.name << std::endl; //std::cout << "Queueing job " << job->finishedEvent.name << std::endl;
@@ -98,6 +98,7 @@ void ThreadPool::notify(Event &event)
{ {
//assert(job.id != -1ull); //assert(job.id != -1ull);
//std::cout << "Waking up " << job->finishedEvent.name << std::endl; //std::cout << "Waking up " << job->finishedEvent.name << std::endl;
job->state = Promise::State::SCHEDULED;
jobQueue.add(job); jobQueue.add(job);
jobQueueCV.notify_one(); jobQueueCV.notify_one();
} }
@@ -111,6 +112,7 @@ void ThreadPool::notify(Event &event)
{ {
//assert(job.id != -1ull); //assert(job.id != -1ull);
//std::cout << "Waking up main " << job->finishedEvent.name << std::endl; //std::cout << "Waking up main " << job->finishedEvent.name << std::endl;
job->state = MainPromise::State::SCHEDULED;
mainJobs.add(job); mainJobs.add(job);
mainJobCV.notify_one(); mainJobCV.notify_one();
} }
+37 -9
View File
@@ -45,12 +45,20 @@ private:
friend class ThreadPool; friend class ThreadPool;
}; };
static std::atomic_uint64_t globalCounter; extern std::atomic_uint64_t globalCounter;
template<bool MainJob> template<bool MainJob>
struct JobBase; struct JobBase;
template<bool MainJob> template<bool MainJob>
struct JobPromiseBase struct JobPromiseBase
{ {
enum class State
{
READY,
WAITING,
SCHEDULED,
EXECUTING,
DONE
};
JobPromiseBase() JobPromiseBase()
{ {
handle = std::coroutine_handle<JobPromiseBase<MainJob>>::from_promise(*this); handle = std::coroutine_handle<JobPromiseBase<MainJob>>::from_promise(*this);
@@ -71,11 +79,12 @@ struct JobPromiseBase
void resume() void resume()
{ {
std::unique_lock lock(promiseLock); std::unique_lock lock(promiseLock);
if(handle && !handle.done()) if(!handle || handle.done() || executing())
{ {
handle.resume(); return;
schedulable = true;
} }
state = State::EXECUTING;
handle.resume();
} }
void setContinuation(JobPromiseBase* cont) void setContinuation(JobPromiseBase* cont)
{ {
@@ -88,9 +97,26 @@ struct JobPromiseBase
{ {
return handle.done(); return handle.done();
} }
bool scheduled()
{
return state == State::SCHEDULED;
}
bool waiting()
{
return state == State::WAITING;
}
bool executing()
{
return state == State::EXECUTING;
}
bool ready()
{
return state == State::READY;
}
void raise() void raise()
{ {
std::unique_lock lock(promiseLock); std::unique_lock lock(promiseLock);
state = State::DONE;
finishedEvent.raise(); finishedEvent.raise();
} }
void reset() void reset()
@@ -100,22 +126,23 @@ struct JobPromiseBase
} }
void enqueue(Event& event) void enqueue(Event& event)
{ {
if(!handle || handle.done() || !schedulable) // no need to lock here, as it is only called while executing, where the lock is already held
if(!handle || handle.done() || waiting() || scheduled())
{ {
return; return;
} }
state = State::WAITING;
getGlobalThreadPool().enqueueWaiting(event, this); getGlobalThreadPool().enqueueWaiting(event, this);
schedulable = false;
} }
void schedule() void schedule()
{ {
std::unique_lock lock(promiseLock); std::unique_lock lock(promiseLock);
if(!handle || handle.done() || !schedulable) if(!handle || done() || !ready())
{ {
return; return;
} }
state = (precondition == nullptr) ? State::SCHEDULED : State::WAITING;
getGlobalThreadPool().enqueueWaiting(precondition, this); getGlobalThreadPool().enqueueWaiting(precondition, this);
schedulable = false;
} }
std::mutex promiseLock; std::mutex promiseLock;
@@ -124,7 +151,7 @@ struct JobPromiseBase
uint64 id; uint64 id;
Event finishedEvent; Event finishedEvent;
Event precondition = nullptr; Event precondition = nullptr;
bool schedulable = true; State state = State::READY;
}; };
template<bool MainJob = false> template<bool MainJob = false>
@@ -176,6 +203,7 @@ public:
} }
Event operator co_await() Event operator co_await()
{ {
promise->schedule();
return promise->finishedEvent; return promise->finishedEvent;
} }
static JobBase all() = delete; static JobBase all() = delete;
+16 -16
View File
@@ -18,28 +18,28 @@ Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const Viewpo
{ {
scene = new Scene(graphics); scene = new Scene(graphics);
scene->addActor(activeCamera); scene->addActor(activeCamera);
/*AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Diffuse.png"); AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Body_Diffuse.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Lightmap.png"); AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Body_Lightmap.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Face_Diffuse.png"); AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Face_Diffuse.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Hair_Diffuse.png"); AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Hair_Diffuse.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Hair_Lightmap.png"); AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Hair_Lightmap.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Tex_FaceLightmap.png"); AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Tex_FaceLightmap.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Ayaka.fbx"); AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Ayaka.fbx");
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ely\\Ely.fbx");
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Cube\\cube.obj");
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Plane\\plane.fbx");
srand(time(NULL));
for(uint32 i = 0; i < 100; ++i)
{
PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka")); PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka"));
ayaka->addWorldTranslation(Vector(0, 0, 0)); ayaka->addWorldTranslation(Vector(((float)rand() / RAND_MAX) * 100, 0, ((float)rand()/RAND_MAX) * 100));
ayaka->setWorldScale(Vector(10, 10, 10)); ayaka->setWorldScale(Vector(10, 10, 10));
scene->addPrimitiveComponent(ayaka);*/ scene->addPrimitiveComponent(ayaka);
}
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Ely\\Ely.fbx");
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Cube\\cube.obj");
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Plane\\plane.fbx");
PPrimitiveComponent plane = new PrimitiveComponent(AssetRegistry::findMesh("plane")); PPrimitiveComponent plane = new PrimitiveComponent(AssetRegistry::findMesh("plane"));
plane->setWorldScale(Vector(100, 100, 100)); plane->setWorldScale(Vector(100, 100, 100));
PPrimitiveComponent arissa = new PrimitiveComponent(AssetRegistry::findMesh("Ely"));
arissa->addWorldTranslation(Vector(0, 0, 100));
arissa->setWorldScale(Vector(0.1f, 0.1f, 0.1f));
scene->addPrimitiveComponent(plane); scene->addPrimitiveComponent(plane);
scene->addPrimitiveComponent(arissa);
PRenderGraphResources resources = new RenderGraphResources(); PRenderGraphResources resources = new RenderGraphResources();
depthPrepass.setResources(resources); depthPrepass.setResources(resources);
+1 -1
View File
@@ -8,7 +8,7 @@ View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &vi
: graphics(graphics) : graphics(graphics)
, owner(window) , owner(window)
, name(name) , name(name)
, renderFinishedEvent(name + "RenderFinished") , renderFinishedEvent(std::format("{}RenderFinished", name))
{ {
viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo); viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo);
} }
+3 -3
View File
@@ -9,7 +9,7 @@ using namespace Seele;
int main() int main()
{ {
PWindowManager windowManager = new WindowManager(); PWindowManager windowManager = new WindowManager();
AssetRegistry::init("D:\\Private\\Programming\\C++\\TestSeeleProject"); AssetRegistry::init("C:\\Users\\Dynamitos\\TestSeeleProject");
WindowCreateInfo mainWindowInfo; WindowCreateInfo mainWindowInfo;
mainWindowInfo.title = "SeeleEngine"; mainWindowInfo.title = "SeeleEngine";
mainWindowInfo.width = 1280; mainWindowInfo.width = 1280;
@@ -34,9 +34,9 @@ int main()
//PInspectorView inspectorView = new InspectorView(windowManager->getGraphics(), window, inspectorViewInfo); //PInspectorView inspectorView = new InspectorView(windowManager->getGraphics(), window, inspectorViewInfo);
//window->addView(inspectorView); //window->addView(inspectorView);
sceneView->setFocused(); sceneView->setFocused();
{
window->render(); window->render();
}
getGlobalThreadPool().threadLoop(true); getGlobalThreadPool().threadLoop(true);
return 0; return 0;
} }