Skip to content

Optimize SPV_EXT_opacity_micromap and SPV_EXT_shader_invocation_reorder#6571

Merged
s-perron merged 3 commits intoKhronosGroup:mainfrom
MarijnS95:important-exts
Mar 11, 2026
Merged

Optimize SPV_EXT_opacity_micromap and SPV_EXT_shader_invocation_reorder#6571
s-perron merged 3 commits intoKhronosGroup:mainfrom
MarijnS95:important-exts

Conversation

@MarijnS95
Copy link
Copy Markdown
Contributor

It's been a while since I last added extensions to these lists, but I just ran into a long-forgotten related issue again that DXC outputs invalid SPIR-V before it's stripped away by spirv-opt: microsoft/DirectXShaderCompiler#8210.

Shaders with these extensions weren't yet extensively tested but this at least gets us past spir-val in both DXC (can also be disabled with -Vd) and the validation layers.


I'm probably way out of my league to ask, but is there still much significance to extensions_allowlist_? It seems like a maintenance burden that's very easy to miss, for (currently) a single extension that's specifically commented out to not be optimized.

It's also mostly duplicated but not entirely in sync across all 4 passes either. I even noticed that SPV_KHR_shader_clock which I added to dead_code_elim_pass in #4049 isn't in any other file, which must have been an oversight on my part but also means that presence of this extension erroneously disables all the other 3 passes.

@MarijnS95 MarijnS95 changed the title Optimize SPV_EXT_opacity_micromap and SPV_EXT_shader_invocation_reorder Optimize SPV_EXT_opacity_micromap and SPV_EXT_shader_invocation_reorder Mar 5, 2026
@MarijnS95
Copy link
Copy Markdown
Contributor Author

MarijnS95 commented Mar 5, 2026

After adding what I believe to be erroneously missing SPV_KHR_shader_clock, and resorting a few other strings to bring the files back together, this is the remaining diff:

diff --git a/source/opt/local_single_block_elim_pass.cpp b/source/opt/local_single_store_elim_pass.cpp
index 021aaca19..df35401eb 100644
--- a/source/opt/local_single_block_elim_pass.cpp
+++ b/source/opt/local_single_store_elim_pass.cpp
@@ -269,7 +122,6 @@ void LocalSingleBlockLoadStoreElimPass::InitExtensions() {
       "SPV_GOOGLE_hlsl_functionality1",
       "SPV_GOOGLE_user_type",
       "SPV_NV_shader_subgroup_partitioned",
-      "SPV_EXT_demote_to_helper_invocation",
       "SPV_EXT_descriptor_indexing",
       "SPV_EXT_descriptor_heap",
       "SPV_NV_fragment_shader_barycentric",
diff --git a/source/opt/local_single_block_elim_pass.cpp b/source/opt/local_access_chain_convert_pass.cpp
index 021aaca19..d604777a0 100644
--- a/source/opt/local_single_block_elim_pass.cpp
+++ b/source/opt/local_access_chain_convert_pass.cpp
@@ -255,7 +419,8 @@ void LocalSingleBlockLoadStoreElimPass::InitExtensions() {
       "SPV_NV_geometry_shader_passthrough",
       "SPV_AMD_texture_gather_bias_lod",
       "SPV_KHR_storage_buffer_storage_class",
-      "SPV_KHR_variable_pointers",
+      // SPV_KHR_variable_pointers
+      //   Currently do not support extended pointer expressions
       "SPV_AMD_gpu_shader_int16",
       "SPV_KHR_post_depth_coverage",
       "SPV_KHR_shader_atomic_counter_ops",
@@ -282,8 +447,6 @@ void LocalSingleBlockLoadStoreElimPass::InitExtensions() {
       "SPV_KHR_ray_tracing",
       "SPV_KHR_ray_query",
       "SPV_EXT_fragment_invocation_density",
-      "SPV_EXT_physical_storage_buffer",
-      "SPV_KHR_physical_storage_buffer",
       "SPV_KHR_terminate_invocation",
       "SPV_KHR_shader_clock",
       "SPV_KHR_subgroup_uniform_control_flow",
diff --git a/source/opt/local_single_block_elim_pass.cpp b/source/opt/aggressive_dead_code_elim_pass.cpp
index 021aaca19..b8f239d2e 100644
--- a/source/opt/local_single_block_elim_pass.cpp
+++ b/source/opt/aggressive_dead_code_elim_pass.cpp
@@ -255,7 +1105,8 @@ void LocalSingleBlockLoadStoreElimPass::InitExtensions() {
       "SPV_NV_geometry_shader_passthrough",
       "SPV_AMD_texture_gather_bias_lod",
       "SPV_KHR_storage_buffer_storage_class",
-      "SPV_KHR_variable_pointers",
+      // SPV_KHR_variable_pointers
+      //   Currently do not support extended pointer expressions
       "SPV_AMD_gpu_shader_int16",
       "SPV_KHR_post_depth_coverage",
       "SPV_KHR_shader_atomic_counter_ops",
@@ -300,7 +1151,6 @@ void LocalSingleBlockLoadStoreElimPass::InitExtensions() {
       "SPV_NV_cooperative_matrix",
       "SPV_KHR_cooperative_matrix",
       "SPV_KHR_ray_tracing_position_fetch",
-      "SPV_AMDX_shader_enqueue",
       "SPV_KHR_fragment_shading_rate",
       "SPV_KHR_quad_control",
       "SPV_NV_shader_invocation_reorder",

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 5, 2026

CLA assistant check
All committers have signed the CLA.

@s-perron
Copy link
Copy Markdown
Collaborator

I'm probably way out of my league to ask, but is there still much significance to extensions_allowlist_? It seems like a maintenance burden that's very easy to miss, for (currently) a single extension that's specifically commented out to not be optimized.

That is a good question. This was a decision we made when the project first started. Those passes make very important assumptions about pointers. We assume no pointer aliasing, and that pointers do not escape. However, there are a handleful of capabilities and extensions that allow the spir-v to breaks those assumptions.

We feel that it is easier to identify cases where the passes are not run than to identify when a new extension is added to spir-v that invalidates our assumptions. In the latter case, people will get get an error at run time because their variables do not seem to have the correct values. It will only happen in select situations. It will be very hard to debug.

That is why we have it the way we do, even if it is a annoying how often people ignore updating this list when updating the validator for their new extensions.

@s-perron s-perron merged commit 6e9d60d into KhronosGroup:main Mar 11, 2026
22 checks passed
@MarijnS95 MarijnS95 deleted the important-exts branch March 11, 2026 14:57
@MarijnS95
Copy link
Copy Markdown
Contributor Author

Thanks for the info. Just fwiw, these extensions weren't tested well yet and at least my custom SPV_EXT_shader_invocation_reorder based shader isn't yet functional; could that be the "error at run time" that you're referring to?

And do you think we need to annotate the remaining differences between the optimizations, explaining why they're intentionally omitted in some places (like SPV_KHR_variable_pointers)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants