Skip to content

Change HitObject::GetAttributes to use out udt param instead of templated Load pattern #495

@tex3d

Description

@tex3d

Which proposal does this relate to?

#### HitObject::GetAttributes
```C++
template<attr_t>
attr_t dx::HitObject::GetAttributes();
```

Describe the issue or outstanding question.
In gen_intrin_main.txt the GetAttributes method is based on the pattern established for the templated ByteAddressBuffer::Load method, where you specify an explicit template type argument, and the method returns a const reference to that type. When lowering the ByteAddressBuffer::Load operation, we need to produce individual DXIL op calls for loading elements of the resulting structure, so this pattern helps in that lowering path.

GetAttributes is different, all the way through to DXIL, in that you want to fill in a user structure one time, and all subsequent field accesses are from that local user-defined structure alloca. Using the pattern from the Load requires creation of another intermediate alloca during lowering to translate the pattern from the high-level returned pointer to the DXIL operation that fills in a pointer to a user-defined attribute type.

I think we should have used a different pattern for GetAttributes to simplify usage and codegen/lowering. This pattern would be the out udt function parameter. This way, a user defined LValue would be supplied to the intrinsic and filled in by it, which is exactly the pattern carried through to the final DXIL operation.

With this change, instead of writing this in HLSL:

MyAttributes attrs = hit_object.GetAttributes<MyAttributes>();

You would write this:

MyAttributes attrs;
hit_object.GetAttributes(attrs);

Additional context
See comment on the DXC PR for GetAttributes lowering here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions