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>2019-06-05 20:52:31 +0300
committerClément Foucault <foucault.clem@gmail.com>2019-08-17 15:48:48 +0300
commitdd4276844ee01f97f0be47d60e324671089d75e4 (patch)
tree70891d9905af723d37dfb08cb39bff81d104ba75
parent7e7c9d4e17b5be72691bb3885c08989e63752428 (diff)
DRW: Add builtin uniform to get full DRWResourceHandle from shader
This solves the issue with loosing outline around meshes that have the same ID. Now it needs to have 16K objects in the scene for that to happen.
-rw-r--r--source/blender/draw/intern/draw_manager.h2
-rw-r--r--source/blender/draw/intern/draw_manager_data.c7
-rw-r--r--source/blender/draw/intern/draw_manager_exec.c35
-rw-r--r--source/blender/draw/modes/shaders/common_view_lib.glsl4
-rw-r--r--source/blender/draw/modes/shaders/object_outline_prepass_vert.glsl6
-rw-r--r--source/blender/gpu/GPU_shader_interface.h6
-rw-r--r--source/blender/gpu/intern/gpu_shader_interface.c2
7 files changed, 31 insertions, 31 deletions
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h
index a1ab0934a3b..289b583b9e9 100644
--- a/source/blender/draw/intern/draw_manager.h
+++ b/source/blender/draw/intern/draw_manager.h
@@ -183,7 +183,7 @@ typedef enum {
/** Per drawcall uniforms/UBO */
DRW_UNIFORM_BLOCK_OBMATS,
DRW_UNIFORM_BLOCK_OBINFOS,
- DRW_UNIFORM_CALLID,
+ DRW_UNIFORM_RESOURCE_CHUNK,
/** Legacy / Fallback */
DRW_UNIFORM_BASE_INSTANCE,
DRW_UNIFORM_MODEL_MATRIX,
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index 5a71468909a..d5da696112d 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -897,10 +897,11 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader)
int model_ubo_location = GPU_shader_get_uniform_block(shader, "modelBlock");
int info_ubo_location = GPU_shader_get_uniform_block(shader, "infoBlock");
int baseinst_location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_BASE_INSTANCE);
- int callid_location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_CALLID);
+ int chunkid_location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_RESOURCE_CHUNK);
- if (callid_location != -1) {
- drw_shgroup_uniform_create_ex(shgroup, callid_location, DRW_UNIFORM_CALLID, NULL, 0, 1);
+ if (chunkid_location != -1) {
+ drw_shgroup_uniform_create_ex(
+ shgroup, chunkid_location, DRW_UNIFORM_RESOURCE_CHUNK, NULL, 0, 1);
}
if (baseinst_location != -1) {
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index 6fafc0bf1aa..a78a0033ffe 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -808,7 +808,7 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup,
int *obmats_loc,
int *obinfos_loc,
int *baseinst_loc,
- int *callid_loc,
+ int *chunkid_loc,
int *obmat_loc,
int *obinv_loc,
int *mvp_loc)
@@ -884,8 +884,9 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup,
GPU_uniformbuffer_bind(ubo, 1);
GPU_shader_uniform_buffer(shgroup->shader, uni->location, ubo);
break;
- case DRW_UNIFORM_CALLID:
- *callid_loc = uni->location;
+ case DRW_UNIFORM_RESOURCE_CHUNK:
+ *chunkid_loc = uni->location;
+ GPU_shader_uniform_int(shgroup->shader, uni->location, 0);
break;
/* Legacy/Fallback support. */
case DRW_UNIFORM_BASE_INSTANCE:
@@ -995,7 +996,8 @@ typedef struct DRWCommandsState {
static void draw_call_resource_bind(DRWCommandsState *state,
DRWResourceHandle handle,
int obmats_loc,
- int obinfos_loc)
+ int obinfos_loc,
+ int chunkid_loc)
{
/* Front face is not a resource but it is inside the resource handle. */
if (handle.negative_scale != state->neg_scale) {
@@ -1004,6 +1006,9 @@ static void draw_call_resource_bind(DRWCommandsState *state,
}
if (state->resource_chunk != handle.chunk) {
+ if (chunkid_loc != -1) {
+ GPU_shader_uniform_int(NULL, chunkid_loc, handle.chunk);
+ }
if (obmats_loc != -1) {
GPU_uniformbuffer_unbind(DST.vmempool->matrices_ubo[state->resource_chunk]);
GPU_uniformbuffer_bind(DST.vmempool->matrices_ubo[handle.chunk], 0);
@@ -1024,10 +1029,10 @@ static bool draw_call_do_batching(DRWShadingGroup *shgroup,
int obmats_loc,
int obinfos_loc,
int baseinst_loc,
- int callid_loc)
+ int chunkid_loc)
{
- if (call->inst_count > 0 || call->vert_first > 0 || call->vert_count > 0 || callid_loc != -1 ||
- obmats_loc == -1 || G.f & G_FLAG_PICKSEL) {
+ if (call->inst_count > 0 || call->vert_first > 0 || call->vert_count > 0 || obmats_loc == -1 ||
+ G.f & G_FLAG_PICKSEL) {
/* Safety guard. Batching should not happen in a shgroup
* where any if the above condition are true. */
BLI_assert(state->inst_count == 0);
@@ -1056,7 +1061,7 @@ static bool draw_call_do_batching(DRWShadingGroup *shgroup,
state->inst_count = 1;
state->base_inst = call->handle.id;
state->batch = call->batch;
- draw_call_resource_bind(state, call->handle, obmats_loc, obinfos_loc);
+ draw_call_resource_bind(state, call->handle, obmats_loc, obinfos_loc, chunkid_loc);
}
else {
state->inst_count++;
@@ -1075,7 +1080,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
int obmats_loc = -1;
int obinfos_loc = -1;
int baseinst_loc = -1;
- int callid_loc = -1;
+ int chunkid_loc = -1;
/* Legacy matrix support. */
int obmat_loc = -1;
int obinv_loc = -1;
@@ -1105,7 +1110,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
&obmats_loc,
&obinfos_loc,
&baseinst_loc,
- &callid_loc,
+ &chunkid_loc,
&obmat_loc,
&obinv_loc,
&mvp_loc);
@@ -1135,18 +1140,12 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
#ifdef USE_BATCHING
/* Pack calls together if their handle.id are consecutive. */
if (draw_call_do_batching(
- shgroup, &state, call, obmats_loc, obinfos_loc, baseinst_loc, callid_loc)) {
+ shgroup, &state, call, obmats_loc, obinfos_loc, baseinst_loc, chunkid_loc)) {
continue;
}
#endif
- draw_call_resource_bind(&state, call->handle, obmats_loc, obinfos_loc);
-
- /* XXX small exception/optimisation for outline rendering. */
- if (callid_loc != -1) {
- GPU_shader_uniform_vector_int(shgroup->shader, callid_loc, 1, 1, &state.callid);
- state.callid += 1;
- }
+ draw_call_resource_bind(&state, call->handle, obmats_loc, obinfos_loc, chunkid_loc);
if (obmats_loc == -1 && (obmat_loc != -1 || obinv_loc != -1 || mvp_loc != -1)) {
/* TODO This is Legacy. Need to be removed. */
diff --git a/source/blender/draw/modes/shaders/common_view_lib.glsl b/source/blender/draw/modes/shaders/common_view_lib.glsl
index f27468492c3..e7bffaa7455 100644
--- a/source/blender/draw/modes/shaders/common_view_lib.glsl
+++ b/source/blender/draw/modes/shaders/common_view_lib.glsl
@@ -24,6 +24,8 @@ layout(std140) uniform viewBlock
_world_clip_planes_calc_clip_distance(p, clipPlanes)
#endif
+uniform int resourceChunk = 0;
+
#ifdef GPU_VERTEX_SHADER
# ifdef GL_ARB_shader_draw_parameters
# define resource_id (gl_BaseInstanceARB + gl_InstanceID)
@@ -70,6 +72,8 @@ layout(std140) uniform modelBlock
#define ModelMatrix (drw_matrices[resource_id].drw_modelMatrix)
#define ModelMatrixInverse (drw_matrices[resource_id].drw_modelMatrixInverse)
+#define resource_handle (resourceChunk * DRW_RESOURCE_CHUNK_LEN + resource_id)
+
/** Transform shortcuts. */
/* Rule of thumb: Try to reuse world positions and normals because converting though viewspace
* will always be decomposed in at least 2 matrix operation. */
diff --git a/source/blender/draw/modes/shaders/object_outline_prepass_vert.glsl b/source/blender/draw/modes/shaders/object_outline_prepass_vert.glsl
index 952d23e9138..7740f9a4af2 100644
--- a/source/blender/draw/modes/shaders/object_outline_prepass_vert.glsl
+++ b/source/blender/draw/modes/shaders/object_outline_prepass_vert.glsl
@@ -1,8 +1,4 @@
-/* Needed to recover the full call resource handle.
- * Here used to have the unique ID of the drawcall. */
-// uniform int resPoolID;
-
in vec3 pos;
#ifdef USE_GEOM
@@ -25,7 +21,7 @@ void main()
gl_Position.z -= 1e-3;
/* ID 0 is nothing (background) */
- objectId = resource_id + 1;
+ objectId = resource_handle + 1;
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance(world_pos);
diff --git a/source/blender/gpu/GPU_shader_interface.h b/source/blender/gpu/GPU_shader_interface.h
index a98a56e1f3e..e336aa53d24 100644
--- a/source/blender/gpu/GPU_shader_interface.h
+++ b/source/blender/gpu/GPU_shader_interface.h
@@ -48,9 +48,9 @@ typedef enum {
GPU_UNIFORM_ORCO, /* vec4 OrcoTexCoFactors[] */
GPU_UNIFORM_CLIPPLANES, /* vec4 WorldClipPlanes[] */
- GPU_UNIFORM_COLOR, /* vec4 color */
- GPU_UNIFORM_CALLID, /* int callId */
- GPU_UNIFORM_BASE_INSTANCE, /* int baseInstance */
+ GPU_UNIFORM_COLOR, /* vec4 color */
+ GPU_UNIFORM_BASE_INSTANCE, /* int baseInstance */
+ GPU_UNIFORM_RESOURCE_CHUNK, /* int resourceChunk */
GPU_UNIFORM_CUSTOM, /* custom uniform, not one of the above built-ins */
diff --git a/source/blender/gpu/intern/gpu_shader_interface.c b/source/blender/gpu/intern/gpu_shader_interface.c
index 1969b8155a7..4273075081b 100644
--- a/source/blender/gpu/intern/gpu_shader_interface.c
+++ b/source/blender/gpu/intern/gpu_shader_interface.c
@@ -65,8 +65,8 @@ static const char *BuiltinUniform_name(GPUUniformBuiltin u)
[GPU_UNIFORM_CLIPPLANES] = "WorldClipPlanes",
[GPU_UNIFORM_COLOR] = "color",
- [GPU_UNIFORM_CALLID] = "callId",
[GPU_UNIFORM_BASE_INSTANCE] = "baseInstance",
+ [GPU_UNIFORM_RESOURCE_CHUNK] = "resourceChunk",
[GPU_UNIFORM_CUSTOM] = NULL,
[GPU_NUM_UNIFORMS] = NULL,