Skip to content

Commit

Permalink
Merge pull request #4891 from hekota/cp-pix-and-hlk-changes
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
hekota authored Dec 16, 2022
2 parents 1c531fb + 1f1b737 commit 8c9d92b
Show file tree
Hide file tree
Showing 16 changed files with 2,127 additions and 349 deletions.
3 changes: 3 additions & 0 deletions include/dxc/DXIL/DxilModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ class DxilModule {
void StripDebugRelatedCode();
void RemoveUnusedTypeAnnotations();

// Copy resource reflection back to this module's resources.
void RestoreResourceReflection(const DxilModule &SourceDM);

// Helper to remove dx.* metadata with source and compile options.
// If the parameter `bReplaceWithDummyData` is true, the named metadata
// are replaced with valid empty data that satisfy tools.
Expand Down
11 changes: 11 additions & 0 deletions include/dxc/DxilContainer/DxilContainerAssembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "llvm/ADT/StringRef.h"

struct IStream;
class DxilPipelineStateValidation;

namespace llvm {
class Module;
Expand Down Expand Up @@ -51,6 +52,16 @@ DxilPartWriter *NewFeatureInfoWriter(const DxilModule &M);
DxilPartWriter *NewPSVWriter(const DxilModule &M, uint32_t PSVVersion = UINT_MAX);
DxilPartWriter *NewRDATWriter(const DxilModule &M);

// Store serialized ViewID data from DxilModule to PipelineStateValidation.
void StoreViewIDStateToPSV(const uint32_t *pInputData,
unsigned InputSizeInUInts,
DxilPipelineStateValidation &PSV);
// Load ViewID state from PSV back to DxilModule view state vector.
// Pass nullptr for pOutputData to compute and return needed OutputSizeInUInts.
unsigned LoadViewIDStateFromPSV(unsigned *pOutputData,
unsigned OutputSizeInUInts,
const DxilPipelineStateValidation &PSV);

// Unaligned is for matching container for validator version < 1.7.
DxilContainerWriter *NewDxilContainerWriter(bool bUnaligned = false);

Expand Down
37 changes: 37 additions & 0 deletions include/dxc/DxilRootSignature/DxilRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,43 @@ bool VerifyRootSignature(_In_ const DxilVersionedRootSignatureDesc *pDesc,
_In_ llvm::raw_ostream &DiagStream,
_In_ bool bAllowReservedRegisterSpace);

class DxilVersionedRootSignature {
DxilVersionedRootSignatureDesc *m_pRootSignature;

public:
// Non-copyable:
DxilVersionedRootSignature(DxilVersionedRootSignature const &) = delete;
DxilVersionedRootSignature const &
operator=(DxilVersionedRootSignature const &) = delete;

// but movable:
DxilVersionedRootSignature(DxilVersionedRootSignature &&) = default;
DxilVersionedRootSignature &
operator=(DxilVersionedRootSignature &&) = default;

DxilVersionedRootSignature() : m_pRootSignature(nullptr) {}
explicit DxilVersionedRootSignature(
const DxilVersionedRootSignatureDesc *pRootSignature)
: m_pRootSignature(
const_cast<DxilVersionedRootSignatureDesc *> (pRootSignature)) {}
~DxilVersionedRootSignature() {
DeleteRootSignature(m_pRootSignature);
}
const DxilVersionedRootSignatureDesc* operator -> () const {
return m_pRootSignature;
}
const DxilVersionedRootSignatureDesc ** get_address_of() {
if (m_pRootSignature != nullptr)
return nullptr; // You're probably about to leak...
return const_cast<const DxilVersionedRootSignatureDesc **> (&m_pRootSignature);
}
const DxilVersionedRootSignatureDesc* get() const {
return m_pRootSignature;
}
DxilVersionedRootSignatureDesc* get_mutable() const {
return m_pRootSignature;
}
};
} // namespace hlsl

#endif // __DXC_ROOTSIGNATURE__
95 changes: 9 additions & 86 deletions include/dxc/Test/HlslTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@
#include "WEXAdapter.h"
#endif
#include "dxc/Support/Unicode.h"
#include "dxc/Test/TestConfig.h"
#include "dxc/DXIL/DxilConstants.h" // DenormMode

#ifdef _HLK_CONF
#define DEFAULT_TEST_DIR ""
#else
#include "dxc/Test/TestConfig.h"
#endif

using namespace std;

#ifndef HLSLDATAFILEPARAM
Expand Down Expand Up @@ -406,91 +411,9 @@ inline bool isnanFloat16(uint16_t val) {
(val & FLOAT16_BIT_MANTISSA) != 0;
}

inline uint16_t ConvertFloat32ToFloat16(float val) {
union Bits {
uint32_t u_bits;
float f_bits;
};

static const uint32_t SignMask = 0x8000;

// Minimum f32 value representable in f16 format without denormalizing
static const uint32_t Min16in32 = 0x38800000;

// Maximum f32 value (next to infinity)
static const uint32_t Max32 = 0x7f7FFFFF;

// Mask for f32 mantissa
static const uint32_t Fraction32Mask = 0x007FFFFF;

// pow(2,24)
static const uint32_t DenormalRatio = 0x4B800000;

static const uint32_t NormalDelta = 0x38000000;

Bits bits;
bits.f_bits = val;
uint32_t sign = bits.u_bits & (SignMask << 16);
Bits Abs;
Abs.u_bits = bits.u_bits ^ sign;

bool isLessThanNormal = Abs.f_bits < *(const float*)&Min16in32;
bool isInfOrNaN = Abs.u_bits > Max32;

if (isLessThanNormal) {
// Compute Denormal result
return (uint16_t)(Abs.f_bits * *(const float*)(&DenormalRatio)) | (uint16_t)(sign >> 16);
}
else if (isInfOrNaN) {
// Compute Inf or Nan result
uint32_t Fraction = Abs.u_bits & Fraction32Mask;
uint16_t IsNaN = Fraction == 0 ? 0 : 0xffff;
return (IsNaN & FLOAT16_BIT_MANTISSA) | FLOAT16_BIT_EXP | (uint16_t)(sign >> 16);
}
else {
// Compute Normal result
return (uint16_t)((Abs.u_bits - NormalDelta) >> 13) | (uint16_t)(sign >> 16);
}
}

inline float ConvertFloat16ToFloat32(uint16_t x) {
union Bits {
float f_bits;
uint32_t u_bits;
};

uint32_t Sign = (x & FLOAT16_BIT_SIGN) << 16;

// nan -> exponent all set and mantisa is non zero
// +/-inf -> exponent all set and mantissa is zero
// denorm -> exponent zero and significand nonzero
uint32_t Abs = (x & 0x7fff);
uint32_t IsNormal = Abs > FLOAT16_BIGGEST_DENORM;
uint32_t IsInfOrNaN = Abs > FLOAT16_BIGGEST_NORMAL;

// Signless Result for normals
uint32_t DenormRatio = 0x33800000;
float DenormResult = Abs * (*(float*)&DenormRatio);

uint32_t AbsShifted = Abs << 13;
// Signless Result for normals
uint32_t NormalResult = AbsShifted + 0x38000000;
// Signless Result for int & nans
uint32_t InfResult = AbsShifted + 0x70000000;

Bits bits;
bits.u_bits = 0;
if (IsInfOrNaN)
bits.u_bits |= InfResult;
else if (IsNormal)
bits.u_bits |= NormalResult;
else
bits.f_bits = DenormResult;
bits.u_bits |= Sign;
return bits.f_bits;
}
uint16_t ConvertFloat32ToFloat16(float val);
float ConvertFloat16ToFloat32(uint16_t val);
// These are defined in ShaderOpTest.cpp using DirectXPackedVector functions.
uint16_t ConvertFloat32ToFloat16(float val) throw();
float ConvertFloat16ToFloat32(uint16_t val) throw();

inline bool CompareFloatULP(const float &fsrc, const float &fref, int ULPTolerance,
hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
Expand Down
2 changes: 1 addition & 1 deletion lib/DXIL/DxilMetadataHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,7 @@ Metadata *DxilMDHelper::EmitSubobject(const DxilSubobject &obj) {
case DXIL::SubobjectKind::HitGroup: {
llvm::StringRef Intersection, AnyHit, ClosestHit;
DXIL::HitGroupType hgType;
IFTBOOL(obj.GetHitGroup(hgType, Intersection, AnyHit, ClosestHit),
IFTBOOL(obj.GetHitGroup(hgType, AnyHit, ClosestHit, Intersection),
DXC_E_INCORRECT_DXIL_METADATA);
Args.emplace_back(Uint32ToConstMD((uint32_t)hgType));
Args.emplace_back(MDString::get(m_Ctx, Intersection));
Expand Down
56 changes: 56 additions & 0 deletions lib/DXIL/DxilModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,62 @@ void DxilModule::RemoveUnusedTypeAnnotations() {
}


template <typename _T>
static void CopyResourceInfo(_T &TargetRes, const _T &SourceRes,
DxilTypeSystem &TargetTypeSys,
const DxilTypeSystem &SourceTypeSys) {
if (TargetRes.GetKind() != SourceRes.GetKind() ||
TargetRes.GetLowerBound() != SourceRes.GetLowerBound() ||
TargetRes.GetRangeSize() != SourceRes.GetRangeSize() ||
TargetRes.GetSpaceID() != SourceRes.GetSpaceID()) {
DXASSERT(false, "otherwise, resource details don't match");
return;
}

if (TargetRes.GetGlobalName().empty() && !SourceRes.GetGlobalName().empty()) {
TargetRes.SetGlobalName(SourceRes.GetGlobalName());
}

if (TargetRes.GetGlobalSymbol() && SourceRes.GetGlobalSymbol() &&
SourceRes.GetGlobalSymbol()->hasName()) {
TargetRes.GetGlobalSymbol()->setName(
SourceRes.GetGlobalSymbol()->getName());
}

Type *Ty = SourceRes.GetHLSLType();
TargetRes.SetHLSLType(Ty);
TargetTypeSys.CopyTypeAnnotation(Ty, SourceTypeSys);
}

void DxilModule::RestoreResourceReflection(const DxilModule &SourceDM) {
DxilTypeSystem &TargetTypeSys = GetTypeSystem();
const DxilTypeSystem &SourceTypeSys = SourceDM.GetTypeSystem();
if (GetCBuffers().size() != SourceDM.GetCBuffers().size() ||
GetSRVs().size() != SourceDM.GetSRVs().size() ||
GetUAVs().size() != SourceDM.GetUAVs().size() ||
GetSamplers().size() != SourceDM.GetSamplers().size()) {
DXASSERT(false, "otherwise, resource lists don't match");
return;
}
for (unsigned i = 0; i < GetCBuffers().size(); ++i) {
CopyResourceInfo(GetCBuffer(i), SourceDM.GetCBuffer(i), TargetTypeSys,
SourceTypeSys);
}
for (unsigned i = 0; i < GetSRVs().size(); ++i) {
CopyResourceInfo(GetSRV(i), SourceDM.GetSRV(i), TargetTypeSys,
SourceTypeSys);
}
for (unsigned i = 0; i < GetUAVs().size(); ++i) {
CopyResourceInfo(GetUAV(i), SourceDM.GetUAV(i), TargetTypeSys,
SourceTypeSys);
}
for (unsigned i = 0; i < GetSamplers().size(); ++i) {
CopyResourceInfo(GetSampler(i), SourceDM.GetSampler(i), TargetTypeSys,
SourceTypeSys);
}
}


void DxilModule::LoadDxilResources(const llvm::MDOperand &MDO) {
if (MDO.get() == nullptr)
return;
Expand Down
Loading

0 comments on commit 8c9d92b

Please sign in to comment.