Debian Codegraph @

servers/rendering/renderer_rd/pipeline_cache_rd.h

raw symbols SCIP
1 /**************************************************************************/
2 /* pipeline_cache_rd.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
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 };