Skip to content

[Scenario] Resources in Structs #367

@hekota

Description

@hekota

Resources and arrays of resources can be declared as members of user-defined structures or classes in constant buffers. These structs or classes can also be declared locally or passed as parameters to functions.

struct S {
    RWBuffer<float> Buf;
    StructuredBuffer<float> BufArray[10];
};

S s : register(u2) : register(t5);

RWBuffer<float> Out : register(u0);

void foo(S local_s, uint index) {
  local_s.Buf = Out;
  local_s.Buf[0] = s.BufArray[0][index] + s.BufArray[2][index];
}

[numthreads(4,1,1)]
void main(uint3 ID : SV_GroupThreadID) {
  foo(s, ID.y);
  s.Buf[ID.x] = s.BufArray[9][ID.x];
}

https://godbolt.org/z/qjrch3a7b

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

Status

Planning

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions