Skip to content

Commit 14f5d35

Browse files
author
kevyuu
committed
Add more validation.
1 parent 52a636d commit 14f5d35

File tree

3 files changed

+51
-28
lines changed

3 files changed

+51
-28
lines changed

include/nbl/asset/IRayTracingPipeline.h

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,43 +107,53 @@ class IRayTracingPipeline : public IPipeline<PipelineLayoutType>, public IRayTra
107107
return shaders[index].shader->getStage();
108108
};
109109

110-
if (shaderGroups.raygen.index >= shaders.size())
111-
return false;
112-
if (getShaderStage(shaderGroups.raygen.index) != ICPUShader::E_SHADER_STAGE::ESS_RAYGEN)
113-
return false;
114-
115-
auto isValidShaderIndex = [this, getShaderStage](size_t index, ICPUShader::E_SHADER_STAGE expectedStage) -> bool
110+
auto isValidShaderIndex = [this, getShaderStage](size_t index, ICPUShader::E_SHADER_STAGE expectedStage, bool is_unused_shader_forbidden) -> bool
116111
{
117112
if (index == SShaderGroupsParams::SIndex::Unused)
118-
return true;
113+
return !is_unused_shader_forbidden;
119114
if (index >= shaders.size())
120115
return false;
121116
if (getShaderStage(index) != expectedStage)
122117
return false;
123118
return true;
124119
};
125120

121+
if (isValidShaderIndex(shaderGroups.raygen.index, ICPUShader::E_SHADER_STAGE::ESS_RAYGEN, true))
122+
{
123+
return false;
124+
}
125+
126126
for (const auto& shaderGroup : shaderGroups.hits)
127127
{
128-
if (!isValidShaderIndex(shaderGroup.anyHit, ICPUShader::E_SHADER_STAGE::ESS_ANY_HIT))
128+
// https://docs.vulkan.org/spec/latest/chapters/pipelines.html#VUID-VkRayTracingPipelineCreateInfoKHR-flags-03470
129+
if (!isValidShaderIndex(shaderGroup.anyHit,
130+
ICPUShader::E_SHADER_STAGE::ESS_ANY_HIT,
131+
bool(flags & FLAGS::NO_NULL_ANY_HIT_SHADERS)))
129132
return false;
130133

131-
if (!isValidShaderIndex(shaderGroup.closestHit, ICPUShader::E_SHADER_STAGE::ESS_CLOSEST_HIT))
134+
// https://docs.vulkan.org/spec/latest/chapters/pipelines.html#VUID-VkRayTracingPipelineCreateInfoKHR-flags-03471
135+
if (!isValidShaderIndex(shaderGroup.closestHit,
136+
ICPUShader::E_SHADER_STAGE::ESS_CLOSEST_HIT,
137+
bool(flags & FLAGS::NO_NULL_CLOSEST_HIT_SHADERS)))
132138
return false;
133139

134-
if (!isValidShaderIndex(shaderGroup.intersectionShader, ICPUShader::E_SHADER_STAGE::ESS_INTERSECTION))
140+
if (!isValidShaderIndex(shaderGroup.intersectionShader,
141+
ICPUShader::E_SHADER_STAGE::ESS_INTERSECTION,
142+
false))
135143
return false;
136144
}
137145

138146
for (const auto& shaderGroup : shaderGroups.misses)
139147
{
140-
if (!isValidShaderIndex(shaderGroup.index, ICPUShader::E_SHADER_STAGE::ESS_MISS))
148+
if (!isValidShaderIndex(shaderGroup.index,
149+
ICPUShader::E_SHADER_STAGE::ESS_MISS,
150+
false))
141151
return false;
142152
}
143153

144154
for (const auto& shaderGroup : shaderGroups.callables)
145155
{
146-
if (!isValidShaderIndex(shaderGroup.index, ICPUShader::E_SHADER_STAGE::ESS_CALLABLE))
156+
if (!isValidShaderIndex(shaderGroup.index, ICPUShader::E_SHADER_STAGE::ESS_CALLABLE, false))
147157
return false;
148158
}
149159
return true;
@@ -163,6 +173,8 @@ class IRayTracingPipeline : public IPipeline<PipelineLayoutType>, public IRayTra
163173
std::span<const SpecInfo> shaders = {};
164174
SShaderGroupsParams shaderGroups;
165175
SCachedCreationParams cached = {};
176+
// TODO: Could guess the required flags from SPIR-V introspection of declared caps
177+
core::bitflag<FLAGS> flags = FLAGS::NONE;
166178
};
167179

168180
inline const SCachedCreationParams& getCachedCreationParams() const { return m_params; }

include/nbl/video/IGPURayTracingPipeline.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ class IGPURayTracingPipeline : public IBackendObject, public asset::IRayTracingP
5656

5757
inline std::span<const IGPUShader::SSpecInfo> getShaders() const { return shaders; }
5858

59-
// TODO: Could guess the required flags from SPIR-V introspection of declared caps
60-
core::bitflag<FLAGS> flags = FLAGS::NONE;
6159
};
6260

6361
inline core::bitflag<SCreationParams::FLAGS> getCreationFlags() const { return m_flags; }

src/nbl/video/ILogicalDevice.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -963,36 +963,49 @@ bool ILogicalDevice::createRayTracingPipelines(IGPUPipelineCache* const pipeline
963963
}
964964

965965
const auto& features = getEnabledFeatures();
966+
967+
// https://docs.vulkan.org/spec/latest/chapters/pipelines.html#VUID-vkCreateRayTracingPipelinesKHR-rayTracingPipeline-03586
966968
if (!features.rayTracingPipeline)
967969
{
968970
NBL_LOG_ERROR("Feature `ray tracing pipeline` is not enabled");
969971
return false;
970972
}
971973

972-
if (!features.rayTraversalPrimitiveCulling)
974+
for (const auto& param : params)
973975
{
974-
for (const auto& param : params)
976+
const bool skipAABBs = bool(param.flags & IGPURayTracingPipeline::SCreationParams::FLAGS::SKIP_AABBS);
977+
const bool skipBuiltin = bool(param.flags & IGPURayTracingPipeline::SCreationParams::FLAGS::SKIP_BUILT_IN_PRIMITIVES);
978+
979+
// https://docs.vulkan.org/spec/latest/chapters/pipelines.html#VUID-VkRayTracingPipelineCreateInfoKHR-rayTraversalPrimitiveCulling-03597
980+
if (skipAABBs && skipBuiltin)
975981
{
976-
// https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#VUID-VkRayTracingPipelineCreateInfoKHR-rayTraversalPrimitiveCulling-03596
977-
if (param.flags & IGPURayTracingPipeline::SCreationParams::FLAGS::SKIP_AABBS)
978-
{
979-
NBL_LOG_ERROR("Feature `rayTraversalPrimitiveCulling` is not enabled when pipeline is created with SKIP_AABBS");
980-
return false;
981-
}
982+
NBL_LOG_ERROR("Flags must not include both SKIP_AABBS and SKIP_BUILT_IN_PRIMITIVE!");
983+
return false;
984+
}
982985

983-
// https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#VUID-VkRayTracingPipelineCreateInfoKHR-rayTraversalPrimitiveCulling-03597
984-
if (param.flags & IGPURayTracingPipeline::SCreationParams::FLAGS::SKIP_BUILT_IN_PRIMITIVES)
985-
{
986-
NBL_LOG_ERROR("Feature `rayTraversalPrimitiveCulling` is not enabled when pipeline is created with SKIP_BUILT_IN_PRIMITIVES");
987-
return false;
988-
}
986+
// https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#VUID-VkRayTracingPipelineCreateInfoKHR-rayTraversalPrimitiveCulling-03596
987+
if (skipAABBs && !features.rayTraversalPrimitiveCulling)
988+
{
989+
NBL_LOG_ERROR("Feature `rayTraversalPrimitiveCulling` is not enabled when pipeline is created with SKIP_AABBS");
990+
return false;
991+
}
989992

993+
// https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#VUID-VkRayTracingPipelineCreateInfoKHR-rayTraversalPrimitiveCulling-03597
994+
if (skipBuiltin && !features.rayTraversalPrimitiveCulling)
995+
{
996+
NBL_LOG_ERROR("Feature `rayTraversalPrimitiveCulling` is not enabled when pipeline is created with SKIP_BUILT_IN_PRIMITIVES");
997+
return false;
990998
}
999+
1000+
}
1001+
if (!features.rayTraversalPrimitiveCulling)
1002+
{
9911003
}
9921004

9931005
const auto& limits = getPhysicalDeviceLimits();
9941006
for (const auto& param : params)
9951007
{
1008+
// https://docs.vulkan.org/spec/latest/chapters/pipelines.html#VUID-VkRayTracingPipelineCreateInfoKHR-maxPipelineRayRecursionDepth-03589
9961009
if (param.cached.maxRecursionDepth > limits.maxRayRecursionDepth)
9971010
{
9981011
NBL_LOG_ERROR("Invalid maxRecursionDepth. maxRecursionDepth(%u) exceed the limits(%u)", param.cached.maxRecursionDepth, limits.maxRayRecursionDepth);

0 commit comments

Comments
 (0)