SubDiv: Use shader create info for lines shader

This PR migrates the subdiv_ibo_lines_comp.glsl to use
shader create info.

Pull Request: https://projects.blender.org/blender/blender/pulls/134857
This commit is contained in:
Jeroen Bakker
2025-02-21 14:16:57 +01:00
parent 8f00f068ad
commit c436972b2b
6 changed files with 60 additions and 45 deletions

View File

@@ -1532,12 +1532,10 @@ void draw_subdiv_build_lines_buffer(const DRWSubdivCache &cache, gpu::IndexBuf *
GPUShader *shader = DRW_shader_subdiv_get(SubdivShaderType::BUFFER_LINES);
GPU_shader_bind(shader);
int binding_point = 0;
GPU_vertbuf_bind_as_ssbo(cache.subdiv_face_offset_buffer, binding_point++);
GPU_vertbuf_bind_as_ssbo(cache.edges_draw_flag, binding_point++);
GPU_vertbuf_bind_as_ssbo(cache.extra_coarse_face_data, binding_point++);
GPU_indexbuf_bind_as_ssbo(lines_indices, binding_point++);
BLI_assert(binding_point <= MAX_GPU_SUBDIV_SSBOS);
GPU_vertbuf_bind_as_ssbo(cache.subdiv_face_offset_buffer, SUBDIV_FACE_OFFSET_BUF_SLOT);
GPU_vertbuf_bind_as_ssbo(cache.edges_draw_flag, LINES_INPUT_EDGE_DRAW_FLAG_BUF_SLOT);
GPU_vertbuf_bind_as_ssbo(cache.extra_coarse_face_data, LINES_EXTRA_COARSE_FACE_DATA_BUF_SLOT);
GPU_indexbuf_bind_as_ssbo(lines_indices, LINES_OUTPUT_LINES_BUF_SLOT);
drw_subdiv_compute_dispatch(cache, shader, 0, 0, cache.num_subdiv_quads);
@@ -1557,8 +1555,8 @@ void draw_subdiv_build_lines_loose_buffer(const DRWSubdivCache &cache,
GPUShader *shader = DRW_shader_subdiv_get(SubdivShaderType::BUFFER_LINES_LOOSE);
GPU_shader_bind(shader);
GPU_indexbuf_bind_as_ssbo(lines_indices, 3);
GPU_vertbuf_bind_as_ssbo(lines_flags, 4);
GPU_indexbuf_bind_as_ssbo(lines_indices, LINES_OUTPUT_LINES_BUF_SLOT);
GPU_vertbuf_bind_as_ssbo(lines_flags, LINES_LINES_LOOSE_FLAGS);
drw_subdiv_compute_dispatch(cache, shader, 0, 0, num_loose_edges, false, edge_loose_offset);

View File

@@ -133,6 +133,12 @@ static blender::StringRefNull get_subdiv_shader_info_name(SubdivShaderType shade
case SubdivShaderType::BUFFER_CUSTOM_NORMALS_FINALIZE:
return "subdiv_custom_normals_finalize";
case SubdivShaderType::BUFFER_LINES:
return "subdiv_lines";
case SubdivShaderType::BUFFER_LINES_LOOSE:
return "subdiv_lines_loose";
default:
break;
}
@@ -329,9 +335,11 @@ GPUShader *DRW_shader_subdiv_get(SubdivShaderType shader_type)
if (e_data.subdiv_sh[uint(shader_type)] == nullptr &&
ELEM(shader_type,
SubdivShaderType::BUFFER_LINES,
SubdivShaderType::BUFFER_LINES_LOOSE,
SubdivShaderType::BUFFER_NORMALS_ACCUMULATE,
SubdivShaderType::BUFFER_NORMALS_FINALIZE,
SubdivShaderType::BUFFER_CUSTOM_NORMALS_FINALIZE,
SubdivShaderType::BUFFER_NORMALS_ACCUMULATE))
SubdivShaderType::BUFFER_CUSTOM_NORMALS_FINALIZE))
{
blender::StringRefNull create_info_name = get_subdiv_shader_info_name(shader_type);
e_data.subdiv_sh[uint(shader_type)] = GPU_shader_create_from_info_name(
@@ -343,7 +351,6 @@ GPUShader *DRW_shader_subdiv_get(SubdivShaderType shader_type)
std::optional<blender::StringRefNull> defines;
if (ELEM(shader_type,
SubdivShaderType::BUFFER_LINES,
SubdivShaderType::BUFFER_LNOR,
SubdivShaderType::BUFFER_TRIS_MULTIPLE_MATERIALS,
SubdivShaderType::BUFFER_UV_STRETCH_AREA))
@@ -355,9 +362,6 @@ GPUShader *DRW_shader_subdiv_get(SubdivShaderType shader_type)
"#define SUBDIV_POLYGON_OFFSET\n"
"#define SINGLE_MATERIAL\n";
}
else if (shader_type == SubdivShaderType::BUFFER_LINES_LOOSE) {
defines = "#define LINES_LOOSE\n";
}
else if (shader_type == SubdivShaderType::BUFFER_EDGE_FAC) {
/* No separate shader for the AMD driver case as we assume that the GPU will not change
* during the execution of the program. */

View File

@@ -18,6 +18,11 @@
/* Storage buffer bindings */
#define SUBDIV_FACE_OFFSET_BUF_SLOT 0
#define LINES_INPUT_EDGE_DRAW_FLAG_BUF_SLOT 1
#define LINES_EXTRA_COARSE_FACE_DATA_BUF_SLOT 2
#define LINES_OUTPUT_LINES_BUF_SLOT 3
#define LINES_LINES_LOOSE_FLAGS 4
#define NORMALS_ACCUMULATE_POS_NOR_BUF_SLOT 0
#define NORMALS_ACCUMULATE_FACE_ADJACENCY_OFFSETS_BUF_SLOT 1
#define NORMALS_ACCUMULATE_FACE_ADJACENCY_LISTS_BUF_SLOT 2

View File

@@ -31,6 +31,7 @@ set(SRC_GLSL_COMP
draw_view_finalize_comp.glsl
draw_visibility_comp.glsl
subdiv_ibo_lines_comp.glsl
subdiv_normals_accumulate_comp.glsl
subdiv_normals_finalize_comp.glsl
)

View File

@@ -2,50 +2,33 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/* To be compiled with subdiv_lib.glsl */
/* Create index buffer for lines and loose lines. */
#include "subdiv_lib.glsl"
#ifndef LINES_LOOSE
layout(std430, binding = 1) readonly buffer inputEdgeDrawFlag
{
int input_edge_draw_flag[];
};
layout(std430, binding = 2) readonly restrict buffer extraCoarseFaceData
{
uint extra_coarse_face_data[];
};
#endif
layout(std430, binding = 3) writeonly buffer outputLinesIndices
{
uint output_lines[];
};
#ifdef LINES_LOOSE
layout(std430, binding = 4) readonly buffer LinesLooseFlags
{
uint lines_loose_flags[];
};
COMPUTE_SHADER_CREATE_INFO(subdiv_lines)
#else
COMPUTE_SHADER_CREATE_INFO(subdiv_lines_loose)
#endif
#ifndef LINES_LOOSE
bool is_face_hidden(uint coarse_quad_index)
{
return (extra_coarse_face_data[coarse_quad_index] & coarse_face_hidden_mask) != 0;
return (extra_coarse_face_data[coarse_quad_index] & shader_data.coarse_face_hidden_mask) != 0;
}
void emit_line(uint line_offset, uint quad_index, uint start_loop_index, uint corner_index)
{
uint vertex_index = start_loop_index + corner_index;
uint coarse_quad_index = coarse_face_index_from_subdiv_quad_index(quad_index, coarse_face_count);
uint coarse_quad_index = coarse_face_index_from_subdiv_quad_index(quad_index,
shader_data.coarse_face_count);
if (use_hide && is_face_hidden(coarse_quad_index) || (input_edge_draw_flag[vertex_index] == 0)) {
if ((shader_data.use_hide && is_face_hidden(coarse_quad_index)) ||
(input_edge_draw_flag[vertex_index] == 0))
{
output_lines[line_offset + 0] = 0xffffffff;
output_lines[line_offset + 1] = 0xffffffff;
}
@@ -68,8 +51,8 @@ void main()
#ifdef LINES_LOOSE
/* In the loose lines case, we execute for each line, with two vertices per line. */
uint line_offset = edge_loose_offset + index * 2;
uint loop_index = num_subdiv_loops + index * 2;
uint line_offset = shader_data.edge_loose_offset + index * 2;
uint loop_index = shader_data.num_subdiv_loops + index * 2;
if (lines_loose_flags[index] != 0) {
/* Line is hidden. */

View File

@@ -25,6 +25,30 @@ STORAGE_BUF(SUBDIV_FACE_OFFSET_BUF_SLOT, READ, uint, subdiv_face_offset[])
ADDITIONAL_INFO(subdiv_base)
GPU_SHADER_CREATE_END()
/* -------------------------------------------------------------------- */
/** \name Line indices
* \{ */
GPU_SHADER_CREATE_INFO(subdiv_lines)
DO_STATIC_COMPILATION()
STORAGE_BUF(LINES_INPUT_EDGE_DRAW_FLAG_BUF_SLOT, READ, int, input_edge_draw_flag[])
STORAGE_BUF(LINES_EXTRA_COARSE_FACE_DATA_BUF_SLOT, READ, uint, extra_coarse_face_data[])
STORAGE_BUF(LINES_OUTPUT_LINES_BUF_SLOT, WRITE, uint, output_lines[])
COMPUTE_SOURCE("subdiv_ibo_lines_comp.glsl")
ADDITIONAL_INFO(subdiv_polygon_offset_base)
GPU_SHADER_CREATE_END()
GPU_SHADER_CREATE_INFO(subdiv_lines_loose)
DO_STATIC_COMPILATION()
DEFINE("LINES_LOOSE")
STORAGE_BUF(LINES_OUTPUT_LINES_BUF_SLOT, WRITE, uint, output_lines[])
STORAGE_BUF(LINES_LINES_LOOSE_FLAGS, READ, uint, lines_loose_flags[])
COMPUTE_SOURCE("subdiv_ibo_lines_comp.glsl")
ADDITIONAL_INFO(subdiv_base)
GPU_SHADER_CREATE_END()
/** \} */
/* -------------------------------------------------------------------- */
/** \name Normals
* \{ */