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

OpSelect does not follow SPIR-V spec #809

Closed
amdrexu opened this issue Mar 30, 2017 · 3 comments
Closed

OpSelect does not follow SPIR-V spec #809

amdrexu opened this issue Mar 30, 2017 · 3 comments
Assignees

Comments

@amdrexu
Copy link
Contributor

amdrexu commented Mar 30, 2017

We have encountered an issue of OpSelect, here is the shader:

#version 450

layout(location = 0) in  vec2 uv;
layout(location = 0) out vec4 o;

bool verify()
{
    return uv == vec2(0.0);
}

void main()
{
    o = verify() ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
}

This is the SPIR-V

// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 30

                              Capability Shader
               1:             ExtInstImport  "GLSL.std.450"
                              MemoryModel Logical GLSL450
                              EntryPoint Fragment 4  "main" 13 24
                              ExecutionMode 4 OriginUpperLeft
                              Source GLSL 450
                              Name 4  "main"
                              Name 8  "verify("
                              Name 13  "uv"
                              Name 24  "o"
                              Decorate 13(uv) Location 0
                              Decorate 24(o) Location 0
               2:             TypeVoid
               3:             TypeFunction 2
               6:             TypeBool
               7:             TypeFunction 6(bool)
              10:             TypeFloat 32
              11:             TypeVector 10(float) 2
              12:             TypePointer Input 11(fvec2)
          13(uv):     12(ptr) Variable Input
              15:   10(float) Constant 0
              16:   11(fvec2) ConstantComposite 15 15
              17:             TypeVector 6(bool) 2
              22:             TypeVector 10(float) 4
              23:             TypePointer Output 22(fvec4)
           24(o):     23(ptr) Variable Output
              26:   10(float) Constant 1065353216
              27:   22(fvec4) ConstantComposite 15 26 15 26
              28:   22(fvec4) ConstantComposite 26 15 15 26
         4(main):           2 Function None 3
               5:             Label
              25:     6(bool) FunctionCall 8(verify()
              29:   22(fvec4) Select 25 27 28
                              Store 24(o) 29
                              Return
                              FunctionEnd
      8(verify():     6(bool) Function None 7
               9:             Label
              14:   11(fvec2) Load 13(uv)
              18:   17(bvec2) FOrdEqual 14 16
              19:     6(bool) All 18
                              ReturnValue 19
                              FunctionEnd

Please pay attention to these instructions:

25:     6(bool) FunctionCall 8(verify()
29:   22(fvec4) Select 25 27 28

25 is a boolean while 29, 27, 28 are all floating-point vectors. In SPIR-V spec, it says:
Condition must be a scalar or vector of Boolean type. It must have the same number of components as Result Type.

So apparently, it violates the spec. Do I miss something? In LLVM spec, the condition could be a scalar (perform vector selection) or a vector (perform component-wise selection). I want to confirm whether it is a spec bug or a glslang bug.

Thank you.

@johnkslang
Copy link
Member

It would be valuable to have a selection instruction that took a bool and selected between two composite objects of the same type. SPIR-V is quite clear that OpSelect does not do that (as you quoted), but I think that's what the implementation expected.

So, for now the implementation needs to be fixed in glslang, but I'd also like a spec issue to request the new behavior; it has come up for selecting between two structures as well, without having to use control flow.

@johnkslang
Copy link
Member

Clarifying: my "implementation", I meant glslang.

So, I'll fix glslang, and also request that we have an instruction added to SPIR-V.

@amdrexu
Copy link
Contributor Author

amdrexu commented Mar 31, 2017

Thank you. It is clear now.

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

No branches or pull requests

2 participants