Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 19 additions & 98 deletions source/slang/glsl.meta.slang
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,7 @@ public float texture(sampler1DShadow sampler, vec3 p)
}

[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)

public float texture(sampler1DShadow sampler, vec3 p, float bias)
{
float location = p.x;
Expand All @@ -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]
Expand All @@ -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;
Expand All @@ -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)]
Expand All @@ -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)
{
Expand All @@ -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]
Expand All @@ -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;
Expand All @@ -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]
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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;
Expand All @@ -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]
Expand All @@ -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)]
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

public float textureOffset(sampler1DShadow sampler, vec3 p, constexpr int offset, float bias)
{
float location = p.x;
Expand All @@ -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>
Expand Down Expand Up @@ -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;
Expand All @@ -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]
Expand Down Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand Down
56 changes: 52 additions & 4 deletions source/slang/hlsl.meta.slang
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,46 @@ float __glsl_texture_level_offset_1d_shadow<TSampler, TCoord, TOffset>(TSampler
}
}

__glsl_extension(GL_EXT_texture_shadow_lod)
[require(glsl, texture_shadowgrad)]
float __glsl_texture_bias_shadow<TSampler, TCoord>(TSampler s, TCoord value, float bias)
{
__target_switch
{
case glsl: __intrinsic_asm "texture($0, $1, $2)";
}
}

__glsl_extension(GL_EXT_texture_shadow_lod)
[require(glsl, texture_shadowgrad)]
float __glsl_texture_bias_offset_shadow<TSampler, TCoord, TOffset>(TSampler s, TCoord value, float bias, constexpr TOffset offset)
{
__target_switch
{
case glsl: __intrinsic_asm "textureOffset($0, $1, $2, $3)";
}
}

__glsl_extension(GL_EXT_texture_shadow_lod)
[require(glsl, texture_shadowgrad)]
float __glsl_texture_grad_shadow<TSampler, TCoord, TGrad>(TSampler s, TCoord value, TGrad gradX, TGrad gradY)
{
__target_switch
{
case glsl: __intrinsic_asm "textureGrad($0, $1, $2, $3)";
}
}

__glsl_extension(GL_EXT_texture_shadow_lod)
[require(glsl, texture_shadowgrad)]
float __glsl_texture_grad_offset_shadow<TSampler, TCoord, TGrad, TOffset>(TSampler s, TCoord value, TGrad gradX, TGrad gradY, constexpr TOffset offset)
{
__target_switch
{
case glsl: __intrinsic_asm "textureGradOffset($0, $1, $2, $3, $4)";
}
}

[require(glsl, texture_sm_4_1)]
float __glsl_texture<TTexture, TCoord>(TTexture t, SamplerComparisonState s, TCoord value)
{
Expand Down Expand Up @@ -1586,12 +1626,14 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>

[__readNone]
[ForceInline]
[require(hlsl_spirv, texture_shadowgrad)]
[require(glsl_hlsl_spirv, texture_shadowgrad)]
float SampleCmpGrad(vector<float, Shape.dimensions+isArray> location, float compareValue, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY)
{
static_assert(!(Shape is __ShapeCube && isArray != 0), "SampleCmpGrad is not supported for TextureCubeArray");
__target_switch
{
case glsl:
return __glsl_texture_grad_shadow(this, __makeVector(location, compareValue), gradX, gradY);
case hlsl:
static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
|| T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
Expand All @@ -1607,13 +1649,15 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>

[__readNone]
[ForceInline]
[require(hlsl_spirv, texture_shadowgrad)]
[require(glsl_hlsl_spirv, texture_shadowgrad)]
float SampleCmpGrad(vector<float, Shape.dimensions+isArray> location, float compareValue, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY, constexpr vector<int, Shape.planeDimensions> offset)
{
static_assert(!(Shape is __ShapeCube && isArray != 0), "SampleCmpGrad is not supported for TextureCubeArray");
static_assert(!(Shape is __ShapeCube), "SampleCmpGrad with offset is not supported for TextureCube or TextureCubeArray");
__target_switch
{
case glsl:
return __glsl_texture_grad_offset_shadow(this, __makeVector(location, compareValue), gradX, gradY, offset);
case hlsl:
static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
|| T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
Expand Down Expand Up @@ -1658,12 +1702,14 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>

[__readNone]
[ForceInline]
[require(hlsl_spirv, texture_shadowgrad)]
[require(glsl_hlsl_spirv, texture_shadowgrad)]
float SampleCmpBias(vector<float, Shape.dimensions+isArray> location, float compareValue, float bias)
{
__requireComputeDerivative();
__target_switch
{
case glsl:
return __glsl_texture_bias_shadow(this, __makeVector(location, compareValue), bias);
case hlsl:
static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
|| T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
Expand All @@ -1679,13 +1725,15 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>

[__readNone]
[ForceInline]
[require(hlsl_spirv, texture_shadowgrad)]
[require(glsl_hlsl_spirv, texture_shadowgrad)]
float SampleCmpBias(vector<float, Shape.dimensions+isArray> location, float compareValue, float bias, constexpr vector<int, Shape.planeDimensions> offset)
{
static_assert(!(Shape is __ShapeCube), "SampleCmpBias with offset is not supported for TextureCube or TextureCubeArray");
__requireComputeDerivative();
__target_switch
{
case glsl:
return __glsl_texture_bias_offset_shadow(this, __makeVector(location, compareValue), bias, offset);
case hlsl:
static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
|| T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
Expand Down
Loading
Loading