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

3783 Коммитов

Автор SHA1 Сообщение Дата
Jeff Noyle e77249a142
PIX: Fix overactive assert in value-to-declare pass 2023-01-10 14:05:20 -08:00
Jeff Noyle d7ce4e5399
PIX: Remove per-instruction disassembly in annotation pass output 2023-01-10 13:45:32 -08:00
Jeff Noyle 32d3debd5a
PIX: Account for alignment when computing member offset (#4903)
* Account for alignment

* Use llvm::RoundUpToAlignment
2023-01-09 17:24:33 -08: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 2b67226ddd
Fix argument translation for C++ member operators (#4916)
Previous to this change if we modified arguments for C++ operator calls
we were sliding the modified parameters in the argument list relative to
where they should have been. This results in mismatched arguments in
calls and all sorts of nastiness.
2023-01-06 15:45:00 -06:00
Nathan Gauër 60530e57eb
misc: update submodules (#4909) 2023-01-06 09:49:49 -08:00
Laura Hermanns b0a96c2a47
[SPIR-V] Fix dangling pointer to previous field in 'LowerTypeVisitor::populateLayoutInformation()' (#4913) 2023-01-06 11:37:06 +01:00
Chris B ac3a6ae9f4
Enable building with ninja through Visual Studio (#4889) 2023-01-05 23:07:36 -06:00
Noah Cabral 57483a3183
Fix typo in README.md (#4912) 2023-01-05 11:44:28 -08:00
Chris B 2168dcb4fb
Clean up and rework DXIL library depencencies (#4877)
* Clean up and rework DXIL library depencencies

This change reworks the dependency specifications for the DXIL*
libraries. Many of these libraries had over and under specified
dependencies.

This also collapses the DxilRDATBuidlder into the DxilContainer library
to remove the cyclic dependency between the two libraries.

* Break assert dependency between DXIL and Analysis

In assert builds the DXILModule constructor was creating forced bindings
to debugging methods that are often used from the debugger. This forced
binding is useful, but doesn't need to live in the DXIL library.

To break the dependency I've moved the code into Analysis. I've also
made that code only included when building with MSVC. When using other
compilers `__attribute__((used))` can be applied to the function via the
`LLVM_DUMP_METHOD` annotation to have the same effect.
2023-01-03 10:04:22 -06: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
Chris B 93543b7b4c
Fix copy-in/copy-out parameter passing (#4900)
This change fixes HLSL's copy-in/copy-out parameter passing. Before
this change we skip emitting copies for all local variable parameters,
which results in code correctness issues.

With this change, we do a poor-man's alias analysis walking each local
variable back to either an argument or an alloca. If it tracks back to
an argument marked noalias we can skip the copy. If it tracks to an
alloca, we skip the copy for the first parameter that tracks to that
alloca, and emit the copies for any subsequent parameters.

This change does have one side-effect that I don't understand. It
results in changing the ordering of some of the disassembly output. I
suspect that is caused by something in the disassembly being
order-dependent but haven't investigated fully.
2023-01-03 10:02:14 -06:00
Nathan Gauër 88a2888112
build: disable LLVM_ENABLE_TERMINFO by default. (#4908)
Having this enabled makes dxc depends on ncurses5. This is required by
LLVM when supporting colored message output, but DXC doesn't supports it
for now.

Fixes #4892
2023-01-03 16:59:11 +01:00
FantasqueX a0b6fc1028
Add RISC-V 64 bit (#4894)
- Add riscv64 target to config.guess
- Update config-ix.cmake to update config-ix.cmake to support riscv64
- Tested on riscv64
2022-12-30 08:22:52 -08:00
Helena Kotas 2a9052a962
Refactor ExecutionTests into a separate dll (#4905)
ExecutionTests are currently compiled into clang-hlsl-tests.dll together with all of the other DXC unit tests. Later in the code pipeline the ExecutionTests are getting transformed into HLK tests which have different dependency constraints than the clang HLSL tests.

Refactoring ExecutionTests into a separate dll allows us to set its dependencies and build settings accordingly and closely matching those of the HLK test dll. This will help HLK authors to implement the tests with those constraints in mind.
2022-12-29 23:53:21 +00:00
Joshua Batista 65795cfd21
add test to handle preprocessing an already preprocessed file. (#4898)
* add test to not blow up if an already preprocessed file is part of the source, remove assert
2022-12-22 10:03:39 -08:00
Helena Kotas 5decc4aa97
Do not include TestConfig.h for all HLK build (#4887)
TestConfig.h is not available in HLK test build.
The test library uses _HLK_CONF define to distinguish
between Exec tests-only and HLK-only code.
2022-12-16 10:41:38 -08:00
Jeff Noyle 20bb3d0228
PIX: Modify root sigs in place (plus fix root sig memory leak) (#4876)
PIX is unique in that it needs to deserialize, modify and then reserialize root sigs. The focus of this checkin is adding such modifications to PixPassHelpers.cpp. (This closes a gap in PIX support: PIX can now support shaders that use dxil-defined and attribute-style root signatures.)

But this required some work outside of the purely PIX-focused areas. Deserialized root sigs are described by a C-like structure with embedded arrays that are new/delete-ed by routines in DxilRootSignature.cpp. Since modifying these structs requires more new/delete calls, I chose to add a new entry point in DxilRootSignature.cpp to do the bare minimum that PIX needs: extend root params by one descriptor. This approach keeps all those raw new/deletes in one file.

I found a leak in DxilRootSignatureSerialzier.cpp, which I fixed. There appear to be no unit tests that exercise this path. I welcome feedback on adding one.

There were other leaks in class CVersionedRootSignatureDeserializer, but this class is unused so I deleted it.

Oh, and there are bazillions of commits because I was cherry-picking from a recent change (#4845) as it eveolved, since I needed that change and this to test PIX.
2022-12-15 16:36:09 -08:00
Joshua Batista ee0994e58e
add barycentrics ordering check onto existing barycentrics test (#4635)
* add barycentrics ordering check onto existing barycentrics test, with extra shader
2022-12-15 15:52:51 -08:00
Chris B ffe931e467
Enable 2021 operator intrinsics in older modes (#4882)
This enables the `select`, `and`, and `or` intrinsics in older HLSL
language modes to ease transitioning to HLSL 2021.
2022-12-15 09:06:35 -06:00
Helena Kotas e7aac8e0f5
Include TestConfig.h only if DEFAULT_TEST_DIR is not defined (#4884)
TestConfig.h is not available in HLK test build.
This change enables skipping of the include.
2022-12-15 09:02:02 -06:00
Tex Riddell 6acd11bfc3
ConvertFloat32ToFloat16: Use DirectXMath conversion functions (#4855)
Custom half <-> float conversion functions had problems in multiple scenarios.  This PR changes them into a wrapper, using the DirectXMath conversion functions instead.
2022-12-14 17:40:03 -08:00
Tex Riddell 5c4d3b6eb7
hcttestcmds: Fix error handling and support skip cleanup on failure (#4879)
Fix problem with expression under :failed subroutine, and preserve Failed variable on endlocal in :cleanup subroutine.

Use environment variable HLSL_TESTCMD_CLEANUP_ON_FAILURE to drive whether hcttestcmd cleans up temporary files on failure.
Defaults to 1 (true) unless it's already set.
You can set it to 0 to disable cleanup when the test fails.

Fix originally intended behavior for -Vi test and check files for cleanup.
2022-12-14 16:45:02 -08:00
Chris B aac8727291
Update all the HLSL tests that rely on HLSL 2018 (#4878)
This updates all the tests cases that rely on HLSL 2018 behaviors that
will break if the default HLSL version updates to 2021.

These tests are updated to be passed the HLSL 2018 version so they
continue testing and working under the same behaviors.
2022-12-14 14:56:17 -06:00
Chris B 45eec33ad4
Backport -ftime-trace from upstream llvm & clang (#4873)
* Backport -ftime-trace from upstream llvm & clang

This change back-ports the -ftime-trace feature implemented by Aras
Pranckevičius (@aras-p) into DXC.

Aras has a great blog post describing the motivaiton for this feature
and how to use it (see:
https://aras-p.info/blog/2019/01/16/time-trace-timeline-flame-chart-prof
iler-for-Clang/).

As shaders are getting more and more complex we need better timing data
for ourselves as compiler writers and our users as HLSL writers to know
how to improve compile times of complex shaders.

This implementation is a starting point to give us data to help drive
our efforts to improve compile-time performance.

Because DXC's LLVM is very far removed from the version of LLVM the
patch was originally written for this change is not strictly a
cherry-pick of
https://github.com/llvm/llvm-project/commit/d880de2d19d46f7cfea7aa593602
458440bc1e8d. Instead this change is a manually applied and
reconstructed patch with significant alterations along the way. The
alaterations are performed by myself, but credit for the patch remains
with @aras-p.

Patch by Aras Pranckevičius (@aras-p).
2022-12-14 10:15:28 -06:00
Nathan Gauër 645f9ee906
Fixing a [[nodiscard]] error in DXC (#4860)
This was found while moving to c++20 by an anonymous internal contributor.
Integrating the finding to mainline, and was already fixed upstream by @rnk (dd870f6929ee)

std::unique iterates on elements of the container, and removes all but
the first element matching the predicate, but does not resize the
container. This means the following code doesn't assert.

```cpp
    std::vector<int> v = { 1, 1, 2, 2, 3, 3 };
    assert(v.size() == 6);
    std::unique(v.begin(), v.end());
    assert(v.size() == 6);
```

The function returns a past-end iterator, and all the undefined elements
are at the end of the container, meaning we can safely erase them, and
fix the container size.

Signed-off-by: Nathan Gauër <brioche@google.com>
2022-12-14 16:16:35 +01:00
Chris B b42bbdd722
Add -enable-lit option to hcttest (#4869)
This patch attempts to translate HCTTest options to LIT build targets.
Since HCTTest and lit break up tests differently the mapping isn't quite
the same, but it should be close enough.

Before we can migrate our automation builds to using lit we need to
separate out the exec tests so that they can be disabled on the ADO
bots.
2022-12-13 11:39:44 -06:00
Tex Riddell 2c3d965b2f
dxcopt: Support full container and restore extra data to module (#4845)
This modifies IDxcOptimizer::RunOptimizier to accept full DxilContainer input. When full container input is used, this restores some data that is stripped from the module and placed in various other container parts.

Data restored:
  - Subobjects from RDAT
  - RootSignature from RTS0
  - ViewID and I/O dependency data from PSV0
  - Resource names and types/annotations from STAT

Serialization of these to metadata in module bitcode output still requires hlsl-dxilemit step.
2022-12-13 02:54:10 +00:00
Jeff Noyle 21cf36aad1
Fix hitgroup metadata argument order 2022-12-12 17:03:27 -08:00
Chris B 35736a719e
Unbuffer raw_string_stream (#4872)
Double buffering a string stream writing in memory is silly. Upstream
LLVM made this change a few years ago based on analysis that most string
implementations are sane:

https://github.com/llvm/llvm-project/commit/65b1361
2022-12-12 18:06:56 -06:00
Cassandra Beckley 529417b900
[SPIR-V] Fix invalid HLSL in test (#4870)
Previously, the test spirv.legal.sbuffer.counter.method.hlsl would cause errors if compiled with the DXIL backend:

```
../DirectXShaderCompiler/tools/clang/test/CodeGenSPIRV/spirv.legal.sbuffer.counter.method.hlsl:72:19: error: cannot map resource to handle.
    float value = localBundle.getCSBuffer().Consume();
                  ^
../DirectXShaderCompiler/tools/clang/test/CodeGenSPIRV/spirv.legal.sbuffer.counter.method.hlsl:87:5: error: cannot map resource to handle.
    localWrapper.getASBuffer().Append(4.2);
    ^
../DirectXShaderCompiler/tools/clang/test/CodeGenSPIRV/spirv.legal.sbuffer.counter.method.hlsl:72:19: error: local resource not guaranteed to map to unique global resource.
    float value = localBundle.getCSBuffer().Consume();
                  ^
../DirectXShaderCompiler/tools/clang/test/CodeGenSPIRV/spirv.legal.sbuffer.counter.method.hlsl:87:5: error: local resource not guaranteed to map to unique global resource.
    localWrapper.getASBuffer().Append(4.2);
    ^
../DirectXShaderCompiler/tools/clang/test/CodeGenSPIRV/spirv.legal.sbuffer.counter.method.hlsl:104:12: error: local resource not guaranteed to map to unique global resource.
    return localRWSBuffer[5];
           ^
```

Fix these errors by assigning global resources to each local variable.
2022-12-12 19:16:26 +00:00
Chris B ae87945a3c
Move HLSL shift behavior to frontend (#4643)
* [NFC] Move HLSL shfit behavior to frontend

The HLSL bit shift behavior was implemented in constant folding which
alters the semantics of the IR. Alternatively we can implement it in
the front end, leveraging the existing OpenCL code paths.

This results in the same final IR optimization and allows reverting the
ConstantFolder and IR tests back to match LLVM 3.7.

The HLSL shift behavior's optimized behavior is verified in existing
tests like the shift-fold.hlsl test, which is unimpacted by this change.

The big motiviation for this change is heading off subtle bugs. All our
tests cover cases where the shift's size is known at compile time. In
those cases the compiler can resolve the masking behavior
automatically. We have _no_ tests, nor compiler changes that impact
shifts that aren't compile-time known.

This means that prior to this change the behavior of shifting by a
compile-time resolvable value and shifting by a non-resolvable value
likely differs. Since backends often load DXIL and treat it as LLVM IR,
this could cause concerning issues.
2022-12-10 11:42:48 -06:00
Chris B df4ab75c51
[NFC] Address some low hanging fruit UBSan failures (#4833)
* Address some low hanging fruit UBSan failures

Undefined Behavior Sanitizer causes hard failures on runtime conditions that exhibit undefined behavior as defined by C and C++. These issues may not cause immediately identifiable software errors, but the code behavior is dependent on the compiler and runtime implementation. As a result they may become difficult to diagnose or detect errors in the future if the compiler or runtime changes.

This change addresses occurrences of the following undefined behaviors.

* Performing arithmetic operations on null pointers.
* Calling memcpy with a source or destination pointer that is null.
* Calling memset with a destination pointer that is null.
* Assigning an enum a value which is not a valid enum for that enum.
* Reading from unaligned pointers.

After this change, there are 23 remaining undefined behavior failures in the current DXC tests which are less trivial to resolve.
2022-12-10 11:42:25 -06:00
Chris B a34231019c
Enable -ftime-report flag (#4736)
This just surfaces and plumbs throug the -ftime-report clang flag in
dxc.exe.

-ftime-report prints timing data for different parts of the compile
to help identify and track down performance issues. When using the
dxcompiler library interface the output for the time report is returned
as a DXC_OUT_TIME_REPORT buffer.

I've set up the -ftime-report tests to run against the DXC command
line. On Windows this usees the hcttestcmds file, on Linux (and windows
if enabled) this will test through a lit shell suite.
2022-12-10 11:41:14 -06:00
Tex Riddell 650cd7f18f
Remove template/ByteAddressBufferLoad test dependency on high-level opcode (#4864)
High-level opcode is not stable, except within a build.  Tests should not take a dependency on these opcode numbers.
Fixed the template/ByteAddressBufferLoad test that was failing due to this dependency.
2022-12-10 01:36:43 +00:00
Helena Kotas 665e97754c
Update version to 1.7.2212 (#4861) 2022-12-09 21:23:30 +00:00
Tex Riddell bd1dc997f5
Fix enum scope used inside template function. (#4859)
While enums were introduced in HLSL 2017, this code should only be reached
on HLSL if we are HLSL 2021 or greater, so an additional language version
check does not appear necessary here.
2022-12-09 11:04:39 -08:00
Greg Roth 7ad9c9c032
Fallthrough (#4843)
A common source of bugs. Although many of these were harmless, some were
not. By eliminating them and enabling this warning as an error, we won't
add more in the future.


Fixed a real SPIRV bug that required a test update to expect the correct behavior.
SPIRV testing was expecting incorrect results that came from a fallthrough error
2022-12-09 10:13:56 -08:00
Chris B 4d66ec8a9c
Remove assumption that templates are never UDTs (#4752)
* Remove assumption that templates are never UDTs

There was an assumtion in the HLSL sema code that a template
specialization could never be a UDT. This assumption is incorrect now.
I've reworked the code so that we instead assume built-in types are
marked as `implicit` (which they all should and seem to be).

Correcting this in `IsHLSLNumericUserDefinedType` resulted in some
breakge in raytracing code generation because we used that method to
deterimine if structures could be payloads or attributes. That was an
incorrect API usage because we do have some builtin types that are
allowed.

The change here does the following:
* Introduce `IsHLSLBuiltinRayAttributeStruct` which returns true for the
  builtin raytracing data types that behave like UDTs.
* Introduce `IsHLSLCopyableAnnotatableRecord` returns true for
  user-defined trivially copyable structures and the builtin ray tracing
  types.
* Adjust `IsHLSLNumericUserDefinedType` to do what the name says.
* Consolidates implementations of `IsUserDefinedRecordType` across
  the project.
* Adds new test cases for the ray tracing built in structs to cover
  diagnostic cases missed by the existing tests.

The new `IsHLSLBuiltinRayAttributeStruct` is hacky and uses the type
names (as the old code did). We should in the future insert an internal
attribute on the types that can be used to denote them so that we don't
need to match string names.

Resolves #4735
2022-12-09 01:19:08 +00:00
Tex Riddell 46db0442d9
Fill in RequiredFeatureFlags in library function reflection (#4774)
ID3D12FunctionReflection was leaving the `RequiredFeatureFlags` blank, but the information is available.  This change fixes that omission.

Like the equivalent for ID3D12ShaderReflection (see `DxilShaderReflection::GetRequiresFlags`), the flags are the same between the `SHADER_FEATURE_*` flags and `D3D_SHADER_REQUIRES_*` flags, except that `D3D_SHADER_REQUIRES_EARLY_DEPTH_STENCIL` collides with `SHADER_FEATURE_COMPUTE_SHADERS_PLUS_RAW_AND_STRUCTURED_BUFFERS_VIA_SHADER_4_X` not exposed in `RequiredFeatureFlags`.  So, the `D3D_SHADER_REQUIRES_EARLY_DEPTH_STENCIL` flag is patched in based on the flag captured in the shader props (`ShaderProps.PS.EarlyDepthStencil`) for library pixel shader entry points.
2022-12-08 08:38:49 -08:00
Chris B f6d15f9aed
LLVM_REQUIRES_* variables shound't be set (#4850)
The `LLVM_REQUIRES_*` variables are internal variables in LLVM's
configuration used to determine if a build setting is required, they
don't actually control the build setting itself, so we shouldn't be
setting them.

`LLVM_ENABLE_*` variables control the build settings, and we do set
those correctly.
2022-12-08 09:27:21 -06:00
Chris B 4271f47e7b
[HLSL2021] UDT template parms follow C++ rules (#4844)
HLSL built-in templates have some special rules for verifying template
type parameters. These break with some common C++ template patterns.
This change applies HLSL template argument validation only to HLSL
implicit templates.
2022-12-08 09:27:00 -06:00
Chris B baae5dd1e5
Remove HLSL 2021 per-feature flags (#4716)
* [NFC] Transform all test cases to use `-HV 2021`

This just updates test cases to use `-HV 2021` instead of the
per-feature options.

* Remove HLSL 2021 per-feature flags

This change removes the HLSL 2021 per-feature enabling flags. Now that
HLSL 2021 is feature complete we're removing the ability to opt into
individual features. Any code relying on a single feature of HLSL 2021
should now adopt HLSL 2021 completely.

Co-authored-by: Greg Roth <grroth@microsoft.com>
2022-12-08 09:23:33 -06:00
Nathan Gauër cce6fe0f43
[SPIR-V] HLSL2021: initial bitfield implementation (#4831)
This commit adds the logic in the SPIR-V backend to generate proper
bitfields. Bitfield are packed using a first-fit method, linearly
packing them, but not mixing types. Goal is to follow C/C++ rules.

Bitfield merging was initially guessed from the offset stored in the FieldInfo.
This offset is not always available and has a very specific meaning.
When the struct is a function local variable, the layout rule is Void,
meaning we shouldn't assume any kind of byte offset, but rely on
construct index.
This commit adds a fieldIndex member to the FieldInfo struct, and this
field is used to determine if 2 fields are merged.

When doing a buffer texture load, the struct must be extracted from a
vector type, and rebuilt. This commit adds support for bitfield extraction for such
types. Fixing this helped me see scalar assignment were also failling in
some cases. Addressing bitfield extraction/insertion issues on with
commit.

Signed-off-by: Nathan Gauër <brioche@google.com>
Co-authored-by: Cassandra Beckley <cbeckley@google.com>
2022-12-07 11:54:10 +01:00
Helena Kotas 12515e884b
Fix dxcisense.h includes (#4852)
- dxcapi.h is in the same directory
- WinAdapter.h not needed on Windows
2022-12-06 20:02:37 +00:00
Cassandra Beckley cafbbed4d1
Temporarily revert for release (#4848)
Revert "spirv: get field index from SPIR-V type, not AST (#4806)"

This reverts commit 8f279baaef. This
commit isn't passing some of our internal tests and needs to be reverted
in preparation for the next Vulkan SDK release.
2022-12-06 10:57:10 +01:00
harshpg 6eedcd2afa
Replacing fileIO exceptions with error codes (#4841)
Exceptions for error handling can have a significant performance impact. The exception-throw codepaths are usually cold, and rely on large in-memory tables that need to be paged in.

This change to instead propagate returned error codes simplifies the code and allows the compiler to more aggressively optimize around both success and failure conditions.
2022-12-05 16:24:30 -06:00
Cassandra Beckley e78b2dd355
Update submodules (#4847) 2022-12-05 21:28:39 +00:00
Tex Riddell af3b9d4ced
Restore impl of DerivedRecordSize in RDAT (#4842)
This default method implementation is necessary for the base->derived size version mechanism to work.
This is only specialized when a base has a derived, and it relies on the newest version to use the default implementation (no specialization).

The implementation was removed in commit 8ee6ed19f3.
2022-12-05 10:42:18 -08:00
Tex Riddell 6caeb266ff
Fix ternary operator for enum result type (#4838)
Note: existing path that limits operator to basic numeric types still allowed enum due to it being AR_TOBJ_BASIC, rather than using a new ArTypeObjectKind.
It's questionable whether this was intentional, but changing it would require another special case to allow enums, like exists for object types, and it might have other side effects as well.
2022-12-05 10:41:13 -08:00