Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/shaders/draw_command_generate_comp.glsl
| /** | /** | ||||
| * Convert DrawPrototype into draw commands. | * Convert DrawPrototype into draw commands. | ||||
| */ | */ | ||||
| #pragma BLENDER_REQUIRE(common_math_lib.glsl) | #pragma BLENDER_REQUIRE(common_math_lib.glsl) | ||||
| #define atomicAddAndGet(dst, val) (atomicAdd(dst, val) + val) | #define atomicAddAndGet(dst, val) (atomicAdd(dst, val) + val) | ||||
| /* This is only called by the last thread executed over the group's prototype draws. */ | /* This is only called by the last thread executed over the group's prototype draws. */ | ||||
| void write_draw_call(DrawGroup group, uint group_id) | void write_draw_call(DrawGroup group, uint group_id) | ||||
| { | { | ||||
| DrawCommand cmd; | DrawCommand cmd; | ||||
| cmd.vertex_len = group.vertex_len; | cmd.vertex_len = group.vertex_len; | ||||
| cmd.vertex_first = group.vertex_first; | cmd.vertex_first = group.vertex_first; | ||||
| if (group.base_index != -1) { | bool indexed_draw = group.base_index != -1; | ||||
| if (indexed_draw) { | |||||
| cmd.base_index = group.base_index; | cmd.base_index = group.base_index; | ||||
| cmd.instance_first_indexed = group.start; | cmd.instance_first_indexed = group.start; | ||||
| } | } | ||||
| else { | else { | ||||
| cmd._instance_first_array = group.start; | cmd._instance_first_array = group.start; | ||||
| } | } | ||||
| /* Back-facing command. */ | /* Back-facing command. */ | ||||
| cmd.instance_len = group_buf[group_id].back_facing_counter; | cmd.instance_len = group_buf[group_id].back_facing_counter; | ||||
| command_buf[group_id * 2 + 0] = cmd; | command_buf[group_id * 2 + 0] = cmd; | ||||
| /* Front-facing command. */ | /* Front-facing command. */ | ||||
| uint front_facing_start = group.start + (group.len - group.front_facing_len); | |||||
| if (indexed_draw) { | |||||
| cmd.instance_first_indexed = front_facing_start; | |||||
| } | |||||
| else { | |||||
| cmd._instance_first_array = front_facing_start; | |||||
| } | |||||
| cmd.instance_len = group_buf[group_id].front_facing_counter; | cmd.instance_len = group_buf[group_id].front_facing_counter; | ||||
| command_buf[group_id * 2 + 1] = cmd; | command_buf[group_id * 2 + 1] = cmd; | ||||
| /* Reset the counters for a next command gen dispatch. Avoids resending the whole data just | /* Reset the counters for a next command gen dispatch. Avoids resending the whole data just | ||||
| * for this purpose. Only the last thread will execute this so it is thread-safe. */ | * for this purpose. Only the last thread will execute this so it is thread-safe. */ | ||||
| group_buf[group_id].front_facing_counter = 0u; | group_buf[group_id].front_facing_counter = 0u; | ||||
| group_buf[group_id].back_facing_counter = 0u; | group_buf[group_id].back_facing_counter = 0u; | ||||
| group_buf[group_id].total_counter = 0u; | group_buf[group_id].total_counter = 0u; | ||||
| ▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines | |||||