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-01-17 18:05:19 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-01-17 18:29:20 +0300
commit6eaf51ef3e5b7d37170473449bcda60bad025e67 (patch)
tree4dff167f66b8d2befe0303fff168573ad943379c /source/blender/draw/intern
parent9410e5dc97c4f21e19865ca8a9e1e185fcf5a1d4 (diff)
DRW: Use USHORT for vertex color and upload them in linear color to the GPU
This way we remove the need for the srgb boolean uniform and a lot of code complexity. However, mesh update is going to be a bit slower. I did not benchmark the performance impact. This also fix a typo in draw_cache_impl_particles.c and fix hair not using vertex color in workbench. Reviewed By: jbakker Differential Revision: https://developer.blender.org/D6610
Diffstat (limited to 'source/blender/draw/intern')
-rw-r--r--source/blender/draw/intern/draw_cache.c39
-rw-r--r--source/blender/draw/intern/draw_cache.h10
-rw-r--r--source/blender/draw/intern/draw_cache_extract.h6
-rw-r--r--source/blender/draw/intern/draw_cache_extract_mesh.c18
-rw-r--r--source/blender/draw/intern/draw_cache_impl.h5
-rw-r--r--source/blender/draw/intern/draw_cache_impl_mesh.c82
-rw-r--r--source/blender/draw/intern/draw_cache_impl_particles.c2
7 files changed, 25 insertions, 137 deletions
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 4d10e781e79..a0e4af8fc8d 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -826,25 +826,11 @@ GPUBatch *DRW_cache_object_surface_get(Object *ob)
GPUBatch **DRW_cache_object_surface_material_get(struct Object *ob,
struct GPUMaterial **gpumat_array,
- uint gpumat_array_len,
- char **auto_layer_names,
- int **auto_layer_is_srgb,
- int *auto_layer_count)
+ uint gpumat_array_len)
{
- if (auto_layer_names != NULL) {
- *auto_layer_names = NULL;
- *auto_layer_is_srgb = NULL;
- *auto_layer_count = 0;
- }
-
switch (ob->type) {
case OB_MESH:
- return DRW_cache_mesh_surface_shaded_get(ob,
- gpumat_array,
- gpumat_array_len,
- auto_layer_names,
- auto_layer_is_srgb,
- auto_layer_count);
+ return DRW_cache_mesh_surface_shaded_get(ob, gpumat_array, gpumat_array_len);
case OB_CURVE:
return DRW_cache_curve_surface_shaded_get(ob, gpumat_array, gpumat_array_len);
case OB_SURF:
@@ -2733,18 +2719,10 @@ GPUBatch *DRW_cache_mesh_surface_edges_get(Object *ob)
/* Return list of batches with length equal to max(1, totcol). */
GPUBatch **DRW_cache_mesh_surface_shaded_get(Object *ob,
struct GPUMaterial **gpumat_array,
- uint gpumat_array_len,
- char **auto_layer_names,
- int **auto_layer_is_srgb,
- int *auto_layer_count)
+ uint gpumat_array_len)
{
BLI_assert(ob->type == OB_MESH);
- return DRW_mesh_batch_cache_get_surface_shaded(ob->data,
- gpumat_array,
- gpumat_array_len,
- auto_layer_names,
- auto_layer_is_srgb,
- auto_layer_count);
+ return DRW_mesh_batch_cache_get_surface_shaded(ob->data, gpumat_array, gpumat_array_len);
}
/* Return list of batches with length equal to max(1, totcol). */
@@ -2895,8 +2873,7 @@ GPUBatch **DRW_cache_curve_surface_shaded_get(Object *ob,
struct Curve *cu = ob->data;
struct Mesh *mesh_eval = ob->runtime.mesh_eval;
if (mesh_eval != NULL) {
- return DRW_mesh_batch_cache_get_surface_shaded(
- mesh_eval, gpumat_array, gpumat_array_len, NULL, NULL, NULL);
+ return DRW_mesh_batch_cache_get_surface_shaded(mesh_eval, gpumat_array, gpumat_array_len);
}
else {
return DRW_curve_batch_cache_get_surface_shaded(cu, gpumat_array, gpumat_array_len);
@@ -3036,8 +3013,7 @@ GPUBatch **DRW_cache_text_surface_shaded_get(Object *ob,
return NULL;
}
if (mesh_eval != NULL) {
- return DRW_mesh_batch_cache_get_surface_shaded(
- mesh_eval, gpumat_array, gpumat_array_len, NULL, NULL, NULL);
+ return DRW_mesh_batch_cache_get_surface_shaded(mesh_eval, gpumat_array, gpumat_array_len);
}
else {
return DRW_curve_batch_cache_get_surface_shaded(cu, gpumat_array, gpumat_array_len);
@@ -3131,8 +3107,7 @@ GPUBatch **DRW_cache_surf_surface_shaded_get(Object *ob,
struct Curve *cu = ob->data;
struct Mesh *mesh_eval = ob->runtime.mesh_eval;
if (mesh_eval != NULL) {
- return DRW_mesh_batch_cache_get_surface_shaded(
- mesh_eval, gpumat_array, gpumat_array_len, NULL, NULL, NULL);
+ return DRW_mesh_batch_cache_get_surface_shaded(mesh_eval, gpumat_array, gpumat_array_len);
}
else {
return DRW_curve_batch_cache_get_surface_shaded(cu, gpumat_array, gpumat_array_len);
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index 11564464546..3759654931a 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -54,10 +54,7 @@ struct GPUBatch *DRW_cache_object_surface_get(struct Object *ob);
struct GPUBatch *DRW_cache_object_loose_edges_get(struct Object *ob);
struct GPUBatch **DRW_cache_object_surface_material_get(struct Object *ob,
struct GPUMaterial **gpumat_array,
- uint gpumat_array_len,
- char **auto_layer_names,
- int **auto_layer_is_srgb,
- int *auto_layer_count);
+ uint gpumat_array_len);
struct GPUBatch *DRW_cache_object_face_wireframe_get(struct Object *ob);
/* Empties */
@@ -127,10 +124,7 @@ struct GPUBatch *DRW_cache_mesh_surface_get(struct Object *ob);
struct GPUBatch *DRW_cache_mesh_surface_edges_get(struct Object *ob);
struct GPUBatch **DRW_cache_mesh_surface_shaded_get(struct Object *ob,
struct GPUMaterial **gpumat_array,
- uint gpumat_array_len,
- char **auto_layer_names,
- int **auto_layer_is_srgb,
- int *auto_layer_count);
+ uint gpumat_array_len);
struct GPUBatch **DRW_cache_mesh_surface_texpaint_get(struct Object *ob);
struct GPUBatch *DRW_cache_mesh_surface_texpaint_single_get(struct Object *ob);
struct GPUBatch *DRW_cache_mesh_surface_vertpaint_get(struct Object *ob);
diff --git a/source/blender/draw/intern/draw_cache_extract.h b/source/blender/draw/intern/draw_cache_extract.h
index 2d10199782b..9228147af44 100644
--- a/source/blender/draw/intern/draw_cache_extract.h
+++ b/source/blender/draw/intern/draw_cache_extract.h
@@ -213,12 +213,6 @@ typedef struct MeshBatchCache {
GPUBatch **surface_per_mat;
- /* arrays of bool uniform names (and value) that will be use to
- * set srgb conversion for auto attributes.*/
- char *auto_layer_names;
- int *auto_layer_is_srgb;
- int auto_layer_len;
-
DRWBatchFlag batch_requested;
DRWBatchFlag batch_ready;
diff --git a/source/blender/draw/intern/draw_cache_extract_mesh.c b/source/blender/draw/intern/draw_cache_extract_mesh.c
index c98494ebdd9..ee0597c6b21 100644
--- a/source/blender/draw/intern/draw_cache_extract_mesh.c
+++ b/source/blender/draw/intern/draw_cache_extract_mesh.c
@@ -1928,7 +1928,7 @@ static void *extract_vcol_init(const MeshRenderData *mr, void *buf)
GPU_vertformat_safe_attrib_name(layer_name, attr_safe_name, GPU_MAX_SAFE_ATTRIB_NAME);
BLI_snprintf(attr_name, sizeof(attr_name), "c%s", attr_safe_name);
- GPU_vertformat_attr_add(&format, attr_name, GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
+ GPU_vertformat_attr_add(&format, attr_name, GPU_COMP_U16, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
if (i == CustomData_get_render_layer(cd_ldata, CD_MLOOPCOL)) {
GPU_vertformat_alias_add(&format, "c");
@@ -1948,12 +1948,20 @@ static void *extract_vcol_init(const MeshRenderData *mr, void *buf)
GPU_vertbuf_init_with_format(vbo, &format);
GPU_vertbuf_data_alloc(vbo, mr->loop_len);
- MLoopCol *vcol_data = (MLoopCol *)vbo->data;
+ typedef struct gpuMeshVcol {
+ ushort r, g, b, a;
+ } gpuMeshVcol;
+
+ gpuMeshVcol *vcol_data = (gpuMeshVcol *)vbo->data;
for (int i = 0; i < 8; i++) {
if (vcol_layers & (1 << i)) {
- void *layer_data = CustomData_get_layer_n(cd_ldata, CD_MLOOPCOL, i);
- memcpy(vcol_data, layer_data, sizeof(*vcol_data) * mr->loop_len);
- vcol_data += mr->loop_len;
+ MLoopCol *mcol = (MLoopCol *)CustomData_get_layer_n(cd_ldata, CD_MLOOPCOL, i);
+ for (int l = 0; l < mr->loop_len; l++, mcol++, vcol_data++) {
+ vcol_data->r = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->r]);
+ vcol_data->g = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->g]);
+ vcol_data->b = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->b]);
+ vcol_data->a = unit_float_to_ushort_clamp(mcol->a * (1.0f / 255.0f));
+ }
}
}
return NULL;
diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h
index 8cb318bd0bb..bf056d7444d 100644
--- a/source/blender/draw/intern/draw_cache_impl.h
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -127,10 +127,7 @@ struct GPUBatch *DRW_mesh_batch_cache_get_surface(struct Mesh *me);
struct GPUBatch *DRW_mesh_batch_cache_get_surface_edges(struct Mesh *me);
struct GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(struct Mesh *me,
struct GPUMaterial **gpumat_array,
- uint gpumat_array_len,
- char **auto_layer_names,
- int **auto_layer_is_srgb,
- int *auto_layer_count);
+ uint gpumat_array_len);
struct GPUBatch **DRW_mesh_batch_cache_get_surface_texpaint(struct Mesh *me);
struct GPUBatch *DRW_mesh_batch_cache_get_surface_texpaint_single(struct Mesh *me);
struct GPUBatch *DRW_mesh_batch_cache_get_surface_vertpaint(struct Mesh *me);
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index aadcc2a939a..458029c2580 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -230,68 +230,6 @@ static DRW_MeshCDMask mesh_cd_calc_used_gpu_layers(const Mesh *me,
return cd_used;
}
-static void mesh_cd_extract_auto_layers_names_and_srgb(Mesh *me,
- DRW_MeshCDMask cd_used,
- char **r_auto_layers_names,
- int **r_auto_layers_srgb,
- int *r_auto_layers_len)
-{
- const Mesh *me_final = (me->edit_mesh) ? me->edit_mesh->mesh_eval_final : me;
- const CustomData *cd_ldata = &me_final->ldata;
-
- int uv_len_used = count_bits_i(cd_used.uv);
- int vcol_len_used = count_bits_i(cd_used.vcol);
- int uv_len = CustomData_number_of_layers(cd_ldata, CD_MLOOPUV);
- int vcol_len = CustomData_number_of_layers(cd_ldata, CD_MLOOPCOL);
-
- uint auto_names_len = 32 * (uv_len_used + vcol_len_used);
- uint auto_ofs = 0;
- /* Allocate max, resize later. */
- char *auto_names = MEM_callocN(sizeof(char) * auto_names_len, __func__);
- int *auto_is_srgb = MEM_callocN(sizeof(int) * (uv_len_used + vcol_len_used), __func__);
-
- for (int i = 0; i < uv_len; i++) {
- if ((cd_used.uv & (1 << i)) != 0) {
- const char *name = CustomData_get_layer_name(cd_ldata, CD_MLOOPUV, i);
- char safe_name[GPU_MAX_SAFE_ATTRIB_NAME];
- GPU_vertformat_safe_attrib_name(name, safe_name, GPU_MAX_SAFE_ATTRIB_NAME);
- auto_ofs += BLI_snprintf_rlen(
- auto_names + auto_ofs, auto_names_len - auto_ofs, "ba%s", safe_name);
- /* +1 to include '\0' terminator. */
- auto_ofs += 1;
- }
- }
-
- uint auto_is_srgb_ofs = uv_len_used;
- for (int i = 0; i < vcol_len; i++) {
- if ((cd_used.vcol & (1 << i)) != 0) {
- const char *name = CustomData_get_layer_name(cd_ldata, CD_MLOOPCOL, i);
- /* We only do vcols that are not overridden by a uv layer with same name. */
- if (CustomData_get_named_layer_index(cd_ldata, CD_MLOOPUV, name) == -1) {
- char safe_name[GPU_MAX_SAFE_ATTRIB_NAME];
- GPU_vertformat_safe_attrib_name(name, safe_name, GPU_MAX_SAFE_ATTRIB_NAME);
- auto_ofs += BLI_snprintf_rlen(
- auto_names + auto_ofs, auto_names_len - auto_ofs, "ba%s", safe_name);
- /* +1 to include '\0' terminator. */
- auto_ofs += 1;
- auto_is_srgb[auto_is_srgb_ofs] = true;
- auto_is_srgb_ofs++;
- }
- }
- }
-
- auto_names = MEM_reallocN(auto_names, sizeof(char) * auto_ofs);
- auto_is_srgb = MEM_reallocN(auto_is_srgb, sizeof(int) * auto_is_srgb_ofs);
-
- /* WATCH: May have been referenced somewhere before freeing. */
- MEM_SAFE_FREE(*r_auto_layers_names);
- MEM_SAFE_FREE(*r_auto_layers_srgb);
-
- *r_auto_layers_names = auto_names;
- *r_auto_layers_srgb = auto_is_srgb;
- *r_auto_layers_len = auto_is_srgb_ofs;
-}
-
/** \} */
/* ---------------------------------------------------------------------- */
@@ -492,8 +430,6 @@ static void mesh_batch_cache_discard_shaded_tri(MeshBatchCache *cache)
mesh_cd_layers_type_clear(&cache->cd_used);
MEM_SAFE_FREE(cache->surface_per_mat);
- MEM_SAFE_FREE(cache->auto_layer_names);
- MEM_SAFE_FREE(cache->auto_layer_is_srgb);
cache->mat_len = 0;
}
@@ -771,10 +707,7 @@ GPUBatch *DRW_mesh_batch_cache_get_edit_mesh_analysis(Mesh *me)
GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(Mesh *me,
struct GPUMaterial **gpumat_array,
- uint gpumat_array_len,
- char **auto_layer_names,
- int **auto_layer_is_srgb,
- int *auto_layer_count)
+ uint gpumat_array_len)
{
MeshBatchCache *cache = mesh_batch_cache_get(me);
DRW_MeshCDMask cd_needed = mesh_cd_calc_used_gpu_layers(me, gpumat_array, gpumat_array_len);
@@ -783,21 +716,8 @@ GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(Mesh *me,
mesh_cd_layers_type_merge(&cache->cd_needed, cd_needed);
- if (!mesh_cd_layers_type_overlap(cache->cd_used, cd_needed)) {
- mesh_cd_extract_auto_layers_names_and_srgb(me,
- cache->cd_needed,
- &cache->auto_layer_names,
- &cache->auto_layer_is_srgb,
- &cache->auto_layer_len);
- }
-
mesh_batch_cache_add_request(cache, MBC_SURF_PER_MAT);
- if (auto_layer_names) {
- *auto_layer_names = cache->auto_layer_names;
- *auto_layer_is_srgb = cache->auto_layer_is_srgb;
- *auto_layer_count = cache->auto_layer_len;
- }
for (int i = 0; i < cache->mat_len; i++) {
DRW_batch_request(&cache->surface_per_mat[i]);
}
diff --git a/source/blender/draw/intern/draw_cache_impl_particles.c b/source/blender/draw/intern/draw_cache_impl_particles.c
index 7de6ee2b3b1..f4057927d55 100644
--- a/source/blender/draw/intern/draw_cache_impl_particles.c
+++ b/source/blender/draw/intern/draw_cache_impl_particles.c
@@ -1199,7 +1199,7 @@ static void particle_batch_cache_ensure_pos_and_seg(PTCacheEdit *edit,
GPU_vertformat_safe_attrib_name(name, attr_safe_name, GPU_MAX_SAFE_ATTRIB_NAME);
BLI_snprintf(uuid, sizeof(uuid), "c%s", attr_safe_name);
- col_id[i] = GPU_vertformat_attr_add(&format, uuid, GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ col_id[i] = GPU_vertformat_attr_add(&format, uuid, GPU_COMP_U16, 4, GPU_FETCH_FLOAT);
if (i == active_col) {
GPU_vertformat_alias_add(&format, "c");