This includes a number of different changes to allow the dx.break
artificial branch conditional to function properly in different
situations that might arise as a result of optimization passes.
First of all, the dx.break usage is eliminated entirely for any function
found to not have need of it during code gen finishing. The dependencies
are not all clear at this stage, so it only determines if the function
makes use of any wave operations.
During the original dx.break elimination pass, the code allows for any
kind of instruction. This requires a bit more information about the user
of dx.break since the immediate user might not be a branch. So first the
dx.break users are traversed the same way that the wave users are. Then
the wave users are used to cull the list of dxbreak users. Then the
remaining dx.break users, which are not wave sensitive have their branch
conditionals removed by traversing the users until the branch is found.
An incidental optimization in the finding of wave sensitive functions is
used which requires depth first traversal. Since certain checks are
performed on a per-block basis and the user chain can be expected to
stay in the same block at least for a bit, by using depth first search,
we can skip when the new block matches the one just processed.
There is a bit of consolidation of logic here. Instead of repeatedly
checking for the pattern that indicates a dx.break modified branch, it
is done once to collect all such blocks and thereafter, its presence
there is taken to mean that it qualifies.
A test is added to verify that this solves the original motivation of
this which was a circumstance where merging of conditionals resulted in
the dx.break call instruction was not immediately used by the branch.
Add additional early exit for waveless compiles
If the shader has no wave ops at all, there's no reason to create the
function at all.
* 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.
* Correct DomTree usage in memcpy lowering
By copying the code meant for memcpy used on global variables, I forced
recalculation of the DominatorTree for each and every memcpy. This
was pretty slow and entirely unnecessary. The global variables are
invoked from SROA_HLSL_Parameters, which is a module pass that doesn't
really know which function its dealing with until it addresses the
actual memcpy. SROA_HLSL already depends on the domination tree analysis
pass which allows the pass to draw from that for the dominator tree.
In addition, copying from the original code made use of a Post Dominator
Tree. This was a mistake. What we really want to know is if the source
dominates the uses of the destination. In practice, rarely would
anything be found to post dominate unless they shared a block. In the
contrived case where a memcpy post dominated its destination, the way
dxilgen dealt with cbuffers made it irrelevant because they were all
replaced with the result of its initialization result in the entry.
Finally, as Xiang suggested, this now uses the source to determine
domination.
The result of these is faster compiles and faster code produced. No
incorrect behavior should have resulted from the previous code. So this
doesn't correct any.
Incidental removal of unused method in SROA_HLSL
* Avoid more problem memcpy replaces
The previous location for memcpy replace too narrow. It only handled one
way that memcpy replacement might be triggered. What's more, it was done
regardless of other things, potentially quicker to check that might
prevent the replacement. By moving the check into ReplaceMemcpy, it is
checked every time it needs to be and never when it doesn't.
Additionally, ReplaceMemcpy was called on memcpys that were created as
part of a memcpy split. This isn't a problem if they get replaced by
loads and stores, but if all uses of the dest are replaced by the src,
the memcpy is essentially removed. sub-memcpy params are only used
directly by their memcpy. So this effectively removes the sub memcpy
entirely. By detecting when the only users of the memcpy parameters are
that memcpy and refusing to replace it entirely, we evade this however
it arises.
This eliminates the earlier fix that disabled subelement memcpy when the
domination check failed. The effect is largely the same in many cases,
but makes the check more directly.
* 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.
* Gather should not be considered a gradient operation.
* Mark WriteSamplerFeedback[Bias] as gradient
* Remove SampleCmpLevelZero from DxilConvergent
* Add WriteSamplerFeedback[Bias] to DxilConvergent
Three classes of fixes:
First a couple of trivial fixes in the DxcPix storage class, for >1-d arrays and embedded types.
Second, the addition of a new fragment iterator (now renamed "member iterator") that knows how to traverse the full structure of a struct, enabling the DxcPix* code to know bit offset and size for contained types.
Third, fixes to the numbering pass to know how to find alloca offsets via the various GetElementPtr statements that result when addressing struct members.
Lastly, a whole bunch of unit tests. Cuz this was really hard.
Remaining to do, as noted in the tests: the presence of a pointer-to-pointer type like floatNxM results in dbg.declare instructions not being emitted for structs. These tests (and perhaps some of the code) will need to be revisited if/when this is fixed.
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.
The previous lowering of dx.break() assumed that the user was still a
branch as it was when it was set up. However, optimizations can switch
things around so this assumption is wrong.
By allowing for other instructions, the replacement takes place just the
same regardless of whether its a branch.
Various code simplifications too.
* Account for non-one user of dx.break call
The original code expected that optimizations wouldn't remove any of the
users of a call to dx.break(). In loop unrolling cases, simplifyCFG may
do just that, which caused the original assert and assume we're right
method to break.
Now we assert we're in the confines of what is now known to be possible,
but we don't assume anything. There's a loop over the users of the call
instruction that I only ever expect to be executed once or never, but
it's there just in case.
* 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 splitting a memcpy because of faile dependency checks, any memcpy
created to copy part of the original is going to have the same
characteristics that caused the first to be split. Instead of splitting
repeatedly, just use the alternative code generation built into splitCpy
* 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.
Allow static global resource arrays to be lowered to allocas
Note: allowing other aggregate types here leads to problems due to
not properly translating aggregate initializers.
When the only use of an alloca is as the destination of a memcpy
operation, the compiler will try to replace all uses of the alloca with
the source of the memcpy. That's fine when all the uses are in locations
where the source of the memcpy is sure to be defined, otherwise, a lot
of complicated PHI insertion is needed to get things right. Lacking it
made LCSSA checks fail. When LCSSA did succeed in inserting PHIs, it did
it wrong which caused other problems.
Rather than do the complicated PHI insertion at memcpy replace, this
change borrows from the previous work for global variables in similar
circumstances and recharacterizes the use of the pointer to be stored
only, but not uniquely. The result of this is the memcpy is replaced
with a load/store pair. There is a good chance that pair will go on to
be replaced by the mem2reg pass, which eliminates the alloca in the end.
That pass has excellent PHI insertion logic that gets everything right.
The added test includes a number of different conditional locations for
memcpy that each produced unique issues in investigating this issue.
- 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
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.
When stripping reflection data, structures are searched for any member
or submember scalars that are smaller than 32 bits. When one is found
and min precision is being used, the structure is identified as not
being able to be stripped.
In the case of a shader that has a resource that contains a struct which
contains an array which contains a struct, the struct was not being
processed as a struct, but rather as a scalar, which would cause it to
return a size of zero, which was found to be less than 32 bits. This
isn't right if the innermost struct contained a 32 bit integer. Either
way, this resulted in inconsistent results for the parent struct and the
innermost struct. As a result, the annotations were stripped from the
innermost, but left on the outermost. Because the parent struct had
annotations, validation was attempted, but ultimately hit an assert or
caused validation failures because of the innermost struct being
stripped.
By reorganizing the function that searches for 16 bit scalars to look
for a struct only after processing the arrays, the struct is properly
traversed and all annotations are stripped, avoiding the failures.
Rather than determining all aspects of keeping or stripping reflection
annotation based on the individual struct and its contents, all structs
contained in a struct are collected so that they can be excluded from
stripping should their parent struct be found needing of maintaining its
annotations.
Thanks to @tex3d for suggesting (and mostly implementing) this addition
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.
When validating CBuffer ranges, the validator may find itself with a field
with an empty EltSize. This may be due to partial reflection stripping which
removes some of the annotations, but not all. This allows the validation to
begin, but runs into problems with the missing inner fields. Specifically, this
has been found to occur when using a library stage with a cbuffer containing
an array of structs. This is a bug with the compiler that this change works
around by bailing on validation late.
This can also occur when a cbuffer contains an array of empty structs. Not
a terribly useful case, but it should be handled correctly.
This also adds tests for each of the above described conditions.
* 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>
* Add missing UTF8 for source and output filenames
- These need to be converted back to UTF-16 after argument processing for
a couple APIs and CA2W constructors were missing CP_UTF8 for the input
encoding from the utf-8 argument strings.
* Add CP_UTF8 to more CW2A and CA2W uses
* 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>
This checkin adds new basic blocks as new preceding blocks between blocks containing Phis and the previous preceding blocks. The new blocks output PIX debug instrumentation for the value named by the Phi for that edge.
Zero code change here, except moving the #include for DxilOperations.h to be on its own in a few files, in order to cope with our clang-format's habit of ordering includes alphabetically.
This is in preparation for a real change coming next.
- 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
* Always write shader hash when supported, don't tie to debug name
* Stop trimming quotes from pdb name
This is the responsibility of cmd.exe, not the API.
The API user should not be adding extra quotes to the pdb name string
if they don't want them.
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.
- Makes it compatible with a module stripped of function bodies.
- Signature masks are improved, making it necessary to switch expected
masks in DxilContainerTest.
- This would cause an assert when you store, write to bitcode, load from
bitcode, store to bitcode again, then load again, when using the
Type template arg metadata.
- 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
Later versions of clang fail to compile a lambda function that includes
a parameter that shadows an explicit capture. Such a one was introduced
to HLOperationLower recently. This preserves the existing behavior while
removing the shadow.
* Add mesh shader support to RootSignature parsing/validation
* Fix PSV so MS output topology doesn't overlap SigInputVectors
* fix PSV version code to use latest when validation disabled
- Compute mesh payload size before final object serialization
- During CodeGen for MS based on payload parameter
- During CollecShaderFlagsForModule for AS based on DispatchMesh call
- Store payload sizes in corresponding funtion properties, serializing
these properly for HL and Dxil Modules
- Use payload sizes from function props for PSV0 data during serialization
- Validate measured and declared payload sizes, don't just fill in
properties during validation
- Fix Wave/Quad allowed shader stages, enabling Quad* with CS-like models
- rename payloadByteSize members to payloadSizeInBytes
- Add GetMinShaderModelAndMask overload taking CallInst for additional
detail required to produce correct SM mask for Barrier operations
- Update the HLSL syntax from FeedbackTexture2DMinLod to FeedbackTexture2D<SAMPLER_FEEDBACK_MIN_MIP>
- Update DXIL to only have two UAV types for FeedbackTexture2D[Array] and use an extra metadata field to distinguish between the sampler feedback type.
The primitive signature was being used with vertexStoreOutput instructions. It would crash if the vertex signature was bigger than the primitive signature.
GlobalOpt has an explicit test for a function called "main" (eww...) to enable an optimization. This updates the test to match the entry point, independent of its name.
Instead of hard-coding properties here, constructing every overload of
every resource method we know about, then iterating users, we:
- iterate through used intrinsic functions, collecting the ones that
have handle parameters (resource accesses). This will pick up all
used overloads.
- Instead of hard coding read/write access in a table here, we use the
function attribute which carries this same information for main resource
operations.
- Exceptions to matching function attribute:
GetDimensions: DescriptorRead, but commented to match prior behavior
BufferUpdateCounter: Counter
TraceRay[Inline]: Read, but commented to match prior behavior for now
- Then, this type of resource access is emitted for the first handle arg
- Subsequent handles are considered DescriptorRead operations,
- DescriptorRead currently just aliases to Read, but could be useful in
the future if we want to differentiate or support GetDimensions.
- Fix metadata version logic to handle no shader model for early HLModule.
- Modify validation tests that change validator version to 1.3 to also
modify the struct annotation to conform to that version of the type
annotation metadata.
- Fix opcodes from merge.
- Add CHECKs for RayQuery intrinsics in tryAllOps, disabled until handle
alloca can be properly eliminated.
1) avoids leaking exceptions during symbol initialization
2) returns E_FAIL when the scope for a local variable is not found
3) uses getInlinedAtScope when searching for the local variable's scopes.
- Array of [1] would crash in UpdateStructTypeForLegacyLayout
since IsResourceArray would be false.
- Unbounded array has weird quirk in D3DCompiler reflection:
all resources report BindCount == 0, except cbuffer reports UINT_MAX.
Added simple unbounded cases for other resource types to verify.
- Fxc has some auto-binding bugs.
Worked around in the test with explicit binding.
- Added suggested helper functions for strip/wrap array types.
Used in code that's part of this change, but didn't search for other
places to replace yet.
Bugs for arrays:
- Size incorrect for ConstantBuffer type
(should not be divided by array size)
- Size incorrect for StructuredBuffer element
(was calculated with array dimensions multiplied in)
- Nested arrays would assert (ConstantBuffer) or
fail to count/unwrap all resource dims (StructuredBuffer)
Match fxc weirdness:
- ConstantBuffer array has Elements == 1 for inner element type
instead of 0, which would be consistent with everything else.
- StructuredBuffer array has "[0]" appended to the Name
for each array dimension of the buffer...
- base of struct should always be aligned - or internal bug
- offset for array member must always be aligned - (new) validation error
- alloc and verify struct layouts even when not array field
- out of bound check would have missed OOB on last array element
- would translate all matrices into arrays, but all arrays have to be
row-aligned, when only multi-row matrices are row-aligned by fxc.
- would force matrix cols=4 if IsCBuf, but:
a) this is not the correct way to align matrices that should be aligned.
b) IsCBuf was true if resource was array (which should not impact
layout of elements inside)
- now we only translate matrix to array if rows > 1 because, that's the
only case in which they must be aligned like an array. And all arrays
must be aligned (even elements == 1).
Copy of original annotation would copy original struct type,
instead of one for legacy layout. This leads to internal validation
using a different type when validating cbuffer layout than external
validation would use, since this member would be synthesized by the
key, rather than saved and restored directly.
It seemed overkill to request backends to support a @dx.op.threadId.i16 intrinsic so I'm always calling the i32 version and then truncating or zextending to the final type.
- Added test with a number of apparently untested cases
- Updated some tests used for the more exhaustive reflection test
which were failing to compile on fxc due to utf-8 bom and bool `|=`.
- Don't ignore dxc failures with ignore dxbc fails flag.
- Added test with a number of apparently untested cases
- Updated some tests used for the more exhaustive reflection test
which were failing to compile on fxc due to utf-8 bom and bool `|=`.
- Don't ignore dxc failures with ignore dxbc fails flag.
LowerMemcpy tries to see if a variable is only written to by a single memcpy. There is a special case for llvm::Arguments, since arguments have an implicit first write for their initialization in addition to whatever memcpy they might have. During parameter SROA, aggregate arguments get broken down into their constituing elements as plateholder AllocaInsts, and at the end of the pass they'll get promoted back into llvm::Arguments of the SROA'd function. In the intermediate steps, however, a test for isa<Argument> will fail to detect that an AllocaInst is a placeholder for a future argument, and so its implicit initialization will not be taken into account. This would cause a bad ReplaceMemcpy, yielding reads from uninitialized locals, causing undefs and all of that fun stuff.
This would break when official DXIL.dll was used, since it would exclude
the shader hash part that the validator wouldn't recognize, and is not
required for a valid shader. This prevented shader signing for the
output of newer compiler versions.
Buffer<Struct>[i].Field was handled by the structuredbuffer code, which emitted a rawBufferLoad intrinsic. However, typed buffers cannot use rawBufferLoad, so some further code patched it back into a bufferLoad. The problem is that bufferLoad cannot take a byte offset into the element to be loaded, it has to load the entire thing, so we always ended up loading the first struct field.
This fix makes us emit a bufferLoad directly, and use the offset to determine which ResRet components to return, falling back to using a temporary array for dynamic indexing if needed.
The legalize sample offset pass runs a bunch of optimizations in the hope to turn the offset argument into a constant value. This includes running the vanilla "SROA" pass, which differs from the HLSL one and will promote alloca i1s to alloca i8s, which is invalid dxil. This change modifies the "SROA" pass to leave alloca i1s intact as it is the solution least likely to introduce regressions.
* Hide Unix symbols by default
Using the -fvisibility=hidden by default only exposes symbols that have
the __attribute__((visibility("default"))) attribute applied to them.
There are only a couple of functions that are meant to be exposed from
libdxcompiler. To expose the proper functions, the macros used to create
the UUIDs for class types are redefined with the attribute and
DXC_API_IMPORT is defined with the attribute above for non-windows
platforms.
Since we're hiding everything now, the portions that were explicitly
hidden to make MacOS work are removed.
This exposed a number of missing dependencies of libraries and unit
tests. Namely clang-hlsl-tests, clang-spirv-tests, and libclangCodeGen.
Resolves#2203
* Remove explicit marking of DxcThreadMalloc hidden
This was a workaround that is not longer necessary since all symbols are
hidden by default on Unix platforms now.
* Moves the implementation of DxcThreadMalloc to dxcmem.cpp; removes DxcSwapThreadMalloc
* Remove DxcSetThreadMalloc(OrDefault) -- they were always been used for installing the default allocator
* Deletes copy and move ctors and assignment
* stores the allocator in the TLS slot.
* DxcSwapThreadMalloc should be able to install a null allocator
* Marks the DxcThreadMalloc members as hidden (linux only)
Deleted some old code where we manually delete users of resource GV's while stripping debug modules. This is normally unnecessary but harmless, because we are guaranteed to have reduced all resource variables, and any failure to do so would result in a validation failure. However, library shaders can have resource variables. Removing the instructions here would result in incorrect code.
* Modifies DxilDia's to use factories instead of lambdas for creating symbols
DxilDia used to hold a vector of lambdas -- constructors -- for the symbols
it knew about. When the user requested a symbol, said constructor was to be
invoked, creating a brand new symbol.
C++ lambdas can be hard to debug (i.e., how does one inspect the lambda's
state?), so the library is modified to hold a vector of factories -- i.e.,
objects with fields and a CreateSymbol method.
* fixes typo when creating Typedef symbols
* caches the VarInfo when creating the LocalVariable factories
This change adds support for : register(spaceN), where a space is specified but no register, such that the resource allocator runs on the given space.
For backwards compatibility, -auto-binding-space applies to resources without register bindings but not to those with an explicit register assignment like : register(t0) - those always go in space 0. To support this, I had to add state to represent "unspecified space". In the UnusualAnnotation, it's a Optional<uint32_t>. In the DxilResource, it's UINT_MAX, like we do for unspecified registers.
Adds support for templatized RWRawByteBuffer.Store<T>. To avoid SROA making us lose the original layout of any struct arguments, a new pass runs before SROA and breaks down such cases into per-element stores. So better be careful with the likes of buf.Store(0, (int[65536])0);...
This change replaces more malloc/calloc/realloc/free calls to new/delete. This creates several new out of memory exception paths (especially due to changing MallocAllocator) which exposed many memory mismanagement bugs that I found using the OOM test. Hence this grew to be a pretty big change.
(finally) updating PIX's shader access tracking code to add the SM6.3 overloads of the various resource-access opcodes.
The new test passes on debug and release.
We added an exception when the bitcode reader reports an error, however the code higher up in the call stack isn't fully exception-safe and it turns out that two unique_ptrs over the same MemoryBuffer are alive at the same time, hence the double-delete and, more often than not, crash.