| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/os/spin_lock.h" |
| 34 |
#include "servers/rendering/rendering_device.h" |
| 35 |
|
| 36 |
class PipelineCacheRD { |
| 37 |
SpinLock spin_lock; |
| 38 |
|
| 39 |
RID shader; |
| 40 |
|
| 41 |
RD::RenderPrimitive render_primitive; |
| 42 |
RD::PipelineRasterizationState rasterization_state; |
| 43 |
RD::PipelineMultisampleState multisample_state; |
| 44 |
RD::PipelineDepthStencilState depth_stencil_state; |
| 45 |
RD::PipelineColorBlendState blend_state; |
| 46 |
int dynamic_state_flags = 0; |
| 47 |
Vector<RD::PipelineSpecializationConstant> base_specialization_constants; |
| 48 |
|
| 49 |
struct Version { |
| 50 |
RD::VertexFormatID vertex_id; |
| 51 |
RD::FramebufferFormatID framebuffer_id; |
| 52 |
uint32_t render_pass; |
| 53 |
bool wireframe; |
| 54 |
uint32_t bool_specializations; |
| 55 |
RID pipeline; |
| 56 |
}; |
| 57 |
|
| 58 |
Version *versions = nullptr; |
| 59 |
uint32_t version_count; |
| 60 |
|
| 61 |
RID _generate_version(RD::VertexFormatID p_vertex_format_id, RD::FramebufferFormatID p_framebuffer_format_id, bool p_wireframe, uint32_t p_render_pass, uint32_t p_bool_specializations = 0); |
| 62 |
|
| 63 |
void _clear(); |
| 64 |
|
| 65 |
public: |
| 66 |
void setup(RID p_shader, RD::RenderPrimitive p_primitive, const RD::PipelineRasterizationState &p_rasterization_state, RD::PipelineMultisampleState p_multisample, const RD::PipelineDepthStencilState &p_depth_stencil_state, const RD::PipelineColorBlendState &p_blend_state, int p_dynamic_state_flags = 0, const Vector<RD::PipelineSpecializationConstant> &p_base_specialization_constants = Vector<RD::PipelineSpecializationConstant>()); |
| 67 |
void update_specialization_constants(const Vector<RD::PipelineSpecializationConstant> &p_base_specialization_constants); |
| 68 |
void update_shader(RID p_shader); |
| 69 |
|
| 70 |
_FORCE_INLINE_ RID get_render_pipeline(RD::VertexFormatID p_vertex_format_id, RD::FramebufferFormatID p_framebuffer_format_id, bool p_wireframe = false, uint32_t p_render_pass = 0, uint32_t p_bool_specializations = 0) { |
| 71 |
#ifdef DEBUG_ENABLED |
| 72 |
ERR_FAIL_COND_V_MSG(shader.is_null(), RID(), |
| 73 |
"Attempted to use an unused shader variant (shader is null),"); |
| 74 |
#endif |
| 75 |
|
| 76 |
spin_lock.lock(); |
| 77 |
p_wireframe |= rasterization_state.wireframe; |
| 78 |
|
| 79 |
RID result; |
| 80 |
for (uint32_t i = 0; i < version_count; i++) { |
| 81 |
if (versions[i].vertex_id == p_vertex_format_id && versions[i].framebuffer_id == p_framebuffer_format_id && versions[i].wireframe == p_wireframe && versions[i].render_pass == p_render_pass && versions[i].bool_specializations == p_bool_specializations) { |
| 82 |
result = versions[i].pipeline; |
| 83 |
spin_lock.unlock(); |
| 84 |
return result; |
| 85 |
} |
| 86 |
} |
| 87 |
result = _generate_version(p_vertex_format_id, p_framebuffer_format_id, p_wireframe, p_render_pass, p_bool_specializations); |
| 88 |
spin_lock.unlock(); |
| 89 |
return result; |
| 90 |
} |
| 91 |
|
| 92 |
_FORCE_INLINE_ uint64_t get_vertex_input_mask() { |
| 93 |
ERR_FAIL_COND_V(shader.is_null(), 0); |
| 94 |
return RD::get_singleton()->shader_get_vertex_input_attribute_mask(shader); |
| 95 |
} |
| 96 |
void clear(); |
| 97 |
PipelineCacheRD(); |
| 98 |
~PipelineCacheRD(); |
| 99 |
}; |