Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 34 additions & 11 deletions .github/workflows/clang-format-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
permissions:
pull-requests: write
steps:
- name: Fetch LLVM sources
- name: Fetch DirectXShaderCompiler sources
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.pull_request.head.sha }}
Expand All @@ -31,6 +31,20 @@ jobs:
separator: ","
skip_initial_fetch: true

# We need to pull the script from the main branch, so that we ensure
# we get the latest version of this script.
- name: Fetch code formatting utils
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: microsoft/DirectXShaderCompiler
ref: ${{ github.base_ref }}
sparse-checkout: |
utils/git/requirements_formatting.txt
utils/git/code-format-helper.py
utils/git/code-format-save-diff.py
sparse-checkout-cone-mode: false
path: code-format-tools

- name: "Listed files"
env:
LISTED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
Expand All @@ -48,10 +62,10 @@ jobs:
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: 'utils/git/requirements_formatting.txt'
cache-dependency-path: 'code-format-tools/utils/git/requirements_formatting.txt'

- name: Install python dependencies
run: pip install -r utils/git/requirements_formatting.txt
run: pip install -r code-format-tools/utils/git/requirements_formatting.txt

- name: Run code formatter
id: formatter
Expand All @@ -61,7 +75,7 @@ jobs:
END_REV: ${{ github.event.pull_request.head.sha }}
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
python utils/git/code-format-helper.py \
python code-format-tools/utils/git/code-format-helper.py \
--token ${{ secrets.GITHUB_TOKEN }} \
--issue-number $GITHUB_PR_NUMBER \
--start-rev $START_REV \
Expand Down Expand Up @@ -92,28 +106,37 @@ jobs:
} catch (err) {
core.setFailed(`Request failed with error ${err}`)
}
- name: Fetch LLVM sources
uses: actions/checkout@v4

# We need to pull the script from the main branch, so that we ensure
# we get the latest version of this script.
- name: Fetch code formatting utils
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 2
path: build/main_src
repository: microsoft/DirectXShaderCompiler
ref: ${{ github.base_ref }}
sparse-checkout: |
utils/git/requirements_formatting.txt
utils/git/code-format-helper.py
utils/git/code-format-save-diff.py
sparse-checkout-cone-mode: false
path: code-format-tools

- name: Setup Python env
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: 'build/main_src/utils/git/requirements_formatting.txt'
cache-dependency-path: 'code-format-tools/utils/git/requirements_formatting.txt'

- name: Install python dependencies
run: pip install -r build/main_src/utils/git/requirements_formatting.txt
run: pip install -r code-format-tools/utils/git/requirements_formatting.txt

- name: Apply code diff
env:
GITHUB_PR_NUMBER: ${{ github.event.issue.number }}
COMMENT_ID: ${{ github.event.comment.id }}
run: |
python build/main_src/utils/git/code-format-save-diff.py \
python code-format-tools/utils/git/code-format-save-diff.py \
--token ${{ secrets.GITHUB_TOKEN }} \
--issue-number $GITHUB_PR_NUMBER \
--tmp-diff-file $TMP_DIFF_FILE \
Expand Down
2 changes: 0 additions & 2 deletions include/dxc/Support/HLSLOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@ def print_before_all : Flag<["-", "/"], "print-before-all">, Group<hlslcomp_Grou
HelpText<"Print LLVM IR before each pass.">;
def print_before : Separate<["-", "/"], "print-before">, Group<hlslcomp_Group>, Flags<[CoreOption, HelpHidden]>,
HelpText<"Print LLVM IR before a specific pass. May be specificied multiple times.">;
def select_validator : Separate<["-", "/"], "select-validator">, Group<hlslcomp_Group>, Flags<[CoreOption, HelpHidden]>,
HelpText<"Select validator: auto: (default) use DXIL.dll if found, otherwise use internal; internal: internal non-signing validator; external: use DXIL.dll if found, otherwise fail compilation.">;
def print_after_all : Flag<["-", "/"], "print-after-all">, Group<hlslcomp_Group>, Flags<[CoreOption, HelpHidden]>,
HelpText<"Print LLVM IR after each pass.">;
def print_after : Separate<["-", "/"], "print-after">, Group<hlslcomp_Group>, Flags<[CoreOption, HelpHidden]>,
Expand Down
16 changes: 8 additions & 8 deletions lib/DXIL/DxilOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,32 +765,32 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
"unary",
Attribute::ReadNone,
1,
{{0x403}},
{{0x3}}}, // Overloads: hf<hf
{{0x3}},
{{0x0}}}, // Overloads: hf
{OC::DerivCoarseY,
"DerivCoarseY",
OCC::Unary,
"unary",
Attribute::ReadNone,
1,
{{0x403}},
{{0x3}}}, // Overloads: hf<hf
{{0x3}},
{{0x0}}}, // Overloads: hf
{OC::DerivFineX,
"DerivFineX",
OCC::Unary,
"unary",
Attribute::ReadNone,
1,
{{0x403}},
{{0x3}}}, // Overloads: hf<hf
{{0x3}},
{{0x0}}}, // Overloads: hf
{OC::DerivFineY,
"DerivFineY",
OCC::Unary,
"unary",
Attribute::ReadNone,
1,
{{0x403}},
{{0x3}}}, // Overloads: hf<hf
{{0x3}},
{{0x0}}}, // Overloads: hf

// Pixel shader
{OC::EvalSnapped,
Expand Down
14 changes: 0 additions & 14 deletions lib/DxcSupport/HLSLOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,20 +1033,6 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
opts.ValVerMinor = (unsigned long)minor64;
}

llvm::StringRef valSelectStr = Args.getLastArgValue(OPT_select_validator);
if (!valSelectStr.empty()) {
opts.SelectValidator = llvm::StringSwitch<ValidatorSelection>(valSelectStr)
.Case("auto", ValidatorSelection::Auto)
.Case("internal", ValidatorSelection::Internal)
.Case("external", ValidatorSelection::External)
.Default(ValidatorSelection::Invalid);
if (opts.SelectValidator == ValidatorSelection::Invalid) {
errors << "Unsupported value '" << valSelectStr
<< "for -select-validator option.";
return 1;
}
}

if (opts.IsLibraryProfile() && Minor == 0xF) {
if (opts.ValVerMajor != UINT_MAX && opts.ValVerMajor != 0) {
errors << "Offline library profile cannot be used with non-zero "
Expand Down
26 changes: 26 additions & 0 deletions lib/DxilValidation/DxilValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,32 @@ static void ValidateDxilOperationCallInProfile(CallInst *CI,
break;
}

// Shader Execution Reordering - from ray query
case DXIL::OpCode::HitObject_FromRayQuery:
case DXIL::OpCode::HitObject_FromRayQueryWithAttrs: {
for (unsigned i = 1; i < CI->getNumOperands(); ++i) {
Value *Arg = CI->getArgOperand(i);
if (isa<UndefValue>(Arg))
ValCtx.EmitInstrError(CI, ValidationRule::InstrNoReadingUninitialized);
}
break;
}

case DXIL::OpCode::HitObject_Invoke: {
if (isa<UndefValue>(CI->getArgOperand(1)))
ValCtx.EmitInstrError(CI, ValidationRule::InstrUndefHitObject);
if (isa<UndefValue>(CI->getArgOperand(2)))
ValCtx.EmitInstrError(CI, ValidationRule::InstrNoReadingUninitialized);
} break;
case DXIL::OpCode::HitObject_TraceRay: {
Value *Hdl = CI->getArgOperand(
DxilInst_HitObject_TraceRay::arg_accelerationStructure);
ValidateASHandle(CI, Hdl, ValCtx);
for (unsigned ArgIdx = 2; ArgIdx < CI->getNumArgOperands(); ++ArgIdx)
if (isa<UndefValue>(CI->getArgOperand(ArgIdx)))
ValCtx.EmitInstrError(CI, ValidationRule::InstrNoReadingUninitialized);
DxilInst_HitObject_TraceRay HOTraceRay(CI);
} break;
case DXIL::OpCode::AtomicBinOp:
case DXIL::OpCode::AtomicCompareExchange: {
Type *pOverloadType = OP::GetOverloadType(Opcode, CI->getCalledFunction());
Expand Down
1 change: 0 additions & 1 deletion lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2819,7 +2819,6 @@ void SROA_Helper::RewriteCall(CallInst *CI) {
DeadInsts.push_back(CI);
break;
}
LLVM_FALLTHROUGH;
default:
// RayQuery this pointer replacement.
if (OldVal->getType()->isPointerTy() &&
Expand Down
8 changes: 7 additions & 1 deletion tools/clang/lib/SPIRV/EmitVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,13 @@ bool EmitVisitor::visit(SpirvIntrinsicInstruction *inst) {
}
}

finalizeInstruction(&mainBinary);
auto opcode = static_cast<spv::Op>(inst->getInstruction());
if ((opcode == spv::Op::OpSpecConstant || opcode == spv::Op::OpConstant) &&
!inst->getInstructionSet()) {
finalizeInstruction(&typeConstantBinary);
} else {
finalizeInstruction(&mainBinary);
}
return true;
}

Expand Down
50 changes: 49 additions & 1 deletion tools/clang/test/CodeGenDXIL/hlsl/types/longvec-intrinsics.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// RUN: %dxc -T cs_6_9 -enable-16bit-types -DNUM=7 %s | FileCheck %s
// RUN: %dxc -T cs_6_9 -enable-16bit-types -DNUM=125 %s | FileCheck %s
// RUN: %dxc -T cs_6_9 -enable-16bit-types -DNUM=256 %s | FileCheck %s
// RUN: %dxc -T cs_6_9 -enable-16bit-types -DNUM=1024 %s | FileCheck %s

// Test vector-enabled non-trivial intrinsics that take parameters of various types.

Expand Down Expand Up @@ -203,6 +202,36 @@ void main() {
// CHECK: fmul fast <[[NUM]] x float> [[tmp]], <float 0x3FE62E4300000000
fRes += log(fVec1);

// CHECK-NOT: extractelement
// CHECK-NOT: insertelement
// CHECK: [[tmp:%.*]] = call <[[NUM]] x half> @dx.op.unary.[[HTY]](i32 23, <[[NUM]] x half> [[hvec2]]) ; Log(value)
// CHECK: [[tmp2:%.*]] = fmul fast <[[NUM]] x half> [[tmp]], [[hvec1]]
// CHECK: call <[[NUM]] x half> @dx.op.unary.[[HTY]](i32 21, <[[NUM]] x half> [[tmp2]]) ; Exp(value)
hRes += pow(hVec2, hVec1);

// CHECK-NOT: extractelement
// CHECK-NOT: insertelement
// CHECK: [[tmp:%.*]] = call <[[NUM]] x float> @dx.op.unary.[[FTY]](i32 23, <[[NUM]] x float> [[fvec2]]) ; Log(value)
// CHECK: [[tmp2:%.*]] = fmul fast <[[NUM]] x float> [[tmp]], [[fvec1]]
// CHECK: call <[[NUM]] x float> @dx.op.unary.[[FTY]](i32 21, <[[NUM]] x float> [[tmp2]]) ; Exp(value)
fRes += pow(fVec2, fVec1);

vector<half, NUM> hVal;
// CHECK-NOT: extractelement
// CHECK-NOT: insertelement
// CHECK: [[tmp:%.*]] = call <[[NUM]] x half> @dx.op.unary.[[HTY]](i32 29, <[[NUM]] x half> [[hvec1]]) ; Round_z(value)
// CHECK: fsub fast <[[NUM]] x half> [[hvec1]], [[tmp]]
hRes *= modf(hVec1, hVal);
hRes += hVal;

vector<float, NUM> fVal;
// CHECK-NOT: extractelement
// CHECK-NOT: insertelement
// CHECK: [[tmp:%.*]] = call <[[NUM]] x float> @dx.op.unary.[[FTY]](i32 29, <[[NUM]] x float> [[fvec1]]) ; Round_z(value)
// CHECK: fsub fast <[[NUM]] x float> [[fvec1]], [[tmp]]
fRes *= modf(fVec1, fVal);
fRes += fVal;

// CHECK-NOT: extractelement
// CHECK-NOT: insertelement
// CHECK: [[sub:%.*]] = fsub fast <[[NUM]] x half> [[hvec2]], [[hvec1]]
Expand All @@ -227,6 +256,25 @@ void main() {
// CHECK: fmul fast <[[NUM]] x float> [[mul]], [[sub]]
fRes += smoothstep(fVec1, fVec2, fVec3);

// Note that Fabs is tested in longvec-trivial-unary-float-intrinsics.
// CHECK-NOT: extractelement
// CHECK-NOT: insertelement
// CHECK: [[tmp:%.*]] = sub <[[NUM]] x i16> zeroinitializer, [[svec1]]
// CHECK: call <[[NUM]] x i16> @dx.op.binary.[[STY]](i32 37, <[[NUM]] x i16> [[svec1]], <[[NUM]] x i16> [[tmp]]) ; IMax(a,b)
sRes += abs(sVec1);

// CHECK-NOT: extractelement
// CHECK-NOT: insertelement
// CHECK: [[tmp:%.*]] = sub <[[NUM]] x i32> zeroinitializer, [[ivec1]]
// CHECK: call <[[NUM]] x i32> @dx.op.binary.[[ITY]](i32 37, <[[NUM]] x i32> [[ivec1]], <[[NUM]] x i32> [[tmp]]) ; IMax(a,b)
iRes += abs(iVec1);

// CHECK-NOT: extractelement
// CHECK-NOT: insertelement
// CHECK: [[tmp:%.*]] = sub <[[NUM]] x i64> zeroinitializer, [[lvec1]]
// CHECK: call <[[NUM]] x i64> @dx.op.binary.[[LTY]](i32 37, <[[NUM]] x i64> [[lvec1]], <[[NUM]] x i64> [[tmp]]) ; IMax(a,b)
lRes += abs(lVec1);

// Intrinsics that expand into llvm ops.

// CHECK-NOT: extractelement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
// RUN: %dxc -DFUNC=countbits -DARITY=1 -DTYPE=uint -T ps_6_9 %s | FileCheck %s --check-prefixes=CHECK,UNARY
// RUN: %dxc -DFUNC=firstbithigh -DARITY=1 -DTYPE=uint -T ps_6_9 %s | FileCheck %s --check-prefixes=CHECK,UNARY
// RUN: %dxc -DFUNC=firstbitlow -DARITY=1 -DTYPE=uint -T ps_6_9 %s | FileCheck %s --check-prefixes=CHECK,UNARY
// RUN: %dxc -DFUNC=ddx -DARITY=1 -T ps_6_9 %s | FileCheck %s --check-prefixes=CHECK,UNARY
// RUN: %dxc -DFUNC=ddx_coarse -DARITY=1 -T ps_6_9 %s | FileCheck %s --check-prefixes=CHECK,UNARY
// RUN: %dxc -DFUNC=ddx_fine -DARITY=1 -T ps_6_9 %s | FileCheck %s --check-prefixes=CHECK,UNARY
// RUN: %dxc -DFUNC=ddy -DARITY=1 -T ps_6_9 %s | FileCheck %s --check-prefixes=CHECK,UNARY
// RUN: %dxc -DFUNC=ddy_coarse -DARITY=1 -T ps_6_9 %s | FileCheck %s --check-prefixes=CHECK,UNARY
// RUN: %dxc -DFUNC=ddy_fine -DARITY=1 -T ps_6_9 %s | FileCheck %s --check-prefixes=CHECK,UNARY
// RUN: %dxc -DFUNC=fwidth -DARITY=1 -T ps_6_9 %s | FileCheck %s --check-prefixes=CHECK,UNARY
// RUN: %dxc -DFUNC=QuadReadLaneAt -DARITY=4 -T ps_6_9 %s | FileCheck %s --check-prefixes=CHECK,QUAD
// RUN: %dxc -DFUNC=QuadReadAcrossX -DARITY=1 -T ps_6_9 %s | FileCheck %s --check-prefixes=CHECK,QUAD
// RUN: %dxc -DFUNC=QuadReadAcrossY -DARITY=1 -T ps_6_9 %s | FileCheck %s --check-prefixes=CHECK,QUAD
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// RUN: %dxc -T cs_6_9 -enable-16bit-types -DFUNC=abs -DOP=6 -DNUM=7 %s | FileCheck %s
// RUN: %dxc -T cs_6_9 -enable-16bit-types -DFUNC=abs -DOP=6 -DNUM=1022 %s | FileCheck %s
// RUN: %dxc -T cs_6_9 -enable-16bit-types -DFUNC=saturate -DOP=7 -DNUM=7 %s | FileCheck %s
// RUN: %dxc -T cs_6_9 -enable-16bit-types -DFUNC=saturate -DOP=7 -DNUM=1022 %s | FileCheck %s
// RUN: %dxc -T cs_6_9 -enable-16bit-types -DFUNC=cos -DOP=12 -DNUM=7 %s | FileCheck %s
Expand Down
13 changes: 13 additions & 0 deletions tools/clang/test/CodeGenSPIRV/spv.intrinsicConstantValue.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %dxc -Od -T cs_6_8 -spirv -fcgl %s | FileCheck %s

// CHECK: %spirvIntrinsicType = OpTypeInt 8 0
using uint8_t [[vk::ext_capability(/* Int8 */ 39)]] =
vk::SpirvType</* OpTypeInt */ 21, 8, 8, vk::Literal<vk::integral_constant<uint, 8> >,
vk::Literal<vk::integral_constant<bool, false> > >;

[[vk::ext_instruction(/* OpConstant */ 43)]] uint8_t mkconsant([[vk::ext_literal]] int v);

// CHECK: OpConstant %spirvIntrinsicType 42
static const uint8_t K = mkconsant(42);

[numthreads(1, 1, 1)] void main() {}
14 changes: 14 additions & 0 deletions tools/clang/test/DXC/deprecated-select-validator.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Test that the deprecated option, select-validator, doesn't work.
// RUN: not %dxc -E main -T vs_6_7 -select-validator internal %s 2>&1 | FileCheck %s

// CHECK: dxc failed : Unknown argument: '-select-validator'

float4 main(int loc : SV_StartVertexLocation
, uint loc2 : SV_StartInstanceLocation
) : SV_Position
{
float4 r = 0;
r += loc;
r += loc2;
return r;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %dxc -T ps_6_8 -E main -Qkeep_reflect_in_dxil -select-validator internal %s | FileCheck -check-prefix=CHECK68 %s
// RUN: %dxc -T ps_6_7 -E main -Qkeep_reflect_in_dxil -select-validator internal %s | FileCheck -check-prefix=CHECK67 %s
// RUN: %dxc -T ps_6_8 -E main -Qkeep_reflect_in_dxil %s | FileCheck -check-prefix=CHECK68 %s
// RUN: %dxc -T ps_6_7 -E main -Qkeep_reflect_in_dxil %s | FileCheck -check-prefix=CHECK67 %s

// Make sure the vector is annotated with vector size (DXIL 1.8 and higher),
// matrix is annotated with matrix size and orientation, and scalar does not
Expand Down Expand Up @@ -47,4 +47,4 @@ StructuredBuffer<MyStruct> g_myStruct;
float main() : SV_Target
{
return g_myStruct[0].vec.x + g_myStruct[0].vec.y;
}
}
11 changes: 6 additions & 5 deletions tools/clang/test/HLSLFileCheck/infra/auto-dxilver.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
// This should implicitly require dxilver 1.8.

// RUN: %dxc -T vs_6_8 -Vd %s | FileCheck %s
// Even though this is using -Vd, the validator version is set by the available
// validator. If that isn't version 1.8 or above, we'll see an error.
// Even though this is using -Vd, the validator version being checked is the internal
// validator's version. If a pre-DXIL-1.8 DXC was used to run this test, we expect failure,
// since the internal validator will be the same version as the older DXC.
// The implicit dxilver logic should not skip the check when -Vd is used.
// CHECK-NOT: error: validator version {{.*}} does not support target profile.

// RUN: %dxc -T vs_6_0 -validator-version 1.8 %s | FileCheck %s
// Even though target is 6.0, the explicit -validator-version should add an
// implicit dxilver 1.8 requirement.
// implicit dxilver 1.8 requirement. The requirement should pass for DXCs that
// are newer than DXIL Version 1.8, since then, the internal validator's version will
// be sufficiently new for this check.
// CHECK-NOT: error: The module cannot be validated by the version of the validator currently attached.

// This error would occur if run against wrong compiler.
Expand All @@ -21,8 +24,6 @@
// Catch any other unexpected error cases.
// CHECK-NOT: error

// RUN: %dxc -T vs_6_8 -select-validator internal %s | FileCheck %s
// This should always be run, and always succeed.
// CHECK: define void @main()

void main() {}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; REQUIRES: dxil-1-9
; RUN: not %dxv %s 2>&1 | FileCheck %s

; Ensure proper validation errors are produced for invalid parameters to load and store operations.
Expand Down
Loading
Loading