From 6d8461f545ad46f0c17a4152aebaea47c55d35eb Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Thu, 8 Feb 2024 09:07:20 -0800 Subject: [PATCH] d3d12: Subgroup ballot Part-of: --- docs/features.txt | 2 +- src/gallium/drivers/d3d12/d3d12_compiler.cpp | 34 ++++++++++++++++++++ src/gallium/drivers/d3d12/d3d12_screen.cpp | 1 + 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/features.txt b/docs/features.txt index b68b62ec34a..12e52ca15d2 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -306,7 +306,7 @@ Khronos, ARB, and OES extensions that are not part of any OpenGL or OpenGL ES ve GL_ARB_robustness_isolation not started GL_ARB_sample_locations DONE (freedreno/a6xx, nvc0, zink) GL_ARB_seamless_cubemap_per_texture DONE (etnaviv/SEAMLESS_CUBE_MAP, freedreno, nvc0, r600, radeonsi, softpipe, virgl, zink, asahi, iris, crocus) - GL_ARB_shader_ballot DONE (nvc0, radeonsi, zink, iris, crocus/gen8) + GL_ARB_shader_ballot DONE (nvc0, radeonsi, zink, iris, crocus/gen8, d3d12) GL_ARB_shader_clock DONE (nv50, nvc0, r600, radeonsi, llvmpipe, virgl, zink, iris, crocus/gen7+) GL_ARB_shader_stencil_export DONE (r600, radeonsi, softpipe, llvmpipe, virgl, panfrost, zink, asahi, iris/gen9+) GL_ARB_shader_viewport_layer_array DONE (freedreno/a6xx, nvc0, radeonsi, zink, iris, crocus/gen6+) diff --git a/src/gallium/drivers/d3d12/d3d12_compiler.cpp b/src/gallium/drivers/d3d12/d3d12_compiler.cpp index 73191ee7ee5..14c307e4723 100644 --- a/src/gallium/drivers/d3d12/d3d12_compiler.cpp +++ b/src/gallium/drivers/d3d12/d3d12_compiler.cpp @@ -131,6 +131,40 @@ compile_nir(struct d3d12_context *ctx, struct d3d12_shader_selector *sel, shader->has_default_ubo0 = num_uniforms_before_lower_to_ubo > 0 && nir->info.num_ubos > num_ubos_before_lower_to_ubo; + NIR_PASS_V(nir, dxil_nir_lower_subgroup_id); + NIR_PASS_V(nir, dxil_nir_lower_num_subgroups); + + nir_lower_subgroups_options subgroup_options = {}; + subgroup_options.ballot_bit_size = 32; + subgroup_options.ballot_components = 4; + subgroup_options.lower_subgroup_masks = true; + subgroup_options.lower_to_scalar = true; + subgroup_options.lower_relative_shuffle = true; + subgroup_options.lower_inverse_ballot = true; + if (nir->info.stage != MESA_SHADER_FRAGMENT && nir->info.stage != MESA_SHADER_COMPUTE) + subgroup_options.lower_quad = true; + NIR_PASS_V(nir, nir_lower_subgroups, &subgroup_options); + NIR_PASS_V(nir, nir_lower_bit_size, [](const nir_instr *instr, void *) -> unsigned { + if (instr->type != nir_instr_type_intrinsic) + return 0; + nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr); + switch (intr->intrinsic) { + case nir_intrinsic_quad_swap_horizontal: + case nir_intrinsic_quad_swap_vertical: + case nir_intrinsic_quad_swap_diagonal: + case nir_intrinsic_reduce: + case nir_intrinsic_inclusive_scan: + case nir_intrinsic_exclusive_scan: + return intr->def.bit_size == 1 ? 32 : 0; + default: + return 0; + } + }, NULL); + + // Ensure subgroup scans on bools are gone + NIR_PASS_V(nir, nir_opt_dce); + NIR_PASS_V(nir, dxil_nir_lower_unsupported_subgroup_scan); + if (key->last_vertex_processing_stage) { if (key->invert_depth) NIR_PASS_V(nir, d3d12_nir_invert_depth, key->invert_depth, key->halfz); diff --git a/src/gallium/drivers/d3d12/d3d12_screen.cpp b/src/gallium/drivers/d3d12/d3d12_screen.cpp index 06fbb8ebe16..7d6a1aa1699 100644 --- a/src/gallium/drivers/d3d12/d3d12_screen.cpp +++ b/src/gallium/drivers/d3d12/d3d12_screen.cpp @@ -344,6 +344,7 @@ d3d12_get_param(struct pipe_screen *pscreen, enum pipe_cap param) case PIPE_CAP_GL_SPIRV: case PIPE_CAP_POLYGON_OFFSET_CLAMP: case PIPE_CAP_SHADER_GROUP_VOTE: + case PIPE_CAP_SHADER_BALLOT: case PIPE_CAP_QUERY_PIPELINE_STATISTICS: case PIPE_CAP_QUERY_SO_OVERFLOW: return 1;