Blender V5.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"
9#include "GPU_state.hh"
10#include "GPU_vertex_buffer.hh"
11#include "GPU_vertex_format.hh"
12
14
15#include "gpu_testing.hh"
16
17namespace blender::gpu::tests {
18
20{
21 /* Build compute shader. */
22 gpu::Shader *shader = GPU_shader_create_from_info_name("gpu_buffer_texture_test");
23 EXPECT_NE(shader, nullptr);
25
26 /* Vertex buffer. */
27 GPUVertFormat format = {};
28 uint value_pos = GPU_vertformat_attr_add(&format, "value", gpu::VertAttrType::SFLOAT_32);
29 VertBuf *vertex_buffer = GPU_vertbuf_create_with_format_ex(format,
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. */
39 4 * sizeof(float), nullptr, GPU_USAGE_STATIC, __func__);
41
42 /* Dispatch compute task. */
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);
58}
59
60GPU_TEST(buffer_texture)
61
62} // namespace blender::gpu::tests
#define EXPECT_NE(result, expect)
#define GPU_TEST(test_name)
static void test_buffer_texture()
int GPU_shader_get_sampler_binding(gpu::Shader *shader, const char *name)
void GPU_vertbuf_bind_as_texture(gpu::VertBuf *verts, int binding)
unsigned int uint
Definition BKE_text.h:55
gpu::StorageBuf * GPU_storagebuf_create_ex(size_t size, const void *data, GPUUsageType usage, const char *name)
gpu::Shader * GPU_shader_create_from_info_name(const char *info_name)
void GPU_compute_dispatch(gpu::Shader *shader, uint groups_x_len, uint groups_y_len, uint groups_z_len, const gpu::shader::SpecializationConstants *constants_state=nullptr)
int GPU_shader_get_ssbo_binding(gpu::Shader *shader, const char *name)
void GPU_memory_barrier(GPUBarrier barrier)
Definition gpu_state.cc:305
void GPU_shader_unbind()
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
@ GPU_BARRIER_BUFFER_UPDATE
Definition GPU_state.hh:59
void GPU_storagebuf_bind(gpu::StorageBuf *ssbo, int slot)
gpu::VertBuf * GPU_vertbuf_create_with_format_ex(const GPUVertFormat &format, GPUUsageType usage)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void GPU_vertbuf_attr_fill(gpu::VertBuf *, uint a_idx, const void *data)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
void GPU_shader_free(gpu::Shader *shader)
void GPU_storagebuf_free(gpu::StorageBuf *ssbo)
void GPU_vertbuf_discard(gpu::VertBuf *)
@ GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY
void GPU_storagebuf_read(gpu::StorageBuf *ssbo, void *data)