pipeline_cache_rd.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*************************************************************************/
  2. /* pipeline_cache_rd.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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. #ifndef PIPELINE_CACHE_RD_H
  31. #define PIPELINE_CACHE_RD_H
  32. #include "core/os/spin_lock.h"
  33. #include "servers/rendering/rendering_device.h"
  34. class PipelineCacheRD {
  35. SpinLock spin_lock;
  36. RID shader;
  37. uint32_t input_mask;
  38. RD::RenderPrimitive render_primitive;
  39. RD::PipelineRasterizationState rasterization_state;
  40. RD::PipelineMultisampleState multisample_state;
  41. RD::PipelineDepthStencilState depth_stencil_state;
  42. RD::PipelineColorBlendState blend_state;
  43. int dynamic_state_flags;
  44. struct Version {
  45. RD::VertexFormatID vertex_id;
  46. RD::FramebufferFormatID framebuffer_id;
  47. bool wireframe;
  48. RID pipeline;
  49. };
  50. Version *versions;
  51. uint32_t version_count;
  52. RID _generate_version(RD::VertexFormatID p_vertex_format_id, RD::FramebufferFormatID p_framebuffer_format_id, bool p_wireframe);
  53. void _clear();
  54. public:
  55. 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);
  56. void update_shader(RID p_shader);
  57. _FORCE_INLINE_ RID get_render_pipeline(RD::VertexFormatID p_vertex_format_id, RD::FramebufferFormatID p_framebuffer_format_id, bool p_wireframe = false) {
  58. #ifdef DEBUG_ENABLED
  59. ERR_FAIL_COND_V_MSG(shader.is_null(), RID(),
  60. "Attempted to use an unused shader variant (shader is null),");
  61. #endif
  62. spin_lock.lock();
  63. RID result;
  64. for (uint32_t i = 0; i < version_count; i++) {
  65. if (versions[i].vertex_id == p_vertex_format_id && versions[i].framebuffer_id == p_framebuffer_format_id && versions[i].wireframe == p_wireframe) {
  66. result = versions[i].pipeline;
  67. spin_lock.unlock();
  68. return result;
  69. }
  70. }
  71. result = _generate_version(p_vertex_format_id, p_framebuffer_format_id, p_wireframe);
  72. spin_lock.unlock();
  73. return result;
  74. }
  75. _FORCE_INLINE_ uint32_t get_vertex_input_mask() const {
  76. return input_mask;
  77. }
  78. void clear();
  79. PipelineCacheRD();
  80. ~PipelineCacheRD();
  81. };
  82. #endif // RENDER_PIPELINE_CACHE_RD_H