From 242acdab58738d04f794b11c0282a4cda4df1363 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Fri, 27 Sep 2024 15:57:37 +0200 Subject: [PATCH] Changing descriptor update signature --- cmake/SuperBuild.cmake | 2 +- external/slang | 2 +- res/shaders/TerrainPass.slang | 2 +- res/shaders/lib/DispatchParams.slang | 2 +- res/shaders/lib/Material.slang | 2 +- res/shaders/raytracing/ClosestHit.slang | 2 +- src/Engine/Graphics/Descriptor.h | 18 ++- src/Engine/Graphics/RenderPass/BasePass.cpp | 18 +-- .../Graphics/RenderPass/CachedDepthPass.cpp | 4 +- .../Graphics/RenderPass/DepthCullingPass.cpp | 6 +- .../Graphics/RenderPass/LightCullingPass.cpp | 22 +-- .../Graphics/RenderPass/RayTracingPass.cpp | 6 +- src/Engine/Graphics/RenderPass/RenderPass.cpp | 2 +- .../Graphics/RenderPass/TerrainRenderer.cpp | 6 +- src/Engine/Graphics/RenderPass/TextPass.cpp | 10 +- src/Engine/Graphics/RenderPass/UIPass.cpp | 16 +- .../Graphics/RenderPass/VisibilityPass.cpp | 4 +- .../Graphics/RenderPass/WaterRenderer.cpp | 28 ++-- src/Engine/Graphics/StaticMeshVertexData.cpp | 24 ++- src/Engine/Graphics/VertexData.cpp | 12 +- src/Engine/Graphics/Vulkan/Command.cpp | 71 +++++---- src/Engine/Graphics/Vulkan/Descriptor.cpp | 145 +++++++++--------- src/Engine/Graphics/Vulkan/Descriptor.h | 18 +-- src/Engine/Graphics/Vulkan/Graphics.cpp | 4 +- src/Engine/Graphics/slang-compile.cpp | 4 +- src/Engine/Material/Material.cpp | 25 ++- src/Engine/Scene/LightEnvironment.cpp | 6 +- src/Engine/Window/GameView.cpp | 4 +- 28 files changed, 240 insertions(+), 225 deletions(-) diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake index 4625c05..d737e16 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SuperBuild.cmake @@ -26,7 +26,7 @@ elseif(APPLE) DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) endif() target_include_directories(slang INTERFACE - $ + $ $ ) diff --git a/external/slang b/external/slang index 1a0bbb5..a77d50b 160000 --- a/external/slang +++ b/external/slang @@ -1 +1 @@ -Subproject commit 1a0bbb53c116e6e5f89ed577803341e6aa1bce82 +Subproject commit a77d50b724fdfe15ec17f6df9a7671adcd6024ba diff --git a/res/shaders/TerrainPass.slang b/res/shaders/TerrainPass.slang index 04efc14..aa98028 100644 --- a/res/shaders/TerrainPass.slang +++ b/res/shaders/TerrainPass.slang @@ -151,7 +151,7 @@ void meshMain( // float3 displacement2 = pWaterMaterial.displacementTextures.Sample(pWaterMaterial.sampler, float3(worldPos.xz * pWaterMaterial.tile2, 1)).xyz * pWaterMaterial.contributeDisplacement2; // float3 displacement3 = pWaterMaterial.displacementTextures.Sample(pWaterMaterial.sampler, float3(worldPos.xz * pWaterMaterial.tile3, 2)).xyz * pWaterMaterial.contributeDisplacement3; // float3 displacement4 = pWaterMaterial.displacementTextures.Sample(pWaterMaterial.sampler, float3(worldPos.xz * pWaterMaterial.tile4, 3)).xyz * pWaterMaterial.contributeDisplacement4; - float displacement = pTerrainData.displacement.Sample(pTerrainData.sampler, worldPos.xz); + float displacement = pTerrainData.displacement.SampleLevel(pTerrainData.sampler, worldPos.xz, 0); float4 clipPos = mul(vp, float4(worldPos, 1)); float ndcDepth = clipPos.z / clipPos.w; diff --git a/res/shaders/lib/DispatchParams.slang b/res/shaders/lib/DispatchParams.slang index 66923ea..201dd39 100644 --- a/res/shaders/lib/DispatchParams.slang +++ b/res/shaders/lib/DispatchParams.slang @@ -10,7 +10,7 @@ struct DispatchParams struct DispatchParamWrapper { - ParameterBlock p; + DispatchParams p; RWStructuredBuffer frustums; } ParameterBlock pDispatchParams; \ No newline at end of file diff --git a/res/shaders/lib/Material.slang b/res/shaders/lib/Material.slang index 5184b2f..3b3bef2 100644 --- a/res/shaders/lib/Material.slang +++ b/res/shaders/lib/Material.slang @@ -10,9 +10,9 @@ import Scene; //}; struct MaterialResources { - StructuredBuffer floatArray; Texture2D textureArray[512]; SamplerState samplerArray[512]; + StructuredBuffer floatArray; }; layout(set=4) ParameterBlock pResources; diff --git a/res/shaders/raytracing/ClosestHit.slang b/res/shaders/raytracing/ClosestHit.slang index 45f4d9c..eba2d88 100644 --- a/res/shaders/raytracing/ClosestHit.slang +++ b/res/shaders/raytracing/ClosestHit.slang @@ -3,7 +3,7 @@ import MaterialParameter; import LightEnv; import Scene; import RayTracingData; -import VertexData; +import StaticMeshVertexData; import Material; import MATERIAL_FILE_NAME; diff --git a/src/Engine/Graphics/Descriptor.h b/src/Engine/Graphics/Descriptor.h index bf704ab..20a5942 100644 --- a/src/Engine/Graphics/Descriptor.h +++ b/src/Engine/Graphics/Descriptor.h @@ -54,6 +54,8 @@ DECLARE_REF(UniformBuffer) DECLARE_REF(ShaderBuffer) DECLARE_REF(Texture) DECLARE_REF(Texture2D) +DECLARE_REF(Texture3D) +DECLARE_REF(TextureCube) DECLARE_REF(Sampler) DECLARE_REF(TopLevelAS) class DescriptorSet { @@ -61,14 +63,14 @@ class DescriptorSet { DescriptorSet(PDescriptorLayout layout); virtual ~DescriptorSet(); virtual void writeChanges() = 0; - virtual void updateBuffer(uint32 binding, PUniformBuffer uniformBuffer) = 0; - virtual void updateBuffer(uint32 binding, PIndexBuffer indexBuffer) = 0; - virtual void updateBuffer(uint32 binding, PShaderBuffer shaderBuffer) = 0; - virtual void updateSampler(uint32 binding, PSampler sampler) = 0; - virtual void updateTexture(uint32 binding, PTexture texture, PSampler samplerState = nullptr) = 0; - virtual void updateTextureArray(uint32_t binding, Array texture) = 0; - virtual void updateSamplerArray(uint32_t binding, Array samplers) = 0; - virtual void updateAccelerationStructure(uint32 binding, PTopLevelAS as) = 0; + virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PUniformBuffer uniformBuffer) = 0; + virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) = 0; + virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PIndexBuffer indexBuffer) = 0; + virtual void updateSampler(uint32 binding, uint32 index, Gfx::PSampler samplerState) = 0; + virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTexture2D texture) = 0; + virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTexture3D texture) = 0; + virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTextureCube texture) = 0; + virtual void updateAccelerationStructure(uint32 binding, uint32 index, Gfx::PTopLevelAS as) = 0; bool operator<(PDescriptorSet other); constexpr PDescriptorLayout getLayout() const { return layout; } diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index 31a3a6c..e0e6c3d 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -128,21 +128,21 @@ void BasePass::beginFrame(const Component::Camera& cam) { skyboxBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_UNIFORM_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); skyboxDataSet = skyboxDataLayout->allocateDescriptorSet(); - skyboxDataSet->updateBuffer(0, skyboxBuffer); + skyboxDataSet->updateBuffer(0, 0, skyboxBuffer); skyboxDataSet->writeChanges(); textureSet = textureLayout->allocateDescriptorSet(); - textureSet->updateTexture(0, skybox.day); - textureSet->updateTexture(1, skybox.night); - textureSet->updateSampler(2, skyboxSampler); + textureSet->updateTexture(0, 0, skybox.day); + textureSet->updateTexture(1, 0, skybox.night); + textureSet->updateSampler(2, 0, skyboxSampler); textureSet->writeChanges(); } } void BasePass::render() { - opaqueCulling->updateBuffer(0, oLightIndexList); - opaqueCulling->updateTexture(1, oLightGrid); - transparentCulling->updateBuffer(0, tLightIndexList); - transparentCulling->updateTexture(1, tLightGrid); + opaqueCulling->updateBuffer(0, 0, oLightIndexList); + opaqueCulling->updateTexture(1, 0, oLightGrid); + transparentCulling->updateBuffer(0, 0, tLightIndexList); + transparentCulling->updateTexture(1, 0, tLightGrid); opaqueCulling->writeChanges(); transparentCulling->writeChanges(); @@ -157,7 +157,7 @@ void BasePass::render() { // Base Rendering for (VertexData* vertexData : VertexData::getList()) { transparentData.addAll(vertexData->getTransparentData()); - vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer); + vertexData->getInstanceDataSet()->updateBuffer(6, 0, cullingBuffer); vertexData->getInstanceDataSet()->writeChanges(); permutation.setVertexData(vertexData->getTypeName()); const auto& materials = vertexData->getMaterialData(); diff --git a/src/Engine/Graphics/RenderPass/CachedDepthPass.cpp b/src/Engine/Graphics/RenderPass/CachedDepthPass.cpp index 7fbbace..1be4212 100644 --- a/src/Engine/Graphics/RenderPass/CachedDepthPass.cpp +++ b/src/Engine/Graphics/RenderPass/CachedDepthPass.cpp @@ -53,7 +53,7 @@ void CachedDepthPass::render() { permutation.setDepthCulling(true); for (VertexData* vertexData : VertexData::getList()) { permutation.setVertexData(vertexData->getTypeName()); - vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer); + vertexData->getInstanceDataSet()->updateBuffer(6, 0, cullingBuffer); vertexData->getInstanceDataSet()->writeChanges(); // Create Pipeline(VertexData) @@ -63,7 +63,7 @@ void CachedDepthPass::render() { // SceneData => per meshtype Gfx::PermutationId id(permutation); - Gfx::ORenderCommand command = graphics->createRenderCommand("DepthRender"); + Gfx::ORenderCommand command = graphics->createRenderCommand("CullingRender"); command->setViewport(viewport); const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id); diff --git a/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp b/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp index 79129ad..4b6f79d 100644 --- a/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp @@ -75,8 +75,8 @@ void DepthCullingPass::render() { depthMipBuffer->rotateBuffer(depthMipBuffer->getNumElements() * sizeof(uint32)); Gfx::PDescriptorSet set = depthAttachmentLayout->allocateDescriptorSet(); - set->updateTexture(0, Gfx::PTexture2D(depthAttachment.getTexture())); - set->updateBuffer(1, depthMipBuffer); + set->updateTexture(0, 0, depthAttachment.getTexture()); + set->updateBuffer(1, 0, depthMipBuffer); set->writeChanges(); timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "MipBegin"); @@ -125,7 +125,7 @@ void DepthCullingPass::render() { permutation.setDepthCulling(getGlobals().useDepthCulling); for (VertexData* vertexData : VertexData::getList()) { permutation.setVertexData(vertexData->getTypeName()); - vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer); + vertexData->getInstanceDataSet()->updateBuffer(6, 0, cullingBuffer); vertexData->getInstanceDataSet()->writeChanges(); // Create Pipeline(VertexData) // Descriptors: diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp index d54967d..56069ed 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp @@ -42,13 +42,13 @@ void LightCullingPass::render() { Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); tLightGrid->pipelineBarrier(Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); - cullingDescriptorSet->updateTexture(0, depthAttachment); - cullingDescriptorSet->updateBuffer(1, oLightIndexCounter); - cullingDescriptorSet->updateBuffer(2, tLightIndexCounter); - cullingDescriptorSet->updateBuffer(3, oLightIndexList); - cullingDescriptorSet->updateBuffer(4, tLightIndexList); - cullingDescriptorSet->updateTexture(5, Gfx::PTexture2D(oLightGrid)); - cullingDescriptorSet->updateTexture(6, Gfx::PTexture2D(tLightGrid)); + cullingDescriptorSet->updateTexture(0, 0, depthAttachment); + cullingDescriptorSet->updateBuffer(1, 0, oLightIndexCounter); + cullingDescriptorSet->updateBuffer(2, 0, tLightIndexCounter); + cullingDescriptorSet->updateBuffer(3, 0, oLightIndexList); + cullingDescriptorSet->updateBuffer(4, 0, tLightIndexList); + cullingDescriptorSet->updateTexture(5, 0, oLightGrid); + cullingDescriptorSet->updateTexture(6, 0, tLightGrid); cullingDescriptorSet->writeChanges(); Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("CullingCommand"); if (getGlobals().useLightCulling) { @@ -96,8 +96,8 @@ void LightCullingPass::publishOutputs() { dispatchParamsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_UNIFORM_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet(); - dispatchParamsSet->updateBuffer(0, dispatchParamsBuffer); - dispatchParamsSet->updateBuffer(1, frustumBuffer); + dispatchParamsSet->updateBuffer(0, 0, dispatchParamsBuffer); + dispatchParamsSet->updateBuffer(1, 0, frustumBuffer); dispatchParamsSet->writeChanges(); cullingDescriptorLayout = graphics->createDescriptorLayout("pCullingParams"); @@ -305,8 +305,8 @@ void LightCullingPass::setupFrustums() { Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); Gfx::PDescriptorSet dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet(); - dispatchParamsSet->updateBuffer(0, frustumDispatchParamsBuffer); - dispatchParamsSet->updateBuffer(1, frustumBuffer); + dispatchParamsSet->updateBuffer(0, 0, frustumDispatchParamsBuffer); + dispatchParamsSet->updateBuffer(1, 0, frustumBuffer); dispatchParamsSet->writeChanges(); Gfx::OComputeCommand command = graphics->createComputeCommand("FrustumCommand"); diff --git a/src/Engine/Graphics/RenderPass/RayTracingPass.cpp b/src/Engine/Graphics/RenderPass/RayTracingPass.cpp index a141b7d..73c8bb3 100644 --- a/src/Engine/Graphics/RenderPass/RayTracingPass.cpp +++ b/src/Engine/Graphics/RenderPass/RayTracingPass.cpp @@ -103,9 +103,9 @@ void RayTracingPass::render() { .bottomLevelStructures = accelerationStructures, }); Gfx::PDescriptorSet desc = paramsLayout->allocateDescriptorSet(); - desc->updateAccelerationStructure(0, tlas); - desc->updateTexture(1, Gfx::PTexture2D(texture)); - desc->updateBuffer(2, StaticMeshVertexData::getInstance()->getIndexBuffer()); + desc->updateAccelerationStructure(0, 0, tlas); + desc->updateTexture(1, 0, texture); + desc->updateBuffer(2, 0, StaticMeshVertexData::getInstance()->getIndexBuffer()); desc->writeChanges(); Gfx::ORenderCommand command = graphics->createRenderCommand("RayTracing"); diff --git a/src/Engine/Graphics/RenderPass/RenderPass.cpp b/src/Engine/Graphics/RenderPass/RenderPass.cpp index eb94b96..6b359ec 100644 --- a/src/Engine/Graphics/RenderPass/RenderPass.cpp +++ b/src/Engine/Graphics/RenderPass/RenderPass.cpp @@ -41,7 +41,7 @@ void RenderPass::beginFrame(const Component::Camera& cam) { Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT); viewParamsLayout->reset(); viewParamsSet = viewParamsLayout->allocateDescriptorSet(); - viewParamsSet->updateBuffer(0, viewParamsBuffer); + viewParamsSet->updateBuffer(0, 0, viewParamsBuffer); viewParamsSet->writeChanges(); } diff --git a/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp b/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp index dab8ccb..cf9ac2e 100644 --- a/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp +++ b/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp @@ -86,9 +86,9 @@ void TerrainRenderer::beginFrame() { Gfx::SE_PIPELINE_STAGE_TASK_SHADER_BIT_EXT); set = layout->allocateDescriptorSet(); - set->updateBuffer(0, tilesBuffer); - set->updateTexture(1, Gfx::PTexture2D(displacementMap)); - set->updateSampler(2, sampler); + set->updateBuffer(0, 0, tilesBuffer); + set->updateTexture(1, 0, Gfx::PTexture2D(displacementMap)); + set->updateSampler(2, 0, sampler); set->writeChanges(); } diff --git a/src/Engine/Graphics/RenderPass/TextPass.cpp b/src/Engine/Graphics/RenderPass/TextPass.cpp index d6c48f1..f09f5d7 100644 --- a/src/Engine/Graphics/RenderPass/TextPass.cpp +++ b/src/Engine/Graphics/RenderPass/TextPass.cpp @@ -54,7 +54,7 @@ void TextPass::beginFrame(const Component::Camera& cam) { } auto proj = viewport->getProjectionMatrix(); projectionBuffer->updateContents(0, sizeof(Matrix4), &proj); - generalSet->updateBuffer(1, projectionBuffer); + generalSet->updateBuffer(1, 0, projectionBuffer); generalSet->writeChanges(); // co_return; } @@ -139,8 +139,8 @@ void TextPass::createRenderPass() { }); generalSet = generalLayout->allocateDescriptorSet(); - generalSet->updateBuffer(0, projectionBuffer); - generalSet->updateSampler(1, glyphSampler); + generalSet->updateBuffer(0, 0, projectionBuffer); + generalSet->updateSampler(1, 0, glyphSampler); generalSet->writeChanges(); pipelineLayout = graphics->createPipelineLayout(); @@ -194,7 +194,9 @@ TextPass::FontData& TextPass::getFontData(PFontAsset font) { textureArrayLayout->reset(); fd.textureArraySet = textureArrayLayout->allocateDescriptorSet(); - fd.textureArraySet->updateTextureArray(0, textures); + for (uint32 i = 0; i < textures.size(); ++i) { + fd.textureArraySet->updateTexture(0, i, textures[i]); + } fd.textureArraySet->writeChanges(); return fontData[font]; } diff --git a/src/Engine/Graphics/RenderPass/UIPass.cpp b/src/Engine/Graphics/RenderPass/UIPass.cpp index 59602ab..9eef0f5 100644 --- a/src/Engine/Graphics/RenderPass/UIPass.cpp +++ b/src/Engine/Graphics/RenderPass/UIPass.cpp @@ -14,15 +14,21 @@ UIPass::~UIPass() {} void UIPass::beginFrame(const Component::Camera& cam) { RenderPass::beginFrame(cam); VertexBufferCreateInfo info = { - .sourceData = {.size = (uint32)(sizeof(UI::RenderElementStyle) * renderElements.size()), .data = (uint8*)renderElements.data()}, + .sourceData = + { + .size = (uint32)(sizeof(UI::RenderElementStyle) * renderElements.size()), + .data = (uint8*)renderElements.data(), + }, .vertexSize = sizeof(UI::RenderElementStyle), .numVertices = (uint32)renderElements.size(), }; elementBuffer = graphics->createVertexBuffer(info); uint32 numTextures = static_cast(usedTextures.size()); numTexturesBuffer->updateContents(0, sizeof(uint32), &numTextures); - descriptorSet->updateBuffer(2, numTexturesBuffer); - descriptorSet->updateTextureArray(3, usedTextures); + descriptorSet->updateBuffer(2, 0, numTexturesBuffer); + for (uint32 i = 0; i < usedTextures.size(); ++i) { + descriptorSet->updateTexture(3, i, usedTextures[i]); + } descriptorSet->writeChanges(); // co_return; } @@ -131,8 +137,8 @@ void UIPass::createRenderPass() { numTexturesBuffer = graphics->createUniformBuffer(info); descriptorSet = descriptorLayout->allocateDescriptorSet(); - descriptorSet->updateBuffer(0, uniformBuffer); - descriptorSet->updateSampler(1, backgroundSampler); + descriptorSet->updateBuffer(0, 0, uniformBuffer); + descriptorSet->updateSampler(1, 0, backgroundSampler); descriptorSet->writeChanges(); pipelineLayout = graphics->createPipelineLayout(); diff --git a/src/Engine/Graphics/RenderPass/VisibilityPass.cpp b/src/Engine/Graphics/RenderPass/VisibilityPass.cpp index 278f907..e30ff9e 100644 --- a/src/Engine/Graphics/RenderPass/VisibilityPass.cpp +++ b/src/Engine/Graphics/RenderPass/VisibilityPass.cpp @@ -21,8 +21,8 @@ void VisibilityPass::render() { Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); visibilityDescriptor->reset(); visibilitySet = visibilityDescriptor->allocateDescriptorSet(); - visibilitySet->updateTexture(0, visibilityAttachment.getTexture()); - visibilitySet->updateBuffer(1, cullingBuffer); + visibilitySet->updateTexture(0, 0, visibilityAttachment.getTexture()); + visibilitySet->updateBuffer(1, 0, cullingBuffer); visibilitySet->writeChanges(); query->beginQuery(); diff --git a/src/Engine/Graphics/RenderPass/WaterRenderer.cpp b/src/Engine/Graphics/RenderPass/WaterRenderer.cpp index ac0c41f..114669b 100644 --- a/src/Engine/Graphics/RenderPass/WaterRenderer.cpp +++ b/src/Engine/Graphics/RenderPass/WaterRenderer.cpp @@ -532,14 +532,14 @@ void WaterRenderer::updateFFTDescriptor() { Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); computeSet = computeLayout->allocateDescriptorSet(); - computeSet->updateBuffer(0, paramsBuffer); - computeSet->updateTexture(1, Gfx::PTexture2D(spectrumTextures)); - computeSet->updateTexture(2, Gfx::PTexture2D(initialSpectrumTextures)); - computeSet->updateTexture(3, Gfx::PTexture2D(displacementTextures)); - computeSet->updateTexture(4, Gfx::PTexture2D(slopeTextures)); - computeSet->updateTexture(5, Gfx::PTexture2D(boyancyData)); - computeSet->updateBuffer(6, spectrumBuffer); - computeSet->updateSampler(7, linearRepeatSampler); + computeSet->updateBuffer(0, 0, paramsBuffer); + computeSet->updateTexture(1, 0, spectrumTextures); + computeSet->updateTexture(2, 0, initialSpectrumTextures); + computeSet->updateTexture(3, 0, displacementTextures); + computeSet->updateTexture(4, 0, slopeTextures); + computeSet->updateTexture(5, 0, boyancyData); + computeSet->updateBuffer(6, 0, spectrumBuffer); + computeSet->updateSampler(7, 0, linearRepeatSampler); computeSet->writeChanges(); } @@ -549,11 +549,11 @@ void WaterRenderer::updateMaterialDescriptor() { Gfx::SE_ACCESS_UNIFORM_READ_BIT, Gfx::SE_PIPELINE_STAGE_MESH_SHADER_BIT_EXT | Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); materialSet = materialLayout->allocateDescriptorSet(); - materialSet->updateBuffer(0, materialUniforms); - materialSet->updateTexture(1, Gfx::PTexture2D(displacementTextures)); - materialSet->updateTexture(2, Gfx::PTexture2D(slopeTextures)); - materialSet->updateTexture(3, Gfx::PTextureCube(skyBox)); - materialSet->updateSampler(4, linearRepeatSampler); - materialSet->updateBuffer(5, waterTiles); + materialSet->updateBuffer(0, 0, materialUniforms); + materialSet->updateTexture(1, 0, displacementTextures); + materialSet->updateTexture(2, 0, slopeTextures); + materialSet->updateTexture(3, 0, skyBox); + materialSet->updateSampler(4, 0, linearRepeatSampler); + materialSet->updateBuffer(5, 0, waterTiles); materialSet->writeChanges(); } diff --git a/src/Engine/Graphics/StaticMeshVertexData.cpp b/src/Engine/Graphics/StaticMeshVertexData.cpp index 4d4703e..9734295 100644 --- a/src/Engine/Graphics/StaticMeshVertexData.cpp +++ b/src/Engine/Graphics/StaticMeshVertexData.cpp @@ -134,13 +134,11 @@ void StaticMeshVertexData::init(Gfx::PGraphics _graphics) { descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); - for(uint32 i = 0; i < MAX_TEXCOORDS; ++i) - { - descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ - .binding = 5 + i, - .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, - }); - } + descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ + .binding = 5, + .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, + .descriptorCount = MAX_TEXCOORDS, + }); descriptorLayout->create(); descriptorSet = descriptorLayout->allocateDescriptorSet(); } @@ -220,13 +218,13 @@ void StaticMeshVertexData::updateBuffers() { colData.clear(); descriptorLayout->reset(); descriptorSet = descriptorLayout->allocateDescriptorSet(); - descriptorSet->updateBuffer(0, positions); - descriptorSet->updateBuffer(1, normals); - descriptorSet->updateBuffer(2, tangents); - descriptorSet->updateBuffer(3, biTangents); - descriptorSet->updateBuffer(4, colors); + descriptorSet->updateBuffer(0, 0, positions); + descriptorSet->updateBuffer(1, 0, normals); + descriptorSet->updateBuffer(2, 0, tangents); + descriptorSet->updateBuffer(3, 0, biTangents); + descriptorSet->updateBuffer(4, 0, colors); for (size_t i = 0; i < MAX_TEXCOORDS; ++i) { - descriptorSet->updateBuffer(5 + i, texCoords[i]); + descriptorSet->updateBuffer(5, i, texCoords[i]); } descriptorSet->writeChanges(); } diff --git a/src/Engine/Graphics/VertexData.cpp b/src/Engine/Graphics/VertexData.cpp index 8e0b254..a77a085 100644 --- a/src/Engine/Graphics/VertexData.cpp +++ b/src/Engine/Graphics/VertexData.cpp @@ -165,12 +165,12 @@ void VertexData::createDescriptors() { instanceDataLayout->reset(); descriptorSet = instanceDataLayout->allocateDescriptorSet(); - descriptorSet->updateBuffer(0, instanceBuffer); - descriptorSet->updateBuffer(1, instanceMeshDataBuffer); - descriptorSet->updateBuffer(2, meshletBuffer); - descriptorSet->updateBuffer(3, primitiveIndicesBuffer); - descriptorSet->updateBuffer(4, vertexIndicesBuffer); - descriptorSet->updateBuffer(5, cullingOffsetBuffer); + descriptorSet->updateBuffer(0, 0, instanceBuffer); + descriptorSet->updateBuffer(1, 0, instanceMeshDataBuffer); + descriptorSet->updateBuffer(2, 0, meshletBuffer); + descriptorSet->updateBuffer(3, 0, primitiveIndicesBuffer); + descriptorSet->updateBuffer(4, 0, vertexIndicesBuffer); + descriptorSet->updateBuffer(5, 0, cullingOffsetBuffer); Material::updateDescriptor(); } diff --git a/src/Engine/Graphics/Vulkan/Command.cpp b/src/Engine/Graphics/Vulkan/Command.cpp index bfd9d2b..730820f 100644 --- a/src/Engine/Graphics/Vulkan/Command.cpp +++ b/src/Engine/Graphics/Vulkan/Command.cpp @@ -248,18 +248,23 @@ void RenderCommand::bindPipeline(Gfx::PRayTracingPipeline gfxPipeline) { boundResources.add(PBufferAllocation(rtPipeline->miss)); } -void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) { +void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) { assert(threadId == std::this_thread::get_id()); - auto descriptor = descriptorSet.cast(); - assert(descriptor->writeDescriptors.size() == 0); - descriptor->bind(); - boundResources.add(descriptor); - for (auto binding : descriptor->boundResources) { - binding->bind(); - boundResources.add(binding); + auto descriptorSet = descriptor.cast(); + assert(descriptorSet->writeDescriptors.size() == 0); + descriptorSet->bind(); + boundResources.add(descriptorSet); + for (auto& binding : descriptorSet->boundResources) { + for (auto& res : binding) { + // partially bound descriptors can include nulls + if (res != nullptr) { + res->bind(); + boundResources.add(res); + } + } } - VkDescriptorSet setHandle = descriptor->getHandle(); + VkDescriptorSet setHandle = descriptorSet->getHandle(); Gfx::PPipelineLayout layout = pipeline != nullptr ? pipeline->getPipelineLayout() : rtPipeline->getPipelineLayout(); vkCmdBindDescriptorSets(handle, pipeline != nullptr ? VK_PIPELINE_BIND_POINT_GRAPHICS : VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, pipeline->getLayout(), layout->findParameter(descriptorSet->getName()), 1, &setHandle, 0, @@ -277,11 +282,13 @@ void RenderCommand::bindDescriptor(const Array& descriptorS descriptorSet->bind(); boundResources.add(descriptorSet); - for (auto binding : descriptorSet->boundResources) { + for (auto& binding : descriptorSet->boundResources) { + for (auto& res : binding) { // partially bound descriptors can include nulls - if (binding != nullptr) { - binding->bind(); - boundResources.add(binding); + if (res != nullptr) { + res->bind(); + boundResources.add(res); + } } } sets[layout->findParameter(descriptorSet->getName())] = descriptorSet->getHandle(); @@ -407,20 +414,24 @@ void ComputeCommand::bindPipeline(Gfx::PComputePipeline computePipeline) { pipeline->bind(handle); } -void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) { +void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) { assert(threadId == std::this_thread::get_id()); - auto descriptor = descriptorSet.cast(); - assert(descriptor->writeDescriptors.size() == 0); - descriptor->bind(); - boundResources.add(descriptor.getHandle()); + auto descriptorSet = descriptor.cast(); + assert(descriptorSet->writeDescriptors.size() == 0); + descriptorSet->bind(); + boundResources.add(descriptorSet.getHandle()); - for (auto& binding : descriptor->boundResources) { - binding->bind(); - boundResources.add(binding); - + for (auto& binding : descriptorSet->boundResources) { + for (auto& res : binding) { + // partially bound descriptors can include nulls + if (res != nullptr) { + res->bind(); + boundResources.add(res); + } + } } - VkDescriptorSet setHandle = descriptor->getHandle(); + VkDescriptorSet setHandle = descriptorSet->getHandle(); vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), pipeline->getPipelineLayout()->findParameter(descriptorSet->getName()), 1, &setHandle,0, nullptr); @@ -434,12 +445,14 @@ void ComputeCommand::bindDescriptor(const Array& descriptor assert(descriptorSet->writeDescriptors.size() == 0); descriptorSet->bind(); boundResources.add(descriptorSet.getHandle()); - - // std::cout << "Binding descriptor " << descriptorSet->getHandle() << " to cmd " << handle << std::endl; - - for (auto binding : descriptorSet->boundResources) { - binding->bind(); - boundResources.add(binding); + for (auto& binding : descriptorSet->boundResources) { + for (auto& res : binding) { + // partially bound descriptors can include nulls + if (res != nullptr) { + res->bind(); + boundResources.add(res); + } + } } sets[pipeline->getPipelineLayout()->findParameter(descriptorSet->getName())] = descriptorSet->getHandle(); } diff --git a/src/Engine/Graphics/Vulkan/Descriptor.cpp b/src/Engine/Graphics/Vulkan/Descriptor.cpp index 11ff074..4728f04 100644 --- a/src/Engine/Graphics/Vulkan/Descriptor.cpp +++ b/src/Engine/Graphics/Vulkan/Descriptor.cpp @@ -163,15 +163,15 @@ DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner) graphics(graphics), owner(owner) { boundResources.resize(owner->getLayout()->getBindings().size()); for (uint32 i = 0; i < boundResources.size(); ++i) { - if(owner->getLayout()->getBindings()[i].descriptorCount > 1) std::abort(); + boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount); } } DescriptorSet::~DescriptorSet() {} -void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) { +void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PUniformBuffer uniformBuffer) { PUniformBuffer vulkanBuffer = uniformBuffer.cast(); - if (boundResources[binding] == vulkanBuffer->getAlloc()) { + if (boundResources[binding][index] == vulkanBuffer->getAlloc()) { return; } @@ -186,18 +186,18 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBu .pNext = nullptr, .dstSet = setHandle, .dstBinding = binding, - .dstArrayElement = 0, + .dstArrayElement = index, .descriptorCount = 1, .descriptorType = cast(layout->getBindings()[binding].descriptorType), .pBufferInfo = &bufferInfos.back(), }); - boundResources[binding] = vulkanBuffer->getAlloc(); + boundResources[binding][index] = vulkanBuffer->getAlloc(); } -void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuffer) { +void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) { PShaderBuffer vulkanBuffer = shaderBuffer.cast(); - if (boundResources[binding] == vulkanBuffer->getAlloc()) { + if (boundResources[binding][index] == vulkanBuffer->getAlloc()) { return; } @@ -211,18 +211,18 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuff .pNext = nullptr, .dstSet = setHandle, .dstBinding = binding, - .dstArrayElement = 0, + .dstArrayElement = index, .descriptorCount = 1, .descriptorType = cast(layout->getBindings()[binding].descriptorType), .pBufferInfo = &bufferInfos.back(), }); - boundResources[binding] = vulkanBuffer->getAlloc(); + boundResources[binding][index] = vulkanBuffer->getAlloc(); } -void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PIndexBuffer indexBuffer) { +void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PIndexBuffer indexBuffer) { PIndexBuffer vulkanBuffer = indexBuffer.cast(); - if (boundResources[binding] == vulkanBuffer->getAlloc()) { + if (boundResources[binding][index] == vulkanBuffer->getAlloc()) { return; } @@ -236,18 +236,18 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PIndexBuffer indexBuffer .pNext = nullptr, .dstSet = setHandle, .dstBinding = binding, - .dstArrayElement = 0, + .dstArrayElement = index, .descriptorCount = 1, .descriptorType = cast(layout->getBindings()[binding].descriptorType), .pBufferInfo = &bufferInfos.back(), }); - boundResources[binding] = vulkanBuffer->getAlloc(); + boundResources[binding][index] = vulkanBuffer->getAlloc(); } -void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) { +void DescriptorSet::updateSampler(uint32_t binding, uint32 index, Gfx::PSampler samplerState) { PSampler vulkanSampler = samplerState.cast(); - if (boundResources[binding] == vulkanSampler->getHandle()) { + if (boundResources[binding][index] == vulkanSampler->getHandle()) { return; } @@ -262,24 +262,24 @@ void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) .pNext = nullptr, .dstSet = setHandle, .dstBinding = binding, - .dstArrayElement = 0, + .dstArrayElement = index, .descriptorCount = 1, .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER, .pImageInfo = &imageInfos.back(), }); - boundResources[binding] = vulkanSampler->getHandle(); + boundResources[binding][index] = vulkanSampler->getHandle(); } -void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) { +void DescriptorSet::updateTexture(uint32_t binding, uint32 index, Gfx::PTexture2D texture) { TextureBase* vulkanTexture = texture.cast().getHandle(); - if (boundResources[binding] == vulkanTexture->getHandle()) { + if (boundResources[binding][index] == vulkanTexture->getHandle()) { return; } // It is assumed that the image is in the correct layout imageInfos.add(VkDescriptorImageInfo{ - .sampler = samplerState != nullptr ? samplerState.cast()->getSampler() : VK_NULL_HANDLE, + .sampler = VK_NULL_HANDLE, .imageView = vulkanTexture->getView(), .imageLayout = cast(vulkanTexture->getLayout()), }); @@ -288,73 +288,68 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx:: .pNext = nullptr, .dstSet = setHandle, .dstBinding = binding, - .dstArrayElement = 0, + .dstArrayElement = index, .descriptorCount = 1, .descriptorType = cast(layout->getBindings()[binding].descriptorType), .pImageInfo = &imageInfos.back(), }); - boundResources[binding] = vulkanTexture->getHandle(); + boundResources[binding][index] = vulkanTexture->getHandle(); } -void DescriptorSet::updateTextureArray(uint32_t binding, Array textures) { - // maybe make this a parameter? - uint32 arrayElement = 0; - for (auto& gfxTexture : textures) { - TextureBase* vulkanTexture = gfxTexture.cast().getHandle(); - if (boundResources[binding+arrayElement] == vulkanTexture->getHandle()) { - continue; - } - imageInfos.add(VkDescriptorImageInfo{ - .sampler = VK_NULL_HANDLE, - .imageView = vulkanTexture->getView(), - .imageLayout = cast(vulkanTexture->getLayout()), - }); - - boundResources[binding+arrayElement] = vulkanTexture->getHandle(); - writeDescriptors.add(VkWriteDescriptorSet{ - .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, - .pNext = nullptr, - .dstSet = setHandle, - .dstBinding = binding, - .dstArrayElement = arrayElement++, - .descriptorCount = 1, - .descriptorType = cast(layout->getBindings()[binding].descriptorType), - .pImageInfo = &imageInfos.back(), - }); +void DescriptorSet::updateTexture(uint32_t binding, uint32 index, Gfx::PTexture3D texture) { + TextureBase* vulkanTexture = texture.cast().getHandle(); + if (boundResources[binding][index] == vulkanTexture->getHandle()) { + return; } + + // It is assumed that the image is in the correct layout + imageInfos.add(VkDescriptorImageInfo{ + .sampler = VK_NULL_HANDLE, + .imageView = vulkanTexture->getView(), + .imageLayout = cast(vulkanTexture->getLayout()), + }); + writeDescriptors.add(VkWriteDescriptorSet{ + .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, + .pNext = nullptr, + .dstSet = setHandle, + .dstBinding = binding, + .dstArrayElement = index, + .descriptorCount = 1, + .descriptorType = cast(layout->getBindings()[binding].descriptorType), + .pImageInfo = &imageInfos.back(), + }); + + boundResources[binding][index] = vulkanTexture->getHandle(); } -void DescriptorSet::updateSamplerArray(uint32_t binding, Array samplers) { - // maybe make this a parameter? - uint32 arrayElement = 0; - for (auto& gfxSampler : samplers) { - PSampler vulkanSampler = gfxSampler.cast(); - if (boundResources[binding+arrayElement] == vulkanSampler->getHandle()) { - continue; - } - imageInfos.add(VkDescriptorImageInfo{ - .sampler = vulkanSampler->getHandle()->sampler, - .imageView = VK_NULL_HANDLE, - .imageLayout = VK_IMAGE_LAYOUT_UNDEFINED, - }); - - VkDescriptorType descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; - boundResources[binding] = vulkanSampler->getHandle(); - writeDescriptors.add(VkWriteDescriptorSet{ - .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, - .pNext = nullptr, - .dstSet = setHandle, - .dstBinding = binding, - .dstArrayElement = arrayElement++, - .descriptorCount = 1, - .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER, - .pImageInfo = &imageInfos.back(), - }); +void DescriptorSet::updateTexture(uint32_t binding, uint32 index, Gfx::PTextureCube texture) { + TextureBase* vulkanTexture = texture.cast().getHandle(); + if (boundResources[binding][index] == vulkanTexture->getHandle()) { + return; } + + // It is assumed that the image is in the correct layout + imageInfos.add(VkDescriptorImageInfo{ + .sampler = VK_NULL_HANDLE, + .imageView = vulkanTexture->getView(), + .imageLayout = cast(vulkanTexture->getLayout()), + }); + writeDescriptors.add(VkWriteDescriptorSet{ + .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, + .pNext = nullptr, + .dstSet = setHandle, + .dstBinding = binding, + .dstArrayElement = index, + .descriptorCount = 1, + .descriptorType = cast(layout->getBindings()[binding].descriptorType), + .pImageInfo = &imageInfos.back(), + }); + + boundResources[binding][index] = vulkanTexture->getHandle(); } -void DescriptorSet::updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) { +void DescriptorSet::updateAccelerationStructure(uint32 binding, uint32 index, Gfx::PTopLevelAS as) { auto tlas = as.cast(); accelerationInfos.add(VkWriteDescriptorSetAccelerationStructureKHR{ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR, @@ -367,7 +362,7 @@ void DescriptorSet::updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS .pNext = &accelerationInfos.back(), .dstSet = setHandle, .dstBinding = binding, - .dstArrayElement = 0, + .dstArrayElement = index, .descriptorCount = 1, .descriptorType = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, }); diff --git a/src/Engine/Graphics/Vulkan/Descriptor.h b/src/Engine/Graphics/Vulkan/Descriptor.h index 14833d9..07cb314 100644 --- a/src/Engine/Graphics/Vulkan/Descriptor.h +++ b/src/Engine/Graphics/Vulkan/Descriptor.h @@ -48,14 +48,14 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource { DescriptorSet(PGraphics graphics, PDescriptorPool owner); virtual ~DescriptorSet(); virtual void writeChanges() override; - virtual void updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) override; - virtual void updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) override; - virtual void updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) override; - virtual void updateSampler(uint32 binding, Gfx::PSampler samplerState) override; - virtual void updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr) override; - virtual void updateTextureArray(uint32 binding, Array texture) override; - virtual void updateSamplerArray(uint32 binding, Array samplers) override; - virtual void updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) override; + virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PUniformBuffer uniformBuffer) override; + virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) override; + virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PIndexBuffer indexBuffer) override; + virtual void updateSampler(uint32 binding, uint32 index, Gfx::PSampler samplerState) override; + virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTexture2D texture) override; + virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTexture3D texture) override; + virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTextureCube texture) override; + virtual void updateAccelerationStructure(uint32 binding, uint32 index, Gfx::PTopLevelAS as) override; constexpr VkDescriptorSet getHandle() const { return setHandle; } @@ -68,7 +68,7 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource { // since the layout is fixed, trying to bind a texture to a buffer // would not work anyways, so casts should be safe // Array cachedData; - Array boundResources; + Array> boundResources; VkDescriptorSet setHandle; PGraphics graphics; PDescriptorPool owner; diff --git a/src/Engine/Graphics/Vulkan/Graphics.cpp b/src/Engine/Graphics/Vulkan/Graphics.cpp index d4550e5..a34e9ed 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.cpp +++ b/src/Engine/Graphics/Vulkan/Graphics.cpp @@ -114,9 +114,6 @@ Graphics::~Graphics() { void Graphics::init(GraphicsInitializer initInfo) { initInstance(initInfo); -#if ENABLE_VALIDATION - setupDebugCallback(); -#endif pickPhysicalDevice(); createDevice(initInfo); VmaAllocatorCreateInfo createInfo = { @@ -754,6 +751,7 @@ void Graphics::pickPhysicalDevice() { .storageBuffer8BitAccess = true, .uniformAndStorageBuffer8BitAccess = true, .shaderFloat16 = true, + .shaderInt8 = true, .shaderUniformBufferArrayNonUniformIndexing = true, .shaderSampledImageArrayNonUniformIndexing = true, .shaderStorageBufferArrayNonUniformIndexing = true, diff --git a/src/Engine/Graphics/slang-compile.cpp b/src/Engine/Graphics/slang-compile.cpp index e7a5af7..54f7620 100644 --- a/src/Engine/Graphics/slang-compile.cpp +++ b/src/Engine/Graphics/slang-compile.cpp @@ -42,7 +42,7 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg option[1].value.intValue0 = 1; option[2].name = slang::CompilerOptionName::DebugInformation; option[2].value.kind = slang::CompilerOptionValueKind::Int; - option[2].value.intValue0 = SLANG_DEBUG_INFO_LEVEL_NONE; + option[2].value.intValue0 = SLANG_DEBUG_INFO_LEVEL_STANDARD; option[3].name = slang::CompilerOptionName::DebugInformationFormat; option[3].value.kind = slang::CompilerOptionValueKind::Int; option[3].value.intValue0 = SLANG_DEBUG_INFO_FORMAT_PDB; @@ -116,7 +116,7 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg for (size_t i = 0; i < signature->getParameterCount(); ++i) { auto param = signature->getParameterByIndex(i); layout->addMapping(param->getName(), param->getBindingIndex()); - std::cout << param->getName() << ": " << param->getBindingIndex() << std::endl; + //std::cout << param->getName() << ": " << param->getBindingIndex() << std::endl; } // workaround diff --git a/src/Engine/Material/Material.cpp b/src/Engine/Material/Material.cpp index c1b753d..d4cbf5c 100644 --- a/src/Engine/Material/Material.cpp +++ b/src/Engine/Material/Material.cpp @@ -34,28 +34,28 @@ Material::Material(Gfx::PGraphics graphics, uint32 numTextures, uint32 numSample Material::~Material() {} void Material::init(Gfx::PGraphics graphics) { - layout = graphics->createDescriptorLayout("pMaterial"); + layout = graphics->createDescriptorLayout("pResources"); layout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 0, - .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, - .descriptorCount = 1, - .bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT, - .shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT | Gfx::SE_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, - }); - layout->addDescriptorBinding(Gfx::DescriptorBinding{ - .binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, .descriptorCount = 512, .bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT, .shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT | Gfx::SE_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, }); layout->addDescriptorBinding(Gfx::DescriptorBinding{ - .binding = 2, + .binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER, .descriptorCount = 512, .bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT, .shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT | Gfx::SE_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, }); + layout->addDescriptorBinding(Gfx::DescriptorBinding{ + .binding = 2, + .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, + .descriptorCount = 1, + .bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT, + .shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT | Gfx::SE_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, + }); layout->create(); floatBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ .dynamic = true, @@ -76,18 +76,17 @@ void Material::updateDescriptor() { Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); layout->reset(); set = layout->allocateDescriptorSet(); - uint32 binding = 0; - set->updateBuffer(binding++, floatBuffer); for (uint32 i = 0; i < textures.size(); ++i) { if (textures[i] != nullptr) { - set->updateTexture(binding++, textures[i]); + set->updateTexture(0, i, textures[i]); } } for (uint32 i = 0; i < samplers.size(); ++i) { if (samplers[i] != nullptr) { - set->updateSampler(binding++, samplers[i]); + set->updateSampler(1, i, samplers[i]); } } + set->updateBuffer(2, 0, floatBuffer); set->writeChanges(); } diff --git a/src/Engine/Scene/LightEnvironment.cpp b/src/Engine/Scene/LightEnvironment.cpp index 21f75fe..35ab6b5 100644 --- a/src/Engine/Scene/LightEnvironment.cpp +++ b/src/Engine/Scene/LightEnvironment.cpp @@ -62,9 +62,9 @@ void LightEnvironment::commit() { Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR | Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT); - set->updateBuffer(0, lightEnvBuffer); - set->updateBuffer(1, directionalLights); - set->updateBuffer(2, pointLights); + set->updateBuffer(0, 0, lightEnvBuffer); + set->updateBuffer(1, 0, directionalLights); + set->updateBuffer(2, 0, pointLights); set->writeChanges(); } diff --git a/src/Engine/Window/GameView.cpp b/src/Engine/Window/GameView.cpp index ab3d983..96539cd 100644 --- a/src/Engine/Window/GameView.cpp +++ b/src/Engine/Window/GameView.cpp @@ -28,7 +28,9 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate renderGraph.addPass(new VisibilityPass(graphics, scene)); renderGraph.addPass(new LightCullingPass(graphics, scene)); renderGraph.addPass(new BasePass(graphics, scene)); - renderGraph.addPass(new RayTracingPass(graphics, scene)); + + //renderGraph.addPass(new RayTracingPass(graphics, scene)); + renderGraph.setViewport(viewport); renderGraph.createRenderPass(); }