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>2020-06-04 14:43:28 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-06-04 15:17:06 +0300
commit7534bbfa344f47700a04e2a8c4dcdcd0310ea9f2 (patch)
treeac60a91026e937ffe90eb6a4a2def97ca765a069 /source/blender/gpu/intern/gpu_shader_interface.c
parent1438c1cfd55e5d3bda7c558d62378f8dda1f2ef1 (diff)
GPUShaderInterface: Add Builtin Uniform blocks query
This makes the query of theses mandatory uniforms faster.
Diffstat (limited to 'source/blender/gpu/intern/gpu_shader_interface.c')
-rw-r--r--source/blender/gpu/intern/gpu_shader_interface.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/source/blender/gpu/intern/gpu_shader_interface.c b/source/blender/gpu/intern/gpu_shader_interface.c
index 84be8affc16..766193acea9 100644
--- a/source/blender/gpu/intern/gpu_shader_interface.c
+++ b/source/blender/gpu/intern/gpu_shader_interface.c
@@ -48,8 +48,6 @@
static const char *BuiltinUniform_name(GPUUniformBuiltin u)
{
static const char *names[] = {
- [GPU_UNIFORM_NONE] = NULL,
-
[GPU_UNIFORM_MODEL] = "ModelMatrix",
[GPU_UNIFORM_VIEW] = "ViewMatrix",
[GPU_UNIFORM_MODELVIEW] = "ModelViewMatrix",
@@ -73,13 +71,25 @@ static const char *BuiltinUniform_name(GPUUniformBuiltin u)
[GPU_UNIFORM_RESOURCE_ID] = "resourceId",
[GPU_UNIFORM_SRGB_TRANSFORM] = "srgbTarget",
- [GPU_UNIFORM_CUSTOM] = NULL,
[GPU_NUM_UNIFORMS] = NULL,
};
return names[u];
}
+static const char *BuiltinUniformBlock_name(GPUUniformBlockBuiltin u)
+{
+ static const char *names[] = {
+ [GPU_UNIFORM_BLOCK_VIEW] = "viewBlock",
+ [GPU_UNIFORM_BLOCK_MODEL] = "modelBlock",
+ [GPU_UNIFORM_BLOCK_INFO] = "infoBlock",
+
+ [GPU_NUM_UNIFORM_BLOCKS] = NULL,
+ };
+
+ return names[u];
+}
+
GPU_INLINE bool match(const char *a, const char *b)
{
return strcmp(a, b) == 0;
@@ -356,11 +366,18 @@ GPUShaderInterface *GPU_shaderinterface_create(int32_t program)
sort_input_list(inputs, inputs_tmp, shaderface->uniform_len);
/* Builtin Uniforms */
- for (GPUUniformBuiltin u = GPU_UNIFORM_NONE + 1; u < GPU_UNIFORM_CUSTOM; u++) {
+ for (GPUUniformBuiltin u = 0; u < GPU_NUM_UNIFORMS; u++) {
shaderface->builtins[u].location = glGetUniformLocation(program, BuiltinUniform_name(u));
shaderface->builtins[u].binding = -1;
}
+ /* Builtin Uniforms Blocks */
+ for (GPUUniformBlockBuiltin u = 0; u < GPU_NUM_UNIFORM_BLOCKS; u++) {
+ const GPUShaderInput *block = GPU_shaderinterface_ubo(shaderface, BuiltinUniformBlock_name(u));
+ shaderface->builtin_blocks[u].location = -1;
+ shaderface->builtin_blocks[u].binding = (block != NULL) ? block->binding : -1;
+ }
+
/* Batches ref buffer */
shaderface->batches_len = GPU_SHADERINTERFACE_REF_ALLOC_COUNT;
shaderface->batches = MEM_callocN(shaderface->batches_len * sizeof(GPUBatch *),
@@ -463,14 +480,17 @@ const GPUShaderInput *GPU_shaderinterface_uniform(const GPUShaderInterface *shad
const GPUShaderInput *GPU_shaderinterface_uniform_builtin(const GPUShaderInterface *shaderface,
GPUUniformBuiltin builtin)
{
-#if TRUST_NO_ONE
- assert(builtin != GPU_UNIFORM_NONE);
- assert(builtin != GPU_UNIFORM_CUSTOM);
- assert(builtin != GPU_NUM_UNIFORMS);
-#endif
+ BLI_assert(builtin >= 0 && builtin < GPU_NUM_UNIFORMS);
return &shaderface->builtins[builtin];
}
+const GPUShaderInput *GPU_shaderinterface_block_builtin(const GPUShaderInterface *shaderface,
+ GPUUniformBlockBuiltin builtin)
+{
+ BLI_assert(builtin >= 0 && builtin < GPU_NUM_UNIFORM_BLOCKS);
+ return &shaderface->builtin_blocks[builtin];
+}
+
void GPU_shaderinterface_add_batch_ref(GPUShaderInterface *shaderface, GPUBatch *batch)
{
int i; /* find first unused slot */