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

146 Коммитов

Автор SHA1 Сообщение Дата
Young Kim f66e8083d6 Allow two SV_Barycentrics (#282)
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.
2017-05-09 18:59:30 -07:00
Marcelo Lopez Ruiz ad76d814a4 Debug name part implementation (#264)
* 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.
2017-05-09 18:32:48 -07:00
Xiang Li 9edb1a553e Lower static global resource and local resource to handle. (#276)
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.
2017-05-05 18:31:35 -07:00
Lei Zhang 2c7a3fc39d [spirv] Add bare bone code for SPIR-V codegen (#233)
* [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.
2017-05-05 19:39:59 -03:00
Young Kim 47d21ad6c0 Fix EvalauteAttribute Intrinsics (#275)
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.
2017-05-05 15:10:46 -07:00
Tex Riddell da5f98bb95 Updates to DxcValidator and DxcCompiler wrt. versioning/flags (#269)
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
2017-05-04 22:18:57 -07:00
Xiang Li 7179f13400 Do not create phi on non-default address space. (#273) 2017-05-04 16:25:44 -07:00
Young Kim 13cf7d466c Update barycentric with new spec (#265)
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
2017-05-03 17:07:02 -07:00
Tex Riddell c0d3163ee3 Dxil versioned OpCode/Class counts, and other dxil versioning fixes (#263) 2017-05-02 14:42:05 -07:00
Tex Riddell bd6c105e9b Add ViewID slot validation for PSIn (#254) 2017-05-01 17:54:33 -07:00
Xiang Li d108a552de Refactoring DynamicIndexingVectorToArray to share code with MultiDimArrayToOneDimArray. (#259) 2017-05-01 11:15:32 -07:00
Xiang Li 9f437adda5 Lower memcpy before SORA a pointer. (#253)
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.
2017-04-28 14:42:04 -07:00
Tex Riddell a581927370 Add SV_ViewID support (#251)
- 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
2017-04-27 14:17:31 -07:00
Young Kim 108b897f40 Barycentric init (#250)
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
2017-04-26 12:29:48 -07:00
Xiang Li aec310b4ea Use memcpy to copy when possible in clang code gen to avoid flatten too early. (#247) 2017-04-25 13:37:06 -07:00
Xiang Li 478a433366 Disable CSE, leave it to target backend. (#246) 2017-04-24 19:19:22 -07:00
Tex Riddell 23082dbef2 Add HLSL 2017 (-HV 2017) option. (#245)
- Fix detection of invalid options in dxcompilerobj
2017-04-24 16:05:06 -07:00
Xiang Li bc4a68b6b4 Use SRet for struct return type. (#243)
1. Use SRet for struct return type.
2. Add SM6.1 and DXIL1.1.
2017-04-24 14:34:57 -07:00
Xiang Li 6bc247d4af Lower parameter (#242)
* Lower vector/matrix/resource/multi-dim array parameters to  scalars/array/handle/one-dim array.

* Code cleanup.
2017-04-21 17:47:26 -07:00
Xiang Li e14dc5ed1b Update matrix code gen. (#234)
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.
2017-04-21 11:56:37 -07:00
Xiang Li 4c22ec7802 Prepare to support handle as parameter. (#231)
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.
2017-04-19 11:33:33 -07:00
Xiang Li 3911371309 Fix dbg info for temp variable. (#230)
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.
2017-04-18 13:49:59 -07:00
Marcelo Lopez Ruiz b3eb288629 Add opt support for naming module prints and to diff them in dndxc. (#228) 2017-04-16 22:01:30 -07:00
David Peixotto 449165a52d Run constant array hoisting pass by default (#224) 2017-04-13 17:56:28 -07:00
David Peixotto 022eb5717f Add hooks for constant folding extensions (#209)
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.
2017-04-13 15:04:14 -07:00
Lei Zhang c9f8438d90 Remove unnecessary const qualifier on return type (#221)
This solves compiler warnings given by -Wignored-qualifiers.
2017-04-13 14:41:08 -07:00
David Peixotto 76a4288913 Support lowering extensions directly to dxil (#217)
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.
2017-04-13 10:19:00 -07:00
Lei Zhang 7008b2ad52 Add default virtual destructors for virtual classes (#218)
This fixes compiler warnings generated by -Wnon-virtual-dtor.
2017-04-12 14:21:01 -07:00
Lei Zhang 806fbb2bbf Fix initialization order of various class members (#211)
This solves compiler warnings given -Wreorder.
2017-04-12 13:34:28 -07:00
Lei Zhang 8c6ba6716b Upgrade SAL annotations in some source files (#197) 2017-04-12 12:39:41 -07:00
David Peixotto 0ba250e9dc Add pass to hoist constant arrays (#205)
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.
2017-04-11 13:58:16 -07:00
Lei Zhang 026176362f Use typename to mark subtypes in templated class (#200) 2017-04-11 09:26:39 -07:00
Lei Zhang 8afb120125 Use llvm::make_unique instead of std::make_unique (#201)
std::make_unique is a C++14 feature.
2017-04-11 09:15:34 -07:00
Lei Zhang 892e7953fd Match filename cases (#199) 2017-04-10 22:52:10 -07:00
David Peixotto b0fd2d3949 Use opcode class to guide constant folding possibilities (#191)
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.
2017-04-06 17:42:42 -07:00
Xiang Li bd16165aa7 Keep unused pointer in TranslateHLSubscript, it will be removed in TranslateSubscriptOperation. (#188) 2017-04-06 13:56:09 -07:00
David Peixotto deec58372a Ensure the cached Function->OpCodeClass map is updated (#186)
* 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.
2017-04-06 13:48:27 -07:00
Xiang Li 9e8137c54d Use high level intrinsic when lower matrix mul to make sure DXIL operation only exist when DxilModule is ready. (#189) 2017-04-06 12:36:28 -07:00
Xiang Li 73e76ff294 Use mad for matrix mul. (#184) 2017-04-05 10:39:56 -07:00
Marcelo Lopez Ruiz a528d7bd86 Remove use of dynamic_cast, use dyn_cast instead. (#183)
Remove use of dynamic_cast, use dyn_cast instead.
2017-04-05 02:28:20 +01:00
David Peixotto ae69cf0a58 Add constant folding for dxil intrinsics (#179)
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.
2017-04-04 09:15:19 -07:00
David Peixotto 84c30e388d Make hctdb output stable (#172) 2017-03-30 18:38:48 -07:00
Xiang Li c7db25781e Report error on invalid input/ouput type. (#176) 2017-03-30 14:12:36 -07:00
Xiang Li 2b4f3e4801 Support resource inside cbuffer. (#175) 2017-03-30 12:06:21 -07:00
Xiang Li 238c2221e2 Cast i32 col idx into i8. (#170) 2017-03-29 16:53:39 -07:00
David Peixotto 13f92a77c4 Fix #169 - Bad codegen for firstbithigh/firstbitlow (#171)
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.
2017-03-29 12:38:07 -07:00
Xiang Li a3306bff1d Lower resource to createHandle at clang code gen. (#163)
* 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.
2017-03-28 18:43:59 -07:00
Xiang Li 9afb4cfcb8 Don't change bitcast (gep a, 0, 0) into bicast a for validation. (#164) 2017-03-28 17:27:31 -07:00
Tim Foley 7aa3fbd04b Generate fxc-compatible reflection type info for buffer members (#146)
* 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).
2017-03-28 00:25:37 +01:00
Marcelo Lopez Ruiz 843be2528a Close #62: strange error output on recursive function calls (#150)
* 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.
2017-03-28 00:12:55 +01:00