* Update PSV with ViewID data structures
* Update PSV with signature element data and gate PSV1 on SM 6.1
* Unwrap array on primitive when assigning semantic indexes
- fix semantic index assignment for matrix and primitives
- fix some tests
- disable two tests due to AssembleToContainer fail:
ValidationTest::SigOutOfRangeFail
ValidationTest::SimpleGs1Fail
unlike other system value semantics, pixel shader is allowed to declare at most two input attributes with SV_Barycentrics, with one declaration uses perspective interpolation type while other one uses noperspective interpolation type.
* Add documentation with source-level debugging with HLSL and DXIL.
* Fix trailing underscore in generate .rst documentation.
* Add container support for debug name part.
* Bump validator version to 1.1.
* Implement debug stripping in dxc, including /Fd dir-named behavior.
* Implement IDxcCompiler2 and CompileWithDebug.
1. Add ResourceToHandle pass to lower resource to handle.
2. Don't performPromotion in SROA_HLSL.
3. Add Option support for DynamicIndexingVectorToArray.
4. Fix bug in GetPassOption.
5. Replace GEP ptr, 0 with ptr in DynamicIndexingVectorToArray::ReplaceStaticIndexingOnVector.
6. Run mem2reg before DxilGenerationPass.
7.Legalize EvalOperations before change vector to array.
* [spirv] Add libclangSPIRV and skeleton FrontendAction for SPIR-V
* [spirv] Add -spirv into dxc for invoking EmitSPIRVAction
* [spirv] Build SPIR-V codegen conditionally
Added ENABLE_SPIRV_CODEGEN in CMake config to control the
building of SPIR-V component and wrap up SPIR-V code using it.
Also add -spirv to hctbuild to turn it on.
Currently the compiler crashes when we pass in matrix or vectors with reduced dimension from the original signature element for EvalAttribute functions. This change resolves this issue by replacing allocas before we translate these function calls from DXIR to DXIL and find LoadInputs to replace correctly.
Make DxcCreateInstance load validator from dxil.dll when available
Add DxcVersionInfoFlags_Internal flag to indicate internal validator
Add DxcValidatorFlags_ModuleOnly to indicate absense of full container for validation, requiring explicit use. This will not succeed when using dxil.dll validator.
Bump Validator version
Implement IDxcVersionInfo in DxcCompiler to indicate DXIL highest version supported and debug flag for compiler separately from validator
Refactor version detection code for tests, adding dxil and validator versions
Make SystemValueTest version aware
Add version check to AttributeAtVertex and SV_Barycentrics tests.
Fix line endings for HlslTestUtils.h
1. Adding SV_Barycentric and removing barycentric intrinsics/dxilops
2. GetAttributeAtVertex only thakes no_interpolation attribute
3. SV_Barycentric can take any interpolation modifier except nointerpolation
4. SV_Barycentric can only have float3 type
1. Try to propagate if the pointer is only write once by the memcpy.
2. Use correct size for memcpy created in AppendBuffer::Append.
3. Ignore unused Constant user of Matrix value.
4. Replace Constant with Inst on the Instruction version of Constant.
5. When match size of memcpy, go deeper if struct only has 1 element.
Doing this will leave memcpy be lowered at deeper level.
6. Do not replace when SimplePtrCopy, cannot decide replace is safe or not.
- Add SV_ViewID loaded from intrinsic in Dxil,
for input to all graphics shader stages
- hctdb: rename shader_models to shader_stages,
add shader_model for min required shader model
- Validator: validate dxil version required for shader model
- DxilModule: Add GetDxilVersion
- Set Barycentric intrinsics to SM 6.1
- Update SystemValueTest for SM 6.1
This change is the initial step to support Barycentric coordinates for shader model 6.1 / DXIL 1.1
- Add GetBarycentrics, GetAttributeAtVertex intrinsics and their corresponding dxil ops
- Lowering intrinsics to dxil ops
- Adding codegen tests for these operations
1. Keep major for matrix pointers.
2. Change matrix values to row major to match hlsl.
Only ColMatLoad, RowMatrixToColMatrix and col matrix value parameter for entry function are col major matrix value.
And should only used by ColMatStore and ColMatrixToRowMatrix.
1. Add resource attribute to FieldAnnotation.
2. Find resource arribute from Argument in FindCreateHandleResourceBase.
3. Remove limitation handle must be instruction.
4. Add HandleToResCast to help lower resource parameter to handle parameter.
1. Remove debug info when strip function parameter from entry function.
2. Set OptLevel to 0 for -Od.
3. If optimization is disabled, always load ReturnValue.
This commit adds placeholder hooks to support constant folding of
extensions. They are defined in a separate file to make it easy to merge
changes or link in other versions. There should be no upstream changes to
these definitions.
This commit adds the 'dxil' strategy for lowering extensions. This
strategy will change the extension call into a call to a dxil intrinsic.
This is useful for targeting dxil intrinsics that are not exposed in hlsl.
This commit adds a new pass to hoist arrays from local to global scope
when the array only contains constant values. A local array will use
alloca and stores for initialization, but a global array uses a global
variable with a constant initializer.
The idea is that a global array with constant initializer will allow the
backend compilers to produce better code because it is much easier to see
that the array is fully constant.
This change modifies dxil constant folding to use the opcode class when
deciding if a dxil function can be constant folded. We now require a
DxilModule to be available when constant folding dxil functions.
To ensure that the dxil module is available we add a new pass that loads a
dxil module from metadata if it does not exist. We use the new pass in the
dxopt tests for constant folding.
* Ensure the cached Function->OpCodeClass map is updated
The original goal of this change was to use opcode class for deciding when we
can perform constant folding on a function.
We maintain a mapping from Function* to OpCodeClass inside the OP class.
We wanted to use this map in constant folding to decide if we can constant
fold a function to avoid string comparison on the function names.
However, it turns out that the DxilModule is not always available during
constant folding of dxil calls so we cannot use the map inside of OP. The
change contains a few bug fixes and improvements that came out of trying
to get opcode class working inside constant folding.
1. Use opcode class in dxil constant folding where possible.
2. Make sure the opcode cache is refreshed properly.
3. Remove 64-bit test for bfi.
4. Add equality comparison for the ShaderModel class.
When switching to use the opcode class for constant folding, we discovered
that our test for 64-bit bfi is invalid. There is no 64-bit overload for
bfi in dxil, so the test we had written was not legal dxil. This change
removes the 64-bit test for bfi constant prop.
This commit adds the ability to constant fold dxil intrinsics when
all inputs are constant. We reuse the llvm constant folding
infrastructure and add special cases for calls to dxil intrinsics.
This patch changes codegen for firstbithigh and firstbitlow.
For firstbitlow we do not generate a select on the return value from the
intrinsic. The previous codegen would check if the value is 0 and return -1 if
it was. However, the FirstbitLo intrinsic will return -1 when the input is 0 so
the select is not needed. So regardless of the input value we can take the
result of the intrinsic. This would match the code produced by fxc.
For firstbithi we check the value returned from the intrinsic for -1. If
the value returned is -1 we return -1. We do this for both signed and
unsigned intrinsics. The old codegen would check the input value for
0 and so would produce wrong code when the input value was -1.
We also disable constant folding in the front end for these intrinsics.
There was a bug in the constant folding that would cause a crash and
we are adding constant folding for dxil intrinsics to the optimizer
so we should not need it explicitly in the frontend for these
intrinsics.
* Lower resource to createHandle at clang code gen.
1. A HL createHandle will have 1 or 2 parameters.
For uav/srv/sampler, 1 parameter. 1 is the resource load from resource ptr.
For cbuffer, 2 parameter. 1 is the same. 2 is for dynamic indexing on array of cbuffers.
uav/srv/sampler don't have 2 is because all the use of them is on builtin methods. Resource on methods is scalar.
createHandle function will have metadata to save the resource information like class/kind/type/...
2. Added 2 more passes DxilLegalizeResourceUsePass DxilLegalizeStaticResourceUsePass to remove load/store on local/static resource.
Also make sure HL createHandle don't have phi operand.
3. For DxilGenerationPass, Dxil createHandle will be generated after GenerateDxilOperations.
And HLObjectOperationLowerHelper now get RK/RC from MetadataAsValue argument of HL createHandle.
* Add support for reflection on types of constant-buffer members.
This change performs a best-effort translation from the LLVM types and their DXIL annotations over to the representation exported by the current `ID3D12ShaderReflectionType` interface.
- Added missing implementation of `CShaderReflectionType` members that implement `ID3D12ShaderReflectionType`
- Added a new `CShaderReflectionType::Initialize()` that intializates the instance data from an `llvm::Type*` and its `DxilFieldAnnotation`
- The main complexity here is a helper routine to extract the appropriate `D3D_SHADER_VARIABLE_TYPE` from an `llvm::StructType*`. The current code copies the logic used in `HLModule::IsHLSLObjectType()`; that bit of copy-paste programming may need to be refactored away.
- Call into the new logic where there had been a `TODO: create reflection type` comment before
- Know issues:
- Leaks the `CShaderReflectionType` instances. It is probably best to just store the type of a variable directly in the `CShaderReflectionVariable`, but the existing declarations had an unowned pointer, so I expect a tiny bit of discussion is warranted about the right way to proceed.
- Related: I did not implement the type equality test (`ID3D12ShaderReflectionType::IsEqual()`), because I don't expect it is needed by most users, and it adds complexity. A trivial implementation might store and then compare the underlying `llvm::Type` pointers, but it isn't clear to me whether the type-equality test here is supposed to consider additional properites like offsets for `struct` fields.
Fixes issue #134
* Address small-scope review feedback.
Thanks to @marcelolr for the comments. This change tries to address the simpler style/convention issues. The memory ownership fix will come next.
* Update DXBC reflection comparison tests to comapre type reflection data.
This is a small change. I added a `CompareType()` method to `DxilContainerTest` that can compare the fields of two `ID3D12ShaderReflectionType*`, and then invoked aht routine when comparing the members of reflection contstant buffers.
The comparison applies to all the simple data fields, but does *not* test:
- Anything related to inheritance, interfaces, sub-types, etc.
- Type equality tests (they aren't being implemented right now, and I don't know if most clients of the reflection API care about them)
* Fix computation of names for fxc-compatible reflection types.
Previously I'd used the name from the DXIL *field* annotation, which obviously isn't correct.
For now I just compute type names in a relatively ad hoc fashion, using the information I glean as I destructure the type.
I also don't try to be efficient, and just use `std::string` operations to concatenate on suffixes for matrices/vectors.
Not yet handled here:
- Arrays (do they get suffixed in DXBC reflection data?)
- Object types
- Any demangling required for user-defined `struct` types (is there any?)
* More fixes to fxc-compatible reflection for types.
- A matrix may show up as an LLVM array type, so we need to be careful when unwrapping outer array types to *not* count a matrix as an array.
- Be a little more overt about handling array layouts: include a note that the `Undefined` layout is being treated as column-major (the default).
- Correct name for `uint` type in reflection (apparently it reflects as `dword`)
- Remove any `struct.` prefix from user-define `struct` type names
- Apparently `struct` types are "scalar enough" that they get `Rows` and `Columns` set to 1. Need to double-check whether this should just apply to *all* non-matrix/vector types.
- Store field types with an indirection, so that type name (stored in a `std::string`) doesn't get copied/moved and thus invalidate the pointer we store in `m_Desc.Name`
- Special-case `void` so that it can have a correct name (not sure if this will matter in practice)
* Create fxc-compatible reflection types for `StructuredBuffer` element type
- This was another case where a shader reflection type was just being left `NULL`; it just didn't have a handy `TODO` comment calling it out. :)
* More fixes for fxc-compatible type reflection.
- Reflect scalar `uint` type name as `"dword"`, but not for vector/matrix (e.g., still use `"uint3"`)
- Supress checking of the `Offset` field in type reflection for element type of a structured buffer
- Note: looking at the existing compiler output for structured buffers, there seems to be an existing (hopefully known) issue that the field offsets for `StructuredBuffer` elements don't match fxc
- Strip of prefixes from user-defined `struct` type names: `"struct."` and `"dx.alignment.legacy."`
- Try to emulate fxc behavior for computing the `Columns` field for reflection on a `struct` type
- The behavior here doesn't seem to be documented on MSDN (it implies that `Columns` would be zero for a `struct` type)
- From what I can tell, the desired value is something like "total number of scalar values (not counting objects) recursively contained in this `struct` type"
With these changes, the revamped `DxilContainerTest::ReflectionMatchesDXBC_`{`Checkin`,`Full`} tests pass.
* Implement memory management for fxc-compatible reflection types.
In previous changes the `CShaderReflectionType` instances were allowed to leak.
This change still heap allocates the types, but places `std::unique_ptr`s to them all into a field in the base shader reflection object.
The reason for storing the types together in one master list (rather than having, e.g., a `CShaderReflectionVariable` directly store a `unique_ptr` to its type) is to allow for the possibility of re-using identical types in cases where that is possible (e.g., two `cbuffer` fields that use the same `struct` type should be able to share the `CShaderReflectionType` instances for their nested fields).
* Traverse call graph to report recursive calls in the front-end.
* Emit function declarations only as needed.
* Fix extra echo output in hctbuild help.
* Remove unused test case.
* Remove clang header generation from the build
These headers aren't used by the compiler nor by HLSL program.
* Remove references to clang-headers and redundant discard test.
* Fix a few leaks to make tests pass with AppVerifier.
* Save imm initializer when possible.
* Remove UpdateHLSLIncompleteArrayType which already done in SemaInit.
* Take care parent record in AddMissingCastOpsInInitList and HLSLExternalSource::GetNumBasicElements.
* Support nest init list in CaculateInitListArraySizeForHLSL.
Add reducibility analysis to the list of passes and paramless ctor.
This restores the property of having all passes initialized at DLL load time, keeps the reported list of passes stable, and fixes an assertion when the DLL is loaded on a thread but the first compile invocation occurs in a different thread.
1. enable unsigned keyword for [int,min16int,int64] vectors and matrices
(e.g. unsigned int2 -> vector<unsigned int, 2>)
2. disable unsigned keyword as a complete type specifier
Previously, If an extension uses the replication lowering strategy
and a non-vector overload was chosen we would return the function
un-modified. This change makes sure that we still use the
custom lowering name for the extension if one was specified.
This commit adds a standalone class for expanding macros and uses it
to for root signature and semantic define processing. Previously,
we were using the raw macro value instead of the expanded value
so something like:
#define MYRS "DescriptorTable(SRV(t0))"
#define RS MYRS
would fail to compile the root signature with an entry point of
RS because it would get a root signature value of MYRS instead
of the expanded value. Similarly, for semantic defines we were
saving the non-expanded value into the bitcode.
This commit also adds a new flag that is used to specify that
the root signature should be read from a #define. So compiling
with `-rootsig-define RS` will read the root signature from
a `#define RS ...` in the source. The -roosig-define flag
takes precedence over a root signature annotation in the souce.
* Only promote local resource when has store of handle.
* Report error when cannot map local resource usage to global resource.
* Promote static resource when optimization is disabled too.
* Take care PHINode on local resource.
* Dxc fix verifyrootsignature option
- distinguish stream type (stdout, stderr) when printing to console
- verifyrootsignature option returns correct errorlevel depending on its result
- adding more test cases to hcttest for verifyrootsignature option
- enable verifyrootsignature option when dxil.dll not present
* Fixes from review
- Change parameters for writing to consoles from File* to DWORD
- Change comment when dxil.dll does not exist
* Fix ValidateDxilBitcode PSV generation for Root Signature validation.
- also fix validation for empty patch constant signature.
* Test container and root signature validation.
* Fix DXASSERT when PC in/out patch sig mismatch HS.
- zero DxilProgramSignatureElement to prevent garbage in signature
- rewrite bitcode when stripping root signature
- use correct part when reading debug module in ValidateDxilContainer
- report general error message when signature validation fails
* Clean up dxc options:
setrootsignature, setprivate :
Allow replacing existing rootsignature or private data and make a new container with new parts
(e.g dxc /dumpbin private.dxil /setprivate private.data /Fo private.new.dxil)
extractrootsignature:
Make it back compatible with fxc by returning dxil container with RTS0 part only and having the user to provide /Fo option.
Other Options:
For unimplemented options that was from fxc, ignore those options and proceed given operation.
For unimplemented options that was not from fxc, remove them for now.
Add more test cases for dxc command line operations.
Fix ISenseOption flag to have valid HLSL version check for dxc (disable 2015)
* Fix Preprocess option for dxc
Fix hcttestcmd for testing invalid rootsignature
* Write thread group uniform value will not cause race condition.
* Only report race condition when know the data is not uniform.
* Disable race condition check.
- Implement and centralize container validation components in DxilValidation
- Strip RootSignature from module metadata before serializing to container
- Use existing DxilModule when serializing rather than constructing new one
- Add DxilModule::TryGetDxilModule for capturing diagnostics on metadata load
- Expose DxilPartWriters/DxilContainerWriter for use elsewhere (such as in validation)
- Update command line options of dxc
(Qstrip_debug, Qstrip_priv, Qstrip_rootsignature, setrootsignature, getprivate, setprivate)
- Add IDxcContainerBuilder API and its implementation
- Resolve lifetime of dxil.dll on dxcompiler.dll to guarantee access of memory generated from dxil.dll
Fix#30: Revert license text in banner comments to original llvm verbage
This commit removes the Microsoft-specific copyright in llvm files
and reverts the copyright wording to the original llvm wording.
We used the following method to find the files to change:
1. Find all files in DirectXShaderCompiler that are also in llvm 3.7
2. For those files that have the Microsoft-specific copyright, revert
it to the original llvm copyright as present in llvm 3.7
3. Revert the copyright in a few files that are not in llvm, but are
mostly copies of files in llvm:
lib\Transforms\Scalar\ScalarReplAggregatesHLSL.cpp
lib\Transforms\Scalar\Reg2MemHLSL.cpp
Leave the Microsoft-specific copyright header in files not present
in stock llvm:
include\dxc\*
lib\HLSL\*
lib\DxcSupport\*
tools\clang\test\HLSL\*
tools\clang\test\CodeGenHLSL\*
tools\clang\unittests\HLSL\*
tools\clang\unittests\HLSLHost\*
tools\clang\tools\dxcompiler\*
tools\clang\tools\dxa\*
tools\clang\tools\dxc\*
tools\clang\tools\dxopt\*
tools\clang\tools\dxr\*
tools\clang\tools\dxv\*
tools\clang\tools\dotnetc\*
utils\hct\*
CONTRIBUTING.md
COPYRIGHT
LICENSE-MIT
README.md
cmake\modules\FindD3D12.cmake
cmake\modules\FindDiaSDK.cmake
cmake\modules\FindTAEF.cmake
docs\DXIL.rst
docs\HLSLChanges.rst
docs\_themes\dxc-theme\layout.html
docs\_themes\dxc-theme\theme.conf
docs\_themes\dxc-theme\static\dxc-theme.css
include\llvm\llvm_assert\assert.h
include\llvm\llvm_assert\cassert
include\llvm\Support\MSFileSystem.h
include\llvm\Support\OacrIgnoreCond.h
lib\MSSupport\CMakeLists.txt
lib\MSSupport\MSFileSystemImpl.cpp
lib\Support\assert.cpp
lib\Support\MSFileSystemBasic.cpp
lib\Support\Windows\MSFileSystem.inc.cpp
lib\Transforms\Scalar\Reg2MemHLSL.cpp
lib\Transforms\Scalar\ScalarReplAggregatesHLSL.cpp
tools\clang\docs\UsingDxc.rst
tools\clang\include\clang\AST\HlslTypes.h
tools\clang\include\clang\Basic\BuiltinsDXIL.def
tools\clang\include\clang\Basic\LangOptions.fixed.def
tools\clang\include\clang\Parse\ParseHLSL.h
tools\clang\include\clang\Sema\SemaHLSL.h
tools\clang\lib\AST\ASTContextHLSL.cpp
tools\clang\lib\AST\HlslTypes.cpp
tools\clang\lib\CodeGen\CGHLSLMS.cpp
tools\clang\lib\CodeGen\CGHLSLRuntime.cpp
tools\clang\lib\CodeGen\CGHLSLRuntime.h
tools\clang\lib\Frontend\Rewrite\FrontendActions_rewrite.cpp
tools\clang\lib\Parse\HLSLRootSignature.cpp
tools\clang\lib\Parse\HLSLRootSignature.h
tools\clang\lib\Parse\ParseHLSL.cpp
tools\clang\lib\Sema\gen_intrin_main_tables_15.h
tools\clang\lib\Sema\SemaHLSL.cpp
tools\clang\tools\d3dcomp\CMakeLists.txt
tools\clang\tools\d3dcomp\d3dcomp.cpp
tools\clang\tools\d3dcomp\d3dcomp.def
tools\clang\tools\libclang\dxcisenseimpl.cpp
tools\clang\tools\libclang\dxcisenseimpl.h
tools\clang\tools\libclang\dxcrewriteunused.cpp
tools\clang\tools\libclang\libclang.rc
tools\dxexp\CMakeLists.txt
tools\dxexp\dxexp.cpp
tools\dxexp\LLVMBuild.txt
This commit adds support for extension intrinsics that work as
methods on resources. For example, we could have an extension
on buffers called `MyBufferOp`
Buffer<float2> buf;
float2 val = buf.MyBufferOp(int2(1, 2))
To support extension methods we add a new resource lowering strategy
that does three transformations to the intrinsic call
1. Expand vectors in place in the call arguments.
2. Convert non-void return value to dx.types.ResRet.
3. Convert resource parameter to dx.types.Handle value.
For example, assuming that MyBufferOp has opcode 138. The resource
lowering strategy would convert the call as HL-dxil to dxil as
follows
call <2 x float> MyBufferOp(i32 138, %class.Buffer %3, <2 x i32> <1 , 2> )
==>
call %dx.types.ResRet.f32 MyBufferOp(i32 138, %dx.types.Handle %buf, i32 1, i32 2 )
This commit improves the support for intrinsics added through
the IDxcIntrinsicTable interface:
- Only rewrite unsigned opcode for builtin intrinsics
- Allow replication to work when only vector is return value
- upconvert to 6.0 in dxc.exe and d3dcompiler_dxc_bridge
- restrict to 6.0 in dxcompiler API
- restrict to 6.0 in DxilValidator
- allow loading of SM < 6.0 for now on DXIL 0.7
- Add DxilSignatureAllocator for signature packing
- Fix signature validation. Add more validation.
- Fix and add validation tests.
- Fix codegen for inout params with SV like SV_Coverage
- fix m_SemanticStartIndex on DxilSignatureElement::Initialize
- fix DxilSignatureElement::GetColsAsMask for start col == 2
- Add diags for signature allocation failures
- Use Regex in ValidationTest
This commit adds initial support for extension intrinsics and defines, including:
-Support for recognizing hlsl extensions as new intrinsic functions.
-Support for requesting lowering of extensions.
-Support for preserving semantic defines.
-Support for validating semantic defines.
This commit adds support for hlsl extensions in the form of additional
intrisic functions and semantic defines.
We now allow a dxcompiler instance to register that it can handle
additional intrinsic functions beyond the standard hlsl intrinsics. These
new intrinsics are called extensions. For each extension, the compiler
supplies a lowering strategy that is used by the dxcompiler to translate
from the source level intrinsic to a high-level dxil intrinsic.
We initially support the two lowering strategies: replicate and pack.
The replicate strategy will scalarize the vector elements in the call
and replicate the function call once for each element in the vector.
The pack strategy changes the vector arguments into literal struct
arguments.
We also now include support for "semantic defines". A semantic define is
a source level define whose value is preserved in the final dxil as
metatdata. The source level define can come as either a #define in
the hlsl source or a /D define from the command line.
We provide a hook to validate that a semantic define has a legal value
(for example to ensure that the value is an integer). Validation failures
can produce warnings and errors that will be emitted through the standard
clang diagnostic mechanism.
This code was originally written by marcelolr and modified by dmpots to
support packed lowering of intriniscs and validation of semantic defines.