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

306 Коммитов

Автор SHA1 Сообщение Дата
Nathan Gauër 3e7c98a91f
spirv: stop emitting ImageMSArray capability (#5663)
ImageMSArray is only required is OpTypeImage arrayed=1, MS=1 and
sampled=2. This is never the case AFAIK for code emitted from HLSL. No
tests or shaders I knew about required it, so should be OK removing it
from DXC.

---------

Signed-off-by: Nathan Gauër <brioche@google.com>
2023-09-08 09:57:20 -04:00
Kirill Kozlov 38fcd6f741
[SPIRV] Add option to preserve interface variables (#5400)
Add `-fspv-preserve-interface` CLI option to prevent DCE optimization
pass from compiling out interface variables. It happens if these
variables are unused.

The option may be useful when decompiling SPIR-V back to HLSL.
Personally, I need it to convert DX12 shaders to DX11 ones using
SPIRV-Cross as a tool for converting SPIR-V, produced by DXC, to the old
shader model HLSL.

SPIR-V Tools now have a parameter in `RegisterPerformancePasses()` and
`RegisterLegalizationPasses()` for this. This PR creates a new command
line option in DXC and passes it to the `spvtools::Optimizer`.

Closes #4567
2023-07-11 12:20:58 +02:00
Nathan Gauër 2096d1b805
Revert "[SPIR-V] add support for extension KHR_fragment_shading_barycentric (SV_Barycentrics)" (#5384)
Reverts microsoft/DirectXShaderCompiler#4638
This PR causes multiples issues (#5326, #5342, #5270). Reverting, will
need more testing.

Fixed #5270
2023-07-04 09:39:23 -04:00
Xiang Li 06a7197e23
Enable lit by default. (#5133)
* Enable lit by default.

* Update README for git user bin.

* Add DXC_DISABLE_LIT to replace DXC_ENABLE_LIT

* Set -DDXC_DISABLE_LIT=Off for appveyor.

* Keep original name for ClangSPIRVTests

* Set correct path for unit tests binary.

* Remove doc about DXC_DISABLE_LIT

* Remove extra space.

* Remove DxcOnUnix.rst.
2023-06-05 10:35:24 -07:00
Chow cd3b40bd2e
[SPIR-V] add support for extension KHR_fragment_shading_barycentric (SV_Barycentrics) (#4638)
Implement latest `SV_Barycentrics` semantics in DXC, according to DXC wiki spec.

  For variant qualifier decorated baryCoord inputs, as KHR extension has no matched built-in, still mapped to Bary*AMD.

  Add support for using input as first parameter of GetAttributeAtVertex. This would expand input's dimension to meet extension spec.

  Merge some features from AMD_shader_explicit_parameter and current extension together for MSAA usage. Keep generated SPIR-V codes similar to GLSL as possible.

  With concern to HLSL/DXIL part, keep most type modification/variable decoration change in SPIRV trans unit.

  Remove AMD_shader_explicit_parameter related features.

  Support struct member as parameter of GetAttributeAtVertex.

  Support using Decorator for MSAA features.
2023-05-31 09:48:52 -04:00
Xiang Li 18c9e114f9
[lit] Port Support %if ... %else syntax for RUN lines from upstream (#5227)
* [lit] Port Support %if ... %else syntax for RUN lines from upstream

Based on
1041a9642b

This syntax allows to modify RUN lines based on features
available. For example:

    RUN: ... | FileCheck %s --check-prefix=%if windows %{CHECK-W%} %else %{CHECK-NON-W%}
    CHECK-W: ...
    CHECK-NON-W: ...

This is merged to allow dxilver check apply on each RUN line.
2023-05-26 14:10:34 -07:00
Nathan Gauër 40d5e1fb9d
hlsl, spirv: allow use of ffinit-math-only (#4955)
* hlsl, spirv: allow use of ffinit-math-only

This options should match GCC's & Clang's behavior:

From GCC documention:
```
Allow optimizations for floating-point arithmetic that assume that arguments and results are not NaNs or +-Infs.

This option is not turned on by any -O option since it can result in incorrect output for programs that depend on an exact implementation of IEEE or ISO rules/specifications for math functions. It may, however, yield faster code for programs that do not require the guarantees of these specifications.

The default is -fno-finite-math-only.
```

This commit allows the flag to be used again, and makes SPIR-V min/max
intrinsics use FMin/FMax instead of NMin/NMax when enabled.

Fixes #4954

Signed-off-by: Nathan Gauër <brioche@google.com>
Co-authored-by: Laura Hermanns <laura.hermanns@epicgames.com>
2023-02-09 18:40:00 +01:00
Xiang Li 2eb641d56b
Enable build for dxa/dxl/dxopt/dxr/dxv on linux (#4895)
* Enable build for dxa/dxl/dxopt/dxr/dxv on linux

* Add CComBSTR and enable PdbUtils, Rewriter and recompile.
2023-01-09 15:10:56 -08:00
Chris B 8f39f4a861
[Docs] Add new docs on unified build workflow (#4890)
This document tries to capture the basics of a unified build and test
workflow for all platforms. It is complete enough to start using but not
yet ready to be the default build mode.
2023-01-03 10:03:12 -06:00
Greg Fischer b348d24071
[SPIR-V] Add -fspv-debug=vulkan-with-source to usage and README (#4811)
-fspv-debug=vulkan will be kept for testing purposes but will
not be documented in usage or README (for now).
2022-11-23 10:37:55 -05:00
TY-AMD 97bafd2a60
[SPIR-V] Add support for the extension VK_EXT_mesh_shader (#4725)
* Support VK_EXT_mesh_shader

* Fix errors when compiling with SPV_NV_mesh_shader

* Minor tweak onto amplification shaders

* Fix pre-checkin failure

* Add amplification and mesh tests for EXT_mesh_shader

* Add some comments

* Fix primitive indices

Co-authored-by: Tianyuan <Tianyuan.Wu@amd.com>
2022-11-18 15:43:59 -08:00
Nathan Gauër 0ff2aa5fd7
doc: fix code display on Github (#4775) 2022-11-08 16:04:11 +01:00
Nathan V. Morrical 44c767c8e3
[SPIRV] Add support for vk::RawBufferStore (#4573)
* initial code stubbed in to get vk raw buffer store working

* adding in additional intrinsic to support custom alignment of store

* altering test, forgot to add template argument

* some changes to unit test, though not sure checks are correct... and then added support for bool

* updating unit test, correcting some mistakes with the checks

* more changes to unit test

* removing addr variable to see if thats causing tests to fail

* fixing tests

* Updating documentation

* Small typo fix in docs
2022-08-13 13:56:16 -04:00
Jakub Kuderski 24ea9e83d2
Treat matrix load/stores as column major in raw buffers (#4526)
Assume that matrices are stored in the column major order in raw
buffers, e.g., `ByteAddressBuffer` and `RWByteAddressBuffer`.

Add a new flag,`-fspv-use-legacy-buffer-matrix-order`, so that shaders
that depend on the previous matrix order (row major) can opt-out of this
change.

Fixes: https://github.com/microsoft/DirectXShaderCompiler/issues/3370
2022-06-24 17:29:49 -04:00
Junda Liu a19c326294
[spirv] Add VK_AMD_shader_early_and_late_fragment_tests support (#4504) 2022-06-21 00:20:11 -04:00
Natalie Chouinard 72f76439e0
[spirv] Clarify error when Globals binding missing (#4519)
When -fvk-bind-register is used, all resource must have corresponding
register bindings set, including the Globals cbuffer. This change
clarifies the error message when the latter is the cause of failure and
directs the user to specify -fvk-bind-globals.

Fixes #3781
2022-06-20 10:26:29 -04:00
Natalie Chouinard 2a0833afb4
[spirv] Translate HLSL min/max to NMin/NMax (#4517)
The specification for the HLSL min and max intrinsic functions states
that if one of the values is NaN, the other will be given as the result,
which is correctly represented by the GLSL.std.450 instructions NMin and
NMax, respectively. By the semantics of the previously used FMin and
FMax instructions, this would be undefined behavior.

Fixes #3221
2022-06-17 16:17:54 -04:00
Natalie Chouinard b75a988411
[spirv] Translate HLSL round to RoundEven (#4515)
The specification for the HLSL round intrinsic function states "Rounds
the specified value to the nearest integer. Halfway cases are rounded to
the nearest even.", so translate it to RoundEven SPIR-V extended
instruction rather than Round.

Fixes #4368
2022-06-16 16:25:27 -04:00
Grace Jennings b602097210
Validate no gaps in UAV store writemask (#4495)
* Adding validation for uav continuous store

* Updated message text

* Add comment

* Updating text and adding tests
2022-06-03 10:39:00 -07:00
Greg Roth caec6aaf9e
Disallow illegal Atomic targets + propagate consts (#4453)
This change does a few things.

First and foremost, it disallows a number of illegal destination
parameters to atomic operations. This includes SRVs and other const
 values, non-groupshared and non-resource variables, members of
typed resources, and bitfield members of any resource.

In addition, this correctly propagates const information so that they
can be properly rejected and also the information is reflected.
This involves the consolidation and earlier detection of a number of
these failures as well as an expansion of that detection.
Also adds validation checks that the targets are not const and either
UAVs or groupshared address space.

The const errors are produced in clang and manifest as overload
mismatches. The errors for member access of typed buffers, bitfields,
or non-groupshared and non-UAV destinations are generated
as part of the lowering operation. This is where they were before
and easier to replicate though they would be better in codegen.
In some cases, existing errors were moved earlier in the process
and the logic to generate them simplified.

Add compilation and verifier tests for all.

Also adds validation errors for const destination targets and other
invalid targets and tests for the same.

In order to make those tests, I had to give locations to the function
candidate notes for function builtins. This changed a single verifier
test that depended on the locationless notes.

These tests make use of const groupshared variables that are of
questionable utility, but are valid for now.

Incidentally enhances some existing atomics tests to use a more
complex sequence of references and subscripts.

Finally incidentally added some foolproofing for mistakenly comparing
opcodes without taking into account the "table" or namespace that
they belonged to by changing some utility functions in Sema to require
the table as well as the opcode to produce results.

Fixes #4319
Fixes #4377
Fixes #4437
2022-05-16 21:26:21 -07:00
Helena Kotas 95da6e7452
Rename master branch to main (#4461) 2022-05-16 15:00:19 -07:00
Natalie Chouinard 787245f28f
[SPIR-V] Add option to rename SPIR-V entry point (#4390)
Allow renaming the SPIR-V entry point name from the default HLSL entry
point name with `-fspv-entrypoint-name`.

Fixes #2972
Fixes #4356
2022-04-20 16:04:56 -04:00
Jaebaek Seo 3cb5d80bb8
[spirv] support 'T vk::RawBufferLoad<T = uint>(uint64_t address [, uint alignment = 4] )' (#4226)
VK_KHR_buffer_device_address extension support a Vulkan feature to load data
from an arbitrary raw buffer address. We added
'uint vk::RawBufferLoad(uint64_t address)' before, but it is limited to loading data
with the unsigned integer type.

This commit adds
'T vk::RawBufferLoad<T = uint>(uint64_t address [, uint alignment = 4] )' that
allows us to load data with an arbitrary type.
2022-04-11 16:44:13 -04:00
Natalie Chouinard 68dd2877d7
[SPIR-V] Allow Vulkan 1.1 with SPIR-V 1.4 as a target environment (#4364)
Since we check for the "SPIR-V 1.4 (under Vulkan 1.1 semantics)"
minimum target environment for ray tracing extension use, this change
allows it to be now configured as a target-env via command line options.
Some out of date documentation target environments is also updated,
and improvements are made to version checking to use enums rather
than string comparisons.

Fixes #4313
2022-03-31 16:11:00 -04:00
Jaebaek Seo ad4ebb7d51
[spirv] support signature packing (#4361)
Currently, DXC assigns new locations for each stage variable. When there
are lots of stage variables, the number of locations we use can exceed the
maximum location limit. This commit uses `Component` decoration to pack
signature and reduce the number of locations DXC uses.
2022-03-31 15:38:33 -04:00
Jaebaek Seo 2322f53773
[spirv] change __spirv definition to __spirv__ (#4270)
We implicitly defined `__spirv` when SPIR-V code gen is enabled and
`-spirv` command line option is given. This commit changes it to
__spirv__.
2022-02-16 12:29:38 -05:00
Tex Riddell b338314f6e
Implement Shader Model 6.7 (#4260)
Shader Model 6.7 is still a work in progress.
Thanks to multiple contributors at Microsoft for this work.

Added support for additional advanced texture operations, including:
Raw Gather, Programmable Offsets, SampleCmpLevel, and RWTexture2DMSAA.

Added new QuadAny/QuadAll intrinsics to help with writing quad-uniform control flow.

Added [WaveOpsIncludeHelperLanes] pixel shader entry attribute, changing the
behavior of wave ops to treat helper lanes as active lanes.
2022-02-15 11:38:42 -08:00
Natalie Chouinard 20ccd72e80
[spirv] Append template params to UserTypeGOOGLE (#4248) 2022-02-14 15:00:01 -05:00
Jaebaek Seo 13a9c7de74
[spirv] add predefined macro '__spirv' (#4225) 2022-02-02 10:47:48 -05:00
Jaebaek Seo 85947a043e
[spirv] add documentation for inline SPIR-V (#4201) 2022-01-25 12:24:11 -05:00
Jaebaek Seo 1196af4137
[spirv] use OpIsHelperInvocation for [[vk::HelperInvocation]] (#4172)
For Vulkan 1.2 or less, we must not use HelperInvocation BuiltIn
decoration. Instread, for a variable with `[[vk::HelperInvocation]]`
attribute, we have to use `OpIsHelperInvocation` instruction:
- Create a variable (with Input storage class)
- In the module initialization, execute `OpIsHelperInvocation`
  instruction and store the result in the variable
2022-01-06 14:19:10 -05:00
Natalie Chouinard dc4c6efca6
[spirv] Use t shift for combined image samplers (#4170)
When command-line shift values are provided for binding numbers inferred
for register types, always use the t shift value for combined image
sampler resources, and ignore the s shift value.

Fixes #4166
2022-01-06 12:14:54 -05:00
Jaebaek Seo b6360c6c0c
[spirv] handle hull shader OutputPatch (#4119)
The existing code creates a temporary variable with Output storage class
for the parameter with OutputPatch type for the patch constant
functions. However, this adds an additional output stage variable and
consumes more locations. In addition, it can also change the rendering
result depending on the driver.

This commit removes the additional output stage variable and use the
actual output stage variables for the argument passing for the
OutputPatch. This is correctly working because the output stage variable
keeps the output value for all invocation id and we can simply reuse it.
2021-12-02 23:54:58 -05:00
Yuriy O'Donnell f836555907
[spirv] Add Vk::RawBufferLoad intrinsic (#4069)
* Only support raw buffer (i.e. HLSL ByteAddressBuffer) style loads of single uint-s
* Always use 4 byte alignment for loads (same as HLSL ByteAddressBuffer)
* Add PhysicalStorageBufferAddresses capability and KHR_physical_storage_buffer extension when needed
* Promote memory addressing model to PhysicalStorageBuffer64 when needed
* Add custom alignment support to SpirvLoad
* Add createUnaryOp() overload that takes SpirvType
* Add getPhysicalStorageBufferType()
* Add documentation and a test case for the new intrinsic
2021-11-17 15:41:54 -05:00
Jaebaek Seo becb9c816e
[spirv] separate resource from cbuffer (#4040)
The current DXC does not separate the resources from a cbuffer, which
results in a OpTypeStruct including resources. We have to separate the
resources from a cbuffer.

Fixes #4019
2021-11-02 10:17:03 -04:00
Chris B b55eb88561
Convert cmake-predefined-config-params to cache (#3918)
CMake supports passing in CMake scripts via the `-C` command line
option, which can set CMake cache variables to initialize options
before the first CMakeLists file is processed. This is a portable and
shell-agnostic way of supporting what the
`cmake-predefined-config-params` file is used for.
2021-10-05 17:49:07 -05:00
Greg Roth 61bd18526d
Allow variable offsets to gathers (#3764)
Mostly reverts the change that added an error when offsets were not
immediate or out of range for gather operations. More research suggests
this error was not required and it broke some existing shaders

Fixes #3738
2021-05-11 17:04:58 -07:00
Junda Liu d31f05ffd6
[spirv] Add VK_KHR_variable_rate_fragment_shading SPIR-V support (#3664)
Change the mapping of SV_ShadingRate from FragSizeEXT (VK_EXT_fragment_density_map) to PrimitiveShadingRateKHR/ShadingRateKHR (VK_KHR_variable_rate_fragment_shading).
2021-04-12 10:06:49 -04:00
Tex Riddell 6244ab8337
Validator/Dxil version error improvements (#3623)
- Move validator/dxil version checks up-front
  These should fail first rather than side effects of trying to validate
  details of a version we don't support.
- Improve message for unsupported validator or dxil version
  These errors are most likely if compiling separately from validation
  and failing to override the validator version properly, or running on
  an external validator that doesn't support a newer dxil.
- Use dxil version from metadata for DxilModule when loading,
  rather than just setting it to minimum based on shader model.
- Remove TODO from validator messages that shouldn't be there
2021-03-25 14:03:31 -07:00
Greg Roth 3bd5f9ccfa
Errors on non-immediate load/gather offsets (#3283)
Gather operations that take four separate offsets are meant to allow for
programmable, non-immediate values. This removes them from the immediate
and range validations by giving the immediate versions their own opcodes
For these intrinsics and loads, errors are generated when offsets are non-literal
or out of range. These largely use the slightly altered validation paths that the
sample intrinsics use.

Reword error when texture access offsets are not immediates to be
more all encompassing and grammatical.

Incidentally remove duplicate shaders being used for the validation
test from the old directory while identical copies in the validation
directory went unused. Redirected validation test to the appropriate
copies. This is consistent with the test shader re-org's stated intent

Sample operations have a maximum of 3 args, but gather has a maximum of
two since it always operates on 2D images. So gather operations only
pass in two offset args to the offset validation, which resulted in an
invalid access.

Rather than adding a specialized condition to evade this, just iterate
over the number of elements in the array. For sample it will be 3 and
for gather 2 and it will still check for expected undefined args
appropriately.

For the offset legalization pass, the opcode is used to determine the
start and end of the offset args

Only produce the loop unroll suggestion when within a loop

Base error line on call instruction instead of source of the offset

Sort by location in source when possible and remove duplicates

Adapt tests to verify and match these changes

Fixes #2590
Fixes #2713
2021-03-02 18:42:09 -08:00
Tex Riddell 19360a8fa6
Validate CBuffer size to max of 65536 bytes (#3507) 2021-03-02 16:34:35 -08:00
seppala2 03cc4f8663
[spirv] Add vk::image_format attribute for Buffers, RWBuffers and RWTextures (#3395)
According to Vulkan specification when using `OpImageRead/OpImageWrite`, the `OpTypeImage` (`Buffers`, `RWBuffers`, `RWTextures`) must have a format that matches the format on the API side, unless the StorageImageReadWithoutFormat/StorageImageWriteWithoutFormat is added and `Unknown` is used as the format.

This pull request addressess #2498 for the format part by adding an attribute `[[vk::image_format("<image format as spelled in SPIR-V spec>")]].` Example of the syntax:

```
[[vk::image_format("rgba8")]]
RWBuffer<float4> Buf;

[[vk::image_format("rg16f")]]
RWTexture2D<float2> Tex;

RWTexture2D<float2> Tex2; // Works like before
```

The `image_format` only applies to **global variables** of type `Buffer`, `RWBuffer`, `RWTexture`. For variables and function parameters it is propagated by the inlining pass in legalization. This required a small change to one of the passes in SPIRV-Tools, that should be also checked by someone more familiar with the codebase: https://github.com/KhronosGroup/SPIRV-Tools/pull/4126

Note that this does not fix the handling of unspecified format (that case still works like before, using `R32f`, etc. based on the type in shader), although it should be still fixed to add the
StorageImageReadWithoutFormat and/or StorageImageWriteWithoutFormat and use Undefined. But I think the ability to specify the format is more urgent.

Design note from Jaebaek:
Since the `image_format` attribute only applies to **global variables**, under the DXC architecture
only `DeclResultIdMapper` can check the attribute when it handles `VarDecl`s. It means
we have to pass the `image_format` information to `LowerTypeVisitor` because it cannot access to
`VarDecl`. In order to pass the `image_format`, we use `SpirvContext` that can be accessed by
`SpirvEmitter` and all visitors. We use `SpirvVariable` to `spv::ImageFormat` mapping because the
attribute only applies to **global variables** (not to image types).
See how we use `llvm::DenseMap<const SpirvVariable *, spv::ImageFormat> spvVarToImageFormat`.
2021-03-01 10:07:40 -05:00
Greg Roth deacf03358
Add used by atomics resource flag (#3513)
To identify resources that are used in 64-bit atomics operations in order to catch invalid use of heap resources
2021-02-26 11:25:28 -08:00
Greg Roth 5fbaf73466
Error for groupshared outside of compute (#3472)
groupshared variables shouldn't be allowed outside of compute and
compute-like shaders. This adds a validation error when such
variables are used.

Add shader mask where groupshared are used

Correct several tests that used groupshared incorrectly

Incidental fix to atomics tests where the special case initializations
might have allowed the threads that failed to write to proceed
before the write took place and read the improperly initialized values

Changed up the assignments to avoid write collisions and be more
readable

Fixes #2603, #2677
2021-02-24 15:22:29 -08:00
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
Tex Riddell 7c9e487afd
Implement IsHelperLane() (#3382) 2021-01-22 12:45:18 -08:00
Greg Roth 61c6573842
Remove early aspirational language about DXIR standard (#3375)
Early on, the plan was to document DXIR similar to DXIL. There are no
current plans to do so. This updates the documentation to reflect that.
2021-01-20 17:02:25 -08:00
Vishal Sharma b0820241c1
Update validation rule info in hctdb.py (#3311) 2020-12-10 17:27:07 -08:00
Greg Roth d574d27c1f
Implement Shader Model 6.6 (#3293)
This is the work of many contributors from Microsoft and our partners.
Thank you all!

Add support for 64-bit atomics, compute shader derivatives, dynamic
resources (from heap), 8-bit Packed Operations, and Wave Size.
All of these require compiling with 6_6 targets with just a few
exceptions. Each of these features include unittests and Execution
tests.

64-bit atomics add 64-bit variants of all Interlocked* intrinsic
operations. This involves changing some of the code that matches
intrinsic overloads to call instructions. Also adds a few float
intrinsics for compare and exchange interlocked ops which are available
for all shader models 6.0 and up.

Compute shader derivatives adds dd[x|y], CalculateLevelOfDetail, and
Sample operations that require derivatives to compute. QuadRead
operations have been allowed in compute from 6.0+ and tests are added
for them here.

Dynamic resources introduce global arrays that represent the resource
and sampler heaps that can be indexed without requiring root signature
representations. This involves a new way of creating and annotating
resource handles.

8-bit Packed operations introduces a set of intrinsics to pack and
unpack 8-bit values into and out of new 32-bit unsigned types that can
be trivially converted to and from uints.

WaveSize introduces a shader attribute that indicates what size the
shader depends on the wave being. If the runtime has a different wave
size, trying to create a pipeline with this size will fail.
2020-12-02 21:10:44 -08:00