Only define global heap variables in 6.6+ (#4011)

RsourceDescriptorHeap and SamplerDescriptorHeap were predefined in all
shader models, not just 6.6+. By checking the shader model version
before declaring them, we can limit this to relevant shader models.

Added tests for 6.6 and 6.5 behavior when these are redefined
This commit is contained in:
Greg Roth 2021-10-14 16:48:54 -06:00 коммит произвёл GitHub
Родитель ebdf8fbdb4
Коммит 7c6a6bc7aa
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 37 добавлений и 6 удалений

Просмотреть файл

@ -3508,6 +3508,8 @@ private:
TypeSourceInfo *float4TypeSourceInfo = m_context->getTrivialTypeSourceInfo(float4Type, NoLoc);
m_objectTypeLazyInitMask = 0;
unsigned effectKindIndex = 0;
const auto *SM =
hlsl::ShaderModel::GetByName(m_sema->getLangOpts().HLSLProfile.c_str());
for (unsigned i = 0; i < _countof(g_ArBasicKindsAsTypes); i++)
{
ArBasicKind kind = g_ArBasicKindsAsTypes[i];
@ -3566,14 +3568,18 @@ private:
recordDecl = DeclareRayQueryType(*m_context);
} else if (kind == AR_OBJECT_HEAP_RESOURCE) {
recordDecl = DeclareResourceType(*m_context, /*bSampler*/false);
// create Resource ResourceDescriptorHeap;
DeclareBuiltinGlobal("ResourceDescriptorHeap",
m_context->getRecordType(recordDecl), *m_context);
if (SM->IsSM66Plus()) {
// create Resource ResourceDescriptorHeap;
DeclareBuiltinGlobal("ResourceDescriptorHeap",
m_context->getRecordType(recordDecl), *m_context);
}
} else if (kind == AR_OBJECT_HEAP_SAMPLER) {
recordDecl = DeclareResourceType(*m_context, /*bSampler*/true);
// create Resource SamplerDescriptorHeap;
DeclareBuiltinGlobal("SamplerDescriptorHeap",
m_context->getRecordType(recordDecl), *m_context);
if (SM->IsSM66Plus()) {
// create Resource SamplerDescriptorHeap;
DeclareBuiltinGlobal("SamplerDescriptorHeap",
m_context->getRecordType(recordDecl), *m_context);
}
}
else if (kind == AR_OBJECT_FEEDBACKTEXTURE2D) {

Просмотреть файл

@ -0,0 +1,25 @@
// RUN: %dxc -T ps_6_5 %s | %FileCheck %s
// RUN: %dxc -T ps_6_6 %s | %FileCheck %s -check-prefix=FAIL
// Make sure that global heap variable redeclaration fails
// on 6.6 and passes on previous shader models
// FAIL: error: redefinition of 'ResourceDescriptorHeap' with a different type: 'Texture2D<float> []' vs '.Resource'
// FAIL: error: redefinition of 'SamplerDescriptorHeap' with a different type: 'SamplerState []' vs '.Sampler'
// Verify that feature bits aren't set and the shader produce roughly reasonable code
// CHECK-NOT: Resource descriptor heap indexing
// CHECK-NOT: Sampler descriptor heap indexing
// CHECK: @main
// CHECK: @dx.op.sample.f32
Texture2D<float> ResourceDescriptorHeap[] : register(t0);
SamplerState SamplerDescriptorHeap[] : register(s0);
uint ID;
float main(float4 pos: SV_Position): SV_Target {
Texture2D<float> tex = ResourceDescriptorHeap[ID];
SamplerState samp = SamplerDescriptorHeap[ID];
return tex.Sample(samp, pos.xy);
}