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

3519 Коммитов

Автор SHA1 Сообщение Дата
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
Marcelo Lopez Ruiz 6f2f08bac1 Update default maxcpucount in hctbuild (#202)
Quick fix; we tend to be more constrained by memory than cycles in many build configurations, so ease back a bit.
2017-04-11 10:55:25 -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 26d48613ba No need to qualify methods with class name in class body (#198) 2017-04-11 09:03:46 -07:00
Marcelo Lopez Ruiz 06e0f064e8 Update README.md with hctgettaef reference 2017-04-10 23:16:06 -07:00
Marcelo Lopez Ruiz 2cce7933fb Add support for an inline TAEF install rather than requiring WDK (#196)
Adds support for SDK 10.0.15063.0.
Adds support for TAEF download into external dir, no WDK required.
2017-04-10 22:53:37 -07:00
Lei Zhang 892e7953fd Match filename cases (#199) 2017-04-10 22:52:10 -07:00
David Peixotto f4cad71d1b Allow dxopt.exe to read from stdin (#194)
Support both text (.ll) and binary (.bc) inputs on stdin.
2017-04-08 14:33:11 -07:00
Lei Zhang db586162c2 Move some functions from clang CodeGen to clang AST (#193)
These functions are defined in HlslTypes.h in clang AST so they
should have implementations in libclangAST.a.
2017-04-08 11:01:12 -07:00
Lei Zhang 900f072920 Fix missing $ before CMAKE_CURRENT_SOURCE_DIR (#192)
Thanks for the fix!
2017-04-07 13:56:56 -07:00
Marcelo Lopez Ruiz 254f253b14 Move unused global tracing flags into single usage, closes #157. (#185)
* Move unused global tracing flags into single usage, closes #157.

Normalizes API-provided names to include at least a current-relative
directory, simplifying file lookups. There are still restrictions on
how expressive include handlers enable the virtual file system to be,
these should be documented on the project wiki.

Handle some errors in BeginSourceFile paths where include handlers may
cause early errors, before compilation execution can begin.

Removes the prior scheme for directory handles, where the same handle
would be returned for any parent directory.

Future improvements would be to expand dxc paths before calling into
dxcompiler, and/or to fully implement OS API calls from console apps.

Improve hcttest to describe build config better and not override env var.
2017-04-07 12:02:20 -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 0677af11e4 Don't cast function type in HLSLExternalSource::CanConvert. (#190) 2017-04-06 12:55:47 -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
Tex Riddell 3fda136aee Fix #180 Select correct device when running ShaderOp tests. (#181)
* Fix reversed inf/-inf, comment typos
* Select correct device when running ShaderOp tests.
* Fix appendCount log message in ExecutionTest::WaveIntrinsicPSTest
2017-04-04 13:10:10 -07: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 6cb57e90be Add support for building with VS 2017 integrated cmake (#125)
Use the new CMake build support in VS2017 to build without having to run cmake
separately. Removes the need to download cmake separately.

By default binaries are built in:

  %LOCALAPPDATA%\CMakeBuild\DirectXShaderCompiler\build\{build-flavor}

Build settings can be changed by modifying CMakeSettings.json.
2017-03-31 16:15:15 -07:00
David Peixotto c9bdb370d7 Make hctdb compatiable with python 3 (#173)
Make sure we only use python3 compatible code.  In the process of compatibility
fixes I found a bug in how we check for duplicate instruction classes. The fixed
code triggers an assert because we have duplicate instruction classes. I have
commented out the assert for now and we can re-enable it when we sort out what
we want to do about the duplicated classes.
2017-03-31 15:41:53 -07:00
Xiang Li 8693031f38 Force minprec cast to float for case DXIL don't support f16. (#178) 2017-03-31 15:39:31 -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 cea8048912 Use CreateTempAlloca to make sure alloca is in entry block. (#165) 2017-03-28 18:44:31 -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
Marcelo Lopez Ruiz 19568158d1 dndxc UX improvements (#149)
* Add support to dndxc for debug line lookup, restore CFG printer passes.

* Add support to dndxc to interactively grow and shrink code font.

* Fix highlights for modified controls, and enlarge/shrink font generally.
2017-03-27 21:00:30 +01:00
Marcelo Lopez Ruiz f9401736a6 Fix memory leaks and improve build (#156)
* 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.
2017-03-27 20:59:05 +01:00
Xiang Li d712e7e651 Skip decl which don't have init when ScanConstInitList. (#155) 2017-03-24 18:08:56 -07:00
Xiang Li df5f52024b Make scalar static global matrix to col major. (#154) 2017-03-23 16:53:42 -07:00
Tex Riddell 027a3dcf3d Merge pull request #152 from Microsoft/dxil-v1.0
Merge dxil-v1.0 into master
2017-03-22 17:20:18 -07:00
Xiang Li 02832543e0 Do not make basic type rvalue to lvalue. (#148) 2017-03-20 13:58:50 -07:00
Tex Riddell 6b3aeea0e5 Merge pull request #147 from Microsoft/master
Merge master into dxil-v1.0
2017-03-20 12:16:59 -07:00
Xiang Li 094dfa1746 Save imm initializer when possible. (#145)
* 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.
2017-03-20 11:19:22 -07:00
Young Kim 2f3a28076c Disable function call inside function parameter declaration (#144)
This change is to syntactically check function declarations inside a function parameter.
Note that in vanilla clang they allow this to pass in a function to a function (c99, 6.9.1). So this check should be changed once we support function pointers in HLSL.
2017-03-16 13:21:47 -07:00
Xiang Li 29a09802e3 Support array of struct when flatten types. (#143) 2017-03-15 18:08:15 -07:00
Xiang Li a38ada07d0 Support component float to bool cast. (#142) 2017-03-15 18:08:03 -07:00
Xiang Li a8d4c914ce Set array bounds for case like int ar[] = {1, 2, 3}. (#141) 2017-03-15 16:05:44 -07:00
Xiang Li 8b5a14ec74 Support dynamic indexing on matrix subscript. (#140) 2017-03-15 15:02:30 -07:00
Xiang Li b88ce03da3 Support swizzle indexing. (#139) 2017-03-15 15:02:16 -07:00
Young Kim dc00d74028 Set default global varaibles to const (#117)
Implement default global varaibles.
According to HLSL documentation, the global variables are set to default const unless it is specified with 'static' specifier. The front end therefore should assign 'const' specifiers for all global variables that will be in global constant buffers. We also show warnings for 'extern const' variables that have initializers since these variables should be imported from external sources.
2017-03-15 10:56:13 -07:00
Young Kim 1a1475326e Check Syntax errors for matrix/vector subscript operators (#123)
Check Syntax errors for matrix/vector subscript operators
 - Throw errors for subscript operators with index out of bounds
 - Throw errors for cases where matrix/vectors are modified using subscript operators
 - There was an issue on the release build with the vector/matrix variables
    picking invalid candidate for overloaded array subscript operators. This was because
    implicit conversion sequence was not initialized correctly.
2017-03-15 10:31:38 -07:00