diff --git a/CMakeSettings.json b/CMakeSettings.json index 3e49ade..800a3c7 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -10,7 +10,7 @@ "inheritEnvironments": [ "msvc_x64" ], "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", "buildRoot": "C:/Users/Dynamitos/Seele/bin/", - "installRoot": "C:/Program Files/Seele", + "installRoot": "C:/Program Files/Seele" }, { "name": "Release", diff --git a/res/shaders/Debug.slang b/res/shaders/Debug.slang index e69de29..f61527f 100644 --- a/res/shaders/Debug.slang +++ b/res/shaders/Debug.slang @@ -0,0 +1,28 @@ +import Common; + +struct DebugVertex +{ + float3 position; + float3 color; +} + +struct VertexOutput +{ + float4 clipPosition : SV_Position; + float3 color : COLOR0; +}; + +[shader("vertex")] +VertexOutput vertexMain(DebugVertex input) +{ + VertexOutput output; + output.clipPosition = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, float4(input.position, 1.0f))); + output.color = input.color; + return output; +} + +[shader("pixel")] +float4 fragmentMain(VertexOutput input) +{ + return float4(input.color, 1.0f); +} \ No newline at end of file diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index d633e9d..1215154 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -71,6 +71,11 @@ void BasePass::render() tLightGrid->pipelineBarrier( Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); + depthAttachment->getTexture()->pipelineBarrier( + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT); + depthAttachment->getTexture()->transferOwnership(Gfx::QueueType::GRAPHICS); + depthAttachment->getTexture()->changeLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); descriptorSets[INDEX_VIEW_PARAMS] = viewParamsSet; descriptorSets[INDEX_LIGHT_ENV] = scene->getLightEnvironment()->getDescriptorSet(); @@ -191,7 +196,7 @@ void BasePass::publishOutputs() void BasePass::createRenderPass() { - Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH"); + depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH"); depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD; Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{ .colorAttachments = { colorAttachment }, diff --git a/src/Engine/Graphics/RenderPass/BasePass.h b/src/Engine/Graphics/RenderPass/BasePass.h index 9d8b589..a4bda20 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.h +++ b/src/Engine/Graphics/RenderPass/BasePass.h @@ -20,7 +20,7 @@ public: static void modifyRenderPassMacros(Map& defines); private: Gfx::ORenderTargetAttachment colorAttachment; - Gfx::PTexture2D depthBuffer; + Gfx::PRenderTargetAttachment depthAttachment; Gfx::PShaderBuffer oLightIndexList; Gfx::PShaderBuffer tLightIndexList; Gfx::PTexture2D oLightGrid; diff --git a/src/Engine/Graphics/RenderPass/DebugPass.cpp b/src/Engine/Graphics/RenderPass/DebugPass.cpp index 35b697e..034e55a 100644 --- a/src/Engine/Graphics/RenderPass/DebugPass.cpp +++ b/src/Engine/Graphics/RenderPass/DebugPass.cpp @@ -23,6 +23,7 @@ DebugPass::DebugPass(Gfx::PGraphics graphics, PScene scene) { } + DebugPass::~DebugPass() { @@ -50,7 +51,7 @@ void DebugPass::render() Gfx::PRenderCommand renderCommand = graphics->createRenderCommand("DebugRender"); renderCommand->setViewport(viewport); renderCommand->bindPipeline(pipeline); - renderCommand->bindDescriptor(descriptorSet); + renderCommand->bindDescriptor(viewParamsSet); renderCommand->bindVertexBuffer({ debugVertices }); renderCommand->draw((uint32)gDebugVertices.size(), 1, 0, 0); graphics->executeCommands(Array{renderCommand}); @@ -64,18 +65,6 @@ void DebugPass::endFrame() void DebugPass::publishOutputs() { - UniformBufferCreateInfo viewCreateInfo = { - .sourceData = DataSource { - .size = sizeof(ViewParameter), - .data = nullptr, - }, - .dynamic = true - }; - viewParamsBuffer = graphics->createUniformBuffer(viewCreateInfo); - - descriptorLayout = graphics->createDescriptorLayout("DebugDescLayout"); - descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER); - descriptorLayout->create(); } void DebugPass::createRenderPass() @@ -91,22 +80,47 @@ void DebugPass::createRenderPass() renderPass = graphics->createRenderPass(std::move(layout), viewport); Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout(); - pipelineLayout->addDescriptorLayout(0, descriptorLayout); + pipelineLayout->addDescriptorLayout(0, viewParamsLayout); pipelineLayout->create(); - ShaderCreateInfo createInfo; - createInfo.name = "DebugVertex"; - createInfo.mainModule = "Debug"; - createInfo.entryPoint = "vertexMain"; - createInfo.defines["INDEX_VIEW_PARAMS"] = "0"; + ShaderCreateInfo createInfo = { + .mainModule = "Debug", + .additionalModules = { "Debug" }, + .name = "DebugVertex", + .entryPoint = "vertexMain", + }; vertexShader = graphics->createVertexShader(createInfo); createInfo.name = "DebugFragment"; - createInfo.entryPoint = "fragmentMain"; fragmentShader = graphics->createFragmentShader(createInfo); + VertexInputStateCreateInfo inputCreate = { + .bindings = { + VertexInputBinding { + .binding = 0, + .stride = sizeof(DebugVertex), + .inputRate = Gfx::SE_VERTEX_INPUT_RATE_VERTEX, + }, + }, + .attributes = { + VertexInputAttribute { + .location = 0, + .binding = 0, + .format = Gfx::SE_FORMAT_R32G32B32_SFLOAT, + .offset = 0, + }, + VertexInputAttribute { + .location = 1, + .binding = 0, + .format = Gfx::SE_FORMAT_R32G32B32_SFLOAT, + .offset = sizeof(Vector) + } + }, + }; + vertexInput = graphics->createVertexInput(inputCreate); Gfx::LegacyPipelineCreateInfo gfxInfo; + gfxInfo.vertexInput = vertexInput; gfxInfo.vertexShader = vertexShader; gfxInfo.fragmentShader = fragmentShader; gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_LINE; diff --git a/src/Engine/Graphics/RenderPass/DebugPass.h b/src/Engine/Graphics/RenderPass/DebugPass.h index 834488b..3ae78fe 100644 --- a/src/Engine/Graphics/RenderPass/DebugPass.h +++ b/src/Engine/Graphics/RenderPass/DebugPass.h @@ -2,6 +2,7 @@ #include "RenderPass.h" #include "Scene/Scene.h" #include "Graphics/DebugVertex.h" +#include "Graphics/Pipeline.h" namespace Seele { @@ -21,10 +22,8 @@ public: virtual void publishOutputs() override; virtual void createRenderPass() override; private: + Gfx::OVertexInput vertexInput; Gfx::OVertexBuffer debugVertices; - Gfx::OUniformBuffer viewParamsBuffer; - Gfx::ODescriptorLayout descriptorLayout; - Gfx::PDescriptorSet descriptorSet; Gfx::OVertexShader vertexShader; Gfx::OFragmentShader fragmentShader; Gfx::PGraphicsPipeline pipeline; diff --git a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp index 0027771..9b3e6db 100644 --- a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp +++ b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp @@ -40,10 +40,6 @@ void DepthPrepass::beginFrame(const Component::Camera& cam) void DepthPrepass::render() { - depthAttachment->getTexture()->pipelineBarrier( - Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT); - depthAttachment->getTexture()->transferOwnership(Gfx::QueueType::GRAPHICS); Gfx::ShaderPermutation permutation; if(graphics->supportMeshShading()) { diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp index 88f812d..cc41ffc 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp @@ -64,8 +64,6 @@ void LightCullingPass::render() //computeCommand->dispatch(dispatchParams.numThreadGroups.x, dispatchParams.numThreadGroups.y, dispatchParams.numThreadGroups.z); Array commands = {computeCommand}; 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; } diff --git a/src/Engine/Graphics/Vulkan/Resources.cpp b/src/Engine/Graphics/Vulkan/Resources.cpp index 863afde..2119540 100644 --- a/src/Engine/Graphics/Vulkan/Resources.cpp +++ b/src/Engine/Graphics/Vulkan/Resources.cpp @@ -37,6 +37,7 @@ Fence::Fence(PGraphics graphics) Fence::~Fence() { + vkWaitForFences(graphics->getDevice(), 1, &fence, true, 100000); vkDestroyFence(graphics->getDevice(), fence, nullptr); } diff --git a/src/Engine/Scene/Scene.h b/src/Engine/Scene/Scene.h index 1e4ba7e..dac8c30 100644 --- a/src/Engine/Scene/Scene.h +++ b/src/Engine/Scene/Scene.h @@ -19,9 +19,7 @@ public: void update(float deltaTime); entt::entity createEntity() { - auto result = registry.create(); - std::cout << "Created " << (uint64_t)result << " at " << this << std::endl; - return result; + return registry.create(); } void destroyEntity(entt::entity identifier) { @@ -30,8 +28,6 @@ public: template Component& attachComponent(entt::entity entity, Args&&... args) { - std::cout << "Emplace " << (uint64_t)entity << std::endl; - std::cout << "Exists " << registry.valid(entity) << std::endl; return registry.emplace(entity, std::forward(args)...); } template diff --git a/src/Engine/Window/GameView.cpp b/src/Engine/Window/GameView.cpp index a6834d3..af2ea85 100644 --- a/src/Engine/Window/GameView.cpp +++ b/src/Engine/Window/GameView.cpp @@ -20,6 +20,7 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate DepthPrepass(graphics, scene), LightCullingPass(graphics, scene), BasePass(graphics, scene), + DebugPass(graphics, scene), SkyboxRenderPass(graphics, scene) )) { diff --git a/src/Engine/Window/GameView.h b/src/Engine/Window/GameView.h index b7e4a18..6717d40 100644 --- a/src/Engine/Window/GameView.h +++ b/src/Engine/Window/GameView.h @@ -5,6 +5,7 @@ #include "Graphics/RenderPass/LightCullingPass.h" #include "Graphics/RenderPass/BasePass.h" #include "Graphics/RenderPass/SkyboxRenderPass.h" +#include "Graphics/RenderPass/DebugPass.h" #include "System/KeyboardInput.h" #ifdef WIN32 #include "Platform/Windows/GameInterface.h" // TODO @@ -35,6 +36,7 @@ protected: DepthPrepass, LightCullingPass, BasePass, + DebugPass, SkyboxRenderPass > renderGraph;