shaders
shaders copied to clipboard
"flat" is automatically added to int/ivec attributes
This is probably an intended feature, but when the compiler adds "flat" to vertex shader input, and I convert the file to GLSL using SPIRV-Cross, loaded it into my OpenGL program, it triggers a compilation error. (I haven't tried passing the SPIR-V code directly to GL though.)
Example:
This code:
[[spirv::in(0)]]
ivec4 pos;
[[spirv::vert]]
void vert_main() {
glvert_Output.Position = vec4(pos);
}
becomes this in SPIR-V disassembly:
; SPIR-V
; Version: 1.5
; Generator: Khronos; 0
; Bound: 19
; Schema: 0
OpCapability Shader
OpExtension "GL_EXT_scalar_block_layout"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %_Z9vert_mainv "_Z9vert_mainv" %pos %glvert_Output
OpName %pos "pos"
OpName %gl_PerVertex "gl_PerVertex"
OpMemberName %gl_PerVertex 0 "Position"
OpName %glvert_Output "glvert_Output"
OpName %_Z9vert_mainv "_Z9vert_mainv"
OpDecorate %pos Location 0
OpDecorate %pos Flat
OpDecorate %gl_PerVertex Block
OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
%int = OpTypeInt 32 1
%v4int = OpTypeVector %int 4
%_ptr_Input_v4int = OpTypePointer Input %v4int
%pos = OpVariable %_ptr_Input_v4int Input
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%gl_PerVertex = OpTypeStruct %v4float
%_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
%glvert_Output = OpVariable %_ptr_Output_gl_PerVertex Output
%void = OpTypeVoid
%12 = OpTypeFunction %void
%_ptr_Output_v4float = OpTypePointer Output %v4float
%int_0 = OpConstant %int 0
%_Z9vert_mainv = OpFunction %void None %12
%13 = OpLabel
%14 = OpLoad %v4int %pos
%15 = OpConvertSToF %v4float %14
%18 = OpAccessChain %_ptr_Output_v4float %glvert_Output %int_0
OpStore %18 %15
OpReturn
OpFunctionEnd
(flat is added in line 16)
GLSL output:
#version 450
layout(location = 0) flat in ivec4 pos;
void main()
{
gl_Position = vec4(pos);
}
Adding something like [[spirv::noflat]]
would be helpful
Ya flat is intentional. When I get around to more shader improvements I will add a noflat attribute.