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
parent1438c1cfd55e5d3bda7c558d62378f8dda1f2ef1 (diff)
GPUShaderInterface: Add Builtin Uniform blocks query
This makes the query of theses mandatory uniforms faster.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/draw/intern/draw_manager_data.c7
-rw-r--r--source/blender/gpu/GPU_shader.h1
-rw-r--r--source/blender/gpu/GPU_shader_interface.h21
-rw-r--r--source/blender/gpu/intern/gpu_shader.c9
-rw-r--r--source/blender/gpu/intern/gpu_shader_interface.c38
5 files changed, 55 insertions, 21 deletions
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index 376bc69b392..ea67dd87772 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -1168,10 +1168,9 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader)
{
shgroup->uniforms = NULL;
- /* TODO(fclem) make them builtin. */
- int view_ubo_location = GPU_shader_get_uniform_block_binding(shader, "viewBlock");
- int model_ubo_location = GPU_shader_get_uniform_block_binding(shader, "modelBlock");
- int info_ubo_location = GPU_shader_get_uniform_block_binding(shader, "infoBlock");
+ int view_ubo_location = GPU_shader_get_builtin_block(shader, GPU_UNIFORM_BLOCK_VIEW);
+ int model_ubo_location = GPU_shader_get_builtin_block(shader, GPU_UNIFORM_BLOCK_MODEL);
+ int info_ubo_location = GPU_shader_get_builtin_block(shader, GPU_UNIFORM_BLOCK_INFO);
int baseinst_location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_BASE_INSTANCE);
int chunkid_location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_RESOURCE_CHUNK);
int resourceid_location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_RESOURCE_ID);
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index 40bae88f46d..0ad472113c9 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -93,6 +93,7 @@ void GPU_shader_set_srgb_uniform(const struct GPUShaderInterface *interface);
int GPU_shader_get_uniform(GPUShader *shader, const char *name);
int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin);
+int GPU_shader_get_builtin_block(GPUShader *shader, int builtin);
int GPU_shader_get_uniform_block(GPUShader *shader, const char *name);
int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name);
diff --git a/source/blender/gpu/GPU_shader_interface.h b/source/blender/gpu/GPU_shader_interface.h
index 319a79a9e42..7875ac35fae 100644
--- a/source/blender/gpu/GPU_shader_interface.h
+++ b/source/blender/gpu/GPU_shader_interface.h
@@ -33,9 +33,7 @@ extern "C" {
#endif
typedef enum {
- GPU_UNIFORM_NONE = 0, /* uninitialized/unknown */
-
- GPU_UNIFORM_MODEL, /* mat4 ModelMatrix */
+ GPU_UNIFORM_MODEL = 0, /* mat4 ModelMatrix */
GPU_UNIFORM_VIEW, /* mat4 ViewMatrix */
GPU_UNIFORM_MODELVIEW, /* mat4 ModelViewMatrix */
GPU_UNIFORM_PROJECTION, /* mat4 ProjectionMatrix */
@@ -58,11 +56,17 @@ typedef enum {
GPU_UNIFORM_RESOURCE_ID, /* int resourceId */
GPU_UNIFORM_SRGB_TRANSFORM, /* bool srgbTarget */
- GPU_UNIFORM_CUSTOM, /* custom uniform, not one of the above built-ins */
-
GPU_NUM_UNIFORMS, /* Special value, denotes number of builtin uniforms. */
} GPUUniformBuiltin;
+typedef enum {
+ GPU_UNIFORM_BLOCK_VIEW = 0, /* viewBlock */
+ GPU_UNIFORM_BLOCK_MODEL, /* modelBlock */
+ GPU_UNIFORM_BLOCK_INFO, /* infoBlock */
+
+ GPU_NUM_UNIFORM_BLOCKS, /* Special value, denotes number of builtin uniforms block. */
+} GPUUniformBlockBuiltin;
+
typedef struct GPUShaderInput {
uint32_t name_offset;
uint32_t name_hash;
@@ -90,6 +94,7 @@ typedef struct GPUShaderInterface {
/** Opengl Location of builtin uniforms. Fast access, no lookup needed. */
/* TODO replace by location only array. */
GPUShaderInput builtins[GPU_NUM_UNIFORMS];
+ GPUShaderInput builtin_blocks[GPU_NUM_UNIFORM_BLOCKS];
/** Flat array. In this order: Attributes, Ubos, Uniforms. */
GPUShaderInput inputs[0];
} GPUShaderInterface;
@@ -98,8 +103,10 @@ GPUShaderInterface *GPU_shaderinterface_create(int32_t program_id);
void GPU_shaderinterface_discard(GPUShaderInterface *);
const GPUShaderInput *GPU_shaderinterface_uniform(const GPUShaderInterface *, const char *name);
-const GPUShaderInput *GPU_shaderinterface_uniform_builtin(const GPUShaderInterface *,
- GPUUniformBuiltin);
+const GPUShaderInput *GPU_shaderinterface_uniform_builtin(const GPUShaderInterface *shaderface,
+ GPUUniformBuiltin builtin);
+const GPUShaderInput *GPU_shaderinterface_block_builtin(const GPUShaderInterface *shaderface,
+ GPUUniformBlockBuiltin builtin);
const GPUShaderInput *GPU_shaderinterface_ubo(const GPUShaderInterface *, const char *name);
const GPUShaderInput *GPU_shaderinterface_attr(const GPUShaderInterface *, const char *name);
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index 66f98461047..651410cf333 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -736,7 +736,14 @@ int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin)
{
BLI_assert(shader && shader->program);
const GPUShaderInput *uniform = GPU_shaderinterface_uniform_builtin(shader->interface, builtin);
- return uniform ? uniform->location : -1;
+ return uniform->location;
+}
+
+int GPU_shader_get_builtin_block(GPUShader *shader, int builtin)
+{
+ BLI_assert(shader && shader->program);
+ const GPUShaderInput *uniform = GPU_shaderinterface_block_builtin(shader->interface, builtin);
+ return uniform->binding;
}
int GPU_shader_get_uniform_block(GPUShader *shader, const char *name)
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 */