Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion docs/SPIR-V.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4227,7 +4227,7 @@ codegen for Vulkan:
- ``-fvk-use-dx-layout``: Uses DirectX layout rules for resources.
- ``-fvk-invert-y``: Negates (additively inverts) SV_Position.y before writing
to stage output. Used to accommodate the difference between Vulkan's
coordinate system and DirectX's. Only allowed in VS/DS/GS.
coordinate system and DirectX's. Only allowed in VS/DS/GS/MS/Lib.
- ``-fvk-use-dx-position-w``: Reciprocates (multiplicatively inverts)
SV_Position.w after reading from stage input. Used to accommodate the
difference between Vulkan DirectX: the w component of SV_Position in PS is
Expand Down
2 changes: 1 addition & 1 deletion include/dxc/Support/HLSLOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def fvk_bind_register : MultiArg<["-"], "fvk-bind-register", 4>, MetaVarName<"<t
HelpText<"Specify Vulkan descriptor set and binding for a specific register">;
def vkbr : MultiArg<["-"], "vkbr", 4>, Flags<[CoreOption, DriverOption]>, Alias<fvk_bind_register>;
def fvk_invert_y: Flag<["-"], "fvk-invert-y">, Group<spirv_Group>, Flags<[CoreOption, DriverOption]>,
HelpText<"Negate SV_Position.y before writing to stage output in VS/DS/GS to accommodate Vulkan's coordinate system">;
HelpText<"Negate SV_Position.y before writing to stage output in VS/DS/GS/MS/Lib to accommodate Vulkan's coordinate system">;
Comment thread
s-perron marked this conversation as resolved.
def fvk_use_dx_position_w: Flag<["-"], "fvk-use-dx-position-w">, Group<spirv_Group>, Flags<[CoreOption, DriverOption]>,
HelpText<"Reciprocate SV_Position.w after reading from stage input in PS to accommodate the difference between Vulkan and DirectX">;
def fvk_support_nonzero_base_instance: Flag<["-"], "fvk-support-nonzero-base-instance">, Group<spirv_Group>, Flags<[CoreOption, DriverOption]>,
Expand Down
14 changes: 10 additions & 4 deletions tools/clang/lib/SPIRV/SpirvEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,8 @@ SpirvEmitter::SpirvEmitter(CompilerInstance &ci)
emitError("unknown shader module: %0", {}) << shaderModel->GetName();

if (spirvOptions.invertY && !shaderModel->IsVS() && !shaderModel->IsDS() &&
!shaderModel->IsGS() && !shaderModel->IsMS())
emitError("-fvk-invert-y can only be used in VS/DS/GS/MS", {});
!shaderModel->IsGS() && !shaderModel->IsMS() && !shaderModel->IsLib())
emitError("-fvk-invert-y can only be used in VS/DS/GS/MS/Lib", {});

if (spirvOptions.useGlLayout && spirvOptions.useDxLayout)
emitError("cannot specify both -fvk-use-dx-layout and -fvk-use-gl-layout",
Expand Down Expand Up @@ -14881,8 +14881,14 @@ SpirvEmitter::createSpirvIntrInstExt(llvm::ArrayRef<const Attr *> attrs,
SpirvInstruction *SpirvEmitter::invertYIfRequested(SpirvInstruction *position,
SourceLocation loc,
SourceRange range) {
// Negate SV_Position.y if requested
if (spirvOptions.invertY) {
// Negate SV_Position.y if requested and supported

bool supportsInvertY = spvContext.isVS() || spvContext.isGS() ||
spvContext.isDS() || spvContext.isMS();
Comment thread
s-perron marked this conversation as resolved.

assert(supportsInvertY && "invertY is only supported in VS/DS/GS/MS")
Comment thread
s-perron marked this conversation as resolved.
Outdated

if (spirvOptions.invertY) {
const auto oldY = spvBuilder.createCompositeExtract(
astContext.FloatTy, position, {1}, loc, range);
const auto newY = spvBuilder.createUnaryOp(
Expand Down
12 changes: 12 additions & 0 deletions tools/clang/test/CodeGenSPIRV/vk.cloption.invert-y.lib.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %dxc -T lib_6_3 -fvk-invert-y -fcgl %s -spirv | FileCheck %s

[shader("vertex")]
float4 main(float4 a : A) : SV_Position {
return a;
}

// CHECK: [[a:%[0-9]+]] = OpFunctionCall %v4float %src_main %param_var_a
// CHECK-NEXT: [[oldY:%[0-9]+]] = OpCompositeExtract %float [[a]] 1
// CHECK-NEXT: [[newY:%[0-9]+]] = OpFNegate %float [[oldY]]
// CHECK-NEXT: [[pos:%[0-9]+]] = OpCompositeInsert %v4float [[newY]] [[a]] 1
// CHECK-NEXT: OpStore %gl_Position [[pos]]
Loading