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

4731 Коммитов

Автор SHA1 Сообщение Дата
Chris B 09e4742436
Add license and readme for HLSL header library (#6872)
As we're starting to grow some new language features that are more
convienent to write in headers, having a set of headers that are
distributable without attribution requirement is a big win. These
headers will all be contributed under the Apache 2.0 with LLVM exception
license to align with upstream LLVM and provide apporpriate protections.
2024-09-16 11:24:36 -05:00
Antonio Maiorano 05334a70d3
Fix CMake gen failing when HLSL_BUILD_DXILCONV=0 (#6912)
Target dxildll depends on DxcRuntimeEtw, so make sure to add this
target, even when HLSL_BUILD_DXILCONV is false.
2024-09-12 19:04:41 +00:00
Antonio Maiorano f11914c4ef
Fix ASAN UAF in DxilConditionalMem2Reg (#6910)
ScalarizePreciseVectorAlloca would iterate over all instructions, then
for each instruction use, would iterate and potentially erase the
instruction. If the erased instruction was the immediate next
instruction after the alloca, this would invalidate the outer
instruction iterator. Fixed by collecting the allocas in a vector first.
2024-09-11 17:57:50 -04:00
Nathan Gauër b400c7281e
[SPIR-V] Fix isfinite/isinf generation for mat/buffers (#6905)
In some cases (matrices for ex), we generated the wrong result type for
isinf/isfinite.

Fixes #6783

Signed-off-by: Nathan Gauër <brioche@google.com>
2024-09-10 17:52:32 +02:00
Nathan Gauër efdee6c994
deps: update spirv-headers/spirv-tools (#6906)
Pull latest revision of both repositories.

Fixes #6804

Signed-off-by: Nathan Gauër <brioche@google.com>
2024-09-10 17:51:53 +02:00
Steven Perron 496482c4e4
Enable vk-allow-rwstructuredbuffer-arrays, and remove option (#6903)
We have done all of the development on this feature that we will do.

We cannot handle Multidimentional arrays of these buffers because Vulkan
does not allow it.

We cannot handle arrays that are in a struct if the counter variable is
used. We have tests cases to identify those cases.

Closes https://github.com/microsoft/DirectXShaderCompiler/issues/5440
2024-09-09 20:32:17 -07:00
Cassandra Beckley ca2e67d29e
[SPIRV-V] Implement Shader Model 6.8 Expanded Comparison Sampling (#6854)
Compile `SampleCmpBias` using `OpImage*SampleDrefImplicitLod` and
`SampleCmpGrad` using `OpImage*SampleDrefExplicitLod`.

The existing handlers for `CalculateLevelOfDetail` and
`CalculateLevelOfDetailUnclamped` work for the
`SamplerComparisonSampler` overload, so no new code is needed other than
tests.
2024-09-09 18:42:24 +00:00
Steven Perron 937c8c8811
Add linkage capability based on decorations (#6900)
We currently add the linkage attribute only if there are no extry
pointer. However, there are cases where we may want an extry point with
an exported function.

This commit add the linkage capability any time it sees the linkage
attribute decoration. Note I do not add the linkage attribute all of the
time and leave it to the capability trimming pass because having this
capability with vulkan shaders is generally illegal, and I don't want
the unoptimized code to fail validation.

Fixes #6738
2024-09-06 14:30:08 -04:00
Xiang Li 0fd84aa814
[Test] Add validator version check for tests (#6901)
This change adds validation version check for the tests.

This is for fix tests fail when running on different version of
validator.
2024-09-05 17:47:30 -07:00
Xiang Li 9e039e254e
Move dxil.dll to DXC repo. (#6866)
Build dxil.dll in DXC repo.
It will shares same validator code with dxcompiler.dll.

Fixes #6769
2024-09-05 11:27:19 -07:00
Xiang Li 72f306c883
[ViewID] build viewid mask for primitive output (#6886)
Currently, viewid mask for primitive output is always empty. This change
will fix it by treat entry as PC entry and skip output when it is not
what is checking.

For #6817
2024-09-05 18:09:06 +00:00
Shaikh Yaser 663785ad7c
Typo fix in Readme file (#6890)
Replaced 'As of of' to 'As of'
2024-09-03 09:17:54 -07:00
Jeff Noyle bf24b7a54d
PIX: Rationalize UAV generation (#6883)
The impetus for these changes was unexplained crashes in a display
driver while attempting to create a debug-instrumented shader for PIX.
The heart of it is the new test in pixtest.cpp: use the compiler to
generate a raw UAV, and then compare the generated DXIL with what PIX
generates for the same purpose.
Some of the PIX passes need only one UAV for a module, but some need two
or more. In the latter case, the previous code was a bit loose about
what it was doing with respect to adding the UAV resource, and creating
its handles for each interested function. Most of the actual changes
herein are to do with that.
Lastly, the PIX UAV is raw at the D3D API level, but the instrumentation
had been doing non-raw writes. No driver seemed to care, but I've fixed
it anyway.
2024-09-03 09:02:07 -07:00
artamonovoleg bb3a0c3641
[SPIR-V] add -fvk-support-nonzero-base-vertex option (#6865)
There is already a workaround for the SV_BaseInstance inconsistency
between HLSL and SPIR-V. The same issue applies to SV_BaseVertex, but no
such option is available. This commit adds the
-fvk-support-nonzero-base-vertex option, which behaves the same as the
-fvk-support-nonzero-base-instance option.
2024-09-03 09:25:44 -04:00
Steven Perron b766b43267
Process subrecord decls in spirv backend (#6879)
The spir-v backend does not recurse into structs defined in struct in
doRecoredDecl. This causes us to miss some declarations.

Fixes #5916
2024-08-28 16:56:06 -04:00
Xiang Li 6c99ecfc8a
[Dump] Fix PSV dump issues. (#6881)
1. Number of SemanticIndex should match number of rows instead of number
of columns.
2. Mesh shader could have ViewID mask for Primitive output.

For #6817.
2024-08-28 12:24:18 -07:00
Xiang Li 6227e57c25
[Build] Update to clang-18 for linux clang pipeline (#6876)
This is to work around LeakSanitizer issue 'LeakSanitizer has encountered a fatal error.'

For #6769
2024-08-26 10:09:55 -07:00
Steven Perron 9c6b2c1275
Remove invalid assert in literal visitor (#6875)
The code has an assert when processing an OpLoad in the literal visitor
to make sure that the result of the load is not a literal type. This is
not always true. If there is a compiler-generated, temporary variable
that gets its type from a literal, then the result type of the load will
have to be decuded by the literal visitor. That is not always possible.

However, the code already handle this situation correctly. If the result
of the load is a literal type, then the function will return true
without doing anything because `canDeduceTypeFromLitType` will return
false, as it should.

Fixes #6798
2024-08-23 09:47:43 +02:00
Steven Perron 7dcf2b483d
Add SPIRV version macros to DXC (#6874)
With inline spir-v, it becomes important for users to know which version
of SPIR-V is being targeted. They may need to generate different code
depending on the version.

This commit add these `__SPIRV_MAJOR_VERSION__` and
`__SPIRV_MINOR_VERSION__` to the compiler.
2024-08-22 10:01:27 -04:00
Xiang Li 8a677d22cb
[NFC] add utils for PSV. (#6869)
Add init functions to help build
PSVSignatureElement0/PSVRuntimeInfo/PSVResourceInfo.

Add print function for DxilPipelineStateValidation.

Add new option -dumppsv to dxa for testing.

For #6817.
2024-08-21 15:24:52 -07:00
Greg Roth 9018970f26
Correct build exclusion in gitignore (#6870)
The build* entry in .gitignore was intended to exclude any build
directories with whatever suffixes a developer might use for various
build configurations. The way it was written made it exclude any file
that had build in the name, which was more aggressive than needed.

By adding a leading slash, it is limited to items in the git root
directory. By adding a trailing slash, it is limited to directories in
the root directory. This accomplishes the intended exclusions as
narrowly as possible.

(I swear I'm not trying to win a bet on writing the longest description
of a two character change in history)

Fixes #4733
2024-08-20 15:24:50 -07:00
Xiang Li 913ae2ce86
[Validator] enable validator hash by default. (#6853)
The changes affect both the internal validator (used within the DXIL
compiler) and external validation tools. Now, by default, validator hash
is enabled for all validation processes.

#6863 was created for tracking the skip hash discussion.

This is second step for #6808.
Fixes #6857
2024-08-16 14:24:32 -07:00
Xiang Li 0e7591a6ee
[NFC] Move DxilValidation to a dedicated folder. (#6849)
Move DxilValidation out of HLSL.
Also move code to validate dxil container into
DxilContainerValidation.cpp from DxilValidation.cpp.

This is a preparatory step for #6817.

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-08-13 17:33:09 -07:00
Antonio Maiorano f810e92e72
scalarrepl-param-hlsl: fix zero replacement in entry (#6855)
This is the same fix as was done in
https://github.com/microsoft/DirectXShaderCompiler/pull/6516 except that
this is for replace uses of zero-init for instructions in the entry
block.
2024-08-12 13:24:31 -04:00
Steven Perron 06da989c4a
[SPIRV] Add vulkan memory option to DXC (#6848)
Some recent features require the vulkan memory model. We need a way to
support it in DXC. This commit adds an option to enable the Vulkan
memory model. The generated code will not change, but the compiler will
call the upgrade-memory-model pass in spirv-opt to generate the correct
code.

The expectation is that new code that requieres the vulkan memory model
can be written using the vulkan memory model, and then have the pass
update other references.

This change will undo the fix for #6066. The device scope in GLSL450 was
not a real device scope. It corresponds to QueueFamily scope in the
Vulkan memory model. We will start to use that scope for the atomic
operations in order to keep the behavoiur of the atomics the same
between the two memory models.

Haveing a true device scope atomic will not be possible with DXC. We
should be able to do something better when atomic operations are
implemented in clang.

Fixes #5784
2024-08-08 12:47:52 -04:00
Xiang Li 84f68ed1a4
Open source DxilHash (#6846)
This pull request introduces the open-source implementation of hashing
functionality for DXIL containers.

DxilHash.cpp: Implements DXBC/DXIL container hashing functions.

This is first part for #6808
2024-08-07 11:43:10 -07:00
Cassandra Beckley 99f2d49810
[SPIR-V] Implement Shader Model 6.8 Extended Command Information (#6843)
Compile `SV_StartVertexLocation` as `BaseVertex` and
`SV_StartInstanceLocation` as `BaseInstance`.
2024-08-07 15:32:53 +02:00
Steve Urquhart 1e782479c6
[SPIRV] Generate DebugFunctionDefinition in real function instead of wrapper (#6758)
This PR moves the DebugFunctionDefinition instruction from the SPIR-V
wrapper to the real function. This supplies debugger users with greater
accuracy.
2024-08-07 15:29:03 +02:00
Nathan Gauër b52f9ba477
[SPIR-V] Don't flatten arrays during legalization (#6767)
When struct contains opaque resources, we must legalize the SPIR-V to
move those resources out of the struct (Vulkan doesn't allow composite
to store opaque resources).
Before this change, any resource array would also be flattened due to
the pass flattening everything by default.

Patched SPIRV-Tools to allow some level of selection in what we flatten.
Not perfect, as we would flatten all arrays or all composites and cannot
pick only one variable to flatten, but for now this should be enough.

Fixes #6745
Signed-off-by: Nathan Gauër <brioche@google.com>

---------

Signed-off-by: Nathan Gauër <brioche@google.com>
2024-08-06 10:09:34 -04:00
Xiang Li 8652894e69
[Validator] Remove the pModule input for RunInternalValidator (#6845)
This change ensures that data validation occurs within the container
itself,
rather than relying on the module—especially since the module may be
modified during container assembly.

Furthermore, simplifying the validator’s interface would be an added
benefit.
2024-08-05 10:43:44 -07:00
Xiang Li cc6c6656d5
[DOC] update release note for remove WaveMatrix. (#6842)
Add remove WaveMatrix in release note.
2024-08-02 06:51:33 -07:00
Antonio Maiorano 91b348912b
Add llvm assertions trap and no strings (#6838)
Add option LLVM_ASSERTIONS_NO_STRINGS
    
When defined, drop the stringized expression, __FILE__, and __FUNCTION__
    strings passed to llvm_assert. This dramatically reduces the binary
    size, which is useful when enabling assertions in a non-debug build.

   Add option LLVM_ASSERTIONS_TRAP
    
When enabled, this forces asserts to always trap. Currently, on Windows
    asserts calls RaiseException, while they trap on non-Windows. This
    option makes the assertion behaviour consistent across platforms.
2024-08-01 15:37:02 -04:00
Minmin Gong 71d6766881
Fix the SAL of IDxcResult::GetOutput (#4487)
The ppOutputName parameter can be nullptr and can return nullptr. Change
its SAL to _COM_Outptr_opt_result_maybenull_.

Related to #4149 .
2024-08-01 12:05:56 -07:00
Devon Loehr 5ecee0b599
[NFC] Remove implicit `this` capture in lambdas (#6761)
When declaring a lambda with a value-capture default [=, ...], the this
pointer is implicitly captured by value as well. This results in
potentially-unintuitive behavior and has been deprecated in C++20. It
produces a warning in newer versions of clang
(https://reviews.llvm.org/D142639).

This PR makes the implicit captures explicit, preventing the warning. It
does not change the compiled code at all, since it's just removing some
syntactic sugar.
2024-08-01 11:50:30 -07:00
Xiang Li 8b33431849
Remove WaveMatrix (#6807)
Remove WaveMatrix from main branch.
The DXIL operations are changed to Reserved to avoid affect DXIL
operation ID.
2024-08-01 10:52:13 -07:00
David Neto d324261642
Reassociation: fix counting of constant multiplicative factors (#6830)
In the middle of rewriting expressions like (A*B + A*C + D) to pull
common factor A out, the algorithm finds that there's actually only one
A. This is unexpected, and it fires an assertion.

This can occur when A is a constant, and constant -A also appears in the
terms somewhere else.

There is no harm in this situation, however, because the algorithm then
creates an addition-tree, but with a single element, and that's still
correct.

This bookkeeping issue was fixed later in LLVM, at
95abfa35d6

Unfortunately the associated test doesn't translate cleanly to DXC-era
LLVM. I've added test case reduced from our original case.

Fixed: #6829
2024-08-01 11:41:05 -04:00
Steven Perron 4fabd7a318
[SPIRV] Implement Gis option for spir-v (#6840)
Fixes #3331
2024-07-31 19:55:36 -04:00
Steven Perron 01fa18a57b
[SPRIV] Allow vk-invert-y for MS shaders (#6839)
Fixes #3154
2024-07-31 13:53:48 -07:00
Steven Perron bb373fb88e
[spirv] Avoid adding spec and push constants to global ubo (#6832)
The code the decides which global variables to include in the implicit
global cbuffer does not check for spec constant or push constant. They
end up being incorrectly include in it, causing problems.

The solution is to add those to the type of variable that should be
skipped.

Fixes #4542
2024-07-31 08:40:01 -04:00
Xiang Li ef043e90f3
Fix warning when use implicit launch type. (#6837)
By default, the launch type should be set to ‘Broadcast’ when diagnosing
barriers. However, the current behavior sets the default launch type to
‘Invalid,’ resulting in warnings when the launch type is not explicitly
specified as an attribute.

To address this issue, we’ll adjust the default setting to ‘Broadcast’
and thereby resolve the problem.

Fixes #6836

---------

Co-authored-by: Damyan Pepper <damyanp@microsoft.com>
2024-07-30 17:16:06 -07:00
Antonio Maiorano b6f7ff81e9
Use llvm_assert/assert.h on all platforms, not just Windows (#6815)
This makes it possible to define how assert works on all platforms. The
header was already being included by String.cpp, and was already
designed to work for non-Windows platforms.

Also modify the non-Windows llvm_assert to emit the assertion message to
stderr and trap. We cannot call standard assert as we are overriding it
via include dirs, so there's no way to include the standard one and call
it.
2024-07-29 20:42:09 +00:00
David Neto 9ef04817ef
Avoid OOB index when fixing constant array-initialization (#6825)
If the index on a constant store into an array is negative or out of
bounds, that's an error, but shouldn't make the compiler index a vector
out of bounds.

Fixed: #6824
2024-07-26 18:44:08 -04:00
David Neto aa048b81ed
Fix escape in Python string in lit.cfg (#6826)
Change Python regexp ' clang\+\+ ' to ' clang\\+\\+' We're trying to
match fixed strings like ` clang++ `, but `\+` is not a valid Python
escape sequence. Use `\\+` so the regexp machinery sees `\+`
2024-07-26 18:43:38 -04:00
Xiang Li 716e74100a
[NFC] create static lib for validator. (#6811)
A static lib dxcvalidator is added.
The validators in dxcompiler and dxrfallbackcompiler links dxcvalidator.

Fixes #6790

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-07-26 14:46:07 -07:00
Jesse Natalie bc91bc57c4
Reserve some RDAT/DXIL enum values used by the mesh node preview (#6818)
Let's ensure we don't accidentally stomp on these. If we do choose to
break them, it should be intentional, not accidental.
2024-07-26 14:23:38 -07:00
Antonio Maiorano ef4f44de20
Fix MSAN use-after-free in SmallVectorImpl dtor (#6819)
Hit when compiled with `-fsanitize-memory-use-after-dtor`. This was
fixed upstream here:

527352b6ac
This applies the same patch.
2024-07-26 13:38:15 -04:00
Xiang Li 0777bff092
[Doc] Release note update for 1.8.2407. (#6821)
Add note for loop structurizer fixes.
Fix the ReleaseNotes.md path.
2024-07-25 10:31:34 -07:00
David Peixotto 83e4cd4084
Fix crash in constant initializer lowering for global variable. (#6820)
In #6814, we modified the compiler to avoid generating bad code in some
cases for array initializers. However, this caused a crash in the case
where the initializer does not use a GEP expression for addressing
because the `GV` will be null.

I considered setting `GV` to the value in the `store` pointer operand,
but it looked like `GV` was also checked elsewhere for null and did not
want to modify the behavior of the code in other places.

The fix is to check if we found a global variable before validating the
array case.
2024-07-25 09:19:04 -07:00
Steve Urquhart e0fbce714d
[SPIRV] Generate DebugTypeMatrix (#6757)
When the OpenCL.DebugInfo.100 debug info was implemented, there was no
DebugTypeMatrix. Now that NonSemantic.Shader.DebugInfo.100 has been
merged, we should use DebugTypeMatrix. This PR corrects that oversight.
2024-07-24 11:13:00 +02:00
Antonio Maiorano 4a5253d003
Fix assertion when compiling array of struct init (#6814)
In CGHLSLMSFinishCodeGen's BuildImmInit, when initializing an array, if
the init value type doesn't match the array element type, we must bail
and instead, have it inject a call to the global ctor. Without this,
builds with asserts enabled would assert later with "Wrong type in array
element initializer". In non-assert builds, this invalid IR would be
removed, and valid code emitted.

See https://github.com/microsoft/DirectXShaderCompiler/issues/5294
2024-07-23 20:46:16 +00:00