Skip to content

Commit cd6aeb7

Browse files
committed
Fix documentation of __targetHasImplicitDerivatives()
Also, add capability `implicit_derivatives_sampling`. This should be a requirement for functions such as _Texture.Sample() and _Texture.CalculateLevelOfDetail(). But currently this cannot be achieved without complex __target_switch/__stage_switch constructs in GLSL texture() functions due to requirement inheritance. Further, enforcing this requirements with static_assert() does not allow capabilities to be inferred, which has too high a likelihood of breaking existing code. So, we're not doing that in this patch, either. Instead, we accept that we can generate invalid code without diagnostics for now. Issue #8683
1 parent 01fdbb8 commit cd6aeb7

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

docs/command-line-slangc-reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,7 @@ A capability describes an optional feature that a target may or may not support.
15231523
* `consumestructuredbuffer`
15241524
* `structuredbuffer`
15251525
* `structuredbuffer_rw`
1526+
* `implicit_derivatives_sampling`
15261527
* `fragmentprocessing`
15271528
* `fragmentprocessing_derivativecontrol`
15281529
* `getattributeatvertex`

docs/user-guide/a3-02-reference-capability-atoms.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,20 @@ Compound Capabilities
11241124
`image_size`
11251125
> Capabilities required to query image (RWTexture) size info
11261126
1127+
`implicit_derivatives_sampling`
1128+
> Capabilities required for implicit derivatives sampling.
1129+
>
1130+
> This capability is required by texture sampling functions such as `_Texture.Sample()`
1131+
> where the level of detail is determined by implicit derivatives.
1132+
>
1133+
> @remark In GLSL, implicit level-of-detail `texture()` functions use the base texture when
1134+
> the implicit derivatives are unavailable. When this capability is not present, invocations of
1135+
> these functions are translated to invocations of `_Texture.SampleLevelZero()`.
1136+
>
1137+
> @remark Implicit derivatives for the compute stage can be enabled by declaring capability `GL_NV_compute_shader_derivatives` (GLSL),
1138+
> `SPV_KHR_compute_shader_derivatives` (SPIR-V), or profile `cs_6_6` (HLSL).
1139+
>
1140+
11271141
`memorybarrier`
11281142
> Capabilities required to use sm_5_0 style memory barriers
11291143

source/slang/hlsl.meta.slang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ struct _Texture<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let is
700700
//@hidden:
701701

702702
// Returns true when the stage supports implicit derivatives on the
703-
// target. This must match with compound capability `fragmentprocessing`.
703+
// target. This must match with capability `implicit_derivatives_sampling`.
704704
//
705705
[__readNone]
706706
[ForceInline]

source/slang/slang-capabilities.capdef

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,6 +2033,23 @@ alias structuredbuffer = sm_4_0_version;
20332033
/// [Compound]
20342034
alias structuredbuffer_rw = sm_4_0_version;
20352035

2036+
/// Capabilities required for implicit derivatives sampling.
2037+
///
2038+
/// This capability is required by texture sampling functions such as `_Texture.Sample()`
2039+
/// where the level of detail is determined by implicit derivatives.
2040+
///
2041+
/// @remark In GLSL, implicit level-of-detail `texture()` functions use the base texture when
2042+
/// the implicit derivatives are unavailable. When this capability is not present, invocations of
2043+
/// these functions are translated to invocations of `_Texture.SampleLevelZero()`.
2044+
///
2045+
/// @remark Implicit derivatives for the compute stage can be enabled by declaring capability `GL_NV_compute_shader_derivatives` (GLSL),
2046+
/// `SPV_KHR_compute_shader_derivatives` (SPIR-V), or profile `cs_6_6` (HLSL).
2047+
///
2048+
/// [compound]
2049+
alias implicit_derivatives_sampling = fragment
2050+
| raytracingstages_compute_amplification_mesh + GL_NV_compute_shader_derivatives
2051+
;
2052+
20362053
/// Capabilities required to use fragment derivative operations (without GLSL derivativecontrol)
20372054
/// [Compound]
20382055
alias fragmentprocessing = fragment + _sm_5_0

0 commit comments

Comments
 (0)