From daad5cfd29c74a8858e86f8eb0de4ca1f35d7801 Mon Sep 17 00:00:00 2001 From: Mara Vogt <mvogt@uni-koblenz.de> Date: Fri, 17 Sep 2021 17:52:27 +0200 Subject: [PATCH] [#92] changed DescriptorSets to just one, now the cube is gone --- modules/rtx/include/vkcv/rtx/RTX.hpp | 4 +- modules/rtx/src/vkcv/rtx/RTX.cpp | 16 +++++--- projects/rtx/resources/shaders/raytrace.rchit | 12 +++--- projects/rtx/resources/shaders/raytrace.rgen | 4 +- projects/rtx/resources/shaders/raytrace.rmiss | 2 +- projects/rtx/src/main.cpp | 38 +++++++++---------- 6 files changed, 40 insertions(+), 36 deletions(-) diff --git a/modules/rtx/include/vkcv/rtx/RTX.hpp b/modules/rtx/include/vkcv/rtx/RTX.hpp index 60906978..78b11853 100644 --- a/modules/rtx/include/vkcv/rtx/RTX.hpp +++ b/modules/rtx/include/vkcv/rtx/RTX.hpp @@ -74,7 +74,9 @@ namespace vkcv::rtx { * @param rayClostestHitShader The ray closest hit shader. * @return The Vulkan handle of the RTX pipeline. */ - void createRTXPipeline(uint32_t pushConstantSize, std::vector<DescriptorSetLayoutHandle> descriptorSetLayouts, ShaderProgram &rayGenShader, ShaderProgram &rayMissShader, ShaderProgram &rayClosestHitShader); + //void createRTXPipeline(uint32_t pushConstantSize, std::vector<DescriptorSetLayoutHandle> descriptorSetLayouts, ShaderProgram &rayGenShader, ShaderProgram &rayMissShader, ShaderProgram &rayClosestHitShader); + + void createRTXPipeline(uint32_t pushConstantSize, std::vector<DescriptorSetLayoutHandle> descriptorSetLayouts, ShaderProgram &rtxShader); }; } diff --git a/modules/rtx/src/vkcv/rtx/RTX.cpp b/modules/rtx/src/vkcv/rtx/RTX.cpp index aea7a62a..439f71be 100644 --- a/modules/rtx/src/vkcv/rtx/RTX.cpp +++ b/modules/rtx/src/vkcv/rtx/RTX.cpp @@ -78,10 +78,14 @@ namespace vkcv::rtx { tlasWrite.setDescriptorCount(1); tlasWrite.setDescriptorType(vk::DescriptorType::eAccelerationStructureKHR); m_core->getContext().getDevice().updateDescriptorSets(tlasWrite, nullptr); + tlasWrite.setDstBinding(2); + m_core->getContext().getDevice().updateDescriptorSets(tlasWrite, nullptr); + /* tlasWrite.setDstSet(m_core->getDescriptorSet(descriptorSetHandles[1]).vulkanHandle); m_core->getContext().getDevice().updateDescriptorSets(tlasWrite, nullptr); tlasWrite.setDstSet(m_core->getDescriptorSet(descriptorSetHandles[2]).vulkanHandle); m_core->getContext().getDevice().updateDescriptorSets(tlasWrite, nullptr); + */ //INDEX & VERTEX BUFFER BottomLevelAccelerationStructure blas = m_asManager->getBLAS(0);//HARD CODED @@ -93,7 +97,7 @@ namespace vkcv::rtx { vertexInfo.setRange(blas.vertexBuffer.deviceSize); //maybe check if size is correct vk::WriteDescriptorSet vertexWrite; - vertexWrite.setDstSet(m_core->getDescriptorSet(descriptorSetHandles[2]).vulkanHandle); + vertexWrite.setDstSet(m_core->getDescriptorSet(descriptorSetHandles[0]).vulkanHandle); vertexWrite.setDstBinding(3); vertexWrite.setDescriptorCount(1); vertexWrite.setDescriptorType(vk::DescriptorType::eStorageBuffer); @@ -107,7 +111,7 @@ namespace vkcv::rtx { indexInfo.setRange(blas.indexBuffer.deviceSize); //maybe check if size is correct vk::WriteDescriptorSet indexWrite; - indexWrite.setDstSet(m_core->getDescriptorSet(descriptorSetHandles[2]).vulkanHandle); + indexWrite.setDstSet(m_core->getDescriptorSet(descriptorSetHandles[0]).vulkanHandle); indexWrite.setDstBinding(4); indexWrite.setDescriptorCount(1); indexWrite.setDescriptorType(vk::DescriptorType::eStorageBuffer); @@ -117,11 +121,11 @@ namespace vkcv::rtx { } - void RTXModule::createRTXPipeline(uint32_t pushConstantSize, std::vector<DescriptorSetLayoutHandle> descriptorSetLayouts, ShaderProgram &rayGenShader, ShaderProgram &rayMissShader, ShaderProgram &rayClosestHitShader) { + void RTXModule::createRTXPipeline(uint32_t pushConstantSize, std::vector<DescriptorSetLayoutHandle> descriptorSetLayouts, ShaderProgram &rtxShader) { // TODO: maybe all of this must be moved to the vkcv::PipelineManager? If we use scene.recordDrawcalls(), this requires a vkcv::PipelineHandle and not a vk::Pipeline // -- process vkcv::ShaderProgram into vk::ShaderModule - std::vector<char> rayGenShaderCode = rayGenShader.getShader(ShaderStage::RAY_GEN).shaderCode; + std::vector<char> rayGenShaderCode = rtxShader.getShader(ShaderStage::RAY_GEN).shaderCode; vk::ShaderModuleCreateInfo rayGenShaderModuleInfo( vk::ShaderModuleCreateFlags(), // vk::ShaderModuleCreateFlags flags_, @@ -133,7 +137,7 @@ namespace vkcv::rtx { vkcv_log(LogLevel::ERROR, "The Ray Generation Shader Module could not be created!"); } - std::vector<char> rayMissShaderCode = rayMissShader.getShader(ShaderStage::RAY_MISS).shaderCode; + std::vector<char> rayMissShaderCode = rtxShader.getShader(ShaderStage::RAY_MISS).shaderCode; vk::ShaderModuleCreateInfo rayMissShaderModuleInfo( vk::ShaderModuleCreateFlags(), // vk::ShaderModuleCreateFlags flags_, rayMissShaderCode.size(), //size_t codeSize @@ -145,7 +149,7 @@ namespace vkcv::rtx { vkcv_log(LogLevel::ERROR, "The Ray Miss Shader Module could not be created!"); } - std::vector<char> rayClosestHitShaderCode = rayClosestHitShader.getShader(ShaderStage::RAY_CLOSEST_HIT).shaderCode; + std::vector<char> rayClosestHitShaderCode = rtxShader.getShader(ShaderStage::RAY_CLOSEST_HIT).shaderCode; vk::ShaderModuleCreateInfo rayClosestHitShaderModuleInfo( vk::ShaderModuleCreateFlags(), // vk::ShaderModuleCreateFlags flags_, rayClosestHitShaderCode.size(), //size_t codeSize diff --git a/projects/rtx/resources/shaders/raytrace.rchit b/projects/rtx/resources/shaders/raytrace.rchit index 28b37856..b6977083 100644 --- a/projects/rtx/resources/shaders/raytrace.rchit +++ b/projects/rtx/resources/shaders/raytrace.rchit @@ -26,10 +26,10 @@ layout(location = 0) rayPayloadInEXT Payload { int rayActive; } payload; -layout(location = 1) rayPayloadEXT bool isShadow; +//layout(location = 1) rayPayloadEXT bool isShadow; + +layout(binding = 2, set = 0) uniform accelerationStructureEXT tlas; // top level acceleration structure (for the noobs here (you!)) -layout(location = 2, binding = 1, set = 0) uniform accelerationStructureEXT tlas; // top level acceleration structure (for the noobs here (you!)) -/* layout( push_constant ) uniform constants { vec4 camera_position; // as origin for ray generation vec4 camera_right; // for computing ray direction @@ -38,7 +38,7 @@ layout( push_constant ) uniform constants { uint frameCount; // what is this? the actual frame? }camera; -*/ + layout(binding = 3, set = 0) buffer rtxVertices { @@ -74,10 +74,10 @@ vec3 alignHemisphereWithCoordinateSystem(vec3 hemisphere, vec3 up) { return hemisphere.x * right + hemisphere.y * up + hemisphere.z * forward; } -void main() {/* +void main() { if (payload.rayActive == 0) { return; - }*/ + } //ivec3 rtindices = ivec3(rtxIndexBuffer.indices[3 * gl_PrimitiveID + 0], rtxIndexBuffer.indices[3 * gl_PrimitiveID + 1], rtxIndexBuffer.indices[3 * gl_PrimitiveID + 2]); /* diff --git a/projects/rtx/resources/shaders/raytrace.rgen b/projects/rtx/resources/shaders/raytrace.rgen index a5824e87..470e59a2 100644 --- a/projects/rtx/resources/shaders/raytrace.rgen +++ b/projects/rtx/resources/shaders/raytrace.rgen @@ -15,7 +15,7 @@ layout(location = 0) rayPayloadEXT Payload { } payload; layout(binding = 0, set = 0, rgba16) uniform image2D outImg; // the output image -> maybe use 16 bit values? -layout(location = 0, binding = 1, set = 0) uniform accelerationStructureEXT tlas; // top level acceleration structure (for the noobs here (you!)) +layout(binding = 1, set = 0) uniform accelerationStructureEXT tlas; // top level acceleration structure (for the noobs here (you!)) layout( push_constant ) uniform constants { vec4 camera_position; // as origin for ray generation @@ -58,6 +58,6 @@ void main(){ color += previousColor; color /= (camera.frameCount + 1); } - //color=vec4(0.0001*camera.frameCount,0,0,1);//DEBUG + color=vec4(0.0001*camera.frameCount,0,0,1);//DEBUG imageStore(outImg, ivec2(gl_LaunchIDEXT.xy), color); } diff --git a/projects/rtx/resources/shaders/raytrace.rmiss b/projects/rtx/resources/shaders/raytrace.rmiss index 53910f86..0f1075dc 100644 --- a/projects/rtx/resources/shaders/raytrace.rmiss +++ b/projects/rtx/resources/shaders/raytrace.rmiss @@ -13,7 +13,7 @@ layout(location = 0) rayPayloadInEXT Payload { int rayActive; } payload; -layout(location = 1, binding = 1, set = 0) uniform accelerationStructureEXT tlas; //not neccesary in shader but for compiling ->bug +//layout(location = 0, binding = 1, set = 0) uniform accelerationStructureEXT tlas; //not neccesary in shader but for compiling ->bug void main() { payload.rayActive = 0; diff --git a/projects/rtx/src/main.cpp b/projects/rtx/src/main.cpp index d3db8dc1..fca90528 100644 --- a/projects/rtx/src/main.cpp +++ b/projects/rtx/src/main.cpp @@ -103,32 +103,33 @@ int main(int argc, const char** argv) { //vkcv::ShaderProgram sceneShaderProgram; vkcv::shader::GLSLCompiler compiler; - vkcv::ShaderProgram rayGenShaderProgram; + vkcv::ShaderProgram rtxShaderProgram; compiler.compile(vkcv::ShaderStage::RAY_GEN, std::filesystem::path("resources/shaders/raytrace.rgen"), - [&rayGenShaderProgram](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) { - rayGenShaderProgram.addShader(shaderStage, path); + [&rtxShaderProgram](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) { + rtxShaderProgram.addShader(shaderStage, path); }); - vkcv::ShaderProgram rayClosestHitShaderProgram; + //vkcv::ShaderProgram rayClosestHitShaderProgram; compiler.compile(vkcv::ShaderStage::RAY_CLOSEST_HIT, std::filesystem::path("resources/shaders/raytrace.rchit"), - [&rayClosestHitShaderProgram](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) { - rayClosestHitShaderProgram.addShader(shaderStage, path); + [&rtxShaderProgram](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) { + rtxShaderProgram.addShader(shaderStage, path); }); - vkcv::ShaderProgram rayMissShaderProgram; + //vkcv::ShaderProgram rayMissShaderProgram; compiler.compile(vkcv::ShaderStage::RAY_MISS, std::filesystem::path("resources/shaders/raytrace.rmiss"), - [&rayMissShaderProgram](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) { - rayMissShaderProgram.addShader(shaderStage, path); + [&rtxShaderProgram](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) { + rtxShaderProgram.addShader(shaderStage, path); }); std::vector<vkcv::DescriptorSetHandle> descriptorSetHandles; std::vector<vkcv::DescriptorSetLayoutHandle> descriptorSetLayoutHandles; - vkcv::DescriptorSetLayoutHandle rayGenShaderDescriptorSetLayout = core.createDescriptorSetLayout(rayGenShaderProgram.getReflectedDescriptors().at(0)); - vkcv::DescriptorSetHandle rayGenShaderDescriptorSet = core.createDescriptorSet(rayGenShaderDescriptorSetLayout);// - descriptorSetHandles.push_back(rayGenShaderDescriptorSet); - descriptorSetLayoutHandles.push_back(rayGenShaderDescriptorSetLayout); + vkcv::DescriptorSetLayoutHandle rtxShaderDescriptorSetLayout = core.createDescriptorSetLayout(rtxShaderProgram.getReflectedDescriptors().at(0)); + vkcv::DescriptorSetHandle rtxShaderDescriptorSet = core.createDescriptorSet(rtxShaderDescriptorSetLayout);// + descriptorSetHandles.push_back(rtxShaderDescriptorSet); + descriptorSetLayoutHandles.push_back(rtxShaderDescriptorSetLayout); + /* vkcv::DescriptorSetLayoutHandle rayMissShaderDescriptorSetLayout = core.createDescriptorSetLayout(rayMissShaderProgram.getReflectedDescriptors().at(0)); vkcv::DescriptorSetHandle rayMissShaderDescriptorSet = core.createDescriptorSet(rayMissShaderDescriptorSetLayout); descriptorSetHandles.push_back(rayMissShaderDescriptorSet); @@ -138,7 +139,7 @@ int main(int argc, const char** argv) { vkcv::DescriptorSetHandle rayCHITShaderDescriptorSet = core.createDescriptorSet(rayClosestHitShaderDescriptorSetLayout); descriptorSetHandles.push_back(rayCHITShaderDescriptorSet); descriptorSetLayoutHandles.push_back(rayClosestHitShaderDescriptorSetLayout); - + */ // init RTXModule @@ -154,7 +155,7 @@ int main(int argc, const char** argv) { uint32_t pushConstantSize = sizeof(RaytracingPushConstantData); - rtxModule.createRTXPipeline(pushConstantSize, descriptorSetLayoutHandles, rayGenShaderProgram, rayMissShaderProgram, rayClosestHitShaderProgram); + rtxModule.createRTXPipeline(pushConstantSize, descriptorSetLayoutHandles, rtxShaderProgram); vk::Pipeline rtxPipeline = rtxModule.getPipeline(); vk::PipelineLayout rtxPipelineLayout = rtxModule.getPipelineLayout(); @@ -222,7 +223,7 @@ int main(int argc, const char** argv) { rtxWrites.storageImageWrites = { vkcv::StorageImageDescriptorWrite(0, swapchainInput) }; - core.writeDescriptorSet(rayGenShaderDescriptorSet, rtxWrites); + core.writeDescriptorSet(rtxShaderDescriptorSet, rtxWrites); core.prepareImageForStorage(cmdStream, swapchainInput); @@ -232,10 +233,7 @@ int main(int argc, const char** argv) { rtxPipelineLayout, rtxModule.getShaderBindingBuffer(), rtxModule.getShaderGroupBaseAlignment(), - { vkcv::DescriptorSetUsage(0, core.getDescriptorSet(rayGenShaderDescriptorSet).vulkanHandle), - vkcv::DescriptorSetUsage(1, core.getDescriptorSet(rayMissShaderDescriptorSet).vulkanHandle), - vkcv::DescriptorSetUsage(2, core.getDescriptorSet(rayCHITShaderDescriptorSet).vulkanHandle) - }, + { vkcv::DescriptorSetUsage(0, core.getDescriptorSet(rtxShaderDescriptorSet).vulkanHandle)}, pushConstantsRTX, windowHandle); -- GitLab