GPU: Only compile test shaders when test cases option is enabled.

The glsl files + create infos of shaders that are only used
during development where still being compiled into blender.

This isn't needed and shouldn't be included. This change will
only include them when WITH_GTEST and WITH_OPENGL_DRAW_TESTS are
enabled. All other cases those files will be skipped.
This commit is contained in:
Jeroen Bakker 2023-01-30 15:43:49 +01:00
parent 1a50f814e6
commit ce13d0d326
8 changed files with 71 additions and 61 deletions

View File

@ -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()

View File

@ -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);

View File

@ -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);

View File

@ -0,0 +1,5 @@
void main() {
int index = int(gl_GlobalInvocationID.x);
vec4 pos = vec4(gl_GlobalInvocationID.x);
imageStore(img_output, index, pos);
}

View File

@ -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);
}

View File

@ -0,0 +1,4 @@
void main() {
uint store_index = int(gl_GlobalInvocationID.x);
out_indices[store_index] = store_index;
}

View File

@ -0,0 +1,5 @@
void main() {
uint index = gl_GlobalInvocationID.x;
vec4 pos = vec4(gl_GlobalInvocationID.x);
out_positions[index] = pos;
}