Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 20, 2025

  • Add GLSL target case to SampleCmpBias in hlsl.meta.slang (now using wrappers)
  • Add GLSL target case to SampleCmpGrad in hlsl.meta.slang (using wrappers)
  • Update require statements to allow calling from glsl.meta.slang (texture_shadowgrad)
  • Replace TODO comments in glsl.meta.slang texture() functions with SampleCmpBias calls
  • Replace TODO comments in glsl.meta.slang textureOffset() functions with SampleCmpBias calls
  • Update capability requirements in glsl.meta.slang for functions using bias
  • Add GLSL checks to existing sample-cmp.slang test instead of creating new test file
  • Build and test the changes - all tests pass
  • Address review feedback: use GLSL wrappers for both SampleCmpBias and SampleCmpGrad
Original prompt

This section details on the original issue you should resolve

<issue_title>add GLSL support of SampleCmpBias and SampleCmpGrad</issue_title>
<issue_description>Also refactor glsl.meta.slang texture*() functions to use them and fix TODOs like:

// TODO: Need to apply bias 
return sampler.SampleCmp(location, compareValue); 
```</issue_description>

<agent_instructions>implement target switch case of glsl for the recently added SampleCmpBias and SampleCmpGrad overloads in hlsl.meta.slang.
then modify the relevant texture*() overloads in glsl.meta.slang to use the Sample*() overloads in hlsl.meta.slang, and address the `TODO: Need to apply bias` using appropriate SampleCmpBias overloads.
might need to fixup the require statements in hlsl.meta.slang to allow calling from glsl.meta.slang</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@jhelferty-nv</author><body>
@davli-nv I've tentatively assigned this to you since it sounded on the other issue like you were thinking of eventually doing it, just low priority? Unassign if I'm wrong.</body></comment_new>
</comments>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 20, 2025 20:10
…sl.meta.slang

Co-authored-by: davli-nv <219758217+davli-nv@users.noreply.github.com>
Co-authored-by: davli-nv <219758217+davli-nv@users.noreply.github.com>
Copilot AI changed the title [WIP] Add GLSL support for SampleCmpBias and SampleCmpGrad Add GLSL support for SampleCmpBias and SampleCmpGrad Nov 20, 2025
Copilot AI requested a review from davli-nv November 20, 2025 20:21
Copilot finished work on behalf of davli-nv November 20, 2025 20:21

[ForceInline]
[require(glsl_hlsl_spirv, texture_shadowlod)]
[require(glsl_hlsl_spirv, texture_shadowgrad)]
Copy link
Contributor

Choose a reason for hiding this comment

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

the require for existing untouched texture* functions in glsl.meta.slang should not change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted the require change for functions without bias parameters that don't transitively call SampleCmpBias. Note that textureProjOffset(sampler2DShadow, vec4, offset) still needs texture_shadowgrad since it calls textureOffset with default bias=0.0. (26fe990)

__target_switch
{
case glsl:
__intrinsic_asm "textureGrad";
Copy link
Contributor

Choose a reason for hiding this comment

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

GLSL textureGrad etc have different parameter order and semantics than HLSL intrinsics, might need to use wrappers here similar to __glsl_texture_1d_shadow etc, and add wrappers as needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added GLSL wrapper functions __glsl_texture_grad_shadow and __glsl_texture_grad_offset_shadow similar to existing __glsl_texture_1d_shadow pattern. Updated SampleCmpGrad methods to use these wrappers that handle the GLSL parameter format. (26fe990)

case spirv:
return spirv_asm
{
result:$$float = OpImageSampleDrefImplicitLod $sampler $location $compareValue Bias|ConstOffset $bias $offset;
Copy link
Contributor

Choose a reason for hiding this comment

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

the glsl and spirv cases can call appropriate sampler.SampleCmp* overloads

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified texture functions to call sampler.SampleCmpBias directly for all targets instead of using __target_switch with separate glsl/spirv cases. This applies to texture(), textureOffset(), and their variants with bias parameters. (26fe990)


[ForceInline]
[require(glsl_hlsl_spirv, texture_shadowlod)]
[require(glsl_hlsl_spirv, texture_shadowgrad)]
Copy link
Contributor

Choose a reason for hiding this comment

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

this require change is probably needed to call sampler.SampleCmpBias

@davli-nv
Copy link
Contributor

@copilot address my review comments

…s, fix capability requirements

Co-authored-by: davli-nv <219758217+davli-nv@users.noreply.github.com>
Copilot AI requested a review from davli-nv November 20, 2025 21:54
Copilot finished work on behalf of davli-nv November 20, 2025 21:54
@@ -0,0 +1,81 @@
// Test GLSL output for SampleCmpBias and SampleCmpGrad functions
Copy link
Contributor

Choose a reason for hiding this comment

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

this new test file is not needed, there is existing test of glsl texture* function overloads.
need to add glsl checks into existing tests for SampleCmpGrad and SampleCmpBias overloads.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the new test file and added CHECK_GLSL checks to the existing tests/hlsl-intrinsic/texture/sample-cmp.slang test for SampleCmpBias and SampleCmpGrad calls. (0b68ed9)

__target_switch
{
case glsl:
__intrinsic_asm "texture";
Copy link
Contributor

Choose a reason for hiding this comment

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

are the arguments of this call to glsl intrinsic texture() correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed - the GLSL case now properly calls wrapper function __glsl_texture_bias_shadow(this, __makeVector(location, compareValue), bias) which formats parameters correctly for GLSL's texture() intrinsic. Added wrappers __glsl_texture_bias_shadow and __glsl_texture_bias_offset_shadow similar to the existing __glsl_texture_grad_shadow pattern. (0b68ed9)

@davli-nv
Copy link
Contributor

@copilot address my latest review

…move redundant test file

Co-authored-by: davli-nv <219758217+davli-nv@users.noreply.github.com>
Copilot AI requested a review from davli-nv November 20, 2025 23:12
Copilot finished work on behalf of davli-nv November 20, 2025 23:12
@davli-nv davli-nv added the pr: breaking change PRs with breaking changes label Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: breaking change PRs with breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add GLSL support of SampleCmpBias and SampleCmpGrad

2 participants