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

WIP: HLSL: Suggested changes to allow Load to function on typed vectors and also unsigned input #444

Closed
wants to merge 5 commits into from

Conversation

dankbaker
Copy link
Contributor

Needed to make these changes to allow some or our code to compile. The changes to Sampler are more WIP, as this value isn't used elsewhere yet. The vector dimension return in HLSL is mostly for validation, so in theory it doesn't need to be used at the moment.

The Loads were not being recognized with unsigned ints as inputs, which is the normal use case for Loads on buffers anyway.

…In reality, load will take unsigned int, could prob change to only accept unsigned.
@dankbaker
Copy link
Contributor Author

Some sample code:

Buffer V_Position : register(t0);

struct VSOut
{
float4 fPos : SV_POSITION;
};

// -----------------------------------------------------------------------
VSOut PosShader( uint VertexID : SV_VertexID )
{
    VSOut Out;
    float4 vPos = float4( V_Position.Load( VertexID ).xyz, 1 );
   Out.fPos = vPos;
   return Out;
}

@johnkslang johnkslang changed the title HLSL: Suggested changes to allow Load to function on typed vectors and also unsigned input WIP: HLSL: Suggested changes to allow Load to function on typed vectors and also unsigned input Aug 8, 2016
@johnkslang
Copy link
Member

johnkslang commented Aug 8, 2016

Note we can't merge in PRs that break the test suite; the tests have to be updated with the code change.

A higher-level note is that SPIR-V also cannot have sub-vectors for sampling-function returns. This is the same as the list item

  • sub-vec4 return types from sampling

On issue #362. It could be that it should be turned into syntactic sugar for doing a swizzle after the operation, rather than changing the type system, but I agree it deserves deeper investigation.

@dankbaker
Copy link
Contributor Author

I can't really make heads or tails of the failure, the specific shader appears to compile so I'm not sure exactly what's wrong with it. I will try a few other things, the test harness looked liked i need to install some things to get running.

The return type is mostly syntactic sugar, it does come into play in the AST when you see the return type in a unary expression, since then the AST knows that the vector dimension of the return without needing an explicit cast. I think that case should be pretty easy to put in. That is, an expression like,

Buffer<float3> FooBuffer;
...
float DotP = dot(FooBuffer.Load(0), float3(1,1,1));

You wouldn't need to cast the return value to float3 because the compiler knows that this is the return type. If SPIR-V doesn't have this, then we can just scratch the last component though I think it should probably be added at some point in the future.

Likewise, you can put a struct as a return type, but in that case it needs to be all the same component, and less then 4 components. It really ends up being just a cast. That's a rarely used construct for HLSL, however.

…on, rather then looking at file extension. For HLSL files, this is nice because .hlsl extension is natively udnerstood by visual studio, likely to be used with the -e option.
…on, rather then looking at file extension. For HLSL files, this is nice because .hlsl extension is natively udnerstood by visual studio, likely to be used with the -e option.
@dankbaker
Copy link
Contributor Author

I guess this PR can be deleted? I can work around the issue on HLSL code size by putting an explicit (int) cast in front of Loads. Not sure why this auto test is failing though. I'm thinking there is some sort of precedent order when both uint and int are present.

@johnkslang
Copy link
Member

Feel free to close. But because you'll want one PR per subject, you might want to keep this PR for it's subject and the other PR for the other subject.

(Normal git model is to make a branch per subject git checkout -b <new-subject> and form a PR from that.)

Fixing the tests shouldn't normally be about "fixing" the shaders; they might be intentionally incorrect anyway. It's a regression suite, so it's really about verifying that the differences in the test results are valid differences, caused as intended by the differences in the source code.

@johnkslang johnkslang added the HLSL label Aug 9, 2016
@johnkslang
Copy link
Member

the test harness looked liked i need to install some things to get running

Yes, see if the readme (displayed on the home page) has sufficient instructions. Can't really be doing this without that.

@ghost
Copy link

ghost commented Aug 9, 2016

turned into syntactic sugar for doing a swizzle after the operation,

Nod - that's been my working assumption, unless the above mentioned deeper investigation uncovers something else. IMHO: while in a sense the existing shape conversions might handle cases of mismatching vectorness, it seems better just to get the type right by adding the swizzle. Then there's no danger about situations where shape conversions do not happen. The info to actually do the swizzle will have to be preserved of course.

Edit for typo.

@johnkslang
Copy link
Member

I guess this PR can be deleted?

Yes, I think so, and it is accumulating the -T code changes a well, so something else is needed, thanks.

@johnkslang johnkslang closed this Aug 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants