Cleaned up the createShaderBindingTable for the raytracing examples
This commit is contained in:
parent
e1e348ac7a
commit
cd2ec54f7f
3 changed files with 5 additions and 6 deletions
|
|
@ -44,6 +44,8 @@ struct GeometryInstance {
|
||||||
#define INDEX_MISS 1
|
#define INDEX_MISS 1
|
||||||
#define INDEX_CLOSEST_HIT 2
|
#define INDEX_CLOSEST_HIT 2
|
||||||
|
|
||||||
|
#define NUM_SHADER_GROUPS 3
|
||||||
|
|
||||||
class VulkanExample : public VulkanExampleBase
|
class VulkanExample : public VulkanExampleBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -421,7 +423,7 @@ public:
|
||||||
*/
|
*/
|
||||||
void createShaderBindingTable() {
|
void createShaderBindingTable() {
|
||||||
// Create buffer for the shader binding table
|
// Create buffer for the shader binding table
|
||||||
const uint32_t sbtSize = rayTracingProperties.shaderGroupHandleSize * 3;
|
const uint32_t sbtSize = rayTracingProperties.shaderGroupHandleSize * NUM_SHADER_GROUPS;
|
||||||
VK_CHECK_RESULT(vulkanDevice->createBuffer(
|
VK_CHECK_RESULT(vulkanDevice->createBuffer(
|
||||||
VK_BUFFER_USAGE_RAY_TRACING_BIT_NV,
|
VK_BUFFER_USAGE_RAY_TRACING_BIT_NV,
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
|
||||||
|
|
@ -431,10 +433,9 @@ public:
|
||||||
|
|
||||||
auto shaderHandleStorage = new uint8_t[sbtSize];
|
auto shaderHandleStorage = new uint8_t[sbtSize];
|
||||||
// Get shader identifiers
|
// Get shader identifiers
|
||||||
VK_CHECK_RESULT(vkGetRayTracingShaderGroupHandlesNV(device, pipeline, 0, 3, sbtSize, shaderHandleStorage));
|
VK_CHECK_RESULT(vkGetRayTracingShaderGroupHandlesNV(device, pipeline, 0, NUM_SHADER_GROUPS, sbtSize, shaderHandleStorage));
|
||||||
auto* data = static_cast<uint8_t*>(shaderBindingTable.mapped);
|
auto* data = static_cast<uint8_t*>(shaderBindingTable.mapped);
|
||||||
// Copy the shader identifiers to the shader binding table
|
// Copy the shader identifiers to the shader binding table
|
||||||
VkDeviceSize offset = 0;
|
|
||||||
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_RAYGEN);
|
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_RAYGEN);
|
||||||
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_MISS);
|
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_MISS);
|
||||||
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_CLOSEST_HIT);
|
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_CLOSEST_HIT);
|
||||||
|
|
@ -540,7 +541,7 @@ public:
|
||||||
/*
|
/*
|
||||||
Setup ray tracing shader groups
|
Setup ray tracing shader groups
|
||||||
*/
|
*/
|
||||||
std::array<VkRayTracingShaderGroupCreateInfoNV, 3> groups{};
|
std::array<VkRayTracingShaderGroupCreateInfoNV, NUM_SHADER_GROUPS> groups{};
|
||||||
for (auto& group : groups) {
|
for (auto& group : groups) {
|
||||||
// Init all groups with some default values
|
// Init all groups with some default values
|
||||||
group.sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV;
|
group.sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV;
|
||||||
|
|
|
||||||
|
|
@ -423,7 +423,6 @@ public:
|
||||||
VK_CHECK_RESULT(vkGetRayTracingShaderGroupHandlesNV(device, pipeline, 0, NUM_SHADER_GROUPS, sbtSize, shaderHandleStorage));
|
VK_CHECK_RESULT(vkGetRayTracingShaderGroupHandlesNV(device, pipeline, 0, NUM_SHADER_GROUPS, sbtSize, shaderHandleStorage));
|
||||||
auto* data = static_cast<uint8_t*>(shaderBindingTable.mapped);
|
auto* data = static_cast<uint8_t*>(shaderBindingTable.mapped);
|
||||||
// Copy the shader identifiers to the shader binding table
|
// Copy the shader identifiers to the shader binding table
|
||||||
VkDeviceSize offset = 0;
|
|
||||||
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_RAYGEN);
|
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_RAYGEN);
|
||||||
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_MISS);
|
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_MISS);
|
||||||
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_CLOSEST_HIT);
|
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_CLOSEST_HIT);
|
||||||
|
|
|
||||||
|
|
@ -432,7 +432,6 @@ public:
|
||||||
VK_CHECK_RESULT(vkGetRayTracingShaderGroupHandlesNV(device, pipeline, 0, NUM_SHADER_GROUPS, sbtSize, shaderHandleStorage));
|
VK_CHECK_RESULT(vkGetRayTracingShaderGroupHandlesNV(device, pipeline, 0, NUM_SHADER_GROUPS, sbtSize, shaderHandleStorage));
|
||||||
auto* data = static_cast<uint8_t*>(shaderBindingTable.mapped);
|
auto* data = static_cast<uint8_t*>(shaderBindingTable.mapped);
|
||||||
// Copy the shader identifiers to the shader binding table
|
// Copy the shader identifiers to the shader binding table
|
||||||
VkDeviceSize offset = 0;
|
|
||||||
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_RAYGEN);
|
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_RAYGEN);
|
||||||
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_MISS);
|
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_MISS);
|
||||||
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_SHADOW_MISS);
|
data += copyShaderIdentifier(data, shaderHandleStorage, INDEX_SHADOW_MISS);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue