effects_rd.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**************************************************************************/
  2. /* effects_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. #ifndef EFFECTS_RD_H
  31. #define EFFECTS_RD_H
  32. #include "core/math/projection.h"
  33. #include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
  34. #include "servers/rendering/renderer_rd/shaders/roughness_limiter.glsl.gen.h"
  35. #include "servers/rendering/renderer_rd/shaders/sort.glsl.gen.h"
  36. #include "servers/rendering/renderer_scene_render.h"
  37. #include "servers/rendering_server.h"
  38. class EffectsRD {
  39. private:
  40. bool prefer_raster_effects;
  41. struct RoughnessLimiterPushConstant {
  42. int32_t screen_size[2];
  43. float curve;
  44. uint32_t pad;
  45. };
  46. struct RoughnessLimiter {
  47. RoughnessLimiterPushConstant push_constant;
  48. RoughnessLimiterShaderRD shader;
  49. RID shader_version;
  50. RID pipeline;
  51. } roughness_limiter;
  52. enum SortMode {
  53. SORT_MODE_BLOCK,
  54. SORT_MODE_STEP,
  55. SORT_MODE_INNER,
  56. SORT_MODE_MAX
  57. };
  58. struct Sort {
  59. struct PushConstant {
  60. uint32_t total_elements;
  61. uint32_t pad[3];
  62. int32_t job_params[4];
  63. };
  64. SortShaderRD shader;
  65. RID shader_version;
  66. RID pipelines[SORT_MODE_MAX];
  67. } sort;
  68. RID default_sampler;
  69. RID default_mipmap_sampler;
  70. RID index_buffer;
  71. RID index_array;
  72. HashMap<RID, RID> texture_to_uniform_set_cache;
  73. HashMap<RID, RID> input_to_uniform_set_cache;
  74. HashMap<RID, RID> image_to_uniform_set_cache;
  75. struct TexturePair {
  76. RID texture1;
  77. RID texture2;
  78. _FORCE_INLINE_ bool operator<(const TexturePair &p_pair) const {
  79. if (texture1 == p_pair.texture1) {
  80. return texture2 < p_pair.texture2;
  81. } else {
  82. return texture1 < p_pair.texture1;
  83. }
  84. }
  85. };
  86. struct TextureSamplerPair {
  87. RID texture;
  88. RID sampler;
  89. _FORCE_INLINE_ bool operator<(const TextureSamplerPair &p_pair) const {
  90. if (texture == p_pair.texture) {
  91. return sampler < p_pair.sampler;
  92. } else {
  93. return texture < p_pair.texture;
  94. }
  95. }
  96. };
  97. RBMap<TexturePair, RID> texture_pair_to_uniform_set_cache;
  98. RBMap<RID, RID> texture_to_compute_uniform_set_cache;
  99. RBMap<TexturePair, RID> texture_pair_to_compute_uniform_set_cache;
  100. RBMap<TexturePair, RID> image_pair_to_compute_uniform_set_cache;
  101. RBMap<TextureSamplerPair, RID> texture_sampler_to_compute_uniform_set_cache;
  102. RID _get_uniform_set_from_image(RID p_texture);
  103. RID _get_compute_uniform_set_from_texture(RID p_texture, bool p_use_mipmaps = false);
  104. public:
  105. bool get_prefer_raster_effects();
  106. void roughness_limit(RID p_source_normal, RID p_roughness, const Size2i &p_size, float p_curve);
  107. void sort_buffer(RID p_uniform_set, int p_size);
  108. EffectsRD(bool p_prefer_raster_effects);
  109. ~EffectsRD();
  110. };
  111. #endif // EFFECTS_RD_H