Skip to content

Commit 8a281b7

Browse files
committed
pull upstream & resolve conflicts
2 parents c0e532f + 070d0d5 commit 8a281b7

33 files changed

+714
-153
lines changed

.github/ISSUE_TEMPLATE/bug_report_spirv.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ assignees: ''
1212

1313
**Steps to Reproduce**
1414
<!--- Provide a description of how to reproduce the error. If possible please
15-
provide source and tool command line options. If the issue reproduces on
16-
Compiler Explorer (https://godbolt.org/) or Shader Playground
17-
(https://shader-playground.timjones.io/) please provide a link. If the source is
18-
split across multiple files, please preprocess into a single file using DXC's
19-
command line `-P -Fi <path>`. --->
15+
provide source and tool command line options, or if the issue reproduces on
16+
Compiler Explorer (https://godbolt.org/), please provide a link.
17+
If the source is split across multiple files, please preprocess into a single file using DXC's
18+
command line `-P -Fi <path>`.
19+
--->
2020

2121

2222
**Actual Behavior**

cmake/modules/HandleLLVMOptions.cmake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,11 @@ if( MSVC )
357357

358358
# Change release to always build debug information out-of-line, but
359359
# also enable Reference optimization, ie dead function elimination.
360-
append("/Zi" CMAKE_CXX_FLAGS_RELEASE)
361-
append("/DEBUG /OPT:REF" CMAKE_SHARED_LINKER_FLAGS_RELEASE)
362-
append("/DEBUG /OPT:REF" CMAKE_EXE_LINKER_FLAGS_RELEASE)
360+
if (NOT CMAKE_MSVC_DEBUG_INFORMATION_FORMAT)
361+
append("/Zi" CMAKE_CXX_FLAGS_RELEASE)
362+
append("/DEBUG /OPT:REF" CMAKE_SHARED_LINKER_FLAGS_RELEASE)
363+
append("/DEBUG /OPT:REF" CMAKE_EXE_LINKER_FLAGS_RELEASE)
364+
endif()
363365

364366
# HLSL Changes End
365367

docs/SPIR-V.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,32 @@ Supported extensions
293293
* SPV_KHR_fragment_shading_rate
294294
* SPV_KHR_multivew
295295
* SPV_KHR_post_depth_coverage
296+
* SPV_KHR_non_semantic_info
296297
* SPV_KHR_shader_draw_parameters
298+
* SPV_KHR_ray_tracing
299+
* SPV_KHR_shader_clock
300+
* SPV_EXT_demote_to_helper_invocation
297301
* SPV_EXT_descriptor_indexing
298302
* SPV_EXT_fragment_fully_covered
303+
* SPV_EXT_fragment_invocation_density
304+
* SPV_EXT_fragment_shader_interlock
299305
* SPV_EXT_mesh_shader
300306
* SPV_EXT_shader_stencil_support
307+
* SPV_EXT_shader_viewport_index_layer
301308
* SPV_AMD_shader_early_and_late_fragment_tests
302309
* SPV_GOOGLE_hlsl_functionality1
303310
* SPV_GOOGLE_user_type
311+
* SPV_NV_ray_tracing
304312
* SPV_NV_mesh_shader
313+
* SPV_KHR_ray_query
314+
* SPV_EXT_shader_image_int64
305315
* SPV_KHR_fragment_shading_barycentric
316+
* SPV_KHR_physical_storage_buffer
317+
* SPV_KHR_vulkan_memory_model
318+
* SPV_NV_compute_shader_derivatives
319+
* SPV_KHR_maximal_reconvergence
306320
* SPV_KHR_float_controls
321+
* SPV_NV_shader_subgroup_partitioned
307322

308323
Vulkan specific attributes
309324
--------------------------

include/dxc/Support/DxcOptToggles.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,29 @@ namespace options {
2727
struct Toggle {
2828
llvm::StringRef Name;
2929
bool Default = false;
30-
Toggle(llvm::StringRef Name, bool Default) : Name(Name), Default(Default) {}
30+
constexpr Toggle(llvm::StringRef Name, bool Default)
31+
: Name(Name), Default(Default) {}
3132
};
3233

3334
enum {
3435
DEFAULT_ON = 1,
3536
DEFAULT_OFF = 0,
3637
};
3738

38-
static const Toggle TOGGLE_GVN = {"gvn", DEFAULT_ON};
39-
static const Toggle TOGGLE_LICM = {"licm", DEFAULT_ON};
40-
static const Toggle TOGGLE_SINK = {"sink", DEFAULT_ON};
41-
static const Toggle TOGGLE_ENABLE_AGGRESSIVE_REASSOCIATION = {
39+
static constexpr Toggle TOGGLE_GVN = {"gvn", DEFAULT_ON};
40+
static constexpr Toggle TOGGLE_LICM = {"licm", DEFAULT_ON};
41+
static constexpr Toggle TOGGLE_SINK = {"sink", DEFAULT_ON};
42+
static constexpr Toggle TOGGLE_ENABLE_AGGRESSIVE_REASSOCIATION = {
4243
"aggressive-reassociation", DEFAULT_ON};
43-
static const Toggle TOGGLE_LIFETIME_MARKERS = {"lifetime-markers", DEFAULT_ON};
44-
static const Toggle TOGGLE_PARTIAL_LIFETIME_MARKERS = {
44+
static constexpr Toggle TOGGLE_LIFETIME_MARKERS = {"lifetime-markers",
45+
DEFAULT_ON};
46+
static constexpr Toggle TOGGLE_PARTIAL_LIFETIME_MARKERS = {
4547
"partial-lifetime-markers", DEFAULT_OFF};
46-
static const Toggle TOGGLE_STRUCTURIZE_LOOP_EXITS_FOR_UNROLL = {
48+
static constexpr Toggle TOGGLE_STRUCTURIZE_LOOP_EXITS_FOR_UNROLL = {
4749
"structurize-loop-exits-for-unroll", DEFAULT_ON};
48-
static const Toggle TOGGLE_DEBUG_NOPS = {"debug-nops", DEFAULT_ON};
49-
static const Toggle TOGGLE_STRUCTURIZE_RETURNS = {"structurize-returns",
50-
DEFAULT_OFF};
50+
static constexpr Toggle TOGGLE_DEBUG_NOPS = {"debug-nops", DEFAULT_ON};
51+
static constexpr Toggle TOGGLE_STRUCTURIZE_RETURNS = {"structurize-returns",
52+
DEFAULT_OFF};
5153

5254
struct OptimizationToggles {
5355
// Optimization pass enables, disables and selects

include/llvm/ADT/StringRef.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,20 @@ namespace llvm {
6666
/*implicit*/ StringRef() : Data(nullptr), Length(0) {}
6767
StringRef(std::nullptr_t) = delete; // HLSL Change - So we don't accidentally pass `false` again
6868

69+
// HLSL Change - Begin - Make StringRef constructors constexpr.
6970
/// Construct a string ref from a cstring.
70-
/*implicit*/ StringRef(const char *Str)
71-
: Data(Str) {
72-
assert(Str && "StringRef cannot be built from a NULL argument");
73-
Length = ::strlen(Str); // invoking strlen(NULL) is undefined behavior
74-
}
71+
/*implicit*/ constexpr StringRef(const char *Str)
72+
: Data(Str), Length(Str ? std::char_traits<char>::length(Str) : 0) {
73+
assert(Str && "StringRef cannot be built from a NULL argument");
74+
}
7575

7676
/// Construct a string ref from a pointer and length.
77-
/*implicit*/ StringRef(const char *data, size_t length)
78-
: Data(data), Length(length) {
79-
assert((data || length == 0) &&
80-
"StringRef cannot be built from a NULL argument with non-null length");
81-
}
77+
/*implicit*/ constexpr StringRef(const char *data, size_t length)
78+
: Data(data), Length(length) {
79+
assert((data || length == 0) && "StringRef cannot be built from a NULL "
80+
"argument with non-null length");
81+
}
82+
// HLSL Change - End - Make StringRef constructors constexpr.
8283

8384
/// Construct a string ref from an std::string.
8485
/*implicit*/ StringRef(const std::string &Str)

lib/Analysis/LoopPass.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/IR/IRPrintingPasses.h"
1818
#include "llvm/IR/LLVMContext.h"
1919
#include "llvm/Support/Debug.h"
20+
#include "llvm/Support/TimeProfiler.h" // HLSL Change
2021
#include "llvm/Support/Timer.h"
2122
#include "llvm/Support/raw_ostream.h"
2223
using namespace llvm;
@@ -199,6 +200,10 @@ bool LPPassManager::runOnFunction(Function &F) {
199200
LI = &LIWP.getLoopInfo();
200201
bool Changed = false;
201202

203+
// HLSL Change Begin - Support hierarchial time tracing.
204+
llvm::TimeTraceScope FunctionScope("Loop Pass Manager Function", F.getName());
205+
// HLSL Change End
206+
202207
// Collect inherited analysis from Module level pass manager.
203208
populateInheritedAnalysis(TPM->activeStack);
204209

@@ -248,6 +253,10 @@ bool LPPassManager::runOnFunction(Function &F) {
248253
PassManagerPrettyStackEntry X(P, *CurrentLoop->getHeader());
249254
TimeRegion PassTimer(getPassTimer(P));
250255

256+
// HLSL Change Begin - Support hierarchial time tracing.
257+
llvm::TimeTraceScope PassScope("RunLoopPass", P->getPassName());
258+
// HLSL Change End - Support hierarchial time tracing.
259+
251260
Changed |= P->runOnLoop(CurrentLoop, *this);
252261
}
253262

lib/DxilPIXPasses/DxilAnnotateWithVirtualRegister.cpp

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class DxilAnnotateWithVirtualRegister : public llvm::ModulePass {
7777
private:
7878
void AnnotateValues(llvm::Instruction *pI);
7979
void AnnotateStore(llvm::Instruction *pI);
80+
void SplitVectorStores(hlsl::OP *HlslOP, llvm::Instruction *pI);
8081
bool IsAllocaRegisterWrite(llvm::Value *V, llvm::AllocaInst **pAI,
8182
llvm::Value **pIdx);
8283
void AnnotateAlloca(llvm::AllocaInst *pAlloca);
@@ -133,6 +134,15 @@ bool DxilAnnotateWithVirtualRegister::runOnModule(llvm::Module &M) {
133134
auto instrumentableFunctions =
134135
PIXPassHelpers::GetAllInstrumentableFunctions(*m_DM);
135136

137+
for (auto *F : instrumentableFunctions) {
138+
for (auto &block : F->getBasicBlockList()) {
139+
for (auto it = block.begin(); it != block.end();) {
140+
llvm::Instruction *I = &*(it++);
141+
SplitVectorStores(m_DM->GetOP(), I);
142+
}
143+
}
144+
}
145+
136146
for (auto *F : instrumentableFunctions) {
137147
for (auto &block : F->getBasicBlockList()) {
138148
for (llvm::Instruction &I : block.getInstList()) {
@@ -297,15 +307,37 @@ bool DxilAnnotateWithVirtualRegister::IsAllocaRegisterWrite(
297307
return false;
298308
}
299309
// And of course the member we're after might not be at the beginning of
300-
// the struct:
301-
auto *pStructType = llvm::dyn_cast<llvm::StructType>(
302-
pPointerGEP->getPointerOperandType()->getPointerElementType());
303-
auto *pStructMember =
304-
llvm::dyn_cast<llvm::ConstantInt>(pPointerGEP->getOperand(2));
305-
uint64_t memberIndex = pStructMember->getLimitedValue();
306-
for (uint64_t i = 0; i < memberIndex; ++i) {
307-
precedingMemberCount +=
308-
CountStructMembers(pStructType->getStructElementType(i));
310+
// any containing struct:
311+
if (auto *pStructType = llvm::dyn_cast<llvm::StructType>(
312+
pPointerGEP->getPointerOperandType()
313+
->getPointerElementType())) {
314+
auto *pStructMember =
315+
llvm::dyn_cast<llvm::ConstantInt>(pPointerGEP->getOperand(2));
316+
uint64_t memberIndex = pStructMember->getLimitedValue();
317+
for (uint64_t i = 0; i < memberIndex; ++i) {
318+
precedingMemberCount +=
319+
CountStructMembers(pStructType->getStructElementType(i));
320+
}
321+
}
322+
323+
// And the source pointer may be a vector (floatn) type,
324+
// and if so, that's another offset to consider.
325+
llvm::Type *DestType = pGEP->getPointerOperand()->getType();
326+
// We expect this to be a pointer type (it's a GEP after all):
327+
if (DestType->isPointerTy()) {
328+
llvm::Type *PointedType = DestType->getPointerElementType();
329+
// Being careful to check num operands too in order to avoid false
330+
// positives:
331+
if (PointedType->isVectorTy() && pGEP->getNumOperands() == 3) {
332+
// Fetch the second deref (in operand 2).
333+
// (the first derefs the pointer to the "floatn",
334+
// and the second denotes the index into the floatn.)
335+
llvm::Value *vectorIndex = pGEP->getOperand(2);
336+
if (auto *constIntIIndex =
337+
llvm::cast<llvm::ConstantInt>(vectorIndex)) {
338+
precedingMemberCount += constIntIIndex->getLimitedValue();
339+
}
340+
}
309341
}
310342
} else {
311343
return false;
@@ -365,6 +397,8 @@ void DxilAnnotateWithVirtualRegister::AnnotateAlloca(
365397
AssignNewAllocaRegister(pAlloca, 1);
366398
} else if (auto *AT = llvm::dyn_cast<llvm::ArrayType>(pAllocaTy)) {
367399
AssignNewAllocaRegister(pAlloca, AT->getNumElements());
400+
} else if (auto *VT = llvm::dyn_cast<llvm::VectorType>(pAllocaTy)) {
401+
AssignNewAllocaRegister(pAlloca, VT->getNumElements());
368402
} else if (auto *ST = llvm::dyn_cast<llvm::StructType>(pAllocaTy)) {
369403
AssignNewAllocaRegister(pAlloca, CountStructMembers(ST));
370404
} else {
@@ -433,6 +467,36 @@ void DxilAnnotateWithVirtualRegister::AssignNewAllocaRegister(
433467
m_uVReg += C;
434468
}
435469

470+
void DxilAnnotateWithVirtualRegister::SplitVectorStores(hlsl::OP *HlslOP,
471+
llvm::Instruction *pI) {
472+
auto *pSt = llvm::dyn_cast<llvm::StoreInst>(pI);
473+
if (pSt == nullptr) {
474+
return;
475+
}
476+
477+
llvm::AllocaInst *Alloca;
478+
llvm::Value *Index;
479+
if (!IsAllocaRegisterWrite(pSt->getPointerOperand(), &Alloca, &Index)) {
480+
return;
481+
}
482+
483+
llvm::Type *SourceType = pSt->getValueOperand()->getType();
484+
if (SourceType->isVectorTy()) {
485+
if (auto *constIntIIndex = llvm::cast<llvm::ConstantInt>(Index)) {
486+
// break vector alloca stores up into individual stores
487+
llvm::IRBuilder<> B(pSt);
488+
for (uint64_t el = 0; el < SourceType->getVectorNumElements(); ++el) {
489+
llvm::Value *destPointer = B.CreateGEP(pSt->getPointerOperand(),
490+
{B.getInt32(0), B.getInt32(el)});
491+
llvm::Value *source =
492+
B.CreateExtractElement(pSt->getValueOperand(), el);
493+
B.CreateStore(source, destPointer);
494+
}
495+
pI->eraseFromParent();
496+
}
497+
}
498+
}
499+
436500
} // namespace
437501

438502
using namespace llvm;

lib/DxilPIXPasses/DxilShaderAccessTracking.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,9 @@ bool DxilShaderAccessTracking::runOnModule(Module &M) {
10521052
// Done with these guys:
10531053
m_GEPOperandAsInstructionDestroyers.clear();
10541054

1055+
if (OSOverride != nullptr && !Modified) {
1056+
*OSOverride << "\nNotModified\n";
1057+
}
10551058
return Modified;
10561059
}
10571060
char DxilShaderAccessTracking::ID = 0;

0 commit comments

Comments
 (0)