diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-01-26 14:46:37 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-01-26 14:46:37 +0300 |
commit | 5b299e5999e2b59e30edd4e770f64aa700e482d6 (patch) | |
tree | 17052358b339e20c44ca942e62b735ef63b23f88 /source/blender/gpu | |
parent | 9bce134e56c28045aee37080f5c5b6622a07927b (diff) |
D13910: Workbench: Port shaders to use GPUShaderCreateInfo
Also adds a few things to GPUShader for easily create shaders.
Heavy usage of macros to compose the createInfo and avoid
duplications and copy paste bugs.
This makes the link between the shader request functions
(in workbench_shader.cc) and the actual createInfo a bit
obscure since the names are composed and not searchable.
Reviewed By: jbakker
Differential Revision: https://developer.blender.org/D13910
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/CMakeLists.txt | 12 | ||||
-rw-r--r-- | source/blender/gpu/GPU_shader.h | 5 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_create_info.cc | 36 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_create_info.hh | 10 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_interface.hh | 9 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_shader.cc | 6 |
6 files changed, 69 insertions, 9 deletions
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 5be4352cffd..c898392dc7e 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -402,8 +402,16 @@ 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/engines/workbench/shaders/infos/workbench_composite_info.hh +../draw/engines/workbench/shaders/infos/workbench_effect_antialiasing_info.hh +../draw/engines/workbench/shaders/infos/workbench_effect_cavity_info.hh +../draw/engines/workbench/shaders/infos/workbench_effect_dof_info.hh +../draw/engines/workbench/shaders/infos/workbench_effect_outline_info.hh +../draw/engines/workbench/shaders/infos/workbench_merge_infront_info.hh +../draw/engines/workbench/shaders/infos/workbench_prepass_info.hh +../draw/engines/workbench/shaders/infos/workbench_shadow_info.hh +../draw/engines/workbench/shaders/infos/workbench_transparent_resolve_info.hh +../draw/engines/workbench/shaders/infos/workbench_volume_info.hh ../draw/intern/shaders/draw_fullscreen_info.hh ../draw/intern/shaders/draw_object_infos_info.hh ../draw/intern/shaders/draw_view_info.hh diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index d2716b46124..972758febd4 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -149,9 +149,14 @@ typedef enum { } GPUUniformBuiltin; typedef enum { + /** Deprecated */ GPU_UNIFORM_BLOCK_VIEW = 0, /* viewBlock */ GPU_UNIFORM_BLOCK_MODEL, /* modelBlock */ GPU_UNIFORM_BLOCK_INFO, /* infoBlock */ + /** New ones */ + GPU_UNIFORM_BLOCK_DRW_VIEW, + GPU_UNIFORM_BLOCK_DRW_MODEL, + GPU_UNIFORM_BLOCK_DRW_INFOS, GPU_NUM_UNIFORM_BLOCKS, /* Special value, denotes number of builtin uniforms block. */ } GPUUniformBlockBuiltin; diff --git a/source/blender/gpu/intern/gpu_shader_create_info.cc b/source/blender/gpu/intern/gpu_shader_create_info.cc index 66536133795..f7622751726 100644 --- a/source/blender/gpu/intern/gpu_shader_create_info.cc +++ b/source/blender/gpu/intern/gpu_shader_create_info.cc @@ -27,6 +27,8 @@ #include "BLI_set.hh" #include "BLI_string_ref.hh" +#include "GPU_capabilities.h" +#include "GPU_platform.h" #include "GPU_shader.h" #include "GPU_texture.h" @@ -58,6 +60,11 @@ void ShaderCreateInfo::finalize() /* Recursive. */ const_cast<ShaderCreateInfo &>(info).finalize(); +#if 0 /* Enabled for debugging merging. TODO(fclem) exception handling and error reporting in \ + console. */ + std::cout << "Merging : " << info_name << " > " << name_ << std::endl; +#endif + interface_names_size_ += info.interface_names_size_; vertex_inputs_.extend(info.vertex_inputs_); @@ -70,7 +77,7 @@ void ShaderCreateInfo::finalize() batch_resources_.extend(info.batch_resources_); pass_resources_.extend(info.pass_resources_); - typedef_sources_.extend(info.typedef_sources_); + typedef_sources_.extend_non_duplicates(info.typedef_sources_); validate(info); @@ -194,6 +201,13 @@ void gpu_shader_create_info_init() # 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(GPU_DEVICE_INTEL | GPU_DEVICE_INTEL_UHD, GPU_OS_ANY, GPU_DRIVER_ANY) || + GPU_type_matches(GPU_DEVICE_ANY, GPU_OS_MAC, GPU_DRIVER_ANY) || GPU_crappy_amd_driver()) { + draw_modelmat = draw_modelmat_legacy; + } + /* TEST */ // gpu_shader_create_info_compile_all(); } @@ -213,25 +227,37 @@ void gpu_shader_create_info_exit() bool gpu_shader_create_info_compile_all() { + int success = 0; + int total = 0; for (ShaderCreateInfo *info : g_create_infos->values()) { if (info->do_static_compilation_) { - // printf("Compiling %s: ... \n", info->name_.c_str()); + total++; GPUShader *shader = GPU_shader_create_from_info( reinterpret_cast<const GPUShaderCreateInfo *>(info)); if (shader == nullptr) { printf("Compilation %s Failed\n", info->name_.c_str()); - return false; + } + else { + success++; } GPU_shader_free(shader); - // printf("Success\n"); } } - return true; + printf("===============================\n"); + printf("Shader Test compilation result: \n"); + printf("%d Total\n", total); + printf("%d Passed\n", success); + printf("%d Failed\n", total - success); + printf("===============================\n"); + return success == total; } /* Runtime create infos are not registered in the dictionary and cannot be searched. */ const GPUShaderCreateInfo *gpu_shader_create_info_get(const char *info_name) { + if (g_create_infos->contains(info_name) == false) { + printf("Error: Cannot find shader create info named \"%s\"\n", info_name); + } ShaderCreateInfo *info = g_create_infos->lookup(info_name); return reinterpret_cast<const GPUShaderCreateInfo *>(info); } diff --git a/source/blender/gpu/intern/gpu_shader_create_info.hh b/source/blender/gpu/intern/gpu_shader_create_info.hh index f8149bc7be0..6236e92a226 100644 --- a/source/blender/gpu/intern/gpu_shader_create_info.hh +++ b/source/blender/gpu/intern/gpu_shader_create_info.hh @@ -559,7 +559,9 @@ struct ShaderCreateInfo { StringRefNull info_name1 = "", StringRefNull info_name2 = "", StringRefNull info_name3 = "", - StringRefNull info_name4 = "") + StringRefNull info_name4 = "", + StringRefNull info_name5 = "", + StringRefNull info_name6 = "") { additional_infos_.append(info_name0); if (!info_name1.is_empty()) { @@ -574,6 +576,12 @@ struct ShaderCreateInfo { if (!info_name4.is_empty()) { additional_infos_.append(info_name4); } + if (!info_name5.is_empty()) { + additional_infos_.append(info_name5); + } + if (!info_name6.is_empty()) { + additional_infos_.append(info_name6); + } return *(Self *)this; } diff --git a/source/blender/gpu/intern/gpu_shader_interface.hh b/source/blender/gpu/intern/gpu_shader_interface.hh index 735b8fea71d..44dadec7b84 100644 --- a/source/blender/gpu/intern/gpu_shader_interface.hh +++ b/source/blender/gpu/intern/gpu_shader_interface.hh @@ -189,7 +189,7 @@ inline const char *ShaderInterface::builtin_uniform_name(GPUUniformBuiltin u) case GPU_UNIFORM_COLOR: return "color"; case GPU_UNIFORM_BASE_INSTANCE: - return "baseInstance"; + return "gpu_BaseInstance"; case GPU_UNIFORM_RESOURCE_CHUNK: return "resourceChunk"; case GPU_UNIFORM_RESOURCE_ID: @@ -211,6 +211,13 @@ inline const char *ShaderInterface::builtin_uniform_block_name(GPUUniformBlockBu return "modelBlock"; case GPU_UNIFORM_BLOCK_INFO: return "infoBlock"; + + case GPU_UNIFORM_BLOCK_DRW_VIEW: + return "drw_view"; + case GPU_UNIFORM_BLOCK_DRW_MODEL: + return "drw_matrices"; + case GPU_UNIFORM_BLOCK_DRW_INFOS: + return "drw_infos"; default: return NULL; } diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc index f7ef5c037c9..1e6e2475665 100644 --- a/source/blender/gpu/opengl/gl_shader.cc +++ b/source/blender/gpu/opengl/gl_shader.cc @@ -217,6 +217,8 @@ static void print_image_type(std::ostream &os, case ImageType::UINT_2D_ARRAY: case ImageType::SHADOW_2D: case ImageType::SHADOW_2D_ARRAY: + case ImageType::DEPTH_2D: + case ImageType::DEPTH_2D_ARRAY: os << "2D"; break; case ImageType::FLOAT_3D: @@ -232,6 +234,8 @@ static void print_image_type(std::ostream &os, case ImageType::UINT_CUBE_ARRAY: case ImageType::SHADOW_CUBE: case ImageType::SHADOW_CUBE_ARRAY: + case ImageType::DEPTH_CUBE: + case ImageType::DEPTH_CUBE_ARRAY: os << "Cube"; break; default: @@ -250,6 +254,8 @@ static void print_image_type(std::ostream &os, case ImageType::UINT_CUBE_ARRAY: case ImageType::SHADOW_2D_ARRAY: case ImageType::SHADOW_CUBE_ARRAY: + case ImageType::DEPTH_2D_ARRAY: + case ImageType::DEPTH_CUBE_ARRAY: os << "Array"; break; default: |