Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"flat" is automatically added to int/ivec attributes #14

Open
btmxh opened this issue Sep 4, 2021 · 2 comments
Open

"flat" is automatically added to int/ivec attributes #14

btmxh opened this issue Sep 4, 2021 · 2 comments

Comments

@btmxh
Copy link

btmxh commented Sep 4, 2021

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);
}
@btmxh
Copy link
Author

btmxh commented Sep 4, 2021

Adding something like [[spirv::noflat]] would be helpful

@seanbaxter
Copy link
Owner

Ya flat is intentional. When I get around to more shader improvements I will add a noflat attribute.

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

No branches or pull requests

2 participants