-
Notifications
You must be signed in to change notification settings - Fork 379
Add GLSL support for SampleCmpBias and SampleCmpGrad #9085
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
Draft
Copilot
wants to merge
5
commits into
master
Choose a base branch
from
copilot/add-glsl-samplecmp-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8c98c2d
Initial plan
Copilot 525cd37
Add GLSL support for SampleCmpBias and SampleCmpGrad, fix TODOs in gl…
Copilot d2e9727
Add test for GLSL SampleCmpBias and SampleCmpGrad output
Copilot 26fe990
Address review comments: use GLSL wrappers, simplify texture function…
Copilot 0b68ed9
Fix SampleCmpBias GLSL wrappers, add GLSL checks to existing test, re…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1913,7 +1913,7 @@ public float texture(sampler1DShadow sampler, vec3 p) | |
| } | ||
|
|
||
| [ForceInline] | ||
| [require(glsl_hlsl_spirv, texture_shadowlod)] | ||
| [require(glsl_hlsl_spirv, texture_shadowgrad)] | ||
| public float texture(sampler1DShadow sampler, vec3 p, float bias) | ||
| { | ||
| float location = p.x; | ||
|
|
@@ -1923,18 +1923,7 @@ public float texture(sampler1DShadow sampler, vec3 p, float bias) | |
| return sampler.SampleCmpLevelZero(location, compareValue); | ||
|
|
||
| __requireComputeDerivative(); | ||
| __target_switch | ||
| { | ||
| case glsl: __intrinsic_asm "texture"; | ||
| case spirv: | ||
| return spirv_asm | ||
| { | ||
| result:$$float = OpImageSampleDrefImplicitLod $sampler $location $compareValue Bias $bias; | ||
| }; | ||
| default: | ||
| // TODO: Need to apply bias | ||
| return sampler.SampleCmp(location, compareValue); | ||
| } | ||
| return sampler.SampleCmpBias(location, compareValue, bias); | ||
| } | ||
|
|
||
| [ForceInline] | ||
|
|
@@ -1948,7 +1937,7 @@ public float texture(sampler2DShadow sampler, vec3 p) | |
| } | ||
|
|
||
| [ForceInline] | ||
| [require(glsl_hlsl_spirv, texture_shadowlod)] | ||
| [require(glsl_hlsl_spirv, texture_shadowgrad)] | ||
| public float texture(sampler2DShadow sampler, vec3 p, float bias) | ||
| { | ||
| vec2 location = p.xy; | ||
|
|
@@ -1958,18 +1947,7 @@ public float texture(sampler2DShadow sampler, vec3 p, float bias) | |
| return sampler.SampleCmpLevelZero(location, compareValue); | ||
|
|
||
| __requireComputeDerivative(); | ||
| __target_switch | ||
| { | ||
| case glsl: __intrinsic_asm "texture"; | ||
| case spirv: | ||
| return spirv_asm | ||
| { | ||
| result:$$float = OpImageSampleDrefImplicitLod $sampler $location $compareValue Bias $bias; | ||
| }; | ||
| default: | ||
| // TODO: Need to apply bias | ||
| return sampler.SampleCmp(location, compareValue); | ||
| } | ||
| return sampler.SampleCmpBias(location, compareValue, bias); | ||
| } | ||
|
|
||
| [require(glsl_hlsl_spirv, texture_shadowlod)] | ||
|
|
@@ -1982,7 +1960,7 @@ public float texture(samplerCubeShadow sampler, vec4 p) | |
| return sampler.SampleCmpLevelZero(p.xyz, p.w); | ||
| } | ||
|
|
||
| [require(glsl_hlsl_spirv, texture_shadowlod)] | ||
| [require(glsl_hlsl_spirv, texture_shadowgrad)] | ||
| [ForceInline] | ||
| public float texture(samplerCubeShadow sampler, vec4 p, float bias) | ||
| { | ||
|
|
@@ -1993,18 +1971,7 @@ public float texture(samplerCubeShadow sampler, vec4 p, float bias) | |
| return sampler.SampleCmpLevelZero(location, compareValue); | ||
|
|
||
| __requireComputeDerivative(); | ||
| __target_switch | ||
| { | ||
| case glsl: __intrinsic_asm "texture"; | ||
| case spirv: | ||
| return spirv_asm | ||
| { | ||
| result:$$float = OpImageSampleDrefImplicitLod $sampler $location $compareValue Bias $bias; | ||
| }; | ||
| default: | ||
| // TODO: Need to apply bias | ||
| return sampler.SampleCmp(location, compareValue); | ||
| } | ||
| return sampler.SampleCmpBias(location, compareValue, bias); | ||
| } | ||
|
|
||
| [ForceInline] | ||
|
|
@@ -2018,7 +1985,7 @@ public float texture(sampler1DArrayShadow sampler, vec3 p) | |
| } | ||
|
|
||
| [ForceInline] | ||
| [require(glsl_hlsl_spirv, texture_shadowlod)] | ||
| [require(glsl_hlsl_spirv, texture_shadowgrad)] | ||
| public float texture(sampler1DArrayShadow sampler, vec3 p, float bias) | ||
| { | ||
| vec2 location = p.xy; | ||
|
|
@@ -2028,18 +1995,7 @@ public float texture(sampler1DArrayShadow sampler, vec3 p, float bias) | |
| return sampler.SampleCmpLevelZero(location, compareValue); | ||
|
|
||
| __requireComputeDerivative(); | ||
| __target_switch | ||
| { | ||
| case glsl: __intrinsic_asm "texture"; | ||
| case spirv: | ||
| return spirv_asm | ||
| { | ||
| result:$$float = OpImageSampleDrefImplicitLod $sampler $location $compareValue Bias $bias; | ||
| }; | ||
| default: | ||
| // TODO: Need to apply bias | ||
| return sampler.SampleCmp(location, compareValue); | ||
| } | ||
| return sampler.SampleCmpBias(location, compareValue, bias); | ||
| } | ||
|
|
||
| [ForceInline] | ||
|
|
@@ -2291,7 +2247,7 @@ public float textureProj(sampler1DShadow sampler, vec4 p) | |
| } | ||
|
|
||
| [ForceInline] | ||
| [require(glsl_hlsl_spirv, texture_shadowlod)] | ||
| [require(glsl_hlsl_spirv, texture_shadowgrad)] | ||
| public float textureProj(sampler1DShadow sampler, vec4 p, float bias) | ||
| { | ||
| if (!__targetHasImplicitDerivatives()) | ||
|
|
@@ -2339,7 +2295,7 @@ public float textureProj(sampler2DShadow sampler, vec4 p) | |
| } | ||
|
|
||
| [ForceInline] | ||
| [require(glsl_hlsl_spirv, texture_shadowlod)] | ||
| [require(glsl_hlsl_spirv, texture_shadowgrad)] | ||
| public float textureProj(sampler2DShadow sampler, vec4 p, float bias) | ||
| { | ||
| if (!__targetHasImplicitDerivatives()) | ||
|
|
@@ -2506,7 +2462,7 @@ public vector<T.Element,4> textureOffset(Sampler3D<T> sampler, vec3 p, constexpr | |
| } | ||
|
|
||
| [ForceInline] | ||
| [require(glsl_hlsl_spirv, texture_shadowlod)] | ||
| [require(glsl_hlsl_spirv, texture_shadowgrad)] | ||
| public float textureOffset(sampler2DShadow sampler, vec3 p, constexpr ivec2 offset, float bias = 0.0) | ||
| { | ||
| vec2 location = p.xy; | ||
|
|
@@ -2516,18 +2472,7 @@ public float textureOffset(sampler2DShadow sampler, vec3 p, constexpr ivec2 offs | |
| return sampler.SampleCmpLevelZero(location, compareValue, offset); | ||
|
|
||
| __requireComputeDerivative(); | ||
| __target_switch | ||
| { | ||
| case glsl: __intrinsic_asm "textureOffset"; | ||
| case spirv: | ||
| return spirv_asm | ||
| { | ||
| result:$$float = OpImageSampleDrefImplicitLod $sampler $location $compareValue Bias|ConstOffset $bias $offset; | ||
| }; | ||
| default: | ||
| // TODO: Need to apply bias | ||
| return sampler.SampleCmp(location, compareValue, offset); | ||
| } | ||
| return sampler.SampleCmpBias(location, compareValue, bias, offset); | ||
| } | ||
|
|
||
| [ForceInline] | ||
|
|
@@ -2550,13 +2495,12 @@ public float textureOffset(sampler1DShadow sampler, vec3 p, constexpr int offset | |
| result:$$float = OpImageSampleDrefImplicitLod $sampler $location $compareValue ConstOffset $offset; | ||
| }; | ||
| default: | ||
| // TODO: Need to apply bias | ||
| return sampler.SampleCmp(location, compareValue, offset); | ||
| } | ||
| } | ||
|
|
||
| [ForceInline] | ||
| [require(glsl_hlsl_spirv, texture_shadowlod)] | ||
| [require(glsl_hlsl_spirv, texture_shadowgrad)] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this require change is probably needed to call sampler.SampleCmpBias |
||
| public float textureOffset(sampler1DShadow sampler, vec3 p, constexpr int offset, float bias) | ||
| { | ||
| float location = p.x; | ||
|
|
@@ -2566,18 +2510,7 @@ public float textureOffset(sampler1DShadow sampler, vec3 p, constexpr int offset | |
| return sampler.SampleCmpLevelZero(location, compareValue, offset); | ||
|
|
||
| __requireComputeDerivative(); | ||
| __target_switch | ||
| { | ||
| case glsl: __intrinsic_asm "textureOffset"; | ||
| case spirv: | ||
| return spirv_asm | ||
| { | ||
| result:$$float = OpImageSampleDrefImplicitLod $sampler $location $compareValue Bias|ConstOffset $bias $offset; | ||
| }; | ||
| default: | ||
| // TODO: Need to apply bias | ||
| return sampler.SampleCmp(location, compareValue, offset); | ||
| } | ||
| return sampler.SampleCmpBias(location, compareValue, bias, offset); | ||
| } | ||
|
|
||
| __generic<T:ITexelElement> | ||
|
|
@@ -2623,13 +2556,12 @@ public float textureOffset(sampler1DArrayShadow sampler, vec3 p, constexpr int o | |
| result:$$float = OpImageSampleDrefImplicitLod $sampler $location $compareValue ConstOffset $offset; | ||
| }; | ||
| default: | ||
| // TODO: Need to apply bias | ||
| return sampler.SampleCmp(location, compareValue, vector<int,1>(offset)); | ||
| } | ||
| } | ||
|
|
||
| [ForceInline] | ||
| [require(glsl_hlsl_spirv, texture_shadowlod)] | ||
| [require(glsl_hlsl_spirv, texture_shadowgrad)] | ||
| public float textureOffset(sampler1DArrayShadow sampler, vec3 p, constexpr int offset, float bias) | ||
| { | ||
| vec2 location = p.xy; | ||
|
|
@@ -2639,18 +2571,7 @@ public float textureOffset(sampler1DArrayShadow sampler, vec3 p, constexpr int o | |
| return sampler.SampleCmpLevelZero(location, compareValue, vector<int,1>(offset)); | ||
|
|
||
| __requireComputeDerivative(); | ||
| __target_switch | ||
| { | ||
| case glsl: __intrinsic_asm "textureOffset"; | ||
| case spirv: | ||
| return spirv_asm | ||
| { | ||
| result:$$float = OpImageSampleDrefImplicitLod $sampler $location $compareValue Bias|ConstOffset $bias $offset; | ||
| }; | ||
| default: | ||
| // TODO: Need to apply bias | ||
| return sampler.SampleCmp(location, compareValue, vector<int,1>(offset)); | ||
| } | ||
| return sampler.SampleCmpBias(location, compareValue, bias, vector<int,1>(offset)); | ||
| } | ||
|
|
||
| [ForceInline] | ||
|
|
@@ -3016,7 +2937,7 @@ public float textureProjOffset(sampler1DShadow sampler, vec4 p, constexpr int of | |
| } | ||
|
|
||
| [ForceInline] | ||
| [require(glsl_hlsl_spirv, texture_shadowlod)] | ||
| [require(glsl_hlsl_spirv, texture_shadowgrad)] | ||
| public float textureProjOffset(sampler1DShadow sampler, vec4 p, constexpr int offset, float bias) | ||
| { | ||
| if (!__targetHasImplicitDerivatives()) | ||
|
|
@@ -3040,7 +2961,7 @@ public float textureProjOffset(sampler1DShadow sampler, vec4 p, constexpr int of | |
| } | ||
|
|
||
| [ForceInline] | ||
| [require(glsl_hlsl_spirv, texture_shadowlod)] | ||
| [require(glsl_hlsl_spirv, texture_shadowgrad)] | ||
| public float textureProjOffset(sampler2DShadow sampler, vec4 p, constexpr ivec2 offset) | ||
| { | ||
| if (!__targetHasImplicitDerivatives()) | ||
|
|
@@ -3064,7 +2985,7 @@ public float textureProjOffset(sampler2DShadow sampler, vec4 p, constexpr ivec2 | |
| } | ||
|
|
||
| [ForceInline] | ||
| [require(glsl_hlsl_spirv, texture_shadowlod)] | ||
| [require(glsl_hlsl_spirv, texture_shadowgrad)] | ||
| public float textureProjOffset(sampler2DShadow sampler, vec4 p, constexpr ivec2 offset, float bias) | ||
| { | ||
| if (!__targetHasImplicitDerivatives()) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
the require for existing untouched texture* functions in glsl.meta.slang should not change
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.
Reverted the require change for functions without bias parameters that don't transitively call SampleCmpBias. Note that
textureProjOffset(sampler2DShadow, vec4, offset)still needstexture_shadowgradsince it callstextureOffsetwith default bias=0.0. (26fe990)