Blender V5.3
draw_command.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "GPU_batch.hh"
10#include "GPU_capabilities.hh"
11#include "GPU_compute.hh"
12#include "GPU_debug.hh"
13
14#include "draw_command.hh"
15#include "draw_pass.hh"
16#include "draw_shader.hh"
17#include "draw_view.hh"
18
19#include <bitset>
20#include <sstream>
21
23
24static gpu::Batch *procedural_batch_get(GPUPrimType primitive)
25{
26 switch (primitive) {
27 case GPU_PRIM_POINTS:
29 case GPU_PRIM_LINES:
31 case GPU_PRIM_TRIS:
35 default:
36 /* Add new one as needed. */
38 return nullptr;
39 }
40}
41
42/* -------------------------------------------------------------------- */
45
47{
48 state.shader_use_specialization = !GPU_shader_get_default_constant_state(shader).is_empty();
49 if (assign_if_different(state.shader, shader) || state.shader_use_specialization) {
50 GPU_shader_bind(shader, state.specialization_constants_get());
51 }
52 /* Signal that we can reload the default for a different specialization later on.
53 * However, we keep the specialization_constants state around for compute shaders. */
54 state.specialization_constants_in_use = false;
55}
56
61
63{
64 /* TODO(fclem): Require framebuffer bind to always be part of the pass so that we can track it
65 * inside RecordingState. */
67 /* Unpack to the real enum type. */
68 const GPUAttachmentState states[9] = {
78 };
79 GPU_framebuffer_subpass_transition_array(framebuffer, states, ARRAY_SIZE(states));
80}
81
83{
84 if (slot == -1) {
85 return;
86 }
87 switch (type) {
90 break;
92 GPU_vertbuf_bind_as_texture(is_reference ? *vertex_buf_ref : vertex_buf, slot);
93 break;
96 break;
98 GPU_uniformbuf_bind(is_reference ? *uniform_buf_ref : uniform_buf, slot);
99 break;
101 GPU_storagebuf_bind(is_reference ? *storage_buf_ref : storage_buf, slot);
102 break;
104 GPU_uniformbuf_bind_as_ssbo(is_reference ? *uniform_buf_ref : uniform_buf, slot);
105 break;
107 GPU_vertbuf_bind_as_ssbo(is_reference ? *vertex_buf_ref : vertex_buf, slot);
108 break;
110 GPU_indexbuf_bind_as_ssbo(is_reference ? *index_buf_ref : index_buf, slot);
111 break;
113 tlas->bind(slot);
114 break;
115 }
116}
117
119{
120 if (location == -1) {
121 return;
122 }
123 switch (type) {
126 break;
129 break;
132 break;
135 break;
136 }
137}
138
140{
141 /* All specialization constants should exist as they are not optimized out like uniforms. */
142 BLI_assert(location != -1);
143
144 if (state.specialization_constants_in_use == false) {
145 state.specialization_constants = GPU_shader_get_default_constant_state(this->shader);
146 state.specialization_constants_in_use = true;
147 }
148
149 switch (type) {
151 state.specialization_constants.set_value(location, int_value);
152 break;
154 state.specialization_constants.set_value(location, *int_ref);
155 break;
157 state.specialization_constants.set_value(location, uint_value);
158 break;
160 state.specialization_constants.set_value(location, *uint_ref);
161 break;
163 state.specialization_constants.set_value(location, float_value);
164 break;
166 state.specialization_constants.set_value(location, *float_ref);
167 break;
169 state.specialization_constants.set_value(location, bool_value);
170 break;
172 state.specialization_constants.set_value(location, *bool_ref);
173 break;
174 }
175}
176
178{
179 state.front_facing_set(res_id.has_inverted_handedness());
180
181 /* Use same logic as in `finalize_commands`. */
182 uint instance_first = 0;
183 if (res_id.raw > 0) {
184 instance_first = state.instance_offset;
185 state.instance_offset += instance_len;
186 }
187
189
191 /* Expanded draw-call. */
193 batch->prim_type,
198
199 if (expanded_range.is_empty()) {
200 /* Nothing to draw, and can lead to asserts in GPU_batch_bind_as_resources. */
201 return;
202 }
203
204 GPU_batch_bind_as_resources(batch, state.shader, state.specialization_constants_get());
205
206 gpu::Batch *gpu_batch = procedural_batch_get(GPUPrimType(expand_prim_type));
207 GPU_batch_set_shader(gpu_batch, state.shader, state.specialization_constants_get());
209 gpu_batch, expanded_range.start(), expanded_range.size(), instance_first, instance_len);
210 }
211 else {
212 /* Regular draw-call. */
213 GPU_batch_set_shader(batch, state.shader, state.specialization_constants_get());
215 }
216}
217
219{
220 DrawMultiBuf::DrawCommandBuf &indirect_buf = multi_draw_buf->command_buf_;
221 DrawMultiBuf::DrawGroupBuf &groups = multi_draw_buf->group_buf_;
222
223 uint group_index = this->group_first;
224 while (group_index != uint(-1)) {
225 const DrawGroup &group = groups[group_index];
226
227 if (group.vertex_len > 0) {
228 gpu::Batch *batch = group.desc.gpu_batch;
229
230 if (GPUPrimType(group.desc.expand_prim_type) != GPU_PRIM_NONE) {
231 /* Bind original batch as resource and use a procedural batch to issue the draw-call. */
233 group.desc.gpu_batch, state.shader, state.specialization_constants_get());
234 batch = procedural_batch_get(GPUPrimType(group.desc.expand_prim_type));
235 }
236
237 GPU_batch_set_shader(batch, state.shader, state.specialization_constants_get());
238
239 constexpr intptr_t stride = sizeof(DrawCommand);
240 /* We have 2 indirect command reserved per draw group. */
241 intptr_t offset = stride * group_index * 2;
242
243 /* Draw negatively scaled geometry first. */
244 if (group.len - group.front_facing_len > 0) {
245 state.front_facing_set(true);
246 GPU_batch_draw_indirect(batch, indirect_buf, offset);
247 }
248
249 if (group.front_facing_len > 0) {
250 state.front_facing_set(false);
251 GPU_batch_draw_indirect(batch, indirect_buf, offset + stride);
252 }
253 }
254
255 group_index = group.next;
256 }
257}
258
265
267{
268 if (is_reference) {
270 state.shader, size_ref->x, size_ref->y, size_ref->z, state.specialization_constants_get());
271 }
272 else {
274 state.shader, size.x, size.y, size.z, state.specialization_constants_get());
275 }
276}
277
279{
280 GPU_compute_dispatch_indirect(state.shader, *indirect_buf, state.specialization_constants_get());
281}
282
284{
286}
287
293
299
300void StateSet::execute(RecordingState &recording_state) const
301{
302 bool state_changed = assign_if_different(recording_state.pipeline_state, new_state);
303 bool clip_changed = assign_if_different(recording_state.clip_plane_count, clip_plane_count);
304
305 if (!state_changed && !clip_changed) {
306 return;
307 }
308
309 GPU_state_set(to_write_mask(new_state),
310 to_blend(new_state),
311 to_face_cull_test(new_state),
312 to_depth_test(new_state),
313 to_stencil_test(new_state),
314 to_stencil_op(new_state),
315 to_provoking_vertex(new_state));
316
319 }
320 else {
322 }
323
324 /* TODO: this should be part of shader state. */
325 GPU_clip_distances(recording_state.clip_plane_count);
326
329 }
330 else {
332 }
333}
334
336{
337 RecordingState recording_state;
338 StateSet{state, 0}.execute(recording_state);
339
340 /* This function is used for cleaning the state for the viewport drawing.
341 * Make sure to reset textures resources to avoid feedback loop when rendering (see #131652). */
346
347 /* Remained of legacy draw manager. Kept it to avoid regression, but might become unneeded. */
349 GPU_line_smooth(false);
350 GPU_line_width(0.0f);
351}
352
359
361{
362 gpu::Texture *exec_src = src_is_ref ? *src_ref : src;
363 gpu::Texture *exec_dst = dst_is_ref ? *dst_ref : dst;
364
365 if (!GPU_texture_is_view(exec_src) && !GPU_texture_is_view(exec_dst)) {
366 GPU_texture_copy(exec_dst, exec_src);
367 return;
368 }
369
370 /* WORKAROUND: There are some issues with copies involving texture views.
371 * Needed for the EEVEE Prepass depth copy. */
372 /* TODO(@pragma37): This path should be removed in 5.3 once #158607 lands. */
374 gpu::FrameBuffer *src_fb = GPU_framebuffer_create("TextureCopy-tmp-src");
375 gpu::FrameBuffer *dst_fb = GPU_framebuffer_create("TextureCopy-tmp-dst");
379 GPU_framebuffer_free(src_fb);
380 GPU_framebuffer_free(dst_fb);
381}
382
384
385/* -------------------------------------------------------------------- */
388
389std::string ShaderBind::serialize() const
390{
391 return std::string(".shader_bind(") + GPU_shader_get_name(shader) + ")";
392}
393
394std::string FramebufferBind::serialize() const
395{
396 return std::string(".framebuffer_bind(") +
397 (*framebuffer == nullptr ? "nullptr" : GPU_framebuffer_get_name(*framebuffer)) + ")";
398}
399
401{
402 auto to_str = [](GPUAttachmentState state) {
403 return (state != GPU_ATTACHMENT_IGNORE) ?
404 ((state == GPU_ATTACHMENT_WRITE) ? "write" : "read") :
405 "ignore";
406 };
407
408 return std::string(".subpass_transition(\n") +
409 "depth=" + to_str(GPUAttachmentState(depth_state)) + ",\n" +
410 "color0=" + to_str(GPUAttachmentState(color_states[0])) + ",\n" +
411 "color1=" + to_str(GPUAttachmentState(color_states[1])) + ",\n" +
412 "color2=" + to_str(GPUAttachmentState(color_states[2])) + ",\n" +
413 "color3=" + to_str(GPUAttachmentState(color_states[3])) + ",\n" +
414 "color4=" + to_str(GPUAttachmentState(color_states[4])) + ",\n" +
415 "color5=" + to_str(GPUAttachmentState(color_states[5])) + ",\n" +
416 "color6=" + to_str(GPUAttachmentState(color_states[6])) + ",\n" +
417 "color7=" + to_str(GPUAttachmentState(color_states[7])) + "\n)";
418}
419
420std::string ResourceBind::serialize() const
421{
422 switch (type) {
423 case Type::Sampler:
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) + ")";
429 case Type::Image:
430 return std::string(".bind_image") + (is_reference ? "_ref" : "") + "(" +
431 std::to_string(slot) + ")";
432 case Type::UniformBuf:
433 return std::string(".bind_uniform_buf") + (is_reference ? "_ref" : "") + "(" +
434 std::to_string(slot) + ")";
435 case Type::StorageBuf:
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) + ")";
447 default:
449 return "";
450 }
451}
452
453std::string PushConstant::serialize() const
454{
455 std::stringstream ss;
456 for (int i = 0; i < array_len; i++) {
457 switch (comp_len) {
458 case 1:
459 switch (type) {
460 case Type::IntValue:
461 ss << int1_value;
462 break;
464 ss << int_ref[i];
465 break;
466 case Type::FloatValue:
467 ss << float1_value;
468 break;
470 ss << float_ref[i];
471 break;
472 }
473 break;
474 case 2:
475 switch (type) {
476 case Type::IntValue:
477 ss << int2_value;
478 break;
480 ss << int2_ref[i];
481 break;
482 case Type::FloatValue:
483 ss << float2_value;
484 break;
486 ss << float2_ref[i];
487 break;
488 }
489 break;
490 case 3:
491 switch (type) {
492 case Type::IntValue:
493 ss << int3_value;
494 break;
496 ss << int3_ref[i];
497 break;
498 case Type::FloatValue:
499 ss << float3_value;
500 break;
502 ss << float3_ref[i];
503 break;
504 }
505 break;
506 case 4:
507 switch (type) {
508 case Type::IntValue:
509 ss << int4_value;
510 break;
512 ss << int4_ref[i];
513 break;
514 case Type::FloatValue:
515 ss << float4_value;
516 break;
518 ss << float4_ref[i];
519 break;
520 }
521 break;
522 case 16:
523 switch (type) {
524 case Type::IntValue:
527 break;
528 case Type::FloatValue:
529 ss << float4x4(
530 (&float4_value)[0], (&float4_value)[1], (&float4_value)[2], (&float4_value)[3]);
531 break;
533 ss << *float4x4_ref;
534 break;
535 }
536 break;
537 }
538 if (i < array_len - 1) {
539 ss << ", ";
540 }
541 }
542
543 return std::string(".push_constant(") + std::to_string(location) + ", data=" + ss.str() + ")";
544}
545
547{
548 std::stringstream ss;
549 switch (type) {
550 case Type::IntValue:
551 ss << int_value;
552 break;
553 case Type::UintValue:
554 ss << uint_value;
555 break;
556 case Type::FloatValue:
557 ss << float_value;
558 break;
559 case Type::BoolValue:
560 ss << bool_value;
561 break;
563 ss << *int_ref;
564 break;
566 ss << *uint_ref;
567 break;
569 ss << *float_ref;
570 break;
572 ss << *bool_ref;
573 break;
574 }
575 return std::string(".specialize_constant(") + std::to_string(location) + ", data=" + ss.str() +
576 ")";
577}
578
579std::string Draw::serialize() const
580{
581 std::string inst_len = std::to_string(instance_len);
582 std::string vert_len = (vertex_len == uint(-1)) ? "from_batch" : std::to_string(vertex_len);
583 std::string vert_first = (vertex_first == uint(-1)) ? "from_batch" :
584 std::to_string(vertex_first);
585 return std::string(".draw(inst_len=") + inst_len + ", vert_len=" + vert_len +
586 ", vert_first=" + vert_first + ", res_id=" + std::to_string(res_id.index()) + ")";
587}
588
589std::string DrawMulti::serialize(const std::string &line_prefix) const
590{
591 DrawMultiBuf::DrawGroupBuf &groups = multi_draw_buf->group_buf_;
592
593 MutableSpan<DrawPrototype> prototypes(multi_draw_buf->prototype_buf_.data(),
594 multi_draw_buf->prototype_count_);
595
596 /* This emulates the GPU sorting but without the unstable draw order. */
597 std::ranges::sort(prototypes, [](const DrawPrototype &a, const DrawPrototype &b) {
598 return (a.group_id < b.group_id) || (a.group_id == b.group_id && a.res_id > b.res_id);
599 });
600
601 /* Compute prefix sum to have correct offsets. */
602 uint prefix_sum = 0u;
603 for (DrawGroup &group : groups) {
604 group.start = prefix_sum;
605 prefix_sum += group.front_facing_counter + group.back_facing_counter;
606 }
607
608 std::stringstream ss;
609
610 uint group_len = 0;
611 uint group_index = this->group_first;
612 while (group_index != uint(-1)) {
613 const DrawGroup &grp = groups[group_index];
614
615 ss << std::endl << line_prefix << " .group(id=" << group_index << ", len=" << grp.len << ")";
616
617 intptr_t offset = grp.start;
618
619 if (grp.back_facing_counter > 0) {
620 for (DrawPrototype &proto : prototypes.slice_safe({offset, grp.back_facing_counter})) {
621 BLI_assert(proto.group_id == group_index);
622 ResourceID res_id(proto.res_id);
624 ss << std::endl
625 << line_prefix << " .proto(instance_len=" << std::to_string(proto.instance_len)
626 << ", resource_id=" << std::to_string(res_id.index()) << ", back_face)";
627 }
628 offset += grp.back_facing_counter;
629 }
630
631 if (grp.front_facing_counter > 0) {
632 for (DrawPrototype &proto : prototypes.slice_safe({offset, grp.front_facing_counter})) {
633 BLI_assert(proto.group_id == group_index);
634 ResourceID res_id(proto.res_id);
636 ss << std::endl
637 << line_prefix << " .proto(instance_len=" << std::to_string(proto.instance_len)
638 << ", resource_id=" << std::to_string(res_id.index()) << ", front_face)";
639 }
640 }
641
642 group_index = grp.next;
643 group_len++;
644 }
645
646 ss << std::endl;
647
648 return line_prefix + ".draw_multi(" + std::to_string(group_len) + ")" + ss.str();
649}
650
651std::string DrawIndirect::serialize() const
652{
653 return std::string(".draw_indirect()");
654}
655
656std::string Dispatch::serialize() const
657{
658 int3 sz = is_reference ? *size_ref : size;
659 return std::string(".dispatch") + (is_reference ? "_ref" : "") + "(" + std::to_string(sz.x) +
660 ", " + std::to_string(sz.y) + ", " + std::to_string(sz.z) + ")";
661}
662
664{
665 return std::string(".dispatch_indirect()");
666}
667
668std::string Barrier::serialize() const
669{
670 /* TODO(@fclem): Better serialization... */
671 return std::string(".barrier(") + std::to_string(type) + ")";
672}
673
674std::string Clear::serialize() const
675{
676 std::stringstream ss;
678 ss << "color=" << color;
680 ss << ", ";
681 }
682 }
684 ss << "depth=" << depth;
686 ss << ", ";
687 }
688 }
690 ss << "stencil=0b" << std::bitset<8>(stencil) << ")";
691 }
692 return std::string(".clear(") + ss.str() + ")";
693}
694
695std::string ClearMulti::serialize() const
696{
697 std::stringstream ss;
699 ss << color << ", ";
700 }
701 return std::string(".clear_multi(colors={") + ss.str() + "})";
702}
703
704std::string StateSet::serialize() const
705{
706 /* TODO(@fclem): Better serialization... */
707 return std::string(".state_set(") + std::to_string(new_state) + ")";
708}
709
710std::string StencilSet::serialize() const
711{
712 std::stringstream ss;
713 ss << ".stencil_set(write_mask=0b" << std::bitset<8>(write_mask) << ", reference=0b"
714 << std::bitset<8>(reference) << ", compare_mask=0b" << std::bitset<8>(compare_mask) << ")";
715 return ss.str();
716}
717
718std::string TextureCopy::serialize() const
719{
720 return ".texture_copy()";
721}
722
724
725/* -------------------------------------------------------------------- */
728
729void DrawCommandBuf::finalize_commands(Vector<Header, 0> &headers,
730 Vector<Undetermined, 0> &commands,
731 SubPassVector &sub_passes,
732 uint &resource_id_count,
733 ResourceIdBuf &resource_id_buf)
734{
735 for (const Header &header : headers) {
736 if (header.type == Type::SubPass) {
738 auto &sub = sub_passes[int64_t(header.index)];
739 finalize_commands(
740 sub.headers_, sub.commands_, sub_passes, resource_id_count, resource_id_buf);
741 }
742
743 if (header.type != Type::Draw) {
744 continue;
745 }
746
747 Draw &cmd = commands[header.index].draw;
748
749 int batch_vert_len, batch_vert_first, batch_base_index, batch_inst_len;
750 /* Now that GPUBatches are guaranteed to be finished, extract their parameters. */
752 cmd.batch, &batch_vert_len, &batch_vert_first, &batch_base_index, &batch_inst_len);
753 /* Instancing attributes are not supported using the new pipeline since we use the base
754 * instance to set the correct resource_id. Workaround is a storage_buf + gpu_InstanceIndex. */
755 BLI_assert(batch_inst_len == 1);
756
757 if (cmd.vertex_len == uint(-1)) {
758 cmd.vertex_len = batch_vert_len;
759 }
760
761 /* NOTE: Only do this if a handle is present. If a draw-call is using instancing with null
762 * handle, the shader should not rely on `resource_id` at ***all***. This allows procedural
763 * instanced draw-calls with lots of instances with no overhead. */
764 /* TODO(fclem): Think about either fixing this feature or removing support for instancing all
765 * together. */
766 if (cmd.res_id.raw > 0) {
767 /* Save correct offset to start of resource_id buffer region for this draw. */
768 uint instance_first = resource_id_count;
769 resource_id_count += cmd.instance_len;
770 /* Ensure the buffer is big enough. */
771 resource_id_buf.get_or_resize(resource_id_count - 1);
772
773 /* Copy the resource id for all instances. */
774 uint index = cmd.res_id.index();
775 for (int i = instance_first; i < (instance_first + cmd.instance_len); i++) {
776 resource_id_buf[i] = index;
777 }
778 }
779 }
780}
781
783 Vector<Undetermined, 0> &commands,
784 SubPassVector &sub_passes)
785{
786 /* First instance ID contains the null handle with identity transform.
787 * This is referenced for draw-calls with no handle. */
788 resource_id_buf_.get_or_resize(0) = 0;
789 resource_id_count_ = 1;
790 finalize_commands(headers, commands, sub_passes, resource_id_count_, resource_id_buf_);
791 resource_id_buf_.push_update();
792}
793
795{
796 GPU_storagebuf_bind(resource_id_buf_, DRW_RESOURCE_ID_SLOT);
797}
798
800 Vector<Undetermined, 0> & /*commands*/,
801 VisibilityBuf &visibility_buf,
802 int visibility_word_per_draw,
803 int view_len,
804 bool use_custom_ids)
805{
806 GPU_debug_group_begin("DrawMultiBuf.bind");
807
808 resource_id_count_ = 0u;
809 for (DrawGroup &group : MutableSpan<DrawGroup>(group_buf_.data(), group_count_)) {
810 /* Compute prefix sum of all instance of previous group. */
811 group.start = resource_id_count_;
812 resource_id_count_ += group.len;
813
814 int batch_vert_len, batch_vert_first, batch_base_index, batch_inst_len;
815 /* Now that GPUBatches are guaranteed to be finished, extract their parameters. */
816 GPU_batch_draw_parameter_get(group.desc.gpu_batch,
817 &batch_vert_len,
818 &batch_vert_first,
819 &batch_base_index,
820 &batch_inst_len);
821
822 group.vertex_len = group.desc.vertex_len == 0 ? batch_vert_len : group.desc.vertex_len;
823 group.vertex_first = group.desc.vertex_first == -1 ? batch_vert_first :
824 group.desc.vertex_first;
825 group.base_index = batch_base_index;
826 /* Instancing attributes are not supported using the new pipeline since we use the base
827 * instance to set the correct resource_id. Workaround is a storage_buf + gpu_InstanceIndex. */
828 BLI_assert(batch_inst_len == 1);
829 UNUSED_VARS_NDEBUG(batch_inst_len);
830
831 if (group.desc.expand_prim_type != GPU_PRIM_NONE) {
832 /* Expanded draw-call. */
834 group.desc.gpu_batch->prim_type,
835 GPUPrimType(group.desc.expand_prim_type),
836 group.vertex_len,
837 group.vertex_first,
838 group.desc.expand_prim_len);
839
840 group.vertex_first = vert_range.start();
841 group.vertex_len = vert_range.size();
842 /* Override base index to -1 as the generated draw-call will not use an index buffer and do
843 * the indirection manually inside the shader. */
844 group.base_index = -1;
845 }
846
847 /* Reset counters to 0 for the GPU. */
848 group.total_counter = group.front_facing_counter = group.back_facing_counter = 0;
849 }
850
851 group_buf_.push_update();
852 prototype_buf_.push_update();
853 /* Allocate enough for the expansion pass. */
854 resource_id_buf_.get_or_resize(resource_id_count_ * view_len * (use_custom_ids ? 2 : 1));
855 /* Two commands per group (inverted and non-inverted scale). */
856 command_buf_.get_or_resize(group_count_ * 2);
857
858 if (prototype_count_ > 0) {
861 GPU_shader_uniform_1i(shader, "prototype_len", prototype_count_);
862 GPU_shader_uniform_1i(shader, "visibility_word_per_draw", visibility_word_per_draw);
863 GPU_shader_uniform_1i(shader, "view_len", view_len);
864 GPU_shader_uniform_1i(shader, "view_shift", log2_ceil_u(view_len));
865 GPU_shader_uniform_1b(shader, "use_custom_ids", use_custom_ids);
866 GPU_storagebuf_bind(group_buf_, GPU_shader_get_ssbo_binding(shader, "group_buf"));
867 GPU_storagebuf_bind(visibility_buf, GPU_shader_get_ssbo_binding(shader, "visibility_buf"));
868 GPU_storagebuf_bind(prototype_buf_, GPU_shader_get_ssbo_binding(shader, "prototype_buf"));
869 GPU_storagebuf_bind(command_buf_, GPU_shader_get_ssbo_binding(shader, "command_buf"));
870 GPU_storagebuf_bind(resource_id_buf_, DRW_RESOURCE_ID_SLOT);
872 /* TODO(@fclem): Investigate moving the barrier in the bind function. */
875 }
876
878}
879
881{
882 GPU_storagebuf_bind(resource_id_buf_, DRW_RESOURCE_ID_SLOT);
883}
884
886
887}; // namespace blender::draw::command
#define GPU_ATTACHMENT_TEXTURE(_texture)
#define GPU_framebuffer_ensure_config(_fb,...)
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
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
Definition BLI_span.hh:596
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
#define index(i)
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
const int state
static gpu::Batch * procedural_batch_get(GPUPrimType primitive)
StorageArrayBuffer< uint, 4, true > VisibilityBuf
Definition draw_view.hh:35
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void GPU_batch_draw_indirect(gpu::Batch *batch, gpu::StorageBuf *indirect_buf, intptr_t offset)
void GPU_storagebuf_debug_unbind_all()
bool GPU_texture_has_depth_format(const gpu::Texture *texture)
gpu::FrameBuffer * GPU_framebuffer_active_get()
__int64 int64_t
Definition BKE_text.h:90
void GPU_vertbuf_bind_as_texture(gpu::VertBuf *verts, int binding)
void GPU_framebuffer_clear(gpu::FrameBuffer *fb, GPUFrameBufferBits buffers, const double4 clear_col, float clear_depth, unsigned int clear_stencil)
void GPU_batch_bind_as_resources(gpu::Batch *batch, gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants=nullptr)
void GPU_state_set(GPUWriteMask write_mask, GPUBlend blend, GPUFaceCullTest culling_test, GPUDepthTest depth_test, GPUStencilTest stencil_test, GPUStencilOp stencil_op, GPUProvokingVertex provoking_vert)
Definition gpu_state.cc:121
bool GPU_texture_is_view(const gpu::Texture *texture)
unsigned int uint
Definition BKE_text.h:55
const char * GPU_framebuffer_get_name(gpu::FrameBuffer *fb)
bool assign_if_different(T &old_value, T &&new_value)
void GPU_framebuffer_free(gpu::FrameBuffer *fb)
void GPU_clip_distances(int distances_enabled)
Definition gpu_state.cc:116
void GPU_storagebuf_sync_as_indirect_buffer(gpu::StorageBuf *ssbo)
BLI_INLINE float fb(float length, float L)
gpu::Batch * GPU_batch_procedural_points_get()
Definition gpu_batch.cc:513
void GPU_point_size(float size)
Definition gpu_state.cc:157
void GPU_texture_copy(gpu::Texture *dst, gpu::Texture *src)
void GPU_line_smooth(bool enable)
Definition gpu_state.cc:80
gpu::Shader * DRW_shader_draw_command_generate_get()
void GPU_texture_unbind_all()
@ GPU_PRIM_TRI_STRIP
void GPU_batch_set_shader(gpu::Batch *batch, gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
MatBase< float, 4, 4 > float4x4
void GPU_compute_dispatch(gpu::Shader *shader, uint groups_x_len, uint groups_y_len, uint groups_z_len, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_compute_dispatch_indirect(gpu::Shader *shader, gpu::StorageBuf *indirect_buf_, const gpu::shader::SpecializationConstants *constants_state)
void GPU_shader_uniform_int_ex(gpu::Shader *shader, int location, int length, int array_size, const int *value)
void GPU_shader_uniform_1b(gpu::Shader *sh, const char *name, bool value)
void GPU_vertbuf_bind_as_ssbo(gpu::VertBuf *verts, int binding)
MINLINE unsigned int log2_ceil_u(unsigned int x)
int GPU_shader_get_ssbo_binding(gpu::Shader *shader, const char *name)
void GPU_line_width(float width)
Definition gpu_state.cc:151
void GPU_stencil_reference_set(uint reference)
Definition gpu_state.cc:190
void GPU_indexbuf_bind_as_ssbo(gpu::IndexBuf *elem, int binding)
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)
Definition gpu_batch.cc:329
VecBase< int32_t, 3 > int3
void GPU_memory_barrier(GPUBarrier barrier)
Definition gpu_state.cc:305
void GPU_shader_uniform_float_ex(gpu::Shader *shader, int location, int length, int array_size, const float *value)
gpu::Batch * GPU_batch_procedural_triangle_strips_get()
Definition gpu_batch.cc:528
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void GPU_uniformbuf_bind_as_ssbo(gpu::UniformBuf *ubo, int slot)
void GPU_program_point_size(bool enable)
Definition gpu_state.cc:165
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_uniform_1i(gpu::Shader *sh, const char *name, int value)
@ GPU_BARRIER_SHADER_STORAGE
Definition GPU_state.hh:51
@ DRW_STATE_CLIP_CONTROL_UNIT_RANGE
Definition draw_state.hh:71
@ DRW_STATE_PROGRAM_POINT_SIZE
Definition draw_state.hh:75
void GPU_storagebuf_bind(gpu::StorageBuf *ssbo, int slot)
void GPU_uniformbuf_bind(gpu::UniformBuf *ubo, int slot)
void GPU_texture_bind_ex(gpu::Texture *texture, GPUSamplerState state, int unit)
void GPU_framebuffer_blit(gpu::FrameBuffer *fb_read, int read_slot, gpu::FrameBuffer *fb_write, int write_slot, GPUFrameBufferBits blit_buffers)
gpu::FrameBuffer * GPU_framebuffer_create(const char *name)
void GPU_debug_group_end()
Definition gpu_debug.cc:34
void GPU_framebuffer_multi_clear(gpu::FrameBuffer *fb, Span< double4 > clear_colors)
gpu::Batch * GPU_batch_procedural_triangles_get()
Definition gpu_batch.cc:523
void GPU_clip_control_unit_range(bool enable)
Definition gpu_state.cc:140
MINLINE uint divide_ceil_u(uint a, uint b)
const char * GPU_shader_get_name(gpu::Shader *shader)
void GPU_texture_image_unbind_all()
void GPU_texture_image_bind(gpu::Texture *texture, int unit)
void GPU_batch_draw_advanced(gpu::Batch *batch, int vertex_first, int vertex_count, int instance_first, int instance_count)
void GPU_stencil_write_mask_set(uint write_mask)
Definition gpu_state.cc:195
void GPU_uniformbuf_debug_unbind_all()
void GPU_framebuffer_subpass_transition_array(gpu::FrameBuffer *fb, const GPUAttachmentState *attachment_states, uint attachment_len)
void GPU_batch_draw_parameter_get(gpu::Batch *batch, int *r_vertex_count, int *r_vertex_first, int *r_base_index, int *r_instance_count)
void GPU_stencil_compare_mask_set(uint compare_mask)
Definition gpu_state.cc:200
VecBase< double, 4 > double4
gpu::Batch * GPU_batch_procedural_lines_get()
Definition gpu_batch.cc:518
void GPU_debug_group_begin(const char *name)
Definition gpu_debug.cc:23
_W64 int intptr_t
Definition BKE_text.h:119
const gpu::shader::SpecializationConstants & GPU_shader_get_default_constant_state(gpu::Shader *sh)
std::string to_string() const
bool has_inverted_handedness() const
std::string serialize() const
void execute(RecordingState &state) const
void execute(RecordingState &state) const
struct blender::draw::command::DrawGroup::@260053362377366347260167202326266235125360167346 desc
void execute(RecordingState &state) const
std::string serialize(const std::string &line_prefix) const
void execute(RecordingState &state) const
void execute(RecordingState &state) const
std::string serialize() const
void execute(RecordingState &state) const
enum blender::draw::command::PushConstant::Type type
enum blender::draw::command::ResourceBind::Type type
void execute(RecordingState &state) const
void execute(RecordingState &state) const
enum blender::draw::command::SpecializeConstant::Type type
void execute(RecordingState &state) const
static void set(DRWState state=DRW_STATE_DEFAULT)