Fixing warning issues with VS2017

This commit is contained in:
mklefrancois 2021-01-04 10:48:37 +01:00
parent 9a174a8269
commit 7082dca46d

View file

@ -87,8 +87,8 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf)
// UBO on the device, and what stages access it.
vk::Buffer deviceUBO = m_cameraMat.buffer;
auto uboUsageStages = vk::PipelineStageFlagBits::eVertexShader
| vk::PipelineStageFlagBits::eRayTracingShaderKHR;
auto uboUsageStages =
vk::PipelineStageFlagBits::eVertexShader | vk::PipelineStageFlagBits::eRayTracingShaderKHR;
// Ensure that the modified UBO is not visible to previous frames.
vk::BufferMemoryBarrier beforeBarrier;
@ -97,9 +97,7 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf)
beforeBarrier.setBuffer(deviceUBO);
beforeBarrier.setOffset(0);
beforeBarrier.setSize(sizeof hostUBO);
cmdBuf.pipelineBarrier(
uboUsageStages,
vk::PipelineStageFlagBits::eTransfer,
cmdBuf.pipelineBarrier(uboUsageStages, vk::PipelineStageFlagBits::eTransfer,
vk::DependencyFlagBits::eDeviceGroup, {}, {beforeBarrier}, {});
// Schedule the host-to-device upload. (hostUBO is copied into the cmd
@ -113,9 +111,7 @@ void HelloVulkan::updateUniformBuffer(const vk::CommandBuffer& cmdBuf)
afterBarrier.setBuffer(deviceUBO);
afterBarrier.setOffset(0);
afterBarrier.setSize(sizeof hostUBO);
cmdBuf.pipelineBarrier(
vk::PipelineStageFlagBits::eTransfer,
uboUsageStages,
cmdBuf.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer, uboUsageStages,
vk::DependencyFlagBits::eDeviceGroup, {}, {afterBarrier}, {});
}
@ -724,7 +720,8 @@ nvvk::RaytracingBuilderKHR::BlasInput HelloVulkan::objectToVkGeometryKHR(const O
// Tesselate a sphere as a list of triangles; return its
// vertices and indices as reference arguments.
void HelloVulkan::fillLanternVerts(std::vector<nvmath::vec3f>& vertices, std::vector<uint32_t>& indices)
void HelloVulkan::fillLanternVerts(std::vector<nvmath::vec3f>& vertices,
std::vector<uint32_t>& indices)
{
// Create a spherical lantern model by recursively tesselating an octahedron.
struct VertexIndex
@ -737,7 +734,7 @@ void HelloVulkan::fillLanternVerts(std::vector<nvmath::vec3f>& vertices, std::ve
VertexIndex vert0, vert1, vert2;
};
VertexIndex posX{{ m_lanternModelRadius, 0, 0}, 0};
VertexIndex posX{{m_lanternModelRadius, 0, 0}, 0};
VertexIndex negX{{-m_lanternModelRadius, 0, 0}, 1};
VertexIndex posY{{0, m_lanternModelRadius, 0}, 2};
VertexIndex negY{{0, -m_lanternModelRadius, 0}, 3};
@ -746,34 +743,26 @@ void HelloVulkan::fillLanternVerts(std::vector<nvmath::vec3f>& vertices, std::ve
uint32_t vertexCount = 6;
// Initial triangle list is octahedron.
std::vector<Triangle> triangles {
{ posX, posY, posZ },
{ posX, posY, negZ },
{ posX, negY, posZ },
{ posX, negY, negZ },
{ negX, posY, posZ },
{ negX, posY, negZ },
{ negX, negY, posZ },
{ negX, negY, negZ } };
std::vector<Triangle> triangles{{posX, posY, posZ}, {posX, posY, negZ}, {posX, negY, posZ},
{posX, negY, negZ}, {negX, posY, posZ}, {negX, posY, negZ},
{negX, negY, posZ}, {negX, negY, negZ}};
// Recursion: every iteration, convert the current model to a new
// model by breaking each triangle into 4 triangles.
for (int recursions = 0; recursions < 3; ++recursions)
for(int recursions = 0; recursions < 3; ++recursions)
{
std::vector<Triangle> new_triangles;
for (Triangle t : triangles) {
for(Triangle t : triangles)
{
// Split each of three edges in half, then fixup the
// length of the midpoint to match m_lanternModelRadius.
// Record the index the new vertices will eventually have in vertices.
VertexIndex v01 {
m_lanternModelRadius * nvmath::normalize(t.vert0.vertex + t.vert1.vertex),
vertexCount++ };
VertexIndex v12 {
m_lanternModelRadius * nvmath::normalize(t.vert1.vertex + t.vert2.vertex),
vertexCount++ };
VertexIndex v02 {
m_lanternModelRadius * nvmath::normalize(t.vert0.vertex + t.vert2.vertex),
vertexCount++ };
VertexIndex v01{m_lanternModelRadius * nvmath::normalize(t.vert0.vertex + t.vert1.vertex),
vertexCount++};
VertexIndex v12{m_lanternModelRadius * nvmath::normalize(t.vert1.vertex + t.vert2.vertex),
vertexCount++};
VertexIndex v02{m_lanternModelRadius * nvmath::normalize(t.vert0.vertex + t.vert2.vertex),
vertexCount++};
// Old triangle becomes 4 new triangles.
new_triangles.push_back({t.vert0, v01, v02});
@ -790,7 +779,7 @@ void HelloVulkan::fillLanternVerts(std::vector<nvmath::vec3f>& vertices, std::ve
// Write out the vertices to the vertices vector, and
// connect the tesselated triangles with indices in the indices vector.
for (Triangle t : triangles)
for(Triangle t : triangles)
{
vertices[t.vert0.index] = t.vert0.vertex;
vertices[t.vert1.index] = t.vert1.vertex;
@ -948,8 +937,8 @@ void HelloVulkan::createRtDescriptorSet()
using vkDSLB = vk::DescriptorSetLayoutBinding;
// TLAS (binding = 0)
m_rtDescSetLayoutBind.addBinding(vkDSLB(0, vkDT::eAccelerationStructureKHR, 1,
vkSS::eRaygenKHR | vkSS::eClosestHitKHR));
m_rtDescSetLayoutBind.addBinding(
vkDSLB(0, vkDT::eAccelerationStructureKHR, 1, vkSS::eRaygenKHR | vkSS::eClosestHitKHR));
// Output image (binding = 1)
m_rtDescSetLayoutBind.addBinding(
vkDSLB(1, vkDT::eStorageImage, 1, vkSS::eRaygenKHR)); // Output image
@ -969,8 +958,8 @@ void HelloVulkan::createRtDescriptorSet()
descASInfo.setPAccelerationStructures(&tlas);
vk::DescriptorImageInfo imageInfo{
{}, m_offscreenColor.descriptor.imageView, vk::ImageLayout::eGeneral};
vk::DescriptorBufferInfo lanternBufferInfo{
m_lanternIndirectBuffer.buffer, 0, m_lanternCount * sizeof(LanternIndirectEntry)};
vk::DescriptorBufferInfo lanternBufferInfo{m_lanternIndirectBuffer.buffer, 0,
m_lanternCount * sizeof(LanternIndirectEntry)};
std::vector<vk::WriteDescriptorSet> writes;
writes.emplace_back(m_rtDescSetLayoutBind.makeWrite(m_rtDescSet, 0, &descASInfo));
@ -1065,8 +1054,9 @@ void HelloVulkan::createRtPipeline()
// Miss shader 2 is invoked when a shadow ray for lantern lighting misses the
// lantern. It shouldn't be invoked, but I include it just in case.
vk::ShaderModule lanternmissSM = nvvk::createShaderModule(
m_device, nvh::loadFile("shaders/lanternShadow.rmiss.spv", true, paths, true));
vk::ShaderModule lanternmissSM =
nvvk::createShaderModule(m_device,
nvh::loadFile("shaders/lanternShadow.rmiss.spv", true, paths, true));
std::vector<vk::PipelineShaderStageCreateInfo> stages;
@ -1113,36 +1103,34 @@ void HelloVulkan::createRtPipeline()
nvh::loadFile("shaders/lantern.rchit.spv", true, paths, true));
vk::RayTracingShaderGroupCreateInfoKHR lanternHg{
vk::RayTracingShaderGroupTypeKHR::eTrianglesHitGroup,
VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR,
VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR};
vk::RayTracingShaderGroupTypeKHR::eTrianglesHitGroup, VK_SHADER_UNUSED_KHR,
VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR};
stages.push_back({{}, vk::ShaderStageFlagBits::eClosestHitKHR, lanternChitSM, "main"});
lanternHg.setClosestHitShader(static_cast<uint32_t>(stages.size() - 1));
m_rtShaderGroups.push_back(lanternHg);
// OBJ Lantern Shadow Ray Hit Group
vk::ShaderModule lanternShadowObjChitSM =
nvvk::createShaderModule(m_device, //
vk::ShaderModule lanternShadowObjChitSM = nvvk::createShaderModule(
m_device, //
nvh::loadFile("shaders/lanternShadowObj.rchit.spv", true, paths, true));
vk::RayTracingShaderGroupCreateInfoKHR lanternShadowObjHg{
vk::RayTracingShaderGroupTypeKHR::eTrianglesHitGroup,
VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR,
VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR};
vk::RayTracingShaderGroupTypeKHR::eTrianglesHitGroup, VK_SHADER_UNUSED_KHR,
VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR};
stages.push_back({{}, vk::ShaderStageFlagBits::eClosestHitKHR, lanternShadowObjChitSM, "main"});
lanternShadowObjHg.setClosestHitShader(static_cast<uint32_t>(stages.size() - 1));
m_rtShaderGroups.push_back(lanternShadowObjHg);
// Lantern Lantern Shadow Ray Hit Group
vk::ShaderModule lanternShadowLanternChitSM =
nvvk::createShaderModule(m_device, //
vk::ShaderModule lanternShadowLanternChitSM = nvvk::createShaderModule(
m_device, //
nvh::loadFile("shaders/lanternShadowLantern.rchit.spv", true, paths, true));
vk::RayTracingShaderGroupCreateInfoKHR lanternShadowLanternHg{
vk::RayTracingShaderGroupTypeKHR::eTrianglesHitGroup,
VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR,
VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR};
stages.push_back({{}, vk::ShaderStageFlagBits::eClosestHitKHR, lanternShadowLanternChitSM, "main"});
vk::RayTracingShaderGroupTypeKHR::eTrianglesHitGroup, VK_SHADER_UNUSED_KHR,
VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR};
stages.push_back(
{{}, vk::ShaderStageFlagBits::eClosestHitKHR, lanternShadowLanternChitSM, "main"});
lanternShadowLanternHg.setClosestHitShader(static_cast<uint32_t>(stages.size() - 1));
m_rtShaderGroups.push_back(lanternShadowLanternHg);
@ -1171,8 +1159,7 @@ void HelloVulkan::createRtPipeline()
// In this case, m_rtShaderGroups.size() == 8: we have one raygen group,
// three miss shader groups, and four hit groups.
rayPipelineInfo.setGroupCount(static_cast<uint32_t>(
m_rtShaderGroups.size()));
rayPipelineInfo.setGroupCount(static_cast<uint32_t>(m_rtShaderGroups.size()));
rayPipelineInfo.setPGroups(m_rtShaderGroups.data());
rayPipelineInfo.setMaxPipelineRayRecursionDepth(2); // Ray depth
@ -1250,15 +1237,16 @@ void HelloVulkan::createLanternIndirectDescriptorSet()
m_lanternIndirectDescPool = m_lanternIndirectDescSetLayoutBind.createPool(m_device);
m_lanternIndirectDescSetLayout = m_lanternIndirectDescSetLayoutBind.createLayout(m_device);
m_lanternIndirectDescSet =
m_device.allocateDescriptorSets({m_lanternIndirectDescPool, 1, &m_lanternIndirectDescSetLayout})[0];
m_lanternIndirectDescSet = m_device.allocateDescriptorSets(
{m_lanternIndirectDescPool, 1, &m_lanternIndirectDescSetLayout})[0];
assert(m_lanternIndirectBuffer.buffer);
vk::DescriptorBufferInfo lanternBufferInfo{
m_lanternIndirectBuffer.buffer, 0, m_lanternCount * sizeof(LanternIndirectEntry)};
vk::DescriptorBufferInfo lanternBufferInfo{m_lanternIndirectBuffer.buffer, 0,
m_lanternCount * sizeof(LanternIndirectEntry)};
std::vector<vk::WriteDescriptorSet> writes;
writes.emplace_back(m_lanternIndirectDescSetLayoutBind.makeWrite(m_lanternIndirectDescSet, 0, &lanternBufferInfo));
writes.emplace_back(m_lanternIndirectDescSetLayoutBind.makeWrite(m_lanternIndirectDescSet, 0,
&lanternBufferInfo));
m_device.updateDescriptorSets(static_cast<uint32_t>(writes.size()), writes.data(), 0, nullptr);
}
@ -1267,8 +1255,8 @@ void HelloVulkan::createLanternIndirectDescriptorSet()
void HelloVulkan::createLanternIndirectCompPipeline()
{
// Compile compute shader and package as stage.
vk::ShaderModule computeShader =
nvvk::createShaderModule(m_device, //
vk::ShaderModule computeShader = nvvk::createShaderModule(
m_device, //
nvh::loadFile("shaders/lanternIndirect.comp.spv", true, defaultSearchPaths, true));
vk::PipelineShaderStageCreateInfo stageInfo;
stageInfo.setStage(vk::ShaderStageFlagBits::eCompute);
@ -1276,7 +1264,7 @@ void HelloVulkan::createLanternIndirectCompPipeline()
stageInfo.setPName("main");
// Set up push constant and pipeline layout.
constexpr auto pushSize = sizeof(m_lanternIndirectPushConstants);
constexpr auto pushSize = static_cast<uint32_t>(sizeof(m_lanternIndirectPushConstants));
vk::PushConstantRange pushCRange = {vk::ShaderStageFlagBits::eCompute, 0, pushSize};
static_assert(pushSize <= 128, "Spec guarantees only 128 byte push constant");
vk::PipelineLayoutCreateInfo layoutInfo;
@ -1290,7 +1278,8 @@ void HelloVulkan::createLanternIndirectCompPipeline()
vk::ComputePipelineCreateInfo pipelineInfo;
pipelineInfo.setStage(stageInfo);
pipelineInfo.setLayout(m_lanternIndirectCompPipelineLayout);
m_lanternIndirectCompPipeline = static_cast<const vk::Pipeline&>(m_device.createComputePipeline({}, pipelineInfo));
m_lanternIndirectCompPipeline =
static_cast<const vk::Pipeline&>(m_device.createComputePipeline({}, pipelineInfo));
m_device.destroy(computeShader);
}
@ -1317,8 +1306,10 @@ void HelloVulkan::createLanternIndirectBuffer()
vk::MemoryPropertyFlagBits::eDeviceLocal);
std::vector<LanternIndirectEntry> entries(m_lanternCount);
for (size_t i = 0; i < m_lanternCount; ++i) entries[i].lantern = m_lanterns[i];
cmdBuf.updateBuffer(m_lanternIndirectBuffer.buffer, 0, entries.size() * sizeof entries[0], entries.data());
for(size_t i = 0; i < m_lanternCount; ++i)
entries[i].lantern = m_lanterns[i];
cmdBuf.updateBuffer(m_lanternIndirectBuffer.buffer, 0, entries.size() * sizeof entries[0],
entries.data());
cmdBufGet.submitAndWait(cmdBuf);
}
@ -1352,7 +1343,7 @@ void HelloVulkan::raytrace(const vk::CommandBuffer& cmdBuf, const nvmath::vec4f&
bufferBarrier.size = m_lanternCount * sizeof m_lanterns[0];
cmdBuf.pipelineBarrier( //
vk::PipelineStageFlagBits::eDrawIndirect, //
vk::PipelineStageFlagBits::eComputeShader,//
vk::PipelineStageFlagBits::eComputeShader, //
vk::DependencyFlags(0), //
{}, {bufferBarrier}, {});
@ -1367,12 +1358,11 @@ void HelloVulkan::raytrace(const vk::CommandBuffer& cmdBuf, const nvmath::vec4f&
m_lanternIndirectPushConstants.screenX = m_size.width;
m_lanternIndirectPushConstants.screenY = m_size.height;
m_lanternIndirectPushConstants.lanternCount = int32_t(m_lanternCount);
cmdBuf.pushConstants<LanternIndirectPushConstants>(
m_lanternIndirectCompPipelineLayout,
vk::ShaderStageFlagBits::eCompute,
0, m_lanternIndirectPushConstants);
cmdBuf.bindDescriptorSets(
vk::PipelineBindPoint::eCompute, m_lanternIndirectCompPipelineLayout, 0, {m_lanternIndirectDescSet}, {});
cmdBuf.pushConstants<LanternIndirectPushConstants>(m_lanternIndirectCompPipelineLayout,
vk::ShaderStageFlagBits::eCompute, 0,
m_lanternIndirectPushConstants);
cmdBuf.bindDescriptorSets(vk::PipelineBindPoint::eCompute, m_lanternIndirectCompPipelineLayout, 0,
{m_lanternIndirectDescSet}, {});
cmdBuf.dispatch(1, 1, 1);
// Ensure compute results are visible when doing indirect ray trace.
@ -1421,19 +1411,17 @@ void HelloVulkan::raytrace(const vk::CommandBuffer& cmdBuf, const nvmath::vec4f&
Stride{0u, 0u, 0u}}; // callable
// First pass, illuminate scene with global light.
cmdBuf.traceRaysKHR(
&strideAddresses[0], &strideAddresses[1], //
cmdBuf.traceRaysKHR(&strideAddresses[0], &strideAddresses[1], //
&strideAddresses[2], &strideAddresses[3], //
m_size.width, m_size.height, 1);
// Lantern passes, ensure previous pass completed, then add light contribution from each lantern.
for (int i = 0; i < static_cast<int>(m_lanternCount); ++i)
for(int i = 0; i < static_cast<int>(m_lanternCount); ++i)
{
// Barrier to ensure previous pass finished.
vk::Image offscreenImage{m_offscreenColor.image};
vk::ImageSubresourceRange colorRange(
vk::ImageAspectFlagBits::eColor, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS
);
vk::ImageSubresourceRange colorRange(vk::ImageAspectFlagBits::eColor, 0,
VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS);
vk::ImageMemoryBarrier imageBarrier;
imageBarrier.setOldLayout(vk::ImageLayout::eGeneral);
imageBarrier.setNewLayout(vk::ImageLayout::eGeneral);
@ -1443,8 +1431,7 @@ void HelloVulkan::raytrace(const vk::CommandBuffer& cmdBuf, const nvmath::vec4f&
imageBarrier.setSubresourceRange(colorRange);
imageBarrier.setSrcAccessMask(vk::AccessFlagBits::eShaderWrite);
imageBarrier.setDstAccessMask(vk::AccessFlagBits::eShaderRead);
cmdBuf.pipelineBarrier(
vk::PipelineStageFlagBits::eRayTracingShaderKHR, //
cmdBuf.pipelineBarrier(vk::PipelineStageFlagBits::eRayTracingShaderKHR, //
vk::PipelineStageFlagBits::eRayTracingShaderKHR, //
vk::DependencyFlags(0), //
{}, {}, {imageBarrier});
@ -1458,10 +1445,10 @@ void HelloVulkan::raytrace(const vk::CommandBuffer& cmdBuf, const nvmath::vec4f&
0, m_rtPushConstants);
// Execute lantern pass.
cmdBuf.traceRaysIndirectKHR(
&strideAddresses[0], &strideAddresses[1], //
cmdBuf.traceRaysIndirectKHR(&strideAddresses[0], &strideAddresses[1], //
&strideAddresses[2], &strideAddresses[3], //
m_device.getBufferAddress({m_lanternIndirectBuffer.buffer}) + i * sizeof(LanternIndirectEntry));
m_device.getBufferAddress({m_lanternIndirectBuffer.buffer})
+ i * sizeof(LanternIndirectEntry));
}
m_debug.endLabel(cmdBuf);