copy_effects.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*************************************************************************/
  2. /* copy_effects.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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. #include "copy_effects.h"
  31. #include "servers/rendering/renderer_rd/renderer_compositor_rd.h"
  32. #include "servers/rendering/renderer_rd/storage_rd/material_storage.h"
  33. #include "servers/rendering/renderer_rd/uniform_set_cache_rd.h"
  34. using namespace RendererRD;
  35. CopyEffects *CopyEffects::singleton = nullptr;
  36. CopyEffects *CopyEffects::get_singleton() {
  37. return singleton;
  38. }
  39. CopyEffects::CopyEffects(bool p_prefer_raster_effects) {
  40. singleton = this;
  41. prefer_raster_effects = p_prefer_raster_effects;
  42. if (prefer_raster_effects) {
  43. // init blur shader (on compute use copy shader)
  44. Vector<String> blur_modes;
  45. blur_modes.push_back("\n#define MODE_MIPMAP\n"); // BLUR_MIPMAP
  46. blur_modes.push_back("\n#define MODE_GAUSSIAN_BLUR\n"); // BLUR_MODE_GAUSSIAN_BLUR
  47. blur_modes.push_back("\n#define MODE_GAUSSIAN_GLOW\n"); // BLUR_MODE_GAUSSIAN_GLOW
  48. blur_modes.push_back("\n#define MODE_GAUSSIAN_GLOW\n#define GLOW_USE_AUTO_EXPOSURE\n"); // BLUR_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE
  49. blur_modes.push_back("\n#define MODE_COPY\n"); // BLUR_MODE_COPY
  50. blur_raster.shader.initialize(blur_modes);
  51. memset(&blur_raster.push_constant, 0, sizeof(BlurRasterPushConstant));
  52. blur_raster.shader_version = blur_raster.shader.version_create();
  53. for (int i = 0; i < BLUR_MODE_MAX; i++) {
  54. blur_raster.pipelines[i].setup(blur_raster.shader.version_get_shader(blur_raster.shader_version, i), RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RD::PipelineColorBlendState::create_disabled(), 0);
  55. }
  56. } else {
  57. // not used in clustered
  58. for (int i = 0; i < BLUR_MODE_MAX; i++) {
  59. blur_raster.pipelines[i].clear();
  60. }
  61. Vector<String> copy_modes;
  62. copy_modes.push_back("\n#define MODE_GAUSSIAN_BLUR\n");
  63. copy_modes.push_back("\n#define MODE_GAUSSIAN_BLUR\n#define DST_IMAGE_8BIT\n");
  64. copy_modes.push_back("\n#define MODE_GAUSSIAN_BLUR\n#define MODE_GLOW\n");
  65. copy_modes.push_back("\n#define MODE_GAUSSIAN_BLUR\n#define MODE_GLOW\n#define GLOW_USE_AUTO_EXPOSURE\n");
  66. copy_modes.push_back("\n#define MODE_SIMPLE_COPY\n");
  67. copy_modes.push_back("\n#define MODE_SIMPLE_COPY\n#define DST_IMAGE_8BIT\n");
  68. copy_modes.push_back("\n#define MODE_SIMPLE_COPY_DEPTH\n");
  69. copy_modes.push_back("\n#define MODE_SET_COLOR\n");
  70. copy_modes.push_back("\n#define MODE_SET_COLOR\n#define DST_IMAGE_8BIT\n");
  71. copy_modes.push_back("\n#define MODE_MIPMAP\n");
  72. copy_modes.push_back("\n#define MODE_LINEARIZE_DEPTH_COPY\n");
  73. copy_modes.push_back("\n#define MODE_CUBEMAP_TO_PANORAMA\n");
  74. copy_modes.push_back("\n#define MODE_CUBEMAP_ARRAY_TO_PANORAMA\n");
  75. copy.shader.initialize(copy_modes);
  76. memset(&copy.push_constant, 0, sizeof(CopyPushConstant));
  77. copy.shader_version = copy.shader.version_create();
  78. for (int i = 0; i < COPY_MODE_MAX; i++) {
  79. if (copy.shader.is_variant_enabled(i)) {
  80. copy.pipelines[i] = RD::get_singleton()->compute_pipeline_create(copy.shader.version_get_shader(copy.shader_version, i));
  81. }
  82. }
  83. }
  84. {
  85. Vector<String> copy_modes;
  86. copy_modes.push_back("\n");
  87. copy_modes.push_back("\n#define MODE_PANORAMA_TO_DP\n");
  88. copy_modes.push_back("\n#define MODE_TWO_SOURCES\n");
  89. copy_modes.push_back("\n#define MULTIVIEW\n");
  90. copy_modes.push_back("\n#define MULTIVIEW\n#define MODE_TWO_SOURCES\n");
  91. copy_to_fb.shader.initialize(copy_modes);
  92. if (!RendererCompositorRD::singleton->is_xr_enabled()) {
  93. copy_to_fb.shader.set_variant_enabled(COPY_TO_FB_MULTIVIEW, false);
  94. copy_to_fb.shader.set_variant_enabled(COPY_TO_FB_MULTIVIEW_WITH_DEPTH, false);
  95. }
  96. copy_to_fb.shader_version = copy_to_fb.shader.version_create();
  97. //use additive
  98. for (int i = 0; i < COPY_TO_FB_MAX; i++) {
  99. if (copy_to_fb.shader.is_variant_enabled(i)) {
  100. copy_to_fb.pipelines[i].setup(copy_to_fb.shader.version_get_shader(copy_to_fb.shader_version, i), RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RD::PipelineColorBlendState::create_disabled(), 0);
  101. } else {
  102. copy_to_fb.pipelines[i].clear();
  103. }
  104. }
  105. }
  106. }
  107. CopyEffects::~CopyEffects() {
  108. if (prefer_raster_effects) {
  109. blur_raster.shader.version_free(blur_raster.shader_version);
  110. } else {
  111. copy.shader.version_free(copy.shader_version);
  112. }
  113. copy_to_fb.shader.version_free(copy_to_fb.shader_version);
  114. singleton = nullptr;
  115. }
  116. void CopyEffects::copy_to_rect(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_rect, bool p_flip_y, bool p_force_luminance, bool p_all_source, bool p_8_bit_dst, bool p_alpha_to_one) {
  117. ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use the compute version of the copy_to_rect shader with the mobile renderer.");
  118. UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
  119. ERR_FAIL_NULL(uniform_set_cache);
  120. MaterialStorage *material_storage = MaterialStorage::get_singleton();
  121. ERR_FAIL_NULL(material_storage);
  122. memset(&copy.push_constant, 0, sizeof(CopyPushConstant));
  123. if (p_flip_y) {
  124. copy.push_constant.flags |= COPY_FLAG_FLIP_Y;
  125. }
  126. if (p_force_luminance) {
  127. copy.push_constant.flags |= COPY_FLAG_FORCE_LUMINANCE;
  128. }
  129. if (p_all_source) {
  130. copy.push_constant.flags |= COPY_FLAG_ALL_SOURCE;
  131. }
  132. if (p_alpha_to_one) {
  133. copy.push_constant.flags |= COPY_FLAG_ALPHA_TO_ONE;
  134. }
  135. copy.push_constant.section[0] = 0;
  136. copy.push_constant.section[1] = 0;
  137. copy.push_constant.section[2] = p_rect.size.width;
  138. copy.push_constant.section[3] = p_rect.size.height;
  139. copy.push_constant.target[0] = p_rect.position.x;
  140. copy.push_constant.target[1] = p_rect.position.y;
  141. // setup our uniforms
  142. RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
  143. RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_rd_texture }));
  144. RD::Uniform u_dest_texture(RD::UNIFORM_TYPE_IMAGE, 0, p_dest_texture);
  145. CopyMode mode = p_8_bit_dst ? COPY_MODE_SIMPLY_COPY_8BIT : COPY_MODE_SIMPLY_COPY;
  146. RID shader = copy.shader.version_get_shader(copy.shader_version, mode);
  147. ERR_FAIL_COND(shader.is_null());
  148. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  149. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, copy.pipelines[mode]);
  150. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
  151. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 3, u_dest_texture), 3);
  152. RD::get_singleton()->compute_list_set_push_constant(compute_list, &copy.push_constant, sizeof(CopyPushConstant));
  153. RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_rect.size.width, p_rect.size.height, 1);
  154. RD::get_singleton()->compute_list_end();
  155. }
  156. void CopyEffects::copy_cubemap_to_panorama(RID p_source_cube, RID p_dest_panorama, const Size2i &p_panorama_size, float p_lod, bool p_is_array) {
  157. ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use the compute version of the copy_cubemap_to_panorama shader with the mobile renderer.");
  158. UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
  159. ERR_FAIL_NULL(uniform_set_cache);
  160. MaterialStorage *material_storage = MaterialStorage::get_singleton();
  161. ERR_FAIL_NULL(material_storage);
  162. memset(&copy.push_constant, 0, sizeof(CopyPushConstant));
  163. copy.push_constant.section[0] = 0;
  164. copy.push_constant.section[1] = 0;
  165. copy.push_constant.section[2] = p_panorama_size.width;
  166. copy.push_constant.section[3] = p_panorama_size.height;
  167. copy.push_constant.target[0] = 0;
  168. copy.push_constant.target[1] = 0;
  169. copy.push_constant.camera_z_far = p_lod;
  170. // setup our uniforms
  171. RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
  172. RD::Uniform u_source_cube(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_cube }));
  173. RD::Uniform u_dest_panorama(RD::UNIFORM_TYPE_IMAGE, 0, p_dest_panorama);
  174. CopyMode mode = p_is_array ? COPY_MODE_CUBE_ARRAY_TO_PANORAMA : COPY_MODE_CUBE_TO_PANORAMA;
  175. RID shader = copy.shader.version_get_shader(copy.shader_version, mode);
  176. ERR_FAIL_COND(shader.is_null());
  177. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  178. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, copy.pipelines[mode]);
  179. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 0, u_source_cube), 0);
  180. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 3, u_dest_panorama), 3);
  181. RD::get_singleton()->compute_list_set_push_constant(compute_list, &copy.push_constant, sizeof(CopyPushConstant));
  182. RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_panorama_size.width, p_panorama_size.height, 1);
  183. RD::get_singleton()->compute_list_end();
  184. }
  185. void CopyEffects::copy_depth_to_rect(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_rect, bool p_flip_y) {
  186. ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use the compute version of the copy_depth_to_rect shader with the mobile renderer.");
  187. UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
  188. ERR_FAIL_NULL(uniform_set_cache);
  189. MaterialStorage *material_storage = MaterialStorage::get_singleton();
  190. ERR_FAIL_NULL(material_storage);
  191. memset(&copy.push_constant, 0, sizeof(CopyPushConstant));
  192. if (p_flip_y) {
  193. copy.push_constant.flags |= COPY_FLAG_FLIP_Y;
  194. }
  195. copy.push_constant.section[0] = 0;
  196. copy.push_constant.section[1] = 0;
  197. copy.push_constant.section[2] = p_rect.size.width;
  198. copy.push_constant.section[3] = p_rect.size.height;
  199. copy.push_constant.target[0] = p_rect.position.x;
  200. copy.push_constant.target[1] = p_rect.position.y;
  201. // setup our uniforms
  202. RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
  203. RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_rd_texture }));
  204. RD::Uniform u_dest_texture(RD::UNIFORM_TYPE_IMAGE, 0, p_dest_texture);
  205. CopyMode mode = COPY_MODE_SIMPLY_COPY_DEPTH;
  206. RID shader = copy.shader.version_get_shader(copy.shader_version, mode);
  207. ERR_FAIL_COND(shader.is_null());
  208. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  209. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, copy.pipelines[mode]);
  210. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
  211. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 3, u_dest_texture), 3);
  212. RD::get_singleton()->compute_list_set_push_constant(compute_list, &copy.push_constant, sizeof(CopyPushConstant));
  213. RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_rect.size.width, p_rect.size.height, 1);
  214. RD::get_singleton()->compute_list_end();
  215. }
  216. void CopyEffects::copy_depth_to_rect_and_linearize(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_rect, bool p_flip_y, float p_z_near, float p_z_far) {
  217. ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use the compute version of the copy_depth_to_rect_and_linearize shader with the mobile renderer.");
  218. UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
  219. ERR_FAIL_NULL(uniform_set_cache);
  220. MaterialStorage *material_storage = MaterialStorage::get_singleton();
  221. ERR_FAIL_NULL(material_storage);
  222. memset(&copy.push_constant, 0, sizeof(CopyPushConstant));
  223. if (p_flip_y) {
  224. copy.push_constant.flags |= COPY_FLAG_FLIP_Y;
  225. }
  226. copy.push_constant.section[0] = 0;
  227. copy.push_constant.section[1] = 0;
  228. copy.push_constant.section[2] = p_rect.size.width;
  229. copy.push_constant.section[3] = p_rect.size.height;
  230. copy.push_constant.target[0] = p_rect.position.x;
  231. copy.push_constant.target[1] = p_rect.position.y;
  232. copy.push_constant.camera_z_far = p_z_far;
  233. copy.push_constant.camera_z_near = p_z_near;
  234. // setup our uniforms
  235. RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
  236. RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_rd_texture }));
  237. RD::Uniform u_dest_texture(RD::UNIFORM_TYPE_IMAGE, 0, p_dest_texture);
  238. CopyMode mode = COPY_MODE_LINEARIZE_DEPTH;
  239. RID shader = copy.shader.version_get_shader(copy.shader_version, mode);
  240. ERR_FAIL_COND(shader.is_null());
  241. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  242. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, copy.pipelines[mode]);
  243. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
  244. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 3, u_dest_texture), 3);
  245. RD::get_singleton()->compute_list_set_push_constant(compute_list, &copy.push_constant, sizeof(CopyPushConstant));
  246. RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_rect.size.width, p_rect.size.height, 1);
  247. RD::get_singleton()->compute_list_end();
  248. }
  249. void CopyEffects::copy_to_atlas_fb(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2 &p_uv_rect, RD::DrawListID p_draw_list, bool p_flip_y, bool p_panorama) {
  250. ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use the compute version of the copy_to_atlas_fb shader with the mobile renderer.");
  251. UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
  252. ERR_FAIL_NULL(uniform_set_cache);
  253. MaterialStorage *material_storage = MaterialStorage::get_singleton();
  254. ERR_FAIL_NULL(material_storage);
  255. memset(&copy_to_fb.push_constant, 0, sizeof(CopyToFbPushConstant));
  256. copy_to_fb.push_constant.use_section = true;
  257. copy_to_fb.push_constant.section[0] = p_uv_rect.position.x;
  258. copy_to_fb.push_constant.section[1] = p_uv_rect.position.y;
  259. copy_to_fb.push_constant.section[2] = p_uv_rect.size.x;
  260. copy_to_fb.push_constant.section[3] = p_uv_rect.size.y;
  261. if (p_flip_y) {
  262. copy_to_fb.push_constant.flip_y = true;
  263. }
  264. // setup our uniforms
  265. RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
  266. RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_rd_texture }));
  267. CopyToFBMode mode = p_panorama ? COPY_TO_FB_COPY_PANORAMA_TO_DP : COPY_TO_FB_COPY;
  268. RID shader = copy_to_fb.shader.version_get_shader(copy_to_fb.shader_version, mode);
  269. ERR_FAIL_COND(shader.is_null());
  270. RD::DrawListID draw_list = p_draw_list;
  271. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, copy_to_fb.pipelines[mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  272. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
  273. RD::get_singleton()->draw_list_bind_index_array(draw_list, material_storage->get_quad_index_array());
  274. RD::get_singleton()->draw_list_set_push_constant(draw_list, &copy_to_fb.push_constant, sizeof(CopyToFbPushConstant));
  275. RD::get_singleton()->draw_list_draw(draw_list, true);
  276. }
  277. void CopyEffects::copy_to_fb_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2i &p_rect, bool p_flip_y, bool p_force_luminance, bool p_alpha_to_zero, bool p_srgb, RID p_secondary, bool p_multiview) {
  278. ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use the compute version of the copy_to_fb_rect shader with the mobile renderer.");
  279. UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
  280. ERR_FAIL_NULL(uniform_set_cache);
  281. MaterialStorage *material_storage = MaterialStorage::get_singleton();
  282. ERR_FAIL_NULL(material_storage);
  283. memset(&copy_to_fb.push_constant, 0, sizeof(CopyToFbPushConstant));
  284. if (p_flip_y) {
  285. copy_to_fb.push_constant.flip_y = true;
  286. }
  287. if (p_force_luminance) {
  288. copy_to_fb.push_constant.force_luminance = true;
  289. }
  290. if (p_alpha_to_zero) {
  291. copy_to_fb.push_constant.alpha_to_zero = true;
  292. }
  293. if (p_srgb) {
  294. copy_to_fb.push_constant.srgb = true;
  295. }
  296. // setup our uniforms
  297. RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
  298. RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_rd_texture }));
  299. CopyToFBMode mode;
  300. if (p_multiview) {
  301. mode = p_secondary.is_valid() ? COPY_TO_FB_MULTIVIEW_WITH_DEPTH : COPY_TO_FB_MULTIVIEW;
  302. } else {
  303. mode = p_secondary.is_valid() ? COPY_TO_FB_COPY2 : COPY_TO_FB_COPY;
  304. }
  305. RID shader = copy_to_fb.shader.version_get_shader(copy_to_fb.shader_version, mode);
  306. ERR_FAIL_COND(shader.is_null());
  307. RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD, Vector<Color>(), 1.0, 0, p_rect);
  308. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, copy_to_fb.pipelines[mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  309. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
  310. if (p_secondary.is_valid()) {
  311. // TODO may need to do this differently when reading from depth buffer for multiview
  312. RD::Uniform u_secondary(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_secondary }));
  313. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 1, u_secondary), 1);
  314. }
  315. RD::get_singleton()->draw_list_bind_index_array(draw_list, material_storage->get_quad_index_array());
  316. RD::get_singleton()->draw_list_set_push_constant(draw_list, &copy_to_fb.push_constant, sizeof(CopyToFbPushConstant));
  317. RD::get_singleton()->draw_list_draw(draw_list, true);
  318. RD::get_singleton()->draw_list_end();
  319. }
  320. void CopyEffects::copy_raster(RID p_source_texture, RID p_dest_framebuffer) {
  321. ERR_FAIL_COND_MSG(!prefer_raster_effects, "Can't use the raster version of the copy with the clustered renderer.");
  322. UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
  323. ERR_FAIL_NULL(uniform_set_cache);
  324. MaterialStorage *material_storage = MaterialStorage::get_singleton();
  325. ERR_FAIL_NULL(material_storage);
  326. memset(&blur_raster.push_constant, 0, sizeof(BlurRasterPushConstant));
  327. // setup our uniforms
  328. RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
  329. RD::Uniform u_source_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_texture }));
  330. RID shader = blur_raster.shader.version_get_shader(blur_raster.shader_version, BLUR_MODE_COPY);
  331. ERR_FAIL_COND(shader.is_null());
  332. // Just copy it back (we use our blur raster shader here)..
  333. RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
  334. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur_raster.pipelines[BLUR_MODE_COPY].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  335. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_source_texture), 0);
  336. RD::get_singleton()->draw_list_bind_index_array(draw_list, material_storage->get_quad_index_array());
  337. memset(&blur_raster.push_constant, 0, sizeof(BlurRasterPushConstant));
  338. RD::get_singleton()->draw_list_set_push_constant(draw_list, &blur_raster.push_constant, sizeof(BlurRasterPushConstant));
  339. RD::get_singleton()->draw_list_draw(draw_list, true);
  340. RD::get_singleton()->draw_list_end();
  341. }
  342. void CopyEffects::gaussian_blur(RID p_source_rd_texture, RID p_texture, const Rect2i &p_region, bool p_8bit_dst) {
  343. ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use the compute version of the gaussian blur with the mobile renderer.");
  344. UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
  345. ERR_FAIL_NULL(uniform_set_cache);
  346. MaterialStorage *material_storage = MaterialStorage::get_singleton();
  347. ERR_FAIL_NULL(material_storage);
  348. memset(&copy.push_constant, 0, sizeof(CopyPushConstant));
  349. copy.push_constant.section[0] = p_region.position.x;
  350. copy.push_constant.section[1] = p_region.position.y;
  351. copy.push_constant.section[2] = p_region.size.width;
  352. copy.push_constant.section[3] = p_region.size.height;
  353. // setup our uniforms
  354. RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
  355. RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_rd_texture }));
  356. RD::Uniform u_texture(RD::UNIFORM_TYPE_IMAGE, 0, p_texture);
  357. CopyMode mode = p_8bit_dst ? COPY_MODE_GAUSSIAN_COPY_8BIT : COPY_MODE_GAUSSIAN_COPY;
  358. RID shader = copy.shader.version_get_shader(copy.shader_version, mode);
  359. ERR_FAIL_COND(shader.is_null());
  360. //HORIZONTAL
  361. RD::DrawListID compute_list = RD::get_singleton()->compute_list_begin();
  362. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, copy.pipelines[mode]);
  363. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
  364. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 3, u_texture), 3);
  365. RD::get_singleton()->compute_list_set_push_constant(compute_list, &copy.push_constant, sizeof(CopyPushConstant));
  366. RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_region.size.width, p_region.size.height, 1);
  367. RD::get_singleton()->compute_list_end();
  368. }
  369. void CopyEffects::gaussian_glow(RID p_source_rd_texture, RID p_back_texture, const Size2i &p_size, float p_strength, bool p_high_quality, bool p_first_pass, float p_luminance_cap, float p_exposure, float p_bloom, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, RID p_auto_exposure, float p_auto_exposure_grey) {
  370. ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use the compute version of the gaussian glow with the mobile renderer.");
  371. UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
  372. ERR_FAIL_NULL(uniform_set_cache);
  373. MaterialStorage *material_storage = MaterialStorage::get_singleton();
  374. ERR_FAIL_NULL(material_storage);
  375. memset(&copy.push_constant, 0, sizeof(CopyPushConstant));
  376. CopyMode copy_mode = p_first_pass && p_auto_exposure.is_valid() ? COPY_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE : COPY_MODE_GAUSSIAN_GLOW;
  377. uint32_t base_flags = 0;
  378. copy.push_constant.section[2] = p_size.x;
  379. copy.push_constant.section[3] = p_size.y;
  380. copy.push_constant.glow_strength = p_strength;
  381. copy.push_constant.glow_bloom = p_bloom;
  382. copy.push_constant.glow_hdr_threshold = p_hdr_bleed_threshold;
  383. copy.push_constant.glow_hdr_scale = p_hdr_bleed_scale;
  384. copy.push_constant.glow_exposure = p_exposure;
  385. copy.push_constant.glow_white = 0; //actually unused
  386. copy.push_constant.glow_luminance_cap = p_luminance_cap;
  387. copy.push_constant.glow_auto_exposure_grey = p_auto_exposure_grey; //unused also
  388. // setup our uniforms
  389. RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
  390. RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_rd_texture }));
  391. RD::Uniform u_back_texture(RD::UNIFORM_TYPE_IMAGE, 0, p_back_texture);
  392. RID shader = copy.shader.version_get_shader(copy.shader_version, copy_mode);
  393. ERR_FAIL_COND(shader.is_null());
  394. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  395. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, copy.pipelines[copy_mode]);
  396. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
  397. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 3, u_back_texture), 3);
  398. if (p_auto_exposure.is_valid() && p_first_pass) {
  399. RD::Uniform u_auto_exposure(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_auto_exposure }));
  400. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 1, u_auto_exposure), 1);
  401. }
  402. copy.push_constant.flags = base_flags | (p_first_pass ? COPY_FLAG_GLOW_FIRST_PASS : 0) | (p_high_quality ? COPY_FLAG_HIGH_QUALITY_GLOW : 0);
  403. RD::get_singleton()->compute_list_set_push_constant(compute_list, &copy.push_constant, sizeof(CopyPushConstant));
  404. RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_size.width, p_size.height, 1);
  405. RD::get_singleton()->compute_list_end();
  406. }
  407. void CopyEffects::gaussian_glow_raster(RID p_source_rd_texture, float p_luminance_multiplier, RID p_framebuffer_half, RID p_rd_texture_half, RID p_dest_framebuffer, const Size2i &p_size, float p_strength, bool p_high_quality, bool p_first_pass, float p_luminance_cap, float p_exposure, float p_bloom, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, RID p_auto_exposure, float p_auto_exposure_grey) {
  408. ERR_FAIL_COND_MSG(!prefer_raster_effects, "Can't use the raster version of the gaussian glow with the clustered renderer.");
  409. UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
  410. ERR_FAIL_NULL(uniform_set_cache);
  411. MaterialStorage *material_storage = MaterialStorage::get_singleton();
  412. ERR_FAIL_NULL(material_storage);
  413. memset(&blur_raster.push_constant, 0, sizeof(BlurRasterPushConstant));
  414. BlurRasterMode blur_mode = p_first_pass && p_auto_exposure.is_valid() ? BLUR_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE : BLUR_MODE_GAUSSIAN_GLOW;
  415. uint32_t base_flags = 0;
  416. blur_raster.push_constant.pixel_size[0] = 1.0 / float(p_size.x);
  417. blur_raster.push_constant.pixel_size[1] = 1.0 / float(p_size.y);
  418. blur_raster.push_constant.glow_strength = p_strength;
  419. blur_raster.push_constant.glow_bloom = p_bloom;
  420. blur_raster.push_constant.glow_hdr_threshold = p_hdr_bleed_threshold;
  421. blur_raster.push_constant.glow_hdr_scale = p_hdr_bleed_scale;
  422. blur_raster.push_constant.glow_exposure = p_exposure;
  423. blur_raster.push_constant.glow_white = 0; //actually unused
  424. blur_raster.push_constant.glow_luminance_cap = p_luminance_cap;
  425. blur_raster.push_constant.glow_auto_exposure_grey = p_auto_exposure_grey; //unused also
  426. blur_raster.push_constant.luminance_multiplier = p_luminance_multiplier;
  427. // setup our uniforms
  428. RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
  429. RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_rd_texture }));
  430. RD::Uniform u_rd_texture_half(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_rd_texture_half }));
  431. RID shader = blur_raster.shader.version_get_shader(blur_raster.shader_version, blur_mode);
  432. ERR_FAIL_COND(shader.is_null());
  433. //HORIZONTAL
  434. RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_framebuffer_half, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
  435. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur_raster.pipelines[blur_mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_framebuffer_half)));
  436. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
  437. if (p_auto_exposure.is_valid() && p_first_pass) {
  438. RD::Uniform u_auto_exposure(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_auto_exposure }));
  439. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 1, u_auto_exposure), 1);
  440. }
  441. RD::get_singleton()->draw_list_bind_index_array(draw_list, material_storage->get_quad_index_array());
  442. blur_raster.push_constant.flags = base_flags | BLUR_FLAG_HORIZONTAL | (p_first_pass ? BLUR_FLAG_GLOW_FIRST_PASS : 0);
  443. RD::get_singleton()->draw_list_set_push_constant(draw_list, &blur_raster.push_constant, sizeof(BlurRasterPushConstant));
  444. RD::get_singleton()->draw_list_draw(draw_list, true);
  445. RD::get_singleton()->draw_list_end();
  446. blur_mode = BLUR_MODE_GAUSSIAN_GLOW;
  447. shader = blur_raster.shader.version_get_shader(blur_raster.shader_version, blur_mode);
  448. ERR_FAIL_COND(shader.is_null());
  449. //VERTICAL
  450. draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
  451. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur_raster.pipelines[blur_mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  452. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_rd_texture_half), 0);
  453. RD::get_singleton()->draw_list_bind_index_array(draw_list, material_storage->get_quad_index_array());
  454. blur_raster.push_constant.flags = base_flags;
  455. RD::get_singleton()->draw_list_set_push_constant(draw_list, &blur_raster.push_constant, sizeof(BlurRasterPushConstant));
  456. RD::get_singleton()->draw_list_draw(draw_list, true);
  457. RD::get_singleton()->draw_list_end();
  458. }
  459. void CopyEffects::make_mipmap(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size) {
  460. ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use the compute version of the make_mipmap shader with the mobile renderer.");
  461. UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
  462. ERR_FAIL_NULL(uniform_set_cache);
  463. MaterialStorage *material_storage = MaterialStorage::get_singleton();
  464. ERR_FAIL_NULL(material_storage);
  465. memset(&copy.push_constant, 0, sizeof(CopyPushConstant));
  466. copy.push_constant.section[0] = 0;
  467. copy.push_constant.section[1] = 0;
  468. copy.push_constant.section[2] = p_size.width;
  469. copy.push_constant.section[3] = p_size.height;
  470. // setup our uniforms
  471. RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
  472. RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_rd_texture }));
  473. RD::Uniform u_dest_texture(RD::UNIFORM_TYPE_IMAGE, 0, p_dest_texture);
  474. CopyMode mode = COPY_MODE_MIPMAP;
  475. RID shader = copy.shader.version_get_shader(copy.shader_version, mode);
  476. ERR_FAIL_COND(shader.is_null());
  477. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  478. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, copy.pipelines[mode]);
  479. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
  480. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 3, u_dest_texture), 3);
  481. RD::get_singleton()->compute_list_set_push_constant(compute_list, &copy.push_constant, sizeof(CopyPushConstant));
  482. RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_size.width, p_size.height, 1);
  483. RD::get_singleton()->compute_list_end();
  484. }
  485. void CopyEffects::make_mipmap_raster(RID p_source_rd_texture, RID p_dest_framebuffer, const Size2i &p_size) {
  486. ERR_FAIL_COND_MSG(!prefer_raster_effects, "Can't use the raster version of mipmap with the clustered renderer.");
  487. UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
  488. ERR_FAIL_NULL(uniform_set_cache);
  489. MaterialStorage *material_storage = MaterialStorage::get_singleton();
  490. ERR_FAIL_NULL(material_storage);
  491. memset(&blur_raster.push_constant, 0, sizeof(BlurRasterPushConstant));
  492. BlurRasterMode mode = BLUR_MIPMAP;
  493. blur_raster.push_constant.pixel_size[0] = 1.0 / float(p_size.x);
  494. blur_raster.push_constant.pixel_size[1] = 1.0 / float(p_size.y);
  495. // setup our uniforms
  496. RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
  497. RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_rd_texture }));
  498. RID shader = blur_raster.shader.version_get_shader(blur_raster.shader_version, mode);
  499. ERR_FAIL_COND(shader.is_null());
  500. RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
  501. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur_raster.pipelines[mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  502. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
  503. RD::get_singleton()->draw_list_bind_index_array(draw_list, material_storage->get_quad_index_array());
  504. RD::get_singleton()->draw_list_set_push_constant(draw_list, &blur_raster.push_constant, sizeof(BlurRasterPushConstant));
  505. RD::get_singleton()->draw_list_draw(draw_list, true);
  506. RD::get_singleton()->draw_list_end();
  507. }
  508. void CopyEffects::set_color(RID p_dest_texture, const Color &p_color, const Rect2i &p_region, bool p_8bit_dst) {
  509. ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use the compute version of the set_color shader with the mobile renderer.");
  510. UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
  511. ERR_FAIL_NULL(uniform_set_cache);
  512. memset(&copy.push_constant, 0, sizeof(CopyPushConstant));
  513. copy.push_constant.section[0] = 0;
  514. copy.push_constant.section[1] = 0;
  515. copy.push_constant.section[2] = p_region.size.width;
  516. copy.push_constant.section[3] = p_region.size.height;
  517. copy.push_constant.target[0] = p_region.position.x;
  518. copy.push_constant.target[1] = p_region.position.y;
  519. copy.push_constant.set_color[0] = p_color.r;
  520. copy.push_constant.set_color[1] = p_color.g;
  521. copy.push_constant.set_color[2] = p_color.b;
  522. copy.push_constant.set_color[3] = p_color.a;
  523. // setup our uniforms
  524. RD::Uniform u_dest_texture(RD::UNIFORM_TYPE_IMAGE, 0, p_dest_texture);
  525. CopyMode mode = p_8bit_dst ? COPY_MODE_SET_COLOR_8BIT : COPY_MODE_SET_COLOR;
  526. RID shader = copy.shader.version_get_shader(copy.shader_version, mode);
  527. ERR_FAIL_COND(shader.is_null());
  528. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  529. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, copy.pipelines[mode]);
  530. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 3, u_dest_texture), 3);
  531. RD::get_singleton()->compute_list_set_push_constant(compute_list, &copy.push_constant, sizeof(CopyPushConstant));
  532. RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_region.size.width, p_region.size.height, 1);
  533. RD::get_singleton()->compute_list_end();
  534. }