Skip to content

[SPIR-V][Feature Request] Implement Buffer Pointers in HLSL With vk::BufferPointer #6489

Description

@Keenuts

The proposal for BufferPointer is now in the accepted state.
So we should now be able to start implementation on this.

https://github.com/microsoft/hlsl-specs/blob/main/proposals/0010-vk-buffer-ref.md

Adding this issue to track the SPIR-V side of the work.

Activity

  1. added
    enhancement
    spirv
    on Apr 3, 2024
  2. changed the title [-][Feature Request] Implement Buffer Pointers in HLSL With vk::BufferPointer[/-] [+][SPIR-V][Feature Request] Implement Buffer Pointers in HLSL With vk::BufferPointer[/+] on Apr 3, 2024
  3. devshgraphicsprogramming commented on Apr 16, 2024

    @devshgraphicsprogramming

    Here's the deal, given that Proposal 0011 is merged, I could implement proposal 0010 as a pure header-only library.

    Provided this issue is fixed
    #5784

  4. devshgraphicsprogramming commented on Apr 17, 2024

    @devshgraphicsprogramming

    I'm actually quite close to getting it working, blocked by #6541 though

  5. s-perron commented on Jun 21, 2024

    @s-perron
    Collaborator

    I've looked at this more closely. We might be able to implement something similar to the proposal using inline spir-v, but it cannot implement is properly. The main reason is the get() is suppose to return a reference, but that cannot be expressed in HLSL at this time. When references are added to HLSL properly, then we could implement it in inline spir-v.

    I don't think we should wait until them.

    The reason this is such a big deal is that if you cannot return a reference, then the number of operations you will need to define in inline spir-v grows to a huge number. You will have to define specific load and store instruction. You'll have to redefine all of the atomic operations. Just in general the syntax will not be as clean.

    We still need to do a builtin definition of the class to be able to get the reference semantics right.

  6. Tobski commented on Jun 21, 2024

    @Tobski

    Hmm, the only thing I'm wondering here though is that if that proposal relies on references, do we need an implementation of references proper to actually make that work anyway? Or do you think it's possible to implement that proposal without doing so?

  7. s-perron commented on Jun 21, 2024

    @s-perron
    Collaborator

    Good question. I do not think that is a problem because we have precedent for having builtin functions that return a reference. It might not be described that way, but that is what it is.

    For example RWStructuredBuffer::operator[] really returns a reference. The same for any operator[]. We will essentially implement the same concept.

  8. devshgraphicsprogramming commented on Jun 24, 2024

    @devshgraphicsprogramming

    The reason this is such a big deal is that if you cannot return a reference, then the number of operations you will need to define in inline spir-v grows to a huge number. You will have to define specific load and store instruction. You'll have to redefine all of the atomic operations. Just in general the syntax will not be as clean.

    Steven Perron (@s-perron) its worse thank you think, you can't define a reference with current inline SPIR-V hence my request for #6578 (which follows/supersedes my #5675 request)

  9. buzmeg commented on Nov 12, 2024

    @buzmeg

    Anybody know what the status of this is?

    It's one of the big points of incompatibility preventing people from fully migrating off of GLSL.

  10. devshgraphicsprogramming commented on Nov 12, 2024

    @devshgraphicsprogramming

    Anybody know what the status of this is?

    It's one of the big points of incompatibility preventing people from fully migrating off of GLSL.

    AFAIK, not in development for DXC, probably in dev for Clang-HLSL. Already implemented in Slang.

    I've been able to make my own BDA with vk::SpirvType and Inline Spir-V intrinsics, HOWEVER they only work for is_fundamental_v<T> (scalar and vector) and I've been banging the drum over and over again that if only this little issue (DXC not being able to figure out/annotate the offsets/layouts for a struct type T #6541) got fixed I'd be able to make BDA for all types.

    I mean, heck, I even have atomics on my BDAs!
    See our counting sort https://github.com/Devsh-Graphics-Programming/Nabla/blob/d37770f6dfab7f19de6c798ddd2c5a93256ee7ae/include/nbl/builtin/hlsl/bda/bda_accessor.hlsl#L39

    Again I'm not a dev so they can probably tell you more about the roadmap

  11. 11 remaining items

  12. added a commit that references this issue on Apr 2, 2025
    9eb7119
  13. Keenuts commented on Apr 4, 2025

    @Keenuts
    CollaboratorAuthor

    Hello!

    It looks like part of the proposal was missed:

    vk::BufferPointer(const uint64_t);
    A buffer pointer can be constructed from a uint64_t using the constructor syntax vk::BufferPointer<T,A>(u).
    

    Thus reopening this issue

  14. danbrown-amd commented on Apr 4, 2025

    @danbrown-amd
    Contributor

    Not so. See vk.buffer-pointer.linked-list.hlsl, line 60:

    block_p copy1 = block_p(addr);

    The RHS constructs a buffer pointer from a uint_64t value.

  15. Keenuts commented on Apr 4, 2025

    @Keenuts
    CollaboratorAuthor

    Mmm interesting, it looks like there is something going on.

    The following code does work.

    // RUN: %dxc -E main -T cs_6_7  %s -spirv -E main | FileCheck %s
    
    typedef vk::BufferPointer<uint, 32> BufferType;
    struct PushConstantStruct {
      BufferType push_buffer;
    };
    [[vk::push_constant]] PushConstantStruct push_constant;
    
    RWStructuredBuffer<uint> output;
    
    [numthreads(1, 1, 1)]
    void main() {
      uint64_t addr = 123;
      //BufferType test = BufferType(addr);
      vk::BufferPointer<uint, 32> test = vk::BufferPointer<uint, 32>(addr);
      output[0] = test.Get();
    }

    Now, if I remove some parts, then things starts to fail:

    Case 1: changing the typedef above to use a different alignment.
    This should have no effect since the ctor I used below is using the type defined in the main function with a 32 byte alignent.

    // RUN: %dxc -E main -T cs_6_7  %s -spirv -E main | FileCheck %s
    
    //typedef vk::BufferPointer<uint, 32> BufferType;
    typedef vk::BufferPointer<uint, 16> BufferType;
    struct PushConstantStruct {
      BufferType push_buffer;
    };
    [[vk::push_constant]] PushConstantStruct push_constant;
    
    RWStructuredBuffer<uint> output;
    
    [numthreads(1, 1, 1)]
    void main() {
      uint64_t addr = 123;
      //BufferType test = BufferType(addr);
      vk::BufferPointer<uint, 32> test = vk::BufferPointer<uint, 32>(addr);
      output[0] = test.Get();
    }
    error: type mismatch
      vk::BufferPointer<uint, 32> test = vk::BufferPointer<uint, 32>(addr);
    error: cannot convert from 'uint64_t' to 'vk::BufferPointer<uint, 32>'
      vk::BufferPointer<uint, 32> test = vk::BufferPointer<uint, 32>(addr);
    

    Another weirdness:
    Removing the push constant prevents me from using the uint64_t ctor.

    // RUN: %dxc -E main -T cs_6_7  %s -spirv -E main | FileCheck %s
    
    typedef vk::BufferPointer<uint, 32> BufferType;
    //struct PushConstantStruct {
    //  BufferType push_buffer;
    //};
    //[[vk::push_constant]] PushConstantStruct push_constant;
    
    RWStructuredBuffer<uint> output;
    
    [numthreads(1, 1, 1)]
    void main() {
      uint64_t addr = 123;
      //BufferType test = BufferType(addr);
      vk::BufferPointer<uint, 32> test = vk::BufferPointer<uint, 32>(addr);
      output[0] = test.Get();
    }
    error: type mismatch
      vk::BufferPointer<uint, 32> test = vk::BufferPointer<uint, 32>(addr);
    error: cannot convert from 'uint64_t' to 'vk::BufferPointer<uint, 32>'
      vk::BufferPointer<uint, 32> test = vk::BufferPointer<uint, 32>(addr);
    
  16. added a commit that references this issue on Apr 10, 2025
    b8087d7
  17. danbrown-amd commented on Apr 10, 2025

    @danbrown-amd
    Contributor

    I've submitted a PR to fix #7302 as well.

  18. danbrown-amd commented on Apr 14, 2025

    @danbrown-amd
    Contributor

    Steven Perron (@s-perron) could you look at PRs #7302 and #7331 as well?

  19. added a commit that references this issue on Apr 15, 2025
    30a7579
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementspirv

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions