There are more cases in which the center/sample/etc modifier
should be treated as identifiers:
* Inside decoration groups
* In assignments
* Inside parentheses
* etc.
This commit adds a few more special handling cases that turns these
modifiers into identifiers, upon seeing the next token as punctuator.
Store outputs before IgnoreHit/AcceptHitAndEndSearch
SROA_Parameter_HLSL would copy arguments to/from allocas at entry and each return. These instrinsics need outputs to have been updated before the call, and do not return (have no-return attribute).
Make sure we copy to outputs before the function call by:
- Split block and add return immediately after call
- SROA_ParameterHLSL will then insert copy to outputs before each return
- In HLOperationLower, move call to just before the return (after copy to outputs)
- Later, the return (all code following the no-return call) will be replaced with 'unreachable'
Also fix build error in DxilPatchShaderRecordBindings.cpp with unused local var cast (void*)index;
Eliminate phi on resources/handles for library
- ensure all handles use only one global resource
- replace resource path with indices into global resource
- replace resource alloca with index allocas
- AddCreateHandleForPhiNodeAndSelect now unnecessary, deleted
- error on resources in library function params or return
- mark entry clones as internal linkage since they could contain params
that are not allowed for libraries.
- fix MarkUavUpdateCounter - handle nested GEP
- disallow static resource use from exported library functions
- add/update tests
- detect undef resource paths that would otherwise be lost (FailUndefResource)
- set internal linkage for HL intrinsic function bodies so they aren't processed with user functions
- Rename legalize [static] resource use passes to DxilPromote(Local|Static)Resources
- Remove various dead code paths for resources, such as:
GenerateParamDxilResourceHandles, RemoveLocalDxilResourceAllocas,
lower handle cast, non-promotable error (may translate to index allocas)
- force resource GVs to external constant with no initializer
For VK_HKR_relaxed_block_layout, a vector inside structs can have
its offset as a multiple of its base element type's alignment.
But the vector's alignment is unaffected, esp. when used for
calculating the alignment of the whole enclosing struct.
Also enables SPIRV-Tools validation on block layouts.
Included file HANDLEs are generated using the type, the file index
and some representation of the directory. Since they are not real
files on a real filesystem, they don't have genuine handles.
This conversion is performed using a union containing the above
values and a HANDLE object, which is returned after these are assigned
However, the size of the above values is far less than that of the
HANDLE, which leaves many bits uninitialized, containing random
values.
By initializing the handle to 0, then the capital-B "Bits" values,
no small-b bits are left uninitialized.
Like on other platforms, on Windows, strtoul is limited to the size
long. However, long on windows is 32, on linux, it's 64. So Linux
happily converts a string that requires more than 32 bits.
However, it is returned into a variable that is only 32 bits.
In order to keep Linux behavior consistent with Windows, and for
lack of a strtou function, strtoul is still called, but overflow
of 32 bits is detected and reported as an error, making Verifier-
Test happy.
* Add 'center' keyword as an interpolation modifier
FXC allows the interpolation modifier 'center' (equivalent to 'linear') and DXC should too. At places where interpolation modifier is not expected 'center' can still be used as an identifier. This change makes it easier to switch from FXC to DXC. Add warnings when center is used with centroid or sample. Update varmod-syntax.hlsl test to include 'center'.
* Allow 'sample', 'precise' and 'globallycoherent' as identifiers
In DXC 'sample', 'precise' and 'globallycoherent' were treated as a keywords and could not be used as identifiers. FXC allowed this.
This change makes it easier to switch from FXC to DXC.
* Update fxc errors in varmods-syntax.hlsl based on fxc version 10.0.17713.
MultiByteToWideChar and WideCharToMultiByte were returning -1 on
failure, which caused failures to be ignored. When successful, they
were returning the number of characters converted excluding the
terminating null character because that's what the std:: functions
used for the implementation do. Both are inconsistent with the
original Windows implementations.
Simply adding one to the return value works in all cases save those
where the number of characters converted was limited by the parameter
In this case, the number of characters converted doesn't include
the terminating null. So no addition is warrented.
Added addition errors in keeping with the function descriptions.
The CW2A conversion class left out the terminating null character
when calculating the max size of the converted string.
A lambda function relied on captured variables after they went out
of scope. The result on Linux was access to random data. The effect
varies randomly just as returning a point to a variable that goes
out of scope might.
Due to existing bugs in debug builds, this couldn't be committed
before now. It should catch that and other issues by being tested
regularly. It just compiles a very simple HLSL shader to spirv and
compares with a previously generated spirv output file
This adds an isolated component *IDxcDxrFallbackCompiler* that is used by the D3D12 Raytracing Fallback Compiler. The component is responsible for linking together DXR shaders into a state machine capable of emulating function invocations including recursion, patching HLSL intrinsics, export renaming, and emulating Shader Record support. This component is compiled to a DxrFallbackCompiler.dll that gets consumedd with D3D12 Raytracing Fallback Compiler apps.
For deeper implementation details, I will be fleshing out lib\DxrFallback\readme.md
Some leftover work still required:
1. Currently the Fallback Layer tests compile to an exe that must be manually run. This should be refactored to conform with existing DXIL unittests.
We should always create a temporary variable for rvalues if we
are trying to get an access chain from it. Now do it in the
turnIntoElementPtr() function, which is used everywhere.
Fixes https://github.com/Microsoft/DirectXShaderCompiler/issues/1387
The previous implementation of CreateFileW for Unix didn't set any permission
flags for the new files it created. This sets the default file
permissions granting read and write permissions to the owner and
read permissions to everyone else. This perpetuates the behavior
before the offending change.
Also adds a few simple smoke tests to verify the code produced by
dxc as well as file creation behavior and other basic smoke-level
functionality of dxc.
Keeping the original struct type is important for some reflection
workflows.
The validation check for layout is alo included. But we disable
it for now and will re-enable it after fixing all the failures.
Fixes https://github.com/Microsoft/DirectXShaderCompiler/issues/1364
The REGEX_H define prevented the inclusion of an Apple system header.
Not coincidentally, the same header regex_impl.h was derived from.
Prevent Apple warning by splitting macro args with an #else. Add HLSL
change comments too which were missing from the start.
Search for libdxcompiler.dylib instead of .so on Apple.
MacOS resolves symbols differently from Linux. Linux takes the first
valid resolution and then uses it wherever it is referenced. MacOS
more similar to Windows, favors symbols that are local to the
compilation unit.
This comes into play where functions set static globals such as
the malloc tls and the IMalloc contained there. The dxc binary
initializes these. For Linux, that's enough because all calls
resolve to the ones from this binary because they are encountered
first. MacOS calls that originate from within the dynamic library
resolve to the local functions, which don't have their globals
initialized. To initialize them, we need to do what is done in
DLLMain in DXCompiler.cpp.
Performing these calls results in duplicate initializations on Linux
unless the calls in question are given visibility hidden. This is
the default on Windows, but not on Unix OSes.
LLVM includes a DynamicLibrary class that works on multiple platforms
Rather than ifdefing between dlopen for non-Windows and LoadLibraryW
on Windows, using this class allows us to abstract platform differences
while using the same code.
Changed DxilLibInitialize to attempt to initialize dxil.dll so the
smart mutex inside the dynamic library object uses the same IMalloc
as the other ManagedStatic objects so they can all be freed in order.
Alpine Linux and probably several others, define fopen64, fseeko64,
ftello64, and tmpfile64 to their 32 bit equivalents in system
headers. This results in duplicates in areas of the code that
include 32 bit and 64 bit references to this. Since HLSL doesn't
have any of these functions anyway, we can safely exclude them.
Some interactions with the FileSystem are not used by any API and are
therefore not implemented for Unix at the moment. We have put assertions in
place to make it easy to spot if any of those methods are ever used.
This change disables the build targets that are not supported on Unix
platforms when compiling on those platforms.
We were also ignoring DXCompiler.cpp when compilation in the past. We
can now bring it back.
We have also added cmake-predefined-config-params which contains all the
cmake configurations needed to build on Unix platforms. It will make it
easy for developers to build.
Some workflow relies on trimming off unused stage output variables.
But we created a wrapper around the source code entry function to
satisfy Vulkan's requirement over entry function signature.
Previously we just blindly write back all stage output variables
in the wrapper function no matter whether the corresponding stage
output variable is used or not in the source code entry function.
Now we can be a little bit clever based on the usedness info
from the AST.
Some code originally in llvm/clang was commented out, and was replaced
with Windows-specific implementation. In this change we bring back some
of those.
Also disabled some code that is not relevant any more.
And a few minor improvements towards cross-platform compilation.
This change completes the necessary adapter code needed to enable
cross-platform compilation.
Discussion on the design/implementation of these are in issue #1341 and
isuee #1342.
In addition to the adapter classes/structs, there exists usages of
Windows-specific functions in the codebase. In some cases, we won't need
to compile/run some of those methods on non-Windows platforms. For the
few cases where we do, we have implemented equivalent functionality in
WindowsFunctions.cpp.
InitializeCriticalSection, DeleteCriticalSection, EnterCriticalSection,
and LeaveCriticalSection serve to create a mutual exclusion section of
code, but they are stubbed out currently for non-win platforms.
There is multi-platform support for the same functionality in LLVM
in the form of SmartMutex. This switches from the Windows specific
to the abstraction, allowing the same code to work on other platforms.
We were unifying struct types as long as they have the exact
same members (regardless of names). BUt it turns out some
reflection workflow requires the exact original struct type
to work.
Add shader mask and min SM to RDAT
- add OP::GetMinShaderModelAndMask to compute mask and min SM
- account for ops that can be translated during linking
- update PS ops that could be allowed in library functions
- update min SM with newer optional feature flags
Fix AV in TranslateHLSubscript for typed buffer with struct element