Skip to content

Commit 64348c7

Browse files
authored
[NFC] Prepare DXC sources for clang-format (microsoft#5571)
This change prepares DXC sources to be ready to clang-format. This change adds annotations to skip formatting parts of the code that will break if clang-format modifies them due to include ordering or generated C++. It also adds missing include and forward declarations where clang-formatting resulted in moving things around that caused code breakages.
1 parent f206b3d commit 64348c7

File tree

15 files changed

+102
-4
lines changed

15 files changed

+102
-4
lines changed

include/dxc/DXIL/DxilConstants.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ namespace DXIL {
172172
Invalid,
173173
};
174174

175+
// clang-format off
176+
// Python lines need to be not formatted.
175177
/* <py::lines('SemanticKind-ENUM')>hctdb_instrhelp.get_enum_decl("SemanticKind", hide_val=True, sort_val=False)</py>*/
178+
// clang-format on
176179
// SemanticKind-ENUM:BEGIN
177180
// Semantic kind; Arbitrary or specific system value.
178181
enum class SemanticKind : unsigned {
@@ -211,7 +214,10 @@ namespace DXIL {
211214
};
212215
// SemanticKind-ENUM:END
213216

217+
// clang-format off
218+
// Python lines need to be not formatted.
214219
/* <py::lines('SigPointKind-ENUM')>hctdb_instrhelp.get_enum_decl("SigPointKind", hide_val=True, sort_val=False)</py>*/
220+
// clang-format on
215221
// SigPointKind-ENUM:BEGIN
216222
// Signature Point is more specific than shader stage or signature as it is unique in both stage and item dimensionality or frequency.
217223
enum class SigPointKind : unsigned {
@@ -239,7 +245,10 @@ namespace DXIL {
239245
};
240246
// SigPointKind-ENUM:END
241247

248+
// clang-format off
249+
// Python lines need to be not formatted.
242250
/* <py::lines('SemanticInterpretationKind-ENUM')>hctdb_instrhelp.get_enum_decl("SemanticInterpretationKind", hide_val=True, sort_val=False)</py>*/
251+
// clang-format on
243252
// SemanticInterpretationKind-ENUM:BEGIN
244253
// Defines how a semantic is interpreted at a particular SignaturePoint
245254
enum class SemanticInterpretationKind : unsigned {
@@ -257,7 +266,10 @@ namespace DXIL {
257266
};
258267
// SemanticInterpretationKind-ENUM:END
259268

269+
// clang-format off
270+
// Python lines need to be not formatted.
260271
/* <py::lines('PackingKind-ENUM')>hctdb_instrhelp.get_enum_decl("PackingKind", hide_val=True, sort_val=False)</py>*/
272+
// clang-format on
261273
// PackingKind-ENUM:BEGIN
262274
// Kind of signature point
263275
enum class PackingKind : unsigned {
@@ -270,7 +282,10 @@ namespace DXIL {
270282
};
271283
// PackingKind-ENUM:END
272284

285+
// clang-format off
286+
// Python lines need to be not formatted.
273287
/* <py::lines('FPDenormMode-ENUM')>hctdb_instrhelp.get_enum_decl("Float32DenormMode", hide_val=False, sort_val=False)</py>*/
288+
// clang-format on
274289
// FPDenormMode-ENUM:BEGIN
275290
// float32 denorm behavior
276291
enum class Float32DenormMode : unsigned {
@@ -750,7 +765,10 @@ namespace DXIL {
750765
};
751766
// OPCODE-ENUM:END
752767

768+
// clang-format off
769+
// Python lines need to be not formatted.
753770
/* <py::lines('OPCODECLASS-ENUM')>hctdb_instrhelp.get_enum_decl("OpCodeClass")</py>*/
771+
// clang-format on
754772
// OPCODECLASS-ENUM:BEGIN
755773
// Groups for DXIL operations with equivalent function templates
756774
enum class OpCodeClass : unsigned {
@@ -1315,7 +1333,10 @@ namespace DXIL {
13151333
ReadAcrossDiagonal = 2, // returns the value from the lane across the quad in horizontal and vertical direction
13161334
};
13171335

1336+
// clang-format off
1337+
// Python lines need to be not formatted.
13181338
/* <py::lines('WAVEBITOPKIND-ENUM')>hctdb_instrhelp.get_enum_decl("WaveBitOpKind")</py>*/
1339+
// clang-format on
13191340
// WAVEBITOPKIND-ENUM:BEGIN
13201341
// Kind of bitwise cross-lane operation
13211342
enum class WaveBitOpKind : unsigned {
@@ -1325,7 +1346,10 @@ namespace DXIL {
13251346
};
13261347
// WAVEBITOPKIND-ENUM:END
13271348

1349+
// clang-format off
1350+
// Python lines need to be not formatted.
13281351
/* <py::lines('WAVEOPKIND-ENUM')>hctdb_instrhelp.get_enum_decl("WaveOpKind")</py>*/
1352+
// clang-format on
13291353
// WAVEOPKIND-ENUM:BEGIN
13301354
// Kind of cross-lane operation
13311355
enum class WaveOpKind : unsigned {
@@ -1336,7 +1360,10 @@ namespace DXIL {
13361360
};
13371361
// WAVEOPKIND-ENUM:END
13381362

1363+
// clang-format off
1364+
// Python lines need to be not formatted.
13391365
/* <py::lines('WAVEMULTIPREFIXOPKIND-ENUM')>hctdb_instrhelp.get_enum_decl("WaveMultiPrefixOpKind")</py>*/
1366+
// clang-format on
13401367
// WAVEMULTIPREFIXOPKIND-ENUM:BEGIN
13411368
// Kind of cross-lane for multi-prefix operation
13421369
enum class WaveMultiPrefixOpKind : unsigned {
@@ -1348,7 +1375,10 @@ namespace DXIL {
13481375
};
13491376
// WAVEMULTIPREFIXOPKIND-ENUM:END
13501377

1378+
// clang-format off
1379+
// Python lines need to be not formatted.
13511380
/* <py::lines('SIGNEDOPKIND-ENUM')>hctdb_instrhelp.get_enum_decl("SignedOpKind")</py>*/
1381+
// clang-format on
13521382
// SIGNEDOPKIND-ENUM:BEGIN
13531383
// Sign vs. unsigned operands for operation
13541384
enum class SignedOpKind : unsigned {
@@ -1357,7 +1387,10 @@ namespace DXIL {
13571387
};
13581388
// SIGNEDOPKIND-ENUM:END
13591389

1390+
// clang-format off
1391+
// Python lines need to be not formatted.
13601392
/* <py::lines('QUADVOTEOPKIND-ENUM')>hctdb_instrhelp.get_enum_decl("QuadVoteOpKind")</py>*/
1393+
// clang-format on
13611394
// QUADVOTEOPKIND-ENUM:BEGIN
13621395
// Kind of cross-quad vote operation
13631396
enum class QuadVoteOpKind : unsigned {

include/dxc/DXIL/DxilCounters.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ namespace llvm {
2121
namespace hlsl {
2222

2323
struct DxilCounters {
24+
// clang-format off
25+
// Python lines need to be not formatted.
2426
// <py::lines('OPCODE-COUNTERS')>['uint32_t %s = 0;' % c for c in hctdb_instrhelp.get_counters()]</py>
27+
// clang-format on
2528
// OPCODE-COUNTERS:BEGIN
2629
uint32_t array_local_bytes = 0;
2730
uint32_t array_local_ldst = 0;

include/dxc/DXIL/DxilShaderModel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ class ShaderModel {
3131
using Kind = DXIL::ShaderKind;
3232

3333
// Major/Minor version of highest shader model
34+
// clang-format off
35+
// Python lines need to be not formatted.
3436
/* <py::lines('VALRULE-TEXT')>hctdb_instrhelp.get_highest_shader_model()</py>*/
37+
// clang-format on
3538
// VALRULE-TEXT:BEGIN
3639
static const unsigned kHighestMajor = 6;
3740
static const unsigned kHighestMinor = 7;
@@ -62,7 +65,10 @@ class ShaderModel {
6265
}
6366
bool IsSM50Plus() const { return IsSMAtLeast(5, 0); }
6467
bool IsSM51Plus() const { return IsSMAtLeast(5, 1); }
68+
// clang-format off
69+
// Python lines need to be not formatted.
6570
/* <py::lines('VALRULE-TEXT')>hctdb_instrhelp.get_is_shader_model_plus()</py>*/
71+
// clang-format on
6672
// VALRULE-TEXT:BEGIN
6773
bool IsSM60Plus() const { return IsSMAtLeast(6, 0); }
6874
bool IsSM61Plus() const { return IsSMAtLeast(6, 1); }

include/dxc/DXIL/DxilSigPoint.inl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ const SigPoint SigPoint::ms_SigPoints[kNumSigPointRecords] = {
5151
#undef DEF_SIGPOINT
5252
};
5353

54+
// clang-format off
55+
// Python lines need to be not formatted.
5456
// <py::lines('INTERPRETATION-TABLE')>hctdb_instrhelp.get_interpretation_table()</py>
57+
// clang-format on
5558
// INTERPRETATION-TABLE:BEGIN
5659
// Semantic, VSIn, VSOut, PCIn, HSIn, HSCPIn, HSCPOut, PCOut, DSIn, DSCPIn, DSOut, GSVIn, GSIn, GSOut, PSIn, PSOut, CSIn, MSIn, MSOut, MSPOut, ASIn
5760
#define DO_INTERPRETATION_TABLE(ROW) \

include/dxc/DxilContainer/RDAT_LibraryTypes.inl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ RDAT_DXIL_ENUM_START(hlsl::DXIL::ShaderKind, uint32_t)
9191
RDAT_ENUM_END()
9292

9393
RDAT_DXIL_ENUM_START(hlsl::DXIL::SemanticKind, uint32_t)
94+
// clang-format off
95+
// Python lines need to be not formatted.
9496
/* <py::lines('SemanticKind-ENUM')>hctdb_instrhelp.get_rdat_enum_decl("SemanticKind", nodef=True)</py>*/
97+
// clang-format onm
9598
// SemanticKind-ENUM:BEGIN
9699
RDAT_ENUM_VALUE_NODEF(Arbitrary)
97100
RDAT_ENUM_VALUE_NODEF(VertexID)

include/dxc/Support/FileIOHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#pragma once
1313

1414
#include "Global.h"
15+
#include "dxc/Support/WinIncludes.h"
1516

1617
#ifndef _ATL_DECLSPEC_ALLOCATOR
1718
#define _ATL_DECLSPEC_ALLOCATOR

lib/DXIL/DxilCounters.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ bool CountLlvmOp_uints(unsigned op) {
230230
// OPCODE-COUNTERS:END
231231

232232
void CountDxilOp(unsigned op, DxilCounters &counters) {
233+
// clang-format off
234+
// Python lines need to be not formatted.
233235
// <py::lines('COUNT-DXIL-OPS')>['if (CountDxilOp_%s(op)) ++counters.%s;' % (c,c) for c in hctdb_instrhelp.get_dxil_op_counters()]</py>
236+
// clang-format on
234237
// COUNT-DXIL-OPS:BEGIN
235238
if (CountDxilOp_atomic(op)) ++counters.atomic;
236239
if (CountDxilOp_barrier(op)) ++counters.barrier;
@@ -251,7 +254,10 @@ void CountDxilOp(unsigned op, DxilCounters &counters) {
251254
}
252255

253256
void CountLlvmOp(unsigned op, DxilCounters &counters) {
257+
// clang-format off
258+
// Python lines need to be not formatted.
254259
// <py::lines('COUNT-LLVM-OPS')>['if (CountLlvmOp_%s(op)) ++counters.%s;' % (c,c) for c in hctdb_instrhelp.get_llvm_op_counters()]</py>
260+
// clang-format on
255261
// COUNT-LLVM-OPS:BEGIN
256262
if (CountLlvmOp_atomic(op)) ++counters.atomic;
257263
if (CountLlvmOp_fence(op)) ++counters.fence;
@@ -334,7 +340,10 @@ struct CounterOffsetByName {
334340

335341
// Must be sorted case-sensitive:
336342
static const CounterOffsetByName CountersByName[] = {
343+
// clang-format off
344+
// Python lines need to be not formatted.
337345
// <py::lines('COUNTER-MEMBER-PTRS')>['{ "%s", &DxilCounters::%s },' % (c,c) for c in hctdb_instrhelp.get_counters()]</py>
346+
// clang-format on
338347
// COUNTER-MEMBER-PTRS:BEGIN
339348
{ "array_local_bytes", &DxilCounters::array_local_bytes },
340349
{ "array_local_ldst", &DxilCounters::array_local_ldst },

lib/DXIL/DxilMetadataHelper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,7 +2267,10 @@ void DxilMDHelper::EmitDxilCounters(const DxilCounters &counters) {
22672267
m_pModule->eraseNamedMetadata(pDxilCountersMD);
22682268

22692269
vector<Metadata*> MDVals;
2270+
// clang-format off
2271+
// Python lines need to be not formatted.
22702272
// <py::lines('OPCODE-COUNTERS')>['AddCounterIfNonZero(counters.%s, "%s", MDVals);' % (c,c) for c in hctdb_instrhelp.get_counters()]</py>
2273+
// clang-format on
22712274
// OPCODE-COUNTERS:BEGIN
22722275
AddCounterIfNonZero(counters.array_local_bytes, "array_local_bytes", MDVals);
22732276
AddCounterIfNonZero(counters.array_local_ldst, "array_local_ldst", MDVals);

lib/DXIL/DxilOperations.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,10 @@ OP::OpCode OP::GetDxilOpFuncCallInst(const llvm::Instruction *I) {
609609

610610
bool OP::IsDxilOpWave(OpCode C) {
611611
unsigned op = (unsigned)C;
612+
// clang-format off
613+
// Python lines need to be not formatted.
612614
/* <py::lines('OPCODE-WAVE')>hctdb_instrhelp.get_instrs_pred("op", "is_wave")</py>*/
615+
// clang-format on
613616
// OPCODE-WAVE:BEGIN
614617
// Instructions: WaveIsFirstLane=110, WaveGetLaneIndex=111,
615618
// WaveGetLaneCount=112, WaveAnyTrue=113, WaveAllTrue=114,
@@ -624,7 +627,10 @@ bool OP::IsDxilOpWave(OpCode C) {
624627

625628
bool OP::IsDxilOpGradient(OpCode C) {
626629
unsigned op = (unsigned)C;
630+
// clang-format off
631+
// Python lines need to be not formatted.
627632
/* <py::lines('OPCODE-GRADIENT')>hctdb_instrhelp.get_instrs_pred("op", "is_gradient")</py>*/
633+
// clang-format on
628634
// OPCODE-GRADIENT:BEGIN
629635
// Instructions: Sample=60, SampleBias=61, SampleCmp=64, CalculateLOD=81,
630636
// DerivCoarseX=83, DerivCoarseY=84, DerivFineX=85, DerivFineY=86,
@@ -635,7 +641,10 @@ bool OP::IsDxilOpGradient(OpCode C) {
635641

636642
bool OP::IsDxilOpFeedback(OpCode C) {
637643
unsigned op = (unsigned)C;
644+
// clang-format off
645+
// Python lines need to be not formatted.
638646
/* <py::lines('OPCODE-FEEDBACK')>hctdb_instrhelp.get_instrs_pred("op", "is_feedback")</py>*/
647+
// clang-format on
639648
// OPCODE-FEEDBACK:BEGIN
640649
// Instructions: WriteSamplerFeedback=174, WriteSamplerFeedbackBias=175,
641650
// WriteSamplerFeedbackLevel=176, WriteSamplerFeedbackGrad=177
@@ -651,7 +660,10 @@ void OP::GetMinShaderModelAndMask(OpCode C, bool bWithTranslation,
651660
// Default is 6.0, all stages
652661
major = 6; minor = 0;
653662
mask = ((unsigned)1 << (unsigned)DXIL::ShaderKind::Invalid) - 1;
663+
// clang-format off
664+
// Python lines need to be not formatted.
654665
/* <py::lines('OPCODE-SMMASK')>hctdb_instrhelp.get_min_sm_and_mask_text()</py>*/
666+
// clang-format on
655667
// OPCODE-SMMASK:BEGIN
656668
// Instructions: ThreadId=93, GroupId=94, ThreadIdInGroup=95,
657669
// FlattenedThreadIdInGroup=96
@@ -1588,7 +1600,10 @@ llvm::Type *OP::GetOverloadType(OpCode opCode, llvm::Function *F) {
15881600
Type *Ty = F->getReturnType();
15891601
FunctionType *FT = F->getFunctionType();
15901602
LLVMContext &Ctx = F->getContext();
1591-
/* <py::lines('OPCODE-OLOAD-TYPES')>hctdb_instrhelp.get_funcs_oload_type()</py>*/
1603+
// clang-format off
1604+
// Python lines need to be not formatted.
1605+
/* <py::lines('OPCODE-OLOAD-TYPES')>hctdb_instrhelp.get_funcs_oload_type()</py>*/
1606+
// clang-format on
15921607
switch (opCode) { // return OpCode
15931608
// OPCODE-OLOAD-TYPES:BEGIN
15941609
case OpCode::TempRegStore:

lib/DXIL/DxilShaderModel.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ bool ShaderModel::IsValidForDxil() const {
5757
switch (m_Major) {
5858
case 6: {
5959
switch (m_Minor) {
60+
// clang-format off
61+
// Python lines need to be not formatted.
6062
/* <py::lines('VALRULE-TEXT')>hctdb_instrhelp.get_is_valid_for_dxil()</py>*/
63+
// clang-format on
6164
// VALRULE-TEXT:BEGIN
6265
case 0:
6366
case 1:
@@ -219,7 +222,10 @@ const ShaderModel *ShaderModel::GetByName(const char *pszName) {
219222
switch (pszName[Idx++]) {
220223
case '0': Minor = 0; break;
221224
case '1': Minor = 1; break;
225+
// clang-format off
226+
// Python lines need to be not formatted.
222227
/* <py::lines('VALRULE-TEXT')>hctdb_instrhelp.get_shader_model_by_name()</py>*/
228+
// clang-format on
223229
// VALRULE-TEXT:BEGIN
224230
case '2':
225231
if (Major == 6) {
@@ -316,7 +322,10 @@ void ShaderModel::GetMinValidatorVersion(unsigned &ValMajor, unsigned &ValMinor)
316322
DXASSERT(IsValidForDxil(), "invalid shader model");
317323
ValMajor = 1;
318324
switch (m_Minor) {
325+
// clang-format off
326+
// Python lines need to be not formatted.
319327
/* <py::lines('VALRULE-TEXT')>hctdb_instrhelp.get_min_validator_version()</py>*/
328+
// clang-format on
320329
// VALRULE-TEXT:BEGIN
321330
case 0:
322331
ValMinor = 0;

0 commit comments

Comments
 (0)