Path: blob/master/servers/rendering/renderer_rd/pipeline_cache_rd.h
10278 views
/**************************************************************************/1/* pipeline_cache_rd.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/os/spin_lock.h"33#include "servers/rendering/rendering_device.h"3435class PipelineCacheRD {36SpinLock spin_lock;3738RID shader;3940RD::RenderPrimitive render_primitive;41RD::PipelineRasterizationState rasterization_state;42RD::PipelineMultisampleState multisample_state;43RD::PipelineDepthStencilState depth_stencil_state;44RD::PipelineColorBlendState blend_state;45int dynamic_state_flags = 0;46Vector<RD::PipelineSpecializationConstant> base_specialization_constants;4748struct Version {49RD::VertexFormatID vertex_id;50RD::FramebufferFormatID framebuffer_id;51uint32_t render_pass;52bool wireframe;53uint32_t bool_specializations;54RID pipeline;55};5657Version *versions = nullptr;58uint32_t version_count;5960RID _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);6162void _clear();6364public:65void 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>());66void update_specialization_constants(const Vector<RD::PipelineSpecializationConstant> &p_base_specialization_constants);67void update_shader(RID p_shader);6869_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) {70#ifdef DEBUG_ENABLED71ERR_FAIL_COND_V_MSG(shader.is_null(), RID(),72"Attempted to use an unused shader variant (shader is null),");73#endif7475spin_lock.lock();76p_wireframe |= rasterization_state.wireframe;7778RID result;79for (uint32_t i = 0; i < version_count; i++) {80if (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) {81result = versions[i].pipeline;82spin_lock.unlock();83return result;84}85}86result = _generate_version(p_vertex_format_id, p_framebuffer_format_id, p_wireframe, p_render_pass, p_bool_specializations);87spin_lock.unlock();88return result;89}9091_FORCE_INLINE_ uint64_t get_vertex_input_mask() {92ERR_FAIL_COND_V(shader.is_null(), 0);93return RD::get_singleton()->shader_get_vertex_input_attribute_mask(shader);94}95void clear();96PipelineCacheRD();97~PipelineCacheRD();98};99100101