-
Notifications
You must be signed in to change notification settings - Fork 565
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
HLSL: Support depth comparison texture sampling in SM 2/3. #1520
Conversation
d4e31d1
to
591dff4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see a test here to see what is going on.
591dff4
to
b3ee7a6
Compare
b3ee7a6
to
6c0b56c
Compare
I added a test for all the samplers supported by SM 3.0. As you can see it's just a matter of passing the dref into the third coordinate. I verified that the resulting shader works correctly for shadow mapping on both Intel and NVIDIA hardware, and furthermore, this is also what the Cg compiler is producing when using a shadow sampler and targeting SM 3.0 (aside from the fact that it can directly generate a Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also missing reference/opt/shaders-hlsl/frag/tex-sampling.sm30.frag
to be committed.
6c0b56c
to
135933d
Compare
I just went ahead and just changed the second coordinate to 0.0, because it's clearer. I verified that the resulting shader still works correctly with a 1D depth map. I also added a return swizzle and added the optimized reference file as requested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
In DX9, all samples of a depth texture result in a depth comparison (in fact, disabling this requires use of the special
INTZ
format, only available on DX10+ hardware). This works with all 4-component texture sample functions (tex2Dlod, tex2Dbias, tex2Dproj).This PR provides access to this functionality by enabling use of the Dref texture sample instruction and passing in the depth compare value into the appropriate register. It assumes that there is indeed a depth texture bound to the appropriate register (which is the application's responsibility, and not something we can check).
Even though the regular
texld
instruction does support this as well, HLSL does not (to my knowledge) allow access to this variant sincetex2D
only accepts 2 coordinates. To work around this, this PR turns an OpImageSampleDrefImplicitLod into atex2Dproj
with a w coordinate of 1.0, which is effectively equivalent.Thanks for your consideration!