[Bf-blender-cvs] [0bf4c5d5327] tmp-gpu-shader-descriptor-2: Compilation of shader_builder.
Jeroen Bakker
noreply at git.blender.org
Wed Jan 5 12:22:30 CET 2022
Commit: 0bf4c5d5327ae6a34f38177de67882866f86488b
Author: Jeroen Bakker
Date: Wed Jan 5 12:18:47 2022 +0100
Branches: tmp-gpu-shader-descriptor-2
https://developer.blender.org/rB0bf4c5d5327ae6a34f38177de67882866f86488b
Compilation of shader_builder.
Shader builder can be used to compile the shader structs at compile
time. This can be activated by enabling the WITH_GPU_SHADER_BUILDER
option.
For compilation we added a lot of stubs as we don't require a full
blender this increases the turn around time when compiling shaders.
Note that we should see if we could split bf_gpu to reduce the amount
of stubs. Or use callback functions reduce the dependencies.
===================================================================
M CMakeLists.txt
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/intern/gpu_shader_builder.cc
A source/blender/gpu/intern/gpu_shader_builder.hh
A source/blender/gpu/intern/gpu_shader_builder_main.cc
A source/blender/gpu/intern/gpu_shader_builder_stubs.hh
M source/blender/gpu/intern/gpu_shader_create_info.cc
A source/blender/gpu/intern/gpu_shader_info_baked.cc
A source/blender/gpu/intern/gpu_shader_info_baked.hh
A source/blender/gpu/intern/gpu_shader_info_baked_stub.cc
===================================================================
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5c5b5eb317e..07ab703a132 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -536,12 +536,14 @@ option(WITH_OPENGL "When off limits visibility of the opengl header
option(WITH_GLEW_ES "Switches to experimental copy of GLEW that has support for OpenGL ES. (temporary option for development purposes)" OFF)
option(WITH_GL_EGL "Use the EGL OpenGL system library instead of the platform specific OpenGL system library (CGL, glX, or WGL)" OFF)
option(WITH_GL_PROFILE_ES20 "Support using OpenGL ES 2.0. (through either EGL or the AGL/WGL/XGL 'es20' profile)" OFF)
+option(WITH_GPU_SHADER_BUILDER "Shader builder is a developer option enabling linting on GLSL during compilation" OFF)
mark_as_advanced(
WITH_OPENGL
WITH_GLEW_ES
WITH_GL_EGL
WITH_GL_PROFILE_ES20
+ WITH_GPU_SHADER_BUILDER
)
if(WIN32)
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index c664786da2b..8106116df4b 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -410,50 +410,23 @@ list(APPEND SRC ${glsl_source_list_file})
list(APPEND INC ${CMAKE_CURRENT_BINARY_DIR})
set(SHADER_CREATE_INFOS
- ../draw/engines/workbench/shaders/workbench_effect_cavity_info.hh
- ../draw/engines/workbench/shaders/workbench_prepass_info.hh
- ../draw/intern/shaders/draw_fullscreen_info.hh
- ../draw/intern/shaders/draw_view_info.hh
- ../draw/intern/shaders/draw_object_infos_info.hh
- shaders/gpu_shader_3D_flat_color_info.hh
- shaders/gpu_clip_planes_info.hh
+../draw/engines/workbench/shaders/workbench_effect_cavity_info.hh
+../draw/engines/workbench/shaders/workbench_prepass_info.hh
+../draw/intern/shaders/draw_fullscreen_info.hh
+../draw/intern/shaders/draw_view_info.hh
+../draw/intern/shaders/draw_object_infos_info.hh
+shaders/gpu_shader_3D_flat_color_info.hh
+shaders/gpu_clip_planes_info.hh
)
set(SHADER_CREATE_INFOS_CONTENT "")
foreach(DESCRIPTOR_FILE ${SHADER_CREATE_INFOS})
- string(APPEND SHADER_CREATE_INFOS_CONTENT "#include \"${DESCRIPTOR_FILE}\"\n")
+string(APPEND SHADER_CREATE_INFOS_CONTENT "#include \"${DESCRIPTOR_FILE}\"\n")
endforeach()
set(shader_create_info_list_file "${CMAKE_CURRENT_BINARY_DIR}/gpu_shader_create_info_list.hh")
file(GENERATE OUTPUT ${shader_create_info_list_file} CONTENT "${SHADER_CREATE_INFOS_CONTENT}")
-# add_executable(shader_builder
-# intern/gpu_shader_builder.cc
-# intern/gpu_shader_create_info.cc
-# intern/gpu_shader_dependency.cc
-# ${shader_create_info_list_file}
-# )
-# target_link_libraries(shader_builder PRIVATE
-# bf_intern_guardedalloc
-# bf_blenlib
-# bf_gpu_shaders
-# bf_draw_shaders
-# ${PLATFORM_LINKLIBS})
-# target_include_directories(shader_builder PRIVATE ${INC} ${CMAKE_CURRENT_BINARY_DIR})
-
-# set(BAKED_CREATE_INFOS_FILE ${CMAKE_CURRENT_BINARY_DIR}/shader_baked.hh)
-
-# add_custom_command(
-# OUTPUT
-# ${BAKED_CREATE_INFOS_FILE}
-# COMMAND
-# "$<TARGET_FILE:shader_builder>" ${BAKED_CREATE_INFOS_FILE}
-# DEPENDS shader_builder
-# )
-
-# list(APPEND SRC ${BAKED_CREATE_INFOS_FILE})
-
-
if(WITH_MOD_FLUID)
add_definitions(-DWITH_FLUID)
endif()
@@ -474,6 +447,50 @@ if(CXX_WARN_NO_SUGGEST_OVERRIDE)
target_compile_options(bf_gpu PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Wsuggest-override>)
endif()
+
+set(GPU_SHADER_INFO_SRC
+ intern/gpu_shader_info_baked.cc
+)
+
+if(WITH_GPU_SHADER_BUILDER)
+ set(GPU_SHADER_BUILDER_SRC
+ intern/gpu_shader_builder.cc
+ intern/gpu_shader_info_baked_stub.cc
+ ${shader_create_info_list_file}
+ )
+
+ add_library(bf_gpu_shader_builder "${GPU_SHADER_BUILDER_SRC}")
+
+ add_executable(shader_builder
+ intern/gpu_shader_builder_main.cc
+ )
+
+ target_link_libraries(shader_builder PUBLIC
+ ${PLATFORM_LINKLIBS}
+ bf_gpu
+ bf_blenlib
+ bf_blenkernel
+ bf_gpu_shader_builder
+ bf_intern_clog
+ )
+ target_include_directories(shader_builder PRIVATE ${INC} ${CMAKE_CURRENT_BINARY_DIR})
+
+ set(BAKED_CREATE_INFOS_FILE ${CMAKE_CURRENT_BINARY_DIR}/shader_baked.hh)
+
+ add_custom_command(
+ OUTPUT
+ ${BAKED_CREATE_INFOS_FILE}
+ COMMAND
+ "$<TARGET_FILE:shader_builder>" ${BAKED_CREATE_INFOS_FILE}
+ DEPENDS shader_builder
+ )
+
+ list(APPEND GPU_SHADER_INFO_SRC ${BAKED_CREATE_INFOS_FILE})
+endif()
+
+blender_add_lib(bf_gpu_shader_infos "${GPU_SHADER_INFO_SRC}" "" "" "")
+#add_dependencies(blender bf_gpu_shader_infos)
+
if(WITH_GTESTS)
if(WITH_OPENGL_DRAW_TESTS)
set(TEST_SRC
diff --git a/source/blender/gpu/intern/gpu_shader_builder.cc b/source/blender/gpu/intern/gpu_shader_builder.cc
index 02aa5a0ca63..d81f9a48ede 100644
--- a/source/blender/gpu/intern/gpu_shader_builder.cc
+++ b/source/blender/gpu/intern/gpu_shader_builder.cc
@@ -25,18 +25,33 @@
#include <iostream>
-#include "gpu_shader_create_info.hh"
-#include "gpu_shader_create_info_private.hh"
-#include "gpu_shader_dependency_private.h"
+#include "gpu_shader_builder.hh"
+
+#include "GHOST_C-api.h"
-#include "CLG_log.h"
#include "GPU_context.h"
#include "GPU_init_exit.h"
+#include "gpu_shader_create_info_private.hh"
-#include "GHOST_C-api.h"
+#include "CLG_log.h"
+
+namespace blender::gpu::shader_builder {
-int main(int argc, char const *argv[])
+class ShaderBuilder {
+ private:
+ GHOST_SystemHandle ghost_system_;
+ GHOST_ContextHandle ghost_context_;
+ GPUContext *gpu_context_ = nullptr;
+
+ public:
+ void init();
+ void bake_create_infos();
+ void exit();
+};
+
+int main(int argc, const char *argv[])
{
+ printf("shader-builder started\n");
if (argc < 2) {
printf("Usage: shader_builder <data_file_to>\n");
exit(1);
@@ -44,22 +59,43 @@ int main(int argc, char const *argv[])
(void)argv;
-#if 0 /* Make it compile. Somehow... (dependency with GPU module is hard). */
- GHOST_GLSettings glSettings = {0};
- GHOST_SystemHandle ghost_system = GHOST_CreateSystem();
- GHOST_ContextHandle ghost_context = GHOST_CreateOpenGLContext(ghost_system, glSettings);
- GHOST_ActivateOpenGLContext(ghost_context);
- struct GPUContext *context = GPU_context_create(nullptr);
- GPU_init();
+ ShaderBuilder builder;
+ builder.init();
+ builder.bake_create_infos();
+ builder.exit();
+ return 0;
+}
+
+void ShaderBuilder::bake_create_infos()
+{
gpu_shader_create_info_compile_all();
+}
- GPU_exit();
+void ShaderBuilder::init()
+{
+ CLG_init();
+
+ GHOST_GLSettings glSettings = {0};
+ ghost_system_ = GHOST_CreateSystem();
+ ghost_context_ = GHOST_CreateOpenGLContext(ghost_system_, glSettings);
+ GHOST_ActivateOpenGLContext(ghost_context_);
+
+ gpu_context_ = GPU_context_create(nullptr);
+ GPU_init();
+}
+
+void ShaderBuilder::exit()
+{
GPU_backend_exit();
- GPU_context_discard(context);
- GHOST_DisposeOpenGLContext(ghost_system, ghost_context);
- GHOST_DisposeSystem(ghost_system);
-#endif
+ GPU_exit();
- return 0;
+ GPU_context_discard(gpu_context_);
+
+ GHOST_DisposeOpenGLContext(ghost_system_, ghost_context_);
+ GHOST_DisposeSystem(ghost_system_);
+
+ CLG_exit();
}
+
+} // namespace blender::gpu::shader_builder
diff --git a/source/blender/gpu/intern/gpu_shader_builder.hh b/source/blender/gpu/intern/gpu_shader_builder.hh
new file mode 100644
index 00000000000..b6e5b7502e7
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_shader_builder.hh
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ *
+ * The Original Code is Copyright (C) 2021 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup gpu
+ *
+ * Compile time automation of shader compilation and validation.
+ */
+
+#pragma once
+
+namespace blender::gpu::shader_builder {
+
+/** \brief Entry point for the shader_builder executable. */
+int main(int argc, const char *argv[]);
+
+} // namespace blender::gpu::shader_builder
\ No newline at end of file
diff --git a/source/blender/gpu/intern/gpu_shader_builder_main.cc b/source/blender/gpu/intern/gpu_shader_builder_main.cc
new file mode 100644
index 00000000000..f7ce43ffd52
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_shader_builder_main.cc
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ *
+ * The Original Code is Copyright (C) 2021 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup gpu
+ *
+ * Entry point of the shader_builder executable.
+ */
+#include <cstdio>
+#include <cstdlib>
+
+#include "gpu_shader_builder.hh"
+#include "gpu_shader_builder_stubs.hh"
+
+int main(int argc, char const *argv[])
+{
+ return blender::gpu::shader_builder::main(argc, argv);
+}
diff --git a/source/blender/gpu/intern/gpu_shader_builder_stubs.hh b/source/blender/gpu/intern/gpu_shader_builder_stubs.hh
new file mode 100644
index 00000000000..d3ef1291ecf
--- /dev/null
+++ b/source/blender/
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list