2019-06-22 16:34:26 +00:00
|
|
|
/*************************************************************************/
|
2020-12-04 18:26:24 +00:00
|
|
|
/* pipeline_cache_rd.h */
|
2019-06-22 16:34:26 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2022-01-03 20:27:34 +00:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2019-06-22 16:34:26 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2020-12-04 18:26:24 +00:00
|
|
|
#ifndef PIPELINE_CACHE_RD_H
|
|
|
|
#define PIPELINE_CACHE_RD_H
|
2019-06-16 02:45:24 +00:00
|
|
|
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/os/spin_lock.h"
|
2020-03-27 18:21:27 +00:00
|
|
|
#include "servers/rendering/rendering_device.h"
|
2019-06-16 02:45:24 +00:00
|
|
|
|
2020-12-04 18:26:24 +00:00
|
|
|
class PipelineCacheRD {
|
2019-09-07 01:51:27 +00:00
|
|
|
SpinLock spin_lock;
|
|
|
|
|
2019-06-16 02:45:24 +00:00
|
|
|
RID shader;
|
2019-08-20 20:54:03 +00:00
|
|
|
uint32_t input_mask;
|
2019-06-16 02:45:24 +00:00
|
|
|
|
|
|
|
RD::RenderPrimitive render_primitive;
|
|
|
|
RD::PipelineRasterizationState rasterization_state;
|
|
|
|
RD::PipelineMultisampleState multisample_state;
|
|
|
|
RD::PipelineDepthStencilState depth_stencil_state;
|
|
|
|
RD::PipelineColorBlendState blend_state;
|
2022-05-02 14:28:25 +00:00
|
|
|
int dynamic_state_flags = 0;
|
2021-07-12 23:32:05 +00:00
|
|
|
Vector<RD::PipelineSpecializationConstant> base_specialization_constants;
|
2019-06-16 02:45:24 +00:00
|
|
|
|
|
|
|
struct Version {
|
2019-07-10 20:44:55 +00:00
|
|
|
RD::VertexFormatID vertex_id;
|
|
|
|
RD::FramebufferFormatID framebuffer_id;
|
2021-06-24 13:58:36 +00:00
|
|
|
uint32_t render_pass;
|
2020-05-01 12:34:23 +00:00
|
|
|
bool wireframe;
|
2021-07-12 23:32:05 +00:00
|
|
|
uint32_t bool_specializations;
|
2019-06-16 02:45:24 +00:00
|
|
|
RID pipeline;
|
|
|
|
};
|
|
|
|
|
2022-04-04 13:06:57 +00:00
|
|
|
Version *versions = nullptr;
|
2019-07-10 20:44:55 +00:00
|
|
|
uint32_t version_count;
|
2019-06-16 02:45:24 +00:00
|
|
|
|
2021-07-12 23:32:05 +00:00
|
|
|
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);
|
2019-06-16 02:45:24 +00:00
|
|
|
|
|
|
|
void _clear();
|
|
|
|
|
|
|
|
public:
|
2021-07-12 23:32:05 +00:00
|
|
|
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>());
|
2021-07-19 19:41:55 +00:00
|
|
|
void update_specialization_constants(const Vector<RD::PipelineSpecializationConstant> &p_base_specialization_constants);
|
2019-06-16 02:45:24 +00:00
|
|
|
void update_shader(RID p_shader);
|
|
|
|
|
2021-07-12 23:32:05 +00:00
|
|
|
_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) {
|
2019-08-18 22:40:52 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
ERR_FAIL_COND_V_MSG(shader.is_null(), RID(),
|
|
|
|
"Attempted to use an unused shader variant (shader is null),");
|
|
|
|
#endif
|
2019-09-07 01:51:27 +00:00
|
|
|
|
|
|
|
spin_lock.lock();
|
|
|
|
RID result;
|
2019-07-10 20:44:55 +00:00
|
|
|
for (uint32_t i = 0; i < version_count; i++) {
|
2021-07-12 23:32:05 +00:00
|
|
|
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) {
|
2019-09-07 01:51:27 +00:00
|
|
|
result = versions[i].pipeline;
|
|
|
|
spin_lock.unlock();
|
|
|
|
return result;
|
2019-06-16 02:45:24 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-12 23:32:05 +00:00
|
|
|
result = _generate_version(p_vertex_format_id, p_framebuffer_format_id, p_wireframe, p_render_pass, p_bool_specializations);
|
2019-09-07 01:51:27 +00:00
|
|
|
spin_lock.unlock();
|
|
|
|
return result;
|
2019-06-16 02:45:24 +00:00
|
|
|
}
|
|
|
|
|
2019-08-20 20:54:03 +00:00
|
|
|
_FORCE_INLINE_ uint32_t get_vertex_input_mask() const {
|
|
|
|
return input_mask;
|
|
|
|
}
|
2019-08-18 22:40:52 +00:00
|
|
|
void clear();
|
2020-12-04 18:26:24 +00:00
|
|
|
PipelineCacheRD();
|
|
|
|
~PipelineCacheRD();
|
2019-06-16 02:45:24 +00:00
|
|
|
};
|
|
|
|
|
2022-07-23 21:41:51 +00:00
|
|
|
#endif // PIPELINE_CACHE_RD_H
|