diff options
author | Jeroen Bakker <jbakker> | 2022-01-17 16:32:03 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2022-01-17 16:32:28 +0300 |
commit | 8fb2ff458ba579dba08bfdf57d043ad158b5db07 (patch) | |
tree | e6324c08c69de3e8ed34c1f85d0b2982fa1d38ed /source/blender/gpu/intern/gpu_shader_interface.hh | |
parent | 08822801acf648d23791fa308ec8c1c26f86963e (diff) |
GPUShaderCreateInfo for interface abstraction
This is a first part of the Shader Create Info system could be.
A shader create info provides a way to define shader structure, resources
and interfaces. This makes for a quick way to provide backend agnostic
binding informations while also making shader variations easy to declare.
- Clear source input (only one file). Cleans up the GPU api since we can create a
shader from one descriptor
- Resources and interfaces are generated by the backend (much simpler than parsing).
- Bindings are explicit from position in the array.
- GPUShaderInterface becomes a trivial translation of enums and string copy.
- No external dependency to third party lib.
- Cleaner code, less fragmentation of resources in several libs.
- Easy to modify / extend at runtime.
- no parser involve, very easy to code.
- Does not hold any data, can be static and kept on disc.
- Could hold precompiled bytecode for static shaders.
This also includes a new global dependency system.
GLSL shaders can include other sources by using #pragma BLENDER_REQUIRE(...).
This patch already migrated several builtin shaders. Other shaders should be migrated
one at a time, and could be done inside master.
There is a new compile directive `WITH_GPU_SHADER_BUILDER` this is an optional
directive for linting shaders to increase turn around time.
What is remaining:
- pyGPU API {T94975}
- Migration of other shaders. This could be a community effort.
Reviewed By: jbakker
Maniphest Tasks: T94975
Differential Revision: https://developer.blender.org/D13360
Diffstat (limited to 'source/blender/gpu/intern/gpu_shader_interface.hh')
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_interface.hh | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/source/blender/gpu/intern/gpu_shader_interface.hh b/source/blender/gpu/intern/gpu_shader_interface.hh index 4bd8f245e2b..735b8fea71d 100644 --- a/source/blender/gpu/intern/gpu_shader_interface.hh +++ b/source/blender/gpu/intern/gpu_shader_interface.hh @@ -34,6 +34,7 @@ #include "BLI_utildefines.h" #include "GPU_shader.h" +#include "gpu_shader_create_info.hh" namespace blender::gpu { @@ -50,6 +51,7 @@ typedef struct ShaderInput { * Base class which is then specialized for each implementation (GL, VK, ...). */ class ShaderInterface { + friend shader::ShaderCreateInfo; /* TODO(fclem): should be protected. */ public: /** Flat array. In this order: Attributes, Ubos, Uniforms. */ @@ -72,6 +74,7 @@ class ShaderInterface { public: ShaderInterface(); + ShaderInterface(const shader::ShaderCreateInfo &info); virtual ~ShaderInterface(); void debug_print(); @@ -129,6 +132,10 @@ class ShaderInterface { static inline const char *builtin_uniform_block_name(GPUUniformBlockBuiltin u); inline uint32_t set_input_name(ShaderInput *input, char *name, uint32_t name_len) const; + inline void copy_input_name(ShaderInput *input, + const StringRefNull &name, + char *name_buffer, + uint32_t &name_buffer_offset) const; /** * Finalize interface construction by sorting the #ShaderInputs for faster lookups. @@ -216,8 +223,12 @@ inline uint32_t ShaderInterface::set_input_name(ShaderInput *input, { /* remove "[0]" from array name */ if (name[name_len - 1] == ']') { - name[name_len - 3] = '\0'; - name_len -= 3; + for (; name_len > 1; name_len--) { + if (name[name_len] == '[') { + name[name_len] = '\0'; + break; + } + } } input->name_offset = (uint32_t)(name - name_buffer_); @@ -225,6 +236,17 @@ inline uint32_t ShaderInterface::set_input_name(ShaderInput *input, return name_len + 1; /* include NULL terminator */ } +inline void ShaderInterface::copy_input_name(ShaderInput *input, + const StringRefNull &name, + char *name_buffer, + uint32_t &name_buffer_offset) const +{ + uint32_t name_len = name.size(); + /* Copy include NULL terminator. */ + memcpy(name_buffer + name_buffer_offset, name.c_str(), name_len + 1); + name_buffer_offset += set_input_name(input, name_buffer + name_buffer_offset, name_len); +} + inline const ShaderInput *ShaderInterface::input_lookup(const ShaderInput *const inputs, const uint inputs_len, const char *name) const |