69using namespace blender::draw;
70using namespace blender::draw::command;
106 if (blocks_.is_empty() || blocks_.last()->size() == block_size) {
109 return blocks_.last()->append_and_get_index(std::move(elem)) +
110 (blocks_.size() - 1) * block_size;
115 return (*blocks_[
index / block_size])[
index % block_size];
120 return (*blocks_[
index / block_size])[
index % block_size];
129 typename DrawCommandBufType>
132 friend DrawCommandBuf;
160 DrawCommandBufType &draw_command_buf,
253 bool deferred_texture_loading =
false,
261 void draw(gpu::Batch *batch,
262 uint instance_len = -1,
263 uint vertex_len = -1,
264 uint vertex_first = -1,
281 uint vertex_first = -1,
326 StorageBuffer<DrawCommand, true> &indirect_buffer,
327 ResourceID res_id = {0});
336 void dispatch(StorageBuffer<DispatchCommand> &indirect_buffer);
355 void bind_image(
const char *name, gpu::Texture *image);
356 void bind_image(
const char *name, gpu::Texture **image);
357 void bind_image(
int slot, gpu::Texture *image);
358 void bind_image(
int slot, gpu::Texture **image);
362 GPUSamplerState
state = sampler_auto);
363 void bind_texture(
const char *name, gpu::VertBuf *buffer);
364 void bind_texture(
const char *name, gpu::VertBuf **buffer);
371 void bind_ssbo(
const char *name, gpu::StorageBuf *buffer);
372 void bind_ssbo(
const char *name, gpu::StorageBuf **buffer);
373 void bind_ssbo(
int slot, gpu::StorageBuf *buffer);
374 void bind_ssbo(
int slot, gpu::StorageBuf **buffer);
375 void bind_ssbo(
const char *name, gpu::UniformBuf *buffer);
376 void bind_ssbo(
const char *name, gpu::UniformBuf **buffer);
377 void bind_ssbo(
int slot, gpu::UniformBuf *buffer);
378 void bind_ssbo(
int slot, gpu::UniformBuf **buffer);
379 void bind_ssbo(
const char *name, gpu::VertBuf *buffer);
380 void bind_ssbo(
const char *name, gpu::VertBuf **buffer);
382 void bind_ssbo(
int slot, gpu::VertBuf *buffer);
383 void bind_ssbo(
int slot, gpu::VertBuf **buffer);
385 void bind_ssbo(
const char *name, gpu::IndexBuf *buffer);
386 void bind_ssbo(
const char *name, gpu::IndexBuf **buffer);
387 void bind_ssbo(
int slot, gpu::IndexBuf *buffer);
388 void bind_ssbo(
int slot, gpu::IndexBuf **buffer);
389 void bind_tlas(
const char *name, gpu::TopLevelAS *tlas);
390 void bind_tlas(
int slot, gpu::TopLevelAS *tlas);
391 void bind_ubo(
const char *name, gpu::UniformBuf *buffer);
392 void bind_ubo(
const char *name, gpu::UniformBuf **buffer);
393 void bind_ubo(
int slot, gpu::UniformBuf *buffer);
394 void bind_ubo(
int slot, gpu::UniformBuf **buffer);
448 void texture_copy(gpu::Texture *src, gpu::Texture *dst);
449 void texture_copy(gpu::Texture **src, gpu::Texture **dst);
450 void texture_copy(gpu::Texture **src, gpu::Texture *dst);
451 void texture_copy(gpu::Texture *src, gpu::Texture **dst);
461 resources.bind_resources(*
this);
467 std::string
serialize(std::string line_prefix =
"")
const;
515 DrawCommandBufType draw_commands_buf_main_;
519 :
detail::
PassBase<DrawCommandBufType>(name, draw_commands_buf_main_, sub_passes_main_) {};
523 this->manager_fingerprint_ = 0;
524 this->view_fingerprint_ = 0;
525 this->headers_.
clear();
526 this->commands_.
clear();
527 this->sub_passes_.
clear();
528 this->draw_commands_buf_.clear();
529 this->is_empty_ =
true;
566 bool sorted_ =
false;
573 sorting_values_.clear();
590 sorting_index = sorting_values_.append_and_get_index(sorting_value);
591 }
while (sorting_index !=
index);
595 std::string
serialize(std::string line_prefix =
"")
const
597 if (sorted_ ==
false) {
606 if (sorted_ ==
false) {
609 float a_val = sorting_values_[a.
index];
610 float b_val = sorting_values_[
b.index];
611 return a_val < b_val || (a_val == b_val && a.
index <
b.index);
680 static_cast<int>(colors.
size())};
716 switch (header.type) {
773 switch (header.type) {
781 commands_[header.index].framebuffer_bind.execute();
784 commands_[header.index].subpass_transition.execute();
790 commands_[header.index].resource_bind.execute();
814 commands_[header.index].barrier.execute();
820 commands_[header.index].clear_multi.execute();
826 commands_[header.index].stencil_set.execute();
829 commands_[header.index].texture_copy.execute();
838 std::stringstream ss;
839 ss << line_prefix <<
"." <<
debug_name << std::endl;
842 switch (header.type) {
847 ss <<
sub_passes_[header.index].serialize(line_prefix);
850 ss << line_prefix <<
commands_[header.index].framebuffer_bind.serialize() << std::endl;
853 ss << line_prefix <<
commands_[header.index].subpass_transition.serialize() << std::endl;
856 ss << line_prefix <<
commands_[header.index].shader_bind.serialize() << std::endl;
859 ss << line_prefix <<
commands_[header.index].resource_bind.serialize() << std::endl;
862 ss << line_prefix <<
commands_[header.index].push_constant.serialize() << std::endl;
865 ss << line_prefix <<
commands_[header.index].draw.serialize() << std::endl;
868 ss <<
commands_[header.index].draw_multi.serialize(line_prefix);
871 ss << line_prefix <<
commands_[header.index].draw_indirect.serialize() << std::endl;
874 ss << line_prefix <<
commands_[header.index].dispatch.serialize() << std::endl;
877 ss << line_prefix <<
commands_[header.index].dispatch_indirect.serialize() << std::endl;
880 ss << line_prefix <<
commands_[header.index].barrier.serialize() << std::endl;
883 ss << line_prefix <<
commands_[header.index].
clear.serialize() << std::endl;
886 ss << line_prefix <<
commands_[header.index].clear_multi.serialize() << std::endl;
889 ss << line_prefix <<
commands_[header.index].state_set.serialize() << std::endl;
892 ss << line_prefix <<
commands_[header.index].stencil_set.serialize() << std::endl;
913 if (instance_len == 0 || vertex_len == 0) {
934 this->
draw(batch, -1, -1, -1, res_id, custom_id);
947 if (instance_len == 0 || vertex_len == 0 || primitive_len == 0) {
972 this->
draw_expand(batch, primitive_type, primitive_len, instance_len, -1, -1, res_id, custom_id);
1098 if (clip_plane_count > 0) {
1129 color_states[i] =
uint8_t(color_attachments[i]);
1145 bool deferred_texture_loading,
1156 const bool use_tile_mapping = tex->tiled_mapping_name[0];
1157 ImageUser *iuser = tex->iuser_available ? &tex->iuser :
nullptr;
1161 tex->ima, iuser, use_tile_mapping, deferred_texture_loading);
1165 if (sampler_state.
filtering & GPU_SAMPLER_FILTERING_ANISOTROPIC_ENABLE) {
1170 if (gputex.
texture ==
nullptr && deferred_texture_loading) {
1174 tex->ima, iuser, use_tile_mapping);
1192 else if (tex->colorband) {
1196 else if (tex->sky) {
1198 bind_texture(tex->sampler_name, *tex->sky, tex->sampler_state);
1203 if (ubo !=
nullptr) {
1204 bind_ubo(GPU_NODE_TREE_UBO_SLOT, ubo);
1579 *
reinterpret_cast<float4x4 *
>(&cmd.float4_value) =
data;
1594 const char *constant_name,
1595 const int &constant_value)
1603 const char *constant_name,
1604 const uint &constant_value)
1612 const char *constant_name,
1613 const float &constant_value)
1621 const char *constant_name,
1622 const bool &constant_value)
1630 const char *constant_name,
1631 const int *constant_value)
1639 const char *constant_name,
1640 const uint *constant_value)
1648 const char *constant_name,
1649 const float *constant_value)
1657 const char *constant_name,
1658 const bool *constant_value)
1673 .src = src, .dst = dst, .src_is_ref =
false, .dst_is_ref =
false};
1678 .src_ref = src, .dst_ref = dst, .src_is_ref =
true, .dst_is_ref =
true};
1683 .src_ref = src, .dst = dst, .src_is_ref =
true, .dst_is_ref =
false};
1688 .src = src, .dst_ref = dst, .src_is_ref =
false, .dst_is_ref =
true};
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
virtual bool serialize(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian) const
Data buffer MUST be 16 byte aligned.
constexpr const T * data() const
constexpr int64_t size() const
constexpr IndexRange index_range() const
int64_t append_and_get_index(const T &value)
void append(const T &value)
void hold_texture(gpu::Texture *texture)
DeferredTexture & add_texture_deferred(blender::Image *image, blender::ImageUser *image_user, const bool use_tile_mapping)
std::string serialize(std::string line_prefix="") const
PassSortable(const char *name_)
PassMain::Sub & sub(const char *name, float sorting_value)
void draw_procedural(GPUPrimType primitive, uint instance_len, uint vertex_len, uint vertex_first=-1, ResourceIDRange res_id={}, uint custom_id=0)
void bind_resources(U &resources)
void framebuffer_set(gpu::FrameBuffer **framebuffer)
friend std::ostream & operator<<(std::ostream &stream, const PassBase &pass)
void shader_set(gpu::Shader *shader)
void material_set(Manager &manager, GPUMaterial *material, bool deferred_texture_loading=false, GPUSamplerFiltering anisotropic_filtering=GPU_SAMPLER_FILTERING_DEFAULT)
void clear_depth(float depth)
void texture_copy(gpu::Texture *src, gpu::Texture *dst)
void bind_texture(const char *name, gpu::Texture *texture, GPUSamplerState state=sampler_auto)
void draw_procedural_indirect(GPUPrimType primitive, StorageBuffer< DrawCommand, true > &indirect_buffer, ResourceID res_id={0})
Vector< command::Header, 0 > headers_
void draw_indirect(gpu::Batch *batch, StorageBuffer< DrawCommand, true > &indirect_buffer, ResourceID res_id={0})
uint64_t view_fingerprint_
uint64_t manager_fingerprint_
bool has_generated_commands() const
void clear_stencil(uint8_t stencil)
void clear(GPUFrameBufferBits planes, float4 color, float depth, uint8_t stencil)
void clear_color(float4 color)
void warm_shader_specialization(command::RecordingState &state) const
void specialize_constant(gpu::Shader *shader, const char *name, const float &data)
void subpass_transition(GPUAttachmentState depth_attachment, Span< GPUAttachmentState > color_attachments)
void bind_image(const char *name, gpu::Texture *image)
void clear_depth_stencil(float depth, uint8_t stencil)
void bind_tlas(const char *name, gpu::TopLevelAS *tlas)
PassBase(const char *name, DrawCommandBufType &draw_command_buf, SubPassVector< PassBase< DrawCommandBufType > > &sub_passes, gpu::Shader *shader=nullptr)
SubPassVector< PassBase< DrawCommandBufType > > & sub_passes_
command::Undetermined & create_command(command::Type type)
PassBase< DrawCommandBufType > & sub(const char *name)
void dispatch(int group_len)
int push_constant_offset(const char *name)
void submit(command::RecordingState &state) const
void state_set(DRWState state, int clip_plane_count=0)
void draw_expand(gpu::Batch *batch, GPUPrimType primitive_type, uint primitive_len, uint instance_len, uint vertex_len, uint vertex_first, ResourceIDRange res_id={}, uint custom_id=0)
void clear_multi(Span< double4 > colors)
void barrier(GPUBarrier type)
Vector< command::Undetermined, 0 > commands_
void state_stencil(uint8_t write_mask, uint8_t reference, uint8_t compare_mask)
void clear_color_depth_stencil(float4 color, float depth, uint8_t stencil)
void bind_ubo(const char *name, gpu::UniformBuf *buffer)
std::string serialize(std::string line_prefix="") const
void push_constant(const char *name, const float &data)
void bind_ssbo(const char *name, gpu::StorageBuf *buffer)
void draw(gpu::Batch *batch, uint instance_len=-1, uint vertex_len=-1, uint vertex_first=-1, ResourceIDRange res_id={}, uint custom_id=0)
gpu::Batch * procedural_batch_get(GPUPrimType primitive)
DrawCommandBufType & draw_commands_buf_
detail::PassBase< command::DrawCommandBuf > Sub
T & operator[](int64_t index)
const T & operator[](int64_t index) const
int64_t append_and_get_index(T &&elem)
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
draw::StorageBuffer< DrawCommand, true > DrawIndirectBuf
detail::Pass< command::DrawMultiBuf > PassMain
draw::StorageBuffer< DispatchCommand > DispatchIndirectBuf
std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > VertBufPtr
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
int GPU_shader_get_sampler_binding(gpu::Shader *shader, const char *name)
unsigned __int64 uint64_t
VecBase< int32_t, 4 > int4
int GPU_shader_get_constant(gpu::Shader *shader, const char *name)
gpu::Batch * GPU_batch_procedural_points_get()
ImageGPUTextures BKE_image_acquire_gpu_material_texture(Image *image, ImageUser *iuser, const bool use_tile_mapping, const bool try_only)
@ GPU_SAMPLER_FILTERING_DEFAULT
MatBase< float, 4, 4 > float4x4
gpu::UniformBuf * GPU_material_uniform_buffer_get(GPUMaterial *material)
int GPU_shader_get_ssbo_binding(gpu::Shader *shader, const char *name)
VecBase< float, 4 > float4
gpu::Shader * GPU_pass_shader_get(GPUPass *pass)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
ListBaseWrapperTemplate< ListBase, T > ListBaseWrapper
BMesh const char void * data
GPUPass * GPU_material_get_pass(GPUMaterial *material)
gpu::Batch * GPU_batch_procedural_triangle_strips_get()
int GPU_shader_get_tlas_binding(gpu::Shader *shader, const char *name)
@ DRW_STATE_PROGRAM_POINT_SIZE
void GPU_debug_group_end()
ListBaseT< GPUMaterialTexture > GPU_material_textures(GPUMaterial *material)
int GPU_shader_get_uniform(gpu::Shader *shader, const char *name)
gpu::Batch * GPU_batch_procedural_triangles_get()
int GPU_shader_get_ubo_binding(gpu::Shader *shader, const char *name)
VecBase< float, 3 > float3
gpu::Batch * GPU_batch_procedural_lines_get()
void GPU_debug_group_begin(const char *name)
void disable_filtering_flag(GPUSamplerFiltering filtering_flags)
GPUSamplerFiltering filtering
static constexpr GPUSamplerState internal_sampler()
void enable_filtering_flag(GPUSamplerFiltering filtering_flags)
gpu::Texture * tile_mapping
gpu::Texture * tile_mapping
enum blender::draw::command::PushConstant::Type type
PushConstant push_constant
SpecializeConstant specialize_constant