Skip to content

Structured buffers, part 1

Tentatively part 1/3, with the other two parts being UAV and UAV atomics.

The basic idea is to transform index chains that point to structured loads into more specific structured loads, e.g:

struct inner
{
    float padding;
    float a;
};

struct outer
{
    inner a;
};

StructuredBuffer<outer> buf;

buf[0].a.a would first get transformed into 3 hlsl_ir_index, then each index would get transformed into a hlsl_ir_resource_load with the field deref modified to be more specific:

<outer> = resource_load(resource = buf, sampler = nil, field = nil)
<inner> = resource_load(resource = buf, sampler = nil, field = 0)
<float> = resource_load(resource = buf, sampler = nil, field = 4)

The one bit I'm very uncertain about is 6/14: while I think we should reuse parts of the current deref infrastructure, it feels very weird to have all the logic related to structured buffer packing living in new_offset_from_path_index() with the register packing logic.

This MR doesn't attempt any vectorization of the loads. I've previously tried doing some but I think it's best if we do it in a separate pass (or if at all, at least the SPIR-V backend emits scalar loads. I haven't checked what these loads look like in real hardware though)

This MR doesn't add support for GLSL structured loads. I had some code written for this but I decided it wasn't good enough to submit, though I might clean it up and submit eventually.

Edited by Victor Chiletto

Merge request reports

Loading