Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SaschaWillems committed Jan 13, 2024
1 parent f6abda6 commit 8143b2d
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions examples/raytracinggltf/raytracinggltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class VulkanExample : public VulkanRaytracingSample

vks::Buffer vertexBuffer;
vks::Buffer indexBuffer;
uint32_t indexCount;
uint32_t indexCount{ 0 };
vks::Buffer transformBuffer;

struct GeometryNode {
Expand All @@ -43,12 +43,12 @@ class VulkanExample : public VulkanRaytracingSample
glm::mat4 projInverse;
uint32_t frame{ 0 };
} uniformData;
vks::Buffer ubo;
vks::Buffer uniformBuffer;

VkPipeline pipeline;
VkPipelineLayout pipelineLayout;
VkDescriptorSet descriptorSet;
VkDescriptorSetLayout descriptorSetLayout;
VkPipeline pipeline{ VK_NULL_HANDLE };
VkPipelineLayout pipelineLayout{ VK_NULL_HANDLE };
VkDescriptorSet descriptorSet{ VK_NULL_HANDLE };
VkDescriptorSetLayout descriptorSetLayout{ VK_NULL_HANDLE };

vkglTF::Model model;

Expand All @@ -75,20 +75,22 @@ class VulkanExample : public VulkanRaytracingSample

~VulkanExample()
{
vkDestroyPipeline(device, pipeline, nullptr);
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
deleteStorageImage();
deleteAccelerationStructure(bottomLevelAS);
deleteAccelerationStructure(topLevelAS);
vertexBuffer.destroy();
indexBuffer.destroy();
transformBuffer.destroy();
shaderBindingTables.raygen.destroy();
shaderBindingTables.miss.destroy();
shaderBindingTables.hit.destroy();
ubo.destroy();
geometryNodesBuffer.destroy();
if (device) {
vkDestroyPipeline(device, pipeline, nullptr);
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
deleteStorageImage();
deleteAccelerationStructure(bottomLevelAS);
deleteAccelerationStructure(topLevelAS);
vertexBuffer.destroy();
indexBuffer.destroy();
transformBuffer.destroy();
shaderBindingTables.raygen.destroy();
shaderBindingTables.miss.destroy();
shaderBindingTables.hit.destroy();
uniformBuffer.destroy();
geometryNodesBuffer.destroy();
}
}

void createAccelerationStructureBuffer(AccelerationStructure &accelerationStructure, VkAccelerationStructureBuildSizesInfoKHR buildSizeInfo)
Expand Down Expand Up @@ -561,7 +563,7 @@ class VulkanExample : public VulkanRaytracingSample
// Binding 1: Ray tracing result image
vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1, &storageImageDescriptor),
// Binding 2: Uniform data
vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 2, &ubo.descriptor),
vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 2, &uniformBuffer.descriptor),
// Binding 4: Geometry node information SSBO
vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 4, &geometryNodesBuffer.descriptor),
};
Expand Down Expand Up @@ -596,10 +598,10 @@ class VulkanExample : public VulkanRaytracingSample
VK_CHECK_RESULT(vulkanDevice->createBuffer(
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
&ubo,
&uniformBuffer,
sizeof(uniformData),
&uniformData));
VK_CHECK_RESULT(ubo.map());
VK_CHECK_RESULT(uniformBuffer.map());

updateUniformBuffers();
}
Expand Down Expand Up @@ -710,7 +712,7 @@ class VulkanExample : public VulkanRaytracingSample
// In this sample we use noise offset by this frame index to shoot rays for transparency into different directions
// Once enough frames with random ray directions have been accumulated, it looks like proper transparency
uniformData.frame++;
memcpy(ubo.mapped, &uniformData, sizeof(uniformData));
memcpy(uniformBuffer.mapped, &uniformData, sizeof(uniformData));
}

void getEnabledFeatures()
Expand Down Expand Up @@ -777,13 +779,13 @@ class VulkanExample : public VulkanRaytracingSample
if (!prepared)
return;
updateUniformBuffers();
if (camera.updated) {
// If the camera's view has been updated we reset the frame accumulation
std::cout << "Cam updated\n";
uniformData.frame = -1;
}
draw();
}

virtual void viewChanged()
{
uniformData.frame = -1;
}
};

VULKAN_EXAMPLE_MAIN()

0 comments on commit 8143b2d

Please sign in to comment.