diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 68e77ef9a92..30a525af6cd 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -495,11 +495,18 @@ set(GLSL_SRC shaders/gpu_shader_cfg_world_clip_lib.glsl shaders/gpu_shader_colorspace_lib.glsl - tests/gpu_math_test.glsl GPU_shader_shared_utils.h ) +set(GLSL_SRC_TEST + tests/shaders/gpu_math_test.glsl + tests/shaders/gpu_compute_1d_test.glsl + tests/shaders/gpu_compute_2d_test.glsl + tests/shaders/gpu_compute_ibo_test.glsl + tests/shaders/gpu_compute_vbo_test.glsl +) + set(MTL_BACKEND_GLSL_SRC metal/kernels/compute_texture_update.msl metal/kernels/compute_texture_read.msl @@ -517,6 +524,12 @@ set(MSL_SRC metal/mtl_shader_shared.h ) +if(WITH_GTESTS) + if(WITH_OPENGL_DRAW_TESTS) + list(APPEND GLSL_SRC ${GLSL_SRC_TEST}) + endif() +endif() + if(WITH_METAL_BACKEND) list(APPEND GLSL_SRC ${MTL_BACKEND_GLSL_SRC}) @@ -638,16 +651,26 @@ set(SRC_SHADER_CREATE_INFOS shaders/infos/gpu_shader_keyframe_shape_info.hh shaders/infos/gpu_shader_line_dashed_uniform_color_info.hh shaders/infos/gpu_shader_simple_lighting_info.hh - shaders/infos/gpu_shader_test_info.hh shaders/infos/gpu_shader_text_info.hh shaders/infos/gpu_srgb_to_framebuffer_space_info.hh ) +set(SRC_SHADER_CREATE_INFOS_TEST + shaders/infos/gpu_shader_test_info.hh +) + + set(SRC_SHADER_CREATE_INFOS_MTL metal/kernels/depth_2d_update_info.hh metal/kernels/gpu_shader_fullscreen_blit_info.hh ) +if(WITH_GTESTS) + if(WITH_OPENGL_DRAW_TESTS) + list(APPEND SRC_SHADER_CREATE_INFOS ${SRC_SHADER_CREATE_INFOS_TEST}) + endif() +endif() + if(WITH_METAL_BACKEND) list(APPEND SRC_SHADER_CREATE_INFOS ${SRC_SHADER_CREATE_INFOS_MTL}) endif() diff --git a/source/blender/gpu/shaders/infos/gpu_shader_test_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_test_info.hh index 358b5b3c5ac..432fa56b95f 100644 --- a/source/blender/gpu/shaders/infos/gpu_shader_test_info.hh +++ b/source/blender/gpu/shaders/infos/gpu_shader_test_info.hh @@ -17,3 +17,27 @@ GPU_SHADER_CREATE_INFO(gpu_math_test) .fragment_source("gpu_math_test.glsl") .additional_info("gpu_shader_test") .do_static_compilation(true); + +GPU_SHADER_CREATE_INFO(gpu_compute_1d_test) + .local_group_size(1) + .image(1, GPU_RGBA32F, Qualifier::WRITE, ImageType::FLOAT_1D, "img_output") + .compute_source("gpu_compute_1d_test.glsl") + .do_static_compilation(true); + +GPU_SHADER_CREATE_INFO(gpu_compute_2d_test) + .local_group_size(1, 1) + .image(1, GPU_RGBA32F, Qualifier::WRITE, ImageType::FLOAT_2D, "img_output") + .compute_source("gpu_compute_2d_test.glsl") + .do_static_compilation(true); + +GPU_SHADER_CREATE_INFO(gpu_compute_ibo_test) + .local_group_size(1) + .storage_buf(0, Qualifier::WRITE, "uint", "out_indices[]") + .compute_source("gpu_compute_ibo_test.glsl") + .do_static_compilation(true); + +GPU_SHADER_CREATE_INFO(gpu_compute_vbo_test) + .local_group_size(1) + .storage_buf(0, Qualifier::WRITE, "vec4", "out_positions[]") + .compute_source("gpu_compute_vbo_test.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/tests/gpu_shader_test.cc b/source/blender/gpu/tests/gpu_shader_test.cc index 6cf22dde014..8a5b70a9b1d 100644 --- a/source/blender/gpu/tests/gpu_shader_test.cc +++ b/source/blender/gpu/tests/gpu_shader_test.cc @@ -38,21 +38,7 @@ static void test_gpu_shader_compute_2d() static constexpr uint SIZE = 512; /* Build compute shader. */ - const char *compute_glsl = R"( -void main() { - vec4 pixel = vec4(1.0, 0.5, 0.2, 1.0); - imageStore(img_output, ivec2(gl_GlobalInvocationID.xy), pixel); -} -)"; - - ShaderCreateInfo info(__func__); - info.local_group_size(1, 1) - .image(0, GPU_RGBA32F, Qualifier::WRITE, ImageType::FLOAT_2D, "img_output") - /* Use actual file to not raise any asserts when checking for errors. */ - .compute_source("gpu_shader_common_hash.glsl"); - info.compute_source_generated = compute_glsl; - - GPUShader *shader = GPU_shader_create_from_info((GPUShaderCreateInfo *)&info); + GPUShader *shader = GPU_shader_create_from_info_name("gpu_compute_2d_test"); EXPECT_NE(shader, nullptr); /* Create texture to store result and attach to shader. */ @@ -98,21 +84,7 @@ static void test_gpu_shader_compute_1d() static constexpr uint SIZE = 10; /* Build compute shader. */ - const char *compute_glsl = R"( -void main() { - int index = int(gl_GlobalInvocationID.x); - vec4 pos = vec4(gl_GlobalInvocationID.x); - imageStore(img_output, index, pos); -} -)"; - - ShaderCreateInfo info(__func__); - info.local_group_size(1) - .image(1, GPU_RGBA32F, Qualifier::WRITE, ImageType::FLOAT_1D, "img_output") - /* Use actual file to not raise any asserts when checking for errors. */ - .compute_source("gpu_shader_common_hash.glsl"); - info.compute_source_generated = compute_glsl; - GPUShader *shader = GPU_shader_create_from_info((GPUShaderCreateInfo *)&info); + GPUShader *shader = GPU_shader_create_from_info_name("gpu_compute_1d_test"); EXPECT_NE(shader, nullptr); /* Construct Texture. */ @@ -161,21 +133,7 @@ static void test_gpu_shader_compute_vbo() static constexpr uint SIZE = 128; /* Build compute shader. */ - const char *compute_glsl = R"( -void main() { - uint index = gl_GlobalInvocationID.x; - vec4 pos = vec4(gl_GlobalInvocationID.x); - out_positions[index] = pos; -} -)"; - - ShaderCreateInfo info(__func__); - info.local_group_size(1) - .storage_buf(0, Qualifier::WRITE, "vec4", "out_positions[]") - /* Use actual file to not raise any asserts when checking for errors. */ - .compute_source("gpu_shader_common_hash.glsl"); - info.compute_source_generated = compute_glsl; - GPUShader *shader = GPU_shader_create_from_info((GPUShaderCreateInfo *)&info); + GPUShader *shader = GPU_shader_create_from_info_name("gpu_compute_vbo_test"); EXPECT_NE(shader, nullptr); GPU_shader_bind(shader); @@ -222,20 +180,7 @@ static void test_gpu_shader_compute_ibo() static constexpr uint SIZE = 128; /* Build compute shader. */ - const char *compute_glsl = R"( -void main() { - uint store_index = int(gl_GlobalInvocationID.x); - out_indices[store_index] = store_index; -} -)"; - - ShaderCreateInfo info(__func__); - info.local_group_size(1) - .storage_buf(0, Qualifier::WRITE, "uint", "out_indices[]") - /* Use actual file to not raise any asserts when checking for errors. */ - .compute_source("gpu_shader_common_hash.glsl"); - info.compute_source_generated = compute_glsl; - GPUShader *shader = GPU_shader_create_from_info((GPUShaderCreateInfo *)&info); + GPUShader *shader = GPU_shader_create_from_info_name("gpu_compute_ibo_test"); EXPECT_NE(shader, nullptr); GPU_shader_bind(shader); diff --git a/source/blender/gpu/tests/shaders/gpu_compute_1d_test.glsl b/source/blender/gpu/tests/shaders/gpu_compute_1d_test.glsl new file mode 100644 index 00000000000..43832b9f16d --- /dev/null +++ b/source/blender/gpu/tests/shaders/gpu_compute_1d_test.glsl @@ -0,0 +1,5 @@ +void main() { + int index = int(gl_GlobalInvocationID.x); + vec4 pos = vec4(gl_GlobalInvocationID.x); + imageStore(img_output, index, pos); +} \ No newline at end of file diff --git a/source/blender/gpu/tests/shaders/gpu_compute_2d_test.glsl b/source/blender/gpu/tests/shaders/gpu_compute_2d_test.glsl new file mode 100644 index 00000000000..a43933151d8 --- /dev/null +++ b/source/blender/gpu/tests/shaders/gpu_compute_2d_test.glsl @@ -0,0 +1,4 @@ +void main() { + vec4 pixel = vec4(1.0, 0.5, 0.2, 1.0); + imageStore(img_output, ivec2(gl_GlobalInvocationID.xy), pixel); +} \ No newline at end of file diff --git a/source/blender/gpu/tests/shaders/gpu_compute_ibo_test.glsl b/source/blender/gpu/tests/shaders/gpu_compute_ibo_test.glsl new file mode 100644 index 00000000000..965d59c7490 --- /dev/null +++ b/source/blender/gpu/tests/shaders/gpu_compute_ibo_test.glsl @@ -0,0 +1,4 @@ +void main() { + uint store_index = int(gl_GlobalInvocationID.x); + out_indices[store_index] = store_index; +} \ No newline at end of file diff --git a/source/blender/gpu/tests/shaders/gpu_compute_vbo_test.glsl b/source/blender/gpu/tests/shaders/gpu_compute_vbo_test.glsl new file mode 100644 index 00000000000..147ef09d004 --- /dev/null +++ b/source/blender/gpu/tests/shaders/gpu_compute_vbo_test.glsl @@ -0,0 +1,5 @@ +void main() { + uint index = gl_GlobalInvocationID.x; + vec4 pos = vec4(gl_GlobalInvocationID.x); + out_positions[index] = pos; +} \ No newline at end of file diff --git a/source/blender/gpu/tests/gpu_math_test.glsl b/source/blender/gpu/tests/shaders/gpu_math_test.glsl similarity index 100% rename from source/blender/gpu/tests/gpu_math_test.glsl rename to source/blender/gpu/tests/shaders/gpu_math_test.glsl