Rendering works now
This commit is contained in:
@@ -504,7 +504,7 @@ namespace Seele
|
||||
// As well as default initialize the others
|
||||
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);
|
||||
arraySize = newSize;
|
||||
|
||||
@@ -20,7 +20,7 @@ BasePassMeshProcessor::~BasePassMeshProcessor()
|
||||
{
|
||||
}
|
||||
|
||||
Job BasePassMeshProcessor::processMeshBatch(
|
||||
void BasePassMeshProcessor::processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
// const PPrimitiveComponent primitiveComponent,
|
||||
const Gfx::PRenderPass& renderPass,
|
||||
@@ -65,7 +65,7 @@ Job BasePassMeshProcessor::processMeshBatch(
|
||||
}
|
||||
std::unique_lock lock(commandLock);
|
||||
renderCommands.add(renderCommand);
|
||||
co_return;
|
||||
//co_return;
|
||||
}
|
||||
|
||||
BasePass::BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
|
||||
@@ -156,9 +156,10 @@ MainJob BasePass::render()
|
||||
List<Job> jobs;
|
||||
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->endRenderPass();
|
||||
co_return;
|
||||
|
||||
@@ -11,7 +11,7 @@ public:
|
||||
BasePassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass);
|
||||
virtual ~BasePassMeshProcessor();
|
||||
|
||||
virtual Job processMeshBatch(
|
||||
virtual void processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
// const PPrimitiveComponent primitiveComponent,
|
||||
const Gfx::PRenderPass& renderPass,
|
||||
|
||||
@@ -18,7 +18,7 @@ DepthPrepassMeshProcessor::~DepthPrepassMeshProcessor()
|
||||
{
|
||||
}
|
||||
|
||||
Job DepthPrepassMeshProcessor::processMeshBatch(
|
||||
void DepthPrepassMeshProcessor::processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
// const PPrimitiveComponent primitiveComponent,
|
||||
const Gfx::PRenderPass& renderPass,
|
||||
@@ -27,7 +27,7 @@ Job DepthPrepassMeshProcessor::processMeshBatch(
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
int32 /*staticMeshId*/)
|
||||
{
|
||||
std::cout << "Depth job started" << std::endl;
|
||||
//std::cout << "Depth job started" << std::endl;
|
||||
PMaterialAsset material = batch.material;
|
||||
//const Gfx::MaterialShadingModel shadingModel = material->getShadingModel();
|
||||
|
||||
@@ -63,8 +63,8 @@ Job DepthPrepassMeshProcessor::processMeshBatch(
|
||||
}
|
||||
std::unique_lock lock(commandLock);
|
||||
renderCommands.add(renderCommand);
|
||||
std::cout << "Finished depth job" << std::endl;
|
||||
co_return;
|
||||
//std::cout << "Finished depth job" << std::endl;
|
||||
//co_return;
|
||||
}
|
||||
|
||||
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
|
||||
@@ -127,10 +127,11 @@ MainJob DepthPrepass::render()
|
||||
List<Job> jobs;
|
||||
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);
|
||||
std::cout << "Finished waiting depth jobs " << std::endl;
|
||||
//co_await Job::all(jobs);
|
||||
//std::cout << "Finished waiting depth jobs " << std::endl;
|
||||
graphics->executeCommands(processor->getRenderCommands());
|
||||
graphics->endRenderPass();
|
||||
co_return;
|
||||
|
||||
@@ -11,7 +11,7 @@ public:
|
||||
DepthPrepassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics);
|
||||
virtual ~DepthPrepassMeshProcessor();
|
||||
|
||||
virtual Job processMeshBatch(
|
||||
virtual void processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
const Gfx::PRenderPass& renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
|
||||
@@ -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 << "Finished light culling beginFrame()" << std::endl;
|
||||
co_return;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
protected:
|
||||
PScene scene;
|
||||
Gfx::PGraphics graphics;
|
||||
virtual Job processMeshBatch(
|
||||
virtual void processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
// const PPrimitiveComponent primitiveComponent,
|
||||
const Gfx::PRenderPass& renderPass,
|
||||
|
||||
@@ -74,7 +74,7 @@ void CmdBuffer::beginRenderPass(PRenderPass newRenderPass, PFramebuffer newFrame
|
||||
beginInfo.framebuffer = framebuffer->getHandle();
|
||||
vkCmdBeginRenderPass(handle, &beginInfo, renderPass->getSubpassContents());
|
||||
state = State::RenderPassActive;
|
||||
std::cout << "Beginning renderPass" << std::endl;
|
||||
//std::cout << "Beginning renderPass" << std::endl;
|
||||
}
|
||||
|
||||
void CmdBuffer::endRenderPass()
|
||||
@@ -82,7 +82,7 @@ void CmdBuffer::endRenderPass()
|
||||
std::unique_lock lock(handleLock);
|
||||
vkCmdEndRenderPass(handle);
|
||||
state = State::InsideBegin;
|
||||
std::cout << "Ending renderPass" << std::endl;
|
||||
//std::cout << "Ending renderPass" << std::endl;
|
||||
}
|
||||
|
||||
void CmdBuffer::executeCommands(const Array<Gfx::PRenderCommand>& commands)
|
||||
|
||||
@@ -270,6 +270,10 @@ DescriptorAllocator::~DescriptorAllocator()
|
||||
{
|
||||
vkDestroyDescriptorPool(graphics->getDevice(), poolHandle, nullptr);
|
||||
graphics = nullptr;
|
||||
if(nextAlloc)
|
||||
{
|
||||
delete nextAlloc;
|
||||
}
|
||||
}
|
||||
|
||||
void DescriptorAllocator::allocateDescriptorSet(Gfx::PDescriptorSet &descriptorSet)
|
||||
@@ -305,7 +309,12 @@ void DescriptorAllocator::allocateDescriptorSet(Gfx::PDescriptorSet &descriptorS
|
||||
//Found set, stop searching
|
||||
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()
|
||||
@@ -318,4 +327,8 @@ void DescriptorAllocator::reset()
|
||||
}
|
||||
cachedHandles[i]->free();
|
||||
}
|
||||
if(nextAlloc != nullptr)
|
||||
{
|
||||
nextAlloc->reset();
|
||||
}
|
||||
}
|
||||
@@ -145,6 +145,7 @@ private:
|
||||
const static int maxSets = 64;
|
||||
StaticArray<PDescriptorSet, maxSets> cachedHandles;
|
||||
VkDescriptorPool poolHandle;
|
||||
DescriptorAllocator* nextAlloc = nullptr;
|
||||
};
|
||||
DEFINE_REF(DescriptorAllocator)
|
||||
} // namespace Vulkan
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
std::atomic_uint64_t Seele::globalCounter;
|
||||
|
||||
Event::Event()
|
||||
: flag(new std::atomic_bool())
|
||||
{
|
||||
@@ -54,7 +56,6 @@ ThreadPool::~ThreadPool()
|
||||
void ThreadPool::enqueueWaiting(Event &event, Promise* job)
|
||||
{
|
||||
assert(!job->done());
|
||||
assert(job->schedulable);
|
||||
if(event == nullptr)
|
||||
{
|
||||
std::unique_lock lock(jobQueueLock);
|
||||
@@ -72,8 +73,7 @@ void ThreadPool::enqueueWaiting(Event &event, Promise* job)
|
||||
void ThreadPool::enqueueWaiting(Event &event, MainPromise* job)
|
||||
{
|
||||
assert(!job->done());
|
||||
assert(job->schedulable);
|
||||
if(event == nullptr)
|
||||
if(event == nullptr || event)
|
||||
{
|
||||
std::unique_lock lock(mainJobLock);
|
||||
//std::cout << "Queueing job " << job->finishedEvent.name << std::endl;
|
||||
@@ -98,6 +98,7 @@ void ThreadPool::notify(Event &event)
|
||||
{
|
||||
//assert(job.id != -1ull);
|
||||
//std::cout << "Waking up " << job->finishedEvent.name << std::endl;
|
||||
job->state = Promise::State::SCHEDULED;
|
||||
jobQueue.add(job);
|
||||
jobQueueCV.notify_one();
|
||||
}
|
||||
@@ -111,6 +112,7 @@ void ThreadPool::notify(Event &event)
|
||||
{
|
||||
//assert(job.id != -1ull);
|
||||
//std::cout << "Waking up main " << job->finishedEvent.name << std::endl;
|
||||
job->state = MainPromise::State::SCHEDULED;
|
||||
mainJobs.add(job);
|
||||
mainJobCV.notify_one();
|
||||
}
|
||||
|
||||
+37
-9
@@ -45,12 +45,20 @@ private:
|
||||
friend class ThreadPool;
|
||||
};
|
||||
|
||||
static std::atomic_uint64_t globalCounter;
|
||||
extern std::atomic_uint64_t globalCounter;
|
||||
template<bool MainJob>
|
||||
struct JobBase;
|
||||
template<bool MainJob>
|
||||
struct JobPromiseBase
|
||||
{
|
||||
enum class State
|
||||
{
|
||||
READY,
|
||||
WAITING,
|
||||
SCHEDULED,
|
||||
EXECUTING,
|
||||
DONE
|
||||
};
|
||||
JobPromiseBase()
|
||||
{
|
||||
handle = std::coroutine_handle<JobPromiseBase<MainJob>>::from_promise(*this);
|
||||
@@ -71,11 +79,12 @@ struct JobPromiseBase
|
||||
void resume()
|
||||
{
|
||||
std::unique_lock lock(promiseLock);
|
||||
if(handle && !handle.done())
|
||||
if(!handle || handle.done() || executing())
|
||||
{
|
||||
handle.resume();
|
||||
schedulable = true;
|
||||
return;
|
||||
}
|
||||
state = State::EXECUTING;
|
||||
handle.resume();
|
||||
}
|
||||
void setContinuation(JobPromiseBase* cont)
|
||||
{
|
||||
@@ -88,9 +97,26 @@ struct JobPromiseBase
|
||||
{
|
||||
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()
|
||||
{
|
||||
std::unique_lock lock(promiseLock);
|
||||
state = State::DONE;
|
||||
finishedEvent.raise();
|
||||
}
|
||||
void reset()
|
||||
@@ -100,22 +126,23 @@ struct JobPromiseBase
|
||||
}
|
||||
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;
|
||||
}
|
||||
state = State::WAITING;
|
||||
getGlobalThreadPool().enqueueWaiting(event, this);
|
||||
schedulable = false;
|
||||
}
|
||||
void schedule()
|
||||
{
|
||||
std::unique_lock lock(promiseLock);
|
||||
if(!handle || handle.done() || !schedulable)
|
||||
if(!handle || done() || !ready())
|
||||
{
|
||||
return;
|
||||
}
|
||||
state = (precondition == nullptr) ? State::SCHEDULED : State::WAITING;
|
||||
getGlobalThreadPool().enqueueWaiting(precondition, this);
|
||||
schedulable = false;
|
||||
}
|
||||
|
||||
std::mutex promiseLock;
|
||||
@@ -124,7 +151,7 @@ struct JobPromiseBase
|
||||
uint64 id;
|
||||
Event finishedEvent;
|
||||
Event precondition = nullptr;
|
||||
bool schedulable = true;
|
||||
State state = State::READY;
|
||||
};
|
||||
|
||||
template<bool MainJob = false>
|
||||
@@ -176,6 +203,7 @@ public:
|
||||
}
|
||||
Event operator co_await()
|
||||
{
|
||||
promise->schedule();
|
||||
return promise->finishedEvent;
|
||||
}
|
||||
static JobBase all() = delete;
|
||||
|
||||
@@ -18,28 +18,28 @@ Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const Viewpo
|
||||
{
|
||||
scene = new Scene(graphics);
|
||||
scene->addActor(activeCamera);
|
||||
/*AssetRegistry::importFile("/home/dynamitos/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("/home/dynamitos/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("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Hair_Lightmap.png");
|
||||
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Tex_FaceLightmap.png");
|
||||
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Ayaka.fbx");
|
||||
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Body_Diffuse.png");
|
||||
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Body_Lightmap.png");
|
||||
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Face_Diffuse.png");
|
||||
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Hair_Diffuse.png");
|
||||
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Hair_Lightmap.png");
|
||||
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Tex_FaceLightmap.png");
|
||||
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"));
|
||||
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));
|
||||
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"));
|
||||
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(arissa);
|
||||
|
||||
PRenderGraphResources resources = new RenderGraphResources();
|
||||
depthPrepass.setResources(resources);
|
||||
|
||||
@@ -8,7 +8,7 @@ View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &vi
|
||||
: graphics(graphics)
|
||||
, owner(window)
|
||||
, name(name)
|
||||
, renderFinishedEvent(name + "RenderFinished")
|
||||
, renderFinishedEvent(std::format("{}RenderFinished", name))
|
||||
{
|
||||
viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo);
|
||||
}
|
||||
|
||||
+3
-3
@@ -9,7 +9,7 @@ using namespace Seele;
|
||||
int main()
|
||||
{
|
||||
PWindowManager windowManager = new WindowManager();
|
||||
AssetRegistry::init("D:\\Private\\Programming\\C++\\TestSeeleProject");
|
||||
AssetRegistry::init("C:\\Users\\Dynamitos\\TestSeeleProject");
|
||||
WindowCreateInfo mainWindowInfo;
|
||||
mainWindowInfo.title = "SeeleEngine";
|
||||
mainWindowInfo.width = 1280;
|
||||
@@ -34,9 +34,9 @@ int main()
|
||||
//PInspectorView inspectorView = new InspectorView(windowManager->getGraphics(), window, inspectorViewInfo);
|
||||
//window->addView(inspectorView);
|
||||
sceneView->setFocused();
|
||||
{
|
||||
|
||||
window->render();
|
||||
}
|
||||
|
||||
getGlobalThreadPool().threadLoop(true);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user