In some cases, arrays embedded within an HLSL global static will be backed by an llvm global variable, rather than an alloca or a set of discrete values.
In those cases, there will be no dbg.value or dbg.declare statements that will allow PIX to associate stores to those globals with the HLSL variable.
But it's possible to stitch the storage to the HLSL variable and emit the dbg.value (and "fake" alloca/stores that PIX's debug instrumentation uses for tracking changes to values during execution).
Prior to this work, PIX had no visibility into non-const global statics at all. Now, PIX can see most things, inlcluding the above-described class of embedded arrays. However, more work remains:
-dynamic indexing of the arrays is not considered
-arrays that have been reduced to 1-dimensional equivalents are not covered
The first two will be tackled next. The last will probably be left until and unless requested by a PIX customer.
In brief, this change walks the global variables and compares types, offsets and sizes to determine where arrays might be embedded within other global variables. Maps are constructed to go from a global member's name to the actual member's offset/size, and from the HLSL DIGlobalVariable to the per-function DILocalVariable "alias" or "mirror" of that global (which are denoted by the "global." name prefix) . This allows the "fake" alloca/store and dbg.declares to be emitted for any store to a GEP operand that references those embedded arrays. (If no other members of the HLSL global are accessed, then there will be no DILocalVariable for the new dbg.declares to be associated with, so a new DILocalVariable must be emitted.)
* [opt] initialize HLSL passes with SetupRegistryPassForHLSL
call hlsl::SetupRegistryPassForHLSL in opt to initialize all HLSL/DXIL passes.
This is for enable lit by default where opt test used to test HLSL/DXIL passes.
GetViewIDOutputMask and GetInputToOutputTable take an output index to support multiple stream outputs in geometry shaders.
Previously, these functions would map the same local pointer to a location for serializing or deserializing the dependency bit vectors.
This causes data to overlap and size to be computed based only on the last used stream.
This change fixes this by using an array of pointers for each of these.
Then, a new test verifies output for two streams, which fails without this fix.
Documentation comments are now formatted using Doxygen-style markup. Although there's no automated processes in place to generate documentation from this markup, aligning around this style allows for comments that are more readable than xmldoc when viewed as text.
Patch by Jake VanAdrighem!
Summary:
Fix the way we sort the llvm.used and llvm.compiler.used members.
This bug seems to have been introduced in rL183756 through a set of improper casts to GlobalValue*. In subsequent patches this problem was missed and transformed into a getName call on a ConstantExpr.
Reviewers: silvas
Subscribers: silvas, llvm-commits
Differential Revision: http://reviews.llvm.org/D12851
llvm-svn: 248728
Co-authored-by: Sean Silva <chisophugis@gmail.com>
These passes have already been run by PIX at this point, and running them twice is both a waste and a source of issues: the annotate-with-virtual-registers pass might thereby change virtual register ordinals, which will cause PIX's view of HLSL variables to degrade as the user steps further into a long function.
* Fix loss of buffer type info with libraries and linker
## Fix loss of buffer type info.
When undef, there was no global symbol, thus type-preserving cast was lost,
and undef type for resource would be dx.types.Handle instead. This would
particularly impact path through higher lib target then linked to a lower
final shader target.
The fix is to use the HLSL type for undef when the GlobalSymbol is undef.
## Copy resource type annotation in linker.
Linker was dropping the resource type annotation for the target module.
Fixed by copying the type annotation to the target after AddResource.
## Check resource type annotation with libs and linking and various targets
These tests check both module metadata and reflection dump.
While IR may be unnecessary given reflection check, it does reveal some
format inconsistencies that should be addressed.
TODO: investigate https://github.com/microsoft/DirectXShaderCompiler/issues/5202
* Set the layout rule in processTemplatedLoadFromBuffer
They layout rules for value coming from processTemplatedLoadFromBuffer
are inconsistent, and this is causing problems. This PR changes the
function to return an instruction whose layout rule is Void.
This should remove the inconsistenty.
Fixes#5123
* Add test
The cg.return.memory-layout.hlsl had to be updated because the Byteaddress load no longer has a different layout rule.
* Remove `-Vd` from test
* Fix reflection on bitfield.
This is for case where bitfield member lost when reflection.
Save bitfield information in DxilFieldAnnotation.
Then use the information in CShaderReflectionType::Initialize.
Add field for the integer and put bit fields as members of the integer field.
* Require break-critical-edges to run before reg2mem_hlsl
A DXIL shader containing a loop, where the `phi` node at the
beginning of the loop is re-used outside the loop, does not get
translated correctly by this version of reg2mem. Running critical
edge splitting beforehand resolves the issue.
* Add a test which verifies the fix
This fixes some fallthrough warnings that were appearing in C source
files and enables -Werror for both C and C++ sources.
Additionally, this fixes some GCC warnings and migrates AppVeyor builds
to building with clang-14 to reach agreement between GCC and Clang
about what is valid in C++.
This is for enable lit by default.
It fix issue when running single test instead of all test under lit.
%TEST_CLANG% will not get update until out of the if.
* [enable lit] Keep same name for ClangHLSLTests when enable lit
This is for enable lit by default.
It will make sure with/without lit enabled, ClangHLSLTests output dll with same name.
Use ClangHLSLTests because LIT needs GoogleTest binaries to be named that way for test discovery.
* Fix build error for deprecated function in UCRT.
This is for enable-lit by default.
gtest got link error for missing dup/dup2/close/creat.
* Update comment.
* Mark HLSL Change.
Those files are the required to drive the new GCP pipeline aimed to
replace AppVeyor. As-is, those file have no effect on the repo.
What's needed to add the CI is to setup some repository permissions,
and only then CI will be able to run.
This CI will build x86_64 versions of DXC on both Linux and Windows, run
tests, and allow retrieving build artifacts (same as Appveyor).
Signed-off-by: Nathan Gauër <brioche@google.com>
HLSL objects have a special hook for validating template arguments.
Previously, this didn't handle dependent arguments.
This change skips dependent arguments, which will be checked once they are concrete.
* [CMake] Update distribution build for DXC
Building off the LLVM 3.9 changes, this gets the `install-distribution`
target working for DXC with preset parameters that configure the
normal distribution. It also enables the DXC distribution to be built
through Visual Studio builds since DXC has a limited number of
components so it doesn't suffer from the IDE issues that upstream
LLVM & Clang do.
The `hctbuild` tooling has been updated to set a default install
prefix relative to the build directory, and allow overriding with a flag.
Cherry-picked commit details below:
From c90e12fe9fd7eb9fd7b342e7ac0cec971dd3e4db Mon Sep 17 00:00:00 2001
From: Chris Bieneman <beanz@apple.com>
Date: Tue, 23 Feb 2016 20:33:53 +0000
Subject: [PATCH] [CMake] Create an install-distribution target driven by LLVM_DISTRIBUTION_COMPONENTS
The idea here is to provide a customizable install target that only depends on building the things you actually want to install. It relies on each component being installed having an auto-generated install-${component}, which in turn depends only on the target being installed.
This is fundamentally a workaround for the fact that CMake generates build files which have their "install" target depend on the "all" target. This results in "ninja install" building a bunch of unneeded things.
llvm-svn: 261681
Under HLSL 2021 short circuiting ternary operators result in _very_
different control flow in these tests, so they aren't really portable.
Changing these tests to being HV 2018 keeps them working with minimal
changes.
This change moves some of the raytracing entry signature diagnostics up
into Sema. This is fallout from some work that I'm doing to cleanup and
reduce complexity in HLSL's CodeGen code, but it is also generally just
a win.
By catching these errors in Sema we stop compilation earlier and don't
need to make our Code Generation code resilient against invalid ASTs or
partial IR generation.
When a semantic was in an inherited class, it was missed and caused
issues later down the pipe. This was because we assumed semantic fields
would only be present at the top-level struct, ignoring inheritance.
This commit also changes the parameter type from `DeclaratorDecl` to
`NamedDecl` as it only requires methods up to `NamedDecl`. Loosening
this requirement allowed me to pass a CXXRecordDecl.
Fixes#5138
Signed-off-by: Nathan Gauër <brioche@google.com>
This pulls in a couple upstream commits by myself and @bogner.
commit 3adaa8cf4a6df45430b47a62c649c7cb54bb1626
Author: Justin Bogner <mail@justinbogner.com>
Date: Wed Jun 8 22:36:37 2016 +0000
cmake: Simplify add_lit_testsuites
cmake 3.4 introduced LIST_DIRECTORIES to glob recurse, which can be
used to simplify this code greatly.
llvm-svn: 272217
commit 25ef9e34c9de7b1edc327189b78200459337f7e5
Author: Justin Bogner <mail@justinbogner.com>
Date: Mon Jul 25 18:07:14 2016 +0000
cmake: When adding lit testsuites, ignore Output directories
With in-tree builds we can get Output directories scattered among
our
tests. Recursing into those to find tests doesn't make sense.
Thanks to nlewycky for noticing this!
llvm-svn: 276667
commit a44ef999fb5e9243df9c4459df1b17b66aa3fd23
Author: Chris Bieneman <chris.bieneman@me.com>
Date: Mon Jan 3 11:52:44 2022 -0600
[NFC][CMake] Add FOLDER to utility targets
As Visual Studio's CMake support is getting better and better the
line
between IDE generator and non-IDE generators is blurring. Visual
Studio
2019 and later have a very useful UI that can handle all of the
various
targets we create, but if they are unsorted it is wildly unwieldy.
This change sorts the lit testsuite targets and per-component
install
targets into folders, which are not generated for IDE generators but
are generated by default under Visual Studio's CMake + Ninja
integration.
* spirv: fix crash when no initializer can be made
When an initializer can't be implemented, an error should be emitted.
Because we deref a pointer without checking for error, we simply crash,
preventing the diagnostic message to be shown.
(Fixing #5124 crash)
Signed-off-by: Nathan Gauër <brioche@google.com>
* [template] Support empty template arg list on TypeAliasTemplateDecl.
This is to help add sperate type for row major and column major matrix.
The issue is only support ClassTemplateSpecializationDecl in getHLSLDefaultSpecialization.
It cause compile error on t22 in following shader.
template<typename T=float, int i=0>
struct test {
T d;
};
template<typename T=float>
using test2 = test<T, 1>;
test2 t22;
The fix is using Sema::CheckTemplateIdType to generate the default specialization for all TemplateDecl.
SemaHLSL had various locations where getAsStructureType or isStructureType were used, when classes should have been handled in the same way.
This change uses `getAs<RecordType>` instead of `getAsStructureType` and replaces `isStructureType` with `isStructureOrClassType` in locations that should handle structs and classes.
Also, it deletes unused HLSL methods in `clang::Sema` found while adding unit tests.
New tests added and existing tests updated.
- `err_hlsl_typeintemplateargument_requires_struct`: say struct/class rather than just struct
- VerifierTests with Texture2D using a specific class failed because it was `class`, not for the right reasons, other checks happen later which could happen earlier, but not this change's purpose to reimplement new diagnostics
- One test had `CHECK-NOT: and` which unfortunately collided with the branch name (`and` in `handle...`) in the llvm.ident metadata. Added label to scope the check to the code in the function.
Fixed a crash when there's addrspacecast going into a getelementptr, which goes into a dbg.decare. The HLSL SROA pass was incorrectly calling dropAllReferences on the addrspacecast ConstExpr, which invalidates the getelementptr ConstExpr (sets the operand to nullptr).
This script automates some operations to make it easier to write IR tests:
1. Gets the pass list for an HLSL compilation using -Odump
2. Compiles HLSL with -fcgl and outputs to intermediate IR
3. Collects list of passes before the desired pass and adds
-hlsl-passes-pause to write correct metadata
4. Invokes dxopt to run passes on -fcgl output and write bitcode result
5. Disassembles bitcode to .ll file for use as a test
6. Inserts RUN line with -hlsl-passes-resume and desired pass
This script automates some operations to make it easier to write IR tests:
1. Gets the pass list for an HLSL compilation using -Odump
2. Compiles HLSL with -fcgl and outputs to intermediate IR
3. Collects list of passes before the desired pass and adds
-hlsl-passes-pause to write correct metadata
4. Invokes dxopt to run passes on -fcgl output and write bitcode result
5. Disassembles bitcode to .ll file for use as a test
6. Inserts RUN line with -hlsl-passes-resume and desired pass
Initially the change here was forcing unannotated parameters to be
treated as uses (`in` parameters). Instead this changes to not handle
them explicitly.
Most `in` parameter uses should produce `LValueToRValue` casts which
will be identified as uses through other means, but by removing this
special case we can support unannotated AST nodes from generated ASTs
through this analysis based on their type and usage alone.
Fixes#5093
We should not try to validate template arguments for invalid decls.
Doing so seems to result in infinte recursion that eventually kills the
compiler... so let's not do that.
Fixes#3455
The UninitializedValues analysis doesn't correctly handle arrays or pointer objects, so we should not enable out parameter analysis for those types. Additionally, because the HLSL ASTs incorrectly represent structure out parameters as non-reference types, the analysis will generate incorrect diagnostics for uses of structs in call expressions. There isn't really an easy solution for that. This change takes a conservative approach to addressing those issues by disabling the analysis for values that we can't correctly identify.
This change also disables the "suggest initialization" fix-it for out parameters. Default initialization for out parameters doesn't work, and would be confusing.
This change adds diagnostic support for uninitialized `out` parameters.
With this change, `out` parameters are treated as uninitiailzed values
until they are initialized and use of the values produdces a diagnostic.
This change is a slightly hacky extension of Clang's uninitiailzed
values analysis which is achieved by adding ParamVarDecls for `out`
parameters to the list of variables to analyize. It also adds dummy
uses of the variables on `return` statements.
It also introduces the maybe_unused attribute, adopting C++ naming and
C++-like behavior.
When applied to an `out` parameter `maybe_unused` results in skipping
uninitialized value analysis on return and function block exits only
if the value is always uninitialized.
If the value is maybe uninitialized or if the value is used explicitly
the warnings are still emitted.