Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial work for bindless buffers & textures in rust-gpu #450

Merged
merged 65 commits into from
May 5, 2021

Conversation

Jasper-Bekkers
Copy link
Contributor

@Jasper-Bekkers Jasper-Bekkers commented Feb 25, 2021

While a lot of this stuff is still in flux (naming wise, most code is in a terrible location, etc). I wanted to share the work so-far to gather some feedback.

There are several reasons for adding bindless support to rust-gpu;

  • Much lower CPU cost for updating bindings (bindings are created only at resource creation time, instead of on-demand like in a more traditional renderer); see for example this post https://ourmachinery.com/post/moving-the-machinery-to-bindless/
  • More flexibility when using resource on the GPU, meaning one can create nested data structures which was previously impossible to do.

Relevant MCP: #389

Example of how to use:

#[derive(Copy, Clone)]
pub struct Bindings {
    pub buffer: Buffer,
}

#[derive(Copy, Clone)]
#[spirv(block)]
pub struct ShaderConstants {
    pub bindings: SimpleBuffer<Bindings>,
    pub user_data0: u32,
    pub user_data1: u32,
    pub user_data2: u32,
}

struct Data {
    a: f32,
    b: u32,
    c: f32,
    d: u32,
}

#[spirv(gl_compute)]
pub fn main(constants: PushConstant<ShaderConstants>) {
    let data = Data {
        a: 1.0,
        b: 0,
        c: 6.0,
        d: 1782,
    };

    let bindings = constants.bindings.load();

    unsafe {
        bindings.buffer.store(0, data)
    };
}

Draft because; lots of work still left to do.

  • store method on Buffer
  • StorageTexture
  • StructuredBuffer<T> equivalent that can function as an array instead of a "bag of bytes" like Buffer
  • Remaining functions on Texture
  • Update Texture to use the generics that recently got added.
  • Other Texture1d and Texture3d
  • Test for the implementations of each, instead of just passing spirv-val and eye-balling the SPIR-V
  • Add NonUniformResourceIndex equivalent

Comment on lines 10 to 22
/// This handle is expected to be used engine-side to refer to descriptors within a descriptor set.
/// To be able to use the bindless system in rust-gpu, an engine is expected to have created
/// four DescriptorSets, each containing a large table of max 1 << 23 elements for each type.
/// And to sub-allocate descriptors from those tables. It must use `RenderResourceHandle` to
/// refer to slots within this table, and it's then expected that these RenderResourceHandle's
/// are freely copied to the GPU to refer to resources there.
///
/// | Buffer Type | Set |
/// |------------------|-----|
/// | Buffers | 0 |
/// | Textures | 1 |
/// | Storage textures | 2 |
/// | Tlas | 3 |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will be hard requirements on a CPU runtime implementing a Vulkan renderer. Samplers aren't yet in this list because they're quite controversial here and a bit of a trade-off.

On low-end devices only 4 descriptor sets are guaranteed to exist for us to use. I've chosen here to dedicate the 4 slots like this and later on require only the use of immutable samplers. This is a bit of a contentious topic of course since low-end GPUs with limited DescriptorSets are ... rare, and having actual Samplers might be more useful.

…self.zombie_ptr_equal` borrow the same refcell
…ride some OpEntryPoint parameters when using bindless in spirv 1.5, and it's useful to be able to sanity check calls into bindless functions
…dation layer complains so we need to sort all OpVariable's with Function scope to be in the first block of a function
…his case anymore now that we do proper error checking around binding and descriptor_set attributes
…, this way we don't require a nightly feature on the CPU side
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants