From df0a201d85eac4c55c1abf15ed0bf9baea0ae971 Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Tue, 11 Jun 2024 07:05:46 -0700 Subject: Support integer typed textures for GLSL (#4329) * Support integer typed textures for GLSL This commit re-enables the ability to sample from an integer typed texture for GLSL functions while keeping it unavailable for HLSL target. --- source/slang/glsl.meta.slang | 129 ++++++++++++++--------------- source/slang/hlsl.meta.slang | 190 +++++++++++++++++++++++++++++++++---------- 2 files changed, 214 insertions(+), 105 deletions(-) (limited to 'source') diff --git a/source/slang/glsl.meta.slang b/source/slang/glsl.meta.slang index 1daf0ec07..db5f9c2fa 100644 --- a/source/slang/glsl.meta.slang +++ b/source/slang/glsl.meta.slang @@ -1878,7 +1878,7 @@ public ivec3 textureSize(Sampler2DMSArray,sampleCount> sampler) // textureQueryLod // ------------------- -__generic +__generic [ForceInline] [require(cpp_cuda_glsl_hlsl_spirv, texture_querylod)] public vec2 textureQueryLod(__TextureImpl< @@ -1910,10 +1910,11 @@ public vec2 textureQueryLod(__TextureImpl< } } -__generic +__generic [ForceInline] [require(cpp_cuda_glsl_hlsl_spirv, texture_querylod)] -public vec2 textureQueryLod(__TextureImpl +__generic [ForceInline] [require(glsl_hlsl_spirv, image_samples)] -public int textureSamples(Sampler2DMS,sampleCount> sampler) +public int textureSamples(Sampler2DMS sampler) { vector dim; int sampleCount; @@ -2098,10 +2099,10 @@ public int textureSamples(Sampler2DMS,sampleCount> sampler) return sampleCount; } -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, image_samples)] -public int textureSamples(Sampler2DMSArray,sampleCount> sampler) +public int textureSamples(Sampler2DMSArray sampler) { vector dim; int sampleCount; @@ -2118,7 +2119,7 @@ public int textureSamples(Sampler2DMSArray,sampleCount> sampler) // texture // ------------------- -__generic +__generic [ForceInline] [require(cpp_cuda_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector texture(Sampler1D> sampler, float p) @@ -2126,7 +2127,7 @@ public vector texture(Sampler1D> sampler, float p) return __vectorReshape<4>(sampler.Sample(p)); } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector texture(Sampler1D> sampler, float p, constexpr float bias) @@ -2134,7 +2135,7 @@ public vector texture(Sampler1D> sampler, float p, constexpr fl return __vectorReshape<4>(sampler.SampleBias(p, bias)); } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector texture(__TextureImpl< @@ -2152,7 +2153,7 @@ public vector texture(__TextureImpl< return __vectorReshape<4>(sampler.Sample(p)); } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector texture(__TextureImpl< @@ -2304,7 +2305,7 @@ public float texture(samplerCubeArrayShadow sampler, vec4 p, float compare) // textureProj // ------------------- -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProj(Sampler1D> sampler, vec2 p) @@ -2321,7 +2322,7 @@ public vector textureProj(Sampler1D> sampler, vec2 p) } } -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProj(Sampler1D> sampler, vec2 p, float bias) @@ -2338,7 +2339,7 @@ public vector textureProj(Sampler1D> sampler, vec2 p, float bia } } -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProj(Sampler1D> sampler, vec4 p) @@ -2355,7 +2356,7 @@ public vector textureProj(Sampler1D> sampler, vec4 p) } } -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProj(Sampler1D> sampler, vec4 p, float bias) @@ -2372,7 +2373,7 @@ public vector textureProj(Sampler1D> sampler, vec4 p, float bia } } -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProj(Sampler2D> sampler, vec3 p) @@ -2389,7 +2390,7 @@ public vector textureProj(Sampler2D> sampler, vec3 p) } } -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProj(Sampler2D> sampler, vec3 p, float bias) @@ -2406,7 +2407,7 @@ public vector textureProj(Sampler2D> sampler, vec3 p, float bia } } -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProj(Sampler2D> sampler, vec4 p) @@ -2423,7 +2424,7 @@ public vector textureProj(Sampler2D> sampler, vec4 p) } } -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProj(Sampler2D> sampler, vec4 p, float bias) @@ -2440,7 +2441,7 @@ public vector textureProj(Sampler2D> sampler, vec4 p, float bia } } -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProj(Sampler3D> sampler, vec4 p) @@ -2457,7 +2458,7 @@ public vector textureProj(Sampler3D> sampler, vec4 p) } } -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProj(Sampler3D> sampler, vec4 p, float bias) @@ -2562,7 +2563,7 @@ public float textureProj(sampler2DShadow sampler, vec4 p, float bias) // textureLod // ------------------- -__generic +__generic [ForceInline] [require(cpp_cuda_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureLod(Sampler1D> sampler, float p, float lod) @@ -2570,7 +2571,7 @@ public vector textureLod(Sampler1D> sampler, float p, float lod return __vectorReshape<4>(sampler.SampleLevel(p, lod)); } -__generic +__generic [ForceInline] [require(cpp_cuda_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureLod(__TextureImpl< @@ -2649,7 +2650,7 @@ public float textureLod(sampler1DArrayShadow sampler, vec3 p, float lod) // textureOffset // ------------------- -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureOffset(Sampler1D> sampler, float p, constexpr int offset, float bias = 0.0) @@ -2657,7 +2658,7 @@ public vector textureOffset(Sampler1D> sampler, float p, conste return __vectorReshape<4>(sampler.SampleBias(p, bias, offset)); } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureOffset(Sampler2D> sampler, vec2 p, constexpr ivec2 offset, float bias = 0.0) @@ -2665,7 +2666,7 @@ public vector textureOffset(Sampler2D> sampler, vec2 p, constex return __vectorReshape<4>(sampler.SampleBias(p, bias, offset)); } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureOffset(Sampler3D> sampler, vec3 p, constexpr ivec3 offset, float bias = 0.0) @@ -2739,7 +2740,7 @@ public float textureOffset(sampler1DShadow sampler, vec3 p, constexpr int offset } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureOffset(Sampler1DArray> sampler, vec2 p, constexpr int offset, float bias = 0.0) @@ -2747,7 +2748,7 @@ public vector textureOffset(Sampler1DArray> sampler, vec2 p, co return __vectorReshape<4>(sampler.SampleBias(p, bias, offset)); } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureOffset(Sampler2DArray> sampler, vec3 p, constexpr ivec2 offset, float bias = 0.0) @@ -2918,7 +2919,7 @@ public vector texelFetchOffset(Sampler2DRect> sampler, ivec2 p, // textureProjOffset // ------------------- -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjOffset(Sampler1D> sampler, vec2 p, constexpr int offset) @@ -2935,7 +2936,7 @@ public vector textureProjOffset(Sampler1D> sampler, vec2 p, con } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjOffset(Sampler1D> sampler, vec2 p, constexpr int offset, float bias) @@ -2952,7 +2953,7 @@ public vector textureProjOffset(Sampler1D> sampler, vec2 p, con } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjOffset(Sampler1D> sampler, vec4 p, constexpr int offset) @@ -2973,7 +2974,7 @@ public vector textureProjOffset(Sampler1D> sampler, vec4 p, con } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjOffset(Sampler1D> sampler, vec4 p, constexpr int offset, float bias) @@ -2994,7 +2995,7 @@ public vector textureProjOffset(Sampler1D> sampler, vec4 p, con } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjOffset(Sampler2D> sampler, vec3 p, constexpr ivec2 offset) @@ -3011,7 +3012,7 @@ public vector textureProjOffset(Sampler2D> sampler, vec3 p, con } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjOffset(Sampler2D> sampler, vec3 p, constexpr ivec2 offset, float bias) @@ -3028,7 +3029,7 @@ public vector textureProjOffset(Sampler2D> sampler, vec3 p, con } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjOffset(Sampler2D> sampler, vec4 p, constexpr ivec2 offset) @@ -3049,7 +3050,7 @@ public vector textureProjOffset(Sampler2D> sampler, vec4 p, con } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjOffset(Sampler2D> sampler, vec4 p, constexpr ivec2 offset, float bias) @@ -3070,7 +3071,7 @@ public vector textureProjOffset(Sampler2D> sampler, vec4 p, con } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjOffset(Sampler3D> sampler, vec4 p, constexpr ivec3 offset) @@ -3087,7 +3088,7 @@ public vector textureProjOffset(Sampler3D> sampler, vec4 p, con } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjOffset(Sampler3D> sampler, vec4 p, constexpr ivec3 offset, float bias) @@ -3192,7 +3193,7 @@ public float textureProjOffset(sampler2DShadow sampler, vec4 p, constexpr ivec2 // textureLodOffset // ------------------- -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] public vector textureLodOffset(Sampler1D> sampler, float p, float lod, constexpr int offset) @@ -3200,7 +3201,7 @@ public vector textureLodOffset(Sampler1D> sampler, float p, flo return __vectorReshape<4>(sampler.SampleLevel(p, lod, offset)); } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] public vector textureLodOffset(__TextureImpl< @@ -3282,7 +3283,7 @@ public float textureLodOffset(sampler1DArrayShadow sampler, vec3 p, float lod, c // textureProjLod // ------------------- -__generic +__generic [ForceInline] [require(cpp_cuda_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjLod(Sampler1D> sampler, vec2 p, float lod) @@ -3298,7 +3299,7 @@ public vector textureProjLod(Sampler1D> sampler, vec2 p, float } } -__generic +__generic [ForceInline] [require(cpp_cuda_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjLod(Sampler1D> sampler, vec4 p, float lod) @@ -3318,7 +3319,7 @@ public vector textureProjLod(Sampler1D> sampler, vec4 p, float } } -__generic +__generic [ForceInline] [require(cpp_cuda_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjLod(Sampler2D> sampler, vec3 p, float lod) @@ -3334,7 +3335,7 @@ public vector textureProjLod(Sampler2D> sampler, vec3 p, float } } -__generic +__generic [ForceInline] [require(cpp_cuda_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjLod(Sampler2D> sampler, vec4 p, float lod) @@ -3354,7 +3355,7 @@ public vector textureProjLod(Sampler2D> sampler, vec4 p, float } } -__generic +__generic [ForceInline] [require(cpp_cuda_glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjLod(Sampler3D> sampler, vec4 p, float lod) @@ -3414,7 +3415,7 @@ public float textureProjLod(sampler2DShadow sampler, vec4 p, float lod) // textureProjLodOffset // ------------------- -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjLodOffset(Sampler1D> sampler, vec2 p, float lod, constexpr int offset) @@ -3430,7 +3431,7 @@ public vector textureProjLodOffset(Sampler1D> sampler, vec2 p, } } -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjLodOffset(Sampler1D> sampler, vec4 p, float lod, constexpr int offset) @@ -3450,7 +3451,7 @@ public vector textureProjLodOffset(Sampler1D> sampler, vec4 p, } } -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjLodOffset(Sampler2D> sampler, vec3 p, float lod, constexpr ivec2 offset) @@ -3466,7 +3467,7 @@ public vector textureProjLodOffset(Sampler2D> sampler, vec3 p, } } -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjLodOffset(Sampler2D> sampler, vec4 p, float lod, constexpr ivec2 offset) @@ -3486,7 +3487,7 @@ public vector textureProjLodOffset(Sampler2D> sampler, vec4 p, } } -__generic +__generic [ForceInline] [require(glsl_hlsl_spirv, texture_sm_4_1_fragment)] public vector textureProjLodOffset(Sampler3D> sampler, vec4 p, float lod, constexpr ivec3 offset) @@ -3547,7 +3548,7 @@ public float textureProjLodOffset(sampler2DShadow sampler, vec4 p, float lod, co // ------------------- -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] public vector textureGrad(Sampler1D> sampler, float p, float dPdx, float dPdy) @@ -3555,7 +3556,7 @@ public vector textureGrad(Sampler1D> sampler, float p, float dP return __vectorReshape<4>(sampler.SampleGrad(p, dPdx, dPdy)); } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] public vector textureGrad(__TextureImpl< @@ -3662,7 +3663,7 @@ public float textureGrad(sampler2DArrayShadow sampler, vec4 p, vec2 dPdx, vec2 d // textureGradOffset // ------------------- -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] public vector textureGradOffset(Sampler1D> sampler, float p, float dPdx, float dPdy, constexpr int offset) @@ -3670,7 +3671,7 @@ public vector textureGradOffset(Sampler1D> sampler, float p, fl return __vectorReshape<4>(sampler.SampleGrad(p, dPdx, dPdy, offset)); } -__generic +__generic [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] [ForceInline] public vector textureGradOffset(__TextureImpl< @@ -3760,7 +3761,7 @@ public float textureGradOffset(sampler2DArrayShadow sampler, vec4 p, vec2 dPdx, // textureProjGrad // ------------------- -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] public vector textureProjGrad(Sampler1D> sampler, vec2 p, float dPdx, float dPdy) @@ -3776,7 +3777,7 @@ public vector textureProjGrad(Sampler1D> sampler, vec2 p, float } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] public vector textureProjGrad(Sampler1D> sampler, vec4 p, float dPdx, float dPdy) @@ -3796,7 +3797,7 @@ public vector textureProjGrad(Sampler1D> sampler, vec4 p, float } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] public vector textureProjGrad(Sampler2D> sampler, vec3 p, vec2 dPdx, vec2 dPdy) @@ -3812,7 +3813,7 @@ public vector textureProjGrad(Sampler2D> sampler, vec3 p, vec2 } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] public vector textureProjGrad(Sampler2D> sampler, vec4 p, vec2 dPdx, vec2 dPdy) @@ -3832,7 +3833,7 @@ public vector textureProjGrad(Sampler2D> sampler, vec4 p, vec2 } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] public vector textureProjGrad(Sampler3D> sampler, vec4 p, vec3 dPdx, vec3 dPdy) @@ -3892,7 +3893,7 @@ public float textureProjGrad(sampler2DShadow sampler, vec4 p, vec2 dPdx, vec2 dP // textureProjGradOffset // ------------------- -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] public vector textureProjGradOffset(Sampler1D> sampler, vec2 p, float dPdx, float dPdy, constexpr int offset) @@ -3908,7 +3909,7 @@ public vector textureProjGradOffset(Sampler1D> sampler, vec2 p, } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] public vector textureProjGradOffset(Sampler1D> sampler, vec4 p, float dPdx, float dPdy, constexpr int offset) @@ -3928,7 +3929,7 @@ public vector textureProjGradOffset(Sampler1D> sampler, vec4 p, } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] public vector textureProjGradOffset(Sampler2D> sampler, vec3 p, vec2 dPdx, vec2 dPdy, constexpr ivec2 offset) @@ -3944,7 +3945,7 @@ public vector textureProjGradOffset(Sampler2D> sampler, vec3 p, } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] public vector textureProjGradOffset(Sampler2D> sampler, vec4 p, vec2 dPdx, vec2 dPdy, constexpr ivec2 offset) @@ -3964,7 +3965,7 @@ public vector textureProjGradOffset(Sampler2D> sampler, vec4 p, } } -__generic +__generic [ForceInline] [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)] public vector textureProjGradOffset(Sampler3D> sampler, vec4 p, vec3 dPdx, vec3 dPdy, constexpr ivec3 offset) diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index abc178317..1fac47588 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -510,8 +510,7 @@ float __glsl_texture_offset_level_zero_1d_shadow(TTex } } - -__generic +__generic extension __TextureImpl { static const int access = 0; @@ -536,10 +535,12 @@ extension __TextureImpl __target_switch { case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().CalculateLevelOfDetail(__getSampler(), location); case metal: - { - return __getTexture().CalculateLevelOfDetail(__getSampler(), location); - } + return __getTexture().CalculateLevelOfDetail(__getSampler(), location); case glsl: __intrinsic_asm "textureQueryLod($0, $1).x"; case spirv: @@ -559,10 +560,12 @@ extension __TextureImpl __target_switch { case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().CalculateLevelOfDetailUnclamped(__getSampler(), location); case metal: - { return __getTexture().CalculateLevelOfDetailUnclamped(__getSampler(), location); - } case glsl: __intrinsic_asm "textureQueryLod($0, $1).y"; case spirv: @@ -581,8 +584,12 @@ extension __TextureImpl __requireComputeDerivative(); __target_switch { - case cpp: case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().Sample(__getSampler(), location); + case cpp: case metal: return __getTexture().Sample(__getSampler(), location); case glsl: @@ -633,8 +640,12 @@ extension __TextureImpl __requireComputeDerivative(); __target_switch { - case cpp: case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().Sample(__getSampler(), location, offset); + case cpp: case metal: return __getTexture().Sample(__getSampler(), location, offset); case glsl: @@ -658,8 +669,12 @@ extension __TextureImpl __requireComputeDerivative(); __target_switch { - case cpp: case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().Sample(__getSampler(), location, offset, clamp); + case cpp: case metal: return __getTexture().Sample(__getSampler(), location, offset, clamp); case glsl: @@ -681,7 +696,11 @@ extension __TextureImpl { __target_switch { - case hlsl: __intrinsic_asm ".Sample"; + case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + __intrinsic_asm ".Sample"; default: status = 0; return Sample(location, offset, clamp); @@ -696,8 +715,12 @@ extension __TextureImpl __requireComputeDerivative(); __target_switch { - case cpp: case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().SampleBias(__getSampler(), location, bias); + case cpp: case metal: return __getTexture().SampleBias(__getSampler(), location, bias); case glsl: @@ -720,8 +743,12 @@ extension __TextureImpl __requireComputeDerivative(); __target_switch { - case cpp: case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().SampleBias(__getSampler(), location, bias, offset); + case cpp: case metal: return __getTexture().SampleBias(__getSampler(), location, bias, offset); case glsl: @@ -757,6 +784,10 @@ extension __TextureImpl return __glsl_texture(this, __makeVector(location, compareValue)); } case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().SampleCmp(__getComparisonSampler(), location, compareValue); case metal: return __getTexture().SampleCmp(__getComparisonSampler(), location, compareValue); case spirv: @@ -784,6 +815,10 @@ extension __TextureImpl return __glsl_texture_level_zero(this, __makeVector(location, compareValue)); } case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue); case metal: return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue); case spirv: @@ -813,6 +848,10 @@ extension __TextureImpl return __glsl_texture_offset(this, __makeVector(location, compareValue), offset); } case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().SampleCmp(__getComparisonSampler(), location, compareValue, offset); case metal: return __getTexture().SampleCmp(__getComparisonSampler(), location, compareValue, offset); case spirv: @@ -840,6 +879,10 @@ extension __TextureImpl return __glsl_texture_offset_level_zero(this, __makeVector(location, compareValue), offset); } case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue, offset); case metal: return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue, offset); case spirv: @@ -858,8 +901,12 @@ extension __TextureImpl { __target_switch { - case cpp: case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY); + case cpp: case metal: return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY); @@ -881,8 +928,12 @@ extension __TextureImpl { __target_switch { - case cpp: case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY, offset); + case cpp: case metal: return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY, offset); case glsl: @@ -904,8 +955,12 @@ extension __TextureImpl { __target_switch { - case cpp: case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY, offset, lodClamp); + case cpp: case metal: return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY, offset, lodClamp); case glsl: @@ -927,8 +982,12 @@ extension __TextureImpl { __target_switch { - case cpp: case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().SampleLevel(__getSampler(), location, level); + case cpp: case metal: return __getTexture().SampleLevel(__getSampler(), location, level); case glsl: @@ -980,8 +1039,12 @@ extension __TextureImpl { __target_switch { - case cpp: case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().SampleLevel(__getSampler(), location, level, offset); + case cpp: case metal: return __getTexture().SampleLevel(__getSampler(), location, level, offset); @@ -1048,7 +1111,7 @@ extension __TextureImpl +__generic extension __TextureImpl { [__readNone] @@ -1060,7 +1123,11 @@ extension __TextureImpl __target_switch { case cpp: + __intrinsic_asm ".Sample"; case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); __intrinsic_asm ".Sample"; case metal: if (isArray == 1) @@ -1140,7 +1207,11 @@ extension __TextureImpl __target_switch { case cpp: + __intrinsic_asm ".Sample"; case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); __intrinsic_asm ".Sample"; case metal: if (isArray == 1) @@ -1184,7 +1255,11 @@ extension __TextureImpl __target_switch { case cpp: + __intrinsic_asm ".Sample"; case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); __intrinsic_asm ".Sample"; case metal: if (isArray == 1) @@ -1226,7 +1301,11 @@ extension __TextureImpl { __target_switch { - case hlsl: __intrinsic_asm ".Sample"; + case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + __intrinsic_asm ".Sample"; default: status = 0; return Sample(s, location, offset, clamp); @@ -1242,8 +1321,12 @@ extension __TextureImpl __target_switch { case cpp: + __intrinsic_asm ".SampleBias"; case hlsl: - __intrinsic_asm ".SampleBias"; + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + __intrinsic_asm ".SampleBias"; case metal: if (isArray == 1) { @@ -1288,8 +1371,12 @@ extension __TextureImpl __target_switch { case cpp: + __intrinsic_asm ".SampleBias"; case hlsl: - __intrinsic_asm ".SampleBias"; + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + __intrinsic_asm ".SampleBias"; case metal: if (isArray == 1) { @@ -1344,6 +1431,9 @@ extension __TextureImpl return __glsl_texture(this, s, __makeVector(location,compareValue)); } case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); __intrinsic_asm ".SampleCmp"; case metal: if (isArray == 1) @@ -1392,6 +1482,9 @@ extension __TextureImpl return __glsl_texture_level_zero(this, s, __makeVector(location,compareValue)); } case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); __intrinsic_asm ".SampleCmpLevelZero"; case metal: if (isArray == 1) @@ -1442,6 +1535,9 @@ extension __TextureImpl return __glsl_texture_offset(this, s, __makeVector(location,compareValue), offset); } case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); __intrinsic_asm ".SampleCmp"; case metal: if (isArray == 1) @@ -1487,6 +1583,9 @@ extension __TextureImpl return __glsl_texture_offset_level_zero(this, s, __makeVector(location,compareValue), offset); } case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); __intrinsic_asm ".SampleCmpLevelZero"; case metal: if (isShadow == 1) @@ -1526,7 +1625,11 @@ extension __TextureImpl __target_switch { case cpp: + __intrinsic_asm ".SampleGrad"; case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); __intrinsic_asm ".SampleGrad"; case metal: if (isArray == 1) @@ -1573,7 +1676,11 @@ extension __TextureImpl __target_switch { case cpp: + __intrinsic_asm ".SampleGrad"; case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); __intrinsic_asm ".SampleGrad"; case metal: if (isArray == 1) @@ -1618,7 +1725,11 @@ extension __TextureImpl __target_switch { case cpp: + __intrinsic_asm ".SampleGrad"; case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); __intrinsic_asm ".SampleGrad"; case metal: if (isArray == 1) @@ -1662,7 +1773,11 @@ extension __TextureImpl __target_switch { case cpp: + __intrinsic_asm ".SampleLevel"; case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); __intrinsic_asm ".SampleLevel"; case metal: if (isArray == 1) @@ -1738,7 +1853,11 @@ extension __TextureImpl __target_switch { case cpp: + __intrinsic_asm ".SampleLevel"; case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); __intrinsic_asm ".SampleLevel"; case metal: if (isArray == 1) @@ -2138,8 +2257,9 @@ vector __texture_gatherCmp_offsets(__TextureImpl\n"; @@ -2153,24 +2273,12 @@ for (int isScalarTexture = 0; isScalarTexture <= 1; isScalarTexture++) { }}}} { // begin extension for gather ${{{{ - if (isCombined) - { -}}}} - __intrinsic_op($(kIROp_CombinedTextureSamplerGetTexture)) - __TextureImpl __getTexture(); - - __intrinsic_op($(kIROp_CombinedTextureSamplerGetSampler)) - SamplerState __getSampler(); - - __intrinsic_op($(kIROp_CombinedTextureSamplerGetSampler)) - SamplerComparisonState __getComparisonSampler(); -${{{{ - } // Gather component const char* samplerStateParam = isCombined ? "" : " s,"; const char* getTexture = isCombined ? "__getTexture()" : "this"; - for (int isCmp = 0; isCmp < 2; ++isCmp) { + for (int isCmp = 0; isCmp < 2; ++isCmp) + { const char* cmp = isCmp ? "Cmp" : ""; const char* cmpParam = isCmp ? ", T compareValue" : ""; const char* compareArg = isCmp ? ", compareValue" : ""; @@ -2179,7 +2287,8 @@ ${{{{ const char* componentNames[] = { "", "Red", "Green", "Blue", "Alpha"}; const char* glslComponentNames[] = { ", 0", ", 1", ", 2", ", 3" }; - for (auto componentId = 0; componentId < 5; componentId++) { + for (auto componentId = 0; componentId < 5; componentId++) + { auto componentName = componentNames[componentId]; auto glslComponent = (isCmp ? "" :glslComponentNames[componentId == 0 ? 0 : componentId - 1]); }}}} @@ -2228,14 +2337,13 @@ ${{{{ } } ${{{{ - } // for (componentId) + } // for (componentId) } // for (isCmp) }}}} } // end extension for gather ${{{{ } // for (isScalarTexture) -} // for (isCombined) }}}} // Load/Subscript for readonly, no MS textures -- cgit v1.2.3