Bulk update NvPro-Samples 05/21/21

This commit is contained in:
Mathias Heyer 2021-05-21 16:15:58 -07:00
parent 3b0c3536e0
commit b3e6d84807
53 changed files with 359 additions and 366 deletions

View file

@ -24,6 +24,10 @@ endif()
set(TUTO_KHR_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 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 # Package shared by all projects

View file

@ -22,29 +22,6 @@
#include "obj_loader.h" #include "obj_loader.h"
#include "nvh/nvprint.hpp" #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) void ObjLoader::loadModel(const std::string& filename)
{ {

View file

@ -121,8 +121,8 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size()); auto nbTxt = static_cast<uint32_t>(m_textures.size());
uint32_t nbObj = static_cast<uint32_t>(m_objModel.size()); auto nbObj = static_cast<uint32_t>(m_objModel.size());
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
m_descSetLayoutBind.addBinding( 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/vert_shader.vert.spv", true, paths, true), vkSS::eVertex);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment);
gpb.addBindingDescription({0, sizeof(VertexObj)}); gpb.addBindingDescription({0, sizeof(VertexObj)});
gpb.addAttributeDescriptions(std::vector<vk::VertexInputAttributeDescription>{ gpb.addAttributeDescriptions({
{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, {0, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, pos))},
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, {1, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, nrm))},
{2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, {2, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, color))},
{3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); {3, 0, vk::Format::eR32G32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, texCoord))},
});
m_graphicsPipeline = gpb.createPipeline(); m_graphicsPipeline = gpb.createPipeline();
m_debug.setObjectName(m_graphicsPipeline, "Graphics"); m_debug.setObjectName(m_graphicsPipeline, "Graphics");

View file

@ -56,7 +56,6 @@ static void onErrorCallback(int error, const char* description)
// Extra UI // Extra UI
void renderUI(HelloVulkan& helloVk) void renderUI(HelloVulkan& helloVk)
{ {
static int item = 1;
bool changed = false; bool changed = false;
changed |= ImGuiH::CameraWidget(); changed |= ImGuiH::CameraWidget();
@ -315,7 +314,7 @@ int main(int argc, char** argv)
helloVk.updateUniformBuffer(cmdBuf); helloVk.updateUniformBuffer(cmdBuf);
// Clearing screen // Clearing screen
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
@ -324,7 +323,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(2); offscreenRenderPassBeginInfo.setClearValueCount(2);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(offscreen.renderPass()); offscreenRenderPassBeginInfo.setRenderPass(offscreen.renderPass());
offscreenRenderPassBeginInfo.setFramebuffer(offscreen.frameBuffer()); offscreenRenderPassBeginInfo.setFramebuffer(offscreen.frameBuffer());
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -346,7 +345,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});

View file

@ -75,6 +75,6 @@ struct ImplInst
std::vector<MaterialObj> implMat; // All materials used by implicit obj std::vector<MaterialObj> implMat; // All materials used by implicit obj
nvvk::Buffer implBuf; // Buffer of objects nvvk::Buffer implBuf; // Buffer of objects
nvvk::Buffer implMatBuf; // Buffer of material nvvk::Buffer implMatBuf; // Buffer of material
int blasId; int blasId{0};
nvmath::mat4f transform{1}; nvmath::mat4f transform{1};
}; };

View file

@ -62,7 +62,7 @@ private:
nvvk::Texture m_colorTexture; nvvk::Texture m_colorTexture;
vk::Format m_colorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_colorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_depthTexture; nvvk::Texture m_depthTexture;
vk::Format m_depthFormat; vk::Format m_depthFormat{vk::Format::eX8D24UnormPack32};
nvvk::ResourceAllocator* m_alloc{ nvvk::ResourceAllocator* m_alloc{
nullptr}; // Allocator for buffer, images, acceleration structures nullptr}; // Allocator for buffer, images, acceleration structures

View file

@ -360,9 +360,8 @@ void Raytracer::createRtPipeline(vk::DescriptorSetLayout& sceneDescLayout)
rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth
rayPipelineInfo.setLayout(m_rtPipelineLayout); rayPipelineInfo.setLayout(m_rtPipelineLayout);
m_rtPipeline = static_cast<const vk::Pipeline&>(
m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo));
m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value;
m_sbtWrapper.create(m_rtPipeline, rayPipelineInfo); m_sbtWrapper.create(m_rtPipeline, rayPipelineInfo);

View file

@ -72,7 +72,7 @@ private:
{ {
nvmath::vec4f clearColor; nvmath::vec4f clearColor;
nvmath::vec3f lightPosition; nvmath::vec3f lightPosition;
float lightIntensity; float lightIntensity{100.0f};
nvmath::vec3f lightDirection{-1, -1, -1}; nvmath::vec3f lightDirection{-1, -1, -1};
float lightSpotCutoff{deg2rad(12.5f)}; float lightSpotCutoff{deg2rad(12.5f)};
float lightSpotOuterCutoff{deg2rad(17.5f)}; float lightSpotOuterCutoff{deg2rad(17.5f)};

View file

@ -111,8 +111,8 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size()); auto nbTxt = static_cast<uint32_t>(m_textures.size());
uint32_t nbObj = static_cast<uint32_t>(m_objModel.size()); auto nbObj = static_cast<uint32_t>(m_objModel.size());
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
m_descSetLayoutBind.addBinding(vkDS(0, vkDT::eUniformBuffer, 1, vkSS::eVertex)); m_descSetLayoutBind.addBinding(vkDS(0, vkDT::eUniformBuffer, 1, vkSS::eVertex));
@ -150,19 +150,19 @@ void HelloVulkan::updateDescriptorSet()
// All material buffers, 1 buffer per OBJ // All material buffers, 1 buffer per OBJ
std::vector<vk::DescriptorBufferInfo> dbiMat; std::vector<vk::DescriptorBufferInfo> dbiMat;
std::vector<vk::DescriptorBufferInfo> dbiMatIdx; std::vector<vk::DescriptorBufferInfo> 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}); dbiMat.emplace_back(m.matColorBuffer.buffer, 0, VK_WHOLE_SIZE);
dbiMatIdx.push_back({m_objModel[i].matIndexBuffer.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, 1, dbiMat.data()));
writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, 4, dbiMatIdx.data())); writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, 4, dbiMatIdx.data()));
// All texture samplers // All texture samplers
std::vector<vk::DescriptorImageInfo> diit; std::vector<vk::DescriptorImageInfo> 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())); 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/vert_shader.vert.spv", true, paths, true), vkSS::eVertex);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment);
gpb.addBindingDescription({0, sizeof(VertexObj)}); gpb.addBindingDescription({0, sizeof(VertexObj)});
gpb.addAttributeDescriptions(std::vector<vk::VertexInputAttributeDescription>{ gpb.addAttributeDescriptions({
{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, {0, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, pos))},
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, {1, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, nrm))},
{2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, {2, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, color))},
{3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); {3, 0, vk::Format::eR32G32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, texCoord))},
});
m_graphicsPipeline = gpb.createPipeline(); m_graphicsPipeline = gpb.createPipeline();
m_debug.setObjectName(m_graphicsPipeline, "Graphics"); m_debug.setObjectName(m_graphicsPipeline, "Graphics");

View file

@ -18,11 +18,12 @@
*/ */
#pragma once #pragma once
#include <vulkan/vulkan.hpp>
#include "nvvk/appbase_vkpp.hpp" #include "nvvk/appbase_vkpp.hpp"
#include "nvvk/debug_util_vk.hpp" #include "nvvk/debug_util_vk.hpp"
#include "nvvk/descriptorsets_vk.hpp" #include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/memallocator_dma_vk.hpp"
#include "nvvk/resourceallocator_vk.hpp" #include "nvvk/resourceallocator_vk.hpp"
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -99,8 +100,7 @@ public:
std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene
nvvk::ResourceAllocatorDedicated nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures
m_alloc; // Allocator for buffer, images, acceleration structures
nvvk::DebugUtil m_debug; // Utility to name objects nvvk::DebugUtil m_debug; // Utility to name objects
@ -122,5 +122,5 @@ public:
nvvk::Texture m_offscreenColor; nvvk::Texture m_offscreenColor;
vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_offscreenDepth; nvvk::Texture m_offscreenDepth;
vk::Format m_offscreenDepthFormat; vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32};
}; };

View file

@ -216,7 +216,7 @@ int main(int argc, char** argv)
// Clearing screen // Clearing screen
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
@ -225,7 +225,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(2); offscreenRenderPassBeginInfo.setClearValueCount(2);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass);
offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer);
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -241,7 +241,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});

View file

@ -118,8 +118,8 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size()); auto nbTxt = static_cast<uint32_t>(m_textures.size());
uint32_t nbObj = static_cast<uint32_t>(m_objModel.size()); auto nbObj = static_cast<uint32_t>(m_objModel.size());
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
m_descSetLayoutBind.addBinding( 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/vert_shader.vert.spv", true, paths, true), vkSS::eVertex);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment);
gpb.addBindingDescription({0, sizeof(VertexObj)}); gpb.addBindingDescription({0, sizeof(VertexObj)});
gpb.addAttributeDescriptions(std::vector<vk::VertexInputAttributeDescription>{ gpb.addAttributeDescriptions({
{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, {0, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, pos))},
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, {1, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, nrm))},
{2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, {2, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, color))},
{3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); {3, 0, vk::Format::eR32G32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, texCoord))},
});
m_graphicsPipeline = gpb.createPipeline(); m_graphicsPipeline = gpb.createPipeline();
m_debug.setObjectName(m_graphicsPipeline, "Graphics"); m_debug.setObjectName(m_graphicsPipeline, "Graphics");
@ -857,8 +858,9 @@ void HelloVulkan::createRtPipeline()
rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth
rayPipelineInfo.setLayout(m_rtPipelineLayout); rayPipelineInfo.setLayout(m_rtPipelineLayout);
m_rtPipeline = static_cast<const vk::Pipeline&>(
m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value;
// Spec only guarantees 1 level of "recursion". Check for that sad possibility here. // Spec only guarantees 1 level of "recursion". Check for that sad possibility here.
if(m_rtProperties.maxRayRecursionDepth <= 1) if(m_rtProperties.maxRayRecursionDepth <= 1)

View file

@ -20,11 +20,10 @@
#pragma once #pragma once
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#include "nvvk/appbase_vkpp.hpp" #include "nvvk/appbase_vkpp.hpp"
#include "nvvk/debug_util_vk.hpp" #include "nvvk/debug_util_vk.hpp"
#include "nvvk/descriptorsets_vk.hpp" #include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/resourceallocator_vk.hpp" #include "nvvk/memallocator_dma_vk.hpp"
// #VKRay // #VKRay
#include "nvvk/raytraceKHR_vk.hpp" #include "nvvk/raytraceKHR_vk.hpp"
@ -102,8 +101,7 @@ public:
nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances
std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene
nvvk::ResourceAllocatorDedicated nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures
m_alloc; // Allocator for buffer, images, acceleration structures
nvvk::DebugUtil m_debug; // Utility to name objects nvvk::DebugUtil m_debug; // Utility to name objects
// #Post // #Post
@ -124,7 +122,7 @@ public:
nvvk::Texture m_offscreenColor; nvvk::Texture m_offscreenColor;
vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_offscreenDepth; nvvk::Texture m_offscreenDepth;
vk::Format m_offscreenDepthFormat; vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32};
// #VKRay // #VKRay
void initRayTracing(); void initRayTracing();

View file

@ -239,7 +239,7 @@ int main(int argc, char** argv)
helloVk.updateUniformBuffer(cmdBuf); helloVk.updateUniformBuffer(cmdBuf);
// Clearing screen // Clearing screen
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
@ -248,7 +248,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(2); offscreenRenderPassBeginInfo.setClearValueCount(2);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass);
offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer);
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -270,7 +270,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});

View file

@ -118,8 +118,8 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size()); auto nbTxt = static_cast<uint32_t>(m_textures.size());
uint32_t nbObj = static_cast<uint32_t>(m_objModel.size()); auto nbObj = static_cast<uint32_t>(m_objModel.size());
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
m_descSetLayoutBind.addBinding( 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/vert_shader.vert.spv", true, paths, true), vkSS::eVertex);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment);
gpb.addBindingDescription({0, sizeof(VertexObj)}); gpb.addBindingDescription({0, sizeof(VertexObj)});
gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, gpb.addAttributeDescriptions({
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, {0, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, pos))},
{2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, {1, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, nrm))},
{3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); {2, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, color))},
{3, 0, vk::Format::eR32G32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, texCoord))},
});
m_graphicsPipeline = gpb.createPipeline(); m_graphicsPipeline = gpb.createPipeline();
m_debug.setObjectName(m_graphicsPipeline, "Graphics"); m_debug.setObjectName(m_graphicsPipeline, "Graphics");
@ -851,8 +853,7 @@ void HelloVulkan::createRtPipeline()
rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth
rayPipelineInfo.setLayout(m_rtPipelineLayout); rayPipelineInfo.setLayout(m_rtPipelineLayout);
m_rtPipeline = static_cast<const vk::Pipeline&>( m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value;
m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo));
m_sbtWrapper.create(m_rtPipeline, rayPipelineInfo); m_sbtWrapper.create(m_rtPipeline, rayPipelineInfo);
@ -898,7 +899,7 @@ void HelloVulkan::raytrace(const vk::CommandBuffer& cmdBuf, const nvmath::vec4f&
void HelloVulkan::animationInstances(float time) void HelloVulkan::animationInstances(float time)
{ {
const int32_t nbWuson = static_cast<int32_t>(m_objInstance.size() - 2); const auto nbWuson = static_cast<int32_t>(m_objInstance.size() - 2);
const float deltaAngle = 6.28318530718f / static_cast<float>(nbWuson); const float deltaAngle = 6.28318530718f / static_cast<float>(nbWuson);
const float wusonLength = 3.f; const float wusonLength = 3.f;
const float radius = wusonLength / (2.f * sin(deltaAngle / 2.0f)); const float radius = wusonLength / (2.f * sin(deltaAngle / 2.0f));
@ -986,7 +987,7 @@ void HelloVulkan::createCompPipelines()
computePipelineCreateInfo.stage = nvvk::createShaderStageInfo( computePipelineCreateInfo.stage = nvvk::createShaderStageInfo(
m_device, nvh::loadFile("spv/anim.comp.spv", true, defaultSearchPaths, true), m_device, nvh::loadFile("spv/anim.comp.spv", true, defaultSearchPaths, true),
VK_SHADER_STAGE_COMPUTE_BIT); VK_SHADER_STAGE_COMPUTE_BIT);
m_compPipeline = static_cast<const vk::Pipeline&>(
m_device.createComputePipeline({}, computePipelineCreateInfo)); m_compPipeline = m_device.createComputePipeline({}, computePipelineCreateInfo).value;
m_device.destroy(computePipelineCreateInfo.stage.module); m_device.destroy(computePipelineCreateInfo.stage.module);
} }

View file

@ -23,7 +23,7 @@
#include "nvvk/appbase_vkpp.hpp" #include "nvvk/appbase_vkpp.hpp"
#include "nvvk/debug_util_vk.hpp" #include "nvvk/debug_util_vk.hpp"
#include "nvvk/descriptorsets_vk.hpp" #include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/resourceallocator_vk.hpp" #include "nvvk/memallocator_dma_vk.hpp"
// #VKRay // #VKRay
#include "nvvk/raytraceKHR_vk.hpp" #include "nvvk/raytraceKHR_vk.hpp"
@ -102,8 +102,7 @@ public:
nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances
std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene
nvvk::ResourceAllocatorDedicated nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures
m_alloc; // Allocator for buffer, images, acceleration structures
nvvk::DebugUtil m_debug; // Utility to name objects nvvk::DebugUtil m_debug; // Utility to name objects
// #Post // #Post
@ -124,7 +123,7 @@ public:
nvvk::Texture m_offscreenColor; nvvk::Texture m_offscreenColor;
vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_offscreenDepth; nvvk::Texture m_offscreenDepth;
vk::Format m_offscreenDepthFormat; vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32};
// #VKRay // #VKRay
void initRayTracing(); void initRayTracing();
@ -155,8 +154,8 @@ public:
{ {
nvmath::vec4f clearColor; nvmath::vec4f clearColor;
nvmath::vec3f lightPosition; nvmath::vec3f lightPosition;
float lightIntensity; float lightIntensity{100.0f};
int lightType; int lightType{0};
} m_rtPushConstants; } m_rtPushConstants;
// #VK_animation // #VK_animation

View file

@ -253,7 +253,7 @@ int main(int argc, char** argv)
helloVk.updateUniformBuffer(cmdBuf); helloVk.updateUniformBuffer(cmdBuf);
// Clearing screen // Clearing screen
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
@ -262,7 +262,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(2); offscreenRenderPassBeginInfo.setClearValueCount(2);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass);
offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer);
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -284,7 +284,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});

View file

@ -118,8 +118,8 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size()); auto nbTxt = static_cast<uint32_t>(m_textures.size());
uint32_t nbObj = static_cast<uint32_t>(m_objModel.size()); auto nbObj = static_cast<uint32_t>(m_objModel.size());
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
m_descSetLayoutBind.addBinding( 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/vert_shader.vert.spv", true, paths, true), vkSS::eVertex);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment);
gpb.addBindingDescription({0, sizeof(VertexObj)}); gpb.addBindingDescription({0, sizeof(VertexObj)});
gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, gpb.addAttributeDescriptions({
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, {0, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, pos))},
{2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, {1, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, nrm))},
{3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); {2, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, color))},
{3, 0, vk::Format::eR32G32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, texCoord))},
});
m_graphicsPipeline = gpb.createPipeline(); m_graphicsPipeline = gpb.createPipeline();
m_debug.setObjectName(m_graphicsPipeline, "Graphics"); m_debug.setObjectName(m_graphicsPipeline, "Graphics");

View file

@ -23,7 +23,7 @@
#include "nvvk/appbase_vkpp.hpp" #include "nvvk/appbase_vkpp.hpp"
#include "nvvk/debug_util_vk.hpp" #include "nvvk/debug_util_vk.hpp"
#include "nvvk/descriptorsets_vk.hpp" #include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/resourceallocator_vk.hpp" #include "nvvk/memallocator_dma_vk.hpp"
// #VKRay // #VKRay
#include "nvvk/raytraceKHR_vk.hpp" #include "nvvk/raytraceKHR_vk.hpp"
@ -101,8 +101,7 @@ public:
nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances
std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene
nvvk::ResourceAllocatorDedicated nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures
m_alloc; // Allocator for buffer, images, acceleration structures
nvvk::DebugUtil m_debug; // Utility to name objects nvvk::DebugUtil m_debug; // Utility to name objects
// #Post // #Post
@ -123,7 +122,7 @@ public:
nvvk::Texture m_offscreenColor; nvvk::Texture m_offscreenColor;
vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_offscreenDepth; nvvk::Texture m_offscreenDepth;
vk::Format m_offscreenDepthFormat; vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32};
// #VKRay // #VKRay
void initRayTracing(); void initRayTracing();
@ -154,8 +153,8 @@ public:
{ {
nvmath::vec4f clearColor; nvmath::vec4f clearColor;
nvmath::vec3f lightPosition; nvmath::vec3f lightPosition;
float lightIntensity; float lightIntensity{100.0f};
int lightType; int lightType{0};
int frame{0}; int frame{0};
} m_rtPushConstants; } m_rtPushConstants;
}; };

View file

@ -242,7 +242,7 @@ int main(int argc, char** argv)
helloVk.updateUniformBuffer(cmdBuf); helloVk.updateUniformBuffer(cmdBuf);
// Clearing screen // Clearing screen
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
@ -251,7 +251,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(2); offscreenRenderPassBeginInfo.setClearValueCount(2);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass);
offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer);
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -273,7 +273,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});

View file

@ -117,8 +117,8 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size()); auto nbTxt = static_cast<uint32_t>(m_textures.size());
uint32_t nbObj = static_cast<uint32_t>(m_objModel.size()); auto nbObj = static_cast<uint32_t>(m_objModel.size());
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
m_descSetLayoutBind.addBinding(vkDS(0, vkDT::eUniformBuffer, 1, vkSS::eVertex)); 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/vert_shader.vert.spv", true, paths, true), vkSS::eVertex);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment);
gpb.addBindingDescription({0, sizeof(VertexObj)}); gpb.addBindingDescription({0, sizeof(VertexObj)});
gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, gpb.addAttributeDescriptions({
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, {0, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, pos))},
{2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, {1, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, nrm))},
{3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); {2, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, color))},
{3, 0, vk::Format::eR32G32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, texCoord))},
});
vk::PipelineColorBlendAttachmentState res; vk::PipelineColorBlendAttachmentState res;
res.colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG res.colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG
| vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA; | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA;
@ -645,9 +648,9 @@ void HelloVulkan::createPostDescriptor()
void HelloVulkan::updatePostDescriptorSet() void HelloVulkan::updatePostDescriptorSet()
{ {
std::vector<vk::WriteDescriptorSet> writes; std::vector<vk::WriteDescriptorSet> writes;
writes.push_back( writes.emplace_back(
m_postDescSetLayoutBind.makeWrite(m_postDescSet, 0, &m_offscreenColor.descriptor)); 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<uint32_t>(writes.size()), writes.data(), 0, nullptr); m_device.updateDescriptorSets(static_cast<uint32_t>(writes.size()), writes.data(), 0, nullptr);
} }
@ -816,8 +819,7 @@ void HelloVulkan::createCompPipelines()
nvvk::createShaderStageInfo(m_device, nvvk::createShaderStageInfo(m_device,
nvh::loadFile("spv/ao.comp.spv", true, defaultSearchPaths, true), nvh::loadFile("spv/ao.comp.spv", true, defaultSearchPaths, true),
VK_SHADER_STAGE_COMPUTE_BIT); VK_SHADER_STAGE_COMPUTE_BIT);
m_compPipeline = static_cast<const vk::Pipeline&>( m_compPipeline = m_device.createComputePipeline({}, computePipelineCreateInfo).value;
m_device.createComputePipeline({}, computePipelineCreateInfo));
m_device.destroy(computePipelineCreateInfo.stage.module); m_device.destroy(computePipelineCreateInfo.stage.module);
} }

View file

@ -23,7 +23,7 @@
#include "nvvk/appbase_vkpp.hpp" #include "nvvk/appbase_vkpp.hpp"
#include "nvvk/debug_util_vk.hpp" #include "nvvk/debug_util_vk.hpp"
#include "nvvk/descriptorsets_vk.hpp" #include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/resourceallocator_vk.hpp" #include "nvvk/memallocator_dma_vk.hpp"
// #VKRay // #VKRay
#include "nvvk/raytraceKHR_vk.hpp" #include "nvvk/raytraceKHR_vk.hpp"
@ -112,8 +112,7 @@ public:
nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances
std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene
nvvk::ResourceAllocatorDedicated nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures
m_alloc; // Allocator for buffer, images, acceleration structures
nvvk::DebugUtil m_debug; // Utility to name objects nvvk::DebugUtil m_debug; // Utility to name objects
// #Post // #Post
@ -136,7 +135,7 @@ public:
nvvk::Texture m_aoBuffer; nvvk::Texture m_aoBuffer;
vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_offscreenDepth; nvvk::Texture m_offscreenDepth;
vk::Format m_offscreenDepthFormat; vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32};
// #Tuto_rayquery // #Tuto_rayquery
void initRayTracing(); void initRayTracing();

View file

@ -260,7 +260,7 @@ int main(int argc, char** argv)
helloVk.updateUniformBuffer(cmdBuf); helloVk.updateUniformBuffer(cmdBuf);
// Clearing screen // Clearing screen
vk::ClearValue clearValues[3]; std::array<vk::ClearValue, 3> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
@ -271,7 +271,7 @@ int main(int argc, char** argv)
clearValues[2].setDepthStencil({1.0f, 0}); clearValues[2].setDepthStencil({1.0f, 0});
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(3); offscreenRenderPassBeginInfo.setClearValueCount(3);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass);
offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer);
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -290,7 +290,7 @@ int main(int argc, char** argv)
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});

View file

@ -118,8 +118,8 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size()); auto nbTxt = static_cast<uint32_t>(m_textures.size());
uint32_t nbObj = static_cast<uint32_t>(m_objModel.size()); auto nbObj = static_cast<uint32_t>(m_objModel.size());
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
m_descSetLayoutBind.addBinding( 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/vert_shader.vert.spv", true, paths, true), vkSS::eVertex);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment);
gpb.addBindingDescription({0, sizeof(VertexObj)}); gpb.addBindingDescription({0, sizeof(VertexObj)});
gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, gpb.addAttributeDescriptions({
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, {0, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, pos))},
{2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, {1, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, nrm))},
{3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); {2, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, color))},
{3, 0, vk::Format::eR32G32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, texCoord))},
});
m_graphicsPipeline = gpb.createPipeline(); m_graphicsPipeline = gpb.createPipeline();
m_debug.setObjectName(m_graphicsPipeline, "Graphics"); m_debug.setObjectName(m_graphicsPipeline, "Graphics");
@ -870,8 +872,9 @@ void HelloVulkan::createRtPipeline()
rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth
rayPipelineInfo.setLayout(m_rtPipelineLayout); rayPipelineInfo.setLayout(m_rtPipelineLayout);
m_rtPipeline = static_cast<const vk::Pipeline&>(
m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value;
m_sbtWrapper.create(m_rtPipeline, rayPipelineInfo); m_sbtWrapper.create(m_rtPipeline, rayPipelineInfo);

View file

@ -23,7 +23,7 @@
#include "nvvk/appbase_vkpp.hpp" #include "nvvk/appbase_vkpp.hpp"
#include "nvvk/debug_util_vk.hpp" #include "nvvk/debug_util_vk.hpp"
#include "nvvk/descriptorsets_vk.hpp" #include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/resourceallocator_vk.hpp" #include "nvvk/memallocator_dma_vk.hpp"
// #VKRay // #VKRay
#include "nvvk/raytraceKHR_vk.hpp" #include "nvvk/raytraceKHR_vk.hpp"
@ -106,8 +106,7 @@ public:
nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances
std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene
nvvk::ResourceAllocatorDedicated nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures
m_alloc; // Allocator for buffer, images, acceleration structures
nvvk::DebugUtil m_debug; // Utility to name objects nvvk::DebugUtil m_debug; // Utility to name objects
// #Post // #Post
@ -128,7 +127,7 @@ public:
nvvk::Texture m_offscreenColor; nvvk::Texture m_offscreenColor;
vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_offscreenDepth; nvvk::Texture m_offscreenDepth;
vk::Format m_offscreenDepthFormat; vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32};
// #VKRay // #VKRay
void initRayTracing(); void initRayTracing();

View file

@ -253,7 +253,7 @@ int main(int argc, char** argv)
helloVk.updateUniformBuffer(cmdBuf); helloVk.updateUniformBuffer(cmdBuf);
// Clearing screen // Clearing screen
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
@ -262,7 +262,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(2); offscreenRenderPassBeginInfo.setClearValueCount(2);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass);
offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer);
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -284,7 +284,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});

View file

@ -123,7 +123,6 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size());
auto& bind = m_descSetLayoutBind; auto& bind = m_descSetLayoutBind;
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
@ -417,7 +416,6 @@ void HelloVulkan::destroyResources()
void HelloVulkan::rasterize(const vk::CommandBuffer& cmdBuf) void HelloVulkan::rasterize(const vk::CommandBuffer& cmdBuf)
{ {
using vkPBP = vk::PipelineBindPoint; using vkPBP = vk::PipelineBindPoint;
using vkSS = vk::ShaderStageFlagBits;
std::vector<vk::DeviceSize> offsets = {0, 0, 0}; std::vector<vk::DeviceSize> offsets = {0, 0, 0};
@ -691,7 +689,6 @@ void HelloVulkan::createTopLevelAS()
{ {
std::vector<nvvk::RaytracingBuilderKHR::Instance> tlas; std::vector<nvvk::RaytracingBuilderKHR::Instance> tlas;
tlas.reserve(m_gltfScene.m_nodes.size()); tlas.reserve(m_gltfScene.m_nodes.size());
uint32_t instID = 0;
for(auto& node : m_gltfScene.m_nodes) for(auto& node : m_gltfScene.m_nodes)
{ {
nvvk::RaytracingBuilderKHR::Instance rayInst; nvvk::RaytracingBuilderKHR::Instance rayInst;
@ -834,8 +831,9 @@ void HelloVulkan::createRtPipeline()
rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth
rayPipelineInfo.setLayout(m_rtPipelineLayout); rayPipelineInfo.setLayout(m_rtPipelineLayout);
m_rtPipeline = static_cast<const vk::Pipeline&>(
m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value;
// Creating the SBT // Creating the SBT

View file

@ -24,7 +24,6 @@
#include "nvvk/appbase_vkpp.hpp" #include "nvvk/appbase_vkpp.hpp"
#include "nvvk/debug_util_vk.hpp" #include "nvvk/debug_util_vk.hpp"
#include "nvvk/descriptorsets_vk.hpp" #include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/resourceallocator_vk.hpp"
#include "nvvk/memallocator_dma_vk.hpp" #include "nvvk/memallocator_dma_vk.hpp"
// #VKRay // #VKRay
@ -119,7 +118,7 @@ public:
nvvk::Texture m_offscreenColor; nvvk::Texture m_offscreenColor;
vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_offscreenDepth; nvvk::Texture m_offscreenDepth;
vk::Format m_offscreenDepthFormat; vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32};
// #VKRay // #VKRay
auto primitiveToGeometry(const nvh::GltfPrimMesh& prim); auto primitiveToGeometry(const nvh::GltfPrimMesh& prim);

View file

@ -236,7 +236,7 @@ int main(int argc, char** argv)
helloVk.updateUniformBuffer(cmdBuf); helloVk.updateUniformBuffer(cmdBuf);
// Clearing screen // Clearing screen
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
@ -245,7 +245,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(2); offscreenRenderPassBeginInfo.setClearValueCount(2);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass);
offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer);
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -267,7 +267,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});

View file

@ -119,8 +119,8 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size()); auto nbTxt = static_cast<uint32_t>(m_textures.size());
uint32_t nbObj = static_cast<uint32_t>(m_objModel.size()); auto nbObj = static_cast<uint32_t>(m_objModel.size());
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
m_descSetLayoutBind.addBinding( 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/vert_shader.vert.spv", true, paths, true), vkSS::eVertex);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment);
gpb.addBindingDescription({0, sizeof(VertexObj)}); gpb.addBindingDescription({0, sizeof(VertexObj)});
gpb.addAttributeDescriptions(std::vector<vk::VertexInputAttributeDescription>{ gpb.addAttributeDescriptions({
{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, {0, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, pos))},
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, {1, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, nrm))},
{2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, {2, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, color))},
{3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); {3, 0, vk::Format::eR32G32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, texCoord))},
});
m_graphicsPipeline = gpb.createPipeline(); m_graphicsPipeline = gpb.createPipeline();
m_debug.setObjectName(m_graphicsPipeline, "Graphics"); m_debug.setObjectName(m_graphicsPipeline, "Graphics");
@ -821,7 +822,7 @@ void HelloVulkan::createLanternModel()
vk::DeviceAddress vertexAddress = m_device.getBufferAddress({m_lanternVertexBuffer.buffer}); vk::DeviceAddress vertexAddress = m_device.getBufferAddress({m_lanternVertexBuffer.buffer});
vk::DeviceAddress indexAddress = m_device.getBufferAddress({m_lanternIndexBuffer.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. // Describe buffer as packed array of float vec3.
vk::AccelerationStructureGeometryTrianglesDataKHR triangles; vk::AccelerationStructureGeometryTrianglesDataKHR triangles;
@ -1151,8 +1152,9 @@ void HelloVulkan::createRtPipeline()
rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth
rayPipelineInfo.setLayout(m_rtPipelineLayout); rayPipelineInfo.setLayout(m_rtPipelineLayout);
m_rtPipeline = static_cast<const vk::Pipeline&>(
m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value;
m_device.destroy(raygenSM); m_device.destroy(raygenSM);
m_device.destroy(missSM); m_device.destroy(missSM);
@ -1265,8 +1267,7 @@ void HelloVulkan::createLanternIndirectCompPipeline()
vk::ComputePipelineCreateInfo pipelineInfo; vk::ComputePipelineCreateInfo pipelineInfo;
pipelineInfo.setStage(stageInfo); pipelineInfo.setStage(stageInfo);
pipelineInfo.setLayout(m_lanternIndirectCompPipelineLayout); pipelineInfo.setLayout(m_lanternIndirectCompPipelineLayout);
m_lanternIndirectCompPipeline = m_lanternIndirectCompPipeline = m_device.createComputePipeline({}, pipelineInfo).value;
static_cast<const vk::Pipeline&>(m_device.createComputePipeline({}, pipelineInfo));
m_device.destroy(computeShader); m_device.destroy(computeShader);
} }

View file

@ -24,7 +24,7 @@
#include "nvvk/appbase_vkpp.hpp" #include "nvvk/appbase_vkpp.hpp"
#include "nvvk/debug_util_vk.hpp" #include "nvvk/debug_util_vk.hpp"
#include "nvvk/descriptorsets_vk.hpp" #include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/resourceallocator_vk.hpp" #include "nvvk/memallocator_dma_vk.hpp"
// #VKRay // #VKRay
#include "nvvk/raytraceKHR_vk.hpp" #include "nvvk/raytraceKHR_vk.hpp"
@ -141,8 +141,7 @@ public:
nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances
std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene
nvvk::ResourceAllocatorDedicated nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures
m_alloc; // Allocator for buffer, images, acceleration structures
nvvk::DebugUtil m_debug; // Utility to name objects nvvk::DebugUtil m_debug; // Utility to name objects
// #Post // #Post
@ -163,7 +162,7 @@ public:
nvvk::Texture m_offscreenColor; nvvk::Texture m_offscreenColor;
vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_offscreenDepth; nvvk::Texture m_offscreenDepth;
vk::Format m_offscreenDepthFormat; vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32};
// #VKRay // #VKRay
void initRayTracing(); void initRayTracing();

View file

@ -251,7 +251,7 @@ int main(int argc, char** argv)
helloVk.updateUniformBuffer(cmdBuf); helloVk.updateUniformBuffer(cmdBuf);
// Clearing screen // Clearing screen
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
@ -260,7 +260,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(2); offscreenRenderPassBeginInfo.setClearValueCount(2);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass);
offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer);
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -282,7 +282,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});

View file

@ -119,8 +119,8 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size()); auto nbTxt = static_cast<uint32_t>(m_textures.size());
uint32_t nbObj = static_cast<uint32_t>(m_objModel.size()); auto nbObj = static_cast<uint32_t>(m_objModel.size());
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
m_descSetLayoutBind.addBinding( 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/vert_shader.vert.spv", true, paths, true), vkSS::eVertex);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment);
gpb.addBindingDescription({0, sizeof(VertexObj)}); gpb.addBindingDescription({0, sizeof(VertexObj)});
gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, gpb.addAttributeDescriptions({
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, {0, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, pos))},
{2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, {1, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, nrm))},
{3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); {2, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, color))},
{3, 0, vk::Format::eR32G32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, texCoord))},
});
m_graphicsPipeline = gpb.createPipeline(); m_graphicsPipeline = gpb.createPipeline();
m_debug.setObjectName(m_graphicsPipeline, "Graphics"); m_debug.setObjectName(m_graphicsPipeline, "Graphics");
@ -843,8 +845,8 @@ void HelloVulkan::createRtPipeline()
rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth
rayPipelineInfo.setLayout(m_rtPipelineLayout); rayPipelineInfo.setLayout(m_rtPipelineLayout);
m_rtPipeline = static_cast<const vk::Pipeline&>(
m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value;
m_sbtWrapper.create(m_rtPipeline, rayPipelineInfo); m_sbtWrapper.create(m_rtPipeline, rayPipelineInfo);

View file

@ -22,9 +22,9 @@
// #VKRay // #VKRay
// //
// Choosing the allocator to use // Choosing the allocator to use
#define ALLOC_DMA //#define ALLOC_DMA
//#define ALLOC_DEDICATED //#define ALLOC_DEDICATED
//#define ALLOC_VMA #define ALLOC_VMA
#include <nvvk/resourceallocator_vk.hpp> #include <nvvk/resourceallocator_vk.hpp>
#if defined(ALLOC_DMA) #if defined(ALLOC_DMA)
@ -141,7 +141,7 @@ public:
nvvk::Texture m_offscreenColor; nvvk::Texture m_offscreenColor;
vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_offscreenDepth; nvvk::Texture m_offscreenDepth;
vk::Format m_offscreenDepthFormat; vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32};
// #VKRay // #VKRay
void initRayTracing(); void initRayTracing();

View file

@ -286,7 +286,7 @@ int main(int argc, char** argv)
helloVk.updateUniformBuffer(cmdBuf); helloVk.updateUniformBuffer(cmdBuf);
// Clearing screen // Clearing screen
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
@ -295,7 +295,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(2); offscreenRenderPassBeginInfo.setClearValueCount(2);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass);
offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer);
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -317,7 +317,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});

View file

@ -118,8 +118,8 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size()); auto nbTxt = static_cast<uint32_t>(m_textures.size());
uint32_t nbObj = static_cast<uint32_t>(m_objModel.size()); auto nbObj = static_cast<uint32_t>(m_objModel.size());
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
m_descSetLayoutBind.addBinding( 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/vert_shader.vert.spv", true, paths, true), vkSS::eVertex);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment);
gpb.addBindingDescription({0, sizeof(VertexObj)}); gpb.addBindingDescription({0, sizeof(VertexObj)});
gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, gpb.addAttributeDescriptions({
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, {0, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, pos))},
{2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, {1, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, nrm))},
{3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); {2, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, color))},
{3, 0, vk::Format::eR32G32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, texCoord))},
});
m_graphicsPipeline = gpb.createPipeline(); m_graphicsPipeline = gpb.createPipeline();
m_debug.setObjectName(m_graphicsPipeline, "Graphics"); m_debug.setObjectName(m_graphicsPipeline, "Graphics");
@ -743,10 +745,10 @@ void HelloVulkan::createSpheres(uint32_t nbSpheres)
std::uniform_real_distribution<float> radd{.05f, .2f}; std::uniform_real_distribution<float> radd{.05f, .2f};
// All spheres // All spheres
Sphere s;
m_spheres.resize(nbSpheres); m_spheres.resize(nbSpheres);
for(uint32_t i = 0; i < nbSpheres; i++) for(uint32_t i = 0; i < nbSpheres; i++)
{ {
Sphere s;
s.center = nvmath::vec3f(xzd(gen), yd(gen), xzd(gen)); s.center = nvmath::vec3f(xzd(gen), yd(gen), xzd(gen));
s.radius = radd(gen); s.radius = radd(gen);
m_spheres[i] = std::move(s); m_spheres[i] = std::move(s);
@ -988,8 +990,9 @@ void HelloVulkan::createRtPipeline()
rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth
rayPipelineInfo.setLayout(m_rtPipelineLayout); rayPipelineInfo.setLayout(m_rtPipelineLayout);
m_rtPipeline = static_cast<const vk::Pipeline&>(
m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value;
m_device.destroy(raygenSM); m_device.destroy(raygenSM);
m_device.destroy(missSM); m_device.destroy(missSM);

View file

@ -23,7 +23,7 @@
#include "nvvk/appbase_vkpp.hpp" #include "nvvk/appbase_vkpp.hpp"
#include "nvvk/debug_util_vk.hpp" #include "nvvk/debug_util_vk.hpp"
#include "nvvk/descriptorsets_vk.hpp" #include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/resourceallocator_vk.hpp" #include "nvvk/memallocator_dma_vk.hpp"
// #VKRay // #VKRay
#include "nvvk/raytraceKHR_vk.hpp" #include "nvvk/raytraceKHR_vk.hpp"
@ -101,8 +101,7 @@ public:
nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances
std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene
nvvk::ResourceAllocatorDedicated nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures
m_alloc; // Allocator for buffer, images, acceleration structures
nvvk::DebugUtil m_debug; // Utility to name objects nvvk::DebugUtil m_debug; // Utility to name objects
// #Post // #Post
@ -123,7 +122,7 @@ public:
nvvk::Texture m_offscreenColor; nvvk::Texture m_offscreenColor;
vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_offscreenDepth; nvvk::Texture m_offscreenDepth;
vk::Format m_offscreenDepthFormat; vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32};
// #VKRay // #VKRay
void initRayTracing(); void initRayTracing();

View file

@ -65,7 +65,7 @@ void renderUI(HelloVulkan& helloVk)
ImGui::SliderFloat3("Position", &helloVk.m_pushConstant.lightPosition.x, -20.f, 20.f); ImGui::SliderFloat3("Position", &helloVk.m_pushConstant.lightPosition.x, -20.f, 20.f);
ImGui::SliderFloat("Intensity", &helloVk.m_pushConstant.lightIntensity, 0.f, 150.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); helloVk.updateUniformBuffer(cmdBuf);
// Clearing screen // Clearing screen
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
@ -248,7 +248,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(2); offscreenRenderPassBeginInfo.setClearValueCount(2);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass);
offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer);
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -270,7 +270,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});

View file

@ -118,8 +118,8 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size()); auto nbTxt = static_cast<uint32_t>(m_textures.size());
uint32_t nbObj = static_cast<uint32_t>(m_objModel.size()); auto nbObj = static_cast<uint32_t>(m_objModel.size());
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
m_descSetLayoutBind.addBinding( 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/vert_shader.vert.spv", true, paths, true), vkSS::eVertex);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment);
gpb.addBindingDescription({0, sizeof(VertexObj)}); gpb.addBindingDescription({0, sizeof(VertexObj)});
gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, gpb.addAttributeDescriptions({
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, {0, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, pos))},
{2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, {1, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, nrm))},
{3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); {2, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, color))},
{3, 0, vk::Format::eR32G32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, texCoord))},
});
m_graphicsPipeline = gpb.createPipeline(); m_graphicsPipeline = gpb.createPipeline();
m_debug.setObjectName(m_graphicsPipeline, "Graphics"); m_debug.setObjectName(m_graphicsPipeline, "Graphics");
@ -842,8 +844,9 @@ void HelloVulkan::createRtPipeline()
rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth
rayPipelineInfo.setLayout(m_rtPipelineLayout); rayPipelineInfo.setLayout(m_rtPipelineLayout);
m_rtPipeline = static_cast<const vk::Pipeline&>(
m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value;
m_device.destroy(raygenSM); m_device.destroy(raygenSM);
m_device.destroy(missSM); m_device.destroy(missSM);

View file

@ -23,7 +23,7 @@
#include "nvvk/appbase_vkpp.hpp" #include "nvvk/appbase_vkpp.hpp"
#include "nvvk/debug_util_vk.hpp" #include "nvvk/debug_util_vk.hpp"
#include "nvvk/descriptorsets_vk.hpp" #include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/resourceallocator_vk.hpp" #include "nvvk/memallocator_dma_vk.hpp"
// #VKRay // #VKRay
#include "nvvk/raytraceKHR_vk.hpp" #include "nvvk/raytraceKHR_vk.hpp"
@ -101,8 +101,7 @@ public:
nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances
std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene
nvvk::ResourceAllocatorDedicated nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures
m_alloc; // Allocator for buffer, images, acceleration structures
nvvk::DebugUtil m_debug; // Utility to name objects nvvk::DebugUtil m_debug; // Utility to name objects
// #Post // #Post
@ -123,7 +122,7 @@ public:
nvvk::Texture m_offscreenColor; nvvk::Texture m_offscreenColor;
vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_offscreenDepth; nvvk::Texture m_offscreenDepth;
vk::Format m_offscreenDepthFormat; vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32};
// #VKRay // #VKRay
void initRayTracing(); void initRayTracing();

View file

@ -251,7 +251,7 @@ int main(int argc, char** argv)
helloVk.updateUniformBuffer(cmdBuf); helloVk.updateUniformBuffer(cmdBuf);
// Clearing screen // Clearing screen
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
@ -260,7 +260,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(2); offscreenRenderPassBeginInfo.setClearValueCount(2);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass);
offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer);
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -282,7 +282,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});

View file

@ -117,8 +117,8 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size()); auto nbTxt = static_cast<uint32_t>(m_textures.size());
uint32_t nbObj = static_cast<uint32_t>(m_objModel.size()); auto nbObj = static_cast<uint32_t>(m_objModel.size());
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
m_descSetLayoutBind.addBinding( m_descSetLayoutBind.addBinding(
@ -166,12 +166,12 @@ void HelloVulkan::updateDescriptorSet()
std::vector<vk::DescriptorBufferInfo> dbiMatIdx; std::vector<vk::DescriptorBufferInfo> dbiMatIdx;
std::vector<vk::DescriptorBufferInfo> dbiVert; std::vector<vk::DescriptorBufferInfo> dbiVert;
std::vector<vk::DescriptorBufferInfo> dbiIdx; std::vector<vk::DescriptorBufferInfo> 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}); dbiMat.emplace_back(m.matColorBuffer.buffer, 0, VK_WHOLE_SIZE);
dbiMatIdx.push_back({m_objModel[i].matIndexBuffer.buffer, 0, VK_WHOLE_SIZE}); dbiMatIdx.emplace_back(m.matIndexBuffer.buffer, 0, VK_WHOLE_SIZE);
dbiVert.push_back({m_objModel[i].vertexBuffer.buffer, 0, VK_WHOLE_SIZE}); dbiVert.emplace_back(m.vertexBuffer.buffer, 0, VK_WHOLE_SIZE);
dbiIdx.push_back({m_objModel[i].indexBuffer.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, 1, dbiMat.data()));
writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, 4, dbiMatIdx.data())); writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, 4, dbiMatIdx.data()));
@ -180,9 +180,9 @@ void HelloVulkan::updateDescriptorSet()
// All texture samplers // All texture samplers
std::vector<vk::DescriptorImageInfo> diit; std::vector<vk::DescriptorImageInfo> 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())); 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/vert_shader.vert.spv", true, paths, true), vkSS::eVertex);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment);
gpb.addBindingDescription({0, sizeof(VertexObj)}); gpb.addBindingDescription({0, sizeof(VertexObj)});
gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, gpb.addAttributeDescriptions({
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, {0, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, pos))},
{2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, {1, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, nrm))},
{3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); {2, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, color))},
{3, 0, vk::Format::eR32G32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, texCoord))},
});
m_graphicsPipeline = gpb.createPipeline(); m_graphicsPipeline = gpb.createPipeline();
m_debug.setObjectName(m_graphicsPipeline, "Graphics"); m_debug.setObjectName(m_graphicsPipeline, "Graphics");
@ -849,8 +851,9 @@ void HelloVulkan::createRtPipeline()
rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth
rayPipelineInfo.setLayout(m_rtPipelineLayout); rayPipelineInfo.setLayout(m_rtPipelineLayout);
m_rtPipeline = static_cast<const vk::Pipeline&>(
m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value;
// Manually defining group indices // Manually defining group indices
m_sbtWrapper.addIndices(rayPipelineInfo); m_sbtWrapper.addIndices(rayPipelineInfo);
@ -927,7 +930,7 @@ void HelloVulkan::createRtShaderBindingTable()
memcpy(pHitBuffer, handles[4], groupHandleSize); // Hit 2 memcpy(pHitBuffer, handles[4], groupHandleSize); // Hit 2
pHitBuffer += groupHandleSize; pHitBuffer += groupHandleSize;
memcpy(pHitBuffer, &m_hitShaderRecord[1], sizeof(HitRecordBuffer)); // Hit 2 data memcpy(pHitBuffer, &m_hitShaderRecord[1], sizeof(HitRecordBuffer)); // Hit 2 data
pBuffer += hitSize; // pBuffer += hitSize;
} }
// Write the handles in the SBT // Write the handles in the SBT

View file

@ -23,7 +23,7 @@
#include "nvvk/appbase_vkpp.hpp" #include "nvvk/appbase_vkpp.hpp"
#include "nvvk/debug_util_vk.hpp" #include "nvvk/debug_util_vk.hpp"
#include "nvvk/descriptorsets_vk.hpp" #include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/resourceallocator_vk.hpp" #include "nvvk/memallocator_dma_vk.hpp"
// #VKRay // #VKRay
#include "nvvk/raytraceKHR_vk.hpp" #include "nvvk/raytraceKHR_vk.hpp"
@ -104,8 +104,7 @@ public:
nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances
std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene
nvvk::ResourceAllocatorDedicated nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures
m_alloc; // Allocator for buffer, images, acceleration structures
nvvk::DebugUtil m_debug; // Utility to name objects nvvk::DebugUtil m_debug; // Utility to name objects
// #Post // #Post
@ -126,7 +125,7 @@ public:
nvvk::Texture m_offscreenColor; nvvk::Texture m_offscreenColor;
vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_offscreenDepth; nvvk::Texture m_offscreenDepth;
vk::Format m_offscreenDepthFormat; vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32};
// #VKRay // #VKRay
void initRayTracing(); void initRayTracing();
@ -155,8 +154,8 @@ public:
{ {
nvmath::vec4f clearColor; nvmath::vec4f clearColor;
nvmath::vec3f lightPosition; nvmath::vec3f lightPosition;
float lightIntensity; float lightIntensity{100.0f};
int lightType; int lightType{0};
} m_rtPushConstants; } m_rtPushConstants;
struct HitRecordBuffer struct HitRecordBuffer

View file

@ -249,7 +249,7 @@ int main(int argc, char** argv)
helloVk.updateUniformBuffer(cmdBuf); helloVk.updateUniformBuffer(cmdBuf);
// Clearing screen // Clearing screen
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
@ -258,7 +258,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(2); offscreenRenderPassBeginInfo.setClearValueCount(2);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass);
offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer);
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -280,7 +280,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});

View file

@ -116,8 +116,8 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size()); auto nbTxt = static_cast<uint32_t>(m_textures.size());
uint32_t nbObj = static_cast<uint32_t>(m_objModel.size()); auto nbObj = static_cast<uint32_t>(m_objModel.size());
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
m_descSetLayoutBind.addBinding( 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/vert_shader.vert.spv", true, paths, true), vkSS::eVertex);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment);
gpb.addBindingDescription({0, sizeof(VertexObj)}); gpb.addBindingDescription({0, sizeof(VertexObj)});
gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, gpb.addAttributeDescriptions({
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, {0, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, pos))},
{2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, {1, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, nrm))},
{3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); {2, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, color))},
{3, 0, vk::Format::eR32G32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, texCoord))},
});
m_graphicsPipeline = gpb.createPipeline(); m_graphicsPipeline = gpb.createPipeline();
m_debug.setObjectName(m_graphicsPipeline, "Graphics"); m_debug.setObjectName(m_graphicsPipeline, "Graphics");

View file

@ -23,7 +23,7 @@
#include "nvvk/appbase_vkpp.hpp" #include "nvvk/appbase_vkpp.hpp"
#include "nvvk/debug_util_vk.hpp" #include "nvvk/debug_util_vk.hpp"
#include "nvvk/descriptorsets_vk.hpp" #include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/resourceallocator_vk.hpp" #include "nvvk/memallocator_dma_vk.hpp"
// #VKRay // #VKRay
#include "nvvk/raytraceKHR_vk.hpp" #include "nvvk/raytraceKHR_vk.hpp"
@ -101,8 +101,7 @@ public:
nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances
std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene
nvvk::ResourceAllocatorDedicated nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures
m_alloc; // Allocator for buffer, images, acceleration structures
nvvk::DebugUtil m_debug; // Utility to name objects nvvk::DebugUtil m_debug; // Utility to name objects
// #Post // #Post
@ -123,7 +122,7 @@ public:
nvvk::Texture m_offscreenColor; nvvk::Texture m_offscreenColor;
vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_offscreenDepth; nvvk::Texture m_offscreenDepth;
vk::Format m_offscreenDepthFormat; vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32};
// #VKRay // #VKRay
void initRayTracing(); void initRayTracing();

View file

@ -235,7 +235,7 @@ int main(int argc, char** argv)
helloVk.updateUniformBuffer(cmdBuf); helloVk.updateUniformBuffer(cmdBuf);
// Clearing screen // Clearing screen
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
@ -244,7 +244,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(2); offscreenRenderPassBeginInfo.setClearValueCount(2);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass);
offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer);
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -261,7 +261,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});

View file

@ -117,8 +117,8 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size()); auto nbTxt = static_cast<uint32_t>(m_textures.size());
uint32_t nbObj = static_cast<uint32_t>(m_objModel.size()); auto nbObj = static_cast<uint32_t>(m_objModel.size());
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
m_descSetLayoutBind.addBinding( m_descSetLayoutBind.addBinding(
@ -166,12 +166,12 @@ void HelloVulkan::updateDescriptorSet()
std::vector<vk::DescriptorBufferInfo> dbiMatIdx; std::vector<vk::DescriptorBufferInfo> dbiMatIdx;
std::vector<vk::DescriptorBufferInfo> dbiVert; std::vector<vk::DescriptorBufferInfo> dbiVert;
std::vector<vk::DescriptorBufferInfo> dbiIdx; std::vector<vk::DescriptorBufferInfo> 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}); dbiMat.emplace_back(m.matColorBuffer.buffer, 0, VK_WHOLE_SIZE);
dbiMatIdx.push_back({m_objModel[i].matIndexBuffer.buffer, 0, VK_WHOLE_SIZE}); dbiMatIdx.emplace_back(m.matIndexBuffer.buffer, 0, VK_WHOLE_SIZE);
dbiVert.push_back({m_objModel[i].vertexBuffer.buffer, 0, VK_WHOLE_SIZE}); dbiVert.emplace_back(m.vertexBuffer.buffer, 0, VK_WHOLE_SIZE);
dbiIdx.push_back({m_objModel[i].indexBuffer.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, 1, dbiMat.data()));
writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, 4, dbiMatIdx.data())); writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, 4, dbiMatIdx.data()));
@ -180,9 +180,9 @@ void HelloVulkan::updateDescriptorSet()
// All texture samplers // All texture samplers
std::vector<vk::DescriptorImageInfo> diit; std::vector<vk::DescriptorImageInfo> 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())); 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/vert_shader.vert.spv", true, paths, true), vkSS::eVertex);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment);
gpb.addBindingDescription({0, sizeof(VertexObj)}); gpb.addBindingDescription({0, sizeof(VertexObj)});
gpb.addAttributeDescriptions({{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, gpb.addAttributeDescriptions({
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, {0, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, pos))},
{2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, {1, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, nrm))},
{3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); {2, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, color))},
{3, 0, vk::Format::eR32G32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, texCoord))},
});
m_graphicsPipeline = gpb.createPipeline(); m_graphicsPipeline = gpb.createPipeline();
m_debug.setObjectName(m_graphicsPipeline, "Graphics"); m_debug.setObjectName(m_graphicsPipeline, "Graphics");
@ -840,8 +842,9 @@ void HelloVulkan::createRtPipeline()
rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth
rayPipelineInfo.setLayout(m_rtPipelineLayout); rayPipelineInfo.setLayout(m_rtPipelineLayout);
m_rtPipeline = static_cast<const vk::Pipeline&>(
m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value;
m_device.destroy(raygenSM); m_device.destroy(raygenSM);
m_device.destroy(missSM); m_device.destroy(missSM);

View file

@ -23,7 +23,7 @@
#include "nvvk/appbase_vkpp.hpp" #include "nvvk/appbase_vkpp.hpp"
#include "nvvk/debug_util_vk.hpp" #include "nvvk/debug_util_vk.hpp"
#include "nvvk/descriptorsets_vk.hpp" #include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/resourceallocator_vk.hpp" #include "nvvk/memallocator_dma_vk.hpp"
// #VKRay // #VKRay
#include "nvvk/raytraceKHR_vk.hpp" #include "nvvk/raytraceKHR_vk.hpp"
@ -101,8 +101,7 @@ public:
nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances
std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene
nvvk::ResourceAllocatorDedicated nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures
m_alloc; // Allocator for buffer, images, acceleration structures
nvvk::DebugUtil m_debug; // Utility to name objects nvvk::DebugUtil m_debug; // Utility to name objects
// #Post // #Post
@ -123,7 +122,7 @@ public:
nvvk::Texture m_offscreenColor; nvvk::Texture m_offscreenColor;
vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_offscreenDepth; nvvk::Texture m_offscreenDepth;
vk::Format m_offscreenDepthFormat; vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32};
// #VKRay // #VKRay
void initRayTracing(); void initRayTracing();
@ -152,8 +151,8 @@ public:
{ {
nvmath::vec4f clearColor; nvmath::vec4f clearColor;
nvmath::vec3f lightPosition; nvmath::vec3f lightPosition;
float lightIntensity; float lightIntensity{100.0f};
int lightType; int lightType{0};
int maxDepth{10}; int maxDepth{10};
} m_rtPushConstants; } m_rtPushConstants;
}; };

View file

@ -244,7 +244,7 @@ int main(int argc, char** argv)
helloVk.updateUniformBuffer(cmdBuf); helloVk.updateUniformBuffer(cmdBuf);
// Clearing screen // Clearing screen
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
@ -253,7 +253,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(2); offscreenRenderPassBeginInfo.setClearValueCount(2);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass);
offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer);
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -275,7 +275,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});

View file

@ -119,8 +119,8 @@ void HelloVulkan::createDescriptorSetLayout()
using vkDS = vk::DescriptorSetLayoutBinding; using vkDS = vk::DescriptorSetLayoutBinding;
using vkDT = vk::DescriptorType; using vkDT = vk::DescriptorType;
using vkSS = vk::ShaderStageFlagBits; using vkSS = vk::ShaderStageFlagBits;
uint32_t nbTxt = static_cast<uint32_t>(m_textures.size()); auto nbTxt = static_cast<uint32_t>(m_textures.size());
uint32_t nbObj = static_cast<uint32_t>(m_objModel.size()); auto nbObj = static_cast<uint32_t>(m_objModel.size());
// Camera matrices (binding = 0) // Camera matrices (binding = 0)
m_descSetLayoutBind.addBinding( 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/vert_shader.vert.spv", true, paths, true), vkSS::eVertex);
gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment); gpb.addShader(nvh::loadFile("spv/frag_shader.frag.spv", true, paths, true), vkSS::eFragment);
gpb.addBindingDescription({0, sizeof(VertexObj)}); gpb.addBindingDescription({0, sizeof(VertexObj)});
gpb.addAttributeDescriptions(std::vector<vk::VertexInputAttributeDescription>{ gpb.addAttributeDescriptions({
{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, pos)}, {0, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, pos))},
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, nrm)}, {1, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, nrm))},
{2, 0, vk::Format::eR32G32B32Sfloat, offsetof(VertexObj, color)}, {2, 0, vk::Format::eR32G32B32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, color))},
{3, 0, vk::Format::eR32G32Sfloat, offsetof(VertexObj, texCoord)}}); {3, 0, vk::Format::eR32G32Sfloat, static_cast<uint32_t>(offsetof(VertexObj, texCoord))},
});
m_graphicsPipeline = gpb.createPipeline(); m_graphicsPipeline = gpb.createPipeline();
m_debug.setObjectName(m_graphicsPipeline, "Graphics"); m_debug.setObjectName(m_graphicsPipeline, "Graphics");
@ -867,7 +868,7 @@ void HelloVulkan::createRtPipeline()
m_rtShaderGroups.push_back(mg); m_rtShaderGroups.push_back(mg);
// Hit Group - Closest Hit + AnyHit // 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::RayTracingShaderGroupCreateInfoKHR hg{vk::RayTracingShaderGroupTypeKHR::eTrianglesHitGroup,
VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR,
@ -877,7 +878,7 @@ void HelloVulkan::createRtPipeline()
stage.stage = vk::ShaderStageFlagBits::eClosestHitKHR; stage.stage = vk::ShaderStageFlagBits::eClosestHitKHR;
stage.module = chitSM; stage.module = chitSM;
stage.pName = "main"; stage.pName = "main";
stage.pSpecializationInfo = specializations[i].getSpecialization(); stage.pSpecializationInfo = specialization.getSpecialization();
stages.push_back(stage); stages.push_back(stage);
m_rtShaderGroups.push_back(hg); m_rtShaderGroups.push_back(hg);
} }
@ -912,8 +913,8 @@ void HelloVulkan::createRtPipeline()
rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth
rayPipelineInfo.setLayout(m_rtPipelineLayout); rayPipelineInfo.setLayout(m_rtPipelineLayout);
m_rtPipeline = static_cast<const vk::Pipeline&>(
m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo)); m_rtPipeline = m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo).value;
m_sbtWrapper.create(m_rtPipeline, rayPipelineInfo); m_sbtWrapper.create(m_rtPipeline, rayPipelineInfo);

View file

@ -24,7 +24,7 @@
#include "nvvk/appbase_vkpp.hpp" #include "nvvk/appbase_vkpp.hpp"
#include "nvvk/debug_util_vk.hpp" #include "nvvk/debug_util_vk.hpp"
#include "nvvk/descriptorsets_vk.hpp" #include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/resourceallocator_vk.hpp" #include "nvvk/memallocator_dma_vk.hpp"
// #VKRay // #VKRay
#include "nvvk/raytraceKHR_vk.hpp" #include "nvvk/raytraceKHR_vk.hpp"
@ -104,8 +104,7 @@ public:
nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances nvvk::Buffer m_sceneDesc; // Device buffer of the OBJ instances
std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene
nvvk::ResourceAllocatorDedicated nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures
m_alloc; // Allocator for buffer, images, acceleration structures
nvvk::DebugUtil m_debug; // Utility to name objects nvvk::DebugUtil m_debug; // Utility to name objects
// #Post // #Post
@ -126,7 +125,7 @@ public:
nvvk::Texture m_offscreenColor; nvvk::Texture m_offscreenColor;
vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat}; vk::Format m_offscreenColorFormat{vk::Format::eR32G32B32A32Sfloat};
nvvk::Texture m_offscreenDepth; nvvk::Texture m_offscreenDepth;
vk::Format m_offscreenDepthFormat; vk::Format m_offscreenDepthFormat{vk::Format::eX8D24UnormPack32};
// #VKRay // #VKRay
void initRayTracing(); void initRayTracing();
@ -154,8 +153,8 @@ public:
{ {
nvmath::vec4f clearColor; nvmath::vec4f clearColor;
nvmath::vec3f lightPosition; nvmath::vec3f lightPosition;
float lightIntensity; float lightIntensity{100.0f};
int lightType; int lightType{0};
int specialization; int specialization{7};
} m_rtPushConstants; } m_rtPushConstants;
}; };

View file

@ -249,7 +249,7 @@ int main(int argc, char** argv)
helloVk.updateUniformBuffer(cmdBuf); helloVk.updateUniformBuffer(cmdBuf);
// Clearing screen // Clearing screen
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].setColor( clearValues[0].setColor(
std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]})); std::array<float, 4>({clearColor[0], clearColor[1], clearColor[2], clearColor[3]}));
clearValues[1].setDepthStencil({1.0f, 0}); clearValues[1].setDepthStencil({1.0f, 0});
@ -258,7 +258,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo offscreenRenderPassBeginInfo; vk::RenderPassBeginInfo offscreenRenderPassBeginInfo;
offscreenRenderPassBeginInfo.setClearValueCount(2); offscreenRenderPassBeginInfo.setClearValueCount(2);
offscreenRenderPassBeginInfo.setPClearValues(clearValues); offscreenRenderPassBeginInfo.setPClearValues(clearValues.data());
offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass); offscreenRenderPassBeginInfo.setRenderPass(helloVk.m_offscreenRenderPass);
offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer); offscreenRenderPassBeginInfo.setFramebuffer(helloVk.m_offscreenFramebuffer);
offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); offscreenRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});
@ -280,7 +280,7 @@ int main(int argc, char** argv)
{ {
vk::RenderPassBeginInfo postRenderPassBeginInfo; vk::RenderPassBeginInfo postRenderPassBeginInfo;
postRenderPassBeginInfo.setClearValueCount(2); postRenderPassBeginInfo.setClearValueCount(2);
postRenderPassBeginInfo.setPClearValues(clearValues); postRenderPassBeginInfo.setPClearValues(clearValues.data());
postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass()); postRenderPassBeginInfo.setRenderPass(helloVk.getRenderPass());
postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]); postRenderPassBeginInfo.setFramebuffer(helloVk.getFramebuffers()[curFrame]);
postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()}); postRenderPassBeginInfo.setRenderArea({{}, helloVk.getSize()});