Skip to content

Commit f85a8c3

Browse files
committed
PIX: Fix overactive assert in value-to-declare pass
1 parent f0ae0b5 commit f85a8c3

2 files changed

Lines changed: 55 additions & 3 deletions

File tree

lib/DxilPIXPasses/DxilDbgValueToDbgDeclare.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,11 @@ VariableRegisters::VariableRegisters(
864864
{
865865
PopulateAllocaMap(Ty);
866866
m_Offsets.AlignTo(Ty); // For padding.
867+
868+
// (min16* types can occupy 16 or 32 bits depending on whether or not they are natively supported.
869+
// If non-native, the alignment will be 32, but the claimed size will still be 16, hence the "max" here)
867870
assert(m_Offsets.GetCurrentAlignedOffset() ==
868-
DITypePeelTypeAlias(Ty)->getSizeInBits());
871+
std::max<uint64_t>(DITypePeelTypeAlias(Ty)->getSizeInBits(), DITypePeelTypeAlias(Ty)->getAlignInBits()));
869872
}
870873

871874
void VariableRegisters::PopulateAllocaMap(

tools/clang/unittests/HLSL/PixTest.cpp

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class PixTest {
223223
TEST_METHOD(PixStructAnnotation_WheresMyDbgValue)
224224

225225
TEST_METHOD(VirtualRegisters_InstructionCounts)
226+
TEST_METHOD(VirtualRegisters_AlignedOffsets)
226227

227228
TEST_METHOD(RootSignatureUpgrade_SubObjects)
228229
TEST_METHOD(RootSignatureUpgrade_Annotation)
@@ -641,7 +642,7 @@ class PixTest {
641642

642643
VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));
643644
CreateBlobFromText(hlsl, &pSource);
644-
std::vector<const wchar_t*> args = { L"/Zi", L"-enable-16bit-types", L"/Qembed_debug" };
645+
std::vector<const wchar_t*> args = { L"/Zi", L"/Qembed_debug" };
645646
args.insert(args.end(), extraArgs.begin(), extraArgs.end());
646647
VERIFY_SUCCEEDED(pCompiler->Compile(pSource, L"source.hlsl", entry,
647648
target, args.data(), static_cast<UINT32>(args.size()), nullptr, 0, nullptr, &pResult));
@@ -2135,7 +2136,8 @@ PixTest::TestableResults PixTest::TestStructAnnotationCase(
21352136
const wchar_t * optimizationLevel,
21362137
bool validateCoverage,
21372138
const wchar_t *profile) {
2138-
CComPtr<IDxcBlob> pBlob = Compile(hlsl, profile, {optimizationLevel});
2139+
CComPtr<IDxcBlob> pBlob = Compile(hlsl, profile,
2140+
{optimizationLevel, L"-HV", L"2018", L"-enable-16bit-types"});
21392141

21402142
CComPtr<IDxcBlob> pDxil = FindModule(DFCC_ShaderDebugInfoDXIL, pBlob);
21412143

@@ -3504,6 +3506,53 @@ void MyMissShader(inout RayPayload payload)
35043506
}
35053507
}
35063508

3509+
3510+
TEST_F(PixTest, VirtualRegisters_AlignedOffsets) {
3511+
if (m_ver.SkipDxilVersion(1, 5))
3512+
return;
3513+
3514+
{
3515+
const char *hlsl = R"(
3516+
cbuffer cbEveryFrame : register(b0)
3517+
{
3518+
int i32;
3519+
float f32;
3520+
};
3521+
3522+
struct VS_OUTPUT_ENV
3523+
{
3524+
float4 Pos : SV_Position;
3525+
float2 Tex : TEXCOORD0;
3526+
};
3527+
3528+
float4 main(VS_OUTPUT_ENV input) : SV_Target
3529+
{
3530+
// (BTW we load from i32 and f32 (which are resident in a cb) so that these local variables aren't optimized away)
3531+
bool i1 = i32 != 0;
3532+
min16uint u16 = (min16uint)(i32 / 4);
3533+
min16int s16 = (min16int)(i32/4) * -1; // signed s16 gets -8
3534+
min12int s12 = (min12int)(i32/8) * -1; // signed s12 gets -4
3535+
half h = (half) f32 / 2.f; // f32 is initialized to 32.0 in8he CB, so the 16-bit type now has "16.0" in it
3536+
min16float mf16 = (min16float) f32 / -2.f;
3537+
min10float mf10 = (min10float) f32 / -4.f;
3538+
return float4((float)(i1 + u16) / 2.f, (float)(s16 + s12) / -128.f, h / 128.f, mf16 / 128.f + mf10 / 256.f);
3539+
}
3540+
)";
3541+
3542+
//This is little more than a crash test, designed to exercise a previously over-active assert..
3543+
std::vector<std::pair<const wchar_t *, std::vector<const wchar_t *>>> argSets = {
3544+
{L"ps_6_0", {L"-Od"}},
3545+
{L"ps_6_2", {L"-Od", L"-HV", L"2018", L"-enable-16bit-types"}}
3546+
};
3547+
for (auto const &args : argSets) {
3548+
3549+
CComPtr<IDxcBlob> pBlob = Compile(hlsl, args.first, args.second);
3550+
CComPtr<IDxcBlob> pDxil = FindModule(DFCC_ShaderDebugInfoDXIL, pBlob);
3551+
RunAnnotationPasses(pDxil).lines;
3552+
}
3553+
}
3554+
}
3555+
35073556
static void VerifyOperationSucceeded(IDxcOperationResult *pResult)
35083557
{
35093558
HRESULT result;

0 commit comments

Comments
 (0)