Граф коммитов

154 Коммитов

Автор SHA1 Сообщение Дата
Jaebaek Seo f913bde7d0
[spirv] support optional use of base vertex instance (#3478)
In DX12, `SV_InstanceID` always counts from 0. On the other hand,
Vulkan `gl_InstanceIndex` starts from the first instance. Thus it
doesn't emulate actual DX12 shader behavior. To make it equivalent,
we can set `SV_InstanceID = gl_InstanceIndex - gl_BaseInstance`.
However, it can break the existing working shaders (i.e., compatibility
issue). We want to provide an option for users to choose what they
exactly want by `SV_InstanceID`. This commit adds
`-fvk-support-nonzero-base-instance` option. If it is enabled, it emits
`SV_InstanceID = gl_InstanceIndex - gl_BaseInstance`. Otherwise,
`SV_InstanceID = gl_InstanceIndex`.
2021-02-19 14:30:39 -05:00
Frank de Jong 02e8662de6
[spirv] Added support for [[vk::shader_record_ext]] (#3426)
I added support for the Shader Record buffer for the Khronos extension.
The code is adapted from [this](https://github.com/microsoft/DirectXShaderCompiler/pull/2179) previous merge.

It should fix this issue #3177
2021-02-08 11:22:51 -05:00
Ehsan d7bb9ee170
Introduce the implicit 'vk' namespace (#3133)
* [spirv] Introduce the implicit 'vk' namespace

If any of these are used for DXIL code generation, the compiler will
report an error about the unknown "vk" namespace.

* [spirv] Introduce vk::ReadClock intrinsic.

The following Vulkan specific intrinsic functions are added:

```hlsl
uint64_t vk::ReadClock(in uint32 scope);
```

Also the following Vulkan-specific implicit constants are added:

```
vk::CrossDeviceScope; // defined as uint 0
vk::DeviceScope       // defined as uint 1
vk::WorkgroupScope    // defined as uint 2
vk::SubgroupScope     // defined as uint 3
vk::InvocationScope   // defined as uint 4
vk::QueueFamilyScope  // defined as uint 5
```

Sample usage looks as follows:

```hlsl
uint64_t clock = vk::ReadClock(vk::WorkgroupScope);
```

If any of these are used for DXIL code generation, the compiler will
report an error about the unknown "vk" namespace.

* [spirv] Add documentation.

* Address code review comments.

* Test: Validate vk namespace is not allowed for dxil.

* Fix usage of DXASSERT.

* Move ValidateVkNamespaceNotAllowed test to HlslFileCheck.
2020-12-01 14:04:14 -06:00
JiaoluAMD 4ced9bdf05
[SPIRV]Updates to final RayTracing semantics (#3279)
1. Add OpTraceRayKHR
2. Remove "provisional" in files
3. Update the SPIRV Headers/Tools to latest version
2020-11-24 10:03:41 -06:00
Dan Ginsburg e93ab88f7d
Add -fvk-auto-shift-bindings that applies -fvk-*-shift bindings to re… (#2959)
* Add -fvk-auto-shift-bindings that applies -fvk-*-shift bindings to resources that do not have explicit register assignments.  Closes #2956
* For resources that don't have an explicit register binding, first categorize their registerType using new method DeclResultIdMapper::getImplicitRegisterType.
* When finding automatic binding indices for implicit register bindings, pass an optional shift to useNextBinding.
* Change getNextBindingChunk() to handle finding the next binding range given a bindingShift

* Fix regression with binding numbers causing AppVeyor failure and also fix crash I ran into in my own testing in getImplicitRegisterType() if the getSpirvInstr() did not have an AstResultType.

* Address review comments.

* Update documentation

Co-authored-by: Ehsan Nasiri <ehsannas@gmail.com>
2020-07-13 09:49:27 -05:00
Maciej Latocha 607d2e4eea
[spirv] Fix incorrect opcode generation for fmod() function (#2990)
* [spirv] Fix incorrect opcode generation for fmod() function

In HLSL fmod() function, first argument is used to deduce return value sign,
which is equivalent to spirv OpFRem, not OpFMod.

Please see the following documentation links for further reference.
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-fmod
https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpFRem

* [spirv] Fix test failures.

Co-authored-by: Ehsan Nasiri <ehsannas@gmail.com>
2020-06-26 14:05:31 -05:00
JiaoluAMD fc54789458
Implement SPV_KHR_ray_query generation (#2834)
* Implement SPV_KHR_ray_query generation

from dxr 1.1 rayquery hlsl

* Fix CodeGenSPIRV folder test failures

* Address reviewing issues and clang-format files

* Undo all spacing changes to HlslTypes.cpp

* Fix formatting issues in the doc file.

Co-authored-by: Ehsan Nasiri <ehsannas@gmail.com>
2020-05-11 12:28:00 -05:00
alelenv 04a84f05a5
Add support for SPV_KHR_ray_tracing. (#2780)
* Add support for SPV_KHR_ray_tracing.

* Target KHR RT extension by default

* Reupdate documentation

* Add missing asterix

* Another typo
2020-03-23 13:37:54 -05:00
Ehsan 9b9615d5b3
[spirv] Ensure loop unroll is run before descriptor scalar replacement. (#2417) 2019-08-22 13:40:35 -05:00
Ehsan 922ef652fa
[spirv] Add option to flatten array of resources. (#2397)
* [spirv] Add option to flatten array of resources.

Current SPIR-V code generation uses 1 binding number for an array of
resources (e.g. an array of textures). However, the DX side uses one
binding number per array element. The newly added
'-fspv-flatten-resource-arrays' changes the SPIR-V backend behavior to
use one binding number per array element, and uses spirv-opt to flatten
the array.

TODO: Add a test where the array is passed around.
TODO: Test this works with steven's PR and proper results are produced.

* [spirv] Update tests to include array of samplers.

* [spirv] Take early exit condition out of the loop.

* [spirv] Add documentation for the new cmd option.

* [spirv] Invoke CreateDescriptorScalarReplacementPass when needed.

* [spirv] address code review comments.
2019-08-14 09:45:01 -04:00
Sahil Parmar 83c1bf8e92 [spirv] Add mesh/amplification shader tests for use of buffers and fn calls (#2390)
- Also cleans up SPIR-V.rst documentation issues.
2019-08-06 11:12:42 -04:00
Sahil Parmar 968fe41136 Merged PR 116: Add support for HLSL Meshlets
This PR adds support for new HLSL mesh and amplification shaders.
2019-07-11 20:19:23 +00:00
JasperNV 4f487432ad [spirv] Add support for SV_ShadingRate as a PS input (#2226)
* Add support for SV_ShadingRate as a PS input

Solves a portion of #2208.

* Fix small typo in error message
2019-06-06 17:15:21 -04:00
Ehsan 101730c57b
[spirv] Respect the -auto-binding-space option in SPIR-V backend (#2211)
* [spirv] Respect the -auto-binding-space option in SPIR-V backend.

* [spirv] Use default space if vk::binding doesn't provide dset.

* Address code review comments.
2019-06-04 09:35:04 -04:00
alelenv b830b09bc5 [spirv] Add support for [[vk::shader_record_nv]] (#2179)
* Add support for [[vk::shader_record_nv]]

* Fixes after first review of ehsannas.
2019-05-16 00:36:28 -04:00
Ehsan 5648e43f18
[spirv] Command line option for providing $Globals binding. (#2156) 2019-05-01 18:28:14 -04:00
alelenv e58ecd4c2f Add support to convert DXR HLSL to SPV_NV_ray_tracing (#1920)
* Add support to convert DXR HLSL to SPV_NV_ray_tracing

* Fix multiple typos and cleanup using clang-format.

* Update tests to verify transpose and custom matrix type
Update tests to add multple entry functions of same shader stage

* Replace ExecutionModel class with ShaderModel::Kind

- This change removes ExecutionModel class and relies on ShaderModel::Kind to track current entry point shader stage
- Also instead of declaring it in SpirvEmitter, DeclResultIdMapper & GlPerVertex, we declare it only once in common object SpirvContext

* Dont create a stageVar for raytracing interface variables.

* Don't perform 'new' memory allocation for FunctionInfo object

This change also -
- removes invalid "SpirvEmitter::" from function declarations in SpirvEmitter class.
- fix build errors by adding a default constructor in FunctionInfo struct to allow functionInfoMap allocate an empty object for no search results.

* Fix some more typos and fomatting errors.

* Update RST with raytracing stage info

* In SpirvContext.h, replace unsigned by uint32_t

* Test add ascii art and fixup grammar mistakes.

* Use placement new to allocate FunctionInfo objects.

Also bundle the insertion into functionInfoMap and workQueue together.

* Remove outdated comment.

* Update RST with intrinsic mapping and typo fixes.

* Some more wording fixes to RST for raytracing.

* Accidently broke table in RST due to missing '-'

* Add tick marks for supported stages in RST

* Final clang-format formatting fixes.

* Add missing labels to flowchart and spacing.
2019-02-27 09:58:59 -05:00
Ehsan ebb720ced3
[spirv] Support HLSL 'register(c#)' annotation. (#1912) 2019-02-12 10:07:20 -05:00
Lei Zhang 7a2a95e36c
[spirv] Add support for VK_EXT_scalar_block_layout (#1716)
Ref: https://github.com/KhronosGroup/Vulkan-Docs/issues/854
2018-11-20 11:24:57 -05:00
Steven Perron fe2d48b984 Add the HLSL-spirv cookbook. (#1618)
Add a document to give examples of what HLSL code patterns will generate
valid Vulkan SPIR-V.
2018-10-22 14:22:44 -04:00
Lei Zhang 2ecc36b382
[spirv] Add doc about supported extensions 2018-10-01 14:47:11 -04:00
Lei Zhang d0fcff32fd
[spirv] Fix doc about half translation (#1539) 2018-09-11 14:49:20 -04:00
Lei Zhang 81b3451b4a
[spirv] Add mechanism for fine-grained control of debug info (#1518)
Added a new command-line option: -fspv-debug=<category>, where
category can be file, source, line, and tool, to give developers
fine-grained control of what debug information they want in
the generated SPIR-V code.
2018-08-29 11:11:30 -04:00
Lei Zhang 4d6e2cfc64
[spirv] Fix array index out of bound in doc (#1516) 2018-08-27 19:40:11 -04:00
Lei Zhang 05cda8da2a
[spirv] Add support for -fvk-bind-register (#1480)
format: -fvk-bind-register <type-number> <space> <binding> <set>

Also created a short alias for it: -vkbr.

This option gives the ultimate manual control of descriptor
assignment. It requires:

* All resources are annotated with :register() in the source code
* -fvk-bind-register is specified for every resource

It overrules all other mechanisms.
It cannot be used together with -fvk-{u|b|s|t}-shift.
2018-08-03 07:36:18 -04:00
Lei Zhang 474954a6ea
[spirv] Update mapping manual w.r.t. debugging and options (#1475) 2018-08-01 10:49:51 -04:00
Ehsan 90103b38c2
[spirv] Expose -Oconfig for running custom optimizer recipes (#1466) 2018-07-31 13:49:19 -04:00
Ehsan f9882c84a7
[spirv] Support for post_depth_coverage extension. (#1461) 2018-07-27 17:16:41 -04:00
Lei Zhang f40667e931
[spirv] Rename -fvk-invert-w to -fvk-use-dx-position-w (#1448) 2018-07-24 20:46:14 -04:00
Lei Zhang dbc67dc4f4
[spirv] -fvk-invert-w in non-PS stages is no-op (#1441)
Allow using -fvk-invert-w in non-PS stages and make it a no-op.
2018-07-21 06:57:55 -04:00
Lei Zhang ef6c9eff15
[spirv] Add -fvk-invert-w (#1429)
This option reciprocates (multiplicatively inverts) SV_Position.w
after reading it from stage input in PS. This is used to accommodate
the difference between Vulkan and DirectX.
2018-07-19 10:34:51 -04:00
Ehsan 18545516b0
[spirv] Handle CalculateLevelOfDetailUnclamped. (#1400) 2018-07-04 15:55:21 -04:00
Lei Zhang ed29623d9a
[spirv] Handle nested structs for [[vk::offset]] (#1399)
Also update the SPIR-V doc about [[vk::offset]
2018-07-04 10:58:35 -04:00
Lei Zhang 8c6d72a2a7
[spirv] Add option to ignore warnings on features without Vulkan support (#1289)
Added -Wno-vk-ignored-features to suppress warnings on features
that are ignored because of no Vulkan support. Examples include
cbuffer member initializer.
2018-05-16 14:32:30 -04:00
Lei Zhang babfc756c3
[spirv] Convert to use 2 as the depth value for OpTypeImage (#1261)
2 means no indication as to whether this is a depth or non-depth
image.

Reverted "Hack OpSampledImage for depth-comparison sampling".

This reverts commit 0f165c6483.
2018-05-11 10:57:26 -04:00
Lei Zhang 4dd7aee306
[spirv] Add doc about synchronization intrinsics (#1263) 2018-05-08 13:18:28 -04:00
Lei Zhang a1a33a4199
[spirv] Convert to use stand-alone variables for gl_PerVertex (#1259)
It's actually a spec reading issue that it seems we cannot
have stand-alone variables for Position, PointSize, ClipDistance,
or CullDistance in HS/DS/GS.

Removed all code regarding Position and PointSize from GlPerVertex.
We still need to keep GlPerVertex aroudn to handle ClipDistance
and CullDistance though.
2018-05-07 10:21:20 -04:00
Lei Zhang 2095fef62c
[spirv] Add support for arrays of structured/byte buffers (#1257)
They are translated into, of course, (runtime) arrays of
structured/byte buffers.
2018-05-03 13:36:09 -04:00
Lei Zhang 9b856626d6
[spirv] Add support for dual-source blending (#1251)
In HLSL, dual-source color blending is enabled only via API;
the shader needs no special marks: it only writes SV_Target0
& SV_Target1 like normal.

But in Vulkan, to enable dual-source blending, the shader need
to mark the two participating output variables with Index = 0
and Index = 1, respectively.

So we introduce a new attribute, vk::index(), to let developers
to specify the index of an output variable so dual-source
blending can be enabled.

See Vulkan spec "26.1.2. Dual-Source Blending".
2018-04-26 16:02:12 -04:00
Lei Zhang 23be4804b6
[spirv] Remove -fvk-ignore-unused-resources (#1246) 2018-04-24 14:47:28 -04:00
Lei Zhang 4491a30fba
[spirv] Support non-constant offsets in .Gather*() methods (#1232)
They are emulated via 4 separate OpImage*Gather instructions.
2018-04-16 17:21:02 -04:00
Lei Zhang 4ac938cc5b
[spirv] Clarify doc about SPIR-V target environment (#1230) 2018-04-16 17:16:07 -04:00
Lei Zhang a4491dd439
[spirv] Support shifting all sets with -fvk-*-shift N all (#1224) 2018-04-13 15:40:44 -04:00
Lei Zhang 0a8b8c4e1d
[spirv] Rename -fvk-use-glsl-layout to -fvk-use-gl-layout (#1206)
GLSL as a shading language does not define the layout rules for
std140/std430; the OpenGL graphics environment defines that.

This is also more consistent with -fvk-use-dx-layout.
2018-04-10 10:25:26 -04:00
Lei Zhang 99c142be0b
[spirv] Add support for DX layout rules (#1198)
These layout rules can be turned on with -fvk-use-dx-layout.
For both cbuffer/tbuffer and structured buffers.
2018-04-08 12:50:57 -04:00
Ehsan 68984b316a
[spirv] Specify "KHR" to enable all KHR extensions (#1195) 2018-04-03 15:21:23 -04:00
Ehsan 2a0b7c49fd
[spirv] Add -fspv-target-env command line option. (#1187)
* [spirv] Add -fspv-target-env command line option.

The valid values for this option currently are:
vulkan1.0
vulkan1.1

If no target environment is specified, vulkan1.0 is used as default.
2018-04-03 09:12:51 -04:00
Lei Zhang 241d32c810
[spirv] Allow explicitly controlling SPIR-V extensions (#1151)
Added FeatureManager to record all extensions specified from
the command-line and emit error if trying to use one not permitted.

Added command-line option -fspv-extension= to specify
whitelisted extensions.
2018-03-27 17:42:16 -04:00
Ehsan c66c37cfa1
[spirv] Add support for DeviceIndex builtin. (#1171) 2018-03-23 10:40:02 -04:00
Lei Zhang 66a8998f87
[spirv] Translate SV_InnerCoverage into FullyCoveredEXT (#1165)
Fixes https://github.com/Microsoft/DirectXShaderCompiler/issues/999
2018-03-22 10:08:43 -04:00