Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2022-01-26 14:46:37 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-01-26 14:46:37 +0300
commit5b299e5999e2b59e30edd4e770f64aa700e482d6 (patch)
tree17052358b339e20c44ca942e62b735ef63b23f88 /source/blender/gpu/intern
parent9bce134e56c28045aee37080f5c5b6622a07927b (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/intern')
-rw-r--r--source/blender/gpu/intern/gpu_shader_create_info.cc36
-rw-r--r--source/blender/gpu/intern/gpu_shader_create_info.hh10
-rw-r--r--source/blender/gpu/intern/gpu_shader_interface.hh9
3 files changed, 48 insertions, 7 deletions
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;
}