Skip to content

Commit 782e01c

Browse files
committed
Merge remote-tracking branch 'msft/main' into ser_reorderscope_patch
2 parents a04dc34 + 0ffd60a commit 782e01c

27 files changed

Lines changed: 4659 additions & 1767 deletions

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:

include/dxc/DXIL/DxilConstants.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -898,8 +898,11 @@ enum class OpCode : unsigned {
898898
GetDimensions = 72, // gets texture size information
899899
RawBufferLoad = 139, // reads from a raw buffer and structured buffer
900900
RawBufferStore = 140, // writes to a RWByteAddressBuffer or RWStructuredBuffer
901-
TextureLoad = 66, // reads texel data without any filtering or sampling
902-
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
903906
TextureStoreSample = 225, // stores texel data at specified sample index
904907

905908
// Sampler Feedback
@@ -1044,7 +1047,7 @@ enum class OpCode : unsigned {
10441047
NumOpCodes_Dxil_1_7 = 226,
10451048
NumOpCodes_Dxil_1_8 = 258,
10461049

1047-
NumOpCodes = 303 // exclusive last value of enumeration
1050+
NumOpCodes = 305 // exclusive last value of enumeration
10481051
};
10491052
// OPCODE-ENUM:END
10501053

@@ -1278,6 +1281,8 @@ enum class OpCodeClass : unsigned {
12781281
GetDimensions,
12791282
RawBufferLoad,
12801283
RawBufferStore,
1284+
RawBufferVectorLoad,
1285+
RawBufferVectorStore,
12811286
TextureLoad,
12821287
TextureStore,
12831288
TextureStoreSample,
@@ -1356,7 +1361,7 @@ enum class OpCodeClass : unsigned {
13561361
NumOpClasses_Dxil_1_7 = 153,
13571362
NumOpClasses_Dxil_1_8 = 174,
13581363

1359-
NumOpClasses = 177 // exclusive last value of enumeration
1364+
NumOpClasses = 179 // exclusive last value of enumeration
13601365
};
13611366
// OPCODECLASS-ENUM:END
13621367

@@ -1415,6 +1420,12 @@ const unsigned kRawBufferLoadElementOffsetOpIdx = 3;
14151420
const unsigned kRawBufferLoadMaskOpIdx = 4;
14161421
const unsigned kRawBufferLoadAlignmentOpIdx = 5;
14171422

1423+
// RawBufferVectorLoad.
1424+
const unsigned kRawBufferVectorLoadHandleOpIdx = 1;
1425+
const unsigned kRawBufferVectorLoadIndexOpIdx = 2;
1426+
const unsigned kRawBufferVectorLoadElementOffsetOpIdx = 3;
1427+
const unsigned kRawBufferVectorLoadAlignmentOpIdx = 4;
1428+
14181429
// RawBufferStore
14191430
const unsigned kRawBufferStoreHandleOpIdx = 1;
14201431
const unsigned kRawBufferStoreIndexOpIdx = 2;
@@ -1424,7 +1435,14 @@ const unsigned kRawBufferStoreVal1OpIdx = 5;
14241435
const unsigned kRawBufferStoreVal2OpIdx = 6;
14251436
const unsigned kRawBufferStoreVal3OpIdx = 7;
14261437
const unsigned kRawBufferStoreMaskOpIdx = 8;
1427-
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;
14281446

14291447
// TextureStore.
14301448
const unsigned kTextureStoreHandleOpIdx = 1;

include/dxc/DXIL/DxilInstructions.h

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8923,5 +8923,98 @@ struct DxilInst_HitObject_MakeNop {
89238923
// Metadata
89248924
bool requiresUniformInputs() const { return false; }
89258925
};
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+
};
89269019
// INSTR-HELPER:END
89279020
} // namespace hlsl

include/dxc/HLSL/DxilGenerationPass.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ ModulePass *createResumePassesPass();
8181
FunctionPass *createMatrixBitcastLowerPass();
8282
ModulePass *createDxilCleanupAddrSpaceCastPass();
8383
ModulePass *createDxilRenameResourcesPass();
84+
ModulePass *createDxilScalarizeVectorLoadStoresPass();
8485

8586
void initializeDxilLowerCreateHandleForLibPass(llvm::PassRegistry &);
8687
void initializeDxilAllocateResourcesForLibPass(llvm::PassRegistry &);
@@ -115,6 +116,7 @@ void initializeResumePassesPass(llvm::PassRegistry &);
115116
void initializeMatrixBitcastLowerPassPass(llvm::PassRegistry &);
116117
void initializeDxilCleanupAddrSpaceCastPass(llvm::PassRegistry &);
117118
void initializeDxilRenameResourcesPass(llvm::PassRegistry &);
119+
void initializeDxilScalarizeVectorLoadStoresPass(llvm::PassRegistry &);
118120

119121
ModulePass *createDxilValidateWaveSensitivityPass();
120122
void initializeDxilValidateWaveSensitivityPass(llvm::PassRegistry &);

include/dxc/WinAdapter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
#define _countof(a) (sizeof(a) / sizeof(*(a)))
5252

5353
// If it is GCC, there is no UUID support and we must emulate it.
54-
#ifndef __clang__
54+
// Clang support depends on the -fms-extensions compiler flag.
55+
#if !defined(__clang__) || !defined(_MSC_EXTENSIONS)
5556
#define __EMULATE_UUID 1
5657
#endif // __clang__
5758

include/dxc/dxcapi.internal.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,12 @@ enum LEGAL_INTRINSIC_COMPTYPES {
132132

133133
LICOMPTYPE_HIT_OBJECT = 51,
134134

135+
#ifdef ENABLE_SPIRV_CODEGEN
135136
LICOMPTYPE_VK_BUFFER_POINTER = 52,
136-
137137
LICOMPTYPE_COUNT = 53
138+
#else
139+
LICOMPTYPE_COUNT = 52
140+
#endif
138141
};
139142

140143
static const BYTE IA_SPECIAL_BASE = 0xf0;

lib/DXIL/DxilOperations.cpp

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,6 +2634,24 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
26342634
0,
26352635
{},
26362636
{}}, // Overloads: v
2637+
2638+
// Resources
2639+
{OC::RawBufferVectorLoad,
2640+
"RawBufferVectorLoad",
2641+
OCC::RawBufferVectorLoad,
2642+
"rawBufferVectorLoad",
2643+
Attribute::ReadOnly,
2644+
1,
2645+
{{0x4e7}},
2646+
{{0xe7}}}, // Overloads: hfwidl<hfwidl
2647+
{OC::RawBufferVectorStore,
2648+
"RawBufferVectorStore",
2649+
OCC::RawBufferVectorStore,
2650+
"rawBufferVectorStore",
2651+
Attribute::None,
2652+
1,
2653+
{{0x4e7}},
2654+
{{0xe7}}}, // Overloads: hfwidl<hfwidl
26372655
};
26382656
// OPCODE-OLOADS:END
26392657

@@ -3421,8 +3439,9 @@ void OP::GetMinShaderModelAndMask(OpCode C, bool bWithTranslation,
34213439
}
34223440
return;
34233441
}
3424-
// Instructions: AllocateRayQuery2=258
3425-
if (op == 258) {
3442+
// Instructions: AllocateRayQuery2=258, RawBufferVectorLoad=303,
3443+
// RawBufferVectorStore=304
3444+
if (op == 258 || (303 <= op && op <= 304)) {
34263445
major = 6;
34273446
minor = 9;
34283447
return;
@@ -5777,6 +5796,25 @@ Function *OP::GetOpFunc(OpCode opCode, Type *pOverloadType) {
57775796
A(pV);
57785797
A(pI32);
57795798
break;
5799+
5800+
// Resources
5801+
case OpCode::RawBufferVectorLoad:
5802+
RRT(pETy);
5803+
A(pI32);
5804+
A(pRes);
5805+
A(pI32);
5806+
A(pI32);
5807+
A(pI32);
5808+
break;
5809+
case OpCode::RawBufferVectorStore:
5810+
A(pV);
5811+
A(pI32);
5812+
A(pRes);
5813+
A(pI32);
5814+
A(pI32);
5815+
A(pETy);
5816+
A(pI32);
5817+
break;
57805818
// OPCODE-OLOAD-FUNCS:END
57815819
default:
57825820
DXASSERT(false, "otherwise unhandled case");
@@ -5926,6 +5964,7 @@ llvm::Type *OP::GetOverloadType(OpCode opCode, llvm::Function *F) {
59265964
case OpCode::StoreVertexOutput:
59275965
case OpCode::StorePrimitiveOutput:
59285966
case OpCode::DispatchMesh:
5967+
case OpCode::RawBufferVectorStore:
59295968
if (FT->getNumParams() <= 4)
59305969
return nullptr;
59315970
return FT->getParamType(4);
@@ -6172,7 +6211,8 @@ llvm::Type *OP::GetOverloadType(OpCode opCode, llvm::Function *F) {
61726211
case OpCode::TextureGatherRaw:
61736212
case OpCode::SampleCmpLevel:
61746213
case OpCode::SampleCmpGrad:
6175-
case OpCode::SampleCmpBias: {
6214+
case OpCode::SampleCmpBias:
6215+
case OpCode::RawBufferVectorLoad: {
61766216
StructType *ST = cast<StructType>(Ty);
61776217
return ST->getElementType(0);
61786218
}

0 commit comments

Comments
 (0)