54 state.specialization_constants_in_use =
false;
141 if (
state.specialization_constants_in_use ==
false) {
143 state.specialization_constants_in_use =
true;
176 state.front_facing_set(
handle.has_inverted_handedness());
183 uint instance_first = 0;
185 instance_first =
state.instance_offset;
221 DrawMultiBuf::DrawCommandBuf &indirect_buf =
multi_draw_buf->command_buf_;
225 while (group_index !=
uint(-1)) {
226 const DrawGroup &group = groups[group_index];
246 intptr_t offset = stride * group_index * 2;
250 state.front_facing_set(
true);
255 state.front_facing_set(
false);
260 group_index = group.
next;
266 state.front_facing_set(
handle.has_inverted_handedness());
310 if (!state_changed && !clip_changed) {
396 return std::string(
".framebuffer_bind(") +
408 return std::string(
".subpass_transition(\n") +
424 return std::string(
".bind_texture") + (
is_reference ?
"_ref" :
"") +
"(" +
425 std::to_string(
slot) +
", sampler=" +
sampler.to_string() +
")";
427 return std::string(
".bind_vertbuf_as_texture") + (
is_reference ?
"_ref" :
"") +
"(" +
428 std::to_string(
slot) +
")";
430 return std::string(
".bind_image") + (
is_reference ?
"_ref" :
"") +
"(" +
431 std::to_string(
slot) +
")";
433 return std::string(
".bind_uniform_buf") + (
is_reference ?
"_ref" :
"") +
"(" +
434 std::to_string(
slot) +
")";
436 return std::string(
".bind_storage_buf") + (
is_reference ?
"_ref" :
"") +
"(" +
437 std::to_string(
slot) +
")";
439 return std::string(
".bind_uniform_as_ssbo") + (
is_reference ?
"_ref" :
"") +
"(" +
440 std::to_string(
slot) +
")";
442 return std::string(
".bind_vertbuf_as_ssbo") + (
is_reference ?
"_ref" :
"") +
"(" +
443 std::to_string(
slot) +
")";
445 return std::string(
".bind_indexbuf_as_ssbo") + (
is_reference ?
"_ref" :
"") +
"(" +
446 std::to_string(
slot) +
")";
455 std::stringstream ss;
543 return std::string(
".push_constant(") + std::to_string(
location) +
", data=" + ss.str() +
")";
548 std::stringstream ss;
575 return std::string(
".specialize_constant(") + std::to_string(
location) +
", data=" + ss.str() +
585 return std::string(
".draw(inst_len=") + inst_len +
", vert_len=" + vert_len +
586 ", vert_first=" + vert_first +
", res_id=" + std::to_string(
handle.resource_index()) +
600 return (a.group_id < b.group_id) ||
601 (a.group_id == b.group_id && a.res_handle > b.res_handle);
605 uint prefix_sum = 0u;
607 group.start = prefix_sum;
608 prefix_sum += group.front_facing_counter + group.back_facing_counter;
611 std::stringstream ss;
615 while (group_index !=
uint(-1)) {
616 const DrawGroup &grp = groups[group_index];
618 ss << std::endl << line_prefix <<
" .group(id=" << group_index <<
", len=" << grp.
len <<
")";
620 intptr_t offset = grp.
start;
628 << line_prefix <<
" .proto(instance_len=" << std::to_string(proto.instance_len)
629 <<
", resource_id=" << std::to_string(handle.
resource_index()) <<
", back_face)";
640 << line_prefix <<
" .proto(instance_len=" << std::to_string(proto.instance_len)
641 <<
", resource_id=" << std::to_string(handle.
resource_index()) <<
", front_face)";
645 group_index = grp.
next;
651 return line_prefix +
".draw_multi(" + std::to_string(group_len) +
")" + ss.str();
656 return std::string(
".draw_indirect()");
662 return std::string(
".dispatch") + (
is_reference ?
"_ref" :
"") +
"(" + std::to_string(sz.x) +
663 ", " + std::to_string(sz.y) +
", " + std::to_string(sz.z) +
")";
668 return std::string(
".dispatch_indirect()");
674 return std::string(
".barrier(") + std::to_string(
type) +
")";
679 std::stringstream ss;
681 ss <<
"color=" <<
color;
687 ss <<
"depth=" <<
depth;
693 ss <<
"stencil=0b" << std::bitset<8>(
stencil) <<
")";
695 return std::string(
".clear(") + ss.str() +
")";
700 std::stringstream ss;
704 return std::string(
".clear_multi(colors={") + ss.str() +
"})";
710 return std::string(
".state_set(") + std::to_string(
new_state) +
")";
715 std::stringstream ss;
716 ss <<
".stencil_set(write_mask=0b" << std::bitset<8>(
write_mask) <<
", reference=0b"
729 SubPassVector &sub_passes,
730 uint &resource_id_count,
731 ResourceIdBuf &resource_id_buf)
733 for (
const Header &header : headers) {
736 auto &sub = sub_passes[
int64_t(header.index)];
738 sub.headers_, sub.commands_, sub_passes, resource_id_count, resource_id_buf);
745 Draw &cmd = commands[header.index].draw;
747 int batch_vert_len, batch_vert_first, batch_base_index, batch_inst_len;
750 cmd.batch, &batch_vert_len, &batch_vert_first, &batch_base_index, &batch_inst_len);
755 if (cmd.vertex_len ==
uint(-1)) {
756 cmd.vertex_len = batch_vert_len;
764 if (cmd.handle.raw > 0) {
766 uint instance_first = resource_id_count;
767 resource_id_count += cmd.instance_len;
769 resource_id_buf.get_or_resize(resource_id_count - 1);
772 uint index = cmd.handle.resource_index();
773 for (
int i = instance_first;
i < (instance_first + cmd.instance_len);
i++) {
774 resource_id_buf[
i] = index;
782 SubPassVector &sub_passes)
786 resource_id_buf_.get_or_resize(0) = 0;
787 resource_id_count_ = 1;
788 finalize_commands(headers, commands, sub_passes, resource_id_count_, resource_id_buf_);
789 resource_id_buf_.push_update();
795 state.resource_id_buf = resource_id_buf_;
805 int visibility_word_per_draw,
811 resource_id_count_ = 0u;
814 group.start = resource_id_count_;
815 resource_id_count_ += group.len;
817 int batch_vert_len, batch_vert_first, batch_base_index, batch_inst_len;
825 group.vertex_len = group.desc.vertex_len == 0 ? batch_vert_len : group.desc.vertex_len;
826 group.vertex_first = group.desc.vertex_first == -1 ? batch_vert_first :
827 group.desc.vertex_first;
828 group.base_index = batch_base_index;
837 group.desc.gpu_batch->prim_type,
841 group.desc.expand_prim_len);
843 group.vertex_first = vert_range.
start();
844 group.vertex_len = vert_range.
size();
847 group.base_index = -1;
851 group.total_counter = group.front_facing_counter = group.back_facing_counter = 0;
854 group_buf_.push_update();
855 prototype_buf_.push_update();
857 resource_id_buf_.get_or_resize(resource_id_count_ * view_len * (use_custom_ids ? 2 : 1));
859 command_buf_.get_or_resize(group_count_ * 2);
861 if (prototype_count_ > 0) {
891 state.resource_id_buf = resource_id_buf_;
#define BLI_assert_unreachable()
MINLINE unsigned int log2_ceil_u(unsigned int x)
MINLINE uint divide_ceil_u(uint a, uint b)
#define UNUSED_VARS_NDEBUG(...)
blender::gpu::Batch * GPU_batch_procedural_triangle_strips_get()
blender::gpu::Batch * GPU_batch_procedural_lines_get()
void GPU_batch_draw_advanced(blender::gpu::Batch *batch, int vertex_first, int vertex_count, int instance_first, int instance_count)
blender::IndexRange GPU_batch_draw_expanded_parameter_get(GPUPrimType input_prim_type, GPUPrimType output_prim_type, int vertex_count, int vertex_first, int output_primitive_cout)
void GPU_batch_draw_indirect(blender::gpu::Batch *batch, GPUStorageBuf *indirect_buf, intptr_t offset)
void GPU_batch_resource_id_buf_set(blender::gpu::Batch *batch, GPUStorageBuf *resource_id_buf)
blender::gpu::Batch * GPU_batch_procedural_points_get()
void GPU_batch_bind_as_resources(blender::gpu::Batch *batch, GPUShader *shader, const blender::gpu::shader::SpecializationConstants *constants=nullptr)
blender::gpu::Batch * GPU_batch_procedural_triangles_get()
void GPU_batch_set_shader(blender::gpu::Batch *batch, GPUShader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_batch_draw_parameter_get(blender::gpu::Batch *batch, int *r_vertex_count, int *r_vertex_first, int *r_base_index, int *r_instance_count)
bool GPU_shader_draw_parameters_support()
void GPU_compute_dispatch(GPUShader *shader, uint groups_x_len, uint groups_y_len, uint groups_z_len, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_debug_group_end()
void GPU_debug_group_begin(const char *name)
const char * GPU_framebuffer_get_name(GPUFrameBuffer *fb)
GPUFrameBuffer * GPU_framebuffer_active_get()
void GPU_framebuffer_subpass_transition_array(GPUFrameBuffer *fb, const GPUAttachmentState *attachment_states, uint attachment_len)
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
void GPU_framebuffer_multi_clear(GPUFrameBuffer *fb, const float(*clear_colors)[4])
void GPU_framebuffer_clear(GPUFrameBuffer *fb, eGPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, unsigned int clear_stencil)
void GPU_indexbuf_bind_as_ssbo(blender::gpu::IndexBuf *elem, int binding)
const char * GPU_shader_get_name(GPUShader *shader)
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
void GPU_shader_uniform_int_ex(GPUShader *shader, int location, int length, int array_size, const int *value)
void GPU_shader_bind(GPUShader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
int GPU_shader_get_ssbo_binding(GPUShader *shader, const char *name)
void GPU_shader_uniform_float_ex(GPUShader *shader, int location, int length, int array_size, const float *value)
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value)
const blender::gpu::shader::SpecializationConstants & GPU_shader_get_default_constant_state(GPUShader *sh)
void GPU_memory_barrier(eGPUBarrier barrier)
void GPU_program_point_size(bool enable)
void GPU_line_width(float width)
void GPU_line_smooth(bool enable)
void GPU_stencil_write_mask_set(uint write_mask)
void GPU_depth_range(float near, float far)
void GPU_stencil_reference_set(uint reference)
@ GPU_BARRIER_SHADER_STORAGE
@ GPU_BARRIER_VERTEX_ATTRIB_ARRAY
void GPU_stencil_compare_mask_set(uint compare_mask)
void GPU_point_size(float size)
void GPU_state_set(eGPUWriteMask write_mask, eGPUBlend blend, eGPUFaceCullTest culling_test, eGPUDepthTest depth_test, eGPUStencilTest stencil_test, eGPUStencilOp stencil_op, eGPUProvokingVertex provoking_vert)
void GPU_clip_control_unit_range(bool enable)
void GPU_clip_distances(int distances_enabled)
void GPU_shadow_offset(bool enable)
void GPU_storagebuf_bind(GPUStorageBuf *ssbo, int slot)
void GPU_storagebuf_sync_as_indirect_buffer(GPUStorageBuf *ssbo)
void GPU_storagebuf_debug_unbind_all()
void GPU_texture_bind_ex(GPUTexture *texture, GPUSamplerState state, int unit)
void GPU_texture_image_unbind_all()
void GPU_texture_image_bind(GPUTexture *texture, int unit)
void GPU_texture_unbind_all()
void GPU_vertbuf_bind_as_ssbo(blender::gpu::VertBuf *verts, int binding)
void GPU_vertbuf_bind_as_texture(blender::gpu::VertBuf *verts, int binding)
constexpr int64_t size() const
constexpr bool is_empty() const
constexpr int64_t start() const
constexpr MutableSpan slice_safe(const int64_t start, const int64_t size) const
constexpr T * end() const
constexpr T * begin() const
void generate_commands(Vector< Header, 0 > &headers, Vector< Undetermined, 0 > &commands, SubPassVector &sub_passes)
void bind(RecordingState &state)
void generate_commands(Vector< Header, 0 > &headers, Vector< Undetermined, 0 > &commands, VisibilityBuf &visibility_buf, int visibility_word_per_draw, int view_len, bool use_custom_ids)
void bind(RecordingState &state)
#define DRW_RESOURCE_ID_SLOT
#define DRW_COMMAND_GROUP_SIZE
GPUShader * DRW_shader_draw_command_generate_get()
@ DRW_STATE_IN_FRONT_SELECT
@ DRW_STATE_PROGRAM_POINT_SIZE
@ DRW_STATE_CLIP_CONTROL_UNIT_RANGE
@ DRW_STATE_SHADOW_OFFSET
void GPU_compute_dispatch_indirect(GPUShader *shader, GPUStorageBuf *indirect_buf_, const blender::gpu::shader::SpecializationConstants *constants_state)
BLI_INLINE float fb(float length, float L)
static gpu::Batch * procedural_batch_get(GPUPrimType primitive)
static eGPUDepthTest to_depth_test(DRWState state)
static eGPUBlend to_blend(DRWState state)
static eGPUProvokingVertex to_provoking_vertex(DRWState state)
static eGPUStencilOp to_stencil_op(DRWState state)
static eGPUStencilTest to_stencil_test(DRWState state)
static eGPUWriteMask to_write_mask(DRWState state)
StorageArrayBuffer< uint, 4, true > VisibilityBuf
static eGPUFaceCullTest to_face_cull_test(DRWState state)
bool assign_if_different(T &old_value, T new_value)
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< int32_t, 3 > int3
bool has_inverted_handedness() const
uint resource_index() const
std::string serialize() const
std::string serialize() const
std::string serialize() const
GPUStorageBuf ** indirect_buf
std::string serialize() const
void execute(RecordingState &state) const
std::string serialize() const
void execute(RecordingState &state) const
uint32_t expand_prim_type
struct blender::draw::command::DrawGroup::@251306170140361114007106001100121365211105052341 desc
uint front_facing_counter
void execute(RecordingState &state) const
std::string serialize() const
GPUStorageBuf ** indirect_buf
std::string serialize(const std::string &line_prefix) const
DrawMultiBuf * multi_draw_buf
void execute(RecordingState &state) const
bool is_primitive_expansion() const
void execute(RecordingState &state) const
std::string serialize() const
GPUFrameBuffer ** framebuffer
std::string serialize() const
void execute(RecordingState &state) const
const float4 * float4_ref
std::string serialize() const
enum blender::draw::command::PushConstant::Type type
const float3 * float3_ref
const float2 * float2_ref
const float4x4 * float4x4_ref
GPUStorageBuf ** storage_buf_ref
gpu::VertBuf * vertex_buf
GPUUniformBuf ** uniform_buf_ref
enum blender::draw::command::ResourceBind::Type type
GPUStorageBuf * storage_buf
gpu::VertBuf ** vertex_buf_ref
GPUUniformBuf * uniform_buf
gpu::IndexBuf * index_buf
std::string serialize() const
gpu::IndexBuf ** index_buf_ref
GPUTexture ** texture_ref
void execute(RecordingState &state) const
std::string serialize() const
void execute(RecordingState &state) const
enum blender::draw::command::SpecializeConstant::Type type
std::string serialize() const
std::string serialize() const
void execute(RecordingState &state) const
static void set(DRWState state=DRW_STATE_DEFAULT)
std::string serialize() const
std::string serialize() const