[Bf-blender-cvs] [983f61e9c5e] tmp-vulkan: Add test case to compile builtin shaders.

Jeroen Bakker noreply at git.blender.org
Wed Jun 23 17:08:09 CEST 2021


Commit: 983f61e9c5ef68bb1fd4b456923ba69344b635f3
Author: Jeroen Bakker
Date:   Wed Jun 23 17:07:10 2021 +0200
Branches: tmp-vulkan
https://developer.blender.org/rB983f61e9c5ef68bb1fd4b456923ba69344b635f3

Add test case to compile builtin shaders.

When using the vulkan backend it crashes. Will look into this later this
week.

===================================================================

M	source/blender/gpu/CMakeLists.txt
A	source/blender/gpu/tests/gpu_shader_builtin_test.cc
M	source/blender/gpu/tests/gpu_shader_compiler_test.cc
M	source/blender/gpu/tests/gpu_testing.cc
M	source/blender/gpu/tests/gpu_testing.hh

===================================================================

diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 64c9daecbd2..fe957a9cb8e 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -435,6 +435,7 @@ if(WITH_GTESTS)
     set(TEST_SRC
       tests/gpu_testing.cc
       tests/gpu_shader_compiler_test.cc
+      tests/gpu_shader_builtin_test.cc
 
       tests/gpu_testing.hh
     )
diff --git a/source/blender/gpu/tests/gpu_shader_builtin_test.cc b/source/blender/gpu/tests/gpu_shader_builtin_test.cc
new file mode 100644
index 00000000000..183a9f0b327
--- /dev/null
+++ b/source/blender/gpu/tests/gpu_shader_builtin_test.cc
@@ -0,0 +1,31 @@
+/* Apache License, Version 2.0 */
+
+#include "gpu_testing.hh"
+
+#include "GPU_shader.h"
+
+namespace blender::gpu::tests {
+
+static void test_compile_builtin_shader(eGPUBuiltinShader shader_type, eGPUShaderConfig sh_cfg)
+{
+  GPUShader *sh = GPU_shader_get_builtin_shader_with_config(shader_type, sh_cfg);
+  EXPECT_NE(sh, nullptr);
+}
+
+TEST_F(GPUOpenGLTest, shader_builtin_opengl)
+{
+  GPU_shader_free_builtin_shaders();
+  test_compile_builtin_shader(GPU_SHADER_3D_DEPTH_ONLY, GPU_SHADER_CFG_DEFAULT);
+}
+
+#ifdef WITH_VULKAN
+
+TEST_F(GPUVulkanTest, shader_builtin_vulkan)
+{
+  GPU_shader_free_builtin_shaders();
+  test_compile_builtin_shader(GPU_SHADER_3D_DEPTH_ONLY, GPU_SHADER_CFG_DEFAULT);
+}
+
+#endif
+
+}  // namespace blender::gpu::tests
\ No newline at end of file
diff --git a/source/blender/gpu/tests/gpu_shader_compiler_test.cc b/source/blender/gpu/tests/gpu_shader_compiler_test.cc
index 4c0b8cb4d67..f247c17876a 100644
--- a/source/blender/gpu/tests/gpu_shader_compiler_test.cc
+++ b/source/blender/gpu/tests/gpu_shader_compiler_test.cc
@@ -6,7 +6,8 @@
 namespace blender::gpu::tests {
 
 #ifdef WITH_VULKAN
-TEST_F(GPUTest, shader_compiler)
+/* TODO(jbakker): GPUVulkanTest crashes. */
+TEST_F(GPUOpenGLTest, shader_compiler)
 {
   const char *source = "#version 450\nvoid main() {}";
   shader_compiler::Compiler *compiler = shader_compiler::Compiler::create_default();
diff --git a/source/blender/gpu/tests/gpu_testing.cc b/source/blender/gpu/tests/gpu_testing.cc
index 25436e517a3..49ff403f2e3 100644
--- a/source/blender/gpu/tests/gpu_testing.cc
+++ b/source/blender/gpu/tests/gpu_testing.cc
@@ -12,10 +12,10 @@ namespace blender::gpu {
 
 void GPUTest::SetUp()
 {
-  GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeOpenGL;
+
   GHOST_GLSettings glSettings = {0};
   ghost_system = GHOST_CreateSystem();
-  ghost_context = GHOST_CreateOpenGLContext(ghost_system, type, glSettings);
+  ghost_context = GHOST_CreateOpenGLContext(ghost_system, draw_context_type, glSettings);
   context = GPU_context_create(NULL, ghost_context);
   GPU_init();
 }
@@ -29,4 +29,18 @@ void GPUTest::TearDown()
   GHOST_DisposeSystem(ghost_system);
 }
 
+GPUOpenGLTest::GPUOpenGLTest()
+{
+  draw_context_type = GHOST_kDrawingContextTypeOpenGL;
+}
+
+#ifdef WITH_VULKAN
+
+GPUVulkanTest::GPUVulkanTest()
+{
+  draw_context_type = GHOST_kDrawingContextTypeVulkan;
+}
+
+#endif
+
 }  // namespace blender::gpu
diff --git a/source/blender/gpu/tests/gpu_testing.hh b/source/blender/gpu/tests/gpu_testing.hh
index cf902a91264..b6425bd4f49 100644
--- a/source/blender/gpu/tests/gpu_testing.hh
+++ b/source/blender/gpu/tests/gpu_testing.hh
@@ -20,8 +20,24 @@ class GPUTest : public ::testing::Test {
   struct GPUContext *context;
 
  protected:
+  GHOST_TDrawingContextType draw_context_type = GHOST_kDrawingContextTypeOpenGL;
+
   void SetUp() override;
   void TearDown() override;
 };
 
+class GPUOpenGLTest : public GPUTest {
+ public:
+  GPUOpenGLTest();
+};
+
+#ifdef WITH_VULKAN
+
+class GPUVulkanTest : public GPUTest {
+ public:
+  GPUVulkanTest();
+};
+
+#endif
+
 }  // namespace blender::gpu



More information about the Bf-blender-cvs mailing list