DrawEngine: Shader Test Suite

A test case that compiles all the GLSL shaders for workbench, gpencil, overlay and some
of eevee. Compilation is still platform dependent, but when run on a test-farm
with different hardware we will be able to detect GLSL compilation
errors early on.

The test will be compiled when `WITH_GTEST` and `WITH_OPENGL_DRAW_TESTS`
are On.

For eevee only the shaders inside eevee_shaders.c are included. EEVEE has some shaders
located inside the submodule. They aren't accessible to the outside and aren't added
to the test case. We should see how we want to add them. For the test cases it is better
to move them to eevee_shaders.c, but for eevee perspective it is better to keep them in
the submodule. Keeping them in the submodule could lead to situations that is harder to test.
as the shader could already have been initialized.

Reviewed By: Clément Foucault

Differential Revision: https://developer.blender.org/D8667
This commit is contained in:
Jeroen Bakker
2020-08-28 14:44:23 +02:00
committed by Jeroen Bakker
parent 2654e9c9c1
commit 0852ecd844
8 changed files with 381 additions and 1 deletions

View File

@@ -419,6 +419,28 @@ if(WITH_XR_OPENXR)
add_definitions(-DWITH_XR_OPENXR)
endif()
if(WITH_GTESTS)
if(WITH_OPENGL_DRAW_TESTS)
add_definitions(-DWITH_OPENGL_DRAW_TESTS)
endif()
endif()
add_definitions(${GL_DEFINITIONS})
blender_add_lib(bf_draw "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
if(WITH_GTESTS)
if(WITH_OPENGL_DRAW_TESTS)
set(TEST_SRC
tests/shaders_test.cc
)
set(TEST_INC
"../../../intern/ghost/"
)
set(TEST_LIB
bf_draw
)
include(GTestTesting)
blender_add_test_lib(bf_draw_tests "${TEST_SRC}" "${INC};${TEST_INC}" "${INC_SYS}" "${LIB};${TEST_LIB}")
endif()
endif()

View File

@@ -32,6 +32,10 @@
#include "BKE_camera.h"
#ifdef __cplusplus
extern "C" {
#endif
struct EEVEE_ShadowCasterBuffer;
struct GPUFrameBuffer;
struct Object;
@@ -1363,3 +1367,7 @@ static const float cubefacemat[6][4][4] = {
{0.0f, 0.0f, 1.0f, 0.0f},
{0.0f, 0.0f, 0.0f, 1.0f}},
};
#ifdef __cplusplus
}
#endif

View File

@@ -24,10 +24,16 @@
#include "DNA_gpencil_types.h"
#include "DRW_render.h"
#include "BLI_bitmap.h"
#include "GPU_batch.h"
#ifdef __cplusplus
extern "C" {
#endif
extern DrawEngineType draw_engine_gpencil_type;
struct GPENCIL_Data;
@@ -397,7 +403,6 @@ void gpencil_vfx_cache_populate(GPENCIL_Data *vedata, Object *ob, GPENCIL_tObjec
/* Shaders */
struct GPUShader *GPENCIL_shader_antialiasing(int stage);
struct GPUShader *GPENCIL_shader_geometry_get(void);
struct GPUShader *GPENCIL_shader_composite_get(void);
struct GPUShader *GPENCIL_shader_layer_blend_get(void);
struct GPUShader *GPENCIL_shader_mask_invert_get(void);
struct GPUShader *GPENCIL_shader_depth_merge_get(void);
@@ -438,3 +443,6 @@ void GPENCIL_render_to_image(void *vedata,
void gpencil_light_pool_free(void *storage);
void gpencil_material_pool_free(void *storage);
GPENCIL_ViewLayerData *GPENCIL_view_layer_data_ensure(void);
#ifdef __cplusplus
}
#endif

View File

@@ -22,6 +22,12 @@
#pragma once
#include "DRW_render.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __APPLE__
# define USE_GEOM_SHADER_WORKAROUND 1
#else
@@ -627,3 +633,7 @@ GPUShader *OVERLAY_shader_xray_fade(void);
OVERLAY_InstanceFormats *OVERLAY_shader_instance_formats_get(void);
void OVERLAY_shader_free(void);
#ifdef __cplusplus
}
#endif

View File

@@ -33,6 +33,10 @@
#include "workbench_engine.h"
#ifdef __cplusplus
extern "C" {
#endif
extern struct DrawEngineType draw_engine_workbench;
#define WORKBENCH_ENGINE "BLENDER_WORKBENCH"
@@ -519,3 +523,6 @@ void workbench_render(void *ved,
void workbench_render_update_passes(struct RenderEngine *engine,
struct Scene *scene,
struct ViewLayer *view_layer);
#ifdef __cplusplus
}
#endif

View File

@@ -84,6 +84,7 @@
#include "draw_color_management.h"
#include "draw_manager_profiling.h"
#include "draw_manager_testing.h"
#include "draw_manager_text.h"
/* only for callbacks */
@@ -2887,6 +2888,8 @@ void DRW_gpu_render_context_disable(void *UNUSED(re_gpu_context))
GPU_context_active_set(NULL);
}
/** \} */
#ifdef WITH_XR_OPENXR
/* XXX
@@ -2922,4 +2925,17 @@ void DRW_xr_drawing_end(void)
}
#endif
/** \name Internal testing API for gtests
* \{ */
#ifdef WITH_OPENGL_DRAW_TESTS
void DRW_draw_state_init_gtests(eGPUShaderConfig sh_cfg)
{
DST.draw_ctx.sh_cfg = sh_cfg;
}
#endif
/** \} */

View File

@@ -0,0 +1,39 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright 2016, Blender Foundation.
*/
/** \file
* \ingroup draw
*/
/* Internal API only for test cases. */
#pragma once
#include "GPU_shader.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef WITH_OPENGL_DRAW_TESTS
void DRW_draw_state_init_gtests(eGPUShaderConfig sh_cfg);
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,270 @@
/* Apache License, Version 2.0 */
#include "testing/testing.h"
#include "intern/draw_manager_testing.h"
#include "GPU_context.h"
#include "GPU_init_exit.h"
#include "GPU_shader.h"
#include "GHOST_C-api.h"
#include "engines/eevee/eevee_private.h"
#include "engines/gpencil/gpencil_engine.h"
#include "engines/overlay/overlay_private.h"
#include "engines/workbench/workbench_private.h"
/* Base class for draw test cases. It will setup and tear down the GPU part around each test. */
class DrawTest : public ::testing::Test {
private:
GHOST_SystemHandle ghost_system;
GHOST_ContextHandle ghost_context;
GPUContext *context;
void SetUp() override
{
ghost_system = GHOST_CreateSystem();
ghost_context = GHOST_CreateOpenGLContext(ghost_system);
context = GPU_context_create(0);
GPU_init();
DRW_draw_state_init_gtests(GPU_SHADER_CFG_DEFAULT);
}
void TearDown() override
{
GPU_exit();
GPU_context_discard(context);
GHOST_DisposeOpenGLContext(ghost_system, ghost_context);
GHOST_DisposeSystem(ghost_system);
}
};
TEST_F(DrawTest, workbench_glsl_shaders)
{
workbench_shader_library_ensure();
DRW_draw_state_init_gtests(GPU_SHADER_CFG_DEFAULT);
const int MAX_WPD = 6;
WORKBENCH_PrivateData wpds[MAX_WPD];
wpds[0].sh_cfg = GPU_SHADER_CFG_DEFAULT;
wpds[0].shading.light = V3D_LIGHTING_FLAT;
wpds[1].sh_cfg = GPU_SHADER_CFG_DEFAULT;
wpds[1].shading.light = V3D_LIGHTING_MATCAP;
wpds[2].sh_cfg = GPU_SHADER_CFG_DEFAULT;
wpds[2].shading.light = V3D_LIGHTING_STUDIO;
wpds[3].sh_cfg = GPU_SHADER_CFG_CLIPPED;
wpds[3].shading.light = V3D_LIGHTING_FLAT;
wpds[4].sh_cfg = GPU_SHADER_CFG_CLIPPED;
wpds[4].shading.light = V3D_LIGHTING_MATCAP;
wpds[5].sh_cfg = GPU_SHADER_CFG_CLIPPED;
wpds[5].shading.light = V3D_LIGHTING_STUDIO;
for (int wpd_index = 0; wpd_index < MAX_WPD; wpd_index++) {
WORKBENCH_PrivateData *wpd = &wpds[wpd_index];
EXPECT_NE(workbench_shader_opaque_get(wpd, WORKBENCH_DATATYPE_MESH), nullptr);
EXPECT_NE(workbench_shader_opaque_get(wpd, WORKBENCH_DATATYPE_HAIR), nullptr);
EXPECT_NE(workbench_shader_opaque_get(wpd, WORKBENCH_DATATYPE_POINTCLOUD), nullptr);
EXPECT_NE(workbench_shader_opaque_image_get(wpd, WORKBENCH_DATATYPE_MESH, false), nullptr);
EXPECT_NE(workbench_shader_opaque_image_get(wpd, WORKBENCH_DATATYPE_MESH, true), nullptr);
EXPECT_NE(workbench_shader_opaque_image_get(wpd, WORKBENCH_DATATYPE_HAIR, false), nullptr);
EXPECT_NE(workbench_shader_opaque_image_get(wpd, WORKBENCH_DATATYPE_HAIR, true), nullptr);
EXPECT_NE(workbench_shader_opaque_image_get(wpd, WORKBENCH_DATATYPE_POINTCLOUD, false),
nullptr);
EXPECT_NE(workbench_shader_opaque_image_get(wpd, WORKBENCH_DATATYPE_POINTCLOUD, true),
nullptr);
EXPECT_NE(workbench_shader_composite_get(wpd), nullptr);
EXPECT_NE(workbench_shader_merge_infront_get(wpd), nullptr);
EXPECT_NE(workbench_shader_transparent_get(wpd, WORKBENCH_DATATYPE_MESH), nullptr);
EXPECT_NE(workbench_shader_transparent_get(wpd, WORKBENCH_DATATYPE_HAIR), nullptr);
EXPECT_NE(workbench_shader_transparent_get(wpd, WORKBENCH_DATATYPE_POINTCLOUD), nullptr);
EXPECT_NE(workbench_shader_transparent_image_get(wpd, WORKBENCH_DATATYPE_MESH, false),
nullptr);
EXPECT_NE(workbench_shader_transparent_image_get(wpd, WORKBENCH_DATATYPE_MESH, true), nullptr);
EXPECT_NE(workbench_shader_transparent_image_get(wpd, WORKBENCH_DATATYPE_HAIR, false),
nullptr);
EXPECT_NE(workbench_shader_transparent_image_get(wpd, WORKBENCH_DATATYPE_HAIR, true), nullptr);
EXPECT_NE(workbench_shader_transparent_image_get(wpd, WORKBENCH_DATATYPE_POINTCLOUD, false),
nullptr);
EXPECT_NE(workbench_shader_transparent_image_get(wpd, WORKBENCH_DATATYPE_POINTCLOUD, true),
nullptr);
EXPECT_NE(workbench_shader_transparent_resolve_get(wpd), nullptr);
}
EXPECT_NE(workbench_shader_shadow_pass_get(false), nullptr);
EXPECT_NE(workbench_shader_shadow_pass_get(true), nullptr);
EXPECT_NE(workbench_shader_shadow_fail_get(false, false), nullptr);
EXPECT_NE(workbench_shader_shadow_fail_get(false, true), nullptr);
EXPECT_NE(workbench_shader_shadow_fail_get(true, false), nullptr);
EXPECT_NE(workbench_shader_shadow_fail_get(true, true), nullptr);
/* NOTE: workbench_shader_cavity_get(false, false) isn't a valid option. */
EXPECT_NE(workbench_shader_cavity_get(false, true), nullptr);
EXPECT_NE(workbench_shader_cavity_get(true, false), nullptr);
EXPECT_NE(workbench_shader_cavity_get(true, true), nullptr);
EXPECT_NE(workbench_shader_outline_get(), nullptr);
EXPECT_NE(workbench_shader_antialiasing_accumulation_get(), nullptr);
EXPECT_NE(workbench_shader_antialiasing_get(0), nullptr);
EXPECT_NE(workbench_shader_antialiasing_get(1), nullptr);
EXPECT_NE(workbench_shader_antialiasing_get(2), nullptr);
EXPECT_NE(workbench_shader_volume_get(false, false, false, false), nullptr);
EXPECT_NE(workbench_shader_volume_get(false, false, false, true), nullptr);
EXPECT_NE(workbench_shader_volume_get(false, false, true, false), nullptr);
EXPECT_NE(workbench_shader_volume_get(false, false, true, true), nullptr);
EXPECT_NE(workbench_shader_volume_get(false, true, false, false), nullptr);
EXPECT_NE(workbench_shader_volume_get(false, true, false, true), nullptr);
EXPECT_NE(workbench_shader_volume_get(false, true, true, false), nullptr);
EXPECT_NE(workbench_shader_volume_get(false, true, true, true), nullptr);
EXPECT_NE(workbench_shader_volume_get(true, false, false, false), nullptr);
EXPECT_NE(workbench_shader_volume_get(true, false, false, true), nullptr);
EXPECT_NE(workbench_shader_volume_get(true, false, true, false), nullptr);
EXPECT_NE(workbench_shader_volume_get(true, false, true, true), nullptr);
EXPECT_NE(workbench_shader_volume_get(true, true, false, false), nullptr);
EXPECT_NE(workbench_shader_volume_get(true, true, false, true), nullptr);
EXPECT_NE(workbench_shader_volume_get(true, true, true, false), nullptr);
EXPECT_NE(workbench_shader_volume_get(true, true, true, true), nullptr);
GPUShader *dof_prepare_sh;
GPUShader *dof_downsample_sh;
GPUShader *dof_blur1_sh;
GPUShader *dof_blur2_sh;
GPUShader *dof_resolve_sh;
workbench_shader_depth_of_field_get(
&dof_prepare_sh, &dof_downsample_sh, &dof_blur1_sh, &dof_blur2_sh, &dof_resolve_sh);
EXPECT_NE(dof_prepare_sh, nullptr);
EXPECT_NE(dof_downsample_sh, nullptr);
EXPECT_NE(dof_blur1_sh, nullptr);
EXPECT_NE(dof_blur2_sh, nullptr);
EXPECT_NE(dof_resolve_sh, nullptr);
workbench_shader_free();
}
TEST_F(DrawTest, gpencil_glsl_shaders)
{
EXPECT_NE(GPENCIL_shader_antialiasing(0), nullptr);
EXPECT_NE(GPENCIL_shader_antialiasing(1), nullptr);
EXPECT_NE(GPENCIL_shader_antialiasing(2), nullptr);
EXPECT_NE(GPENCIL_shader_geometry_get(), nullptr);
EXPECT_NE(GPENCIL_shader_layer_blend_get(), nullptr);
EXPECT_NE(GPENCIL_shader_mask_invert_get(), nullptr);
EXPECT_NE(GPENCIL_shader_depth_merge_get(), nullptr);
EXPECT_NE(GPENCIL_shader_fx_blur_get(), nullptr);
EXPECT_NE(GPENCIL_shader_fx_colorize_get(), nullptr);
EXPECT_NE(GPENCIL_shader_fx_composite_get(), nullptr);
EXPECT_NE(GPENCIL_shader_fx_transform_get(), nullptr);
EXPECT_NE(GPENCIL_shader_fx_glow_get(), nullptr);
EXPECT_NE(GPENCIL_shader_fx_pixelize_get(), nullptr);
EXPECT_NE(GPENCIL_shader_fx_rim_get(), nullptr);
EXPECT_NE(GPENCIL_shader_fx_shadow_get(), nullptr);
GPENCIL_shader_free();
}
TEST_F(DrawTest, overlay_glsl_shaders)
{
for (int i = 0; i < 2; i++) {
eGPUShaderConfig sh_cfg = i == 0 ? GPU_SHADER_CFG_DEFAULT : GPU_SHADER_CFG_CLIPPED;
DRW_draw_state_init_gtests(sh_cfg);
EXPECT_NE(OVERLAY_shader_antialiasing(), nullptr);
EXPECT_NE(OVERLAY_shader_armature_degrees_of_freedom_wire(), nullptr);
EXPECT_NE(OVERLAY_shader_armature_degrees_of_freedom_solid(), nullptr);
EXPECT_NE(OVERLAY_shader_armature_envelope(false), nullptr);
EXPECT_NE(OVERLAY_shader_armature_envelope(true), nullptr);
EXPECT_NE(OVERLAY_shader_armature_shape(false), nullptr);
EXPECT_NE(OVERLAY_shader_armature_shape(true), nullptr);
EXPECT_NE(OVERLAY_shader_armature_shape_wire(), nullptr);
EXPECT_NE(OVERLAY_shader_armature_sphere(false), nullptr);
EXPECT_NE(OVERLAY_shader_armature_sphere(true), nullptr);
EXPECT_NE(OVERLAY_shader_armature_stick(), nullptr);
EXPECT_NE(OVERLAY_shader_armature_wire(), nullptr);
EXPECT_NE(OVERLAY_shader_background(), nullptr);
EXPECT_NE(OVERLAY_shader_clipbound(), nullptr);
EXPECT_NE(OVERLAY_shader_depth_only(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_curve_handle(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_curve_point(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_curve_wire(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_gpencil_guide_point(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_gpencil_point(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_gpencil_wire(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_lattice_point(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_lattice_wire(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_mesh_analysis(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_mesh_edge(false), nullptr);
EXPECT_NE(OVERLAY_shader_edit_mesh_edge(true), nullptr);
EXPECT_NE(OVERLAY_shader_edit_mesh_face(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_mesh_facedot(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_mesh_normal(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_mesh_skin_root(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_mesh_vert(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_particle_strand(), nullptr);
EXPECT_NE(OVERLAY_shader_edit_particle_point(), nullptr);
EXPECT_NE(OVERLAY_shader_extra(false), nullptr);
EXPECT_NE(OVERLAY_shader_extra(true), nullptr);
EXPECT_NE(OVERLAY_shader_extra_groundline(), nullptr);
EXPECT_NE(OVERLAY_shader_extra_wire(false, false), nullptr);
EXPECT_NE(OVERLAY_shader_extra_wire(false, true), nullptr);
EXPECT_NE(OVERLAY_shader_extra_wire(true, false), nullptr);
EXPECT_NE(OVERLAY_shader_extra_wire(true, true), nullptr);
EXPECT_NE(OVERLAY_shader_extra_loose_point(), nullptr);
EXPECT_NE(OVERLAY_shader_extra_point(), nullptr);
EXPECT_NE(OVERLAY_shader_facing(), nullptr);
EXPECT_NE(OVERLAY_shader_gpencil_canvas(), nullptr);
EXPECT_NE(OVERLAY_shader_grid(), nullptr);
EXPECT_NE(OVERLAY_shader_image(), nullptr);
EXPECT_NE(OVERLAY_shader_motion_path_line(), nullptr);
EXPECT_NE(OVERLAY_shader_motion_path_vert(), nullptr);
EXPECT_NE(OVERLAY_shader_uniform_color(), nullptr);
EXPECT_NE(OVERLAY_shader_outline_prepass(false), nullptr);
EXPECT_NE(OVERLAY_shader_outline_prepass(true), nullptr);
EXPECT_NE(OVERLAY_shader_outline_prepass_gpencil(), nullptr);
EXPECT_NE(OVERLAY_shader_outline_prepass_pointcloud(), nullptr);
EXPECT_NE(OVERLAY_shader_extra_grid(), nullptr);
EXPECT_NE(OVERLAY_shader_outline_detect(), nullptr);
EXPECT_NE(OVERLAY_shader_paint_face(), nullptr);
EXPECT_NE(OVERLAY_shader_paint_point(), nullptr);
EXPECT_NE(OVERLAY_shader_paint_texture(), nullptr);
EXPECT_NE(OVERLAY_shader_paint_vertcol(), nullptr);
EXPECT_NE(OVERLAY_shader_paint_weight(), nullptr);
EXPECT_NE(OVERLAY_shader_paint_wire(), nullptr);
EXPECT_NE(OVERLAY_shader_particle_dot(), nullptr);
EXPECT_NE(OVERLAY_shader_particle_shape(), nullptr);
EXPECT_NE(OVERLAY_shader_sculpt_mask(), nullptr);
EXPECT_NE(OVERLAY_shader_volume_velocity(false), nullptr);
EXPECT_NE(OVERLAY_shader_volume_velocity(true), nullptr);
EXPECT_NE(OVERLAY_shader_wireframe(false), nullptr);
EXPECT_NE(OVERLAY_shader_wireframe(true), nullptr);
EXPECT_NE(OVERLAY_shader_wireframe_select(), nullptr);
EXPECT_NE(OVERLAY_shader_xray_fade(), nullptr);
}
OVERLAY_shader_free();
}
TEST_F(DrawTest, eevee_glsl_shaders_static)
{
EEVEE_shaders_lightprobe_shaders_init();
EEVEE_shaders_material_shaders_init();
EXPECT_NE(EEVEE_shaders_probe_filter_glossy_sh_get(), nullptr);
EXPECT_NE(EEVEE_shaders_probe_filter_diffuse_sh_get(), nullptr);
EXPECT_NE(EEVEE_shaders_probe_filter_visibility_sh_get(), nullptr);
EXPECT_NE(EEVEE_shaders_probe_grid_fill_sh_get(), nullptr);
EXPECT_NE(EEVEE_shaders_probe_planar_downsample_sh_get(), nullptr);
EXPECT_NE(EEVEE_shaders_studiolight_probe_sh_get(), nullptr);
EXPECT_NE(EEVEE_shaders_studiolight_background_sh_get(), nullptr);
EXPECT_NE(EEVEE_shaders_probe_cube_display_sh_get(), nullptr);
EXPECT_NE(EEVEE_shaders_probe_grid_display_sh_get(), nullptr);
EXPECT_NE(EEVEE_shaders_probe_planar_display_sh_get(), nullptr);
EXPECT_NE(EEVEE_shaders_update_noise_sh_get(), nullptr);
EXPECT_NE(EEVEE_shaders_velocity_resolve_sh_get(), nullptr);
EXPECT_NE(EEVEE_shaders_taa_resolve_sh_get(EFFECT_TAA), nullptr);
EXPECT_NE(EEVEE_shaders_taa_resolve_sh_get(EFFECT_TAA_REPROJECT), nullptr);
EEVEE_shaders_free();
}