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

18 Коммитов

Автор SHA1 Сообщение Дата
Greg Roth 7ad9c9c032
Fallthrough (#4843)
A common source of bugs. Although many of these were harmless, some were
not. By eliminating them and enabling this warning as an error, we won't
add more in the future.


Fixed a real SPIRV bug that required a test update to expect the correct behavior.
SPIRV testing was expecting incorrect results that came from a fallthrough error
2022-12-09 10:13:56 -08:00
Greg Roth caec6aaf9e
Disallow illegal Atomic targets + propagate consts (#4453)
This change does a few things.

First and foremost, it disallows a number of illegal destination
parameters to atomic operations. This includes SRVs and other const
 values, non-groupshared and non-resource variables, members of
typed resources, and bitfield members of any resource.

In addition, this correctly propagates const information so that they
can be properly rejected and also the information is reflected.
This involves the consolidation and earlier detection of a number of
these failures as well as an expansion of that detection.
Also adds validation checks that the targets are not const and either
UAVs or groupshared address space.

The const errors are produced in clang and manifest as overload
mismatches. The errors for member access of typed buffers, bitfields,
or non-groupshared and non-UAV destinations are generated
as part of the lowering operation. This is where they were before
and easier to replicate though they would be better in codegen.
In some cases, existing errors were moved earlier in the process
and the logic to generate them simplified.

Add compilation and verifier tests for all.

Also adds validation errors for const destination targets and other
invalid targets and tests for the same.

In order to make those tests, I had to give locations to the function
candidate notes for function builtins. This changed a single verifier
test that depended on the locationless notes.

These tests make use of const groupshared variables that are of
questionable utility, but are valid for now.

Incidentally enhances some existing atomics tests to use a more
complex sequence of references and subscripts.

Finally incidentally added some foolproofing for mistakenly comparing
opcodes without taking into account the "table" or namespace that
they belonged to by changing some utility functions in Sema to require
the table as well as the opcode to produce results.

Fixes #4319
Fixes #4377
Fixes #4437
2022-05-16 21:26:21 -07:00
Adam Yang 29a5af5e7c
NoUnwind fix. HLExtIntrinsic collision fix. (#3942) 2021-09-10 16:38:46 -07:00
Xiang Li d0fa5e301b
Not dup barrier in HL level. (#3181) 2020-10-02 20:43:40 -07:00
Greg Roth a0196bcc22
Use Attribute to designate wave-sensitive intrinsics (#2853)
* Use Attribute to designate wave-sensitive intrinsics

This adds an intrinsic attribute to indicate wave-sensitivity that can
be indicated in gen_intrin_main.txt. This and other attributes are
passed along through function representations and lowerings. The
wave-sensitivity needs to be maintained specifically through SROA passes
since it is used by the CleanupDxbreak pass that comes after them.

Specifically this is done to allow extension intrinsics to indicate
wave-sensitivity, but the same mechanism is now used for builtin
intrinsics.

Most intrinsics get a mostly nameless function to represent them between
Codegen and dxilgen. This allows any that have the same prototype to
share the same function. For wave-sensitive intrinsics, they need a
different function or else the attrubute would be similarly shared with
intrinsics matching the prototype. So a minor change is made to their
function names to prevent this.

Adds testing for all these ops and a dummy extension one.
2020-04-28 18:19:51 -07:00
Greg Roth d3af7f1237
Conditionalize breaks to keep them in loops (#2795)
* Conditionalize breaks to keep them in loops

This introduces dx.break, a temporary builtin that is applied as a
condition to any unconditional break in order to keep the basic block
inside the loop. Because it remains in the loop, operations that depend
on wave operations inside the loop will be able to get the right values.

Such builtins have to be added at finishcodegen time or else clang
throws an error for an undefined function. Consequently, the creation of
these is split in two. First the branch is created with just a
constant true conditional. Then at finishcodegen, it is converted to the
result of the dx.break() builtin.

By using the result of a temporary builtin function, the optimization
passes don't touch the false conditional like they might if we started
with the global constant. 

Normal break blocks don't need this conditional, but we don't know that
at code generation. So a later pass identifies break blocks with wave
sensitive operations that depend on wave ops that are inside the loop they
are breaking out of and preserves those conditionals while removing all
the rest.

As part of dxil finalization, the dx.break() function is removed and all
branches that depended on it are made to depend on function-local
loads and compares of a global variable dx.break.cond.

The DxBreak Fixup pass depends on dxil-mem2reg. It is placed immediately
after to allow as many optimizations to go as they would without this
change in shaders that don't have any wave ops.
2020-03-30 19:02:04 -07:00
Xiang Li 4098229583
Code cleanup. (#2708)
* Code cleanup.
2020-02-19 16:41:11 -08:00
Xiang Li 91fe12f0eb
Add GetResourceFromHeap. (#2691)
Add GetResourceFromHeap for hlsl.
For Dxil, add CreateHandleFromHeap and AnnotateHandle.

All handles ( createHandle, createHandleForLib, createHandleFromHeap ) must be annotated with AnnotateHandle before use.

TODO: add AnnotateHandle for pix passes.
            cleanup code about resource.
2020-02-12 21:50:02 -08:00
Tex Riddell 734accbce5 Merged PR 100: Eliminate phi on resources/handles for library
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
2018-07-13 02:04:31 +00:00
Greg Roth ccbb0ec117 [linux-port] Add missing case statements (#1346)
When switching over an enum value, the ideal is to include a case
for every possibly value. Where possible, that's what this change
does to silence warnings and also to provide space to properly
handle every possible input and throw a warning should a new one
be added. In some cases, it's not practical to list every input.
In these cases, putting a default that doesn't change the behavior,
but let's the compiler know that the behavior is intended.
Fixes 133 clang and 8108(!) gcc warnings.
2018-06-08 20:19:52 -04:00
Greg Roth 57f1909f5d [linux-port] Fix preprocessor warnings (#1323)
Remove pragma once from source files. It has no meaning in a source
file unless it's used as a header, which, fortunately, none of
these are.
Fixes 3 clang and 3 gcc warnings.

Remove trailing tokens after #endifs. Common result from copy,
paste, and slightly alter the beginning #if line to keep the
comments after consistent.
Fixes 3 clang and 3 gcc warnings.
2018-05-30 12:50:46 -04:00
Xiang Li 6cca464f51 Remove copy be replace dst with src. (#296)
1. Generate memcpy in EmitHLSLFlatConversionAggregateCopy if type is match.
2. If value is used as Src of memcpy, mark load instead of store.
3. Do not do replace on GEP and bitcast.
4. Delete inst instead of push into DeadInsts when safe.
     This will prevent same inst added into DeadInsts more than once.
2017-05-16 12:37:40 -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 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
Tex Riddell af6b2a552f fixes #37 - License cleanup. 2017-01-27 16:48:08 -08:00
David Peixotto 9451f2c0b3 Add initial support for extension intrinsics and defines (#5)
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.
2017-01-17 17:51:13 -08:00
Marcelo Lopez Ruiz 6ee4074a4b first commit 2016-12-28 11:52:27 -08:00