[SPIR-V] ShaderViewportIndexLayerEXT is now Core 1.2
Hello, the SPIR-V compiler adds the ShaderViewportIndexLayerEXT extension requirement to some of my shaders, but I believe they should be using the ShaderViewportIndex or ShaderLayer features instead: https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#spirvenv-capabilities-table-ShaderViewportIndex
I am using the -fspv-target-env=vulkan1.2 flag when compiling shaders. I am using the latest official DXC release.
@turanszkij could you please give us more information?
the SPIR-V compiler adds the ShaderViewportIndexLayerEXT extension requirement
Do you have validation errors?
If you provided us with a minimal reproducible shader, command to build the shader, and the error message, it would be easier to understand this issue.
Sure, this is a vertex shader that writes to a render target slice:
struct VSOut
{
float4 position : SV_Position;
uint rtindex : SV_RenderTargetArrayIndex;
};
VSOut main(float4 pos : POSITION, uint inst : SV_InstanceID)
{
VSOut ret;
ret.position = pos;
ret.rtindex = inst;
return ret;
}
Compiled with the DXC release found here: https://github.com/microsoft/DirectXShaderCompiler/releases/tag/v1.6.2106 With the following arguments:
dxc vs.hlsl -T vs_6_0 -spirv -fspv-target-env=vulkan1.2
Produces this code:
; SPIR-V
; Version: 1.5
; Generator: Google spiregg; 0
; Bound: 18
; Schema: 0
OpCapability Shader
OpCapability ShaderViewportIndexLayerEXT
OpExtension "SPV_EXT_shader_viewport_index_layer"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %main "main" %gl_Position %gl_InstanceIndex %gl_Layer %in_var_POSITION
OpSource HLSL 600
OpName %in_var_POSITION "in.var.POSITION"
OpName %main "main"
OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex
OpDecorate %gl_Position BuiltIn Position
OpDecorate %gl_Layer BuiltIn Layer
OpDecorate %gl_Layer Flat
OpDecorate %in_var_POSITION Location 0
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Input_v4float = OpTypePointer Input %v4float
%uint = OpTypeInt 32 0
%_ptr_Input_uint = OpTypePointer Input %uint
%_ptr_Output_v4float = OpTypePointer Output %v4float
%_ptr_Output_uint = OpTypePointer Output %uint
%void = OpTypeVoid
%14 = OpTypeFunction %void
%in_var_POSITION = OpVariable %_ptr_Input_v4float Input
%gl_InstanceIndex = OpVariable %_ptr_Input_uint Input
%gl_Position = OpVariable %_ptr_Output_v4float Output
%gl_Layer = OpVariable %_ptr_Output_uint Output
%main = OpFunction %void None %14
%15 = OpLabel
%16 = OpLoad %v4float %in_var_POSITION
%17 = OpLoad %uint %gl_InstanceIndex
OpStore %gl_Position %16
OpStore %gl_Layer %17
OpReturn
OpFunctionEnd
Notice that it states the capability: OpCapability ShaderViewportIndexLayerEXT
I'd expect that this extension wouldn't be required with Vulkan 1.2, as it is now in the core as ShaderViewportIndex and ShaderLayer
This is described here: https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VK_EXT_shader_viewport_index_layer.html
Hello!
I can reproduce this one, I'll take a look into it 🙂
Hello! Update on this: found the reason: DXC doesn't check the SPV version and requests the extension all the time. Fix seemed trivial, but now DXC just drops the generated SPV without errors. Trying to understand why.