Skip to content

Commit 8c9d92b

Browse files
authored
Merge pull request #4891 from hekota/cp-pix-and-hlk-changes
Cherry-pick of PIX and HLK changes for the 2212 release Changes for PIX: 20bb3d0 PIX: Modify root sigs in place (plus fix root sig memory leak) (PIX: Modify root sigs in place (plus fix root sig memory leak) #4876) 2c3d965 dxcopt: Support full container and restore extra data to module (dxcopt: Support full container and restore extra data to module #4845) 21cf36a Fix hitgroup metadata argument order HLK Test Updates: ee0994e add barycentrics ordering check onto existing barycentrics test (add barycentrics ordering check onto existing barycentrics test #4635) 6acd11b ConvertFloat32ToFloat16: Use DirectXMath conversion functions (ConvertFloat32ToFloat16: Use DirectXMath conversion functions #4855) e7aac8e Include TestConfig.h only if DEFAULT_TEST_DIR is not defined (Include TestConfig.h only if DEFAULT_TEST_DIR is not already defined #4884) 5decc4a Do not include TestConfig.h for all HLK build (Do not include TestConfig.h for all HLK build #4887)
2 parents 1c531fb + 1f1b737 commit 8c9d92b

16 files changed

Lines changed: 2127 additions & 349 deletions

File tree

include/dxc/DXIL/DxilModule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ class DxilModule {
204204
void StripDebugRelatedCode();
205205
void RemoveUnusedTypeAnnotations();
206206

207+
// Copy resource reflection back to this module's resources.
208+
void RestoreResourceReflection(const DxilModule &SourceDM);
209+
207210
// Helper to remove dx.* metadata with source and compile options.
208211
// If the parameter `bReplaceWithDummyData` is true, the named metadata
209212
// are replaced with valid empty data that satisfy tools.

include/dxc/DxilContainer/DxilContainerAssembler.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/ADT/StringRef.h"
1717

1818
struct IStream;
19+
class DxilPipelineStateValidation;
1920

2021
namespace llvm {
2122
class Module;
@@ -51,6 +52,16 @@ DxilPartWriter *NewFeatureInfoWriter(const DxilModule &M);
5152
DxilPartWriter *NewPSVWriter(const DxilModule &M, uint32_t PSVVersion = UINT_MAX);
5253
DxilPartWriter *NewRDATWriter(const DxilModule &M);
5354

55+
// Store serialized ViewID data from DxilModule to PipelineStateValidation.
56+
void StoreViewIDStateToPSV(const uint32_t *pInputData,
57+
unsigned InputSizeInUInts,
58+
DxilPipelineStateValidation &PSV);
59+
// Load ViewID state from PSV back to DxilModule view state vector.
60+
// Pass nullptr for pOutputData to compute and return needed OutputSizeInUInts.
61+
unsigned LoadViewIDStateFromPSV(unsigned *pOutputData,
62+
unsigned OutputSizeInUInts,
63+
const DxilPipelineStateValidation &PSV);
64+
5465
// Unaligned is for matching container for validator version < 1.7.
5566
DxilContainerWriter *NewDxilContainerWriter(bool bUnaligned = false);
5667

include/dxc/DxilRootSignature/DxilRootSignature.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,43 @@ bool VerifyRootSignature(_In_ const DxilVersionedRootSignatureDesc *pDesc,
385385
_In_ llvm::raw_ostream &DiagStream,
386386
_In_ bool bAllowReservedRegisterSpace);
387387

388+
class DxilVersionedRootSignature {
389+
DxilVersionedRootSignatureDesc *m_pRootSignature;
390+
391+
public:
392+
// Non-copyable:
393+
DxilVersionedRootSignature(DxilVersionedRootSignature const &) = delete;
394+
DxilVersionedRootSignature const &
395+
operator=(DxilVersionedRootSignature const &) = delete;
396+
397+
// but movable:
398+
DxilVersionedRootSignature(DxilVersionedRootSignature &&) = default;
399+
DxilVersionedRootSignature &
400+
operator=(DxilVersionedRootSignature &&) = default;
401+
402+
DxilVersionedRootSignature() : m_pRootSignature(nullptr) {}
403+
explicit DxilVersionedRootSignature(
404+
const DxilVersionedRootSignatureDesc *pRootSignature)
405+
: m_pRootSignature(
406+
const_cast<DxilVersionedRootSignatureDesc *> (pRootSignature)) {}
407+
~DxilVersionedRootSignature() {
408+
DeleteRootSignature(m_pRootSignature);
409+
}
410+
const DxilVersionedRootSignatureDesc* operator -> () const {
411+
return m_pRootSignature;
412+
}
413+
const DxilVersionedRootSignatureDesc ** get_address_of() {
414+
if (m_pRootSignature != nullptr)
415+
return nullptr; // You're probably about to leak...
416+
return const_cast<const DxilVersionedRootSignatureDesc **> (&m_pRootSignature);
417+
}
418+
const DxilVersionedRootSignatureDesc* get() const {
419+
return m_pRootSignature;
420+
}
421+
DxilVersionedRootSignatureDesc* get_mutable() const {
422+
return m_pRootSignature;
423+
}
424+
};
388425
} // namespace hlsl
389426

390427
#endif // __DXC_ROOTSIGNATURE__

include/dxc/Test/HlslTestUtils.h

Lines changed: 9 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@
2626
#include "WEXAdapter.h"
2727
#endif
2828
#include "dxc/Support/Unicode.h"
29-
#include "dxc/Test/TestConfig.h"
3029
#include "dxc/DXIL/DxilConstants.h" // DenormMode
3130

31+
#ifdef _HLK_CONF
32+
#define DEFAULT_TEST_DIR ""
33+
#else
34+
#include "dxc/Test/TestConfig.h"
35+
#endif
36+
3237
using namespace std;
3338

3439
#ifndef HLSLDATAFILEPARAM
@@ -406,91 +411,9 @@ inline bool isnanFloat16(uint16_t val) {
406411
(val & FLOAT16_BIT_MANTISSA) != 0;
407412
}
408413

409-
inline uint16_t ConvertFloat32ToFloat16(float val) {
410-
union Bits {
411-
uint32_t u_bits;
412-
float f_bits;
413-
};
414-
415-
static const uint32_t SignMask = 0x8000;
416-
417-
// Minimum f32 value representable in f16 format without denormalizing
418-
static const uint32_t Min16in32 = 0x38800000;
419-
420-
// Maximum f32 value (next to infinity)
421-
static const uint32_t Max32 = 0x7f7FFFFF;
422-
423-
// Mask for f32 mantissa
424-
static const uint32_t Fraction32Mask = 0x007FFFFF;
425-
426-
// pow(2,24)
427-
static const uint32_t DenormalRatio = 0x4B800000;
428-
429-
static const uint32_t NormalDelta = 0x38000000;
430-
431-
Bits bits;
432-
bits.f_bits = val;
433-
uint32_t sign = bits.u_bits & (SignMask << 16);
434-
Bits Abs;
435-
Abs.u_bits = bits.u_bits ^ sign;
436-
437-
bool isLessThanNormal = Abs.f_bits < *(const float*)&Min16in32;
438-
bool isInfOrNaN = Abs.u_bits > Max32;
439-
440-
if (isLessThanNormal) {
441-
// Compute Denormal result
442-
return (uint16_t)(Abs.f_bits * *(const float*)(&DenormalRatio)) | (uint16_t)(sign >> 16);
443-
}
444-
else if (isInfOrNaN) {
445-
// Compute Inf or Nan result
446-
uint32_t Fraction = Abs.u_bits & Fraction32Mask;
447-
uint16_t IsNaN = Fraction == 0 ? 0 : 0xffff;
448-
return (IsNaN & FLOAT16_BIT_MANTISSA) | FLOAT16_BIT_EXP | (uint16_t)(sign >> 16);
449-
}
450-
else {
451-
// Compute Normal result
452-
return (uint16_t)((Abs.u_bits - NormalDelta) >> 13) | (uint16_t)(sign >> 16);
453-
}
454-
}
455-
456-
inline float ConvertFloat16ToFloat32(uint16_t x) {
457-
union Bits {
458-
float f_bits;
459-
uint32_t u_bits;
460-
};
461-
462-
uint32_t Sign = (x & FLOAT16_BIT_SIGN) << 16;
463-
464-
// nan -> exponent all set and mantisa is non zero
465-
// +/-inf -> exponent all set and mantissa is zero
466-
// denorm -> exponent zero and significand nonzero
467-
uint32_t Abs = (x & 0x7fff);
468-
uint32_t IsNormal = Abs > FLOAT16_BIGGEST_DENORM;
469-
uint32_t IsInfOrNaN = Abs > FLOAT16_BIGGEST_NORMAL;
470-
471-
// Signless Result for normals
472-
uint32_t DenormRatio = 0x33800000;
473-
float DenormResult = Abs * (*(float*)&DenormRatio);
474-
475-
uint32_t AbsShifted = Abs << 13;
476-
// Signless Result for normals
477-
uint32_t NormalResult = AbsShifted + 0x38000000;
478-
// Signless Result for int & nans
479-
uint32_t InfResult = AbsShifted + 0x70000000;
480-
481-
Bits bits;
482-
bits.u_bits = 0;
483-
if (IsInfOrNaN)
484-
bits.u_bits |= InfResult;
485-
else if (IsNormal)
486-
bits.u_bits |= NormalResult;
487-
else
488-
bits.f_bits = DenormResult;
489-
bits.u_bits |= Sign;
490-
return bits.f_bits;
491-
}
492-
uint16_t ConvertFloat32ToFloat16(float val);
493-
float ConvertFloat16ToFloat32(uint16_t val);
414+
// These are defined in ShaderOpTest.cpp using DirectXPackedVector functions.
415+
uint16_t ConvertFloat32ToFloat16(float val) throw();
416+
float ConvertFloat16ToFloat32(uint16_t val) throw();
494417

495418
inline bool CompareFloatULP(const float &fsrc, const float &fref, int ULPTolerance,
496419
hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {

lib/DXIL/DxilMetadataHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1908,7 +1908,7 @@ Metadata *DxilMDHelper::EmitSubobject(const DxilSubobject &obj) {
19081908
case DXIL::SubobjectKind::HitGroup: {
19091909
llvm::StringRef Intersection, AnyHit, ClosestHit;
19101910
DXIL::HitGroupType hgType;
1911-
IFTBOOL(obj.GetHitGroup(hgType, Intersection, AnyHit, ClosestHit),
1911+
IFTBOOL(obj.GetHitGroup(hgType, AnyHit, ClosestHit, Intersection),
19121912
DXC_E_INCORRECT_DXIL_METADATA);
19131913
Args.emplace_back(Uint32ToConstMD((uint32_t)hgType));
19141914
Args.emplace_back(MDString::get(m_Ctx, Intersection));

lib/DXIL/DxilModule.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,62 @@ void DxilModule::RemoveUnusedTypeAnnotations() {
18731873
}
18741874

18751875

1876+
template <typename _T>
1877+
static void CopyResourceInfo(_T &TargetRes, const _T &SourceRes,
1878+
DxilTypeSystem &TargetTypeSys,
1879+
const DxilTypeSystem &SourceTypeSys) {
1880+
if (TargetRes.GetKind() != SourceRes.GetKind() ||
1881+
TargetRes.GetLowerBound() != SourceRes.GetLowerBound() ||
1882+
TargetRes.GetRangeSize() != SourceRes.GetRangeSize() ||
1883+
TargetRes.GetSpaceID() != SourceRes.GetSpaceID()) {
1884+
DXASSERT(false, "otherwise, resource details don't match");
1885+
return;
1886+
}
1887+
1888+
if (TargetRes.GetGlobalName().empty() && !SourceRes.GetGlobalName().empty()) {
1889+
TargetRes.SetGlobalName(SourceRes.GetGlobalName());
1890+
}
1891+
1892+
if (TargetRes.GetGlobalSymbol() && SourceRes.GetGlobalSymbol() &&
1893+
SourceRes.GetGlobalSymbol()->hasName()) {
1894+
TargetRes.GetGlobalSymbol()->setName(
1895+
SourceRes.GetGlobalSymbol()->getName());
1896+
}
1897+
1898+
Type *Ty = SourceRes.GetHLSLType();
1899+
TargetRes.SetHLSLType(Ty);
1900+
TargetTypeSys.CopyTypeAnnotation(Ty, SourceTypeSys);
1901+
}
1902+
1903+
void DxilModule::RestoreResourceReflection(const DxilModule &SourceDM) {
1904+
DxilTypeSystem &TargetTypeSys = GetTypeSystem();
1905+
const DxilTypeSystem &SourceTypeSys = SourceDM.GetTypeSystem();
1906+
if (GetCBuffers().size() != SourceDM.GetCBuffers().size() ||
1907+
GetSRVs().size() != SourceDM.GetSRVs().size() ||
1908+
GetUAVs().size() != SourceDM.GetUAVs().size() ||
1909+
GetSamplers().size() != SourceDM.GetSamplers().size()) {
1910+
DXASSERT(false, "otherwise, resource lists don't match");
1911+
return;
1912+
}
1913+
for (unsigned i = 0; i < GetCBuffers().size(); ++i) {
1914+
CopyResourceInfo(GetCBuffer(i), SourceDM.GetCBuffer(i), TargetTypeSys,
1915+
SourceTypeSys);
1916+
}
1917+
for (unsigned i = 0; i < GetSRVs().size(); ++i) {
1918+
CopyResourceInfo(GetSRV(i), SourceDM.GetSRV(i), TargetTypeSys,
1919+
SourceTypeSys);
1920+
}
1921+
for (unsigned i = 0; i < GetUAVs().size(); ++i) {
1922+
CopyResourceInfo(GetUAV(i), SourceDM.GetUAV(i), TargetTypeSys,
1923+
SourceTypeSys);
1924+
}
1925+
for (unsigned i = 0; i < GetSamplers().size(); ++i) {
1926+
CopyResourceInfo(GetSampler(i), SourceDM.GetSampler(i), TargetTypeSys,
1927+
SourceTypeSys);
1928+
}
1929+
}
1930+
1931+
18761932
void DxilModule::LoadDxilResources(const llvm::MDOperand &MDO) {
18771933
if (MDO.get() == nullptr)
18781934
return;

0 commit comments

Comments
 (0)