From b3e6d848074291399be3c5e41456ac92924f8657 Mon Sep 17 00:00:00 2001 From: Mathias Heyer Date: Fri, 21 May 2021 16:15:58 -0700 Subject: [PATCH] Bulk update NvPro-Samples 05/21/21 --- CMakeLists.txt | 4 ++ common/obj_loader.cpp | 23 ----------- ray_tracing__advance/hello_vulkan.cpp | 21 +++++----- ray_tracing__advance/main.cpp | 9 ++-- ray_tracing__advance/obj.hpp | 2 +- ray_tracing__advance/offscreen.hpp | 2 +- ray_tracing__advance/raytrace.cpp | 3 +- ray_tracing__advance/raytrace.hpp | 2 +- ray_tracing__before/hello_vulkan.cpp | 31 +++++++------- ray_tracing__before/hello_vulkan.h | 10 ++--- ray_tracing__before/main.cpp | 6 +-- ray_tracing__simple/hello_vulkan.cpp | 26 ++++++------ ray_tracing__simple/hello_vulkan.h | 10 ++--- ray_tracing__simple/main.cpp | 6 +-- ray_tracing_animation/hello_vulkan.cpp | 37 +++++++++-------- ray_tracing_animation/hello_vulkan.h | 13 +++--- ray_tracing_animation/main.cpp | 6 +-- ray_tracing_anyhit/hello_vulkan.cpp | 20 +++++---- ray_tracing_anyhit/hello_vulkan.h | 13 +++--- ray_tracing_anyhit/main.cpp | 6 +-- ray_tracing_ao/hello_vulkan.cpp | 28 +++++++------ ray_tracing_ao/hello_vulkan.h | 9 ++-- ray_tracing_ao/main.cpp | 6 +-- ray_tracing_callable/hello_vulkan.cpp | 25 ++++++----- ray_tracing_callable/hello_vulkan.h | 9 ++-- ray_tracing_callable/main.cpp | 6 +-- ray_tracing_gltf/hello_vulkan.cpp | 14 +++---- ray_tracing_gltf/hello_vulkan.h | 3 +- ray_tracing_gltf/main.cpp | 6 +-- ray_tracing_indirect_scissor/hello_vulkan.cpp | 31 +++++++------- ray_tracing_indirect_scissor/hello_vulkan.h | 9 ++-- ray_tracing_indirect_scissor/main.cpp | 6 +-- ray_tracing_instances/hello_vulkan.cpp | 24 ++++++----- ray_tracing_instances/hello_vulkan.h | 6 +-- ray_tracing_instances/main.cpp | 6 +-- ray_tracing_intersection/hello_vulkan.cpp | 27 ++++++------ ray_tracing_intersection/hello_vulkan.h | 9 ++-- ray_tracing_intersection/main.cpp | 8 ++-- ray_tracing_jitter_cam/hello_vulkan.cpp | 25 ++++++----- ray_tracing_jitter_cam/hello_vulkan.h | 9 ++-- ray_tracing_jitter_cam/main.cpp | 6 +-- ray_tracing_manyhits/hello_vulkan.cpp | 41 ++++++++++--------- ray_tracing_manyhits/hello_vulkan.h | 13 +++--- ray_tracing_manyhits/main.cpp | 6 +-- ray_tracing_rayquery/hello_vulkan.cpp | 20 +++++---- ray_tracing_rayquery/hello_vulkan.h | 9 ++-- ray_tracing_rayquery/main.cpp | 6 +-- ray_tracing_reflections/hello_vulkan.cpp | 39 ++++++++++-------- ray_tracing_reflections/hello_vulkan.h | 13 +++--- ray_tracing_reflections/main.cpp | 6 +-- ray_tracing_specialization/hello_vulkan.cpp | 29 ++++++------- ray_tracing_specialization/hello_vulkan.h | 15 ++++--- ray_tracing_specialization/main.cpp | 6 +-- 53 files changed, 359 insertions(+), 366 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe42ad0..e1c0494 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,10 @@ endif() set(TUTO_KHR_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +if(MSVC) + add_definitions(/wd26812) # 'enum class' over 'enum' + add_definitions(/wd26451) # Arithmetic overflow, casting 4 byte value to 8 byte value +endif() #-------------------------------------------------------------------------------------------------- # Package shared by all projects diff --git a/common/obj_loader.cpp b/common/obj_loader.cpp index 56b8a4d..cf4ae85 100644 --- a/common/obj_loader.cpp +++ b/common/obj_loader.cpp @@ -22,29 +22,6 @@ #include "obj_loader.h" #include "nvh/nvprint.hpp" -//----------------------------------------------------------------------------- -// Extract the directory component from a complete path. -// -#ifdef WIN32 -#define CORRECT_PATH_SEP "\\" -#define WRONG_PATH_SEP '/' -#else -#define CORRECT_PATH_SEP "/" -#define WRONG_PATH_SEP '\\' -#endif - -static inline std::string get_path(const std::string& file) -{ - std::string dir; - size_t idx = file.find_last_of("\\/"); - if(idx != std::string::npos) - dir = file.substr(0, idx); - if(!dir.empty()) - { - dir += CORRECT_PATH_SEP; - } - return dir; -} void ObjLoader::loadModel(const std::string& filename) { diff --git a/ray_tracing__advance/hello_vulkan.cpp b/ray_tracing__advance/hello_vulkan.cpp index a7b1fae..265dbe1 100644 --- a/ray_tracing__advance/hello_vulkan.cpp +++ b/ray_tracing__advance/hello_vulkan.cpp @@ -118,11 +118,11 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); - uint32_t nbObj = static_cast(m_objModel.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; + auto nbTxt = static_cast(m_textures.size()); + auto nbObj = static_cast(m_objModel.size()); // Camera matrices (binding = 0) m_descSetLayoutBind.addBinding( @@ -230,11 +230,12 @@ void HelloVulkan::createGraphicsPipeline() gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), vkSS::eVertex); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addBindingDescription({0, sizeof(VertexObj)}); - gpb.addAttributeDescriptions(std::vector{ - {0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, - {1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, - {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, - {3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); + gpb.addAttributeDescriptions({ + {0, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, pos))}, + {1, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, nrm))}, + {2, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, color))}, + {3, 0, vk::Format::eR32G32Sfloat, static_cast(offsetof(VertexObj, texCoord))}, + }); m_graphicsPipeline = gpb.createPipeline(); m_debug.setObjectName(m_graphicsPipeline, "Graphics"); diff --git a/ray_tracing__advance/main.cpp b/ray_tracing__advance/main.cpp index d9a0ef5..b4a3478 100644 --- a/ray_tracing__advance/main.cpp +++ b/ray_tracing__advance/main.cpp @@ -56,8 +56,7 @@ static void onErrorCallback(int error, const char* description) // Extra UI void renderUI(HelloVulkan& helloVk) { - static int item = 1; - bool changed = false; + bool changed = false; changed |= ImGuiH::CameraWidget(); if(ImGui::CollapsingHeader("Light")) @@ -315,7 +314,7 @@ int main(int argc, char** argv) helloVk.updateUniformBuffer(cmdBuf); // Clearing screen - vk::ClearValue clearValues[2]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); clearValues[1].setDepthStencil({1.0f, 0}); @@ -324,7 +323,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(2); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(offscreen.renderPass()); offscreenRenderPassBeginInfo.setFramebuffer(offscreen.frameBuffer()); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -346,7 +345,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); diff --git a/ray_tracing__advance/obj.hpp b/ray_tracing__advance/obj.hpp index 7a94e8a..555c3b9 100644 --- a/ray_tracing__advance/obj.hpp +++ b/ray_tracing__advance/obj.hpp @@ -75,6 +75,6 @@ struct ImplInst std::vector implMat; // All materials used by implicit obj nvvk::Buffer implBuf; // Buffer of objects nvvk::Buffer implMatBuf; // Buffer of material - int blasId; + int blasId{0}; nvmath::mat4f transform{1}; }; diff --git a/ray_tracing__advance/offscreen.hpp b/ray_tracing__advance/offscreen.hpp index 48c85c7..ef18b25 100644 --- a/ray_tracing__advance/offscreen.hpp +++ b/ray_tracing__advance/offscreen.hpp @@ -62,7 +62,7 @@ private: nvvk::Texture m_colorTexture; vk::Format m_colorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_depthTexture; - vk::Format m_depthFormat; + vk::Format m_depthFormat{vk::Format::eX8D24UnormPack32}; nvvk::ResourceAllocator* m_alloc{ nullptr}; // Allocator for buffer, images, acceleration structures diff --git a/ray_tracing__advance/raytrace.cpp b/ray_tracing__advance/raytrace.cpp index 8f7afc8..492107e 100644 --- a/ray_tracing__advance/raytrace.cpp +++ b/ray_tracing__advance/raytrace.cpp @@ -360,9 +360,8 @@ void Raytracer::createRtPipeline(vk::DescriptorSetLayout& sceneDescLayout) rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setLayout(m_rtPipelineLayout); - m_rtPipeline = static_cast( - m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); + m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value; m_sbtWrapper.create(m_rtPipeline, rayPipelineInfo); diff --git a/ray_tracing__advance/raytrace.hpp b/ray_tracing__advance/raytrace.hpp index f97c489..82a35ac 100644 --- a/ray_tracing__advance/raytrace.hpp +++ b/ray_tracing__advance/raytrace.hpp @@ -72,7 +72,7 @@ private: { nvmath::vec4f clearColor; nvmath::vec3f lightPosition; - float lightIntensity; + float lightIntensity{100.0f}; nvmath::vec3f lightDirection{-1, -1, -1}; float lightSpotCutoff{deg2rad(12.5f)}; float lightSpotOuterCutoff{deg2rad(17.5f)}; diff --git a/ray_tracing__before/hello_vulkan.cpp b/ray_tracing__before/hello_vulkan.cpp index 346685a..731588f 100644 --- a/ray_tracing__before/hello_vulkan.cpp +++ b/ray_tracing__before/hello_vulkan.cpp @@ -108,11 +108,11 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); - uint32_t nbObj = static_cast(m_objModel.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; + auto nbTxt = static_cast(m_textures.size()); + auto nbObj = static_cast(m_objModel.size()); // Camera matrices (binding = 0) m_descSetLayoutBind.addBinding(vkDS(0, vkDT::eUniformBuffer, 1, vkSS::eVertex)); @@ -150,19 +150,19 @@ void HelloVulkan::updateDescriptorSet() // All material buffers, 1 buffer per OBJ std::vector dbiMat; std::vector dbiMatIdx; - for(size_t i = 0; i < m_objModel.size(); ++i) + for(auto &m : m_objModel) { - dbiMat.push_back({m_objModel[i].matColorBuffer.buffer, 0, VK_WHOLE_SIZE}); - dbiMatIdx.push_back({m_objModel[i].matIndexBuffer.buffer, 0, VK_WHOLE_SIZE}); + dbiMat.emplace_back(m.matColorBuffer.buffer, 0, VK_WHOLE_SIZE); + dbiMatIdx.emplace_back(m.matIndexBuffer.buffer, 0, VK_WHOLE_SIZE); } writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, 1, dbiMat.data())); writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, 4, dbiMatIdx.data())); // All texture samplers std::vector diit; - for(size_t i = 0; i < m_textures.size(); ++i) + for(auto& texture : m_textures) { - diit.push_back(m_textures[i].descriptor); + diit.emplace_back(texture.descriptor); } writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, 3, diit.data())); @@ -197,11 +197,12 @@ void HelloVulkan::createGraphicsPipeline() gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), vkSS::eVertex); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addBindingDescription({0, sizeof(VertexObj)}); - gpb.addAttributeDescriptions(std::vector{ - {0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, - {1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, - {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, - {3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); + gpb.addAttributeDescriptions({ + {0, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, pos))}, + {1, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, nrm))}, + {2, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, color))}, + {3, 0, vk::Format::eR32G32Sfloat, static_cast(offsetof(VertexObj, texCoord))}, + }); m_graphicsPipeline = gpb.createPipeline(); m_debug.setObjectName(m_graphicsPipeline, "Graphics"); diff --git a/ray_tracing__before/hello_vulkan.h b/ray_tracing__before/hello_vulkan.h index 13a0297..b54f1e2 100644 --- a/ray_tracing__before/hello_vulkan.h +++ b/ray_tracing__before/hello_vulkan.h @@ -18,11 +18,12 @@ */ #pragma once - +#include #include "nvvk/appbase_vkpp.hpp" #include "nvvk/debug_util_vk.hpp" #include "nvvk/descriptorsets_vk.hpp" +#include "nvvk/memallocator_dma_vk.hpp" #include "nvvk/resourceallocator_vk.hpp" //-------------------------------------------------------------------------------------------------- @@ -99,9 +100,8 @@ public: std::vector m_textures; // vector of all textures of the scene - nvvk::ResourceAllocatorDedicated - m_alloc; // Allocator for buffer, images, acceleration structures - nvvk::DebugUtil m_debug; // Utility to name objects + nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures + nvvk::DebugUtil m_debug; // Utility to name objects // #Post @@ -122,5 +122,5 @@ public: nvvk::Texture m_offscreenColor; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_offscreenDepth; - vk::Format m_offscreenDepthFormat; + vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32}; }; diff --git a/ray_tracing__before/main.cpp b/ray_tracing__before/main.cpp index 61f8497..c4a2e05 100644 --- a/ray_tracing__before/main.cpp +++ b/ray_tracing__before/main.cpp @@ -216,7 +216,7 @@ int main(int argc, char** argv) // Clearing screen - vk::ClearValue clearValues[2]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); clearValues[1].setDepthStencil({1.0f, 0}); @@ -225,7 +225,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(2); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -241,7 +241,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); diff --git a/ray_tracing__simple/hello_vulkan.cpp b/ray_tracing__simple/hello_vulkan.cpp index b972ca4..3d491cb 100644 --- a/ray_tracing__simple/hello_vulkan.cpp +++ b/ray_tracing__simple/hello_vulkan.cpp @@ -115,11 +115,11 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); - uint32_t nbObj = static_cast(m_objModel.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; + auto nbTxt = static_cast(m_textures.size()); + auto nbObj = static_cast(m_objModel.size()); // Camera matrices (binding = 0) m_descSetLayoutBind.addBinding( @@ -217,11 +217,12 @@ void HelloVulkan::createGraphicsPipeline() gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), vkSS::eVertex); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addBindingDescription({0, sizeof(VertexObj)}); - gpb.addAttributeDescriptions(std::vector{ - {0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, - {1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, - {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, - {3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); + gpb.addAttributeDescriptions({ + {0, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, pos))}, + {1, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, nrm))}, + {2, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, color))}, + {3, 0, vk::Format::eR32G32Sfloat, static_cast(offsetof(VertexObj, texCoord))}, + }); m_graphicsPipeline = gpb.createPipeline(); m_debug.setObjectName(m_graphicsPipeline, "Graphics"); @@ -857,8 +858,9 @@ void HelloVulkan::createRtPipeline() rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setLayout(m_rtPipelineLayout); - m_rtPipeline = static_cast( - m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); + + m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value; + // Spec only guarantees 1 level of "recursion". Check for that sad possibility here. if(m_rtProperties.maxRayRecursionDepth <= 1) diff --git a/ray_tracing__simple/hello_vulkan.h b/ray_tracing__simple/hello_vulkan.h index 89f273c..80ac1e6 100644 --- a/ray_tracing__simple/hello_vulkan.h +++ b/ray_tracing__simple/hello_vulkan.h @@ -20,11 +20,10 @@ #pragma once #include - #include "nvvk/appbase_vkpp.hpp" #include "nvvk/debug_util_vk.hpp" #include "nvvk/descriptorsets_vk.hpp" -#include "nvvk/resourceallocator_vk.hpp" +#include "nvvk/memallocator_dma_vk.hpp" // #VKRay #include "nvvk/raytraceKHR_vk.hpp" @@ -102,9 +101,8 @@ public: nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances std::vector m_textures; // vector of all textures of the scene - nvvk::ResourceAllocatorDedicated - m_alloc; // Allocator for buffer, images, acceleration structures - nvvk::DebugUtil m_debug; // Utility to name objects + nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures + nvvk::DebugUtil m_debug; // Utility to name objects // #Post void createOffscreenRender(); @@ -124,7 +122,7 @@ public: nvvk::Texture m_offscreenColor; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_offscreenDepth; - vk::Format m_offscreenDepthFormat; + vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32}; // #VKRay void initRayTracing(); diff --git a/ray_tracing__simple/main.cpp b/ray_tracing__simple/main.cpp index c4c3a50..cffadb5 100644 --- a/ray_tracing__simple/main.cpp +++ b/ray_tracing__simple/main.cpp @@ -239,7 +239,7 @@ int main(int argc, char** argv) helloVk.updateUniformBuffer(cmdBuf); // Clearing screen - vk::ClearValue clearValues[2]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); clearValues[1].setDepthStencil({1.0f, 0}); @@ -248,7 +248,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(2); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -270,7 +270,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); diff --git a/ray_tracing_animation/hello_vulkan.cpp b/ray_tracing_animation/hello_vulkan.cpp index b6a5408..6b3ece9 100644 --- a/ray_tracing_animation/hello_vulkan.cpp +++ b/ray_tracing_animation/hello_vulkan.cpp @@ -115,11 +115,11 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); - uint32_t nbObj = static_cast(m_objModel.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; + auto nbTxt = static_cast(m_textures.size()); + auto nbObj = static_cast(m_objModel.size()); // Camera matrices (binding = 0) m_descSetLayoutBind.addBinding( @@ -217,10 +217,12 @@ void HelloVulkan::createGraphicsPipeline() gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), vkSS::eVertex); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addBindingDescription({0, sizeof(VertexObj)}); - gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, - {1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, - {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, - {3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); + gpb.addAttributeDescriptions({ + {0, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, pos))}, + {1, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, nrm))}, + {2, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, color))}, + {3, 0, vk::Format::eR32G32Sfloat, static_cast(offsetof(VertexObj, texCoord))}, + }); m_graphicsPipeline = gpb.createPipeline(); m_debug.setObjectName(m_graphicsPipeline, "Graphics"); @@ -851,8 +853,7 @@ void HelloVulkan::createRtPipeline() rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setLayout(m_rtPipelineLayout); - m_rtPipeline = static_cast( - m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); + m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value; m_sbtWrapper.create(m_rtPipeline, rayPipelineInfo); @@ -898,11 +899,11 @@ void HelloVulkan::raytrace(const vk::CommandBuffer& cmdBuf, const nvmath::vec4f& void HelloVulkan::animationInstances(float time) { - const int32_t nbWuson = static_cast(m_objInstance.size() - 2); - const float deltaAngle = 6.28318530718f / static_cast(nbWuson); - const float wusonLength = 3.f; - const float radius = wusonLength / (2.f * sin(deltaAngle / 2.0f)); - const float offset = time * 0.5f; + const auto nbWuson = static_cast(m_objInstance.size() - 2); + const float deltaAngle = 6.28318530718f / static_cast(nbWuson); + const float wusonLength = 3.f; + const float radius = wusonLength / (2.f * sin(deltaAngle / 2.0f)); + const float offset = time * 0.5f; for(int i = 0; i < nbWuson; i++) { @@ -986,7 +987,7 @@ void HelloVulkan::createCompPipelines() computePipelineCreateInfo.stage = nvvk::createShaderStageInfo( m_device, nvh::loadFile("spv/anim.comp.spv", true, defaultSearchPaths, true), VK_SHADER_STAGE_COMPUTE_BIT); - m_compPipeline = static_cast( - m_device.createComputePipeline({}, computePipelineCreateInfo)); + + m_compPipeline = m_device.createComputePipeline({}, computePipelineCreateInfo).value; m_device.destroy(computePipelineCreateInfo.stage.module); } diff --git a/ray_tracing_animation/hello_vulkan.h b/ray_tracing_animation/hello_vulkan.h index 93aea5a..b9f07f4 100644 --- a/ray_tracing_animation/hello_vulkan.h +++ b/ray_tracing_animation/hello_vulkan.h @@ -23,7 +23,7 @@ #include "nvvk/appbase_vkpp.hpp" #include "nvvk/debug_util_vk.hpp" #include "nvvk/descriptorsets_vk.hpp" -#include "nvvk/resourceallocator_vk.hpp" +#include "nvvk/memallocator_dma_vk.hpp" // #VKRay #include "nvvk/raytraceKHR_vk.hpp" @@ -102,9 +102,8 @@ public: nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances std::vector m_textures; // vector of all textures of the scene - nvvk::ResourceAllocatorDedicated - m_alloc; // Allocator for buffer, images, acceleration structures - nvvk::DebugUtil m_debug; // Utility to name objects + nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures + nvvk::DebugUtil m_debug; // Utility to name objects // #Post void createOffscreenRender(); @@ -124,7 +123,7 @@ public: nvvk::Texture m_offscreenColor; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_offscreenDepth; - vk::Format m_offscreenDepthFormat; + vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32}; // #VKRay void initRayTracing(); @@ -155,8 +154,8 @@ public: { nvmath::vec4f clearColor; nvmath::vec3f lightPosition; - float lightIntensity; - int lightType; + float lightIntensity{100.0f}; + int lightType{0}; } m_rtPushConstants; // #VK_animation diff --git a/ray_tracing_animation/main.cpp b/ray_tracing_animation/main.cpp index 6e40afd..538d8d0 100644 --- a/ray_tracing_animation/main.cpp +++ b/ray_tracing_animation/main.cpp @@ -253,7 +253,7 @@ int main(int argc, char** argv) helloVk.updateUniformBuffer(cmdBuf); // Clearing screen - vk::ClearValue clearValues[2]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); clearValues[1].setDepthStencil({1.0f, 0}); @@ -262,7 +262,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(2); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -284,7 +284,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); diff --git a/ray_tracing_anyhit/hello_vulkan.cpp b/ray_tracing_anyhit/hello_vulkan.cpp index 0e01bbb..da83c0c 100644 --- a/ray_tracing_anyhit/hello_vulkan.cpp +++ b/ray_tracing_anyhit/hello_vulkan.cpp @@ -115,11 +115,11 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); - uint32_t nbObj = static_cast(m_objModel.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; + auto nbTxt = static_cast(m_textures.size()); + auto nbObj = static_cast(m_objModel.size()); // Camera matrices (binding = 0) m_descSetLayoutBind.addBinding( @@ -220,10 +220,12 @@ void HelloVulkan::createGraphicsPipeline() gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), vkSS::eVertex); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addBindingDescription({0, sizeof(VertexObj)}); - gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, - {1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, - {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, - {3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); + gpb.addAttributeDescriptions({ + {0, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, pos))}, + {1, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, nrm))}, + {2, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, color))}, + {3, 0, vk::Format::eR32G32Sfloat, static_cast(offsetof(VertexObj, texCoord))}, + }); m_graphicsPipeline = gpb.createPipeline(); m_debug.setObjectName(m_graphicsPipeline, "Graphics"); diff --git a/ray_tracing_anyhit/hello_vulkan.h b/ray_tracing_anyhit/hello_vulkan.h index 8683f2e..215b3b1 100644 --- a/ray_tracing_anyhit/hello_vulkan.h +++ b/ray_tracing_anyhit/hello_vulkan.h @@ -23,7 +23,7 @@ #include "nvvk/appbase_vkpp.hpp" #include "nvvk/debug_util_vk.hpp" #include "nvvk/descriptorsets_vk.hpp" -#include "nvvk/resourceallocator_vk.hpp" +#include "nvvk/memallocator_dma_vk.hpp" // #VKRay #include "nvvk/raytraceKHR_vk.hpp" @@ -101,9 +101,8 @@ public: nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances std::vector m_textures; // vector of all textures of the scene - nvvk::ResourceAllocatorDedicated - m_alloc; // Allocator for buffer, images, acceleration structures - nvvk::DebugUtil m_debug; // Utility to name objects + nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures + nvvk::DebugUtil m_debug; // Utility to name objects // #Post void createOffscreenRender(); @@ -123,7 +122,7 @@ public: nvvk::Texture m_offscreenColor; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_offscreenDepth; - vk::Format m_offscreenDepthFormat; + vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32}; // #VKRay void initRayTracing(); @@ -154,8 +153,8 @@ public: { nvmath::vec4f clearColor; nvmath::vec3f lightPosition; - float lightIntensity; - int lightType; + float lightIntensity{100.0f}; + int lightType{0}; int frame{0}; } m_rtPushConstants; }; diff --git a/ray_tracing_anyhit/main.cpp b/ray_tracing_anyhit/main.cpp index 8921c3b..65d516a 100644 --- a/ray_tracing_anyhit/main.cpp +++ b/ray_tracing_anyhit/main.cpp @@ -242,7 +242,7 @@ int main(int argc, char** argv) helloVk.updateUniformBuffer(cmdBuf); // Clearing screen - vk::ClearValue clearValues[2]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); clearValues[1].setDepthStencil({1.0f, 0}); @@ -251,7 +251,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(2); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -273,7 +273,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); diff --git a/ray_tracing_ao/hello_vulkan.cpp b/ray_tracing_ao/hello_vulkan.cpp index 4dd8a4e..0c25097 100644 --- a/ray_tracing_ao/hello_vulkan.cpp +++ b/ray_tracing_ao/hello_vulkan.cpp @@ -114,11 +114,11 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); - uint32_t nbObj = static_cast(m_objModel.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; + auto nbTxt = static_cast(m_textures.size()); + auto nbObj = static_cast(m_objModel.size()); // Camera matrices (binding = 0) m_descSetLayoutBind.addBinding(vkDS(0, vkDT::eUniformBuffer, 1, vkSS::eVertex)); @@ -204,10 +204,13 @@ void HelloVulkan::createGraphicsPipeline() gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), vkSS::eVertex); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addBindingDescription({0, sizeof(VertexObj)}); - gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, - {1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, - {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, - {3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); + gpb.addAttributeDescriptions({ + {0, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, pos))}, + {1, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, nrm))}, + {2, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, color))}, + {3, 0, vk::Format::eR32G32Sfloat, static_cast(offsetof(VertexObj, texCoord))}, + }); + vk::PipelineColorBlendAttachmentState res; res.colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA; @@ -645,9 +648,9 @@ void HelloVulkan::createPostDescriptor() void HelloVulkan::updatePostDescriptorSet() { std::vector writes; - writes.push_back( + writes.emplace_back( m_postDescSetLayoutBind.makeWrite(m_postDescSet, 0, &m_offscreenColor.descriptor)); - writes.push_back(m_postDescSetLayoutBind.makeWrite(m_postDescSet, 1, &m_aoBuffer.descriptor)); + writes.emplace_back(m_postDescSetLayoutBind.makeWrite(m_postDescSet, 1, &m_aoBuffer.descriptor)); m_device.updateDescriptorSets(static_cast(writes.size()), writes.data(), 0, nullptr); } @@ -816,8 +819,7 @@ void HelloVulkan::createCompPipelines() nvvk::createShaderStageInfo(m_device, nvh::loadFile("spv/ao.comp.spv", true, defaultSearchPaths, true), VK_SHADER_STAGE_COMPUTE_BIT); - m_compPipeline = static_cast( - m_device.createComputePipeline({}, computePipelineCreateInfo)); + m_compPipeline = m_device.createComputePipeline({}, computePipelineCreateInfo).value; m_device.destroy(computePipelineCreateInfo.stage.module); } diff --git a/ray_tracing_ao/hello_vulkan.h b/ray_tracing_ao/hello_vulkan.h index 819379c..e498199 100644 --- a/ray_tracing_ao/hello_vulkan.h +++ b/ray_tracing_ao/hello_vulkan.h @@ -23,7 +23,7 @@ #include "nvvk/appbase_vkpp.hpp" #include "nvvk/debug_util_vk.hpp" #include "nvvk/descriptorsets_vk.hpp" -#include "nvvk/resourceallocator_vk.hpp" +#include "nvvk/memallocator_dma_vk.hpp" // #VKRay #include "nvvk/raytraceKHR_vk.hpp" @@ -112,9 +112,8 @@ public: nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances std::vector m_textures; // vector of all textures of the scene - nvvk::ResourceAllocatorDedicated - m_alloc; // Allocator for buffer, images, acceleration structures - nvvk::DebugUtil m_debug; // Utility to name objects + nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures + nvvk::DebugUtil m_debug; // Utility to name objects // #Post void createOffscreenRender(); @@ -136,7 +135,7 @@ public: nvvk::Texture m_aoBuffer; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_offscreenDepth; - vk::Format m_offscreenDepthFormat; + vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32}; // #Tuto_rayquery void initRayTracing(); diff --git a/ray_tracing_ao/main.cpp b/ray_tracing_ao/main.cpp index 314ad09..c5073f2 100644 --- a/ray_tracing_ao/main.cpp +++ b/ray_tracing_ao/main.cpp @@ -260,7 +260,7 @@ int main(int argc, char** argv) helloVk.updateUniformBuffer(cmdBuf); // Clearing screen - vk::ClearValue clearValues[3]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); @@ -271,7 +271,7 @@ int main(int argc, char** argv) clearValues[2].setDepthStencil({1.0f, 0}); vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(3); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -290,7 +290,7 @@ int main(int argc, char** argv) clearValues[1].setDepthStencil({1.0f, 0}); vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); diff --git a/ray_tracing_callable/hello_vulkan.cpp b/ray_tracing_callable/hello_vulkan.cpp index 1ef4ca0..415268c 100644 --- a/ray_tracing_callable/hello_vulkan.cpp +++ b/ray_tracing_callable/hello_vulkan.cpp @@ -115,11 +115,11 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); - uint32_t nbObj = static_cast(m_objModel.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; + auto nbTxt = static_cast(m_textures.size()); + auto nbObj = static_cast(m_objModel.size()); // Camera matrices (binding = 0) m_descSetLayoutBind.addBinding( @@ -217,10 +217,12 @@ void HelloVulkan::createGraphicsPipeline() gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), vkSS::eVertex); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addBindingDescription({0, sizeof(VertexObj)}); - gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, - {1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, - {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, - {3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); + gpb.addAttributeDescriptions({ + {0, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, pos))}, + {1, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, nrm))}, + {2, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, color))}, + {3, 0, vk::Format::eR32G32Sfloat, static_cast(offsetof(VertexObj, texCoord))}, + }); m_graphicsPipeline = gpb.createPipeline(); m_debug.setObjectName(m_graphicsPipeline, "Graphics"); @@ -870,8 +872,9 @@ void HelloVulkan::createRtPipeline() rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setLayout(m_rtPipelineLayout); - m_rtPipeline = static_cast( - m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); + + m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value; + m_sbtWrapper.create(m_rtPipeline, rayPipelineInfo); diff --git a/ray_tracing_callable/hello_vulkan.h b/ray_tracing_callable/hello_vulkan.h index 72636cc..9288e53 100644 --- a/ray_tracing_callable/hello_vulkan.h +++ b/ray_tracing_callable/hello_vulkan.h @@ -23,7 +23,7 @@ #include "nvvk/appbase_vkpp.hpp" #include "nvvk/debug_util_vk.hpp" #include "nvvk/descriptorsets_vk.hpp" -#include "nvvk/resourceallocator_vk.hpp" +#include "nvvk/memallocator_dma_vk.hpp" // #VKRay #include "nvvk/raytraceKHR_vk.hpp" @@ -106,9 +106,8 @@ public: nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances std::vector m_textures; // vector of all textures of the scene - nvvk::ResourceAllocatorDedicated - m_alloc; // Allocator for buffer, images, acceleration structures - nvvk::DebugUtil m_debug; // Utility to name objects + nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures + nvvk::DebugUtil m_debug; // Utility to name objects // #Post void createOffscreenRender(); @@ -128,7 +127,7 @@ public: nvvk::Texture m_offscreenColor; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_offscreenDepth; - vk::Format m_offscreenDepthFormat; + vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32}; // #VKRay void initRayTracing(); diff --git a/ray_tracing_callable/main.cpp b/ray_tracing_callable/main.cpp index 7e8e0e2..eb8d591 100644 --- a/ray_tracing_callable/main.cpp +++ b/ray_tracing_callable/main.cpp @@ -253,7 +253,7 @@ int main(int argc, char** argv) helloVk.updateUniformBuffer(cmdBuf); // Clearing screen - vk::ClearValue clearValues[2]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); clearValues[1].setDepthStencil({1.0f, 0}); @@ -262,7 +262,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(2); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -284,7 +284,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); diff --git a/ray_tracing_gltf/hello_vulkan.cpp b/ray_tracing_gltf/hello_vulkan.cpp index f486755..0685f89 100644 --- a/ray_tracing_gltf/hello_vulkan.cpp +++ b/ray_tracing_gltf/hello_vulkan.cpp @@ -120,10 +120,9 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; auto& bind = m_descSetLayoutBind; // Camera matrices (binding = 0) @@ -417,7 +416,6 @@ void HelloVulkan::destroyResources() void HelloVulkan::rasterize(const vk::CommandBuffer& cmdBuf) { using vkPBP = vk::PipelineBindPoint; - using vkSS = vk::ShaderStageFlagBits; std::vector offsets = {0, 0, 0}; @@ -691,7 +689,6 @@ void HelloVulkan::createTopLevelAS() { std::vector tlas; tlas.reserve(m_gltfScene.m_nodes.size()); - uint32_t instID = 0; for(auto& node : m_gltfScene.m_nodes) { nvvk::RaytracingBuilderKHR::Instance rayInst; @@ -834,8 +831,9 @@ void HelloVulkan::createRtPipeline() rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setLayout(m_rtPipelineLayout); - m_rtPipeline = static_cast( - m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); + + m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value; + // Creating the SBT diff --git a/ray_tracing_gltf/hello_vulkan.h b/ray_tracing_gltf/hello_vulkan.h index 26ca060..c087608 100644 --- a/ray_tracing_gltf/hello_vulkan.h +++ b/ray_tracing_gltf/hello_vulkan.h @@ -24,7 +24,6 @@ #include "nvvk/appbase_vkpp.hpp" #include "nvvk/debug_util_vk.hpp" #include "nvvk/descriptorsets_vk.hpp" -#include "nvvk/resourceallocator_vk.hpp" #include "nvvk/memallocator_dma_vk.hpp" // #VKRay @@ -119,7 +118,7 @@ public: nvvk::Texture m_offscreenColor; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_offscreenDepth; - vk::Format m_offscreenDepthFormat; + vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32}; // #VKRay auto primitiveToGeometry(const nvh::GltfPrimMesh& prim); diff --git a/ray_tracing_gltf/main.cpp b/ray_tracing_gltf/main.cpp index 18e9512..bdebee0 100644 --- a/ray_tracing_gltf/main.cpp +++ b/ray_tracing_gltf/main.cpp @@ -236,7 +236,7 @@ int main(int argc, char** argv) helloVk.updateUniformBuffer(cmdBuf); // Clearing screen - vk::ClearValue clearValues[2]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); clearValues[1].setDepthStencil({1.0f, 0}); @@ -245,7 +245,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(2); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -267,7 +267,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); diff --git a/ray_tracing_indirect_scissor/hello_vulkan.cpp b/ray_tracing_indirect_scissor/hello_vulkan.cpp index 4d1f507..385a117 100644 --- a/ray_tracing_indirect_scissor/hello_vulkan.cpp +++ b/ray_tracing_indirect_scissor/hello_vulkan.cpp @@ -116,11 +116,11 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); - uint32_t nbObj = static_cast(m_objModel.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; + auto nbTxt = static_cast(m_textures.size()); + auto nbObj = static_cast(m_objModel.size()); // Camera matrices (binding = 0) m_descSetLayoutBind.addBinding( @@ -218,11 +218,12 @@ void HelloVulkan::createGraphicsPipeline() gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), vkSS::eVertex); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addBindingDescription({0, sizeof(VertexObj)}); - gpb.addAttributeDescriptions(std::vector{ - {0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, - {1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, - {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, - {3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); + gpb.addAttributeDescriptions({ + {0, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, pos))}, + {1, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, nrm))}, + {2, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, color))}, + {3, 0, vk::Format::eR32G32Sfloat, static_cast(offsetof(VertexObj, texCoord))}, + }); m_graphicsPipeline = gpb.createPipeline(); m_debug.setObjectName(m_graphicsPipeline, "Graphics"); @@ -821,7 +822,7 @@ void HelloVulkan::createLanternModel() vk::DeviceAddress vertexAddress = m_device.getBufferAddress({m_lanternVertexBuffer.buffer}); vk::DeviceAddress indexAddress = m_device.getBufferAddress({m_lanternIndexBuffer.buffer}); - uint32_t maxPrimitiveCount = uint32_t(indices.size() / 3); + auto maxPrimitiveCount = uint32_t(indices.size() / 3); // Describe buffer as packed array of float vec3. vk::AccelerationStructureGeometryTrianglesDataKHR triangles; @@ -1151,8 +1152,9 @@ void HelloVulkan::createRtPipeline() rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setLayout(m_rtPipelineLayout); - m_rtPipeline = static_cast( - m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); + + m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value; + m_device.destroy(raygenSM); m_device.destroy(missSM); @@ -1265,8 +1267,7 @@ void HelloVulkan::createLanternIndirectCompPipeline() vk::ComputePipelineCreateInfo pipelineInfo; pipelineInfo.setStage(stageInfo); pipelineInfo.setLayout(m_lanternIndirectCompPipelineLayout); - m_lanternIndirectCompPipeline = - static_cast(m_device.createComputePipeline({}, pipelineInfo)); + m_lanternIndirectCompPipeline = m_device.createComputePipeline({}, pipelineInfo).value; m_device.destroy(computeShader); } diff --git a/ray_tracing_indirect_scissor/hello_vulkan.h b/ray_tracing_indirect_scissor/hello_vulkan.h index 9ab5a0c..86c7f5c 100644 --- a/ray_tracing_indirect_scissor/hello_vulkan.h +++ b/ray_tracing_indirect_scissor/hello_vulkan.h @@ -24,7 +24,7 @@ #include "nvvk/appbase_vkpp.hpp" #include "nvvk/debug_util_vk.hpp" #include "nvvk/descriptorsets_vk.hpp" -#include "nvvk/resourceallocator_vk.hpp" +#include "nvvk/memallocator_dma_vk.hpp" // #VKRay #include "nvvk/raytraceKHR_vk.hpp" @@ -141,9 +141,8 @@ public: nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances std::vector m_textures; // vector of all textures of the scene - nvvk::ResourceAllocatorDedicated - m_alloc; // Allocator for buffer, images, acceleration structures - nvvk::DebugUtil m_debug; // Utility to name objects + nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures + nvvk::DebugUtil m_debug; // Utility to name objects // #Post void createOffscreenRender(); @@ -163,7 +162,7 @@ public: nvvk::Texture m_offscreenColor; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_offscreenDepth; - vk::Format m_offscreenDepthFormat; + vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32}; // #VKRay void initRayTracing(); diff --git a/ray_tracing_indirect_scissor/main.cpp b/ray_tracing_indirect_scissor/main.cpp index 1abc3ad..4e80346 100644 --- a/ray_tracing_indirect_scissor/main.cpp +++ b/ray_tracing_indirect_scissor/main.cpp @@ -251,7 +251,7 @@ int main(int argc, char** argv) helloVk.updateUniformBuffer(cmdBuf); // Clearing screen - vk::ClearValue clearValues[2]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); clearValues[1].setDepthStencil({1.0f, 0}); @@ -260,7 +260,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(2); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -282,7 +282,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); diff --git a/ray_tracing_instances/hello_vulkan.cpp b/ray_tracing_instances/hello_vulkan.cpp index 7d56ae4..7ed0a23 100644 --- a/ray_tracing_instances/hello_vulkan.cpp +++ b/ray_tracing_instances/hello_vulkan.cpp @@ -116,11 +116,11 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); - uint32_t nbObj = static_cast(m_objModel.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; + auto nbTxt = static_cast(m_textures.size()); + auto nbObj = static_cast(m_objModel.size()); // Camera matrices (binding = 0) m_descSetLayoutBind.addBinding( @@ -218,10 +218,12 @@ void HelloVulkan::createGraphicsPipeline() gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), vkSS::eVertex); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addBindingDescription({0, sizeof(VertexObj)}); - gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, - {1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, - {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, - {3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); + gpb.addAttributeDescriptions({ + {0, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, pos))}, + {1, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, nrm))}, + {2, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, color))}, + {3, 0, vk::Format::eR32G32Sfloat, static_cast(offsetof(VertexObj, texCoord))}, + }); m_graphicsPipeline = gpb.createPipeline(); m_debug.setObjectName(m_graphicsPipeline, "Graphics"); @@ -843,8 +845,8 @@ void HelloVulkan::createRtPipeline() rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setLayout(m_rtPipelineLayout); - m_rtPipeline = static_cast( - m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); + + m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value; m_sbtWrapper.create(m_rtPipeline, rayPipelineInfo); diff --git a/ray_tracing_instances/hello_vulkan.h b/ray_tracing_instances/hello_vulkan.h index 3a4e29f..7f540cc 100644 --- a/ray_tracing_instances/hello_vulkan.h +++ b/ray_tracing_instances/hello_vulkan.h @@ -22,9 +22,9 @@ // #VKRay // // Choosing the allocator to use -#define ALLOC_DMA +//#define ALLOC_DMA //#define ALLOC_DEDICATED -//#define ALLOC_VMA +#define ALLOC_VMA #include #if defined(ALLOC_DMA) @@ -141,7 +141,7 @@ public: nvvk::Texture m_offscreenColor; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_offscreenDepth; - vk::Format m_offscreenDepthFormat; + vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32}; // #VKRay void initRayTracing(); diff --git a/ray_tracing_instances/main.cpp b/ray_tracing_instances/main.cpp index fb8ab83..bd1eb93 100644 --- a/ray_tracing_instances/main.cpp +++ b/ray_tracing_instances/main.cpp @@ -286,7 +286,7 @@ int main(int argc, char** argv) helloVk.updateUniformBuffer(cmdBuf); // Clearing screen - vk::ClearValue clearValues[2]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); clearValues[1].setDepthStencil({1.0f, 0}); @@ -295,7 +295,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(2); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -317,7 +317,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); diff --git a/ray_tracing_intersection/hello_vulkan.cpp b/ray_tracing_intersection/hello_vulkan.cpp index ac34008..23302b5 100644 --- a/ray_tracing_intersection/hello_vulkan.cpp +++ b/ray_tracing_intersection/hello_vulkan.cpp @@ -115,11 +115,11 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); - uint32_t nbObj = static_cast(m_objModel.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; + auto nbTxt = static_cast(m_textures.size()); + auto nbObj = static_cast(m_objModel.size()); // Camera matrices (binding = 0) m_descSetLayoutBind.addBinding( @@ -226,10 +226,12 @@ void HelloVulkan::createGraphicsPipeline() gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), vkSS::eVertex); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addBindingDescription({0, sizeof(VertexObj)}); - gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, - {1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, - {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, - {3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); + gpb.addAttributeDescriptions({ + {0, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, pos))}, + {1, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, nrm))}, + {2, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, color))}, + {3, 0, vk::Format::eR32G32Sfloat, static_cast(offsetof(VertexObj, texCoord))}, + }); m_graphicsPipeline = gpb.createPipeline(); m_debug.setObjectName(m_graphicsPipeline, "Graphics"); @@ -743,10 +745,10 @@ void HelloVulkan::createSpheres(uint32_t nbSpheres) std::uniform_real_distribution radd{.05f, .2f}; // All spheres - Sphere s; m_spheres.resize(nbSpheres); for(uint32_t i = 0; i < nbSpheres; i++) { + Sphere s; s.center = nvmath::vec3f(xzd(gen), yd(gen), xzd(gen)); s.radius = radd(gen); m_spheres[i] = std::move(s); @@ -988,8 +990,9 @@ void HelloVulkan::createRtPipeline() rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setLayout(m_rtPipelineLayout); - m_rtPipeline = static_cast( - m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); + + m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value; + m_device.destroy(raygenSM); m_device.destroy(missSM); diff --git a/ray_tracing_intersection/hello_vulkan.h b/ray_tracing_intersection/hello_vulkan.h index 1b93c71..7299a30 100644 --- a/ray_tracing_intersection/hello_vulkan.h +++ b/ray_tracing_intersection/hello_vulkan.h @@ -23,7 +23,7 @@ #include "nvvk/appbase_vkpp.hpp" #include "nvvk/debug_util_vk.hpp" #include "nvvk/descriptorsets_vk.hpp" -#include "nvvk/resourceallocator_vk.hpp" +#include "nvvk/memallocator_dma_vk.hpp" // #VKRay #include "nvvk/raytraceKHR_vk.hpp" @@ -101,9 +101,8 @@ public: nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances std::vector m_textures; // vector of all textures of the scene - nvvk::ResourceAllocatorDedicated - m_alloc; // Allocator for buffer, images, acceleration structures - nvvk::DebugUtil m_debug; // Utility to name objects + nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures + nvvk::DebugUtil m_debug; // Utility to name objects // #Post void createOffscreenRender(); @@ -123,7 +122,7 @@ public: nvvk::Texture m_offscreenColor; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_offscreenDepth; - vk::Format m_offscreenDepthFormat; + vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32}; // #VKRay void initRayTracing(); diff --git a/ray_tracing_intersection/main.cpp b/ray_tracing_intersection/main.cpp index d02e0c7..62b94b8 100644 --- a/ray_tracing_intersection/main.cpp +++ b/ray_tracing_intersection/main.cpp @@ -65,7 +65,7 @@ void renderUI(HelloVulkan& helloVk) ImGui::SliderFloat3("Position", &helloVk.m_pushConstant.lightPosition.x, -20.f, 20.f); ImGui::SliderFloat("Intensity", &helloVk.m_pushConstant.lightIntensity, 0.f, 150.f); } - ImGui::Text("Nb Spheres and Cubes: %d", helloVk.m_spheres.size()); + ImGui::Text("Nb Spheres and Cubes: %llu", helloVk.m_spheres.size()); } ////////////////////////////////////////////////////////////////////////// @@ -239,7 +239,7 @@ int main(int argc, char** argv) helloVk.updateUniformBuffer(cmdBuf); // Clearing screen - vk::ClearValue clearValues[2]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); clearValues[1].setDepthStencil({1.0f, 0}); @@ -248,7 +248,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(2); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -270,7 +270,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); diff --git a/ray_tracing_jitter_cam/hello_vulkan.cpp b/ray_tracing_jitter_cam/hello_vulkan.cpp index f568616..bbd8562 100644 --- a/ray_tracing_jitter_cam/hello_vulkan.cpp +++ b/ray_tracing_jitter_cam/hello_vulkan.cpp @@ -115,11 +115,11 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); - uint32_t nbObj = static_cast(m_objModel.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; + auto nbTxt = static_cast(m_textures.size()); + auto nbObj = static_cast(m_objModel.size()); // Camera matrices (binding = 0) m_descSetLayoutBind.addBinding( @@ -217,10 +217,12 @@ void HelloVulkan::createGraphicsPipeline() gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), vkSS::eVertex); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addBindingDescription({0, sizeof(VertexObj)}); - gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, - {1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, - {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, - {3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); + gpb.addAttributeDescriptions({ + {0, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, pos))}, + {1, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, nrm))}, + {2, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, color))}, + {3, 0, vk::Format::eR32G32Sfloat, static_cast(offsetof(VertexObj, texCoord))}, + }); m_graphicsPipeline = gpb.createPipeline(); m_debug.setObjectName(m_graphicsPipeline, "Graphics"); @@ -842,8 +844,9 @@ void HelloVulkan::createRtPipeline() rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setLayout(m_rtPipelineLayout); - m_rtPipeline = static_cast( - m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); + + m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value; + m_device.destroy(raygenSM); m_device.destroy(missSM); diff --git a/ray_tracing_jitter_cam/hello_vulkan.h b/ray_tracing_jitter_cam/hello_vulkan.h index 6cec64e..598aab6 100644 --- a/ray_tracing_jitter_cam/hello_vulkan.h +++ b/ray_tracing_jitter_cam/hello_vulkan.h @@ -23,7 +23,7 @@ #include "nvvk/appbase_vkpp.hpp" #include "nvvk/debug_util_vk.hpp" #include "nvvk/descriptorsets_vk.hpp" -#include "nvvk/resourceallocator_vk.hpp" +#include "nvvk/memallocator_dma_vk.hpp" // #VKRay #include "nvvk/raytraceKHR_vk.hpp" @@ -101,9 +101,8 @@ public: nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances std::vector m_textures; // vector of all textures of the scene - nvvk::ResourceAllocatorDedicated - m_alloc; // Allocator for buffer, images, acceleration structures - nvvk::DebugUtil m_debug; // Utility to name objects + nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures + nvvk::DebugUtil m_debug; // Utility to name objects // #Post void createOffscreenRender(); @@ -123,7 +122,7 @@ public: nvvk::Texture m_offscreenColor; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_offscreenDepth; - vk::Format m_offscreenDepthFormat; + vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32}; // #VKRay void initRayTracing(); diff --git a/ray_tracing_jitter_cam/main.cpp b/ray_tracing_jitter_cam/main.cpp index f1eecd0..3d287dc 100644 --- a/ray_tracing_jitter_cam/main.cpp +++ b/ray_tracing_jitter_cam/main.cpp @@ -251,7 +251,7 @@ int main(int argc, char** argv) helloVk.updateUniformBuffer(cmdBuf); // Clearing screen - vk::ClearValue clearValues[2]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); clearValues[1].setDepthStencil({1.0f, 0}); @@ -260,7 +260,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(2); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -282,7 +282,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); diff --git a/ray_tracing_manyhits/hello_vulkan.cpp b/ray_tracing_manyhits/hello_vulkan.cpp index 58305cf..0cc107a 100644 --- a/ray_tracing_manyhits/hello_vulkan.cpp +++ b/ray_tracing_manyhits/hello_vulkan.cpp @@ -114,11 +114,11 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); - uint32_t nbObj = static_cast(m_objModel.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; + auto nbTxt = static_cast(m_textures.size()); + auto nbObj = static_cast(m_objModel.size()); // Camera matrices (binding = 0) m_descSetLayoutBind.addBinding( @@ -166,12 +166,12 @@ void HelloVulkan::updateDescriptorSet() std::vector dbiMatIdx; std::vector dbiVert; std::vector dbiIdx; - for(size_t i = 0; i < m_objModel.size(); ++i) + for(auto& m : m_objModel) { - dbiMat.push_back({m_objModel[i].matColorBuffer.buffer, 0, VK_WHOLE_SIZE}); - dbiMatIdx.push_back({m_objModel[i].matIndexBuffer.buffer, 0, VK_WHOLE_SIZE}); - dbiVert.push_back({m_objModel[i].vertexBuffer.buffer, 0, VK_WHOLE_SIZE}); - dbiIdx.push_back({m_objModel[i].indexBuffer.buffer, 0, VK_WHOLE_SIZE}); + dbiMat.emplace_back(m.matColorBuffer.buffer, 0, VK_WHOLE_SIZE); + dbiMatIdx.emplace_back(m.matIndexBuffer.buffer, 0, VK_WHOLE_SIZE); + dbiVert.emplace_back(m.vertexBuffer.buffer, 0, VK_WHOLE_SIZE); + dbiIdx.emplace_back(m.indexBuffer.buffer, 0, VK_WHOLE_SIZE); } writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, 1, dbiMat.data())); writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, 4, dbiMatIdx.data())); @@ -180,9 +180,9 @@ void HelloVulkan::updateDescriptorSet() // All texture samplers std::vector diit; - for(size_t i = 0; i < m_textures.size(); ++i) + for(auto& t : m_textures) { - diit.push_back(m_textures[i].descriptor); + diit.emplace_back(t.descriptor); } writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, 3, diit.data())); @@ -216,10 +216,12 @@ void HelloVulkan::createGraphicsPipeline() gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), vkSS::eVertex); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addBindingDescription({0, sizeof(VertexObj)}); - gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, - {1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, - {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, - {3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); + gpb.addAttributeDescriptions({ + {0, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, pos))}, + {1, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, nrm))}, + {2, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, color))}, + {3, 0, vk::Format::eR32G32Sfloat, static_cast(offsetof(VertexObj, texCoord))}, + }); m_graphicsPipeline = gpb.createPipeline(); m_debug.setObjectName(m_graphicsPipeline, "Graphics"); @@ -849,8 +851,9 @@ void HelloVulkan::createRtPipeline() rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setLayout(m_rtPipelineLayout); - m_rtPipeline = static_cast( - m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); + + m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value; + // Manually defining group indices m_sbtWrapper.addIndices(rayPipelineInfo); @@ -927,7 +930,7 @@ void HelloVulkan::createRtShaderBindingTable() memcpy(pHitBuffer, handles[4], groupHandleSize); // Hit 2 pHitBuffer += groupHandleSize; memcpy(pHitBuffer, &m_hitShaderRecord[1], sizeof(HitRecordBuffer)); // Hit 2 data - pBuffer += hitSize; + // pBuffer += hitSize; } // Write the handles in the SBT diff --git a/ray_tracing_manyhits/hello_vulkan.h b/ray_tracing_manyhits/hello_vulkan.h index f2b2bdb..f25e3fa 100644 --- a/ray_tracing_manyhits/hello_vulkan.h +++ b/ray_tracing_manyhits/hello_vulkan.h @@ -23,7 +23,7 @@ #include "nvvk/appbase_vkpp.hpp" #include "nvvk/debug_util_vk.hpp" #include "nvvk/descriptorsets_vk.hpp" -#include "nvvk/resourceallocator_vk.hpp" +#include "nvvk/memallocator_dma_vk.hpp" // #VKRay #include "nvvk/raytraceKHR_vk.hpp" @@ -104,9 +104,8 @@ public: nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances std::vector m_textures; // vector of all textures of the scene - nvvk::ResourceAllocatorDedicated - m_alloc; // Allocator for buffer, images, acceleration structures - nvvk::DebugUtil m_debug; // Utility to name objects + nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures + nvvk::DebugUtil m_debug; // Utility to name objects // #Post void createOffscreenRender(); @@ -126,7 +125,7 @@ public: nvvk::Texture m_offscreenColor; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_offscreenDepth; - vk::Format m_offscreenDepthFormat; + vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32}; // #VKRay void initRayTracing(); @@ -155,8 +154,8 @@ public: { nvmath::vec4f clearColor; nvmath::vec3f lightPosition; - float lightIntensity; - int lightType; + float lightIntensity{100.0f}; + int lightType{0}; } m_rtPushConstants; struct HitRecordBuffer diff --git a/ray_tracing_manyhits/main.cpp b/ray_tracing_manyhits/main.cpp index 111a9cf..852d880 100644 --- a/ray_tracing_manyhits/main.cpp +++ b/ray_tracing_manyhits/main.cpp @@ -249,7 +249,7 @@ int main(int argc, char** argv) helloVk.updateUniformBuffer(cmdBuf); // Clearing screen - vk::ClearValue clearValues[2]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); clearValues[1].setDepthStencil({1.0f, 0}); @@ -258,7 +258,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(2); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -280,7 +280,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); diff --git a/ray_tracing_rayquery/hello_vulkan.cpp b/ray_tracing_rayquery/hello_vulkan.cpp index 36f8b3c..b3dc8af 100644 --- a/ray_tracing_rayquery/hello_vulkan.cpp +++ b/ray_tracing_rayquery/hello_vulkan.cpp @@ -113,11 +113,11 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); - uint32_t nbObj = static_cast(m_objModel.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; + auto nbTxt = static_cast(m_textures.size()); + auto nbObj = static_cast(m_objModel.size()); // Camera matrices (binding = 0) m_descSetLayoutBind.addBinding( @@ -224,10 +224,12 @@ void HelloVulkan::createGraphicsPipeline() gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), vkSS::eVertex); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addBindingDescription({0, sizeof(VertexObj)}); - gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, - {1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, - {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, - {3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); + gpb.addAttributeDescriptions({ + {0, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, pos))}, + {1, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, nrm))}, + {2, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, color))}, + {3, 0, vk::Format::eR32G32Sfloat, static_cast(offsetof(VertexObj, texCoord))}, + }); m_graphicsPipeline = gpb.createPipeline(); m_debug.setObjectName(m_graphicsPipeline, "Graphics"); diff --git a/ray_tracing_rayquery/hello_vulkan.h b/ray_tracing_rayquery/hello_vulkan.h index b48ea09..9367576 100644 --- a/ray_tracing_rayquery/hello_vulkan.h +++ b/ray_tracing_rayquery/hello_vulkan.h @@ -23,7 +23,7 @@ #include "nvvk/appbase_vkpp.hpp" #include "nvvk/debug_util_vk.hpp" #include "nvvk/descriptorsets_vk.hpp" -#include "nvvk/resourceallocator_vk.hpp" +#include "nvvk/memallocator_dma_vk.hpp" // #VKRay #include "nvvk/raytraceKHR_vk.hpp" @@ -101,9 +101,8 @@ public: nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances std::vector m_textures; // vector of all textures of the scene - nvvk::ResourceAllocatorDedicated - m_alloc; // Allocator for buffer, images, acceleration structures - nvvk::DebugUtil m_debug; // Utility to name objects + nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures + nvvk::DebugUtil m_debug; // Utility to name objects // #Post void createOffscreenRender(); @@ -123,7 +122,7 @@ public: nvvk::Texture m_offscreenColor; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_offscreenDepth; - vk::Format m_offscreenDepthFormat; + vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32}; // #VKRay void initRayTracing(); diff --git a/ray_tracing_rayquery/main.cpp b/ray_tracing_rayquery/main.cpp index c9c3baa..c8e8ae6 100644 --- a/ray_tracing_rayquery/main.cpp +++ b/ray_tracing_rayquery/main.cpp @@ -235,7 +235,7 @@ int main(int argc, char** argv) helloVk.updateUniformBuffer(cmdBuf); // Clearing screen - vk::ClearValue clearValues[2]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); clearValues[1].setDepthStencil({1.0f, 0}); @@ -244,7 +244,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(2); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -261,7 +261,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); diff --git a/ray_tracing_reflections/hello_vulkan.cpp b/ray_tracing_reflections/hello_vulkan.cpp index dfc2341..7eb2dd1 100644 --- a/ray_tracing_reflections/hello_vulkan.cpp +++ b/ray_tracing_reflections/hello_vulkan.cpp @@ -114,11 +114,11 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); - uint32_t nbObj = static_cast(m_objModel.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; + auto nbTxt = static_cast(m_textures.size()); + auto nbObj = static_cast(m_objModel.size()); // Camera matrices (binding = 0) m_descSetLayoutBind.addBinding( @@ -166,12 +166,12 @@ void HelloVulkan::updateDescriptorSet() std::vector dbiMatIdx; std::vector dbiVert; std::vector dbiIdx; - for(size_t i = 0; i < m_objModel.size(); ++i) + for(auto &m : m_objModel) { - dbiMat.push_back({m_objModel[i].matColorBuffer.buffer, 0, VK_WHOLE_SIZE}); - dbiMatIdx.push_back({m_objModel[i].matIndexBuffer.buffer, 0, VK_WHOLE_SIZE}); - dbiVert.push_back({m_objModel[i].vertexBuffer.buffer, 0, VK_WHOLE_SIZE}); - dbiIdx.push_back({m_objModel[i].indexBuffer.buffer, 0, VK_WHOLE_SIZE}); + dbiMat.emplace_back(m.matColorBuffer.buffer, 0, VK_WHOLE_SIZE); + dbiMatIdx.emplace_back(m.matIndexBuffer.buffer, 0, VK_WHOLE_SIZE); + dbiVert.emplace_back(m.vertexBuffer.buffer, 0, VK_WHOLE_SIZE); + dbiIdx.emplace_back(m.indexBuffer.buffer, 0, VK_WHOLE_SIZE); } writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, 1, dbiMat.data())); writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, 4, dbiMatIdx.data())); @@ -180,9 +180,9 @@ void HelloVulkan::updateDescriptorSet() // All texture samplers std::vector diit; - for(size_t i = 0; i < m_textures.size(); ++i) + for(auto & t: m_textures) { - diit.push_back(m_textures[i].descriptor); + diit.emplace_back(t.descriptor); } writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, 3, diit.data())); @@ -216,10 +216,12 @@ void HelloVulkan::createGraphicsPipeline() gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), vkSS::eVertex); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addBindingDescription({0, sizeof(VertexObj)}); - gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, - {1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, - {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, - {3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); + gpb.addAttributeDescriptions({ + {0, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, pos))}, + {1, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, nrm))}, + {2, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, color))}, + {3, 0, vk::Format::eR32G32Sfloat, static_cast(offsetof(VertexObj, texCoord))}, + }); m_graphicsPipeline = gpb.createPipeline(); m_debug.setObjectName(m_graphicsPipeline, "Graphics"); @@ -840,8 +842,9 @@ void HelloVulkan::createRtPipeline() rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setLayout(m_rtPipelineLayout); - m_rtPipeline = static_cast( - m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); + + m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value; + m_device.destroy(raygenSM); m_device.destroy(missSM); diff --git a/ray_tracing_reflections/hello_vulkan.h b/ray_tracing_reflections/hello_vulkan.h index b3554e8..6e3e13c 100644 --- a/ray_tracing_reflections/hello_vulkan.h +++ b/ray_tracing_reflections/hello_vulkan.h @@ -23,7 +23,7 @@ #include "nvvk/appbase_vkpp.hpp" #include "nvvk/debug_util_vk.hpp" #include "nvvk/descriptorsets_vk.hpp" -#include "nvvk/resourceallocator_vk.hpp" +#include "nvvk/memallocator_dma_vk.hpp" // #VKRay #include "nvvk/raytraceKHR_vk.hpp" @@ -101,9 +101,8 @@ public: nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances std::vector m_textures; // vector of all textures of the scene - nvvk::ResourceAllocatorDedicated - m_alloc; // Allocator for buffer, images, acceleration structures - nvvk::DebugUtil m_debug; // Utility to name objects + nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures + nvvk::DebugUtil m_debug; // Utility to name objects // #Post void createOffscreenRender(); @@ -123,7 +122,7 @@ public: nvvk::Texture m_offscreenColor; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_offscreenDepth; - vk::Format m_offscreenDepthFormat; + vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32}; // #VKRay void initRayTracing(); @@ -152,8 +151,8 @@ public: { nvmath::vec4f clearColor; nvmath::vec3f lightPosition; - float lightIntensity; - int lightType; + float lightIntensity{100.0f}; + int lightType{0}; int maxDepth{10}; } m_rtPushConstants; }; diff --git a/ray_tracing_reflections/main.cpp b/ray_tracing_reflections/main.cpp index f345bab..d90dece 100644 --- a/ray_tracing_reflections/main.cpp +++ b/ray_tracing_reflections/main.cpp @@ -244,7 +244,7 @@ int main(int argc, char** argv) helloVk.updateUniformBuffer(cmdBuf); // Clearing screen - vk::ClearValue clearValues[2]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); clearValues[1].setDepthStencil({1.0f, 0}); @@ -253,7 +253,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(2); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -275,7 +275,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); diff --git a/ray_tracing_specialization/hello_vulkan.cpp b/ray_tracing_specialization/hello_vulkan.cpp index ba90f93..f1b7307 100644 --- a/ray_tracing_specialization/hello_vulkan.cpp +++ b/ray_tracing_specialization/hello_vulkan.cpp @@ -116,11 +116,11 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf) // void HelloVulkan::createDescriptorSetLayout() { - using vkDS = vk::DescriptorSetLayoutBinding; - using vkDT = vk::DescriptorType; - using vkSS = vk::ShaderStageFlagBits; - uint32_t nbTxt = static_cast(m_textures.size()); - uint32_t nbObj = static_cast(m_objModel.size()); + using vkDS = vk::DescriptorSetLayoutBinding; + using vkDT = vk::DescriptorType; + using vkSS = vk::ShaderStageFlagBits; + auto nbTxt = static_cast(m_textures.size()); + auto nbObj = static_cast(m_objModel.size()); // Camera matrices (binding = 0) m_descSetLayoutBind.addBinding( @@ -218,11 +218,12 @@ void HelloVulkan::createGraphicsPipeline() gpb.addShader(nvh::loadFile("spv/vert_shader.vert.spv", true, paths, true), vkSS::eVertex); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addBindingDescription({0, sizeof(VertexObj)}); - gpb.addAttributeDescriptions(std::vector{ - {0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, - {1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, - {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, - {3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); + gpb.addAttributeDescriptions({ + {0, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, pos))}, + {1, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, nrm))}, + {2, 0, vk::Format::eR32G32B32Sfloat, static_cast(offsetof(VertexObj, color))}, + {3, 0, vk::Format::eR32G32Sfloat, static_cast(offsetof(VertexObj, texCoord))}, + }); m_graphicsPipeline = gpb.createPipeline(); m_debug.setObjectName(m_graphicsPipeline, "Graphics"); @@ -867,7 +868,7 @@ void HelloVulkan::createRtPipeline() m_rtShaderGroups.push_back(mg); // Hit Group - Closest Hit + AnyHit - for(size_t i = 0; i < specializations.size(); i++) + for(auto& specialization : specializations) { vk::RayTracingShaderGroupCreateInfoKHR hg{vk::RayTracingShaderGroupTypeKHR::eTrianglesHitGroup, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR, @@ -877,7 +878,7 @@ void HelloVulkan::createRtPipeline() stage.stage = vk::ShaderStageFlagBits::eClosestHitKHR; stage.module = chitSM; stage.pName = "main"; - stage.pSpecializationInfo = specializations[i].getSpecialization(); + stage.pSpecializationInfo = specialization.getSpecialization(); stages.push_back(stage); m_rtShaderGroups.push_back(hg); } @@ -912,8 +913,8 @@ void HelloVulkan::createRtPipeline() rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setLayout(m_rtPipelineLayout); - m_rtPipeline = static_cast( - m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); + + m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value; m_sbtWrapper.create(m_rtPipeline, rayPipelineInfo); diff --git a/ray_tracing_specialization/hello_vulkan.h b/ray_tracing_specialization/hello_vulkan.h index fea5adc..f20cb9a 100644 --- a/ray_tracing_specialization/hello_vulkan.h +++ b/ray_tracing_specialization/hello_vulkan.h @@ -24,7 +24,7 @@ #include "nvvk/appbase_vkpp.hpp" #include "nvvk/debug_util_vk.hpp" #include "nvvk/descriptorsets_vk.hpp" -#include "nvvk/resourceallocator_vk.hpp" +#include "nvvk/memallocator_dma_vk.hpp" // #VKRay #include "nvvk/raytraceKHR_vk.hpp" @@ -104,9 +104,8 @@ public: nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances std::vector m_textures; // vector of all textures of the scene - nvvk::ResourceAllocatorDedicated - m_alloc; // Allocator for buffer, images, acceleration structures - nvvk::DebugUtil m_debug; // Utility to name objects + nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures + nvvk::DebugUtil m_debug; // Utility to name objects // #Post void createOffscreenRender(); @@ -126,7 +125,7 @@ public: nvvk::Texture m_offscreenColor; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; nvvk::Texture m_offscreenDepth; - vk::Format m_offscreenDepthFormat; + vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32}; // #VKRay void initRayTracing(); @@ -154,8 +153,8 @@ public: { nvmath::vec4f clearColor; nvmath::vec3f lightPosition; - float lightIntensity; - int lightType; - int specialization; + float lightIntensity{100.0f}; + int lightType{0}; + int specialization{7}; } m_rtPushConstants; }; diff --git a/ray_tracing_specialization/main.cpp b/ray_tracing_specialization/main.cpp index 9268aa1..7c6aeee 100644 --- a/ray_tracing_specialization/main.cpp +++ b/ray_tracing_specialization/main.cpp @@ -249,7 +249,7 @@ int main(int argc, char** argv) helloVk.updateUniformBuffer(cmdBuf); // Clearing screen - vk::ClearValue clearValues[2]; + std::array clearValues; clearValues[0].setColor( std::array({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); clearValues[1].setDepthStencil({1.0f, 0}); @@ -258,7 +258,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; offscreenRenderPassBeginInfo.setClearValueCount(2); - offscreenRenderPassBeginInfo.setPClearValues(clearValues); + offscreenRenderPassBeginInfo.setPClearValues(clearValues.data()); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); @@ -280,7 +280,7 @@ int main(int argc, char** argv) { vk::RenderPassBeginInfo postRenderPassBeginInfo; postRenderPassBeginInfo.setClearValueCount(2); - postRenderPassBeginInfo.setPClearValues(clearValues); + postRenderPassBeginInfo.setPClearValues(clearValues.data()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});