Blender V4.3
buffer_texture_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "testing/testing.h"
6
7#include "GPU_capabilities.hh"
8#include "GPU_compute.hh"
10#include "GPU_vertex_format.hh"
11
12#include "BLI_index_range.hh"
14
15#include "gpu_testing.hh"
16
18
20{
21 /* Build compute shader. */
22 GPUShader *shader = GPU_shader_create_from_info_name("gpu_buffer_texture_test");
23 EXPECT_NE(shader, nullptr);
24 GPU_shader_bind(shader);
25
26 /* Vertex buffer. */
31 float4 value = float4(42.42, 23.23, 1.0, -1.0);
32 GPU_vertbuf_data_alloc(*vertex_buffer, 4);
33 GPU_vertbuf_attr_fill(vertex_buffer, value_pos, &value);
34 GPU_vertbuf_bind_as_texture(vertex_buffer,
35 GPU_shader_get_sampler_binding(shader, "bufferTexture"));
36
37 /* Construct SSBO. */
38 GPUStorageBuf *ssbo = GPU_storagebuf_create_ex(
39 4 * sizeof(float), nullptr, GPU_USAGE_STATIC, __func__);
40 GPU_storagebuf_bind(ssbo, GPU_shader_get_ssbo_binding(shader, "data_out"));
41
42 /* Dispatch compute task. */
43 GPU_compute_dispatch(shader, 4, 1, 1);
44
45 /* Check if compute has been done. */
47
48 /* Download the storage buffer. */
49 float4 read_data;
50 GPU_storagebuf_read(ssbo, read_data);
51 EXPECT_EQ(read_data, value);
52
53 /* Cleanup. */
56 GPU_vertbuf_discard(vertex_buffer);
57 GPU_shader_free(shader);
58}
59
60GPU_TEST(buffer_texture)
61
62} // namespace blender::gpu::tests
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
unsigned int uint
void GPU_compute_dispatch(GPUShader *shader, uint groups_x_len, uint groups_y_len, uint groups_z_len)
int GPU_shader_get_sampler_binding(GPUShader *shader, const char *name)
GPUShader * GPU_shader_create_from_info_name(const char *info_name)
int GPU_shader_get_ssbo_binding(GPUShader *shader, const char *name)
void GPU_shader_bind(GPUShader *shader)
void GPU_shader_free(GPUShader *shader)
void GPU_shader_unbind()
void GPU_memory_barrier(eGPUBarrier barrier)
Definition gpu_state.cc:374
@ GPU_BARRIER_BUFFER_UPDATE
Definition GPU_state.hh:56
void GPU_storagebuf_bind(GPUStorageBuf *ssbo, int slot)
GPUStorageBuf * GPU_storagebuf_create_ex(size_t size, const void *data, GPUUsageType usage, const char *name)
void GPU_storagebuf_free(GPUStorageBuf *ssbo)
void GPU_storagebuf_read(GPUStorageBuf *ssbo, void *data)
void GPU_vertbuf_attr_fill(blender::gpu::VertBuf *, uint a_idx, const void *data)
blender::gpu::VertBuf * GPU_vertbuf_create_with_format_ex(const GPUVertFormat &format, GPUUsageType usage)
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
void GPU_vertbuf_bind_as_texture(blender::gpu::VertBuf *verts, int binding)
void GPU_vertbuf_discard(blender::gpu::VertBuf *)
@ GPU_USAGE_STATIC
@ GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY
@ GPU_FETCH_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
struct GPUShader GPUShader
#define GPU_TEST(test_name)
format
static void test_buffer_texture()
VecBase< float, 4 > float4