GPU: Remove shader builder
There is no need for this complexity anymore as we now have the shader unit tests. Pull Request: https://projects.blender.org/blender/blender/pulls/129014
This commit is contained in:
committed by
Clément Foucault
parent
20d09435ab
commit
46c452dfc3
@@ -871,14 +871,9 @@ endif()
|
||||
|
||||
|
||||
# GPU Module
|
||||
option(WITH_GPU_BUILDTIME_SHADER_BUILDER "\
|
||||
Shader builder is a developer option enabling linting on GLSL during compilation"
|
||||
OFF
|
||||
)
|
||||
option(WITH_RENDERDOC "Use Renderdoc API to capture frames" OFF)
|
||||
|
||||
mark_as_advanced(
|
||||
WITH_GPU_BUILDTIME_SHADER_BUILDER
|
||||
WITH_RENDERDOC
|
||||
)
|
||||
|
||||
|
||||
@@ -773,61 +773,6 @@ if(CXX_WARN_NO_SUGGEST_OVERRIDE)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
if(WITH_GPU_BUILDTIME_SHADER_BUILDER)
|
||||
set(_manifest)
|
||||
if(WIN32)
|
||||
# We can re-use the manifest from `tests.exe` here since it's
|
||||
# rather generic and just selects the appropriate common
|
||||
# controls version.
|
||||
set(_manifest "${CMAKE_BINARY_DIR}/tests.exe.manifest")
|
||||
endif()
|
||||
add_executable(shader_builder
|
||||
intern/gpu_shader_builder.cc
|
||||
intern/gpu_shader_builder_stubs.cc
|
||||
${_manifest}
|
||||
)
|
||||
unset(_manifest)
|
||||
setup_platform_linker_flags(shader_builder)
|
||||
|
||||
if(WITH_BUILD_INFO)
|
||||
target_link_libraries(shader_builder PRIVATE buildinfoobj)
|
||||
add_definitions(-DWITH_BUILD_INFO)
|
||||
endif()
|
||||
target_link_libraries(shader_builder PRIVATE
|
||||
bf_gpu
|
||||
bf_intern_clog
|
||||
bf_blenlib
|
||||
bf_intern_ghost
|
||||
${PLATFORM_LINKLIBS}
|
||||
PRIVATE bf::intern::guardedalloc
|
||||
)
|
||||
target_include_directories(shader_builder SYSTEM PRIVATE ${INC_SYS})
|
||||
target_include_directories(shader_builder PRIVATE ${INC} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set(SRC_BAKED_CREATE_INFOS_FILE ${CMAKE_CURRENT_BINARY_DIR}/shader_baked.hh)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
${SRC_BAKED_CREATE_INFOS_FILE}
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E env ${PLATFORM_ENV_BUILD}
|
||||
$<TARGET_FILE:shader_builder> ${SRC_BAKED_CREATE_INFOS_FILE}
|
||||
DEPENDS shader_builder
|
||||
)
|
||||
set(GPU_SHADER_INFO_SRC
|
||||
intern/gpu_shader_info_baked.cc
|
||||
${SRC_BAKED_CREATE_INFOS_FILE}
|
||||
|
||||
# For project files to be aware of these headers.
|
||||
${SRC_SHADER_CREATE_INFOS}
|
||||
shaders/infos/gpu_interface_info.hh
|
||||
)
|
||||
|
||||
blender_add_lib(bf_gpu_shader_infos "${GPU_SHADER_INFO_SRC}" "" "" "")
|
||||
endif()
|
||||
|
||||
|
||||
if(WITH_GTESTS)
|
||||
set(TEST_SRC)
|
||||
set(TEST_INC)
|
||||
|
||||
@@ -1,219 +0,0 @@
|
||||
/* SPDX-FileCopyrightText: 2021 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup gpu
|
||||
*
|
||||
* Compile time automation of shader compilation and validation.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "GHOST_C-api.h"
|
||||
|
||||
#include "GPU_context.hh"
|
||||
#include "GPU_init_exit.hh"
|
||||
#include "gpu_shader_create_info_private.hh"
|
||||
|
||||
#include "BLI_string_ref.hh"
|
||||
#include "BLI_vector.hh"
|
||||
|
||||
#include "CLG_log.h"
|
||||
|
||||
namespace blender::gpu::shader_builder {
|
||||
|
||||
class ShaderBuilder {
|
||||
private:
|
||||
GHOST_SystemHandle ghost_system_;
|
||||
GHOST_ContextHandle ghost_context_ = nullptr;
|
||||
GPUContext *gpu_context_ = nullptr;
|
||||
|
||||
public:
|
||||
void init_system();
|
||||
bool init_context();
|
||||
bool bake_create_infos(const char *name_starts_with_filter);
|
||||
void exit_context();
|
||||
void exit_system();
|
||||
};
|
||||
|
||||
bool ShaderBuilder::bake_create_infos(const char *name_starts_with_filter)
|
||||
{
|
||||
return gpu_shader_create_info_compile(name_starts_with_filter);
|
||||
}
|
||||
|
||||
void ShaderBuilder::init_system()
|
||||
{
|
||||
CLG_init();
|
||||
ghost_system_ = GHOST_CreateSystemBackground();
|
||||
GPU_backend_ghost_system_set(ghost_system_);
|
||||
}
|
||||
|
||||
bool ShaderBuilder::init_context()
|
||||
{
|
||||
BLI_assert(ghost_system_);
|
||||
BLI_assert(ghost_context_ == nullptr);
|
||||
BLI_assert(gpu_context_ == nullptr);
|
||||
|
||||
GHOST_GPUSettings gpuSettings = {0};
|
||||
switch (GPU_backend_type_selection_get()) {
|
||||
#ifdef WITH_OPENGL_BACKEND
|
||||
case GPU_BACKEND_OPENGL:
|
||||
gpuSettings.context_type = GHOST_kDrawingContextTypeOpenGL;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef WITH_METAL_BACKEND
|
||||
case GPU_BACKEND_METAL:
|
||||
gpuSettings.context_type = GHOST_kDrawingContextTypeMetal;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef WITH_VULKAN_BACKEND
|
||||
case GPU_BACKEND_VULKAN:
|
||||
gpuSettings.context_type = GHOST_kDrawingContextTypeVulkan;
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
break;
|
||||
}
|
||||
|
||||
ghost_context_ = GHOST_CreateGPUContext(ghost_system_, gpuSettings);
|
||||
if (ghost_context_ == nullptr) {
|
||||
GHOST_DisposeSystem(ghost_system_);
|
||||
return false;
|
||||
}
|
||||
|
||||
GHOST_ActivateGPUContext(ghost_context_);
|
||||
|
||||
gpu_context_ = GPU_context_create(nullptr, ghost_context_);
|
||||
GPU_init();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ShaderBuilder::exit_context()
|
||||
{
|
||||
BLI_assert(ghost_context_);
|
||||
BLI_assert(gpu_context_);
|
||||
GPU_exit();
|
||||
GPU_context_discard(gpu_context_);
|
||||
GHOST_DisposeGPUContext(ghost_system_, ghost_context_);
|
||||
gpu_context_ = nullptr;
|
||||
ghost_context_ = nullptr;
|
||||
}
|
||||
|
||||
void ShaderBuilder::exit_system()
|
||||
{
|
||||
GHOST_DisposeSystem(ghost_system_);
|
||||
CLG_exit();
|
||||
}
|
||||
|
||||
} // namespace blender::gpu::shader_builder
|
||||
|
||||
/** \brief Entry point for the shader_builder. */
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
std::string gpu_backend_arg;
|
||||
std::string shader_name_starts_with_filter_arg;
|
||||
std::string result_file_arg;
|
||||
|
||||
int arg = 1;
|
||||
while (arg < argc) {
|
||||
if (arg < argc - 2) {
|
||||
blender::StringRefNull argument = argv[arg];
|
||||
if (argument == "--gpu-backend") {
|
||||
gpu_backend_arg = std::string(argv[arg + 1]);
|
||||
arg += 2;
|
||||
}
|
||||
else if (argument == "--gpu-shader-filter") {
|
||||
shader_name_starts_with_filter_arg = std::string(argv[arg + 1]);
|
||||
arg += 2;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (arg == argc - 1) {
|
||||
result_file_arg = argv[arg];
|
||||
arg += 1;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (result_file_arg.empty() || (!ELEM(gpu_backend_arg, "", "vulkan", "metal", "opengl"))) {
|
||||
std::cout << "Usage: " << argv[0];
|
||||
std::cout << " [--gpu-backend ";
|
||||
#ifdef WITH_METAL_BACKEND
|
||||
std::cout << "metal";
|
||||
#endif
|
||||
#ifdef WITH_OPENGL_BACKEND
|
||||
std::cout << "opengl";
|
||||
#endif
|
||||
#ifdef WITH_VULKAN_BACKEND
|
||||
std::cout << ",vulkan";
|
||||
#endif
|
||||
std::cout << "]";
|
||||
std::cout << " [--gpu-shader-filter <shader-name>]";
|
||||
std::cout << " <data_file_out>\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int exit_code = 0;
|
||||
|
||||
blender::gpu::shader_builder::ShaderBuilder builder;
|
||||
builder.init_system();
|
||||
|
||||
struct NamedBackend {
|
||||
std::string name;
|
||||
eGPUBackendType backend;
|
||||
};
|
||||
|
||||
blender::Vector<NamedBackend> backends_to_validate;
|
||||
#ifdef WITH_OPENGL_BACKEND
|
||||
if (ELEM(gpu_backend_arg, "", "opengl")) {
|
||||
backends_to_validate.append({"OpenGL", GPU_BACKEND_OPENGL});
|
||||
}
|
||||
#endif
|
||||
#ifdef WITH_METAL_BACKEND
|
||||
if (ELEM(gpu_backend_arg, "", "metal")) {
|
||||
backends_to_validate.append({"Metal", GPU_BACKEND_METAL});
|
||||
}
|
||||
#endif
|
||||
#ifdef WITH_VULKAN_BACKEND
|
||||
if (ELEM(gpu_backend_arg, "", "vulkan")) {
|
||||
backends_to_validate.append({"Vulkan", GPU_BACKEND_VULKAN});
|
||||
}
|
||||
#endif
|
||||
|
||||
for (NamedBackend &backend : backends_to_validate) {
|
||||
GPU_backend_type_selection_set(backend.backend);
|
||||
if (!GPU_backend_supported()) {
|
||||
printf("%s isn't supported on this platform. Shader compilation is skipped\n",
|
||||
backend.name.c_str());
|
||||
continue;
|
||||
}
|
||||
if (builder.init_context()) {
|
||||
if (!builder.bake_create_infos(shader_name_starts_with_filter_arg.c_str())) {
|
||||
printf("Shader compilation failed for %s backend\n", backend.name.c_str());
|
||||
exit_code = 1;
|
||||
}
|
||||
else {
|
||||
printf("%s backend shader compilation succeeded.\n", backend.name.c_str());
|
||||
}
|
||||
builder.exit_context();
|
||||
}
|
||||
else {
|
||||
printf("Shader compilation skipped for %s backend. Context could not be created.\n",
|
||||
backend.name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
builder.exit_system();
|
||||
|
||||
exit(exit_code);
|
||||
return exit_code;
|
||||
}
|
||||
@@ -1,239 +0,0 @@
|
||||
/* SPDX-FileCopyrightText: 2021 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup gpu
|
||||
*
|
||||
* Stubs to reduce linking time for shader_builder.
|
||||
*/
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "IMB_imbuf.hh"
|
||||
#include "IMB_imbuf_types.hh"
|
||||
|
||||
#include "BKE_appdir.hh"
|
||||
#include "BKE_attribute.hh"
|
||||
#include "BKE_customdata.hh"
|
||||
#include "BKE_global.hh"
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_mesh.hh"
|
||||
#include "BKE_node.hh"
|
||||
#include "BKE_paint.hh"
|
||||
#include "BKE_pbvh_api.hh"
|
||||
#include "BKE_subdiv_ccg.hh"
|
||||
|
||||
#include "DNA_userdef_types.h"
|
||||
|
||||
#include "NOD_shader.h"
|
||||
|
||||
#include "DRW_engine.hh"
|
||||
|
||||
#include "bmesh.hh"
|
||||
|
||||
#include "UI_resources.hh"
|
||||
|
||||
Global G;
|
||||
UserDef U;
|
||||
|
||||
char build_hash[16] = {'\0'};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Stubs of BLI_imbuf_types.h
|
||||
* \{ */
|
||||
|
||||
void IMB_freeImBuf(ImBuf * /*ibuf*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
struct ImBuf *IMB_allocImBuf(unsigned int /*x*/,
|
||||
unsigned int /*y*/,
|
||||
unsigned char /*planes*/,
|
||||
unsigned int /*flags*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Stubs of BLI_appdir.h
|
||||
* \{ */
|
||||
|
||||
bool BKE_appdir_folder_caches(char * /*path*/, size_t /*path_maxncpy*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Stubs of UI_resources.hh
|
||||
* \{ */
|
||||
|
||||
void UI_GetThemeColor4fv(int /*colorid*/, float[4] /*col*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
void UI_GetThemeColor3fv(int /*colorid*/, float[3] /*col*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
void UI_GetThemeColorShade4fv(int /*colorid*/, int /*offset*/, float[4] /*col*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
void UI_GetThemeColorShadeAlpha4fv(int /*colorid*/,
|
||||
int /*coloffset*/,
|
||||
int /*alphaoffset*/,
|
||||
float[4] /*col*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
void UI_GetThemeColorBlendShade4fv(
|
||||
int /*colorid1*/, int /*colorid2*/, float /*fac*/, int /*offset*/, float[4] /*col*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
void UI_GetThemeColorBlend3ubv(int /*colorid1*/, int /*colorid2*/, float /*fac*/, uchar[3] /*col*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
void UI_GetThemeColorShadeAlpha4ubv(int /*colorid*/,
|
||||
int /*coloffset*/,
|
||||
int /*alphaoffset*/,
|
||||
uchar[4] /*col*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Stubs of BKE_paint.hh
|
||||
* \{ */
|
||||
|
||||
void BKE_paint_face_set_overlay_color_get(const int /*face_set*/,
|
||||
const int /*seed*/,
|
||||
uchar[4] /*col*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Stubs of BKE_mesh.h
|
||||
* \{ */
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Stubs of BKE_material.h
|
||||
* \{ */
|
||||
|
||||
extern "C" void BKE_material_defaults_free_gpu()
|
||||
{
|
||||
/* This function is reachable via GPU_exit. */
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Stubs of BKE_customdata.hh
|
||||
* \{ */
|
||||
|
||||
int CustomData_get_offset(const struct CustomData * /*data*/, eCustomDataType /*type*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CustomData_get_active_layer_index(const struct CustomData * /*data*/, eCustomDataType /*type*/)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CustomData_get_render_layer_index(const struct CustomData * /*data*/, eCustomDataType /*type*/)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool CustomData_has_layer(const struct CustomData * /*data*/, eCustomDataType /*type*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Stubs of BKE_node.h
|
||||
* \{ */
|
||||
extern "C" void ntreeGPUMaterialNodes(struct bNodeTree * /*localtree*/,
|
||||
struct GPUMaterial * /*mat*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
struct bNodeTree *blender::bke::node_tree_localize(struct bNodeTree * /*ntree*/,
|
||||
ID * /*new_owner_id*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void blender::bke::node_tree_free_local_tree(struct bNodeTree * /*ntree*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Stubs of DRW_engine.hh
|
||||
* \{ */
|
||||
extern void DRW_deferred_shader_remove(struct GPUMaterial * /*mat*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Stubs of IMB_imbuf.hh
|
||||
* \{ */
|
||||
struct ImBuf *IMB_ibImageFromMemory(const unsigned char * /*mem*/,
|
||||
size_t /*size*/,
|
||||
int /*flags*/,
|
||||
char /*colorspace*/[IM_MAX_SPACE],
|
||||
const char * /*descr*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
struct ImBuf *IMB_allocFromBuffer(const uint8_t * /*rect*/,
|
||||
const float * /*rectf*/,
|
||||
unsigned int /*w*/,
|
||||
unsigned int /*h*/,
|
||||
unsigned int /*channels*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool IMB_saveiff(struct ImBuf * /*ibuf*/, const char * /*filepath*/, int /*flags*/)
|
||||
{
|
||||
BLI_assert_unreachable();
|
||||
return false;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
@@ -476,13 +476,6 @@ void gpu_shader_create_info_init()
|
||||
/* Declare, register and construct the infos. */
|
||||
#include "gpu_shader_create_info_list.hh"
|
||||
|
||||
/* Baked shader data appended to create infos. */
|
||||
/* TODO(jbakker): should call a function with a callback. so we could switch implementations.
|
||||
* We cannot compile bf_gpu twice. */
|
||||
#ifdef GPU_RUNTIME
|
||||
# include "gpu_shader_baked.hh"
|
||||
#endif
|
||||
|
||||
/* WORKAROUND: Replace draw_mesh info with the legacy one for systems that have problems with UBO
|
||||
* indexing. */
|
||||
if (GPU_type_matches_ex(GPU_DEVICE_INTEL | GPU_DEVICE_INTEL_UHD,
|
||||
|
||||
Reference in New Issue
Block a user