mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-24 15:20:10 +01:00
radv/rt: use stage ID as handle for general and closestHit shaders
This avoids some code duplication and divergence. Quake II RTX: Totals from 7 (0.01% of 134913) affected shaders: CodeSize: 218880 -> 217592 (-0.59%) Instrs: 39692 -> 39468 (-0.56%) Latency: 789091 -> 761581 (-3.49%) InvThroughput: 526061 -> 507721 (-3.49%) VClause: 1202 -> 1188 (-1.16%) Copies: 4649 -> 4621 (-0.60%) Branches: 1605 -> 1598 (-0.44%) Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17301>
This commit is contained in:
parent
3750663c72
commit
c39cccec9c
1 changed files with 14 additions and 22 deletions
|
|
@ -1804,28 +1804,16 @@ create_rt_shader(struct radv_device *device, const VkRayTracingPipelineCreateInf
|
||||||
nir_ssa_def *idx = nir_load_var(&b, vars.idx);
|
nir_ssa_def *idx = nir_load_var(&b, vars.idx);
|
||||||
|
|
||||||
/* We do a trick with the indexing of the resume shaders so that the first
|
/* We do a trick with the indexing of the resume shaders so that the first
|
||||||
* shader of group x always gets id x and the resume shader ids then come after
|
* shader of stage x always gets id x and the resume shader ids then come after
|
||||||
* groupCount. This makes the shadergroup handles independent of compilation. */
|
* stageCount. This makes the shadergroup handles independent of compilation. */
|
||||||
unsigned call_idx_base = pCreateInfo->groupCount + 1;
|
unsigned call_idx_base = pCreateInfo->stageCount + 1;
|
||||||
for (unsigned i = 0; i < pCreateInfo->groupCount; ++i) {
|
for (unsigned i = 0; i < pCreateInfo->stageCount; ++i) {
|
||||||
const VkRayTracingShaderGroupCreateInfoKHR *group_info = &pCreateInfo->pGroups[i];
|
const VkPipelineShaderStageCreateInfo *stage = &pCreateInfo->pStages[i];
|
||||||
uint32_t shader_id = VK_SHADER_UNUSED_KHR;
|
gl_shader_stage type = vk_to_mesa_shader_stage(stage->stage);
|
||||||
|
if (type != MESA_SHADER_RAYGEN && type != MESA_SHADER_CALLABLE &&
|
||||||
switch (group_info->type) {
|
type != MESA_SHADER_CLOSEST_HIT && type != MESA_SHADER_MISS)
|
||||||
case VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR:
|
|
||||||
shader_id = group_info->generalShader;
|
|
||||||
break;
|
|
||||||
case VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR:
|
|
||||||
case VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR:
|
|
||||||
shader_id = group_info->closestHitShader;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (shader_id == VK_SHADER_UNUSED_KHR)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const VkPipelineShaderStageCreateInfo *stage = &pCreateInfo->pStages[shader_id];
|
|
||||||
nir_shader *nir_stage = parse_rt_stage(device, stage);
|
nir_shader *nir_stage = parse_rt_stage(device, stage);
|
||||||
|
|
||||||
/* Move ray tracing system values to the top that are set by rt_trace_ray
|
/* Move ray tracing system values to the top that are set by rt_trace_ray
|
||||||
|
|
@ -1948,12 +1936,16 @@ radv_rt_pipeline_create(VkDevice _device, VkPipelineCache _cache,
|
||||||
|
|
||||||
compute_pipeline->dynamic_stack_size = radv_rt_pipeline_has_dynamic_stack_size(pCreateInfo);
|
compute_pipeline->dynamic_stack_size = radv_rt_pipeline_has_dynamic_stack_size(pCreateInfo);
|
||||||
|
|
||||||
|
/* For General and ClosestHit shaders, we can use the shader ID directly as handle.
|
||||||
|
* As (potentially different) AnyHit shaders are inlined, for Intersection shaders
|
||||||
|
* we use the Group ID.
|
||||||
|
*/
|
||||||
for (unsigned i = 0; i < local_create_info.groupCount; ++i) {
|
for (unsigned i = 0; i < local_create_info.groupCount; ++i) {
|
||||||
const VkRayTracingShaderGroupCreateInfoKHR *group_info = &local_create_info.pGroups[i];
|
const VkRayTracingShaderGroupCreateInfoKHR *group_info = &local_create_info.pGroups[i];
|
||||||
switch (group_info->type) {
|
switch (group_info->type) {
|
||||||
case VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR:
|
case VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR:
|
||||||
if (group_info->generalShader != VK_SHADER_UNUSED_KHR)
|
if (group_info->generalShader != VK_SHADER_UNUSED_KHR)
|
||||||
compute_pipeline->rt_group_handles[i].handles[0] = i + 2;
|
compute_pipeline->rt_group_handles[i].handles[0] = group_info->generalShader + 2;
|
||||||
break;
|
break;
|
||||||
case VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR:
|
case VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR:
|
||||||
if (group_info->intersectionShader != VK_SHADER_UNUSED_KHR)
|
if (group_info->intersectionShader != VK_SHADER_UNUSED_KHR)
|
||||||
|
|
@ -1961,7 +1953,7 @@ radv_rt_pipeline_create(VkDevice _device, VkPipelineCache _cache,
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR:
|
case VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR:
|
||||||
if (group_info->closestHitShader != VK_SHADER_UNUSED_KHR)
|
if (group_info->closestHitShader != VK_SHADER_UNUSED_KHR)
|
||||||
compute_pipeline->rt_group_handles[i].handles[0] = i + 2;
|
compute_pipeline->rt_group_handles[i].handles[0] = group_info->closestHitShader + 2;
|
||||||
if (group_info->anyHitShader != VK_SHADER_UNUSED_KHR)
|
if (group_info->anyHitShader != VK_SHADER_UNUSED_KHR)
|
||||||
compute_pipeline->rt_group_handles[i].handles[1] = i + 2;
|
compute_pipeline->rt_group_handles[i].handles[1] = i + 2;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue