Blender V5.3
shader_create_info_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
9#include "gpu_testing.hh"
10
11#include "GPU_batch.hh"
12#include "GPU_capabilities.hh"
13#include "GPU_context.hh"
14#include "GPU_framebuffer.hh"
15
16namespace blender::gpu::tests {
17
18using namespace blender::gpu::shader;
19
24{
28 {
29 GTEST_SKIP() << "NVIDIA fails to compile workaround due to reserved names. Gladly it doesn't "
30 "need the workaround.";
31 }
32
34}
35GPU_TEST(static_shaders)
36
38{
42 {
43 GTEST_SKIP() << "NVIDIA fails to compile workaround due to reserved names. Gladly it doesn't "
44 "need the workaround.";
45 }
46
48 GTEST_SKIP() << "Device does not support multi viewport, but the test requires it.";
49 }
50
52
53 ShaderCreateInfo create_info("gpu_framebuffer_layer_viewport_test");
54 create_info.vertex_source("gpu_framebuffer_layer_viewport_test.glsl");
55 create_info.fragment_source("gpu_framebuffer_layer_viewport_test.glsl");
57 create_info.fragment_out(0, Type::int2_t, "out_value");
58
59 create_info.pipeline_state()
68 .viewports(16)
69 .color_format(TextureTargetFormat::SINT_32_32);
70
72 reinterpret_cast<GPUShaderCreateInfo *>(&create_info));
73
74 EXPECT_TRUE(shader != nullptr);
75
76 /* Setup framebuffer */
77 const int2 size(4, 4);
78 const int layers = 256;
81 __func__, UNPACK2(size), layers, 1, TextureFormat::SINT_32_32, usage, nullptr);
82
83 gpu::FrameBuffer *framebuffer = GPU_framebuffer_create(__func__);
86 GPU_framebuffer_bind(framebuffer);
87
88 /* Setup viewports. */
89 int viewport_rects[16][4];
90 for (int i = 0; i < 16; i++) {
91 viewport_rects[i][0] = i % 4;
92 viewport_rects[i][1] = i / 4;
93 viewport_rects[i][2] = 1;
94 viewport_rects[i][3] = 1;
95 }
96 GPU_framebuffer_multi_viewports_set(framebuffer, viewport_rects);
97 int tri_count = size.x * size.y * layers;
98
99 Batch *batch = GPU_batch_create_procedural(GPU_PRIM_TRIS, tri_count * 3);
101 /* On vulkan this triggers an assert when a new pipeline is created (`G.debug_value == 32`) */
102 {
103 GPUContext *context = GPU_context_active_get();
104 DebugScopePipelineCreation scope(context);
105 GPU_batch_draw(batch);
106 }
107 GPU_flush();
108
110 GPU_batch_discard(batch);
111 GPU_framebuffer_free(framebuffer);
115}
116GPU_TEST(shader_create_info_pipeline)
117
118} // namespace blender::gpu::tests
#define GPU_ATTACHMENT_TEXTURE(_texture)
#define GPU_ATTACHMENT_NONE
#define GPU_framebuffer_ensure_config(_fb,...)
#define GPU_SHADER_FREE_SAFE(shader)
#define UNPACK2(a)
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
#define EXPECT_TRUE(result)
#define GPU_TEST(test_name)
static void test_shader_create_info_pipeline()
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
@ GPU_CULL_NONE
Definition GPU_state.hh:157
@ GPU_STENCIL_OP_NONE
Definition GPU_state.hh:149
gpu::Batch * GPU_batch_create_procedural(GPUPrimType primitive_type, int32_t vertex_count)
Definition gpu_batch.cc:85
bool GPU_type_matches_ex(GPUDeviceType device, GPUOSType os, GPUDriverType driver, GPUBackendType backend)
bool gpu_shader_create_info_compile_all(const char *name_starts_with_filter)
void GPU_framebuffer_free(gpu::FrameBuffer *fb)
gpu::Shader * GPU_shader_create_from_info(const GPUShaderCreateInfo *_info)
gpu::Texture * GPU_texture_create_2d_array(const char *name, int width, int height, int layer_len, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_batch_discard(gpu::Batch *batch)
void GPU_render_begin()
void GPU_batch_set_shader(gpu::Batch *batch, gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
@ GPU_DRIVER_OFFICIAL
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ G_DEBUG_GPU_FORCE_WORKAROUNDS
Global G
Definition blender.cc:57
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
@ GPU_TEXTURE_USAGE_HOST_READ
@ GPU_TEXTURE_USAGE_ATTACHMENT
void GPU_render_end()
void GPU_shader_unbind()
void GPU_framebuffer_multi_viewports_set(gpu::FrameBuffer *gpu_fb, const int viewport_rects[GPU_MAX_VIEWPORTS][4])
void GPU_batch_draw(gpu::Batch *batch)
@ GPU_STENCIL_NONE
Definition GPU_state.hh:142
gpu::FrameBuffer * GPU_framebuffer_create(const char *name)
void GPU_flush()
Definition gpu_state.cc:284
@ GPU_WRITE_COLOR
Definition GPU_state.hh:27
void GPU_texture_free(gpu::Texture *texture)
bool GPU_multi_viewport_support()
@ GPU_VERTEX_LAST
Definition GPU_state.hh:163
@ GPU_DEVICE_NVIDIA
GPUContext * GPU_context_active_get()
Activate pipeline creation debugging for a certain scope.
Self & color_format(TextureTargetFormat color_format)
Self & state(GPUWriteMask write_mask, GPUBlend blend, GPUFaceCullTest culling_test, GPUDepthTest depth_test, GPUStencilTest stencil_test, GPUStencilOp stencil_op, GPUProvokingVertex provoking_vert)
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
Self & fragment_source(StringRefNull filename)
Self & fragment_out(int slot, Type type, StringRefNull name, DualBlend blend=DualBlend::NONE, int raster_order_group=-1, ConditionFn cond=nullptr)
Self & builtins(BuiltinBits builtin, ConditionFn cond=nullptr)
PipelineState & pipeline_state()
Create a new pipeline state.