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:
authorGermano Cavalcante <mano-wii>2022-04-13 00:28:27 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2022-04-13 00:50:56 +0300
commit9bc678969aaef5e2343d9362648e9a633d1b6e5e (patch)
tree6967bc7469d26d91925bddc618d4ad69432d12fc /source/blender/gpu
parent359b6baf325a701328732598ecc04b68a9a335d9 (diff)
pyGPU: Port 'StageInterfaceInfo' and 'ShaderCreateInfo' types
In order to allow GLSL Cross Compilation across platforms, expose in Python the `GPUShaderCreateInfo` strategy as detailed in https://wiki.blender.org/wiki/EEVEE_%26_Viewport/GPU_Module/GLSL_Cross_Compilation The new features can be listed as follows: ``` >>> gpu.types.GPUShaderCreateInfo. define( fragment_out( fragment_source( push_constant( sampler( typedef_source( uniform_buf( vertex_in( vertex_out( vertex_source( >>> gpu.types.GPUStageInterfaceInfo. flat( name no_perspective( smooth( >>> gpu.shader.create_from_info( ``` Reviewed By: fclem, campbellbarton Differential Revision: https://developer.blender.org/D14497
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/GPU_shader.h1
-rw-r--r--source/blender/gpu/intern/gpu_shader.cc39
-rw-r--r--source/blender/gpu/intern/gpu_shader_create_info.cc28
-rw-r--r--source/blender/gpu/intern/gpu_shader_create_info.hh2
4 files changed, 48 insertions, 22 deletions
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index c0c25022836..eed7685bf01 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -56,6 +56,7 @@ GPUShader *GPU_shader_create_from_info(const GPUShaderCreateInfo *_info);
GPUShader *GPU_shader_create_from_info_name(const char *info_name);
const GPUShaderCreateInfo *GPU_shader_create_info_get(const char *info_name);
+bool GPU_shader_create_info_check_error(const GPUShaderCreateInfo *_info, char r_error[128]);
struct GPU_ShaderCreateFromArray_Params {
const char **vert, **geom, **frag, **defs;
diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc
index b434cfbbb0e..227525bd5d3 100644
--- a/source/blender/gpu/intern/gpu_shader.cc
+++ b/source/blender/gpu/intern/gpu_shader.cc
@@ -249,6 +249,19 @@ const GPUShaderCreateInfo *GPU_shader_create_info_get(const char *info_name)
return gpu_shader_create_info_get(info_name);
}
+bool GPU_shader_create_info_check_error(const GPUShaderCreateInfo *_info, char r_error[128])
+{
+ using namespace blender::gpu::shader;
+ const ShaderCreateInfo &info = *reinterpret_cast<const ShaderCreateInfo *>(_info);
+ std::string error = info.check_error();
+ if (error.length() == 0) {
+ return true;
+ }
+
+ BLI_strncpy(r_error, error.c_str(), 128);
+ return false;
+}
+
GPUShader *GPU_shader_create_from_info_name(const char *info_name)
{
using namespace blender::gpu::shader;
@@ -270,28 +283,10 @@ GPUShader *GPU_shader_create_from_info(const GPUShaderCreateInfo *_info)
GPU_debug_group_begin(GPU_DEBUG_SHADER_COMPILATION_GROUP);
- /* At least a vertex shader and a fragment shader are required, or only a compute shader. */
- if (info.compute_source_.is_empty()) {
- if (info.vertex_source_.is_empty()) {
- printf("Missing vertex shader in %s.\n", info.name_.c_str());
- }
- if (info.fragment_source_.is_empty()) {
- printf("Missing fragment shader in %s.\n", info.name_.c_str());
- }
- BLI_assert(!info.vertex_source_.is_empty() && !info.fragment_source_.is_empty());
- }
- else {
- if (!info.vertex_source_.is_empty()) {
- printf("Compute shader has vertex_source_ shader attached in %s.\n", info.name_.c_str());
- }
- if (!info.geometry_source_.is_empty()) {
- printf("Compute shader has geometry_source_ shader attached in %s.\n", info.name_.c_str());
- }
- if (!info.fragment_source_.is_empty()) {
- printf("Compute shader has fragment_source_ shader attached in %s.\n", info.name_.c_str());
- }
- BLI_assert(info.vertex_source_.is_empty() && info.geometry_source_.is_empty() &&
- info.fragment_source_.is_empty());
+ std::string error = info.check_error();
+ if (error.length()) {
+ printf(error.c_str());
+ BLI_assert(true);
}
Shader *shader = GPUBackend::get()->shader_alloc(info.name_.c_str());
diff --git a/source/blender/gpu/intern/gpu_shader_create_info.cc b/source/blender/gpu/intern/gpu_shader_create_info.cc
index 0dd82d4ea44..6e82201b424 100644
--- a/source/blender/gpu/intern/gpu_shader_create_info.cc
+++ b/source/blender/gpu/intern/gpu_shader_create_info.cc
@@ -136,6 +136,34 @@ void ShaderCreateInfo::finalize()
}
}
+std::string ShaderCreateInfo::check_error() const
+{
+ std::string error;
+
+ /* At least a vertex shader and a fragment shader are required, or only a compute shader. */
+ if (this->compute_source_.is_empty()) {
+ if (this->vertex_source_.is_empty()) {
+ error += "Missing vertex shader in " + this->name_ + ".\n";
+ }
+ if (this->fragment_source_.is_empty()) {
+ error += "Missing fragment shader in " + this->name_ + ".\n";
+ }
+ }
+ else {
+ if (!this->vertex_source_.is_empty()) {
+ error += "Compute shader has vertex_source_ shader attached in" + this->name_ + ".\n";
+ }
+ if (!this->geometry_source_.is_empty()) {
+ error += "Compute shader has geometry_source_ shader attached in" + this->name_ + ".\n";
+ }
+ if (!this->fragment_source_.is_empty()) {
+ error += "Compute shader has fragment_source_ shader attached in" + this->name_ + ".\n";
+ }
+ }
+
+ return error;
+}
+
void ShaderCreateInfo::validate(const ShaderCreateInfo &other_info)
{
if (!auto_resource_location_) {
diff --git a/source/blender/gpu/intern/gpu_shader_create_info.hh b/source/blender/gpu/intern/gpu_shader_create_info.hh
index 51008993353..dfd73219d1b 100644
--- a/source/blender/gpu/intern/gpu_shader_create_info.hh
+++ b/source/blender/gpu/intern/gpu_shader_create_info.hh
@@ -787,6 +787,8 @@ struct ShaderCreateInfo {
/* WARNING: Recursive. */
void finalize();
+ std::string check_error() const;
+
/** Error detection that some backend compilers do not complain about. */
void validate(const ShaderCreateInfo &other_info);