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

219 Коммитов

Автор SHA1 Сообщение Дата
Chris B 37ed613864
[NFC] Clang-format DXC sources (#5602)
This change applies clang-format to all of the sources added in DXC that
were not part of the original LLVM/Clang 3.7 release when DXC forked.
This provides consistent code formatting across the codebase.

Fixes #5591.
2023-09-19 07:49:22 -05:00
Antonio Maiorano 0163da3757
Fix memory leak on DxcCreateBlob of empty string (#5725)
In the case of an empty string, DxcCreateBlob does not take ownership of
the input data object, and ends up leaking it.

Example ASAN error:
```
./bin/dxc -E main -T lib_6_3 /home/amaiorano/src/external/DirectXShaderCompiler/tools/clang/test/DXC/show-includes.hlsl

==524344==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1 byte(s) in 1 object(s) allocated from:
...
```
2023-09-18 10:27:17 -04:00
Chris B 3266a87f9a
[NFC] Remove SAL annotations from internal APIs (#5639)
We don't keep these annotations up to date or rely on them, so to
simplify our platform layering and ease code formatting this change
removes all the SAL annotations from internal APIs. This change also
replaces most `_Analysis_Assme_(...)` annotations with `assert(...)`.

One `_Analysis_Assume_` in ParseDecl.cpp needed to be updated because it
was incorrect. The code was `_Analysis_Assume_(assert(name.size() >
sizeof("space"));`. When converted to an `assert` it fired in our test
suite because the sizeof a string literal includes the null terminator,
but the size of a StringRef does not.

A few of the `_Analysis_Assume_` annotations were removed because they
didn't make sense (like the ones inside the `DXASSERT` implementation,
and a few others were removed to avoid introducing additional header or
linkage dependencies.

This change does not introduce any functional or behavioral changes.
2023-09-14 08:59:49 -05:00
Xiang Li a9d9e65be8
[NFC] Add dxcutil::ComputeSerializeDxilFlags to share code with linker (#5334)
Add dxcutil::ComputeSerializeDxilFlags to share code with linker

Use refactored ComputeSerializeDxilFlags in DxcCompiler::Compile()

---------

Co-authored-by: Tex Riddell <texr@microsoft.com>
2023-09-08 14:44:22 +00:00
Justin Bogner a88709aa3c
Add `-print-before` and `-print-before-all` flags (#5590)
These match `-print-after` and `-print-after-all`, and are needed if we
want the opt pipeline view to work in compiler explorer.
2023-08-25 14:15:00 -07:00
Chris B 578114efb9
[NFC] Update DXC sources for clang-format (#5593)
One more batch of NFC changes to get DXC ready to clang-format. This
change disables clang-format of some include blocks and breaks other
include blocks into groups. With this change all of the sources in DXC
can be clang-formatted and will continue to build on all supported
platforms.
2023-08-24 13:55:19 -05:00
Helena Kotas f206b3d19d
WArgV is needed only on non-Windows platforms (#5576)
Fixes internal build break.
2023-08-23 13:13:12 -07:00
Adam Yang fc796a0fc3
[NFC] Refactor -opt-enable and -opt-disable (#5516)
Refactored -opt-enable and -opt-disable.

- Added `hlsl::option::OptimizationToggles` to manage the toggles
instead of checking a `std::map`.
- All the options are moved into `hlsl::options::TOGGLE_*` constants,
where each constant contains both the option's name and whether it's
default on or off.
+ Previously, every check had to be either `toggles.count("my-flag") &&
toggles.find("my-flag")->second` for default off, and
`!toggles.count("my-flag") || toggles.map.find("my-flag")->second` for
default on.
  + Now, a check is simply `toggles.IsEnabled(TOGGLE_MY_FLAG)`.
2023-08-14 21:52:54 +00:00
Natalie Chouinard 786268eeed
[spirv] Emit error message when -Gec flag is used (#5526)
The -Gec option is not supported by the SPIR-V backend so emit an
explicit error when it is used in combination with -spirv.

Closes #3890
2023-08-10 21:35:16 +02:00
Helena Kotas 0033aa85b5
Allow new/delete operators to be called before DllMain (#5454)
Allow new/delete operators to be called before DllMain and allocator
initialization in DxcInitThreadMalloc().

The operators can be called before DllMain from CRT libraries when
static linking is enabled. If that happens, the new/delete operators
will fallback to the standard allocator and use CoTaskMemAlloc/Free
directly instead of CoGetMalloc, Alloc/Free & Release for better perf.

Enables fixing of
[#5163](https://github.com/microsoft/DirectXShaderCompiler/issues/5163)
and
[#5178](https://github.com/microsoft/DirectXShaderCompiler/issues/5178).
2023-07-28 01:01:55 +00:00
Antonio Maiorano 44f8833938
Add macro to disable usage of allocator overrides (#5296)
Add macro DXC_DISABLE_ALLOCATOR_OVERRIDES which, if defined, will use
the default CRT allocator for new/delete and malloc/realloc/free.

We need this on Chrome for our GN build of DXC, because our component
builds use libc++as a shared library, and we end up with mismatched
new/delete calls between libc++ and these custom overrides.

---------

Co-authored-by: Chris Bieneman <cbieneman@microsoft.com>
2023-07-17 15:27:30 -04:00
Tex Riddell 68c7d38d42
Fix test break on non-spirv build (#5422)
A previous PR added this spriv option. The default should have been
false, but in the block that checks for spirv options on a non-spirv
build, the default was set to true. This broke testing on non-spirv
builds.
2023-07-14 21:56:51 +00:00
Steven Perron 34b47c2c8b
Allow arrays of RW, consume, and append structured buffers. (#5405)
This is the first commit in a series that will enable array of
RW, consume, and append Structured buffers. This commit removes the
error when one is used on its own.

There will be a failure if a counter variable is needed.

This is the first PR is a series that will slowly enable different
features for arrays of RWStructuredBuffers. To see the general direction
the changes will go see
https://github.com/microsoft/DirectXShaderCompiler/pull/5407.
2023-07-13 17:23:36 +00: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
Xiang Li a35f1fa350
Make HLSLOptions getter methods const (#5333)
Make HLSLOptions getter methods const

Co-authored-by: Tex Riddell <texr@microsoft.com>
2023-06-28 14:44:11 -07:00
David Peixotto 815055bb01
[flag] Update the lifetime markers flag to correctly handle multiple instances (#5283)
The current behavior of the lifetime markers flags is to allow the
`-disable-lifetime-markers` flag to override the enable flag no matter
where it occurs. This means that if you write

    dxc -disable-lifetime-markers ... -enable-lifetime-markers

the lifetime markers will be disabled. This works differently from most
clang flags which allow the last version of the enable/disable flag to win.

This PR modifies these flags so that when there are multiple occurences of
enable/disable the last one will win. It is not clear if the original behavior
was intentional or just a  mis-understanding of the flag API. There were no
tests enforcing the original behavior.
2023-06-13 11:00:50 -07:00
Rajiv Gupta e2c42174d1
[SPIR-V] Add fspv-preserve-bindings option to preserve decoration bin… (#5211)
* [SPIR-V] Add fspv-preserve-bindings option to preserve decoration bindings even when unused

* Set preserve bindings option in SpirvEmitter::spirvToolsLegalize() also
2023-05-31 09:23:07 -04:00
Helena Kotas 667fb773cc
Change SharedLibAffix.h include path to eliminate the need to change build setting (#5085)
The file dxcapi.use.cpp is used in other projects and would require build changes if the #include did not change.
2023-03-08 12:08:51 -08:00
Helena Kotas 845efa9521
Generate SharedLibAffix.h into the include directory (#5058) 2023-02-27 11:08:17 -08:00
Chris B 740dd0951b
Add `-verify` flag to DXC (#5032) 2023-02-16 17:56:34 -06:00
Chris B 143ab95e89
[NFC] Remove custom StringCchCopyEx (#5037)
This patch got a bit away from me. It started as me trying to remove
one of the Windows system functions we have a custom implementation of
(StringCchCopyEx). It didn't really make sense to me that we needed a
custom override of a function where we could have just used `strncpy`
or other LLVM utilities to provide the functionality.

After I rewrote the code calling `StringCchCopyEx`, I wanted to make
sure it was tested, which led me to discover that it was never called
in our existing tests (see:
https://microsoft.github.io/DirectXShaderCompiler/coverage/home/runner/w
ork/DirectXShaderCompiler/DirectXShaderCompiler/lib/DxcSupport/WinFuncti
ons.cpp.html#L27).

I then looked into the behavior of
`clang_getCursorSpellingWithFormatting`, which it turns out _does_
return fully qualified names. As a result the parent traversal we were
attempting always terminated immediately with one name segment found.

I wrote an additional test where the cursor name is _not_ fully
qualified in source to verify that the API works as expected in all
cases then started deleting code.

This patch deletes two functions (`StringCchCopyEx` &
`ConcatPartsReversed`), and simplifies the code in
`GetCursorQualifiedName`. It also adds the additional
non-fully-qualified name test case.
2023-02-16 14:42:07 -06:00
Chris B e0fb6dd640
Support dumping implicit top-level decls (#5007)
This change reworks how we were filtering top-level implicit decls from
the `-ast-dump` output. The change has a couple of key differences, but
the behavior of the `-ast-dump` flag remains unchanged.

The differences in this change are:
* By default Decl::dump _will_ dump implicit top-level decls which
allows attached debuggers to dump top-level decls.
* Top-level implicit decls are determined by the decl's `Implicit` bit
rather than an invalid source location.
* Disabling dumping implicit decls is now a language option, so it can
be toggled.
* A new `-ast-dump-implicit` flag is added to dump the AST including
implicit top-level decls.

The attached test case verifies that the `-ast-dump` flag does not dump
implicit top-level decls, and it is intended to be strict enough that
if we add new top-level decls in the future and fail to mark them as
`implicit` the test will fail.

The attached test also trys to fill some gaps in testing around the
lazy decl initialization by verifying that incomplete implicit decls
are generated, and that a used decl gets completed as expected.
2023-02-10 09:54:04 -06:00
Greg Roth ae51624fca
Allow libdxcompiler.so and dxc to find libdxil.so (#5004)
When present in the library search path, linux builds of
libdxcompiler.so and the dxc executable should load libdxil.so and use
it for validation and signing. However, the code to do that was still
searching for dxil.dll even on these platforms.

This change creates appropriate names for the dxcompiler and dxil
libraries for each platform and uses them where appropriate.

In addition, this changes some of the internal interfaces from wide
chars to simple chars as the wide interface wasn't useful here.
2023-02-10 04:24:22 +00: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
Chris B 2b2a11242b
Add experimental -fnew-inlining-behavior (#4972)
This flag is _extremely_ experimental. It is the first step in an effort
to clean up and adjust our optimization pipeline ordering. This first
step enables compiling shaders using a more traditional LLVM pass
ordering and the normal inlining behavior. For library shaders it also
skips adding the `alwaysinline` attribute to all function calls, so we
end up only inlining profitable calls based on the inliner heuristics.

There is much more work to do to get this flag to generate valid
shaders, but adding the flag so that we can start working on it is the
first step.
2023-02-09 09:38:46 -06: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 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
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
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
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
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
Chris B 8ee6ed19f3
Cleanup Windows code to conform to stricter C++ 17 compiler (#4804)
* Cleanup windows build to conform to C++ 17

MSVC's C++ language implementation deviates from the standard in a
number of ways, this patch cleans up several issues that become errors
if you build DXC using clang-cl, which has a more strict
interpreteation of C++.

This change should not have any functional impact on the final program.

Specific changes include:
* static_assert(false...) is removed, this is always ill-formed by the
C++ standard.
* Under template instantiations implicit `this` is not always allowed.
* Character array `<` comparision is... probably not what was intended.
* Implicit conversions are stricter than MSVC enforces.
* Template base types need explicit type specialization when referred
to.
* It is illegal to initialize more than one member of a union.
* Scope nested enums cannot be forward declared.
* Header paths should be case-sensitive.
* Exception specifications of specific types are disallowed in C++ 17.
* Clang is stricter about const-correctness, especially as it relates
to constant c strings.

* Update based on review feedback.

* Converted string construction to copy-constructor calls.
* Removed constexpr method bodys to cause linker error.

* Catching other methods I missed.

* I was a bit too over-zealous deleting methods.
2022-11-22 15:31:36 -06:00
Marijn Suijten 47f31378a9
[Linux] WinAdapter: Remove virtual dtors from IUnknown to fix vtable ABI (#3793)
* WinAdapter: Remove virtual dtors from IUnknown to fix vtable ABI

The vtable for `IUnknown` and its subclasses contain two deletion
pointers when compiled on non-Windows systems with `IUnknown` from
`WinAdapter.h`:

    vtable for 'DxcLibrary' @ 0x7ffff7cbc5f8 (subobject @ 0x5555556bb9e0):
    [0]: 0x7ffff6a56d40 <DxcLibrary::QueryInterface(_GUID const&, void**)>
    [1]: 0x7ffff6a56d20 <DxcLibrary::AddRef()>
    [2]: 0x7ffff6a56d30 <DxcLibrary::Release()>
    [3]: 0x7ffff6b36bc0 <IUnknown::~IUnknown()> // Complete object destructor
    [4]: 0x7ffff6a57130 <DxcLibrary::~DxcLibrary()> // Deleting destructor
    [5]: 0x7ffff6a56d50 <DxcLibrary::SetMalloc(IMalloc*)>
    [6]: 0x7ffff6a56d60 <DxcLibrary::CreateBlobFromBlob(IDxcBlob*, unsigned int, unsigned int, IDxcBlob**)>
    ... More DxcLibrary virtual functions

This shifts the the pointers for functions for all subclasses, and is
[annoying] to deal with in otherwise cross-platform applications using
DirectXShaderCompiler as library.  `dxcompiler.dll` compiled on/for
Windows without `WinAdapter.h` does not suffer this problem, and only
has three function pointers for `IUnknown`.

Fortunately, it is easily solved by removing the virtual destructor from
`IUnknown`.  LLVM enables `-Wnon-virtual-dtor` that warns against
classes with virtual methods but no virtual destructor, though this
warning is best not enabled akin to Windows builds where `IUnknown` from
`windows.h` (`unknwn.h`) results in the same warning on MSVC ([1]/[2]).

[annoying]: 1e624792fc/src/unknown.rs
[1]: https://github.com/microsoft/DirectXShaderCompiler/issues/3783#issuecomment-844189358
[2]: https://godbolt.org/z/hKPT6ThEf

* WinAdapter: Make `IUnknown` and `IMalloc` pure-virtual classes

`IUnknown` in Windows' `unknwn.h` and `IMalloc` in `ObjIdl.h` are marked
as pure virtual, and are best marked as such in `WinAdapter` for
non-Windows platforms too [1].  Only the shim for `IMalloc` was relying
on the default refcounting implementation, all other subclasses either
contain pure-virtual methods themselves or provide an implementation for
`AddRef`/`Release` as required.  Likewise the default implementation for
`IMalloc` was only instantiated once by `CoGetMalloc`, and has been
moved into a local class implementing the `IMalloc` interface instead.

[1]: https://github.com/microsoft/DirectXShaderCompiler/pull/3793#issuecomment-846459741

* WinAdapter: Add three missing virtual functions to `IMalloc` interface

To prevent unexpected vtable breakage, add the missing functions from
the [documentation].  Note that they are listed in the wrong order, the
right order is retrieved from the `ObjIdl.h` header and implementations
for `IMalloc` in DirectXShaderCompiler.  All implementations are now
properly using the `override` keyword too, to enforce virtual method
existence in the base class.

[documentation]: https://docs.microsoft.com/en-us/windows/win32/api/objidl/nn-objidl-imalloc

* Make all WinAdapter destructions explicit

This prevents warnings about non-virtual destructor usage that trip up
the Linux build. It represents status quo on Windows.

Co-authored-by: Greg Roth <grroth@microsoft.com>
2022-10-13 10:19:39 -07:00
Chris B b49ecd10ee
Add option to force disabling debug info (#4645)
This is (admittedly) a little hacky. DXC spends a lot of compile time
updating debug information because we always generate it so that we can
generate diagnostics for late-running validation.

This patch adds a new flag -fdisable-loc-tracking, which disables
generating debug locations if the user is not generating debug info.

This flag results in about a 15% compile time improvement on a pessimistic
test case. YMMV.
2022-09-16 16:36:16 -05:00
Xiang Li 8bf2b087c2
Change /P to match cl.exe /P behavior. (#4624)
/P will write to InputFile.i
/P -Fi filename will write to filename.
/P filename still work with warning.
2022-08-31 22:07:30 -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
Natalie Chouinard 0ef9b70289
[SPIR-V] Error when -Gis is used with -spirv (#4529)
Though we may support -Gis with the SPIR-V backend in future, it is
currently not supported, so this change makes that explicit to the user
with an error message when it is used.

Related to #3331
2022-06-23 18:28:27 -04:00
Natalie Chouinard e80724a7a0
[spirv] Fail when unsupported options are used (#4518)
Some DXC options are not supported in combination with the SPIR-V
backend. Rather than silently ignore them, we should emit a clear error
message. This change adds appropriate error messages for a couple
options that have been mentioned in issues #3111 and #4496, but more
should be added in future.
2022-06-20 09:42:58 -04:00
Jakub Kuderski e20926ae2e
[spir-v] Add option to print SPIR-V between passes (#4503)
This debug/development option matches the `--print-all` flag in
spirv-opt or `--print-after-all`/`--print-before-all` in llvm's opt.

The new option can be enabled with `-fspv-print-all`.
2022-06-03 15:41:02 -04:00
JiaoluAMD 50c0199c17
[spirv] Add FixFuncCallArguments options (#4439)
1) promotion of spirv-opt `FixFuncCallArgumentsPass`
2) add tests for the FixFuncCallArguments for the compute shader and
   export linkage shaders
2022-05-13 14:39:08 -04: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
Greg Roth 75224d820f
Rename UTF16 to Wide (#4242)
In many cases, systems where wchar was represented as 32-bits were being
referred to by types and variables affixed with "utf16" or similar. To
avoid confusion, this renames all such places to "wide".

In a few cases, the conversion were explicitly 16-bit, which wasn't the
intent.
2022-02-14 15:24:40 -05:00
Chris B cb5bb213d8
Refactor HLSLVersion to enum (#4238)
* Refactor HLSLVersion to enum

This change converts HLSLVersion to an enum type `hlsl::LangStd`. Most
of the change is a mechanical appending `hlsl::LangStd::v` to the
integers we previously compared for version checks.

Additionally this change does the following:
* Adds a parseHLSLVersion function to unify parsing code
* Parsing code is converted to an llvm::StringSwitch over the possible
values instead of converting to integer
* Added enum value for `vLatest` so that changing the latest version is
done in one place
* Added enum value for `v202x` which parses from 202x to allow new
language features a place to land

* Updates based on PR feedback
2022-02-10 20:41:55 -06:00
Grace Jennings 979cc4a276
Support -setprivate, -setrootsignature, and -Qstrip_priv to compile API (#4230)
* Adding /setprivate, /setrootsignature, and /Qstrip_priv to compile API calls

* Adding setprivate to initial container serialization, change warning to error

* Removed unused variable

* Adding private data blob last, because no gaurantee of aligned size

* Add error messages for conflicting private options
2022-02-08 13:36:55 -08:00
Greg Roth 437ae1e5b6
Re-enable a swath of DXIL tests for *nix builds (#3888)
These were disabled at a point that the DXC CI didn't reject builds for
failing on Linux, now that they do, we can enable these tests sure in
the knowledge that any changes to them that break on Linux will be
detected and fixed quickly

Fixed *nix error code return. The previous caused an infinite loop of retries.
This definition more accurately identifies the error that has occurred as not
benefiting from repeated attempts

Skip tests and filechecker elements that entirely depend on reflection or
linker interfaces that aren't implemented on *nix yet.

Correct capitalization in a few places to satisfy a case-sensitive filesystem

Detect directories from test include handler. *nix virtual filesystem will try to
load the file using the include handler when performing stat() on a directory.
The test include handler is pretty basic and would provide the next file, leaving
it without a file to offer when the real include came along.
By detecting a name that looks like a dir and returning failure, it
correctly indicates that the file isn't found by the handler and saves
the virtual file for when its needed.

Don't mark non-debug builds as such. The DEBUG define determines which
tests get run. Some of which depend on consistencies that can only be relied
upon in debug builds. So DEBUG is disabled for all non-debug builds.

Correct free of new() memory. Incidental regex allocations were changed for
HLSL to use the global new() operator, but were still freed using the standard
free(), but replacing the default free() with regex_free() allows the default new()
operator to be paired with the default delete() operator

Correct misnamed test flag. The *nix flag was mistakenly called InputFile instead
of InputPath. By renaming it, the ManualFile test can target a specific HLSL file.

Fix misused ArrayRef in legacy GV replacement. The replacement of the GV with
the legacy form used in libraries collected the arguments into an arrayref without
an array to ref, which caused garbage in release builds. Also moved to using end
vars for loops where the elements can get deleted during the loop.

Fix *nix conversion to utf8. When an unknown codepage is found, it tries to convert
to utf16, but that isn't' actually helpful for *nix for a shader codepage derived from
the BOM, which is correctly identified as utf32
2022-01-20 13:53:47 -08:00
Adam Yang 13553274a8
Added debug option to print-after specific passes (#4196) 2022-01-20 00:53:46 -08:00
Jaebaek Seo ff270c74b8
Enable printing dependencies of compilation target (#4017)
This commit adds `-M, -MF, -MD` options to print dependencies of
compilation target.

For example, when a HLSL file X includes Y, Z, W files,

$ ./bin/dxc -M -T ps_6_0 -E main X

will print:
X
Y
Z
W

The first line i.e., X is the name of the main compilation target.
Following lines are dependencies for X.

`-MF<file_path>` and `-MD` are the same as the ones supported by Clang.
See https://clang.llvm.org/docs/ClangCommandLineReference.html#dependency-file-generation
2021-12-21 13:42:30 -05:00
Grace Jennings 44b1f00caa
Extend encoding option to specify source encoding (#4109)
Extended current encoding option to also set a default encoding for source files. Includes support for UTF-8 and UTF-16 encoded sources with and without BOMs. The default encoding will be used for the main source file when there is no BOM and the DxcBuffer encoding is not specified. The default encoding will be used for included source files with no BOM.
2021-12-06 11:40:23 -08:00
Adam Yang ce6d208234
Added -binding-table-define (#4044) 2021-11-01 18:46:13 -07:00