* Move warning enabling pragma to cpp files before includes and fixed warning that popped up
Whitespace change in ShaderOpArithTable.xml
* Enable and fix warnings on execution tests
* One more warning
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.
* [spirv] Introduce the implicit 'vk' namespace
If any of these are used for DXIL code generation, the compiler will
report an error about the unknown "vk" namespace.
* [spirv] Introduce vk::ReadClock intrinsic.
The following Vulkan specific intrinsic functions are added:
```hlsl
uint64_t vk::ReadClock(in uint32 scope);
```
Also the following Vulkan-specific implicit constants are added:
```
vk::CrossDeviceScope; // defined as uint 0
vk::DeviceScope // defined as uint 1
vk::WorkgroupScope // defined as uint 2
vk::SubgroupScope // defined as uint 3
vk::InvocationScope // defined as uint 4
vk::QueueFamilyScope // defined as uint 5
```
Sample usage looks as follows:
```hlsl
uint64_t clock = vk::ReadClock(vk::WorkgroupScope);
```
If any of these are used for DXIL code generation, the compiler will
report an error about the unknown "vk" namespace.
* [spirv] Add documentation.
* Address code review comments.
* Test: Validate vk namespace is not allowed for dxil.
* Fix usage of DXASSERT.
* Move ValidateVkNamespaceNotAllowed test to HlslFileCheck.
The fallback layer for GCC currently uses pointer comparison to match
IIDs as uuid tagging for types is not supported.
Thus, when an external program dlopens libdxcompiler and calls
with a proper REFIID these will not match internal pointers and result
in E_NOINTERFACE.
Note that the reverted patches before this commit alleviated the
situation somewhat by replacing the pointer with a hash of the interface
name. While this again grants a stable value to be used when called from
external binaries these (usually FFI wrappers) now need to understand
whether the library has been compiled with full IID support (as a binary
compiled with Clang has no such limitations), and then pass the hash
anywhere they'd otherwise pass an IID.
WIP: Not all IIDs are added yet, which requires the extra "empty-GUID"
check in IsEqualIID.
* Enable generation of llvm.lifetime.start/.end intrinsics.
- Remove HLSL change from CGDecl.cpp::EmitLifetimeStart() that disabled
- generation of lifetime markers in the front end.
- Enable generation of lifetime intrinsics when inlining functions
- (PassManagerBuilder.cpp).
- Both of these cover a different set of situations that can lead to
- inefficient code without lifetime intrinsics (see examples below):
- Assume a struct is created inside a loop but some or all of its
fields are only initialized conditionally before the struct is being
used. If the alloca of that struct does not receive lifetime intrinsics
before being lowered to SSA its definition will effectively be hoisted
out of the loop, which changes the original semantics: Since the
initialization is conditional, the correct SSA form for this code
requires a phi node in the loop header that persists the value of the
struct field throughout different iterations because the compiler
doesn't know anymore that the field can't be initialized in a different
iteration than when it is used.
- If the lifetime of an alloca in a function is the entire function it
doesn't need lifetime intrinsics. However, when inlining that function,
the alloca's lifetime will then suddenly span the entire caller, causing
similar issues as described above.
- For backwards compatibility, replace lifetime.start/.end intrinsics
with a store of undef in DxilPreparePasses.cpp, or, for validator
version < 1.6, with a store of 0 (undef store is disallowed). This is
slightly inconvenient but achieves the same goal as the lifetime
intrinsics. The zero initialization is actually the current manual
workaround for developers that hit one of the above issues.
- Allow lifetime intrinsics to pass DXIL validation.
- Allow undef stores to pass DXIL validation.
- Allow bitcast to i8* to pass DXIL validation.
- Make various places in the code aware of lifetime intrinsics and their
- related bitcasts to i8*.
- Adjust ScalarReplAggregatesHLSL so it generates new intrinsics for
each element once a structure is broken up. Also make sure that lifetime
intrinsics are removed when replacing one pointer by another upon seeing
a memcpy. This is required to prevent a pointer accidentally
"inheriting" wrong lifetimes.
- Adjust PromoteMemoryToRegister to treat an existing lifetime.start
- intrinsic as a definition.
- Since lifetime intrinsics require a cleanup, the logic in
CGStmt.cpp:EmitBreakStmt() had to be changed: EmitHLSLCondBreak() now
returns the generated BranchInst. That branch is then passed into
EmitBranchThroughCleanup(), which uses it instead of creating a new one.
This way, the cleanup is generated correctly and the wave handling also
still works as intended.
- Adjust a number of tests that now behave slightly differently.
memcpy_preuser.hlsl was actually exhibiting exactly the situation
explained above and relied on the struct definition of "oStruct" to be
hoisted out to produce the desired IR. And entry_memcpy() in
cbuf_memcpy_replace.hlsl required an explicit initialization: With
lifetime intrinsics, the original code correctly collapsed to returning
undef. Without lifetime intrinsics, the compiler could not prove this.
With proper initialization, the test now has the intended effect, even
though the collapsing to undef could be a desireable test for lifetime
intrinsics.
Example 1:
Original code:
for( ;; ) {
func();
MyStruct s;
if( c ) {
s.x = ...;
... = s.x;
}
... = s.x;
}
Without lifetime intrinsics, this is equivalent to:
MyStruct s;
for( ;; ) {
func();
if( c ) {
s.x = ...;
... = s.x;
}
... = s.x;
}
After SROA, we now have a value live across the function call, which will cause a spill:
for( ;; ) {
x_p = phi( undef, x_p2 );
func();
if( c ) {
x1 = ...;
... = x1;
}
x_p2 = phi( x_p, x1 );
... = x_p2;
}
Example 2:
void consume(in Data data);
void expensiveComputation();
bool produce(out Data data) {
if (condition) {
data = ...; // <-- conditional assignment of out-qualified parameter
return true;
}
return false; // <-- out-qualified parameter left uninitialized
}
void foo(int N) {
for (int i=0; i<N; ++i) {
Data data;
bool valid = produce(data); // <-- generates a phi to prior iteration's value when inlined. There should be none
if (valid)
consume(data);
expensiveComputation(); // <-- said phi is alive here, inflating register pressure
}
}
* Implement lifetime intrinsic execution test.
- Test SM 6.0, 6.3, and 6.5. The 6.5 test behaves exactly the same way
as 6.3, it is meant a placeholder for 6.6.
- Test validator versions 1.5 and 1.6.
- Abstract a few things in the ExecutionTest infrastructure to enable
better code sharing, e.g. for lib compilation.
* Make memcpy replacement conservative by removing lifetimes of both src and dst. Add regression test for this case.
* Allow to force replacing lifetime intrinsics by zeroinitializer stores via compile option.
* Fix regression where lifetimes caused code that was not cleaned up properly.
- Add SROA and Jump Threading passes as early in the optimization
pipeline as possible without interfering with lowering. These two are
required to fully remove redundant code due to insertion of cleanup blocks
for lifetimes. Previously, SROA ran much too late, and Jump Threading
was disabled everywhere.
- A side effect of this is that we can now have unstructured control
flow more often. This also breaks one test that was originally written
when a part of SimplifyCFG that could also create unstructured control
flow was disabled. That part is still disabled, but jump threading has
the same effect. I don't know why unstructured control flow is a
problem for the optimization pipeline.
- Add a regression test that requires the two phases to be cleaned up properly.
- Disable the simplifycfg test which now fails even though simplifycfg
still does what it should.
* Disable lifetime intrinsics for SM < 6.6, add flag to enable explicitly.
- Add missing default value for unrelated option StructurizeLoopExitsForUnroll.
- Re-enable simplify cfg test disabled in a previous commit.
While this prefix may be an implementation detail the BSTR type
guarantees to be able to store NULL values without accidentally
truncating the string, hence its length must be available to replace the
usual NULL terminator. This string length in bytes is stored in the
four bytes preceding a BSTR pointer [1], whose value can be retrieved
using SysStringLen.
This commit implements the type in the same way in WinAdapter such that
users of the functions returning a BSTR (currently only in dxcisense)
can expect and use the type in the same way on Linux as they would on
Windows.
While this function and type currently only seem to be involved in names
and logging where NULLs are unlikely, it is good practice to mirror the
Windows type exactly for future-proofing.
Besides, SysAllocStringLen does not specify anything about taking
ownership of strIn so the realloc here is wrong either way.
[1]: https://docs.microsoft.com/en-us/previous-versions/windows/desktop/automat/bstr
- Fixed value tracking for dxil intrinsics
- Fixed some selects holding on to invalid resource uses
- Fixed some cases where unused globals hold on to invalid resource uses
- Fixed some cases where stores of undefs stick around
* Cleanup and minor changes to improve integration with internal projects
Adds -Debug option to hcttest.cmd
* Case insensitive compare for -Debug and -Release flags in hctbuild and hcttest
Instead of skipping past allocas whenever inserting a new insruction,
which ate up a lot of compilation time, they are inserted at the default
insertion point.
The result is that allocas that would have coallesced just after the
global load an input loads are dispersed throughout the commands. So as
part of dxil finalization, the allocas are moved to the beginning of the
entry block of each function. This results in some minor changes to a
couple tests due to the allocas preceding the loads.
OpenCL.DebugInfo.100
is a SPIR-V extended instruction set that provides DWARF style debug information.
This PR allows DXC SPIR-V backend to generate the rich HLSL debug information
using OpenCL.DebugInfo.100 instructions.
This should fix the warnings that have this pattern:
warning MSB8065: Custom build for item "...\tmpdxcetw.h.rule" succeeded,
but specified output "...\include\dxc\tracing\dxc\tracing\tmpdxcetw.h"
has not been created. This may cause incremental build to work incorrectly.
* Modify the extension mechansim to handle custom lowering for resource methods
The goal is to allow resource extension intrinsics to be handled the same way
as the core hlsl resource intrinsics.
Specifically, we want to support:
1. Multiple hlsl overloads map to a single dxil intrinsic
2. The hlsl overloads can take different parameters for a given resource type
3. The hlsl overloads are not consistent across different resource types
To achieve these goals we need a more complex mechanism for describing how
to translate the high-level arguments to arguments for a dxil function.
This commit implements custom lowering by allowing the mapping from high-level
args to dxil args to be specified as extra information along with the
lowering strategy.
The custom lowering info describes this lowering using the following format.
* Add missing virtual destructors
refactor usage of resourceparams to just use RP
create common way of extracting res properties
make getoverloadtype static
so it can be used to determine version
requirements
Disallow literals where not included
Previously, whether an intrinsic parameter type included an entry for
literals or not, a literal was permitted to be cast to it.
By moving up the explicit per-param check to before this cast takes
place, these implicit casts won't be added
For structurize-returns, the codegenopts assigned were a copy of those
the compiler possesses. This is by design in clang as explicitly stated
in comments. As a result, when the compiler codegenopts are updated, the
codegenmodule's are not.
By adding the ability to query the optimization enables from the hlsl
extension helper, these options can be reflected.
Additionally, the structurize-returns flag would have required a define
with a '-' in it, which isn't possible. So now it converts between '_'
for defines and '-' for options, which is consistent with how other
flags are interpretted.
Adds a unit test similar to that of disable gvn that makes a simple
check to verify that the resturn structurization is enabled.
Because the defined types of Interlocked* Parameters do not restrict
type casting, they can result in late errors that cause crashes due to
reference params with casts that aren't actually respected by dxil
generation.
By constraining the parameters as they should be, instead of crashes, we
get errors.
Fixes#2077Fixes#2483
This conforms to the established -opt-enable -opt-disable flag standard
to enable this optimization as well as tying in with the semantic
defines mechanism.
Adds to -opt-enable and -opt-select flags to the -opt-disable flag and
broadens the utility of all by storing the settings as strings instead
of booleans. -opt-select requires a parameter indicating the setting
name and another indicating the value.
options are repesented as lowercase until they are converted into
semantic defines in metadata. presence of semantic define prefixes
is no longer assumed when trying to write semantic defines to
metadata.
Semantic defines with the user-specified prefix will be propagated to
the corresponding -opt-<enable|disable|select> CodeGen option.
This allows either way of specifying these options to have the
same effect.
Adds two tests to verify that semantic defines will be
detectable as codegen flags. Another verifies that correct errors are
produced for contradictory flags.
* Add -fvk-auto-shift-bindings that applies -fvk-*-shift bindings to resources that do not have explicit register assignments. Closes#2956
* For resources that don't have an explicit register binding, first categorize their registerType using new method DeclResultIdMapper::getImplicitRegisterType.
* When finding automatic binding indices for implicit register bindings, pass an optional shift to useNextBinding.
* Change getNextBindingChunk() to handle finding the next binding range given a bindingShift
* Fix regression with binding numbers causing AppVeyor failure and also fix crash I ran into in my own testing in getImplicitRegisterType() if the getSpirvInstr() did not have an AstResultType.
* Address review comments.
* Update documentation
Co-authored-by: Ehsan Nasiri <ehsannas@gmail.com>
This fixes up the last of the clang errors that are unique to clang 10.
These take two forms, First, indentation that might indicate the mistaken
impression that a line is within an unbraced conditional block produces
a warning and is corrected in a few places. Second, a warning is
produced when a class has one of copy constructor or assignment operator
explicitly defined and the other left to implicit definition. The
solution is generally to add a definition with the = default assignment.
Finally, this adds the -Werror flag to all clang builds to keep the
build warnings clean and detect flaws that can affect all builds and
platforms.
We were not correctly preserving precise metadata when replacing instructions
in various transformations. This caused precise metadata to be dropped
when one a precise instruction was replaced with a non-precise instruction.
For example, given the two equivalent mul expressions
float x = mul(a, b)
precise float y = mul(a, b)
z = x + y
GVN would replace `y` with `x` in the computation of `z`. This caused x to
be computed in non-precise mode.
The fix is to make sure we combine known dxil metadata when replacing instructions.
Many of these take the form of removing unused member variables and
unused functions. Where they were truly unused, I removed them. Where
they were only used in asserts, I hid them for the release builds. Where
the code in question was original to LLVM, I didn't remove so much as
comment out the offending code. In most cases these changes are
counterparts to already excluded code for HLSL.
A few cases concern indexing or type matches. Where relevant, I lifted
the same solutions in the current source of the llvm project.
I altered the fix made recently to LinkAllPasses.h. Instead of just
disabling the warning, I used the temporary variables that the current
llvm project uses to avoid having to cast null pointers.
- Add method to DxilModule to rename resources based on a prefix,
preventing resource merging during linking.
- Also one to rename by binding if desired.
- Add pass to access this resource renaming.
- Fix dxil intrinsic overload names when type disambiguation causes
types with same name to be renamed with .0+ suffix, but intrinsic
names remain in collision.
- Handle colliding intrinsic names with unique types in linker.
It can be helpful to disable an optimization pass or set of passes in
select circumstances. This adds the ability to disable the gvn pass
only, but introduces a way to disable various passes just by accepting
the chosen string to represent them in HLSLOptions and using the
DisablePasses values to determine when a pass needs to be left out in
PassManagerBuilder.
This was using a define before a header to change the option name.
An inline function used the define when adding the path to a filename.
Unfortunately, this header was included from multiple places with
different values defined for the variable name, and it seems that
sheer luck made it work for a while, even when called from a cpp
file that would have had it defined differently.
The validation error message for when one or more of the components of a
storeBuffer (or similar) operation are undefined was terribly confusing
to anyone not developing the compiler. It mentioned mask mismatches when
one of the masks was generated based on which operands were undefined.
This changes the error message when the flaw results from the user under-
specifying the copied variable to simply state that the assignment involves
undefined values. If the masks mismatch because the type-based mask didn't
expect values that the user somehow defined, the original error message
results as this is likely a compiler error.
In addition, this consolidates some of the mask checking for rawbuffer,
texture, and generic buffer storage.
* Dxil container builder refactor + bug fix
- move from dxcompiler to DxilContainer.lib
- rename source file, move class definition to header file
- enable inheritance by changing microcom fields to protected
- enable AddPart for shader debug info
- move CreateDxcContainerBuilder to dxcapi.h to remove dependency
on DxilLibCreateInstance from DxcContainerBuilder.cpp
* Remove unused include
This strips the previous method of error reporting from DxilValidation
in favor of the DxilUtil methods. With these comes a new way to find
location information for those associated with functions or globals.
Instruction reporting is slightly changed in that the asm informtion
including the instruction and its block is added as a note so as to not
clutter up the line with the error and hlsl location.
For the most part, the existing EmitError* functions were retained, but
their implementation was changed to largely format inputs for the
dxilutil:: function and call it.
Errors that had clear associations with instructions, functions, or
globals had their emitting functions changed to variants that had this
information. The result is error message with as much location
information as is available.
In some cases, functions that implicitly added format arguments where
removed in favor of explicit formatted error calls that are clearer.
* Avoid directory duplication in DIFile MD
Change #2030 prevented the duplication of the directory for filenames
with full paths. However the same problem exists for relative paths that
include directories. This results in duplicate DIFile entries and
confusing error message outputs for Global Variables.
This skips the original code which was meant to prepend the directory
name since our filenames always have that information already.
* Validation error message text changes
This includes a number of different changes to validation error
messages. Some correct grammar. Some add a format argument to the
message for better information. Many of them just add a period to the
end of the error message for consistency and to allow the "Use /Zi"
message to be tagged on the end without jumbling the output.
* Enhancements for Dxil DiagnosticInfo and DxilUtil
Introduce *OnContext diagnostic reporting for messages that don't
clearly adhere to any instruction, global, or function. Also includes
the ability to add a note to supplement an earlier diagnostic.
Add function to DiagnosticInfo. This provides a fallback option for
printing location information when debug info isn't available. At least
we can print the function where the issue occurs.
For GV errors, we can't depend on the module having a dxil module in it.
Debug modules don't get the dxil part cloned. The only use of it was the
potentially cached debuginfofinder. Lacking it, we can just create it on
the fly.
Corrected the format of the output for DiagnosticInfoDxil::print. In
addition to minor fixups, when the diagnostic is a remark or note, it
doesn't need the "Use /Zi" prompt.
DxilLoopUnroll has its own diagnostics reporting. This adds the
associated function for the messages.
* Add function location information for interp mode error
This is to satisfy a specific request for line information for this
specific error. It got left out of the original batch, but it's
important enough for a followon.
The existing diagnosticinfo and handler relied on a token for the source
location that isn't available to these locations. By creating
specialized versions, we can retrieve the information from where it is
available and convert it to the source location ID that allows the usage
of the existing diagnostic output complete with code snippets
Add tests that check for line numbers or -Zi
* Use Attribute to designate wave-sensitive intrinsics
This adds an intrinsic attribute to indicate wave-sensitivity that can
be indicated in gen_intrin_main.txt. This and other attributes are
passed along through function representations and lowerings. The
wave-sensitivity needs to be maintained specifically through SROA passes
since it is used by the CleanupDxbreak pass that comes after them.
Specifically this is done to allow extension intrinsics to indicate
wave-sensitivity, but the same mechanism is now used for builtin
intrinsics.
Most intrinsics get a mostly nameless function to represent them between
Codegen and dxilgen. This allows any that have the same prototype to
share the same function. For wave-sensitive intrinsics, they need a
different function or else the attrubute would be similarly shared with
intrinsics matching the prototype. So a minor change is made to their
function names to prevent this.
Adds testing for all these ops and a dummy extension one.
* Skip copy-in/copy-out for constant global variables.
* Enable copy for noinline.
TODO: analysis for global variable alias with parameter.
* Use SetVector and skip resource when copy.
* Disable mayAliasWithGlobal because optimization already covered case not replace when have alias.
When replace const global to a normal value has store, mark it non-constant.
This is a direct implementation of a new API for PIX that shortcuts the large and unwieldy (and not-really-working-well) DIA equivalent to find the set of instructions that correspond to a given source location.
* Add simplify to DxilValueCache for dx.break()
To allow loop unrolling, call instructions that reference dx.break()
are given a constant true boolean simplification in DxilValueCache.
This required making the constant string available by moving it into
Analysis.
As an incidental change, I corrected the spelling of simplify in a
couple cases.
* Conditionalize breaks to keep them in loops
This introduces dx.break, a temporary builtin that is applied as a
condition to any unconditional break in order to keep the basic block
inside the loop. Because it remains in the loop, operations that depend
on wave operations inside the loop will be able to get the right values.
Such builtins have to be added at finishcodegen time or else clang
throws an error for an undefined function. Consequently, the creation of
these is split in two. First the branch is created with just a
constant true conditional. Then at finishcodegen, it is converted to the
result of the dx.break() builtin.
By using the result of a temporary builtin function, the optimization
passes don't touch the false conditional like they might if we started
with the global constant.
Normal break blocks don't need this conditional, but we don't know that
at code generation. So a later pass identifies break blocks with wave
sensitive operations that depend on wave ops that are inside the loop they
are breaking out of and preserves those conditionals while removing all
the rest.
As part of dxil finalization, the dx.break() function is removed and all
branches that depended on it are made to depend on function-local
loads and compares of a global variable dx.break.cond.
The DxBreak Fixup pass depends on dxil-mem2reg. It is placed immediately
after to allow as many optimizations to go as they would without this
change in shaders that don't have any wave ops.
When using libdxcompiler.so, UUIDs of classes don't match
because on Linux a UUID is effectively an address of a
static member variable.
This change replaces UUIDs with a consistent value -
a hash of the class name.
* Print Lines or "add -Zi" on error messages
This change adds to the existing EmitErrorOnInstruction functionality in
dxilutil to include EmitErrorOnFunction and EmitErrorOnGlobalVariable.
Each derives line number information from the metadata of these objects
if available. If it isn't available, the error or warning messages are
still printed, but an additional suggestion to add a -Zi flag is added.
The Linux adapter code includes an implementation of the IUnknown
interface that contains m_count to keep track of the reference counts.
That variable is used extensively, but is not initialized.
Complaints about use before initialization due to this make up the
overwhelming majority of the complaints Valgrind makes against DXC on
Linux. Adding a constructor makes IUnknown no longer an interface,
but the build doesn't seem to care.
- Added rewriter functions for extracting uniforms into global scope
- Will not work if name collides (namespaces have bugs)
- Values under cbuffer _Params, resources outside (more bugs)
- Added rewriter HLSLOptions and support all through RewriteWithOptions
- Refactored dxr.exe to use HLSLOptions and RewriteWithOptions
- Exposed Write*VersionInfo functions from dxclib
- Fixed issue with External[Lib/Fn] for version printing.
* Increase scan limit for DSE, add option
Due to the large number of fields in a struct passed to an exported
function, the number of useless loads and stores exceeded the builtin
limit, which left a lot of them in. This increases the default limit
from 100 to 500 and adds a hidden parameter -memdep-block-scan-limit to
set it to whatever is needed for future workarounds.
The Dead Store Elimination pass examines stores to see if they are
unneeded. If it finds no uses between the store and the original load,
it eliminates both, but if it has to exceed the instruction limit to get
there, it gives up and leaves it in just in case.
* Adds the DxcPixDxilDebugInfo interface and friends.
* Modifies the entrypoints to require InParam/OutParam for pointers, as well as CheckNotNull them
* Removes S_FALSE for happier Jeff
* Fixes broken test
* returns E_POINTER for nullptrs
* Returns S_FALSE from UnAlias for non-aliasing types.
* fails GetName for arrays
* Addresses CR comments
- Fix output naming for StringRef
- Support /Fc when /Fh is provided
- Fix root sig strip flag
- Create root sig stream output
- Validate -Frs root sig output for signing with DXIL.dll
- Move outputs under valHR success branch
- Add test for -Fre, -Fsh, -Frs, and -Fc with -Fh
- Rework hcttestcmds.cmd completely: checks a lot more stuff and is way more robust,
while being much easier to read, add to, and maintain, I hope.
This is a pass for PIX that adds instructions to write mesh shader output (vertices and indices) to a UAV for later ingestion by PIX in order to present a view of that output.
Add GetResourceFromHeap for hlsl.
For Dxil, add CreateHandleFromHeap and AnnotateHandle.
All handles ( createHandle, createHandleForLib, createHandleFromHeap ) must be annotated with AnnotateHandle before use.
TODO: add AnnotateHandle for pix passes.
cleanup code about resource.
* HLSL test infrastucture and other refactoring
Refactor common test infrastructure code into HLSLTestLib
Enable invocation of fxc and other executables via // RUN: commands in test files
Add latest d3dx12.h to include/dxc/Support and remove two other outdated copies
Improve DXIL container header validation on load
New helper classes DxilContainerReader and FixedSizeMemoryStream
Move LoadSubobjectsFromRDAT to DxilSubobjects.cpp
Co-authored-by: Greg Roth <grroth@microsoft.com>
* Fix crash when using precise matrix with -Od
To flag a variable as precise, a dx.attribute.precise call is inserted.
In the case of matrices, this becomes a problem if it persists too long
due to validation errors because the matrix is never lowered. When we
reach the HLMatrixLowerPass, the matrix can be lowered to vector. This
change detects when the precise call is applied to a matrix, lowers the
parameters and replaces the call with one taking a vector instead.
The call is necessary to keep the precise informaton across function
calls.
Adds variante of precise tests. precise/matrix.hlsl is modified by
matrix_od.hlsl to take the -Od parameter.
precise/propagate_to_producers_interproc.hlsl is modified to use
matrices since an earlier fix for this bug caused a regression when this
alteration was made.
Fixes#2189
* Add pragma control for diagnostics and option printing
* Test converting warning to error with #pragma dxc diagnostic error "..."
* Support options: -f[no-]diagnostics-show-option and -W[no-]<warning>
* Fix incorrect definition for DXC_PART_REFLECTION_DATA in dxcapi.h
* Add test for reflection stripping and create reflection when stripped.
- Test stripping of reflection with public API
- Create reflection when stripped should not crash, but provides little
actual info. This tests a fix made previously in that area.
- MinVal[Major|Minor] tracks shader model.
- Account for reflection by special casing for version 0.0 (no validation)
- Tolerate additions to non-critical metadata for future version
- Keep track of unrecognized non-critical metadata for validation
- Update validator to detect this case.
* Integrate changes from internal.
- dxcapi v2
- new dxc options
- DxilValueCache
- PDB and NoOpt improvements
- noop / llvm::donothing() support
* Update dxrfallbacklayer for dxcapi internal changes
* Reorder diag block based on whether pDiag is set first.
* llvm::donothing() requires dxil 1.6 / SM 6.6 for now, lib as well.
* Fixes for spir-v, non-VC compiler and non-Windows builds
- DEFINE_CROSS_PLATFORM_UUIDOF for new interfaces
- add SAL annotations
- turn output argument validation for -P into warning
- handle warnings without concatenating them to main output
- update spirv preprocessing and compilation paths
- return E_NOTIMPL from IDxcUtils::CreateReflection
- cleanup: DxcContainerBuilder back to uft8, DxcTestUtils: remove comment
* Fix some warnings from clang/gcc.
* Fix unicode conversion problems on linux, where sizeof(wchar_t) == 4
Note this is an intermediate fix.
On linux, what we are calling utf16 is actually a wide string
that's probably utf32. This change fixes issues introduced by
the new interface changes so things are consistent and pass tests.
A future fix should correct the encodings so they are correctly labeled
on platforms where wchar_t doesn't mean UTF16.
* Return false for IsBufferNullTerminated when CP_ACP.
One test for Disassembler was crashing because it created a pinned blob
with a size of 1 << 31 + 1 without actual memory backing this. The
IsBufferNullTerminated would attempt to see if this was null terminated,
causing AV.
This change also removes CP_UTF8 from this test when it was creating
binary blobs, not UTF8 text blobs.
- Make header no longer conflict with officially added shader input types
- Replace uses with last enum +1/+2 to make compatible with prev SDKs
- Add reflection Test for FeedbackTexture2D[Array]
New Rules:
outer type may be: [ptr to][1 dim array of]( UDT struct | scalar )
inner type (UDT struct member) may be: [N dim array of]( UDT struct | scalar )
scalar type may be: ( float(16|32|64) | int(16|32|64) )
- Disallow pointers to pointers, and pointers in structs
- Disallow multi-dim arrays at top-level, but allow within struct
- DispatchMesh and other intrinsics that use UDT ptr directly need
this to prevent copying and reconstruction, as well as prevent vectors
and HL matrices from being used in final Dxil.
* Fix lowering for all TextureCube[Array] Sample* and Gather* overloads
* Fix offsets for Gather test for change to i32 0 from i32 undef
- When not specifying immediate offsets when they can apply,
we used to provide undef, but we should have been using zero.
* Erase dead region
* Pass dependencies
* Simpler heuristic, only checking that Begin dominates End and End post dominates Begin
* Small cleanups. No longer iterating whole block to find PHIs
* A few optimizations. Fixed infinite loops caused by self-loops
Fixes problems like:
- extra AllocateRayQuery calls, or improper location (for lifetime)
- proper array support
- static global RayQuery
This RayQuery allocation changes:
- Add a constructor to RayQuery
- Set init sequence to use constructor in InitializeInitSequenceForHLSL, just for RayQuery
- For array: modify EmitCXXAggrConstructorCall to
- loop over index instead of pointer to allow SROA of RayQuery struct
- mark the loop as HlslForceUnroll
- Add hidden flag for HL intrinsics to allow internal intrinsic not produced
by HLSL directly - mangle name so it can't be matched during parse.
- Add hidden HL AllocateRayQuery intrinsic
- Translate constructor call on ptr to HL AllocateRayQuery intrinsic call producing handle i32 during FinishCodeGen
- Translate RayQuery ptr to load i32 handle value for intrinsic methods during SROA_HLSL
- Flatten RayDesc for TraceRayInline
(otherwise /Od fails validation since RayDesc type may still be present)
- No longer skip RayQuery for SROA_HLSL
- Update lowering for AllocateRayQuery, i32 handle, and flattened RayDesc
- Remove ReadNone attribute from AllocateRayQuery to prevent incorrect CSE optimizations
- Manually cleanup unused RayQuery allocations
Some clang versions report compiler errors because of constants
definition for CLSID saying that 'selectany' can only be applied
to data items with external linkage. This commit let only MS VS
build use "__declspec(selectany)".
Two test options, -Qstrip_reflect_from_dxil and -Qkeep_reflect_in_dxil
for making tests work with reflection removed, since many tests are relying
on main module disassembly-reassembly between test phases and reflection
metadata will no longer be present there. The strip option is for the
few cases where tests don't want the reflection kept in DXIL by default.
Validator no longer requires function annotations for no reason.
Fix places where remove global hook was not being called when functions
were removed manually from the list.
StripReflection now deletes function annotations, unless targeting lib or
old validator that required them. Preserve global constructor list and
add annotation for 1.4 validator. The global hook fixes were required
here, otherwise annotations would refer to dead functions during linking.
Struct annotations may not be removed in library case when they still need
translation to legacy types.
Allow missing struct annotation when not necessary to upgrade the layout.
Preserve usage in reflection by upgrading the module, emitting metadata,
cloning for reflection, then restoring validator version and re-emit
metadata.
Fix size for 16-bit type for usage and reflected size.
Make various batch reflection tests require validator 1.5, since these
tests rely on module disassembly->assembly, which will not preserve extra
usage metadata for reflection in 1.4.
Include reflection part in IDxcAssembler, but don't strip from module,
since there are no options to prevent this from breaking a lot of tests.
Don't strip reflection from offline lib target.
- default should be UINT_MAX, not zero, since zero is used
- compare validator version against target profile minimum for error
- add back implicit -Vd for lib_6_1/2 in CompileWithDebug since
target profile is supplied outside options, so option validation
would not know to fail without -Vd.
- add tests for various cases
* [spirv] Add option to flatten array of resources.
Current SPIR-V code generation uses 1 binding number for an array of
resources (e.g. an array of textures). However, the DX side uses one
binding number per array element. The newly added
'-fspv-flatten-resource-arrays' changes the SPIR-V backend behavior to
use one binding number per array element, and uses spirv-opt to flatten
the array.
TODO: Add a test where the array is passed around.
TODO: Test this works with steven's PR and proper results are produced.
* [spirv] Update tests to include array of samplers.
* [spirv] Take early exit condition out of the loop.
* [spirv] Add documentation for the new cmd option.
* [spirv] Invoke CreateDescriptorScalarReplacementPass when needed.
* [spirv] address code review comments.
- Put separate reflection in STAT part for now.
- Separate reflection is the module with deleted function bodies.
- Use new -Qstrip_reflect_from_dxil to drive stipping of reflection
metadata from DXIL part, since now -Qstrip_reflect means strip
the STAT reflection part, or don't include it in the first place.
- Update disassembler to use STAT part if available for reflecting
resource bindings, buffer descriptions, and ViewID state.
- Put some Qstrip_* flags under DriverOption as well as CoreOption.
- Align coord dimensions with Sample for future flexibility and alignment
- Fix ddx and ddy arguments to support the correct number of dimensions
- Rewrite lowering, using SamplerHelper
- Clean up SampleHelper a bit, adding additional asserts/checks
- Set components to zero for default offset, not undef
* flesh out SV_CullPrimitive support (and fill in some missing SV_ShadingRate entries)
* fix build breakl
* moved #defines and added comment
* removed depenency on adding new entries to OS header d3dcommon.h
* test fixes