2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2022 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2022-02-08 23:17:31 +01:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup gpu
|
|
|
|
|
*
|
|
|
|
|
* Storage buffers API. Used to handle many way bigger buffers than Uniform buffers update at once.
|
|
|
|
|
* Make sure that the data structure is compatible with what the implementation expect.
|
|
|
|
|
* (see "7.8 Shader Buffer Variables and Shader Storage Blocks" from the OpenGL spec for more info
|
|
|
|
|
* about std430 layout)
|
|
|
|
|
* Rule of thumb: Padding to 16bytes, don't use vec3.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
#include "GPU_texture.hh"
|
|
|
|
|
#include "GPU_vertex_buffer.hh"
|
2022-02-08 23:17:31 +01:00
|
|
|
|
|
|
|
|
/** Opaque type hiding blender::gpu::StorageBuf. */
|
2024-03-23 01:24:18 +01:00
|
|
|
struct GPUStorageBuf;
|
2022-02-08 23:17:31 +01:00
|
|
|
|
|
|
|
|
GPUStorageBuf *GPU_storagebuf_create_ex(size_t size,
|
|
|
|
|
const void *data,
|
|
|
|
|
GPUUsageType usage,
|
|
|
|
|
const char *name);
|
|
|
|
|
|
|
|
|
|
#define GPU_storagebuf_create(size) \
|
2024-03-23 01:24:18 +01:00
|
|
|
GPU_storagebuf_create_ex(size, nullptr, GPU_USAGE_DYNAMIC, __func__);
|
2022-02-08 23:17:31 +01:00
|
|
|
|
2022-03-16 08:38:33 +01:00
|
|
|
void GPU_storagebuf_free(GPUStorageBuf *ssbo);
|
2022-02-08 23:17:31 +01:00
|
|
|
|
2022-03-16 08:38:33 +01:00
|
|
|
void GPU_storagebuf_update(GPUStorageBuf *ssbo, const void *data);
|
2022-02-08 23:17:31 +01:00
|
|
|
|
2022-03-16 08:38:33 +01:00
|
|
|
void GPU_storagebuf_bind(GPUStorageBuf *ssbo, int slot);
|
|
|
|
|
void GPU_storagebuf_unbind(GPUStorageBuf *ssbo);
|
2024-04-17 11:06:39 +02:00
|
|
|
/**
|
|
|
|
|
* Resets the internal slot usage tracking. But there is no guarantee that
|
|
|
|
|
* this actually undo the bindings for the next draw call. Only has effect when G_DEBUG_GPU is set.
|
|
|
|
|
*/
|
|
|
|
|
void GPU_storagebuf_debug_unbind_all();
|
2022-02-08 23:17:31 +01:00
|
|
|
|
2022-03-16 08:42:12 +01:00
|
|
|
void GPU_storagebuf_clear_to_zero(GPUStorageBuf *ssbo);
|
|
|
|
|
|
2023-03-09 18:46:28 +01:00
|
|
|
/**
|
|
|
|
|
* Clear the content of the buffer using the given #clear_value. #clear_value will be used as a
|
|
|
|
|
* repeatable pattern of 32bits.
|
|
|
|
|
*/
|
|
|
|
|
void GPU_storagebuf_clear(GPUStorageBuf *ssbo, uint32_t clear_value);
|
|
|
|
|
|
2023-10-20 17:04:36 +02:00
|
|
|
/**
|
|
|
|
|
* Explicitly sync updated storage buffer contents back to host within the GPU command stream. This
|
|
|
|
|
* ensures any changes made by the GPU are visible to the host.
|
|
|
|
|
* NOTE: This command is only valid for host-visible storage buffers.
|
|
|
|
|
*/
|
|
|
|
|
void GPU_storagebuf_sync_to_host(GPUStorageBuf *ssbo);
|
|
|
|
|
|
2022-08-30 21:52:09 +02:00
|
|
|
/**
|
|
|
|
|
* Read back content of the buffer to CPU for inspection.
|
|
|
|
|
* Slow! Only use for inspection / debugging.
|
2023-10-20 17:04:36 +02:00
|
|
|
*
|
|
|
|
|
* NOTE: If GPU_storagebuf_sync_to_host is called, this command is synchronized against that call.
|
|
|
|
|
* If pending GPU updates to the storage buffer are not yet visible to the host, the command will
|
|
|
|
|
* stall until dependent GPU work has completed.
|
|
|
|
|
*
|
2024-02-09 16:11:33 +01:00
|
|
|
* Otherwise, this command is synchronized against this call and will stall the CPU until the
|
|
|
|
|
* buffer content can be read by the host.
|
2022-08-30 21:52:09 +02:00
|
|
|
*/
|
|
|
|
|
void GPU_storagebuf_read(GPUStorageBuf *ssbo, void *data);
|
|
|
|
|
|
2022-05-18 21:49:08 +02:00
|
|
|
/**
|
2022-05-19 10:02:52 +10:00
|
|
|
* \brief Copy a part of a vertex buffer to a storage buffer.
|
|
|
|
|
*
|
|
|
|
|
* \param ssbo: destination storage buffer
|
|
|
|
|
* \param src: source vertex buffer
|
|
|
|
|
* \param dst_offset: where to start copying to (in bytes).
|
|
|
|
|
* \param src_offset: where to start copying from (in bytes).
|
|
|
|
|
* \param copy_size: byte size of the segment to copy.
|
2022-05-18 21:49:08 +02:00
|
|
|
*/
|
2024-03-24 16:38:30 +01:00
|
|
|
void GPU_storagebuf_copy_sub_from_vertbuf(GPUStorageBuf *ssbo,
|
|
|
|
|
blender::gpu::VertBuf *src,
|
|
|
|
|
uint dst_offset,
|
|
|
|
|
uint src_offset,
|
|
|
|
|
uint copy_size);
|
2022-05-18 21:49:08 +02:00
|
|
|
|
2024-02-01 17:26:08 +01:00
|
|
|
/**
|
|
|
|
|
* Ensure the ssbo is ready to be used as an indirect buffer in `GPU_batch_draw_indirect`.
|
2024-02-02 10:48:22 +11:00
|
|
|
* NOTE: Internally, this is only required for the OpenGL backend.
|
2024-02-01 17:26:08 +01:00
|
|
|
*/
|
|
|
|
|
void GPU_storagebuf_sync_as_indirect_buffer(GPUStorageBuf *ssbo);
|