Skip to content

Commit 7c157be

Browse files
authored
Remove integer variants of SampleCmp (microsoft#5930)
Disable integer resource for SampleCmp/CmpLevel/CmpLevelZero. Fixes microsoft#5564
1 parent 216e08e commit 7c157be

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

lib/DXIL/DxilOperations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
685685
"SampleCmp",
686686
OCC::SampleCmp,
687687
"sampleCmp",
688-
{false, true, true, false, false, false, true, true, false, false,
688+
{false, true, true, false, false, false, false, false, false, false,
689689
false},
690690
Attribute::ReadOnly,
691691
},
@@ -694,7 +694,7 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
694694
"SampleCmpLevelZero",
695695
OCC::SampleCmpLevelZero,
696696
"sampleCmpLevelZero",
697-
{false, true, true, false, false, false, true, true, false, false,
697+
{false, true, true, false, false, false, false, false, false, false,
698698
false},
699699
Attribute::ReadOnly,
700700
},

lib/HLSL/DxilValidation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ static void ValidateSampleInst(CallInst *CI, Value *srvHandle,
975975
isSampleCompTy |= compTy == DXIL::ComponentType::SNormF16;
976976
isSampleCompTy |= compTy == DXIL::ComponentType::UNormF16;
977977
const ShaderModel *pSM = ValCtx.DxilMod.GetShaderModel();
978-
if (pSM->IsSM67Plus()) {
978+
if (pSM->IsSM67Plus() && !IsSampleC) {
979979
isSampleCompTy |= compTy == DXIL::ComponentType::I16;
980980
isSampleCompTy |= compTy == DXIL::ComponentType::U16;
981981
isSampleCompTy |= compTy == DXIL::ComponentType::I32;

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5884,6 +5884,12 @@ bool HLSLExternalSource::IsValidObjectElement(LPCSTR tableName,
58845884
return true;
58855885
// 6.7 adds UINT sampler support
58865886
if (IS_BASIC_UINT(kind) || IS_BASIC_SINT(kind)) {
5887+
bool IsSampleC = (op == IntrinsicOp::MOP_SampleCmp ||
5888+
op == IntrinsicOp::MOP_SampleCmpLevel ||
5889+
op == IntrinsicOp::MOP_SampleCmpLevelZero);
5890+
// SampleCmp* cannot support integer resource.
5891+
if (IsSampleC)
5892+
return false;
58875893
const auto *SM = hlsl::ShaderModel::GetByName(
58885894
m_sema->getLangOpts().HLSLProfile.c_str());
58895895
return SM->IsSM67Plus();

tools/clang/test/HLSLFileCheck/hlsl/objects/Texture/sampleInteger.hlsl

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,41 @@
1-
// RUN: %dxc -T ps_6_7 %s -DTYPE=uint | FileCheck %s
2-
// RUN: %dxc -T ps_6_7 %s -DTYPE=int | FileCheck %s
1+
// RUN: %dxc -T ps_6_7 %s -DSKIP_SAMPLE_CMP -DTYPE=uint | FileCheck %s
2+
// RUN: %dxc -T ps_6_7 %s -DSKIP_SAMPLE_CMP -DTYPE=int | FileCheck %s
33
// RUN: %dxc -T ps_6_6 %s -DTYPE=uint | FileCheck %s -check-prefix=CHKFAIL
4-
// RUN: %dxc -T ps_6_7 %s -DTYPE=uint16_t -enable-16bit-types | FileCheck %s -check-prefix=CHECK16
5-
// RUN: %dxc -T ps_6_7 %s -DTYPE=int16_t -enable-16bit-types | FileCheck %s -check-prefix=CHECK16
4+
// RUN: %dxc -T ps_6_7 %s -DSKIP_SAMPLE_CMP -DTYPE=uint16_t -enable-16bit-types | FileCheck %s -check-prefix=CHECK16
5+
// RUN: %dxc -T ps_6_7 %s -DSKIP_SAMPLE_CMP -DTYPE=int16_t -enable-16bit-types | FileCheck %s -check-prefix=CHECK16
66
// RUN: %dxc -T ps_6_6 %s -DTYPE=uint16_t -enable-16bit-types | FileCheck %s -check-prefix=CHKFAIL
77

88
SamplerState g_samp : register(s0);
99
SamplerComparisonState g_sampCmp : register(s01);
1010
Texture2D<TYPE> g_tex0 : register(t0);
1111

12-
// CHECK: Note: shader requires additional functionality:
13-
// CHECK-NEXT: Advanced Texture Ops
1412
// CHECK: call %dx.types.ResRet.i32 @dx.op.sample.i32(i32 60
1513
// CHECK: call %dx.types.ResRet.i32 @dx.op.sampleBias.i32(i32 61
1614
// CHECK: call %dx.types.ResRet.i32 @dx.op.sampleLevel.i32(i32 62
1715
// CHECK: call %dx.types.ResRet.i32 @dx.op.sampleGrad.i32(i32 63
18-
// CHECK: call %dx.types.ResRet.f32 @dx.op.sampleCmp.f32(i32 64
19-
// CHECK: call %dx.types.ResRet.f32 @dx.op.sampleCmpLevelZero.f32(i32 65
20-
// CHECK: call %dx.types.ResRet.f32 @dx.op.sampleCmpLevel.f32(i32 224
2116

22-
// CHECK16: Note: shader requires additional functionality:
23-
// CHECK16: Advanced Texture Ops
2417
// CHECK16: call %dx.types.ResRet.i16 @dx.op.sample.i16(i32 60
2518
// CHECK16: call %dx.types.ResRet.i16 @dx.op.sampleBias.i16(i32 61
2619
// CHECK16: call %dx.types.ResRet.i16 @dx.op.sampleLevel.i16(i32 62
2720
// CHECK16: call %dx.types.ResRet.i16 @dx.op.sampleGrad.i16(i32 63
28-
// CHECK16: call %dx.types.ResRet.f32 @dx.op.sampleCmp.f32(i32 64
29-
// CHECK16: call %dx.types.ResRet.f32 @dx.op.sampleCmpLevelZero.f32(i32 65
30-
// CHECK16: call %dx.types.ResRet.f32 @dx.op.sampleCmpLevel.f32(i32 224
3121

3222
// CHKFAIL: error: cannot Sample from resource containing
3323
// CHKFAIL: error: cannot SampleBias from resource containing
3424
// CHKFAIL: error: cannot SampleLevel from resource containing
3525
// CHKFAIL: error: cannot SampleGrad from resource containing
3626
// CHKFAIL: error: cannot SampleCmp from resource containing
3727
// CHKFAIL: error: cannot SampleCmpLevelZero from resource containing
28+
// CHKFAIL: error: cannot SampleCmpLevel from resource containing
3829

3930
float4 main(float2 coord : TEXCOORD0) : SV_Target {
4031
float res = 0;
4132
res = g_tex0.Sample(g_samp, coord);
4233
res += g_tex0.SampleBias(g_samp, coord, 0.0);
4334
res += g_tex0.SampleLevel(g_samp, coord, 0.0);
4435
res += g_tex0.SampleGrad(g_samp, coord, 0.0, 0.0);
36+
#ifndef SKIP_SAMPLE_CMP
4537
res += g_tex0.SampleCmp(g_sampCmp, coord, 0.0);
4638
res += g_tex0.SampleCmpLevelZero(g_sampCmp, coord, 0.0);
47-
#if __SHADER_TARGET_MAJOR > 6 || (__SHADER_TARGET_MAJOR == 6 && __SHADER_TARGET_MINOR >= 7)
4839
res += g_tex0.SampleCmpLevel(g_sampCmp, coord, 0.0, 0.0);
4940
#endif
5041
return res;

utils/hct/hctdb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,7 @@ def UFI(name, **mappings):
18911891
next_op_idx,
18921892
"SampleCmp",
18931893
"samples a texture and compares a single component against the specified comparison value",
1894-
"hfwi",
1894+
"hf",
18951895
"ro",
18961896
[
18971897
db_dxil_param(
@@ -1936,7 +1936,7 @@ def UFI(name, **mappings):
19361936
next_op_idx,
19371937
"SampleCmpLevelZero",
19381938
"samples a texture and compares a single component against the specified comparison value",
1939-
"hfwi",
1939+
"hf",
19401940
"ro",
19411941
[
19421942
db_dxil_param(

0 commit comments

Comments
 (0)