Currently all buffer types were stored in host memory, which is visible to the GPU as well. This is typically slow as the data would be transferred over the PCI bus when used. Most of the time Index and Vertex buffers are written once and read many times so it makes more sense to locate them on the GPU. Storage buffers typically require quick access as they are created for shading/compute purposes. This PR will try to store vertex buffers, index buffers and storage buffers on device memory to improve the performance. Uniform buffers are still located on host memory as they can be uploaded during binding process. This can (will) reset the graphics pipeline triggering draw calls using unattached resources. In future this could be optimized further as in: * using different pools for allocating specific buffers, with a fallback when buffers cannot be stored on the GPU anymore. * store uniform buffers in device memory Pull Request: https://projects.blender.org/blender/blender/pulls/115343
77 lines
2.0 KiB
C++
77 lines
2.0 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);
|
|
|
|
/**
|
|
* Ensure that all Vertex Buffers are uploaded to the GPU.
|
|
*
|
|
* This is a separate step as uploading could flush the graphics pipeline making the state
|
|
* inconsistent.
|
|
*/
|
|
void ensure_vbos_uploaded() const;
|
|
|
|
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
|