From 2491ac5f42d78d082d4afa6416906fad9b32ea80 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Oct 2025 12:52:50 -0700 Subject: Add direct usage support for gl_DrawID (#8594) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - [x] Add `gl_DrawID` property declaration in `source/slang/glsl.meta.slang` similar to `gl_BaseVertex` and `gl_BaseInstance` - [x] Ensure it maps to `SV_DrawIndex` semantic - [x] Add extension requirements in `slang-ir-glsl-legalize.cpp` (GLSL 460 and GL_ARB_shader_draw_parameters) - [x] Create test case to verify SPIRV output contains `DrawIndex` decoration - [x] Run formatting script before committing - [x] Verify existing tests still pass - [x] Remove accidentally committed temp files (1.glsl, 3.spv-asm) - [x] Update .gitignore to prevent similar files from being committed
Original prompt > > ---- > > *This section details on the original issue you should resolve* > > Missing direct usage support for gl_DrawID > # Problem Description > Because DirectX does not have support for DrawIndex like vulkan does, i add the support in d3d12 by emulating it and storing it in a root constant. In vulkan though, i should be able to use it directly, but because now i store it as a global variable, i cannot use the SV_DrawIndex semantic either. > > # Preferred Solution > I'd like to be able to use gl_DrawID like you how can use gl_BaseVertex and gl_BaseInstance. > > > You can just edit glsl.meta.slang and add a declaration for gl_DrawID in a similar way to gl_BaseVertex, and map it to SV_DrawIndex. > > Create a `//TEST:SIMPLE(filecheck=SPIRV): -target spirv` test case, and use filecheck to verify the output contains the correct SPIRV `DrawIndex` decoration. > > ## Comments on the Issue (you are @copilot in this section) > > > >
Fixes shader-slang/slang#8548 --- ✨ Let Copilot coding agent [set things up for you](https://github.com/shader-slang/slang/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> --- source/slang/glsl.meta.slang | 1 + source/slang/slang-ir-glsl-legalize.cpp | 3 +++ 2 files changed, 4 insertions(+) (limited to 'source') diff --git a/source/slang/glsl.meta.slang b/source/slang/glsl.meta.slang index f63daf6b0..c78aa2a15 100644 --- a/source/slang/glsl.meta.slang +++ b/source/slang/glsl.meta.slang @@ -215,6 +215,7 @@ public in int gl_ViewIndex : SV_ViewID; public in int gl_ViewportIndex : SV_ViewportArrayIndex; public in int gl_BaseVertex : SV_StartVertexLocation; public in int gl_BaseInstance : SV_StartInstanceLocation; +public in int gl_DrawID : SV_DrawIndex; public in int gl_FragInvocationCountEXT : SV_FragInvocationCount; public in int2 gl_FragSizeEXT : SV_FragSize; diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp index bc26b223b..1511bbff2 100644 --- a/source/slang/slang-ir-glsl-legalize.cpp +++ b/source/slang/slang-ir-glsl-legalize.cpp @@ -678,6 +678,9 @@ GLSLSystemValueInfo* getGLSLSystemValueInfo( } else if (semanticName == "sv_drawindex") { + context->requireGLSLVersion(ProfileVersion::GLSL_460); + context->requireGLSLExtension(toSlice("GL_ARB_shader_draw_parameters")); + name = "gl_DrawID"; requiredType = builder->getBasicType(BaseType::Int); } -- cgit v1.2.3