Files
test/source/blender/gpu/vulkan/vk_vertex_attribute_object.hh
Jeroen Bakker 4ebd7d84d1 Vulkan: Bind Dummy Vertex Attributes
Batches don't always provide all required resources for a shader.
This can happen when the resource is defined in the shader, but
not used in a specific variant. The definition is still there and
needs to be filled.

This PR adds a dummy buffer to fill the missing attributes.
It also fixes an issue when using vertex attributes that
uses multiple binding locations (mat4).

Pull Request: https://projects.blender.org/blender/blender/pulls/111350
2023-08-22 13:35:01 +02:00

69 lines
1.8 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Authors All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup gpu
*/
#include "vk_buffer.hh"
#include "vk_common.hh"
#include "BLI_vector.hh"
#pragma once
namespace blender::gpu {
class VKVertexBuffer;
class VKContext;
class VKBatch;
class VKShaderInterface;
class VKImmediate;
using AttributeMask = uint16_t;
class VKVertexAttributeObject {
public:
bool is_valid = false;
VkPipelineVertexInputStateCreateInfo info = {
VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, NULL};
Vector<VkVertexInputBindingDescription> bindings;
Vector<VkVertexInputAttributeDescription> attributes;
/* Used for batches. */
Vector<VKVertexBuffer *> vbos;
/* Used for immediate mode. */
Vector<VKBufferWithOffset> buffers;
VKVertexAttributeObject();
void clear();
void bind(VKContext &context);
// Copy assignment operator.
VKVertexAttributeObject &operator=(const VKVertexAttributeObject &other);
void update_bindings(const VKContext &context, VKBatch &batch);
void update_bindings(VKImmediate &immediate);
void debug_print() const;
private:
/** Update unused bindings with a dummy binding. */
void fill_unused_bindings(const VKShaderInterface &interface,
const AttributeMask occupied_attributes);
void update_bindings(const GPUVertFormat &vertex_format,
VKVertexBuffer *vertex_buffer,
VKBufferWithOffset *immediate_vertex_buffer,
const int64_t vertex_len,
const VKShaderInterface &interface,
AttributeMask &r_occupied_attributes,
const bool use_instancing);
void bind_vbos(VKContext &context);
void bind_buffers(VKContext &context);
};
} // namespace blender::gpu