From 7383cfcbe8ade4dce057608e971e8cb7d4b1feb7 Mon Sep 17 00:00:00 2001 From: quou Date: Sun, 29 Dec 2024 13:40:45 +1100 Subject: allow binding only a portion of a cbuffer --- pipeline.cpp | 11 ++++++++++- video.cpp | 4 ++-- video.hpp | 12 ++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pipeline.cpp b/pipeline.cpp index 8867a8d..8750db0 100644 --- a/pipeline.cpp +++ b/pipeline.cpp @@ -185,7 +185,12 @@ void Pipeline_Builder::texture( td->texture = t; } -void Pipeline_Builder::cbuffer(int binding, Buffer_Id id) { +void Pipeline_Builder::cbuffer( + int binding, + Buffer_Id id, + int offset, + int size +) { Descriptor* d; Constant_Buffer_Descriptor* cd; assert(pip->descriptor_count < pipeline_max_descriptors); @@ -194,6 +199,8 @@ void Pipeline_Builder::cbuffer(int binding, Buffer_Id id) { d->slot = binding; d->type = Descriptor::Type::constant_buffer; cd->buffer = id; + cd->offset = offset; + cd->size = size; } void Pipeline_Builder::vertex_format(Vertex_Format_Id vf) { @@ -237,6 +244,8 @@ Pipeline& Pipeline_Builder::build() { case Descriptor::Type::constant_buffer: { auto cd = (Constant_Buffer_Descriptor*)d->payload; h(pip->descriptor_resource_hash, cd->buffer); + h(pip->descriptor_resource_hash, cd->size); + h(pip->descriptor_resource_hash, cd->offset); } break; } } diff --git a/video.cpp b/video.cpp index 5d88d0c..d0720f5 100644 --- a/video.cpp +++ b/video.cpp @@ -2760,8 +2760,8 @@ void Descriptor_Set_Vk::init( Buffer_Vk& b = *(Buffer_Vk*)&dev->get_buffer(cd->buffer); assert(cd->buffer); buf.buffer = b.buf; - buf.offset = 0; - buf.range = b.size; + buf.offset = cd->offset; + buf.range = cd->size? cd->size: b.size; wd.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; wd.pBufferInfo = &buf; } break; diff --git a/video.hpp b/video.hpp index fa479f1..1ccc93d 100644 --- a/video.hpp +++ b/video.hpp @@ -44,7 +44,7 @@ struct Sampler_Id : public Primitive_Id { using Primitive_Id::Primitive_Id; }; -#define descriptor_payload_size 8 +#define descriptor_payload_size 16 struct Descriptor { enum class Type { @@ -61,6 +61,7 @@ struct Texture_Descriptor { }; struct Constant_Buffer_Descriptor { + int offset, size; Buffer_Id buffer; }; @@ -146,6 +147,8 @@ struct Pipeline { Constant_Buffer_Descriptor* cb = (Constant_Buffer_Descriptor*)b.payload; if (ca->buffer != cb->buffer) return false; + if (ca->size != cb->size) return false; + if (ca->offset != cb->offset) return false; } break; } } @@ -254,7 +257,12 @@ struct Pipeline_Builder { void shader(Shader_Id s); void vertex_format(Vertex_Format_Id vf); void texture(int binding, Texture_Id t, Sampler_Id s); - void cbuffer(int binding, Buffer_Id id); + void cbuffer( + int binding, + Buffer_Id id, + int offset = 0, + int size = 0 + ); Pipeline& build(); void validate(); }; -- cgit v1.2.3-54-g00ecf