Skip to content

Commit 6d96524

Browse files
committed
Merge remote-tracking branch 'msft/main' into ser_dxilreorder_patch
2 parents 6237780 + c940161 commit 6d96524

133 files changed

Lines changed: 15527 additions & 5218 deletions

File tree

Some content is hidden

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

.github/CODEOWNERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
* @microsoft/hlsl-release
1+
# Uncomment the next line in release branches after ask-mode begins
2+
# * @microsoft/hlsl-release

CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ if(POLICY CMP0022)
1717
cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required
1818
endif()
1919

20-
if (POLICY CMP0051)
21-
# CMake 3.1 and higher include generator expressions of the form
22-
# $<TARGETLIB:obj> in the SOURCES property. These need to be
23-
# stripped everywhere that access the SOURCES property, so we just
24-
# defer to the OLD behavior of not including generator expressions
25-
# in the output for now.
26-
cmake_policy(SET CMP0051 OLD)
27-
endif()
28-
2920
if(CMAKE_VERSION VERSION_LESS 3.1.20141117)
3021
set(cmake_3_2_USES_TERMINAL)
3122
else()

CONTRIBUTING.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,32 @@ Before submitting a feature or substantial code contribution please discuss it w
4040

4141
### Coding guidelines
4242

43-
The coding, style, and general engineering guidelines follow those described in the docs/CodingStandards.rst. For additional guidelines in code specific to HLSL, see the docs/HLSLChanges.rst file.
43+
The coding, style, and general engineering guidelines follow those described in the [LLVM Coding Standards](docs/CodingStandards.rst). For additional guidelines in code specific to HLSL, see the [HLSL Changes](docs/HLSLChanges.rst) docs.
4444

4545
DXC has adopted a clang-format requirement for all incoming changes to C and C++ files. PRs to DXC should have the *changed code* clang formatted to the LLVM style, and leave the remaining portions of the file unchanged. This can be done using the `git-clang-format` tool or IDE driven workflows. A GitHub action will run on all PRs to validate that the change is properly formatted.
4646

47+
#### Applying LLVM Standards
48+
49+
All new code contributed to DXC should follow the LLVM coding standards.
50+
51+
Note that the LLVM Coding Standards have a golden rule:
52+
53+
> **If you are extending, enhancing, or bug fixing already implemented code, use the style that is already being used so that the source is uniform and easy to follow.**
54+
55+
The golden rule should continue to be applied to places where DXC is self-consistent. A good example is DXC's common use of `PascalCase` instead of `camelCase` for APIs in some parts of the HLSL implementation. In any place where DXC is not self-consistent new code should follow the LLVM Coding Standard.
56+
57+
A good secondary rule to follow is:
58+
59+
> **When in doubt, follow LLVM.**
60+
61+
Adopting LLVM's coding standards provides a consistent set of rules and guidelines to hold all contributions to. This allows patch authors to clearly understand the expectations placed on contributions, and allows reviewers to have a bar to measure contributions against. Aligning with LLVM by default ensures the path of least resistance for everyone.
62+
63+
Since many of the LLVM Coding Standards are not enforced automatically we rely on code reviews to provide feedback and ensure contributions align with the expected coding standards. Since we rely on reviewers for enforcement and humans make mistakes, please keep in mind:
64+
65+
> **Code review is a conversation.**
66+
67+
It is completely reasonable for a patch author to question feedback and provide additional context about why something was done the way it was. Reviewers often see narrow slices in diffs rather than the full context of a file or part of the compiler, so they may not always provide perfect feedback. This is especially true with the application of the "golden rule" since it depends on understanding a wider context.
68+
4769
### Documenting Pull Requests
4870

4971
Pull request descriptions should have the following format:

docs/DXIL.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ DXIL uses 32-bit pointers in its representation.
225225
Out-of-bounds behavior
226226
----------------------
227227

228-
Indexable thread-local accesses are done via LLVM pointer and have C-like OOB semantics.
229-
Groupshared accesses are done via LLVM pointer too. The origin of a groupshared pointer must be a single TGSM allocation.
230-
If a groupshared pointer uses in-bound GEP instruction, it should not OOB. The behavior for an OOB access for in-bound pointer is undefined.
231-
For groupshared pointer from regular GEP, OOB will has same behavior as DXBC. Loads return 0 for OOB accesses; OOB stores are silently dropped.
228+
Indexable thread-local accesses are done via LLVM pointers and have C-like OOB semantics.
229+
Groupshared accesses are done via LLVM pointers too. The origin of a groupshared pointer must be a single TGSM allocation.
230+
If a groupshared pointer uses an in-bound GEP instruction, it should not OOB. The behavior for an OOB access for in-bound pointer is undefined.
231+
For a groupshared pointer from regular GEP, OOB will have the same behavior as DXBC. Loads return 0 for OOB accesses; OOB stores are silently dropped.
232232

233233
Resource accesses keeps the same out-of-bounds behavior as DXBC. Loads return 0 for OOB accesses; OOB stores are silently dropped.
234234

@@ -3294,9 +3294,9 @@ Modules and Linking
32943294
===================
32953295

32963296
HLSL has linking capabilities to enable third-party libraries. The linking step happens before shader DXIL is given to the driver compilers.
3297-
Experimental library generation is added in DXIL1.1. A library could be created by compile with lib_6_1 profile.
3298-
A library is a dxil container like the compile result of other shader profiles. The difference is library will keep information for linking like resource link info and entry function signatures.
3299-
Library support is not part of DXIL spec. Only requirement is linked shader must be valid DXIL.
3297+
Experimental library generation is added in DXIL1.1. A library could be created by compiling with the lib_6_1 profile.
3298+
A library is a dxil container like the compile result of other shader profiles. The difference is a library will keep information for linking like resource link info and entry function signatures.
3299+
Library support is not part of the DXIL spec. The only requirement is that the linked shader must be valid DXIL.
33003300

33013301

33023302
Additional Notes

docs/SPIR-V.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,12 @@ Supported extensions
315315
* SPV_KHR_fragment_shader_barycentric
316316
* SPV_KHR_physical_storage_buffer
317317
* SPV_KHR_vulkan_memory_model
318+
* SPV_KHR_compute_shader_derivatives
318319
* SPV_NV_compute_shader_derivatives
319320
* SPV_KHR_maximal_reconvergence
320321
* SPV_KHR_float_controls
321322
* SPV_NV_shader_subgroup_partitioned
323+
* SPV_KHR_quad_control
322324

323325
Vulkan specific attributes
324326
--------------------------
@@ -4007,6 +4009,8 @@ Quad ``QuadReadAcrossX()`` ``OpGroupNonUniformQuadSwap``
40074009
Quad ``QuadReadAcrossY()`` ``OpGroupNonUniformQuadSwap``
40084010
Quad ``QuadReadAcrossDiagonal()`` ``OpGroupNonUniformQuadSwap``
40094011
Quad ``QuadReadLaneAt()`` ``OpGroupNonUniformQuadBroadcast``
4012+
Quad ``QuadAny()`` ``OpGroupNonUniformQuadAnyKHR``
4013+
Quad ``QuadAll()`` ``OpGroupNonUniformQuadAllKHR``
40104014
N/A ``WaveMatch()`` ``OpGroupNonUniformPartitionNV``
40114015
Multiprefix ``WaveMultiPrefixSum()`` ``OpGroupNonUniform*Add`` ``PartitionedExclusiveScanNV``
40124016
Multiprefix ``WaveMultiPrefixProduct()`` ``OpGroupNonUniform*Mul`` ``PartitionedExclusiveScanNV``
@@ -4015,6 +4019,11 @@ Multiprefix ``WaveMultiPrefixBitOr()`` ``OpGroupNonUniformLogicalOr`` `
40154019
Multiprefix ``WaveMultiPrefixBitXor()`` ``OpGroupNonUniformLogicalXor`` ``PartitionedExclusiveScanNV``
40164020
============= ============================ =================================== ==============================
40174021

4022+
``QuadAny`` and ``QuadAll`` will use the ``OpGroupNonUniformQuadAnyKHR`` and
4023+
``OpGroupNonUniformQuadAllKHR`` instructions if the ``SPV_KHR_quad_control``
4024+
extension is enabled. If it is not, they will fall back to constructing the
4025+
value using multiple calls to ``OpGroupNonUniformQuadBroadcast``.
4026+
40184027
The Implicit ``vk`` Namespace
40194028
=============================
40204029

include/dxc/DXIL/DxilConstants.h

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ const float kMinMipLodBias = -16.0f;
155155

156156
const unsigned kResRetStatusIndex = 4;
157157

158+
/* <py::lines('OLOAD_DIMS-TEXT')>hctdb_instrhelp.get_max_oload_dims()</py>*/
159+
// OLOAD_DIMS-TEXT:BEGIN
160+
const unsigned kDxilMaxOloadDims = 2;
161+
// OLOAD_DIMS-TEXT:END
162+
158163
enum class ComponentType : uint32_t {
159164
Invalid = 0,
160165
I1,
@@ -894,8 +899,11 @@ enum class OpCode : unsigned {
894899
GetDimensions = 72, // gets texture size information
895900
RawBufferLoad = 139, // reads from a raw buffer and structured buffer
896901
RawBufferStore = 140, // writes to a RWByteAddressBuffer or RWStructuredBuffer
897-
TextureLoad = 66, // reads texel data without any filtering or sampling
898-
TextureStore = 67, // reads texel data without any filtering or sampling
902+
RawBufferVectorLoad = 303, // reads from a raw buffer and structured buffer
903+
RawBufferVectorStore =
904+
304, // writes to a RWByteAddressBuffer or RWStructuredBuffer
905+
TextureLoad = 66, // reads texel data without any filtering or sampling
906+
TextureStore = 67, // reads texel data without any filtering or sampling
899907
TextureStoreSample = 225, // stores texel data at specified sample index
900908

901909
// Sampler Feedback
@@ -1040,7 +1048,7 @@ enum class OpCode : unsigned {
10401048
NumOpCodes_Dxil_1_7 = 226,
10411049
NumOpCodes_Dxil_1_8 = 258,
10421050

1043-
NumOpCodes = 303 // exclusive last value of enumeration
1051+
NumOpCodes = 305 // exclusive last value of enumeration
10441052
};
10451053
// OPCODE-ENUM:END
10461054

@@ -1275,6 +1283,8 @@ enum class OpCodeClass : unsigned {
12751283
GetDimensions,
12761284
RawBufferLoad,
12771285
RawBufferStore,
1286+
RawBufferVectorLoad,
1287+
RawBufferVectorStore,
12781288
TextureLoad,
12791289
TextureStore,
12801290
TextureStoreSample,
@@ -1353,7 +1363,7 @@ enum class OpCodeClass : unsigned {
13531363
NumOpClasses_Dxil_1_7 = 153,
13541364
NumOpClasses_Dxil_1_8 = 174,
13551365

1356-
NumOpClasses = 178 // exclusive last value of enumeration
1366+
NumOpClasses = 180 // exclusive last value of enumeration
13571367
};
13581368
// OPCODECLASS-ENUM:END
13591369

@@ -1412,6 +1422,12 @@ const unsigned kRawBufferLoadElementOffsetOpIdx = 3;
14121422
const unsigned kRawBufferLoadMaskOpIdx = 4;
14131423
const unsigned kRawBufferLoadAlignmentOpIdx = 5;
14141424

1425+
// RawBufferVectorLoad.
1426+
const unsigned kRawBufferVectorLoadHandleOpIdx = 1;
1427+
const unsigned kRawBufferVectorLoadIndexOpIdx = 2;
1428+
const unsigned kRawBufferVectorLoadElementOffsetOpIdx = 3;
1429+
const unsigned kRawBufferVectorLoadAlignmentOpIdx = 4;
1430+
14151431
// RawBufferStore
14161432
const unsigned kRawBufferStoreHandleOpIdx = 1;
14171433
const unsigned kRawBufferStoreIndexOpIdx = 2;
@@ -1421,7 +1437,14 @@ const unsigned kRawBufferStoreVal1OpIdx = 5;
14211437
const unsigned kRawBufferStoreVal2OpIdx = 6;
14221438
const unsigned kRawBufferStoreVal3OpIdx = 7;
14231439
const unsigned kRawBufferStoreMaskOpIdx = 8;
1424-
const unsigned kRawBufferStoreAlignmentOpIdx = 8;
1440+
const unsigned kRawBufferStoreAlignmentOpIdx = 9;
1441+
1442+
// RawBufferVectorStore
1443+
const unsigned kRawBufferVectorStoreHandleOpIdx = 1;
1444+
const unsigned kRawBufferVectorStoreIndexOpIdx = 2;
1445+
const unsigned kRawBufferVectorStoreElementOffsetOpIdx = 3;
1446+
const unsigned kRawBufferVectorStoreValOpIdx = 4;
1447+
const unsigned kRawBufferVectorStoreAlignmentOpIdx = 5;
14251448

14261449
// TextureStore.
14271450
const unsigned kTextureStoreHandleOpIdx = 1;

include/dxc/DXIL/DxilInstructions.h

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,42 @@ struct LlvmInst_VAArg {
645645
bool isAllowed() const { return false; }
646646
};
647647

648+
/// This instruction extracts from vector
649+
struct LlvmInst_ExtractElement {
650+
llvm::Instruction *Instr;
651+
// Construction and identification
652+
LlvmInst_ExtractElement(llvm::Instruction *pInstr) : Instr(pInstr) {}
653+
operator bool() const {
654+
return Instr->getOpcode() == llvm::Instruction::ExtractElement;
655+
}
656+
// Validation support
657+
bool isAllowed() const { return true; }
658+
};
659+
660+
/// This instruction inserts into vector
661+
struct LlvmInst_InsertElement {
662+
llvm::Instruction *Instr;
663+
// Construction and identification
664+
LlvmInst_InsertElement(llvm::Instruction *pInstr) : Instr(pInstr) {}
665+
operator bool() const {
666+
return Instr->getOpcode() == llvm::Instruction::InsertElement;
667+
}
668+
// Validation support
669+
bool isAllowed() const { return true; }
670+
};
671+
672+
/// This instruction Shuffle two vectors
673+
struct LlvmInst_ShuffleVector {
674+
llvm::Instruction *Instr;
675+
// Construction and identification
676+
LlvmInst_ShuffleVector(llvm::Instruction *pInstr) : Instr(pInstr) {}
677+
operator bool() const {
678+
return Instr->getOpcode() == llvm::Instruction::ShuffleVector;
679+
}
680+
// Validation support
681+
bool isAllowed() const { return true; }
682+
};
683+
648684
/// This instruction extracts from aggregate
649685
struct LlvmInst_ExtractValue {
650686
llvm::Instruction *Instr;
@@ -8925,5 +8961,98 @@ struct DxilInst_MaybeReorderThread {
89258961
Instr->setOperand(3, val);
89268962
}
89278963
};
8964+
8965+
/// This instruction reads from a raw buffer and structured buffer
8966+
struct DxilInst_RawBufferVectorLoad {
8967+
llvm::Instruction *Instr;
8968+
// Construction and identification
8969+
DxilInst_RawBufferVectorLoad(llvm::Instruction *pInstr) : Instr(pInstr) {}
8970+
operator bool() const {
8971+
return hlsl::OP::IsDxilOpFuncCallInst(
8972+
Instr, hlsl::OP::OpCode::RawBufferVectorLoad);
8973+
}
8974+
// Validation support
8975+
bool isAllowed() const { return true; }
8976+
bool isArgumentListValid() const {
8977+
if (5 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
8978+
return false;
8979+
return true;
8980+
}
8981+
// Metadata
8982+
bool requiresUniformInputs() const { return false; }
8983+
// Operand indexes
8984+
enum OperandIdx {
8985+
arg_buf = 1,
8986+
arg_index = 2,
8987+
arg_elementOffset = 3,
8988+
arg_alignment = 4,
8989+
};
8990+
// Accessors
8991+
llvm::Value *get_buf() const { return Instr->getOperand(1); }
8992+
void set_buf(llvm::Value *val) { Instr->setOperand(1, val); }
8993+
llvm::Value *get_index() const { return Instr->getOperand(2); }
8994+
void set_index(llvm::Value *val) { Instr->setOperand(2, val); }
8995+
llvm::Value *get_elementOffset() const { return Instr->getOperand(3); }
8996+
void set_elementOffset(llvm::Value *val) { Instr->setOperand(3, val); }
8997+
llvm::Value *get_alignment() const { return Instr->getOperand(4); }
8998+
void set_alignment(llvm::Value *val) { Instr->setOperand(4, val); }
8999+
int32_t get_alignment_val() const {
9000+
return (int32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(4))
9001+
->getZExtValue());
9002+
}
9003+
void set_alignment_val(int32_t val) {
9004+
Instr->setOperand(4, llvm::Constant::getIntegerValue(
9005+
llvm::IntegerType::get(Instr->getContext(), 32),
9006+
llvm::APInt(32, (uint64_t)val)));
9007+
}
9008+
};
9009+
9010+
/// This instruction writes to a RWByteAddressBuffer or RWStructuredBuffer
9011+
struct DxilInst_RawBufferVectorStore {
9012+
llvm::Instruction *Instr;
9013+
// Construction and identification
9014+
DxilInst_RawBufferVectorStore(llvm::Instruction *pInstr) : Instr(pInstr) {}
9015+
operator bool() const {
9016+
return hlsl::OP::IsDxilOpFuncCallInst(
9017+
Instr, hlsl::OP::OpCode::RawBufferVectorStore);
9018+
}
9019+
// Validation support
9020+
bool isAllowed() const { return true; }
9021+
bool isArgumentListValid() const {
9022+
if (6 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
9023+
return false;
9024+
return true;
9025+
}
9026+
// Metadata
9027+
bool requiresUniformInputs() const { return false; }
9028+
// Operand indexes
9029+
enum OperandIdx {
9030+
arg_uav = 1,
9031+
arg_index = 2,
9032+
arg_elementOffset = 3,
9033+
arg_value0 = 4,
9034+
arg_alignment = 5,
9035+
};
9036+
// Accessors
9037+
llvm::Value *get_uav() const { return Instr->getOperand(1); }
9038+
void set_uav(llvm::Value *val) { Instr->setOperand(1, val); }
9039+
llvm::Value *get_index() const { return Instr->getOperand(2); }
9040+
void set_index(llvm::Value *val) { Instr->setOperand(2, val); }
9041+
llvm::Value *get_elementOffset() const { return Instr->getOperand(3); }
9042+
void set_elementOffset(llvm::Value *val) { Instr->setOperand(3, val); }
9043+
llvm::Value *get_value0() const { return Instr->getOperand(4); }
9044+
void set_value0(llvm::Value *val) { Instr->setOperand(4, val); }
9045+
llvm::Value *get_alignment() const { return Instr->getOperand(5); }
9046+
void set_alignment(llvm::Value *val) { Instr->setOperand(5, val); }
9047+
int32_t get_alignment_val() const {
9048+
return (int32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(5))
9049+
->getZExtValue());
9050+
}
9051+
void set_alignment_val(int32_t val) {
9052+
Instr->setOperand(5, llvm::Constant::getIntegerValue(
9053+
llvm::IntegerType::get(Instr->getContext(), 32),
9054+
llvm::APInt(32, (uint64_t)val)));
9055+
}
9056+
};
89289057
// INSTR-HELPER:END
89299058
} // namespace hlsl

include/dxc/DXIL/DxilMetadataHelper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ class DxilMDHelper {
427427
// Dxil version.
428428
void EmitDxilVersion(unsigned Major, unsigned Minor);
429429
void LoadDxilVersion(unsigned &Major, unsigned &Minor);
430+
static bool LoadDxilVersion(const llvm::Module *pModule, unsigned &Major,
431+
unsigned &Minor);
430432

431433
// Validator version.
432434
void EmitValidatorVersion(unsigned Major, unsigned Minor);

0 commit comments

Comments
 (0)