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

SPIRV: Remapper: allow 64 bit literals in OperandVariableLiteralId iteration #456

Merged
merged 1 commit into from Aug 12, 2016
Merged

Conversation

ghost
Copy link

@ghost ghost commented Aug 12, 2016

This PR addresses issue #435, where iteration over the OperandVariableLiteralId argument list class would not cope with multiple word literals.

It also includes a small improvement to dead type elimination which picks up some cases previously dropped. The algorithm used for this is suboptimal, but it's an offline tool, it was easy to write that way, and it can be further improved later if there is ever a performance concern.

numOperands -= 2;
case spv::OperandVariableLiteralId: {
// word-2 is the position of the selector ID.
const unsigned literalSize = idTypeSizeInWords(asId(word-2));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "word-2" expression is strongly tied to the fact that this must be an OpSwitch instruction. It just so happens that OpSwitch is the only case so far where we have an OperandVariableLiteralId.
I'd probably assert that opcode == OpSwitch.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Will change.

@dneto0
Copy link
Contributor

dneto0 commented Aug 12, 2016

Works for me.

The only other place in the grammar where Ids and literals are mixed is in OpGroupMemberDecorate, but there the literals are the 32-bit index of the structure member. So this problem won't occur in that context.

This patch works on the submitted case, and also in the following, were I made OpConstant for 64-bit integer and 64-bit float:

               OpCapability Shader
               OpMemoryModel Logical GLSL450
       %void = OpTypeVoid
       %long = OpTypeInt 64 1
     %double = OpTypeFloat 64
          %4 = OpConstant %double 3.14
          %5 = OpConstant %long 5000000000
          %6 = OpTypeFunction %void
          %7 = OpConstant %long 0
          %8 = OpFunction %void None %6
          %9 = OpLabel
               OpSelectionMerge %10 None
               OpSwitch %7 %10 0 %11 1 %12
         %11 = OpLabel
               OpBranch %10
         %12 = OpLabel
               OpBranch %10
         %10 = OpLabel
               OpReturn
               OpFunctionEnd

@ghost
Copy link
Author

ghost commented Aug 12, 2016

Cool; thanks for the review. I've pushed a new version with your review changes.

@ghost ghost changed the title WIP: SPIRV: allow 64 bit literals in OperandVariableLiteralId iteration SPIRV: allow 64 bit literals in OperandVariableLiteralId iteration Aug 12, 2016
@ghost ghost changed the title SPIRV: allow 64 bit literals in OperandVariableLiteralId iteration SPIRV: Remapper: allow 64 bit literals in OperandVariableLiteralId iteration Aug 12, 2016
@johnkslang johnkslang merged commit ad08b30 into KhronosGroup:master Aug 12, 2016
@dneto0
Copy link
Contributor

dneto0 commented Aug 12, 2016

Ooops. This is causing a failure in the Vulkan CTS.
I get an abnormal exit in vk-build-programs --deqp-case=dEQP-VK.glsl.constant_expressions.other.switch_case_fragment

@dneto0
Copy link
Contributor

dneto0 commented Aug 12, 2016

This is the failing test case, in GLSL form.
When I compile this with -V and then run it through the remapper, I get an internal error message:
"ID not found".

#version 310 es
//;dEQP-VK.glsl.constant_expressions.other.switch_case_fragment
precision highp float;
bool isOk (int a, int b)     { return (a == b); }
layout(location = 0) out mediump vec4 dEQP_FragColor;
layout(location = 0) flat in float in0;
layout(binding = 0, std140) uniform Reference
{
        int out0;
} ref;
int out0;


void main()
{
        const int _0 = 0;
        const int _1 = 1;
        const int _2 = 2;
        const int _3 = 3;
        const int _4 = 4;

        switch(int(in0))
        {
                case _0:
                        out0 = 0;
                        break;
                case _1:
                        out0 = 1;
                        break;
                case _2:
                        out0 = 2;
                        break;
                case _3:
                        out0 = 3;
                        break;
                case _4:
                        out0 = 4;
                        break;
                case 5:
                        out0 = 10;
                        break;
                default:
                        out0 = 100;

        }
        bool RES = isOk(out0, ref.out0);
dEQP_FragColor = vec4(RES, RES, RES, 1.0);

}

@dneto0
Copy link
Contributor

dneto0 commented Aug 12, 2016

I've narrowed it down to the --map types option

@dneto0
Copy link
Contributor

dneto0 commented Aug 12, 2016

If I use --map names then I end up with "unimplemented type size request". So there's something deeply bad going on.

dneto0 added a commit to dneto0/glslang that referenced this pull request Aug 12, 2016
…r-literal64"

This reverts commit ad08b30, reversing
changes made to 28660bb.

This backs out the pull request
KhronosGroup#456 because it introduced
several internal errors even on code that only uses 32-bit numeric
types.
@dneto0
Copy link
Contributor

dneto0 commented Aug 12, 2016

With --dce-types I get "ID not found" as well.
I've requested that this PR be backed out.

johnkslang added a commit that referenced this pull request Aug 12, 2016
Revert "Merge pull request #456 from steve-lunarg/remapper-literal64"
@johnkslang
Copy link
Member

It's out.

Definitely need a better testing strategy.

@johnkslang
Copy link
Member

Or, something like this could be experimented with in a branch first, like the Vulkan precision qualifier change.

@ghost
Copy link
Author

ghost commented Aug 12, 2016

Thanks for the reproduction case; I'll check it out.

@ghost
Copy link
Author

ghost commented Aug 12, 2016

I see the problem; it relates to how I was obtaining the type size from the instruction stream during the remapping pass, which is actively changing all the IDs.

I'll fix. Unless you have an urgent need, I'd like to do it next week rather than when tired at the end of this one.

@ghost
Copy link
Author

ghost commented Aug 12, 2016

Also, I'll focus soon on creating a better testing infrastructure, since my test dataset didn't expose the problem. That might take a bit longer since it seems best coupled with other infrastructure changes if it's to use SPIRV-Tools for testing.

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

Successfully merging this pull request may close these issues.

None yet

2 participants