Blender  V3.3
gpu_storage_buffer.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2022 Blender Foundation. All rights reserved. */
3 
8 #include "MEM_guardedalloc.h"
9 #include <cstring>
10 
11 #include "BLI_blenlib.h"
12 #include "BLI_math_base.h"
13 
14 #include "gpu_backend.hh"
15 
16 #include "GPU_material.h"
17 #include "GPU_vertex_buffer.h" /* For GPUUsageType. */
18 
19 #include "GPU_storage_buffer.h"
22 
23 /* -------------------------------------------------------------------- */
27 namespace blender::gpu {
28 
29 StorageBuf::StorageBuf(size_t size, const char *name)
30 {
31  /* Make sure that UBO is padded to size of vec4 */
32  BLI_assert((size % 16) == 0);
33 
35 
36  BLI_strncpy(name_, name, sizeof(name_));
37 }
38 
40 {
42 }
43 
44 } // namespace blender::gpu
45 
48 /* -------------------------------------------------------------------- */
52 using namespace blender::gpu;
53 
55  const void *data,
56  GPUUsageType usage,
57  const char *name)
58 {
59  StorageBuf *ssbo = GPUBackend::get()->storagebuf_alloc(size, usage, name);
60  /* Direct init. */
61  if (data != nullptr) {
62  ssbo->update(data);
63  }
64  return wrap(ssbo);
65 }
66 
68 {
69  delete unwrap(ssbo);
70 }
71 
72 void GPU_storagebuf_update(GPUStorageBuf *ssbo, const void *data)
73 {
74  unwrap(ssbo)->update(data);
75 }
76 
77 void GPU_storagebuf_bind(GPUStorageBuf *ssbo, int slot)
78 {
79  unwrap(ssbo)->bind(slot);
80 }
81 
83 {
84  unwrap(ssbo)->unbind();
85 }
86 
88 {
89  /* FIXME */
90 }
91 
93  eGPUTextureFormat internal_format,
94  eGPUDataFormat data_format,
95  void *data)
96 {
97  unwrap(ssbo)->clear(internal_format, data_format, data);
98 }
99 
101 {
102  uint32_t data = 0u;
104 }
105 
107  GPUStorageBuf *ssbo, GPUVertBuf *src, uint dst_offset, uint src_offset, uint copy_size)
108 {
109  unwrap(ssbo)->copy_sub(unwrap(src), dst_offset, src_offset, copy_size);
110 }
111 
#define BLI_assert(a)
Definition: BLI_assert.h:46
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
unsigned int uint
Definition: BLI_sys_types.h:67
struct GPUStorageBuf GPUStorageBuf
eGPUDataFormat
Definition: GPU_texture.h:170
@ GPU_DATA_UINT
Definition: GPU_texture.h:173
eGPUTextureFormat
Definition: GPU_texture.h:83
@ GPU_R32UI
Definition: GPU_texture.h:108
struct GPUVertBuf GPUVertBuf
GPUUsageType
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
static GPUBackend * get()
Definition: gpu_context.cc:292
virtual StorageBuf * storagebuf_alloc(int size, GPUUsageType usage, const char *name)=0
StorageBuf(size_t size, const char *name)
virtual void update(const void *data)=0
SyclQueue void void * src
void GPU_storagebuf_copy_sub_from_vertbuf(GPUStorageBuf *ssbo, GPUVertBuf *src, uint dst_offset, uint src_offset, uint copy_size)
Copy a part of a vertex buffer to a storage buffer.
void GPU_storagebuf_bind(GPUStorageBuf *ssbo, int slot)
void GPU_storagebuf_unbind_all()
void GPU_storagebuf_clear(GPUStorageBuf *ssbo, eGPUTextureFormat internal_format, eGPUDataFormat data_format, void *data)
void GPU_storagebuf_unbind(GPUStorageBuf *ssbo)
void GPU_storagebuf_clear_to_zero(GPUStorageBuf *ssbo)
void GPU_storagebuf_free(GPUStorageBuf *ssbo)
void GPU_storagebuf_update(GPUStorageBuf *ssbo, const void *data)
GPUStorageBuf * GPU_storagebuf_create_ex(size_t size, const void *data, GPUUsageType usage, const char *name)
static GPUContext * wrap(Context *ctx)
static Context * unwrap(GPUContext *ctx)
unsigned int uint32_t
Definition: stdint.h:80