54 state.specialization_constants_in_use =
false;
141 if (
state.specialization_constants_in_use ==
false) {
143 state.specialization_constants_in_use =
true;
179 uint instance_first = 0;
181 instance_first =
state.instance_offset;
217 DrawMultiBuf::DrawCommandBuf &indirect_buf =
multi_draw_buf->command_buf_;
221 while (group_index !=
uint(-1)) {
222 const DrawGroup &group = groups[group_index];
238 intptr_t offset = stride * group_index * 2;
242 state.front_facing_set(
true);
247 state.front_facing_set(
false);
252 group_index = group.
next;
302 if (!state_changed && !clip_changed) {
388 return std::string(
".framebuffer_bind(") +
400 return std::string(
".subpass_transition(\n") +
416 return std::string(
".bind_texture") + (
is_reference ?
"_ref" :
"") +
"(" +
417 std::to_string(
slot) +
", sampler=" +
sampler.to_string() +
")";
419 return std::string(
".bind_vertbuf_as_texture") + (
is_reference ?
"_ref" :
"") +
"(" +
420 std::to_string(
slot) +
")";
422 return std::string(
".bind_image") + (
is_reference ?
"_ref" :
"") +
"(" +
423 std::to_string(
slot) +
")";
425 return std::string(
".bind_uniform_buf") + (
is_reference ?
"_ref" :
"") +
"(" +
426 std::to_string(
slot) +
")";
428 return std::string(
".bind_storage_buf") + (
is_reference ?
"_ref" :
"") +
"(" +
429 std::to_string(
slot) +
")";
431 return std::string(
".bind_uniform_as_ssbo") + (
is_reference ?
"_ref" :
"") +
"(" +
432 std::to_string(
slot) +
")";
434 return std::string(
".bind_vertbuf_as_ssbo") + (
is_reference ?
"_ref" :
"") +
"(" +
435 std::to_string(
slot) +
")";
437 return std::string(
".bind_indexbuf_as_ssbo") + (
is_reference ?
"_ref" :
"") +
"(" +
438 std::to_string(
slot) +
")";
447 std::stringstream ss;
535 return std::string(
".push_constant(") + std::to_string(
location) +
", data=" + ss.str() +
")";
540 std::stringstream ss;
567 return std::string(
".specialize_constant(") + std::to_string(
location) +
", data=" + ss.str() +
577 return std::string(
".draw(inst_len=") + inst_len +
", vert_len=" + vert_len +
578 ", vert_first=" + vert_first +
", res_id=" + std::to_string(
res_index.resource_index()) +
592 return (a.group_id < b.group_id) ||
593 (a.group_id == b.group_id && a.res_index > b.res_index);
597 uint prefix_sum = 0u;
599 group.start = prefix_sum;
600 prefix_sum += group.front_facing_counter + group.back_facing_counter;
603 std::stringstream ss;
607 while (group_index !=
uint(-1)) {
608 const DrawGroup &grp = groups[group_index];
610 ss << std::endl << line_prefix <<
" .group(id=" << group_index <<
", len=" << grp.
len <<
")";
612 intptr_t offset = grp.
start;
620 << line_prefix <<
" .proto(instance_len=" << std::to_string(proto.instance_len)
621 <<
", resource_id=" << std::to_string(res_index.
resource_index()) <<
", back_face)";
632 << line_prefix <<
" .proto(instance_len=" << std::to_string(proto.instance_len)
633 <<
", resource_id=" << std::to_string(res_index.
resource_index()) <<
", front_face)";
637 group_index = grp.
next;
643 return line_prefix +
".draw_multi(" + std::to_string(group_len) +
")" + ss.str();
648 return std::string(
".draw_indirect()");
654 return std::string(
".dispatch") + (
is_reference ?
"_ref" :
"") +
"(" + std::to_string(sz.x) +
655 ", " + std::to_string(sz.y) +
", " + std::to_string(sz.z) +
")";
660 return std::string(
".dispatch_indirect()");
666 return std::string(
".barrier(") + std::to_string(
type) +
")";
671 std::stringstream ss;
673 ss <<
"color=" <<
color;
679 ss <<
"depth=" <<
depth;
685 ss <<
"stencil=0b" << std::bitset<8>(
stencil) <<
")";
687 return std::string(
".clear(") + ss.str() +
")";
692 std::stringstream ss;
696 return std::string(
".clear_multi(colors={") + ss.str() +
"})";
702 return std::string(
".state_set(") + std::to_string(
new_state) +
")";
707 std::stringstream ss;
708 ss <<
".stencil_set(write_mask=0b" << std::bitset<8>(
write_mask) <<
", reference=0b"
721 SubPassVector &sub_passes,
722 uint &resource_id_count,
723 ResourceIdBuf &resource_id_buf)
725 for (
const Header &header : headers) {
728 auto &sub = sub_passes[
int64_t(header.index)];
730 sub.headers_, sub.commands_, sub_passes, resource_id_count, resource_id_buf);
737 Draw &cmd = commands[header.index].draw;
739 int batch_vert_len, batch_vert_first, batch_base_index, batch_inst_len;
742 cmd.batch, &batch_vert_len, &batch_vert_first, &batch_base_index, &batch_inst_len);
747 if (cmd.vertex_len ==
uint(-1)) {
748 cmd.vertex_len = batch_vert_len;
756 if (cmd.res_index.raw > 0) {
758 uint instance_first = resource_id_count;
759 resource_id_count += cmd.instance_len;
761 resource_id_buf.get_or_resize(resource_id_count - 1);
764 uint index = cmd.res_index.resource_index();
765 for (
int i = instance_first;
i < (instance_first + cmd.instance_len);
i++) {
766 resource_id_buf[
i] = index;
774 SubPassVector &sub_passes)
778 resource_id_buf_.get_or_resize(0) = 0;
779 resource_id_count_ = 1;
780 finalize_commands(headers, commands, sub_passes, resource_id_count_, resource_id_buf_);
781 resource_id_buf_.push_update();
792 int visibility_word_per_draw,
798 resource_id_count_ = 0u;
801 group.start = resource_id_count_;
802 resource_id_count_ += group.len;
804 int batch_vert_len, batch_vert_first, batch_base_index, batch_inst_len;
812 group.vertex_len = group.desc.vertex_len == 0 ? batch_vert_len : group.desc.vertex_len;
813 group.vertex_first = group.desc.vertex_first == -1 ? batch_vert_first :
814 group.desc.vertex_first;
815 group.base_index = batch_base_index;
824 group.desc.gpu_batch->prim_type,
828 group.desc.expand_prim_len);
830 group.vertex_first = vert_range.
start();
831 group.vertex_len = vert_range.
size();
834 group.base_index = -1;
838 group.total_counter = group.front_facing_counter = group.back_facing_counter = 0;
841 group_buf_.push_update();
842 prototype_buf_.push_update();
844 resource_id_buf_.get_or_resize(resource_id_count_ * view_len * (use_custom_ids ? 2 : 1));
846 command_buf_.get_or_resize(group_count_ * 2);
848 if (prototype_count_ > 0) {
#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)
blender::gpu::Batch * GPU_batch_procedural_points_get()
blender::gpu::Batch * GPU_batch_procedural_triangles_get()
void GPU_batch_draw_indirect(blender::gpu::Batch *batch, blender::gpu::StorageBuf *indirect_buf, intptr_t offset)
void GPU_batch_bind_as_resources(blender::gpu::Batch *batch, blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants=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)
void GPU_batch_set_shader(blender::gpu::Batch *batch, blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_compute_dispatch(blender::gpu::Shader *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)
void GPU_framebuffer_subpass_transition_array(blender::gpu::FrameBuffer *fb, const GPUAttachmentState *attachment_states, uint attachment_len)
void GPU_framebuffer_multi_clear(blender::gpu::FrameBuffer *fb, const float(*clear_colors)[4])
const char * GPU_framebuffer_get_name(blender::gpu::FrameBuffer *fb)
void GPU_framebuffer_clear(blender::gpu::FrameBuffer *fb, GPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, unsigned int clear_stencil)
void GPU_framebuffer_bind(blender::gpu::FrameBuffer *fb)
blender::gpu::FrameBuffer * GPU_framebuffer_active_get()
void GPU_indexbuf_bind_as_ssbo(blender::gpu::IndexBuf *elem, int binding)
void GPU_shader_uniform_1b(blender::gpu::Shader *sh, const char *name, bool value)
const blender::gpu::shader::SpecializationConstants & GPU_shader_get_default_constant_state(blender::gpu::Shader *sh)
void GPU_shader_bind(blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
int GPU_shader_get_ssbo_binding(blender::gpu::Shader *shader, const char *name)
void GPU_shader_uniform_int_ex(blender::gpu::Shader *shader, int location, int length, int array_size, const int *value)
void GPU_shader_uniform_1i(blender::gpu::Shader *sh, const char *name, int value)
const char * GPU_shader_get_name(blender::gpu::Shader *shader)
void GPU_shader_uniform_float_ex(blender::gpu::Shader *shader, int location, int length, int array_size, const float *value)
void GPU_program_point_size(bool enable)
@ GPU_BARRIER_SHADER_STORAGE
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_state_set(GPUWriteMask write_mask, GPUBlend blend, GPUFaceCullTest culling_test, GPUDepthTest depth_test, GPUStencilTest stencil_test, GPUStencilOp stencil_op, GPUProvokingVertex provoking_vert)
void GPU_stencil_reference_set(uint reference)
void GPU_stencil_compare_mask_set(uint compare_mask)
void GPU_memory_barrier(GPUBarrier barrier)
void GPU_point_size(float size)
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(blender::gpu::StorageBuf *ssbo, int slot)
void GPU_storagebuf_debug_unbind_all()
void GPU_storagebuf_sync_as_indirect_buffer(blender::gpu::StorageBuf *ssbo)
void GPU_texture_image_unbind_all()
void GPU_texture_bind_ex(blender::gpu::Texture *texture, GPUSamplerState state, int unit)
void GPU_texture_image_bind(blender::gpu::Texture *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
blender::gpu::Shader * 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(blender::gpu::Shader *shader, blender::gpu::StorageBuf *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 GPUFaceCullTest to_face_cull_test(DRWState state)
static GPUWriteMask to_write_mask(DRWState state)
static GPUDepthTest to_depth_test(DRWState state)
static GPUStencilOp to_stencil_op(DRWState state)
static GPUBlend to_blend(DRWState state)
static GPUProvokingVertex to_provoking_vertex(DRWState state)
static GPUStencilTest to_stencil_test(DRWState state)
StorageArrayBuffer< uint, 4, true > VisibilityBuf
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
std::string serialize() const
void execute(RecordingState &state) const
gpu::StorageBuf ** indirect_buf
std::string serialize() const
void execute(RecordingState &state) const
uint32_t expand_prim_type
struct blender::draw::command::DrawGroup::@065172161005140006364026044166345126204356255202 desc
uint front_facing_counter
void execute(RecordingState &state) const
std::string serialize() const
gpu::StorageBuf ** 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
gpu::FrameBuffer ** 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
gpu::UniformBuf * uniform_buf
gpu::Texture ** texture_ref
gpu::VertBuf * vertex_buf
enum blender::draw::command::ResourceBind::Type type
gpu::VertBuf ** vertex_buf_ref
gpu::UniformBuf ** uniform_buf_ref
gpu::IndexBuf * index_buf
gpu::StorageBuf * storage_buf
std::string serialize() const
gpu::IndexBuf ** index_buf_ref
gpu::StorageBuf ** storage_buf_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