Blender V5.0
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
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. */
28 uint value_pos = GPU_vertformat_attr_add(&format, "value", gpu::VertAttrType::SFLOAT_32);
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
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
unsigned int uint
void GPU_compute_dispatch(blender::gpu::Shader *shader, uint groups_x_len, uint groups_y_len, uint groups_z_len, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_free(blender::gpu::Shader *shader)
int GPU_shader_get_sampler_binding(blender::gpu::Shader *shader, const char *name)
void GPU_shader_bind(blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
int GPU_shader_get_ssbo_binding(blender::gpu::Shader *shader, const char *name)
blender::gpu::Shader * GPU_shader_create_from_info_name(const char *info_name)
void GPU_shader_unbind()
@ GPU_BARRIER_BUFFER_UPDATE
Definition GPU_state.hh:56
void GPU_memory_barrier(GPUBarrier barrier)
Definition gpu_state.cc:326
void GPU_storagebuf_free(blender::gpu::StorageBuf *ssbo)
blender::gpu::StorageBuf * GPU_storagebuf_create_ex(size_t size, const void *data, GPUUsageType usage, const char *name)
void GPU_storagebuf_bind(blender::gpu::StorageBuf *ssbo, int slot)
void GPU_storagebuf_read(blender::gpu::StorageBuf *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
uint GPU_vertformat_attr_add(GPUVertFormat *format, blender::StringRef name, blender::gpu::VertAttrType type)
#define GPU_TEST(test_name)
format
static void test_buffer_texture()
VecBase< float, 4 > float4