Mesh: Draw: Replace extractor abstraction for tangents buffer
Part of #116901.
This commit is contained in:
@@ -63,8 +63,6 @@ enum eMRDataType {
|
||||
MR_DATA_POLY_NOR = 1 << 1,
|
||||
MR_DATA_LOOP_NOR = 1 << 2,
|
||||
MR_DATA_LOOSE_GEOM = 1 << 4,
|
||||
/** Force loop normals calculation. */
|
||||
MR_DATA_TAN_LOOP_NOR = 1 << 5,
|
||||
MR_DATA_POLYS_SORTED = 1 << 6,
|
||||
};
|
||||
ENUM_OPERATORS(eMRDataType, MR_DATA_POLYS_SORTED)
|
||||
|
||||
@@ -531,11 +531,11 @@ static void mesh_extract_render_data_node_exec(void *__restrict task_data)
|
||||
MeshBufferList &buffers = update_task_data->cache->buff;
|
||||
|
||||
const bool request_face_normals = DRW_vbo_requested(buffers.vbo.nor) ||
|
||||
(data_flag & (MR_DATA_POLY_NOR | MR_DATA_LOOP_NOR |
|
||||
MR_DATA_TAN_LOOP_NOR)) != 0;
|
||||
DRW_vbo_requested(buffers.vbo.tan) ||
|
||||
(data_flag & (MR_DATA_POLY_NOR | MR_DATA_LOOP_NOR)) != 0;
|
||||
const bool request_corner_normals = DRW_vbo_requested(buffers.vbo.nor) ||
|
||||
(data_flag & MR_DATA_LOOP_NOR) != 0;
|
||||
const bool force_corner_normals = (data_flag & MR_DATA_TAN_LOOP_NOR) != 0;
|
||||
const bool force_corner_normals = DRW_vbo_requested(buffers.vbo.tan);
|
||||
|
||||
if (request_face_normals) {
|
||||
mesh_render_data_update_face_normals(mr);
|
||||
@@ -642,7 +642,6 @@ void mesh_buffer_cache_create_requested(TaskGraph &task_graph,
|
||||
} while (0)
|
||||
|
||||
EXTRACT_ADD_REQUESTED(vbo, uv);
|
||||
EXTRACT_ADD_REQUESTED(vbo, tan);
|
||||
EXTRACT_ADD_REQUESTED(vbo, sculpt_data);
|
||||
EXTRACT_ADD_REQUESTED(vbo, orco);
|
||||
EXTRACT_ADD_REQUESTED(vbo, edge_fac);
|
||||
@@ -679,7 +678,7 @@ void mesh_buffer_cache_create_requested(TaskGraph &task_graph,
|
||||
!DRW_ibo_requested(buffers.ibo.lines_loose) && !DRW_ibo_requested(buffers.ibo.tris) &&
|
||||
!DRW_ibo_requested(buffers.ibo.points) && !DRW_vbo_requested(buffers.vbo.pos) &&
|
||||
!DRW_vbo_requested(buffers.vbo.nor) && !DRW_vbo_requested(buffers.vbo.vnor) &&
|
||||
!DRW_vbo_requested(buffers.vbo.edit_data))
|
||||
!DRW_vbo_requested(buffers.vbo.tan) && !DRW_vbo_requested(buffers.vbo.edit_data))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -828,6 +827,23 @@ void mesh_buffer_cache_create_requested(TaskGraph &task_graph,
|
||||
[](void *task_data) { delete static_cast<TaskData *>(task_data); });
|
||||
BLI_task_graph_edge_create(task_node_mesh_render_data, task_node);
|
||||
}
|
||||
if (DRW_vbo_requested(buffers.vbo.tan)) {
|
||||
struct TaskData {
|
||||
MeshRenderData &mr;
|
||||
MeshBufferList &buffers;
|
||||
MeshBatchCache &cache;
|
||||
bool do_hq_normals;
|
||||
};
|
||||
TaskNode *task_node = BLI_task_graph_node_create(
|
||||
&task_graph,
|
||||
[](void *__restrict task_data) {
|
||||
const TaskData &data = *static_cast<TaskData *>(task_data);
|
||||
extract_tangents(data.mr, data.cache, data.do_hq_normals, *data.buffers.vbo.tan);
|
||||
},
|
||||
new TaskData{*mr, buffers, cache, do_hq_normals},
|
||||
[](void *task_data) { delete static_cast<TaskData *>(task_data); });
|
||||
BLI_task_graph_edge_create(task_node_mesh_render_data, task_node);
|
||||
}
|
||||
|
||||
if (use_thread) {
|
||||
/* First run the requested extractors that do not support asynchronous ranges. */
|
||||
@@ -938,7 +954,6 @@ void mesh_buffer_cache_create_requested_subdiv(MeshBatchCache &cache,
|
||||
EXTRACT_ADD_REQUESTED(vbo, edituv_data);
|
||||
/* Make sure UVs are computed before edituv stuffs. */
|
||||
EXTRACT_ADD_REQUESTED(vbo, uv);
|
||||
EXTRACT_ADD_REQUESTED(vbo, tan);
|
||||
EXTRACT_ADD_REQUESTED(vbo, edituv_stretch_area);
|
||||
EXTRACT_ADD_REQUESTED(vbo, edituv_stretch_angle);
|
||||
EXTRACT_ADD_REQUESTED(ibo, lines_paint_mask);
|
||||
@@ -952,7 +967,7 @@ void mesh_buffer_cache_create_requested_subdiv(MeshBatchCache &cache,
|
||||
!DRW_ibo_requested(buffers.ibo.lines_loose) && !DRW_ibo_requested(buffers.ibo.tris) &&
|
||||
!DRW_ibo_requested(buffers.ibo.points) && !DRW_vbo_requested(buffers.vbo.pos) &&
|
||||
!DRW_vbo_requested(buffers.vbo.orco) && !DRW_vbo_requested(buffers.vbo.nor) &&
|
||||
!DRW_vbo_requested(buffers.vbo.edit_data))
|
||||
!DRW_vbo_requested(buffers.vbo.tan) && !DRW_vbo_requested(buffers.vbo.edit_data))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -981,6 +996,9 @@ void mesh_buffer_cache_create_requested_subdiv(MeshBatchCache &cache,
|
||||
if (DRW_vbo_requested(buffers.vbo.edit_data)) {
|
||||
extract_edit_data_subdiv(mr, subdiv_cache, *buffers.vbo.edit_data);
|
||||
}
|
||||
if (DRW_vbo_requested(buffers.vbo.tan)) {
|
||||
extract_tangents_subdiv(mr, subdiv_cache, cache, *buffers.vbo.tan);
|
||||
}
|
||||
|
||||
void *data_stack = MEM_mallocN(extractors.data_size_total(), __func__);
|
||||
uint32_t data_offset = 0;
|
||||
|
||||
@@ -52,9 +52,6 @@ eMRIterType mesh_extract_iter_type(const MeshExtract *ext)
|
||||
|
||||
static const MeshExtract *mesh_extract_override_hq_normals(const MeshExtract *extractor)
|
||||
{
|
||||
if (extractor == &extract_tan) {
|
||||
return &extract_tan_hq;
|
||||
}
|
||||
if (extractor == &extract_fdots_nor) {
|
||||
return &extract_fdots_nor_hq;
|
||||
}
|
||||
|
||||
@@ -383,6 +383,15 @@ void extract_edit_data_subdiv(const MeshRenderData &mr,
|
||||
const DRWSubdivCache &subdiv_cache,
|
||||
gpu::VertBuf &vbo);
|
||||
|
||||
void extract_tangents(const MeshRenderData &mr,
|
||||
const MeshBatchCache &cache,
|
||||
const bool use_hq,
|
||||
gpu::VertBuf &vbo);
|
||||
void extract_tangents_subdiv(const MeshRenderData &mr,
|
||||
const DRWSubdivCache &subdiv_cache,
|
||||
const MeshBatchCache &cache,
|
||||
gpu::VertBuf &vbo);
|
||||
|
||||
extern const MeshExtract extract_fdots;
|
||||
extern const MeshExtract extract_lines_paint_mask;
|
||||
extern const MeshExtract extract_lines_adjacency;
|
||||
@@ -391,8 +400,6 @@ extern const MeshExtract extract_edituv_lines;
|
||||
extern const MeshExtract extract_edituv_points;
|
||||
extern const MeshExtract extract_edituv_fdots;
|
||||
extern const MeshExtract extract_uv;
|
||||
extern const MeshExtract extract_tan;
|
||||
extern const MeshExtract extract_tan_hq;
|
||||
extern const MeshExtract extract_sculpt_data;
|
||||
extern const MeshExtract extract_orco;
|
||||
extern const MeshExtract extract_edge_fac;
|
||||
|
||||
@@ -21,12 +21,8 @@
|
||||
|
||||
namespace blender::draw {
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/** \name Extract Tangent layers
|
||||
* \{ */
|
||||
|
||||
static void extract_tan_init_common(const MeshRenderData &mr,
|
||||
MeshBatchCache &cache,
|
||||
const MeshBatchCache &cache,
|
||||
GPUVertFormat *format,
|
||||
GPUVertCompType comp_type,
|
||||
GPUVertFetchMode fetch_mode,
|
||||
@@ -167,12 +163,12 @@ static void extract_tan_init_common(const MeshRenderData &mr,
|
||||
*r_tan_len = tan_len;
|
||||
}
|
||||
|
||||
static void extract_tan_ex_init(const MeshRenderData &mr,
|
||||
MeshBatchCache &cache,
|
||||
gpu::VertBuf *vbo,
|
||||
const bool do_hq)
|
||||
void extract_tangents(const MeshRenderData &mr,
|
||||
const MeshBatchCache &cache,
|
||||
const bool use_hq,
|
||||
gpu::VertBuf &vbo)
|
||||
{
|
||||
GPUVertCompType comp_type = do_hq ? GPU_COMP_I16 : GPU_COMP_I10;
|
||||
GPUVertCompType comp_type = use_hq ? GPU_COMP_I16 : GPU_COMP_I10;
|
||||
GPUVertFetchMode fetch_mode = GPU_FETCH_INT_TO_FLOAT_UNIT;
|
||||
|
||||
GPUVertFormat format = {0};
|
||||
@@ -192,11 +188,11 @@ static void extract_tan_ex_init(const MeshRenderData &mr,
|
||||
tangent_names,
|
||||
&use_orco_tan);
|
||||
|
||||
GPU_vertbuf_init_with_format(vbo, &format);
|
||||
GPU_vertbuf_data_alloc(vbo, v_len);
|
||||
GPU_vertbuf_init_with_format(&vbo, &format);
|
||||
GPU_vertbuf_data_alloc(&vbo, v_len);
|
||||
|
||||
if (do_hq) {
|
||||
short(*tan_data)[4] = (short(*)[4])GPU_vertbuf_get_data(vbo);
|
||||
if (use_hq) {
|
||||
short(*tan_data)[4] = (short(*)[4])GPU_vertbuf_get_data(&vbo);
|
||||
for (int i = 0; i < tan_len; i++) {
|
||||
const char *name = tangent_names[i];
|
||||
const float(*layer_data)[4] = (const float(*)[4])CustomData_get_layer_named(
|
||||
@@ -218,7 +214,7 @@ static void extract_tan_ex_init(const MeshRenderData &mr,
|
||||
}
|
||||
}
|
||||
else {
|
||||
GPUPackedNormal *tan_data = (GPUPackedNormal *)GPU_vertbuf_get_data(vbo);
|
||||
GPUPackedNormal *tan_data = (GPUPackedNormal *)GPU_vertbuf_get_data(&vbo);
|
||||
for (int i = 0; i < tan_len; i++) {
|
||||
const char *name = tangent_names[i];
|
||||
const float(*layer_data)[4] = (const float(*)[4])CustomData_get_layer_named(
|
||||
@@ -243,15 +239,6 @@ static void extract_tan_ex_init(const MeshRenderData &mr,
|
||||
CustomData_free(&corner_data, mr.corners_num);
|
||||
}
|
||||
|
||||
static void extract_tan_init(const MeshRenderData &mr,
|
||||
MeshBatchCache &cache,
|
||||
void *buf,
|
||||
void * /*tls_data*/)
|
||||
{
|
||||
gpu::VertBuf *vbo = static_cast<gpu::VertBuf *>(buf);
|
||||
extract_tan_ex_init(mr, cache, vbo, false);
|
||||
}
|
||||
|
||||
static GPUVertFormat *get_coarse_tan_format()
|
||||
{
|
||||
static GPUVertFormat format = {0};
|
||||
@@ -261,11 +248,10 @@ static GPUVertFormat *get_coarse_tan_format()
|
||||
return &format;
|
||||
}
|
||||
|
||||
static void extract_tan_init_subdiv(const DRWSubdivCache &subdiv_cache,
|
||||
const MeshRenderData &mr,
|
||||
MeshBatchCache &cache,
|
||||
void *buffer,
|
||||
void * /*data*/)
|
||||
void extract_tangents_subdiv(const MeshRenderData &mr,
|
||||
const DRWSubdivCache &subdiv_cache,
|
||||
const MeshBatchCache &cache,
|
||||
gpu::VertBuf &vbo)
|
||||
{
|
||||
GPUVertCompType comp_type = GPU_COMP_F32;
|
||||
GPUVertFetchMode fetch_mode = GPU_FETCH_FLOAT;
|
||||
@@ -286,8 +272,7 @@ static void extract_tan_init_subdiv(const DRWSubdivCache &subdiv_cache,
|
||||
tangent_names,
|
||||
&use_orco_tan);
|
||||
|
||||
gpu::VertBuf *dst_buffer = static_cast<gpu::VertBuf *>(buffer);
|
||||
GPU_vertbuf_init_build_on_device(dst_buffer, &format, subdiv_cache.num_subdiv_loops);
|
||||
GPU_vertbuf_init_build_on_device(&vbo, &format, subdiv_cache.num_subdiv_loops);
|
||||
|
||||
gpu::VertBuf *coarse_vbo = GPU_vertbuf_calloc();
|
||||
/* Dynamic as we upload and interpolate layers one at a time. */
|
||||
@@ -312,8 +297,7 @@ static void extract_tan_init_subdiv(const DRWSubdivCache &subdiv_cache,
|
||||
GPU_vertbuf_tag_dirty(coarse_vbo);
|
||||
/* Include stride in offset. */
|
||||
const int dst_offset = int(subdiv_cache.num_subdiv_loops) * 4 * pack_layer_index++;
|
||||
draw_subdiv_interp_custom_data(
|
||||
subdiv_cache, coarse_vbo, dst_buffer, GPU_COMP_F32, 4, dst_offset);
|
||||
draw_subdiv_interp_custom_data(subdiv_cache, coarse_vbo, &vbo, GPU_COMP_F32, 4, dst_offset);
|
||||
}
|
||||
if (use_orco_tan) {
|
||||
float(*tan_data)[4] = (float(*)[4])GPU_vertbuf_get_data(coarse_vbo);
|
||||
@@ -329,55 +313,11 @@ static void extract_tan_init_subdiv(const DRWSubdivCache &subdiv_cache,
|
||||
GPU_vertbuf_tag_dirty(coarse_vbo);
|
||||
/* Include stride in offset. */
|
||||
const int dst_offset = int(subdiv_cache.num_subdiv_loops) * 4 * pack_layer_index++;
|
||||
draw_subdiv_interp_custom_data(
|
||||
subdiv_cache, coarse_vbo, dst_buffer, GPU_COMP_F32, 4, dst_offset);
|
||||
draw_subdiv_interp_custom_data(subdiv_cache, coarse_vbo, &vbo, GPU_COMP_F32, 4, dst_offset);
|
||||
}
|
||||
|
||||
CustomData_free(&corner_data, mr.corners_num);
|
||||
GPU_vertbuf_discard(coarse_vbo);
|
||||
}
|
||||
|
||||
constexpr MeshExtract create_extractor_tan()
|
||||
{
|
||||
MeshExtract extractor = {nullptr};
|
||||
extractor.init = extract_tan_init;
|
||||
extractor.init_subdiv = extract_tan_init_subdiv;
|
||||
extractor.data_type = MR_DATA_POLY_NOR | MR_DATA_TAN_LOOP_NOR;
|
||||
extractor.data_size = 0;
|
||||
extractor.use_threading = false;
|
||||
extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.tan);
|
||||
return extractor;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/** \name Extract HQ Tangent layers
|
||||
* \{ */
|
||||
|
||||
static void extract_tan_hq_init(const MeshRenderData &mr,
|
||||
MeshBatchCache &cache,
|
||||
void *buf,
|
||||
void * /*tls_data*/)
|
||||
{
|
||||
gpu::VertBuf *vbo = static_cast<gpu::VertBuf *>(buf);
|
||||
extract_tan_ex_init(mr, cache, vbo, true);
|
||||
}
|
||||
|
||||
constexpr MeshExtract create_extractor_tan_hq()
|
||||
{
|
||||
MeshExtract extractor = {nullptr};
|
||||
extractor.init = extract_tan_hq_init;
|
||||
extractor.data_type = MR_DATA_POLY_NOR | MR_DATA_TAN_LOOP_NOR;
|
||||
extractor.data_size = 0;
|
||||
extractor.use_threading = false;
|
||||
extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.tan);
|
||||
return extractor;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
const MeshExtract extract_tan = create_extractor_tan();
|
||||
const MeshExtract extract_tan_hq = create_extractor_tan_hq();
|
||||
|
||||
} // namespace blender::draw
|
||||
|
||||
Reference in New Issue
Block a user