From 0bf0bf77ac697d2a0fc7d90ec2899c6393b4306a Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Wed, 12 Jun 2024 23:06:11 -0700 Subject: Implement Sampler2D for CPP target (#4371) Closes #4267 Co-authored-by: Yong He --- source/slang/slang-type-layout.cpp | 10 ++++++++-- tests/bindings/hlsl-to-cpp-combined.slang | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/bindings/hlsl-to-cpp-combined.slang diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp index 623483efe..1aeaceb72 100644 --- a/source/slang/slang-type-layout.cpp +++ b/source/slang/slang-type-layout.cpp @@ -1057,6 +1057,12 @@ struct CPUObjectLayoutRulesImpl : ObjectLayoutRulesImpl case ShaderParameterKind::TextureSampler: case ShaderParameterKind::MutableTextureSampler: + { + ObjectLayoutInfo info; + info.layoutInfos.add(SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*))); + info.layoutInfos.add(SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*))); + return info; + } case ShaderParameterKind::InputRenderTarget: // TODO: how to handle these? default: @@ -1447,11 +1453,11 @@ LayoutRulesImpl* CPULayoutRulesFamilyImpl::getTextureBufferRules() LayoutRulesImpl* CPULayoutRulesFamilyImpl::getVaryingInputRules() { - return nullptr; + return &kCPULayoutRulesImpl_; } LayoutRulesImpl* CPULayoutRulesFamilyImpl::getVaryingOutputRules() { - return nullptr; + return &kCPULayoutRulesImpl_; } LayoutRulesImpl* CPULayoutRulesFamilyImpl::getSpecializationConstantRules() { diff --git a/tests/bindings/hlsl-to-cpp-combined.slang b/tests/bindings/hlsl-to-cpp-combined.slang new file mode 100644 index 000000000..965ee0d47 --- /dev/null +++ b/tests/bindings/hlsl-to-cpp-combined.slang @@ -0,0 +1,17 @@ +//TEST:SIMPLE(filecheck=CHK):-target cpp -stage compute -entry computeMain + +//CHK:struct Sampler2D +//CHK-NEXT:{ +//CHK-NEXT: Texture2D<{{.*}}> [[TEX:texture_[0-9]*]] +//CHK-NEXT: SamplerState [[SMP:sampler_[0-9]*]] + +Sampler2D s2D; + +RWStructuredBuffer outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) +{ + //CHK:[[VAR:[A-Za-z_][A-Za-z_0-9]*]].[[TEX]].Sample([[VAR]].[[SMP]] + outputBuffer[0] = s2D.Sample(float2(0.5f, 0.5f)); +} -- cgit v1.2.3