44 attributes.extend(other.attributes);
46 vbos.extend(other.vbos);
62 for (VkVertexInputAttributeDescription attribute :
attributes) {
63 if (visited_bindings[attribute.binding]) {
66 visited_bindings[attribute.binding].set(
true);
69 VkDeviceSize offset = 0;
71 if (attribute.binding <
buffers.size()) {
72 buffer =
buffers[attribute.binding].buffer;
73 offset =
buffers[attribute.binding].offset;
76 r_vertex_buffer_bindings.
buffer[attribute.binding] = buffer;
77 r_vertex_buffer_bindings.
offset[attribute.binding] = offset;
79 attribute.binding + 1);
122 if (occupied_attributes != interface.enabled_attr_mask_) {
123 fill_unused_bindings(interface, occupied_attributes);
178void VKVertexAttributeObject::fill_unused_bindings(
const VKShaderInterface &interface,
184 if (occupied_attributes & location_mask) {
188 if ((interface.enabled_attr_mask_ & location_mask) == 0) {
193 shader::Type attribute_type = interface.get_attribute_type(location);
195 for (
const uint32_t location_offset : IndexRange(num_locations)) {
197 VkVertexInputAttributeDescription attribute_description = {};
198 attribute_description.binding = binding;
199 attribute_description.location = location + location_offset;
200 attribute_description.offset = 0;
201 attribute_description.format =
to_vk_format(attribute_type);
202 attributes.append(attribute_description);
204 VkVertexInputBindingDescription vk_binding_descriptor = {};
205 vk_binding_descriptor.binding = binding;
206 vk_binding_descriptor.stride = 0;
207 vk_binding_descriptor.inputRate = VK_VERTEX_INPUT_RATE_INSTANCE;
228 BLI_assert(interface.enabled_attr_mask_ == occupied_attributes);
237 const bool use_instancing)
239 BLI_assert(vertex_buffer || immediate_vertex_buffer);
240 BLI_assert(!(vertex_buffer && immediate_vertex_buffer));
252 bool add_vbo =
false;
254 for (
uint32_t attribute_index = 0; attribute_index < vertex_format.
attr_len; attribute_index++) {
257 buffer_offset += ((attribute_index == 0) ? 0 :
258 vertex_format.attrs[attribute_index - 1].size) *
260 stride = attribute.
size;
263 attribute_offset = attribute.offset;
266 for (
uint32_t name_index = 0; name_index < attribute.name_len; name_index++) {
269 if (shader_input ==
nullptr || shader_input->location == -1) {
275 if (r_occupied_attributes & attribute_mask) {
278 r_occupied_attributes |= attribute_mask;
280 for (
const uint32_t location_offset : IndexRange(num_locations)) {
282 VkVertexInputAttributeDescription attribute_description = {};
283 attribute_description.binding = binding;
284 attribute_description.location = shader_input->location + location_offset;
285 attribute_description.offset = attribute_offset + location_offset *
sizeof(
float4);
290 attributes.append(attribute_description);
292 VkVertexInputBindingDescription vk_binding_descriptor = {};
293 vk_binding_descriptor.binding = binding;
294 vk_binding_descriptor.stride = stride;
295 vk_binding_descriptor.inputRate = use_instancing ? VK_VERTEX_INPUT_RATE_INSTANCE :
296 VK_VERTEX_INPUT_RATE_VERTEX;
303 if (immediate_vertex_buffer) {
304 buffers.append(*immediate_vertex_buffer);
312 vbos.append(vertex_buffer);
324 std::cout << __FILE__ <<
"::" << __func__ <<
"\n";
327 for (VkVertexInputAttributeDescription attribute :
attributes) {
328 std::cout <<
" - attribute(binding=" << attribute.binding
329 <<
", location=" << attribute.location <<
")";
331 if (visited_bindings[attribute.binding]) {
332 std::cout <<
" WARNING: Already bound\n";
335 visited_bindings[attribute.binding].set(
true);
337 if (attribute.binding <
vbos.size()) {
338 std::cout <<
" Attach to Buffer\n";
341 std::cout <<
" WARNING: Attach to dummy\n";
MINLINE int max_ii(int a, int b)
#define GPU_BATCH_INST_VBO_MAX_LEN
#define GPU_BATCH_VBO_MAX_LEN
ATTR_WARN_UNUSED_RESULT const BMVert * v
void append(const T &value)
void extend(Span< T > array)
const ShaderInput * attr_get(const char *name) const
VkBuffer vk_handle() const
Vector< VKBufferWithOffset > buffers
VKVertexAttributeObject()
VKVertexAttributeObject & operator=(const VKVertexAttributeObject &other)
Vector< VkVertexInputAttributeDescription > attributes
void update_bindings(const VKContext &context, VKBatch &batch)
VkPipelineVertexInputStateCreateInfo info
Vector< VkVertexInputBindingDescription > bindings
void bind(render_graph::VKVertexBufferBindings &r_vertex_buffer_bindings) const
Vector< VKVertexBuffer * > vbos
const GPUVertFormat & device_format_get() const
void device_format_ensure()
VkBuffer vk_handle() const
static Context * unwrap(GPUContext *ctx)
VkFormat to_vk_format(const eGPUTextureFormat format)
static uint32_t to_binding_location_len(const GPUVertAttr &attribute)
VecBase< float, 4 > float4
constexpr IntT ceil_division(const IntT x, const IntT y)