Skip to content

Commit 9abecc6

Browse files
committed
Merge branch 'main' of github.com:microsoft/DirectXShaderCompiler into devshFixes
2 parents fc05d30 + 0877737 commit 9abecc6

File tree

114 files changed

+1717
-1673
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+1717
-1673
lines changed

appveyor.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ test_script:
4747
- ps: utils\appveyor\appveyor_test.ps1
4848
- cmd: call utils\hct\hcttest -rel clang
4949
- sh: ./bin/dxc --help
50-
- sh: ./bin/dxc -T ps_6_0 ../tools/clang/test/CodeGenSPIRV/passthru-ps.hlsl2spv
51-
- sh: ./bin/dxc -T ps_6_0 -Fo passthru-ps.dxil ../tools/clang/test/CodeGenSPIRV/passthru-ps.hlsl2spv
52-
- sh: ./bin/dxc -T ps_6_0 -Fo passthru-ps.spv ../tools/clang/test/CodeGenSPIRV/passthru-ps.hlsl2spv -spirv
50+
- sh: ./bin/dxc -T ps_6_0 ../tools/clang/test/CodeGenSPIRV_Lit/passthru-ps.hlsl2spv
51+
- sh: ./bin/dxc -T ps_6_0 -Fo passthru-ps.dxil ../tools/clang/test/CodeGenSPIRV_Lit/passthru-ps.hlsl2spv
52+
- sh: ./bin/dxc -T ps_6_0 -Fo passthru-ps.spv ../tools/clang/test/CodeGenSPIRV_Lit/passthru-ps.hlsl2spv -spirv
5353
- sh: ./tools/clang/unittests/SPIRV/ClangSPIRVTests --spirv-test-root ../tools/clang/test/CodeGenSPIRV/
5454
- sh: ./tools/clang/unittests/HLSL/ClangHLSLTests --HlslDataDir $PWD/../tools/clang/test/HLSL/
5555

lib/DxilDia/DxcPixTypes.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
#include "DxcPixTypes.h"
1515
#include "DxilDiaSession.h"
1616

17+
static CA2W GetTypeNameOrDefault(llvm::DIType *diType) {
18+
auto stringRef = diType->getName();
19+
if (stringRef.empty())
20+
return CA2W("<unnamed>");
21+
return CA2W(stringRef.data());
22+
}
23+
1724
HRESULT dxil_debug_info::CreateDxcPixType(
1825
DxcPixDxilDebugInfo *pDxilDebugInfo,
1926
llvm::DIType *diType,
@@ -89,7 +96,9 @@ STDMETHODIMP dxil_debug_info::DxcPixConstType::GetName(
8996
CComBSTR BaseName;
9097
IFR(BaseType->GetName(&BaseName));
9198

92-
*Name = CComBSTR((L"const " + std::wstring(BaseName)).c_str()).Detach();
99+
*Name =
100+
CComBSTR((L"const " + std::wstring(BaseName)).c_str())
101+
.Detach();
93102
return S_OK;
94103
}
95104

@@ -111,7 +120,8 @@ STDMETHODIMP dxil_debug_info::DxcPixConstType::UnAlias(
111120
STDMETHODIMP dxil_debug_info::DxcPixTypedefType::GetName(
112121
_Outptr_result_z_ BSTR *Name)
113122
{
114-
*Name = CComBSTR(CA2W(m_pType->getName().data())).Detach();
123+
*Name =
124+
CComBSTR(GetTypeNameOrDefault(m_pType)).Detach();
115125
return S_OK;
116126
}
117127

@@ -133,7 +143,8 @@ STDMETHODIMP dxil_debug_info::DxcPixTypedefType::UnAlias(
133143
STDMETHODIMP dxil_debug_info::DxcPixScalarType::GetName(
134144
_Outptr_result_z_ BSTR *Name)
135145
{
136-
*Name = CComBSTR(CA2W(m_pType->getName().data())).Detach();
146+
*Name =
147+
CComBSTR(GetTypeNameOrDefault(m_pType)).Detach();
137148
return S_OK;
138149
}
139150

@@ -155,7 +166,7 @@ STDMETHODIMP dxil_debug_info::DxcPixScalarType::UnAlias(
155166
STDMETHODIMP dxil_debug_info::DxcPixArrayType::GetName(
156167
_Outptr_result_z_ BSTR *Name)
157168
{
158-
CComBSTR name(CA2W(m_pBaseType->getName().data()));
169+
CComBSTR name(GetTypeNameOrDefault(m_pBaseType));
159170
name.Append(L"[]");
160171
*Name = name.Detach();
161172
return S_OK;
@@ -225,7 +236,8 @@ STDMETHODIMP dxil_debug_info::DxcPixArrayType::GetElementType(
225236
STDMETHODIMP dxil_debug_info::DxcPixStructType::GetName(
226237
_Outptr_result_z_ BSTR *Name)
227238
{
228-
*Name = CComBSTR(CA2W(m_pStruct->getName().data())).Detach();
239+
*Name =
240+
CComBSTR(GetTypeNameOrDefault(m_pStruct)).Detach();
229241
return S_OK;
230242
}
231243

@@ -357,7 +369,8 @@ STDMETHODIMP dxil_debug_info::DxcPixStructType::GetBaseType(
357369
STDMETHODIMP dxil_debug_info::DxcPixStructField::GetName(
358370
_Outptr_result_z_ BSTR *Name)
359371
{
360-
*Name = CComBSTR(CA2W(m_pField->getName().data())).Detach();
372+
*Name =
373+
CComBSTR(GetTypeNameOrDefault(m_pField)).Detach();
361374
return S_OK;
362375
}
363376

lib/DxilPIXPasses/DxilAnnotateWithVirtualRegister.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,33 @@ bool DxilAnnotateWithVirtualRegister::runOnModule(llvm::Module &M) {
133133

134134
auto instrumentableFunctions = PIXPassHelpers::GetAllInstrumentableFunctions(*m_DM);
135135

136-
for (auto * F : instrumentableFunctions) {
136+
for (auto *F : instrumentableFunctions) {
137+
for (auto &block : F->getBasicBlockList()) {
138+
for (llvm::Instruction &I : block.getInstList()) {
139+
AnnotateValues(&I);
140+
}
141+
}
142+
}
143+
144+
for (auto *F : instrumentableFunctions) {
145+
for (auto &block : F->getBasicBlockList()) {
146+
for (llvm::Instruction &I : block.getInstList()) {
147+
AnnotateStore(&I);
148+
}
149+
}
150+
}
151+
152+
for (auto *F : instrumentableFunctions) {
137153
int InstructionRangeStart = InstNum;
138154
int InstructionRangeEnd = InstNum;
139155
for (auto &block : F->getBasicBlockList()) {
140156
for (llvm::Instruction &I : block.getInstList()) {
157+
// If the instruction is part of the debug value instrumentation added by this pass,
158+
// it doesn't need to be instrumented for the PIX user.
159+
uint32_t unused1, unused2;
160+
if (auto *Alloca = llvm::dyn_cast<llvm::AllocaInst>(&I))
161+
if (PixAllocaReg::FromInst(Alloca, &unused1, &unused2))
162+
continue;
141163
if (!llvm::isa<llvm::DbgDeclareInst>(&I)) {
142164
pix_dxil::PixDxilInstNum::AddMD(M.getContext(), &I, InstNum++);
143165
InstructionRangeEnd = InstNum;
@@ -163,22 +185,6 @@ bool DxilAnnotateWithVirtualRegister::runOnModule(llvm::Module &M) {
163185
*OSOverride << "\nInstructionCount:" << InstNum << "\n";
164186
}
165187

166-
for (auto * F : instrumentableFunctions) {
167-
for (auto &block : F->getBasicBlockList()) {
168-
for (llvm::Instruction &I : block.getInstList()) {
169-
AnnotateValues(&I);
170-
}
171-
}
172-
}
173-
174-
for (auto * F : instrumentableFunctions) {
175-
for (auto &block : F->getBasicBlockList()) {
176-
for (llvm::Instruction &I : block.getInstList()) {
177-
AnnotateStore(&I);
178-
}
179-
}
180-
}
181-
182188
m_DM = nullptr;
183189
return m_uVReg > 0;
184190
}

lib/DxilPIXPasses/DxilDebugInstrumentation.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ class DxilDebugInstrumentation : public ModulePass {
212212
unsigned InstanceId;
213213
} VertexShader;
214214
};
215+
unsigned m_FirstInstruction = 0;
216+
unsigned m_LastInstruction = static_cast<unsigned>(-1);
215217

216218
uint64_t m_UAVSize = 1024 * 1024;
217219
struct PerFunctionValues
@@ -290,6 +292,9 @@ class DxilDebugInstrumentation : public ModulePass {
290292
};
291293

292294
void DxilDebugInstrumentation::applyOptions(PassOptions O) {
295+
GetPassOptionUnsigned(O, "FirstInstruction", &m_FirstInstruction, 0);
296+
GetPassOptionUnsigned(O, "LastInstruction", &m_LastInstruction,
297+
static_cast<unsigned>(-1));
293298
GetPassOptionUnsigned(O, "parameter0", &m_Parameters.Parameters[0], 0);
294299
GetPassOptionUnsigned(O, "parameter1", &m_Parameters.Parameters[1], 0);
295300
GetPassOptionUnsigned(O, "parameter2", &m_Parameters.Parameters[2], 0);
@@ -1008,7 +1013,13 @@ bool DxilDebugInstrumentation::RunOnFunction(
10081013
for (inst_iterator I = inst_begin(entryFunction),
10091014
E = inst_end(entryFunction);
10101015
I != E; ++I) {
1011-
AllInstructions.push_back(&*I);
1016+
std::uint32_t InstructionNumber;
1017+
if (pix_dxil::PixDxilInstNum::FromInst(&*I, &InstructionNumber)) {
1018+
if (InstructionNumber < m_FirstInstruction ||
1019+
InstructionNumber >= m_LastInstruction)
1020+
continue;
1021+
AllInstructions.push_back(&*I);
1022+
}
10121023
}
10131024

10141025
// Branchless instrumentation requires taking care of a few things:
@@ -1121,6 +1132,8 @@ bool DxilDebugInstrumentation::RunOnFunction(
11211132
if (!pix_dxil::PixDxilInstNum::FromInst(ValueNPhi.Phi, &InstNum)) {
11221133
continue;
11231134
}
1135+
if (InstNum < m_FirstInstruction || InstNum >= m_LastInstruction)
1136+
continue;
11241137

11251138
BuilderContext BC{M, DM, Ctx, HlslOP, Builder};
11261139
addStepDebugEntryValue(BC, InstNum, ValueNPhi.Val, RegNum,

tools/clang/include/clang/SPIRV/FeatureManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ enum class Extension {
4343
EXT_descriptor_indexing,
4444
EXT_fragment_fully_covered,
4545
EXT_fragment_invocation_density,
46+
EXT_fragment_shader_interlock,
4647
EXT_mesh_shader,
4748
EXT_shader_stencil_export,
4849
EXT_shader_viewport_index_layer,

tools/clang/lib/SPIRV/CapabilityVisitor.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ void CapabilityVisitor::addExtension(Extension ext, llvm::StringRef target,
2323
spvBuilder.requireExtension(featureManager.getExtensionName(ext), loc);
2424
}
2525

26+
bool CapabilityVisitor::addExtensionAndCapabilitiesIfEnabled(
27+
Extension ext, llvm::ArrayRef<spv::Capability> capabilities) {
28+
if (!featureManager.isExtensionEnabled(ext)) {
29+
return false;
30+
}
31+
32+
addExtension(ext, "", {});
33+
34+
for (auto cap : capabilities) {
35+
addCapability(cap);
36+
}
37+
return true;
38+
}
39+
2640
void CapabilityVisitor::addCapability(spv::Capability cap, SourceLocation loc) {
2741
if (cap != spv::Capability::Max) {
2842
spvBuilder.requireCapability(cap, loc);
@@ -214,18 +228,6 @@ void CapabilityVisitor::addCapabilityForType(const SpirvType *type,
214228
for (auto field : structType->getFields())
215229
addCapabilityForType(field.type, loc, sc);
216230
}
217-
// AccelerationStructureTypeNV and RayQueryTypeKHR type
218-
// Note: Because AccelerationStructureType can be provided by both
219-
// SPV_KHR_ray_query and SPV_{NV,KHR}_ray_tracing extensions, this logic will
220-
// result in SPV_KHR_ray_query being unnecessarily required in some cases. If
221-
// this is an issue in future (more devices are identified that support
222-
// ray_tracing but not ray_query), then we should consider addressing this
223-
// interaction with a spirv-opt pass instead.
224-
else if (isa<AccelerationStructureTypeNV>(type) ||
225-
isa<RayQueryTypeKHR>(type)) {
226-
addCapability(spv::Capability::RayQueryKHR);
227-
addExtension(Extension::KHR_ray_query, "SPV_KHR_ray_query", {});
228-
}
229231
}
230232

231233
bool CapabilityVisitor::visit(SpirvDecoration *decor) {
@@ -869,6 +871,26 @@ bool CapabilityVisitor::visit(SpirvModule *, Visitor::Phase phase) {
869871
// supports only some capabilities. This list should be expanded to match the
870872
// supported capabilities.
871873
addCapability(spv::Capability::MinLod);
874+
875+
addExtensionAndCapabilitiesIfEnabled(
876+
Extension::EXT_fragment_shader_interlock,
877+
{
878+
spv::Capability::FragmentShaderSampleInterlockEXT,
879+
spv::Capability::FragmentShaderPixelInterlockEXT,
880+
spv::Capability::FragmentShaderShadingRateInterlockEXT,
881+
});
882+
883+
// AccelerationStructureType or RayQueryType can be provided by both
884+
// ray_tracing and ray_query extension. By default, we select ray_query to
885+
// provide it. This is an arbitrary decision. If the user wants avoid one
886+
// extension (lack of support by ex), if can be done by providing the list
887+
// of enabled extensions.
888+
if (!addExtensionAndCapabilitiesIfEnabled(Extension::KHR_ray_query,
889+
{spv::Capability::RayQueryKHR})) {
890+
addExtensionAndCapabilitiesIfEnabled(Extension::KHR_ray_tracing,
891+
{spv::Capability::RayTracingKHR});
892+
}
893+
872894
return true;
873895
}
874896

tools/clang/lib/SPIRV/CapabilityVisitor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ class CapabilityVisitor : public Visitor {
6464
/// the given extension to the SPIR-V module in memory.
6565
void addExtension(Extension ext, llvm::StringRef target, SourceLocation loc);
6666

67+
/// Checks that the given extension is enabled based on command line arguments
68+
/// before calling addExtension and addCapability.
69+
/// Returns `true` if the extension was enabled, `false` otherwise.
70+
bool addExtensionAndCapabilitiesIfEnabled(
71+
Extension ext, llvm::ArrayRef<spv::Capability> capabilities);
72+
6773
/// Checks that the given capability is a valid capability. And if so,
6874
/// utilizes the SpirvBuilder to add the given capability to the SPIR-V module
6975
/// in memory.

tools/clang/lib/SPIRV/FeatureManager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ Extension FeatureManager::getExtensionSymbol(llvm::StringRef name) {
172172
Extension::EXT_fragment_fully_covered)
173173
.Case("SPV_EXT_fragment_invocation_density",
174174
Extension::EXT_fragment_invocation_density)
175+
.Case("SPV_EXT_fragment_shader_interlock",
176+
Extension::EXT_fragment_shader_interlock)
175177
.Case("SPV_EXT_mesh_shader", Extension::EXT_mesh_shader)
176178
.Case("SPV_EXT_shader_stencil_export",
177179
Extension::EXT_shader_stencil_export)
@@ -228,6 +230,8 @@ const char *FeatureManager::getExtensionName(Extension symbol) {
228230
return "SPV_EXT_fragment_fully_covered";
229231
case Extension::EXT_fragment_invocation_density:
230232
return "SPV_EXT_fragment_invocation_density";
233+
case Extension::EXT_fragment_shader_interlock:
234+
return "SPV_EXT_fragment_shader_interlock";
231235
case Extension::EXT_mesh_shader:
232236
return "SPV_EXT_mesh_shader";
233237
case Extension::EXT_shader_stencil_export:

0 commit comments

Comments
 (0)