Skip to content

Commit afebf8d

Browse files
committed
Merge remote-tracking branch 'msft/main' into ser_hlslmake_patch
2 parents 46e3623 + 0ffd60a commit afebf8d

127 files changed

Lines changed: 15015 additions & 5122 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,
@@ -893,8 +898,11 @@ enum class OpCode : unsigned {
893898
GetDimensions = 72, // gets texture size information
894899
RawBufferLoad = 139, // reads from a raw buffer and structured buffer
895900
RawBufferStore = 140, // writes to a RWByteAddressBuffer or RWStructuredBuffer
896-
TextureLoad = 66, // reads texel data without any filtering or sampling
897-
TextureStore = 67, // reads texel data without any filtering or sampling
901+
RawBufferVectorLoad = 303, // reads from a raw buffer and structured buffer
902+
RawBufferVectorStore =
903+
304, // writes to a RWByteAddressBuffer or RWStructuredBuffer
904+
TextureLoad = 66, // reads texel data without any filtering or sampling
905+
TextureStore = 67, // reads texel data without any filtering or sampling
898906
TextureStoreSample = 225, // stores texel data at specified sample index
899907

900908
// Sampler Feedback
@@ -1039,7 +1047,7 @@ enum class OpCode : unsigned {
10391047
NumOpCodes_Dxil_1_7 = 226,
10401048
NumOpCodes_Dxil_1_8 = 258,
10411049

1042-
NumOpCodes = 303 // exclusive last value of enumeration
1050+
NumOpCodes = 305 // exclusive last value of enumeration
10431051
};
10441052
// OPCODE-ENUM:END
10451053

@@ -1273,6 +1281,8 @@ enum class OpCodeClass : unsigned {
12731281
GetDimensions,
12741282
RawBufferLoad,
12751283
RawBufferStore,
1284+
RawBufferVectorLoad,
1285+
RawBufferVectorStore,
12761286
TextureLoad,
12771287
TextureStore,
12781288
TextureStoreSample,
@@ -1351,7 +1361,7 @@ enum class OpCodeClass : unsigned {
13511361
NumOpClasses_Dxil_1_7 = 153,
13521362
NumOpClasses_Dxil_1_8 = 174,
13531363

1354-
NumOpClasses = 177 // exclusive last value of enumeration
1364+
NumOpClasses = 179 // exclusive last value of enumeration
13551365
};
13561366
// OPCODECLASS-ENUM:END
13571367

@@ -1410,6 +1420,12 @@ const unsigned kRawBufferLoadElementOffsetOpIdx = 3;
14101420
const unsigned kRawBufferLoadMaskOpIdx = 4;
14111421
const unsigned kRawBufferLoadAlignmentOpIdx = 5;
14121422

1423+
// RawBufferVectorLoad.
1424+
const unsigned kRawBufferVectorLoadHandleOpIdx = 1;
1425+
const unsigned kRawBufferVectorLoadIndexOpIdx = 2;
1426+
const unsigned kRawBufferVectorLoadElementOffsetOpIdx = 3;
1427+
const unsigned kRawBufferVectorLoadAlignmentOpIdx = 4;
1428+
14131429
// RawBufferStore
14141430
const unsigned kRawBufferStoreHandleOpIdx = 1;
14151431
const unsigned kRawBufferStoreIndexOpIdx = 2;
@@ -1419,7 +1435,14 @@ const unsigned kRawBufferStoreVal1OpIdx = 5;
14191435
const unsigned kRawBufferStoreVal2OpIdx = 6;
14201436
const unsigned kRawBufferStoreVal3OpIdx = 7;
14211437
const unsigned kRawBufferStoreMaskOpIdx = 8;
1422-
const unsigned kRawBufferStoreAlignmentOpIdx = 8;
1438+
const unsigned kRawBufferStoreAlignmentOpIdx = 9;
1439+
1440+
// RawBufferVectorStore
1441+
const unsigned kRawBufferVectorStoreHandleOpIdx = 1;
1442+
const unsigned kRawBufferVectorStoreIndexOpIdx = 2;
1443+
const unsigned kRawBufferVectorStoreElementOffsetOpIdx = 3;
1444+
const unsigned kRawBufferVectorStoreValOpIdx = 4;
1445+
const unsigned kRawBufferVectorStoreAlignmentOpIdx = 5;
14231446

14241447
// TextureStore.
14251448
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;
@@ -8887,5 +8923,98 @@ struct DxilInst_HitObject_MakeNop {
88878923
// Metadata
88888924
bool requiresUniformInputs() const { return false; }
88898925
};
8926+
8927+
/// This instruction reads from a raw buffer and structured buffer
8928+
struct DxilInst_RawBufferVectorLoad {
8929+
llvm::Instruction *Instr;
8930+
// Construction and identification
8931+
DxilInst_RawBufferVectorLoad(llvm::Instruction *pInstr) : Instr(pInstr) {}
8932+
operator bool() const {
8933+
return hlsl::OP::IsDxilOpFuncCallInst(
8934+
Instr, hlsl::OP::OpCode::RawBufferVectorLoad);
8935+
}
8936+
// Validation support
8937+
bool isAllowed() const { return true; }
8938+
bool isArgumentListValid() const {
8939+
if (5 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
8940+
return false;
8941+
return true;
8942+
}
8943+
// Metadata
8944+
bool requiresUniformInputs() const { return false; }
8945+
// Operand indexes
8946+
enum OperandIdx {
8947+
arg_buf = 1,
8948+
arg_index = 2,
8949+
arg_elementOffset = 3,
8950+
arg_alignment = 4,
8951+
};
8952+
// Accessors
8953+
llvm::Value *get_buf() const { return Instr->getOperand(1); }
8954+
void set_buf(llvm::Value *val) { Instr->setOperand(1, val); }
8955+
llvm::Value *get_index() const { return Instr->getOperand(2); }
8956+
void set_index(llvm::Value *val) { Instr->setOperand(2, val); }
8957+
llvm::Value *get_elementOffset() const { return Instr->getOperand(3); }
8958+
void set_elementOffset(llvm::Value *val) { Instr->setOperand(3, val); }
8959+
llvm::Value *get_alignment() const { return Instr->getOperand(4); }
8960+
void set_alignment(llvm::Value *val) { Instr->setOperand(4, val); }
8961+
int32_t get_alignment_val() const {
8962+
return (int32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(4))
8963+
->getZExtValue());
8964+
}
8965+
void set_alignment_val(int32_t val) {
8966+
Instr->setOperand(4, llvm::Constant::getIntegerValue(
8967+
llvm::IntegerType::get(Instr->getContext(), 32),
8968+
llvm::APInt(32, (uint64_t)val)));
8969+
}
8970+
};
8971+
8972+
/// This instruction writes to a RWByteAddressBuffer or RWStructuredBuffer
8973+
struct DxilInst_RawBufferVectorStore {
8974+
llvm::Instruction *Instr;
8975+
// Construction and identification
8976+
DxilInst_RawBufferVectorStore(llvm::Instruction *pInstr) : Instr(pInstr) {}
8977+
operator bool() const {
8978+
return hlsl::OP::IsDxilOpFuncCallInst(
8979+
Instr, hlsl::OP::OpCode::RawBufferVectorStore);
8980+
}
8981+
// Validation support
8982+
bool isAllowed() const { return true; }
8983+
bool isArgumentListValid() const {
8984+
if (6 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
8985+
return false;
8986+
return true;
8987+
}
8988+
// Metadata
8989+
bool requiresUniformInputs() const { return false; }
8990+
// Operand indexes
8991+
enum OperandIdx {
8992+
arg_uav = 1,
8993+
arg_index = 2,
8994+
arg_elementOffset = 3,
8995+
arg_value0 = 4,
8996+
arg_alignment = 5,
8997+
};
8998+
// Accessors
8999+
llvm::Value *get_uav() const { return Instr->getOperand(1); }
9000+
void set_uav(llvm::Value *val) { Instr->setOperand(1, val); }
9001+
llvm::Value *get_index() const { return Instr->getOperand(2); }
9002+
void set_index(llvm::Value *val) { Instr->setOperand(2, val); }
9003+
llvm::Value *get_elementOffset() const { return Instr->getOperand(3); }
9004+
void set_elementOffset(llvm::Value *val) { Instr->setOperand(3, val); }
9005+
llvm::Value *get_value0() const { return Instr->getOperand(4); }
9006+
void set_value0(llvm::Value *val) { Instr->setOperand(4, val); }
9007+
llvm::Value *get_alignment() const { return Instr->getOperand(5); }
9008+
void set_alignment(llvm::Value *val) { Instr->setOperand(5, val); }
9009+
int32_t get_alignment_val() const {
9010+
return (int32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(5))
9011+
->getZExtValue());
9012+
}
9013+
void set_alignment_val(int32_t val) {
9014+
Instr->setOperand(5, llvm::Constant::getIntegerValue(
9015+
llvm::IntegerType::get(Instr->getContext(), 32),
9016+
llvm::APInt(32, (uint64_t)val)));
9017+
}
9018+
};
88909019
// INSTR-HELPER:END
88919020
} // 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)