aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/HLSLExternalSemaSource.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-05-28[HLSL] Add Buffer def to frontend (#141086)Ashley Coleman1-0/+13
Fixes #138902 Defines the `Buffer<>` type in the clang frontend. Lowering from IR->Target Machine is already handled by other code
2025-05-14[HLSL] Add resource constructor with implicit binding for global resources ↵Helena Kotas1-1/+2
(#138976) Adds constructor for resources with implicit binding and applies it to all resources without binding at the global scope. Adds Clang builtin function `__builtin_hlsl_resource_handlefromimplicitbinding` that gets translated to `llvm.dx|spv.resource.handlefromimplicitbinding` intrinsic calls. Specific bindings are assigned in DXILResourceImplicitBinding pass. Design proposals: https://github.com/llvm/wg-hlsl/blob/main/proposals/0024-implicit-resource-binding.md https://github.com/llvm/wg-hlsl/blob/main/proposals/0025-resource-constructors.md One change from the proposals is that the `orderId` parameter is added onto the constructor. Originally it was supposed to be generated in codegen when the `llvm.dx|spv.resource.handlefromimplicitbinding` call is emitted, but that is not possible because the call is inside a constructor, and the constructor body is generated once per resource type and not resource instance. So the only way to inject instance-based data like `orderId` into the `llvm.dx|spv.resource.handlefromimplicitbinding` call is that it must come in via the constructor argument. Closes #136784
2025-04-29[HLSL] Resource initialization by constructors (#135120)Helena Kotas1-1/+2
- Adds resource constructor that takes explicit binding for all resource classes. - Updates implementation of default resource constructor to initialize resource handle to `poison`. - Removes initialization of resource classes from Codegen. - Initialization of `cbuffer` still needs to happen in `CGHLSLRuntime` because it does not have a corresponding resource class type. - Adds `ImplicitCastExpr` for builtin function calls. Sema adds these automatically when a method of a template class is instantiated, but some resource classes like `ByteAddressBuffer` are not templates so they need to have this added explicitly. Design proposal: llvm/wg-hlsl#197 Closes #134154
2025-03-24[HLSL][NFC] Refactor HLSLExternalSemaSource (#131032)Helena Kotas1-747/+2
Moving builder classes into separate files `HLSLBuiltinTypeDeclBuilder.cpp`/`.h`, changing a some `HLSLExternalSemaSource` methods to private and removing unused methods. This is a prep work before we start adding more builtin types and methods, like textures, resource constructors or matrices. For example constructors could make use of the `BuiltinTypeMethodBuilder`, but this helper class was defined in `HLSLExternalSemaSource.cpp` after the method that creates a constructor. Rather than reshuffling the code one big source file I am moving the builders into a separate cpp & header file and placing the helper classes declarations up top. Currently the new header only exposes `BuiltinTypeDeclBuilder` to `HLSLExternalSemaSource`. In the future but we might decide to expose more helper classes as needed.
2025-03-17[HLSL] Remove HLSLResource attribute (#130342)Helena Kotas1-26/+20
Fixes #104862
2024-12-20[HLSL] Add Load(int) method on structured buffers (#120663)Helena Kotas1-0/+3
Adds `T Load(int)` method on `StructuredBuffer`, `RWStructuredBuffer` and `RasterizerOrderedStructuredBuffer`. Uses the existing `addLoadMethods` in HLSLExternalSemalSource so most of this change is just tests. Fixes #112977
2024-12-19[HLSL] Add concepts for Structured buffers (#119643)Joshua Batista1-13/+78
This PR adds concept validation to structured buffers, in the same way that it was done for typed buffers (like RWBuffer) in https://github.com/llvm/llvm-project/pull/116413. This PR should also be responsible for introducing rejection of 0 size elements for structured buffers. Fixes https://github.com/llvm/llvm-project/issues/117406
2024-12-17[HLSL][NFC] Fix static analyzer concerns (#120090)Mariya Podchishchaeva1-0/+4
Class BuiltinTypeMethodBuilder has a user-defined destructor so likely compiler generated special functions may behave incorrectly. Delete explicitly copy constructor and copy assignment operator to avoid potential errors.
2024-12-16[HLSL] Add RWBuffer::Load(Index) (#117018)Justin Bogner1-0/+15
This method is the same as `operator[]`, except that it returns a value instead of a reference.
2024-12-10[NFC] Cleanup comments in HLSLExternalSemaSource.cpp (#119444)Joshua Batista1-7/+7
Cleaning up some comments that @bogner pointed out were unpolished.
2024-12-09[HLSL] Implement `Append` and `Consume` methods on ↵Helena Kotas1-14/+66
`Append`/`ConsumeStructuredBuffer` (#118536) The methods are using existing clang builtins `__builtin_hlsl_buffer_update_counter` and `__builtin_hlsl_resource_getpointer` to update the buffer counter and then load or store the value. Fixes #112968
2024-12-06[HLSL] Add ByteAddressBuffer, RWByteAddressBuffer and ↵joaosaffran1-11/+52
RasterizerOrderedByteAddressBuffer definitions to HLSLExternalSemaSource #113477 (#116699) This is the first one in a series of PRs adding the requirements for #58654 This PR adds `ByteAddressBuffer`, `RWByteAddressBuffer ` and `RasterizerOrderedByteAddressBuffer ` definitions as well as their handle lowering to `dx.RawBuffer`. closes #58654 --------- Co-authored-by: Joao Saffran <jderezende@microsoft.com>
2024-12-02[HLSL] Implement RWBuffer::operator[] via __builtin_hlsl_resource_getpointer ↵Justin Bogner1-101/+87
(#117017) This introduces `__builtin_hlsl_resource_getpointer`, which lowers to `llvm.dx.resource.getpointer` and is used to implement indexing into resources. This will only work through the backend for typed buffers at this point, but the changes to structured buffers should be correct as far as the frontend is concerned. Note: We probably want this to return a reference in the HLSL device address space, but for now we're just using address space 0. Creating a device address space and updating this code can be done later as necessary. Fixes #95956
2024-11-26[HLSL] Forward arguments in BuiltinTypeMethodBuilder::callBuiltin. NFC (#117789)Justin Bogner1-22/+39
Introduce BuiltinTypeMethodBuilder::PlaceHolder values and use them in the callBuiltin method in order to specify how we want to forward arguments and pass the resource handle to builtins.
2024-11-25[HLSL] Add `Increment`/`DecrementCounter` methods to structured buffers ↵Helena Kotas1-93/+321
(#117608) Introduces `__builtin_hlsl_buffer_update_counter` clang buildin that is used to implement the `IncrementCounter` and `DecrementCounter` methods on `RWStructuredBuffer` and `RasterizerOrderedStructuredBuffer` (see Note). The builtin is translated to LLVM intrisic `llvm.dx.bufferUpdateCounter` or `llvm.spv.bufferUpdateCounter`. Introduces `BuiltinTypeMethodBuilder` helper in `HLSLExternalSemaSource` that enables adding methods to builtin types using builder pattern like this: ``` BuiltinTypeMethodBuilder(Sema, RecordBuilder, "MethodName", ReturnType) .addParam("param_name", Type, InOutModifier) .callBuiltin("buildin_name", { BuiltinParams }) .finalizeMethod(); ``` Fixes #113513 [First version](llvm/llvm-project#114148) of this PR was reverted because of build break.
2024-11-25[clang][NFC]add static for internal linkage function (#117482)Congcong Cai1-3/+4
Detected by misc-use-internal-linkage
2024-11-23Revert "[HLSL] Add `Increment`/`DecrementCounter` methods to structured ↵Helena Kotas1-321/+93
buffers (#114148)" (#117448) This reverts commit 94bde8cdc39ff7e9c59ee0cd5edda882955242aa.
2024-11-23[HLSL] Add `Increment`/`DecrementCounter` methods to structured buffers ↵Helena Kotas1-93/+321
(#114148) Introduces `__builtin_hlsl_buffer_update_counter` clang buildin that is used to implement the `IncrementCounter` and `DecrementCounter` methods on `RWStructuredBuffer` and `RasterizerOrderedStructuredBuffer` (see Note). The builtin is translated to LLVM intrisic `llvm.dx.bufferUpdateCounter` or `llvm.spv.bufferUpdateCounter`. Introduces `BuiltinTypeMethodBuilder` helper in `HLSLExternalSemaSource` that enables adding methods to builtin types using builder pattern like this: ``` BuiltinTypeMethodBuilder(Sema, RecordBuilder, "MethodName", ReturnType) .addParam("param_name", Type, InOutModifier) .callBuiltin("buildin_name", { BuiltinParams }) .finalizeMethod(); ``` Fixes #113513
2024-11-22[HLSL] Add implicit resource element type concepts to AST (#116413)Joshua Batista1-11/+173
This PR is step one on the journey to implement resource element type validation via C++20 concepts. The PR sets up the infrastructure for injecting implicit concept decls / concept specialization expressions into the AST, which will then be evaluated after template arguments are instantiated. This is not meant to be a complete implementation of the desired validation for HLSL, there are a couple of missing elements: We need the __builtin_hlsl_is_typed_resource_element_compatible builtin to be implemented. We need other constraints, like is_intangible We need to put the first 2 points together, and construct a finalized constraint expression, which should differ between typed and raw buffers This is just an initial PR that puts some of the core infrastructure in place. This PR is an edit of #112600, so that new tests that were put into main don't fail Fixes #75676
2024-11-19[HLSL] Fix placement of `const` for resource operator[] (#116698)Justin Bogner1-1/+1
We had an incorrect AST here - We want `const T &`, not `T &const`.
2024-11-19[HLSL] Fix resource kind for RasterizerOrderedStructuredBuffer (#116700)Justin Bogner1-13/+8
This is a kind of StructuredBuffer, so it should be "Raw" and not "Typed".
2024-11-19[HLSL] Rename resource's "h" member to "__handle". NFC (#116696)Justin Bogner1-1/+1
This makes it clearer that the handle is an implementation detail by using a name that's reserved.
2024-11-14Revert "[HLSL] Add implicit resource element type concepts to AST" (#116305)Joshua Batista1-205/+12
Reverts llvm/llvm-project#112600
2024-11-14[HLSL] Add implicit resource element type concepts to AST (#112600)Joshua Batista1-12/+205
This PR is step one on the journey to implement resource element type validation via C++20 concepts. The PR sets up the infrastructure for injecting implicit concept decls / concept specialization expressions into the AST, which will then be evaluated after template arguments are instantiated. This is not meant to be a complete implementation of the desired validation for HLSL, there are a couple of missing elements: 1. We need the __builtin_hlsl_is_typed_resource_element_compatible builtin to be implemented. 2. We need other constraints, like is_intangible 3. We need to put the first 2 points together, and construct a finalized constraint expression, which should differ between typed and raw buffers This is just an initial PR that puts some of the core infrastructure in place.
2024-11-08[HLSL] Add Append/ConsumeStructuredBuffer definitions to ↵Helena Kotas1-4/+26
HLSLExternalSemaSource (#113643) Adds `AppendStructuredBuffer` and `ConsumeStructuredBuffer` definition to HLSLExternalSemaSource. Adds separate tests for the AST shape and element types, and adds constructor/handle.fromBinding test case to shared test file for structured buffers. These buffers do not have any subscript operators. Append and Consume methods will be added later in llvm/llvm-project#112968. Fixes #112777
2024-11-06[HLSL] Add RasterizerOrderedStructuredBuffer definition to ↵Helena Kotas1-0/+12
HLSLExternalSemaSource (#113648) Adds `RasterizerOrderedStructuredBuffer` definition to HLSLExternalSemaSource. Adds separate tests for the AST shape and element types. Adds constructor/handle.fromBinding and subscript test cases to shared test file for structured buffers. Additional methods will be added later. Fixes #112776
2024-11-04[HLSL][NFC] Cleanup - removed unused function, includes and param, fix typos ↵Helena Kotas1-13/+2
(#113649)
2024-10-24[HLSL] Add RWStructuredBuffer definition to HLSLExternalSemaSource (#113477)Helena Kotas1-0/+11
Add tests for RWStructuredBuffer class definition. Use shared test files for all structured buffers' constructor and subscript tests. Keep AST and element-type tests separate for each buffer type because they longer and failures would be harder to match. Fixes #112775
2024-10-23[HLSL] Change StructuredBuffer resource class to SRV (#113397)Helena Kotas1-1/+1
Change `StructuredBuffer` resource class to SRV (read-only) to match DXC. Part of llvm/llvm-project#112775
2024-10-15[HLSL] Make HLSLAttributedResourceType canonical and add code paths to ↵Helena Kotas1-2/+0
convert HLSL types to DirectX target types (#110327) Translates `RWBuffer` and `StructuredBuffer` resources buffer types to DirectX target types `dx.TypedBuffer` and `dx.RawBuffer`. Includes a change of `HLSLAttributesResourceType` from 'sugar' type to full canonical type. This is required for codegen and other clang infrastructure to work property on HLSL resource types. Fixes #95952 (part 2/2)
2024-09-29[HLSL] Replace `element_type*` handles in HLSLExternalSemaSource with ↵Helena Kotas1-36/+34
`__hlsl_resource_t` builtin type (#110079) Replace `element_type*` handles in HLSLExternalSemaSource with `__hlsl_resource_t` builtin type. The handle used to be defined as `element_type*` which was used by the provisional subscript operator implementation. Now that the handle is `__hlsl_resource_t` the subscript placeholder implementation was updated to add `element_type* e;` field to the resource struct. and return a reference to that. This field is just a temporary workaround until the indexing is implemented properly in llvm/llvm-project#95956, at which point the field will be removed. This seemed like a better solution than disabling many of the existing tests that already use the `[]` operator. One test has to be disabled nevertheless because an error based on interactions of const and template instantiation (potential bug that can be investigated once indexing is implemented the right way). Fixes #84824
2024-09-26[HLSL] Remove `__builtin_hlsl_create_handle` (#109910)Helena Kotas1-30/+2
The `__builtin_hlsl_create_handle` called from the constructor of resource buffer class was supposed to initialize the resource handle based on resource type and registry binding information. It is not possible to do though that because the registry binding information is not accessible from the constructor during codegen. Instead, the handle should be initialized to an empty or null handle with something like `__builtin_hlsl_create_null_handle`. This PR is removing `__builtin_hlsl_create_handle` first and the `__builtin_hlsl_create_null_handle` will be added to the constructor once the handle type changes to `__hlsl_resource_t` and HLSLAttributeResourceType is updated to be a canonical type, which will allow the initialization assignment. The actual handle initialization based on the registry binding will be implemented part 2/2 of llvm/llvm-project#105076 once the dependent tasks are completed. Part 1/2 of llvm/llvm-project#105076.
2024-09-16[HLSL] Add `[[hlsl::raw_buffer]]` attribute (#107954)Helena Kotas1-7/+11
This PR introduces new HLSL resource type attribute `[[hlsl::raw_buffer]]`. Presence of this attribute on a resource handle means that the resource does not require typed element access. The attribute will be used on resource handles that represent buffers like `StructuredBuffer` or `ByteAddressBuffer` and in DXIL it will be translated to target extension type `dx.RawBuffer`. Fixes #107907
2024-09-16[HLSL] Add `[[hlsl::contained_type()]]` attribute (#108456)Helena Kotas1-2/+14
Introducing a new HLSL resource type attribute `[[contained_type(T)]]` which describes the "contained type" of a buffer or resource type. Specifically, the attribute will be used on the resource handle in templated buffer types like so: template <typename T> struct RWBuffer { __hlsl_resource_t [[hlsl::contained_type(T)]] [[hlsl::resource_class(UAV)]] h; }; Fixes #104855
2024-09-11[HLSL] Add StructuredBuffer to external sema source (#106316)Joshua Batista1-0/+10
This PR adds `StructuredBuffer` to `HLSLExternalSemaSource.cpp`, by copying the logic from RWBuffer but just replacing the name with StructuredBuffer. The change now allows StructuredBuffers to be defined in HLSL, though they function the same as RWBuffers. Further work to apply the appropriate attributes that distinguish StructuredBuffers from other Buffer types will be deferred. This improves our position on https://github.com/llvm/llvm-project/issues/106189
2024-09-05[HLSL] Apply resource attributes to the resource type rather than the handle ↵Helena Kotas1-10/+13
member (#107160) Converts existing resource attributes `[[hlsl::resource_class(..)]]` and `[[is_rov]]` from declaration attributes to type attributes. During type attribute processing all HLSL resource type attributes are validated and collected by `SemaHLSL` (`SemaHLSL::handleResourceTypeAttr`). At the end of the declaration they are be combined into a single `HLSLAttributedResourceType` instance (`SemaHLSL::ProcessResourceTypeAttributes`) that wraps the original type and stores all of the necessary information about the resource. `SemaHLSL` will also need to short-term-store the `TypeLoc` information for the newly created type that will be grabbed by `TypeSpecLocFiller` soon after it is created. Updates all places that expected resource attributes on declarations like resource binding diagnostic, builtin types in HLSLExternalSemaSource, or codegen. Also includes implementation of `TreeTransform<Derived>::TransformHLSLAttributedResourceType` that enables the use of attributed resource types inside templates. Fixes #104861 Part 2/2
2024-08-23Implement resource binding type prefix mismatch diagnostic infrastructure ↵Joshua Batista1-1/+3
(#97103) There are currently no diagnostics being emitted for when a resource is bound to a register with an incorrect binding type prefix. For example, a CBuffer type resource should be bound with a a binding type prefix of 'b', but if instead the prefix is 'u', no errors will be emitted. This PR implements such diagnostics. The focus of this PR is to implement both the flag setting and diagnostic emisison steps specified in the relevant spec: https://github.com/microsoft/hlsl-specs/pull/230 The relevant issue is: https://github.com/llvm/llvm-project/issues/57886 This is a continuation / refresh of this PR: https://github.com/llvm/llvm-project/pull/87578
2024-08-14[HLSL] Split out the ROV attribute from the resource attribute, make it a ↵Joshua Batista1-5/+11
new spellable attribute. (#102414) Much like #98193, this PR takes some more data out of the resource attribute, specifically the ROV data. This PR introduces a new attribute called HLSLROVAttr, which contains data on whether or not the decl the attribute applies to is an ROV. Tests were added to ensure the attribute is found on the AST. This attribute may take any boolean condition as an argument. If the condition is true, then the object the attribute applies to "is" an ROV. Fixes #https://github.com/llvm/llvm-project/issues/102392
2024-08-02Attach resource attributes to handle within record, instead of record (#101433)Joshua Batista1-16/+14
This PR attaches the resource attributes, `HLSLResourceAttr` and `HLSLResourceClassAttr`, to the handle contained within such resource classes like `RWBuffer`. CodeGen will now search for fields within HLSL resource decls, and emit previous data based on attributes on the handle member. An AST-dump test was added to verify that the resource attribute is attached to the handle within the resource record decl. Fixes #98556 --------- Co-authored-by: Justin Bogner <mail@justinbogner.com>
2024-07-16[HLSL] Remove hlsl::Resource (#98938)Justin Bogner1-6/+0
This was added in an effort to support resource types before we created the HLSLResource builtin type, but it isn't needed.
2024-07-12[HLSL] Split out resource class data from resource attribute (#98419)Joshua Batista1-6/+7
The ability to spell out and specify the resource class is necessary for testing various resource binding behaviors. Though it is not intended for users to use this in customized HLSL source code, the ability to specify the resource class via an attribute is immensely helpful for writing thorough tests. This PR introduces a new attribute, hlsl::resource_attribute, that can only be applied on structs. This attribute only has 1 required argument, and must be one of: ``` SRV UAV CBuffer Sampler ``` By applying this attribute to a struct, the struct will have the `HLSLResourceClassAttr` attribute attached to it in the AST representation, which provides information on the type of resource class the struct is meant to be. The resource class data that was originally contained within the `HLSLResourceAttr` attribute has been removed in favor of this new attribute, and so certain ast-dump tests need to be modified so that the same information can be represented via 2 attributes instead of one. Fixes #98193 --------- Co-authored-by: Damyan Pepper <damyanp@microsoft.com>
2024-05-22[clang] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument (#92852)Matheus Izvekov1-4/+6
This is an enabler for https://github.com/llvm/llvm-project/pull/92855 This allows an NTTP default argument to be set as an arbitrary TemplateArgument, not just an expression. This allows template parameter packs to have default arguments in the AST, even though the language proper doesn't support the syntax for it. This allows NTTP default arguments to be other kinds of arguments, like packs, integral constants, and such.
2024-05-21[clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (#92854)Matheus Izvekov1-20/+28
This is an enabler for a future patch. This allows an type-parameter default argument to be set as an arbitrary TemplateArgument, not just a type. This allows template parameter packs to have default arguments in the AST, even though the language proper doesn't support the syntax for it. This will be used in a later patch which synthesizes template parameter lists with arbitrary default arguments taken from template specializations. There are a few places we used SubsType, because we only had a type, now we use SubstTemplateArgument. SubstTemplateArgument was missing arguments for setting Instantiation location and entity names. Adding those is needed so we don't regress in diagnostics.
2024-04-30Reapply "[Clang][Sema] Diagnose class member access expressions naming ↵Krystian Stasiowski1-2/+5
non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050)" (#90152) Reapplies #84050, addressing a bug which cases a crash when an expression with the type of the current instantiation is used as the _postfix-expression_ in a class member access expression (arrow form).
2024-04-26Revert "[Clang][Sema] Diagnose class member access expressions naming ↵Pranav Kant1-5/+2
non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050)" This reverts commit a8fd0d029dca7d17eee72d0445223c2fe1ee7758.
2024-04-25[Clang][Sema] Diagnose class member access expressions naming non-existent ↵Krystian Stasiowski1-2/+5
members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050) Consider the following: ```cpp template<typename T> struct A { auto f() { return this->x; } }; ``` Although `A` has no dependent base classes and the lookup context for `x` is the current instantiation, we currently do not diagnose the absence of a member `x` until `A<T>::f` is instantiated. This patch moves the point of diagnosis for such expressions to occur at the point of definition (i.e. prior to instantiation).
2023-12-09[HLSL] Define RasterizerOrderedBuffer resourceJustin Bogner1-6/+17
Define HLSL's RasterizerOrderedBuffer resource type through the external sema source. This doesn't fully work as is, but defining it allows us to exercise the ROV logic in the DirectX backend from HLSL rather than having to manually edit metadata, so it's useful for further testing and development. Pull Request: https://github.com/llvm/llvm-project/pull/74897
2023-12-09[DirectX] Move ROV info into HLSL metadata. NFCJustin Bogner1-2/+2
Pull Request: https://github.com/llvm/llvm-project/pull/74896
2023-12-07[HLSL] Add helpers to simplify HLSL resource type declarations. NFCJustin Bogner1-20/+34
A few changes to HLSLExternalSemaSource and its BuiltinTypeDeclBuilder to make defining buffer types less verbose. This will make it a lot easier to see what the differences between the various buffer types are once we start introducing more of them. Pull Request: https://github.com/llvm/llvm-project/pull/73967
2023-12-06[HLSL] RWBuffer<T> should not have a default parameterJustin Bogner1-1/+1
RWBuffer doesn't have a default type in dxc's implementation, so it shouldn't have one in clang either. Reviewers: llvm-beanz, python3kgae Reviewed By: python3kgae, llvm-beanz Pull Request: https://github.com/llvm/llvm-project/pull/71265