| 1 | /**************************************************************************/ |
| 2 | /* render_scene_buffers_rd.cpp */ |
| 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 | |
| 31 | #include "render_scene_buffers_rd.h" |
| 32 | #include "render_scene_buffers_rd.compat.inc" |
| 33 | |
| 34 | #include "servers/rendering/renderer_rd/storage_rd/texture_storage.h" |
| 35 | |
| 36 | RenderSceneBuffersRD::RenderSceneBuffersRD() { |
| 37 | } |
| 38 | |
| 39 | RenderSceneBuffersRD::~RenderSceneBuffersRD() { |
| 40 | cleanup(); |
| 41 | |
| 42 | data_buffers.clear(); |
| 43 | |
| 44 | RendererRD::MaterialStorage::get_singleton()->samplers_rd_free(samplers); |
| 45 | } |
| 46 | |
| 47 | void RenderSceneBuffersRD::_bind_methods() { |
| 48 | ClassDB::bind_method(D_METHOD("has_texture", "context", "name"), &RenderSceneBuffersRD::has_texture); |
| 49 | ClassDB::bind_method(D_METHOD("create_texture", "context", "name", "data_format", "usage_bits", "texture_samples", "size", "layers", "mipmaps", "unique", "discardable"), &RenderSceneBuffersRD::create_texture); |
| 50 | ClassDB::bind_method(D_METHOD("create_texture_from_format", "context", "name", "format", "view", "unique"), &RenderSceneBuffersRD::_create_texture_from_format); |
| 51 | ClassDB::bind_method(D_METHOD("create_texture_view", "context", "name", "view_name", "view"), &RenderSceneBuffersRD::_create_texture_view); |
| 52 | ClassDB::bind_method(D_METHOD("get_texture", "context", "name"), &RenderSceneBuffersRD::get_texture); |
| 53 | ClassDB::bind_method(D_METHOD("get_texture_format", "context", "name"), &RenderSceneBuffersRD::_get_texture_format); |
| 54 | ClassDB::bind_method(D_METHOD("get_texture_slice", "context", "name", "layer", "mipmap", "layers", "mipmaps"), &RenderSceneBuffersRD::get_texture_slice); |
| 55 | ClassDB::bind_method(D_METHOD("get_texture_slice_view", "context", "name", "layer", "mipmap", "layers", "mipmaps", "view"), &RenderSceneBuffersRD::_get_texture_slice_view); |
| 56 | ClassDB::bind_method(D_METHOD("get_texture_slice_size", "context", "name", "mipmap"), &RenderSceneBuffersRD::get_texture_slice_size); |
| 57 | ClassDB::bind_method(D_METHOD("clear_context", "context"), &RenderSceneBuffersRD::clear_context); |
| 58 | |
| 59 | // Access to some core buffers so users don't need to know their names. |
| 60 | ClassDB::bind_method(D_METHOD("get_color_texture", "msaa"), &RenderSceneBuffersRD::_get_color_texture, DEFVAL(false)); |
| 61 | ClassDB::bind_method(D_METHOD("get_color_layer", "layer", "msaa"), &RenderSceneBuffersRD::_get_color_layer, DEFVAL(false)); |
| 62 | ClassDB::bind_method(D_METHOD("get_depth_texture", "msaa"), &RenderSceneBuffersRD::_get_depth_texture, DEFVAL(false)); |
| 63 | ClassDB::bind_method(D_METHOD("get_depth_layer", "layer", "msaa"), &RenderSceneBuffersRD::_get_depth_layer, DEFVAL(false)); |
| 64 | ClassDB::bind_method(D_METHOD("get_velocity_texture", "msaa"), &RenderSceneBuffersRD::_get_velocity_texture, DEFVAL(false)); |
| 65 | ClassDB::bind_method(D_METHOD("get_velocity_layer", "layer", "msaa"), &RenderSceneBuffersRD::_get_velocity_layer, DEFVAL(false)); |
| 66 | |
| 67 | // Expose a few properties we're likely to use externally |
| 68 | ClassDB::bind_method(D_METHOD("get_render_target"), &RenderSceneBuffersRD::get_render_target); |
| 69 | ClassDB::bind_method(D_METHOD("get_view_count"), &RenderSceneBuffersRD::get_view_count); |
| 70 | ClassDB::bind_method(D_METHOD("get_internal_size"), &RenderSceneBuffersRD::get_internal_size); |
| 71 | ClassDB::bind_method(D_METHOD("get_target_size"), &RenderSceneBuffersRD::get_target_size); |
| 72 | ClassDB::bind_method(D_METHOD("get_scaling_3d_mode"), &RenderSceneBuffersRD::get_scaling_3d_mode); |
| 73 | ClassDB::bind_method(D_METHOD("get_fsr_sharpness"), &RenderSceneBuffersRD::get_fsr_sharpness); |
| 74 | ClassDB::bind_method(D_METHOD("get_msaa_3d"), &RenderSceneBuffersRD::get_msaa_3d); |
| 75 | ClassDB::bind_method(D_METHOD("get_texture_samples"), &RenderSceneBuffersRD::get_texture_samples); |
| 76 | ClassDB::bind_method(D_METHOD("get_screen_space_aa"), &RenderSceneBuffersRD::get_screen_space_aa); |
| 77 | ClassDB::bind_method(D_METHOD("get_use_taa"), &RenderSceneBuffersRD::get_use_taa); |
| 78 | ClassDB::bind_method(D_METHOD("get_use_debanding"), &RenderSceneBuffersRD::get_use_debanding); |
| 79 | } |
| 80 | |
| 81 | void RenderSceneBuffersRD::update_sizes(NamedTexture &p_named_texture) { |
| 82 | ERR_FAIL_COND(p_named_texture.texture.is_null()); |
| 83 | |
| 84 | p_named_texture.sizes.resize(p_named_texture.format.mipmaps); |
| 85 | |
| 86 | Size2i mipmap_size = Size2i(p_named_texture.format.width, p_named_texture.format.height); |
| 87 | for (uint32_t mipmap = 0; mipmap < p_named_texture.format.mipmaps; mipmap++) { |
| 88 | p_named_texture.sizes.ptrw()[mipmap] = mipmap_size; |
| 89 | |
| 90 | mipmap_size = Size2i(mipmap_size.width >> 1, mipmap_size.height >> 1).maxi(1); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | void RenderSceneBuffersRD::free_named_texture(NamedTexture &p_named_texture) { |
| 95 | if (p_named_texture.texture.is_valid()) { |
| 96 | RD::get_singleton()->free_rid(p_named_texture.texture); |
| 97 | } |
| 98 | p_named_texture.texture = RID(); |
| 99 | p_named_texture.slices.clear(); // slices should be freed automatically as dependents... |
| 100 | } |
| 101 | |
| 102 | void RenderSceneBuffersRD::update_samplers() { |
| 103 | float computed_mipmap_bias = texture_mipmap_bias; |
| 104 | |
| 105 | if (use_taa || (RS::scaling_3d_mode_type(scaling_3d_mode) == RS::VIEWPORT_SCALING_3D_TYPE_TEMPORAL)) { |
| 106 | // Use negative mipmap LOD bias when TAA or FSR2 is enabled to compensate for loss of sharpness. |
| 107 | // This restores sharpness in still images to be roughly at the same level as without TAA, |
| 108 | // but moving scenes will still be blurrier. |
| 109 | computed_mipmap_bias -= 0.5; |
| 110 | } |
| 111 | |
| 112 | if (screen_space_aa == RS::VIEWPORT_SCREEN_SPACE_AA_FXAA) { |
| 113 | // Use negative mipmap LOD bias when FXAA is enabled to compensate for loss of sharpness. |
| 114 | // If both TAA and FXAA are enabled, combine their negative LOD biases together. |
| 115 | computed_mipmap_bias -= 0.25; |
| 116 | } |
| 117 | |
| 118 | RendererRD::MaterialStorage *material_storage = RendererRD::MaterialStorage::get_singleton(); |
| 119 | material_storage->samplers_rd_free(samplers); |
| 120 | samplers = material_storage->samplers_rd_allocate(computed_mipmap_bias, anisotropic_filtering_level); |
| 121 | } |
| 122 | |
| 123 | void RenderSceneBuffersRD::cleanup() { |
| 124 | // Free our data buffers (but don't destroy them) |
| 125 | for (KeyValue<StringName, Ref<RenderBufferCustomDataRD>> &E : data_buffers) { |
| 126 | E.value->free_data(); |
| 127 | } |
| 128 | |
| 129 | // Clear our named textures |
| 130 | for (KeyValue<NTKey, NamedTexture> &E : named_textures) { |
| 131 | free_named_texture(E.value); |
| 132 | } |
| 133 | named_textures.clear(); |
| 134 | |
| 135 | // Clear weight_buffer / blur textures. |
| 136 | for (WeightBuffers &weight_buffer : weight_buffers) { |
| 137 | if (weight_buffer.weight.is_valid()) { |
| 138 | RD::get_singleton()->free_rid(weight_buffer.weight); |
| 139 | weight_buffer.weight = RID(); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | #ifdef METAL_ENABLED |
| 144 | if (mfx_spatial_context) { |
| 145 | memdelete(mfx_spatial_context); |
| 146 | mfx_spatial_context = nullptr; |
| 147 | } |
| 148 | #endif |
| 149 | } |
| 150 | |
| 151 | void RenderSceneBuffersRD::configure(const RenderSceneBuffersConfiguration *p_config) { |
| 152 | RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton(); |
| 153 | |
| 154 | render_target = p_config->get_render_target(); |
| 155 | force_hdr = texture_storage->render_target_is_using_hdr(render_target); |
| 156 | |
| 157 | target_size = p_config->get_target_size(); |
| 158 | internal_size = p_config->get_internal_size(); |
| 159 | view_count = p_config->get_view_count(); |
| 160 | |
| 161 | scaling_3d_mode = p_config->get_scaling_3d_mode(); |
| 162 | msaa_3d = p_config->get_msaa_3d(); |
| 163 | screen_space_aa = p_config->get_screen_space_aa(); |
| 164 | |
| 165 | fsr_sharpness = p_config->get_fsr_sharpness(); |
| 166 | texture_mipmap_bias = p_config->get_texture_mipmap_bias(); |
| 167 | anisotropic_filtering_level = p_config->get_anisotropic_filtering_level(); |
| 168 | use_taa = p_config->get_use_taa(); |
| 169 | use_debanding = p_config->get_use_debanding(); |
| 170 | |
| 171 | ERR_FAIL_COND_MSG(view_count == 0, "Must have at least 1 view"); |
| 172 | |
| 173 | vrs_mode = texture_storage->render_target_get_vrs_mode(render_target); |
| 174 | |
| 175 | update_samplers(); |
| 176 | |
| 177 | // cleanout any old buffers we had. |
| 178 | cleanup(); |
| 179 | |
| 180 | // Create our color buffer. |
| 181 | const bool resolve_target = msaa_3d != RS::VIEWPORT_MSAA_DISABLED; |
| 182 | create_texture(RB_SCOPE_BUFFERS, RB_TEX_COLOR, get_base_data_format(), get_color_usage_bits(resolve_target, false, can_be_storage)); |
| 183 | |
| 184 | // TODO: Detect when it is safe to use RD::TEXTURE_USAGE_TRANSIENT_BIT for RB_TEX_DEPTH, RB_TEX_COLOR_MSAA and/or RB_TEX_DEPTH_MSAA. |
| 185 | // (it means we cannot sample from it, we cannot copy from/to it) to save VRAM (and maybe performance too). |
| 186 | |
| 187 | // Create our depth buffer. |
| 188 | create_texture(RB_SCOPE_BUFFERS, RB_TEX_DEPTH, get_depth_format(resolve_target, false, can_be_storage), get_depth_usage_bits(resolve_target, false, can_be_storage)); |
| 189 | |
| 190 | // Create our MSAA buffers. |
| 191 | if (msaa_3d == RS::VIEWPORT_MSAA_DISABLED) { |
| 192 | texture_samples = RD::TEXTURE_SAMPLES_1; |
| 193 | } else { |
| 194 | texture_samples = msaa_to_samples(msaa_3d); |
| 195 | create_texture(RB_SCOPE_BUFFERS, RB_TEX_COLOR_MSAA, get_base_data_format(), get_color_usage_bits(false, true, can_be_storage), texture_samples, Size2i(), 0, 1, true, true); |
| 196 | create_texture(RB_SCOPE_BUFFERS, RB_TEX_DEPTH_MSAA, get_depth_format(false, true, can_be_storage), get_depth_usage_bits(false, true, can_be_storage), texture_samples, Size2i(), 0, 1, true, true); |
| 197 | } |
| 198 | |
| 199 | // VRS (note, our vrs object will only be set if VRS is supported) |
| 200 | RID vrs_texture; |
| 201 | if (vrs && vrs_mode != RS::VIEWPORT_VRS_DISABLED) { |
| 202 | vrs_texture = create_texture(RB_SCOPE_VRS, RB_TEXTURE, get_vrs_format(), get_vrs_usage_bits(), RD::TEXTURE_SAMPLES_1, vrs->get_vrs_texture_size(internal_size)); |
| 203 | } |
| 204 | |
| 205 | // (re-)configure any named buffers |
| 206 | for (KeyValue<StringName, Ref<RenderBufferCustomDataRD>> &E : data_buffers) { |
| 207 | E.value->configure(this); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | void RenderSceneBuffersRD::configure_for_reflections(const Size2i p_reflection_size) { |
| 212 | // For now our render buffers for reflections are only used for effects/environment (Sky/Fog/Etc) |
| 213 | // Possibly at some point move our entire reflection atlas buffer management into this class |
| 214 | |
| 215 | target_size = p_reflection_size; |
| 216 | internal_size = p_reflection_size; |
| 217 | render_target = RID(); |
| 218 | scaling_3d_mode = RS::VIEWPORT_SCALING_3D_MODE_OFF; |
| 219 | fsr_sharpness = 0.0; |
| 220 | msaa_3d = RS::VIEWPORT_MSAA_DISABLED; |
| 221 | screen_space_aa = RS::VIEWPORT_SCREEN_SPACE_AA_DISABLED; |
| 222 | use_taa = false; |
| 223 | use_debanding = false; |
| 224 | view_count = 1; |
| 225 | |
| 226 | // cleanout any old buffers we had. |
| 227 | cleanup(); |
| 228 | |
| 229 | // (re-)configure any named buffers |
| 230 | for (KeyValue<StringName, Ref<RenderBufferCustomDataRD>> &E : data_buffers) { |
| 231 | E.value->configure(this); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | void RenderSceneBuffersRD::set_fsr_sharpness(float p_fsr_sharpness) { |
| 236 | fsr_sharpness = p_fsr_sharpness; |
| 237 | } |
| 238 | |
| 239 | void RenderSceneBuffersRD::set_texture_mipmap_bias(float p_texture_mipmap_bias) { |
| 240 | texture_mipmap_bias = p_texture_mipmap_bias; |
| 241 | |
| 242 | update_samplers(); |
| 243 | } |
| 244 | |
| 245 | void RenderSceneBuffersRD::set_anisotropic_filtering_level(RS::ViewportAnisotropicFiltering p_anisotropic_filtering_level) { |
| 246 | anisotropic_filtering_level = p_anisotropic_filtering_level; |
| 247 | |
| 248 | update_samplers(); |
| 249 | } |
| 250 | |
| 251 | void RenderSceneBuffersRD::set_use_debanding(bool p_use_debanding) { |
| 252 | use_debanding = p_use_debanding; |
| 253 | } |
| 254 | |
| 255 | #ifdef METAL_ENABLED |
| 256 | void RenderSceneBuffersRD::ensure_mfx(RendererRD::MFXSpatialEffect *p_effect) { |
| 257 | if (mfx_spatial_context) { |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton(); |
| 262 | RenderingDevice *rd = RD::get_singleton(); |
| 263 | |
| 264 | // Determine the output format of the render target. |
| 265 | RID dest = texture_storage->render_target_get_rd_texture(render_target); |
| 266 | RD::TextureFormat tf = rd->texture_get_format(dest); |
| 267 | RD::DataFormat output_format = tf.format; |
| 268 | |
| 269 | RendererRD::MFXSpatialEffect::CreateParams params = { |
| 270 | .input_size = internal_size, |
| 271 | .output_size = target_size, |
| 272 | .input_format = get_base_data_format(), |
| 273 | .output_format = output_format, |
| 274 | }; |
| 275 | |
| 276 | mfx_spatial_context = p_effect->create_context(params); |
| 277 | } |
| 278 | #endif |
| 279 | |
| 280 | // Named textures |
| 281 | |
| 282 | bool RenderSceneBuffersRD::has_texture(const StringName &p_context, const StringName &p_texture_name) const { |
| 283 | NTKey key(p_context, p_texture_name); |
| 284 | |
| 285 | return named_textures.has(key); |
| 286 | } |
| 287 | |
| 288 | RID RenderSceneBuffersRD::create_texture(const StringName &p_context, const StringName &p_texture_name, const RD::DataFormat p_data_format, const uint32_t p_usage_bits, const RD::TextureSamples p_texture_samples, const Size2i p_size, const uint32_t p_layers, const uint32_t p_mipmaps, bool p_unique, bool p_discardable) { |
| 289 | // Keep some useful data, we use default values when these are 0. |
| 290 | Size2i size = p_size == Size2i(0, 0) ? internal_size : p_size; |
| 291 | uint32_t layers = p_layers == 0 ? view_count : p_layers; |
| 292 | uint32_t mipmaps = p_mipmaps == 0 ? 1 : p_mipmaps; |
| 293 | |
| 294 | // Create our texture |
| 295 | RD::TextureFormat tf; |
| 296 | tf.format = p_data_format; |
| 297 | if (layers > 1) { |
| 298 | tf.texture_type = RD::TEXTURE_TYPE_2D_ARRAY; |
| 299 | } |
| 300 | |
| 301 | tf.width = size.x; |
| 302 | tf.height = size.y; |
| 303 | tf.depth = 1; |
| 304 | tf.array_layers = layers; |
| 305 | tf.mipmaps = mipmaps; |
| 306 | tf.usage_bits = p_usage_bits; |
| 307 | tf.samples = p_texture_samples; |
| 308 | tf.is_discardable = p_discardable; |
| 309 | |
| 310 | return create_texture_from_format(p_context, p_texture_name, tf, RD::TextureView(), p_unique); |
| 311 | } |
| 312 | |
| 313 | RID RenderSceneBuffersRD::_create_texture_from_format(const StringName &p_context, const StringName &p_texture_name, const Ref<RDTextureFormat> &p_texture_format, const Ref<RDTextureView> &p_view, bool p_unique) { |
| 314 | ERR_FAIL_COND_V(p_texture_format.is_null(), RID()); |
| 315 | |
| 316 | RD::TextureView texture_view; |
| 317 | if (p_view.is_valid()) { // only use when supplied, else default. |
| 318 | texture_view = p_view->base; |
| 319 | } |
| 320 | |
| 321 | return create_texture_from_format(p_context, p_texture_name, p_texture_format->base, texture_view, p_unique); |
| 322 | } |
| 323 | |
| 324 | RID RenderSceneBuffersRD::create_texture_from_format(const StringName &p_context, const StringName &p_texture_name, const RD::TextureFormat &p_texture_format, RD::TextureView p_view, bool p_unique) { |
| 325 | // TODO p_unique, if p_unique is true, this is a texture that can be shared. This will be implemented later as an optimization. |
| 326 | |
| 327 | NTKey key(p_context, p_texture_name); |
| 328 | |
| 329 | // check if this is a known texture |
| 330 | if (named_textures.has(key)) { |
| 331 | return named_textures[key].texture; |
| 332 | } |
| 333 | |
| 334 | // Add a new entry.. |
| 335 | NamedTexture &named_texture = named_textures[key]; |
| 336 | named_texture.format = p_texture_format; |
| 337 | named_texture.is_unique = p_unique; |
| 338 | named_texture.texture = RD::get_singleton()->texture_create(p_texture_format, p_view); |
| 339 | |
| 340 | Array arr = { p_context, p_texture_name }; |
| 341 | RD::get_singleton()->set_resource_name(named_texture.texture, String("RenderBuffer {0}/{1}").format(arr)); |
| 342 | |
| 343 | update_sizes(named_texture); |
| 344 | |
| 345 | // The rest is lazy created.. |
| 346 | |
| 347 | return named_texture.texture; |
| 348 | } |
| 349 | |
| 350 | RID RenderSceneBuffersRD::_create_texture_view(const StringName &p_context, const StringName &p_texture_name, const StringName &p_view_name, const Ref<RDTextureView> p_view) { |
| 351 | RD::TextureView texture_view; |
| 352 | if (p_view.is_valid()) { // only use when supplied, else default. |
| 353 | texture_view = p_view->base; |
| 354 | } |
| 355 | |
| 356 | return create_texture_view(p_context, p_texture_name, p_view_name, texture_view); |
| 357 | } |
| 358 | |
| 359 | RID RenderSceneBuffersRD::create_texture_view(const StringName &p_context, const StringName &p_texture_name, const StringName &p_view_name, RD::TextureView p_view) { |
| 360 | NTKey view_key(p_context, p_view_name); |
| 361 | |
| 362 | // check if this is a known texture |
| 363 | if (named_textures.has(view_key)) { |
| 364 | return named_textures[view_key].texture; |
| 365 | } |
| 366 | |
| 367 | NTKey key(p_context, p_texture_name); |
| 368 | |
| 369 | ERR_FAIL_COND_V(!named_textures.has(key), RID()); |
| 370 | |
| 371 | NamedTexture &named_texture = named_textures[key]; |
| 372 | NamedTexture &view_texture = named_textures[view_key]; |
| 373 | |
| 374 | view_texture.format = named_texture.format; |
| 375 | view_texture.is_unique = named_texture.is_unique; |
| 376 | |
| 377 | view_texture.texture = RD::get_singleton()->texture_create_shared(p_view, named_texture.texture); |
| 378 | |
| 379 | Array arr = { p_context, p_view_name }; |
| 380 | RD::get_singleton()->set_resource_name(view_texture.texture, String("RenderBuffer View {0}/{1}").format(arr)); |
| 381 | |
| 382 | update_sizes(named_texture); |
| 383 | |
| 384 | return view_texture.texture; |
| 385 | } |
| 386 | |
| 387 | RID RenderSceneBuffersRD::get_texture(const StringName &p_context, const StringName &p_texture_name) const { |
| 388 | NTKey key(p_context, p_texture_name); |
| 389 | |
| 390 | ERR_FAIL_COND_V(!named_textures.has(key), RID()); |
| 391 | |
| 392 | return named_textures[key].texture; |
| 393 | } |
| 394 | |
| 395 | Ref<RDTextureFormat> RenderSceneBuffersRD::_get_texture_format(const StringName &p_context, const StringName &p_texture_name) const { |
| 396 | Ref<RDTextureFormat> tf; |
| 397 | tf.instantiate(); |
| 398 | |
| 399 | tf->base = get_texture_format(p_context, p_texture_name); |
| 400 | |
| 401 | return tf; |
| 402 | } |
| 403 | |
| 404 | RID RenderSceneBuffersRD::_get_texture_slice_view(const StringName &p_context, const StringName &p_texture_name, const uint32_t p_layer, const uint32_t p_mipmap, const uint32_t p_layers, const uint32_t p_mipmaps, const Ref<RDTextureView> p_view) { |
| 405 | RD::TextureView texture_view; |
| 406 | if (p_view.is_valid()) { |
| 407 | texture_view = p_view->base; |
| 408 | } |
| 409 | |
| 410 | return get_texture_slice_view(p_context, p_texture_name, p_layer, p_mipmap, p_layers, p_mipmaps, texture_view); |
| 411 | } |
| 412 | |
| 413 | const RD::TextureFormat RenderSceneBuffersRD::get_texture_format(const StringName &p_context, const StringName &p_texture_name) const { |
| 414 | NTKey key(p_context, p_texture_name); |
| 415 | |
| 416 | ERR_FAIL_COND_V(!named_textures.has(key), RD::TextureFormat()); |
| 417 | |
| 418 | return named_textures[key].format; |
| 419 | } |
| 420 | |
| 421 | RID RenderSceneBuffersRD::get_texture_slice(const StringName &p_context, const StringName &p_texture_name, const uint32_t p_layer, const uint32_t p_mipmap, const uint32_t p_layers, const uint32_t p_mipmaps) { |
| 422 | return get_texture_slice_view(p_context, p_texture_name, p_layer, p_mipmap, p_layers, p_mipmaps, RD::TextureView()); |
| 423 | } |
| 424 | |
| 425 | RID RenderSceneBuffersRD::get_texture_slice_view(const StringName &p_context, const StringName &p_texture_name, const uint32_t p_layer, const uint32_t p_mipmap, const uint32_t p_layers, const uint32_t p_mipmaps, RD::TextureView p_view) { |
| 426 | NTKey key(p_context, p_texture_name); |
| 427 | |
| 428 | // check if this is a known texture |
| 429 | ERR_FAIL_COND_V(!named_textures.has(key), RID()); |
| 430 | NamedTexture &named_texture = named_textures[key]; |
| 431 | ERR_FAIL_COND_V(named_texture.texture.is_null(), RID()); |
| 432 | |
| 433 | // check if we're in bounds |
| 434 | ERR_FAIL_UNSIGNED_INDEX_V(p_layer, named_texture.format.array_layers, RID()); |
| 435 | ERR_FAIL_COND_V(p_layers == 0, RID()); |
| 436 | ERR_FAIL_COND_V(p_layer + p_layers > named_texture.format.array_layers, RID()); |
| 437 | ERR_FAIL_UNSIGNED_INDEX_V(p_mipmap, named_texture.format.mipmaps, RID()); |
| 438 | ERR_FAIL_COND_V(p_mipmaps == 0, RID()); |
| 439 | ERR_FAIL_COND_V(p_mipmap + p_mipmaps > named_texture.format.mipmaps, RID()); |
| 440 | |
| 441 | // asking the whole thing? just return the original |
| 442 | RD::TextureView default_view = RD::TextureView(); |
| 443 | if (p_layer == 0 && p_mipmap == 0 && named_texture.format.array_layers == p_layers && named_texture.format.mipmaps == p_mipmaps && p_view == default_view) { |
| 444 | return named_texture.texture; |
| 445 | } |
| 446 | |
| 447 | // see if we have this |
| 448 | NTSliceKey slice_key(p_layer, p_layers, p_mipmap, p_mipmaps, p_view); |
| 449 | if (named_texture.slices.has(slice_key)) { |
| 450 | return named_texture.slices[slice_key]; |
| 451 | } |
| 452 | |
| 453 | // create our slice |
| 454 | RID &slice = named_texture.slices[slice_key]; |
| 455 | slice = RD::get_singleton()->texture_create_shared_from_slice(p_view, named_texture.texture, p_layer, p_mipmap, p_mipmaps, p_layers > 1 ? RD::TEXTURE_SLICE_2D_ARRAY : RD::TEXTURE_SLICE_2D, p_layers); |
| 456 | |
| 457 | Array arr = { |
| 458 | p_context, |
| 459 | p_texture_name, |
| 460 | itos(p_layer), |
| 461 | itos(p_layers), |
| 462 | itos(p_mipmap), |
| 463 | itos(p_mipmaps), |
| 464 | itos(p_view.format_override), |
| 465 | itos(p_view.swizzle_r), |
| 466 | itos(p_view.swizzle_g), |
| 467 | itos(p_view.swizzle_b), |
| 468 | itos(p_view.swizzle_a) |
| 469 | }; |
| 470 | RD::get_singleton()->set_resource_name(slice, String("RenderBuffer {0}/{1}, layer {2}/{3}, mipmap {4}/{5}, view {6}/{7}/{8}/{9}/{10}").format(arr)); |
| 471 | |
| 472 | // and return our slice |
| 473 | return slice; |
| 474 | } |
| 475 | |
| 476 | Size2i RenderSceneBuffersRD::get_texture_slice_size(const StringName &p_context, const StringName &p_texture_name, const uint32_t p_mipmap) { |
| 477 | NTKey key(p_context, p_texture_name); |
| 478 | |
| 479 | // check if this is a known texture |
| 480 | ERR_FAIL_COND_V(!named_textures.has(key), Size2i()); |
| 481 | NamedTexture &named_texture = named_textures[key]; |
| 482 | ERR_FAIL_COND_V(named_texture.texture.is_null(), Size2i()); |
| 483 | |
| 484 | // check if we're in bounds |
| 485 | ERR_FAIL_UNSIGNED_INDEX_V(p_mipmap, named_texture.format.mipmaps, Size2i()); |
| 486 | |
| 487 | // return our size |
| 488 | return named_texture.sizes[p_mipmap]; |
| 489 | } |
| 490 | |
| 491 | void RenderSceneBuffersRD::clear_context(const StringName &p_context) { |
| 492 | Vector<NTKey> to_free; // free these |
| 493 | |
| 494 | // Find all entries for our context, we don't want to free them yet or our loop fails. |
| 495 | for (KeyValue<NTKey, NamedTexture> &E : named_textures) { |
| 496 | if (E.key.context == p_context) { |
| 497 | to_free.push_back(E.key); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | // Now free these and remove them from our textures |
| 502 | for (NTKey &key : to_free) { |
| 503 | free_named_texture(named_textures[key]); |
| 504 | named_textures.erase(key); |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | // Allocate shared buffers |
| 509 | void RenderSceneBuffersRD::allocate_blur_textures() { |
| 510 | if (has_texture(RB_SCOPE_BUFFERS, RB_TEX_BLUR_0)) { |
| 511 | // already allocated... |
| 512 | return; |
| 513 | } |
| 514 | |
| 515 | Size2i blur_size = internal_size; |
| 516 | if (RS::scaling_3d_mode_type(scaling_3d_mode) == RS::VIEWPORT_SCALING_3D_TYPE_TEMPORAL) { |
| 517 | // The blur texture should be as big as the target size when using an upscaler. |
| 518 | blur_size = target_size; |
| 519 | } |
| 520 | |
| 521 | uint32_t mipmaps_required = Image::get_image_required_mipmaps(blur_size.x, blur_size.y, Image::FORMAT_RGBAH); |
| 522 | |
| 523 | uint32_t usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_COPY_TO_BIT; |
| 524 | if (can_be_storage) { |
| 525 | usage_bits += RD::TEXTURE_USAGE_STORAGE_BIT; |
| 526 | } else { |
| 527 | usage_bits += RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT; |
| 528 | } |
| 529 | |
| 530 | create_texture(RB_SCOPE_BUFFERS, RB_TEX_BLUR_0, get_base_data_format(), usage_bits, RD::TEXTURE_SAMPLES_1, blur_size, view_count, mipmaps_required); |
| 531 | create_texture(RB_SCOPE_BUFFERS, RB_TEX_BLUR_1, get_base_data_format(), usage_bits, RD::TEXTURE_SAMPLES_1, Size2i(blur_size.x >> 1, blur_size.y >> 1), view_count, mipmaps_required - 1); |
| 532 | |
| 533 | // TODO redo this: |
| 534 | if (!can_be_storage) { |
| 535 | // create 4 weight textures, 2 full size, 2 half size |
| 536 | |
| 537 | RD::TextureFormat tf; |
| 538 | tf.format = RD::DATA_FORMAT_R16_SFLOAT; // We could probably use DATA_FORMAT_R8_SNORM if we don't pre-multiply by blur_size but that depends on whether we can remove DEPTH_GAP |
| 539 | tf.width = blur_size.x; |
| 540 | tf.height = blur_size.y; |
| 541 | tf.texture_type = RD::TEXTURE_TYPE_2D; |
| 542 | tf.array_layers = 1; // Our DOF effect handles one eye per turn |
| 543 | tf.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_COPY_TO_BIT | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT; |
| 544 | tf.mipmaps = 1; |
| 545 | for (uint32_t i = 0; i < 4; i++) { |
| 546 | // associated blur texture |
| 547 | RID texture; |
| 548 | if (i == 1) { |
| 549 | texture = get_texture_slice(RB_SCOPE_BUFFERS, RB_TEX_BLUR_0, 0, 0); |
| 550 | } else if (i == 2) { |
| 551 | texture = get_texture_slice(RB_SCOPE_BUFFERS, RB_TEX_BLUR_1, 0, 0); |
| 552 | } else if (i == 3) { |
| 553 | texture = get_texture_slice(RB_SCOPE_BUFFERS, RB_TEX_BLUR_0, 0, 1); |
| 554 | } |
| 555 | |
| 556 | // create weight texture |
| 557 | weight_buffers[i].weight = RD::get_singleton()->texture_create(tf, RD::TextureView()); |
| 558 | |
| 559 | // create frame buffer |
| 560 | Vector<RID> fb; |
| 561 | if (i != 0) { |
| 562 | fb.push_back(texture); |
| 563 | } |
| 564 | fb.push_back(weight_buffers[i].weight); |
| 565 | weight_buffers[i].fb = RD::get_singleton()->framebuffer_create(fb); |
| 566 | |
| 567 | if (i == 1) { |
| 568 | // next 2 are half size |
| 569 | tf.width = MAX(1u, tf.width >> 1); |
| 570 | tf.height = MAX(1u, tf.height >> 1); |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | // Data buffers |
| 577 | |
| 578 | bool RenderSceneBuffersRD::has_custom_data(const StringName &p_name) { |
| 579 | return data_buffers.has(p_name); |
| 580 | } |
| 581 | |
| 582 | void RenderSceneBuffersRD::set_custom_data(const StringName &p_name, Ref<RenderBufferCustomDataRD> p_data) { |
| 583 | if (p_data.is_valid()) { |
| 584 | data_buffers[p_name] = p_data; |
| 585 | } else if (has_custom_data(p_name)) { |
| 586 | data_buffers.erase(p_name); |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | Ref<RenderBufferCustomDataRD> RenderSceneBuffersRD::get_custom_data(const StringName &p_name) const { |
| 591 | ERR_FAIL_COND_V(!data_buffers.has(p_name), Ref<RenderBufferCustomDataRD>()); |
| 592 | |
| 593 | Ref<RenderBufferCustomDataRD> ret = data_buffers[p_name]; |
| 594 | |
| 595 | return ret; |
| 596 | } |
| 597 | |
| 598 | // Depth texture |
| 599 | |
| 600 | bool RenderSceneBuffersRD::has_depth_texture() { |
| 601 | if (render_target.is_null()) { |
| 602 | // not applicable when there is no render target (likely this is for a reflection probe) |
| 603 | return false; |
| 604 | } |
| 605 | |
| 606 | RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton(); |
| 607 | RID depth = texture_storage->render_target_get_override_depth(render_target); |
| 608 | if (depth.is_valid()) { |
| 609 | return true; |
| 610 | } else { |
| 611 | return has_texture(RB_SCOPE_BUFFERS, RB_TEX_DEPTH); |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | RID RenderSceneBuffersRD::get_depth_texture() { |
| 616 | if (render_target.is_null()) { |
| 617 | // not applicable when there is no render target (likely this is for a reflection probe) |
| 618 | return RID(); |
| 619 | } |
| 620 | |
| 621 | RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton(); |
| 622 | RID depth = texture_storage->render_target_get_override_depth(render_target); |
| 623 | if (depth.is_valid()) { |
| 624 | return depth; |
| 625 | } else { |
| 626 | return get_texture(RB_SCOPE_BUFFERS, RB_TEX_DEPTH); |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | RID RenderSceneBuffersRD::get_depth_texture(const uint32_t p_layer) { |
| 631 | RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton(); |
| 632 | RID depth_slice = texture_storage->render_target_get_override_depth_slice(render_target, p_layer); |
| 633 | if (depth_slice.is_valid()) { |
| 634 | return depth_slice; |
| 635 | } else { |
| 636 | return get_texture_slice(RB_SCOPE_BUFFERS, RB_TEX_DEPTH, p_layer, 0); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | // Upscaled texture. |
| 641 | |
| 642 | void RenderSceneBuffersRD::ensure_upscaled() { |
| 643 | if (!has_upscaled_texture()) { |
| 644 | uint32_t usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | (can_be_storage ? RD::TEXTURE_USAGE_STORAGE_BIT : 0) | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT; |
| 645 | usage_bits |= RD::TEXTURE_USAGE_INPUT_ATTACHMENT_BIT; |
| 646 | create_texture(RB_SCOPE_BUFFERS, RB_TEX_COLOR_UPSCALED, get_base_data_format(), usage_bits, RD::TEXTURE_SAMPLES_1, target_size); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | // Velocity texture. |
| 651 | |
| 652 | void RenderSceneBuffersRD::ensure_velocity() { |
| 653 | if (!has_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY)) { |
| 654 | const bool msaa = msaa_3d != RS::VIEWPORT_MSAA_DISABLED; |
| 655 | create_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY, get_velocity_format(), get_velocity_usage_bits(msaa, false, can_be_storage)); |
| 656 | |
| 657 | if (msaa) { |
| 658 | create_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY_MSAA, get_velocity_format(), get_velocity_usage_bits(false, msaa, can_be_storage), texture_samples); |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | bool RenderSceneBuffersRD::has_velocity_buffer(bool p_has_msaa) { |
| 664 | if (p_has_msaa) { |
| 665 | return has_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY_MSAA); |
| 666 | } else { |
| 667 | RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton(); |
| 668 | RID velocity = texture_storage->render_target_get_override_velocity(render_target); |
| 669 | if (velocity.is_valid()) { |
| 670 | return true; |
| 671 | } else { |
| 672 | return has_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY); |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | RID RenderSceneBuffersRD::get_velocity_buffer(bool p_get_msaa) { |
| 678 | if (p_get_msaa) { |
| 679 | if (!has_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY_MSAA)) { |
| 680 | return RID(); |
| 681 | } else { |
| 682 | return get_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY_MSAA); |
| 683 | } |
| 684 | } else { |
| 685 | RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton(); |
| 686 | RID velocity = texture_storage->render_target_get_override_velocity(render_target); |
| 687 | if (velocity.is_valid()) { |
| 688 | return velocity; |
| 689 | } else if (!has_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY)) { |
| 690 | return RID(); |
| 691 | } else { |
| 692 | return get_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY); |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | RID RenderSceneBuffersRD::get_velocity_buffer(bool p_get_msaa, uint32_t p_layer) { |
| 698 | if (p_get_msaa) { |
| 699 | return get_texture_slice(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY_MSAA, p_layer, 0); |
| 700 | } else { |
| 701 | RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton(); |
| 702 | RID velocity_slice = texture_storage->render_target_get_override_velocity_slice(render_target, p_layer); |
| 703 | if (velocity_slice.is_valid()) { |
| 704 | return velocity_slice; |
| 705 | } else { |
| 706 | return get_texture_slice(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY, p_layer, 0); |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | RID RenderSceneBuffersRD::get_velocity_depth_buffer() { |
| 712 | RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton(); |
| 713 | RID velocity_depth = texture_storage->render_target_get_override_velocity_depth(render_target); |
| 714 | return velocity_depth; |
| 715 | } |
| 716 | |
| 717 | uint32_t RenderSceneBuffersRD::get_color_usage_bits(bool p_resolve, bool p_msaa, bool p_storage) { |
| 718 | DEV_ASSERT((!p_resolve && !p_msaa) || (p_resolve != p_msaa)); |
| 719 | |
| 720 | uint32_t usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_INPUT_ATTACHMENT_BIT; |
| 721 | if (p_msaa) { |
| 722 | usage_bits |= RD::TEXTURE_USAGE_CAN_COPY_FROM_BIT; |
| 723 | } else if (p_resolve) { |
| 724 | usage_bits |= RD::TEXTURE_USAGE_CAN_COPY_TO_BIT | (p_storage ? RD::TEXTURE_USAGE_STORAGE_BIT : 0); |
| 725 | } else { |
| 726 | usage_bits |= (p_storage ? RD::TEXTURE_USAGE_STORAGE_BIT : 0); |
| 727 | } |
| 728 | |
| 729 | return usage_bits; |
| 730 | } |
| 731 | |
| 732 | RD::DataFormat RenderSceneBuffersRD::get_depth_format(bool p_resolve, bool p_msaa, bool p_storage) { |
| 733 | if (p_resolve && (p_storage || !RenderingDevice::get_singleton()->has_feature(RD::SUPPORTS_FRAMEBUFFER_DEPTH_RESOLVE))) { |
| 734 | // Use R32 for resolve on Forward+ (p_storage == true), or if we don't support depth resolve. |
| 735 | return RD::DATA_FORMAT_R32_SFLOAT; |
| 736 | } else { |
| 737 | const RenderingDeviceCommons::DataFormat preferred_formats[2] = { |
| 738 | p_storage ? RD::DATA_FORMAT_D32_SFLOAT_S8_UINT : RD::DATA_FORMAT_D24_UNORM_S8_UINT, |
| 739 | p_storage ? RD::DATA_FORMAT_D24_UNORM_S8_UINT : RD::DATA_FORMAT_D32_SFLOAT_S8_UINT |
| 740 | }; |
| 741 | |
| 742 | return RD::get_singleton()->texture_is_format_supported_for_usage(preferred_formats[0], get_depth_usage_bits(p_resolve, p_msaa, p_storage)) ? preferred_formats[0] : preferred_formats[1]; |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | uint32_t RenderSceneBuffersRD::get_depth_usage_bits(bool p_resolve, bool p_msaa, bool p_storage) { |
| 747 | DEV_ASSERT((!p_resolve && !p_msaa) || (p_resolve != p_msaa)); |
| 748 | |
| 749 | uint32_t usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT; |
| 750 | if (p_msaa) { |
| 751 | usage_bits |= RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | RD::TEXTURE_USAGE_CAN_COPY_FROM_BIT; |
| 752 | } else if (p_resolve) { |
| 753 | usage_bits |= RD::TEXTURE_USAGE_CAN_COPY_TO_BIT; |
| 754 | if (p_storage) { |
| 755 | usage_bits |= RD::TEXTURE_USAGE_STORAGE_BIT; |
| 756 | } else if (RenderingDevice::get_singleton()->has_feature(RD::SUPPORTS_FRAMEBUFFER_DEPTH_RESOLVE)) { |
| 757 | // We're able to resolve depth in (sub)passes and we make use of this in our mobile renderer. |
| 758 | usage_bits |= RD::TEXTURE_USAGE_DEPTH_RESOLVE_ATTACHMENT_BIT; |
| 759 | } |
| 760 | } else { |
| 761 | usage_bits |= RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 762 | } |
| 763 | |
| 764 | return usage_bits; |
| 765 | } |
| 766 | |
| 767 | RD::DataFormat RenderSceneBuffersRD::get_velocity_format() { |
| 768 | return RD::DATA_FORMAT_R16G16_SFLOAT; |
| 769 | } |
| 770 | |
| 771 | uint32_t RenderSceneBuffersRD::get_velocity_usage_bits(bool p_resolve, bool p_msaa, bool p_storage) { |
| 772 | return get_color_usage_bits(p_resolve, p_msaa, p_storage); |
| 773 | } |
| 774 | |
| 775 | RD::DataFormat RenderSceneBuffersRD::get_vrs_format() { |
| 776 | return RD::get_singleton()->vrs_get_format(); |
| 777 | } |
| 778 | |
| 779 | uint32_t RenderSceneBuffersRD::get_vrs_usage_bits() { |
| 780 | return RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_STORAGE_BIT | RD::TEXTURE_USAGE_VRS_ATTACHMENT_BIT; |
| 781 | } |
| 782 | |
| 783 | float RenderSceneBuffersRD::get_luminance_multiplier() const { |
| 784 | // On mobile renderer when not using HDR2D we need to scale HDR values by two |
| 785 | // to fit 0-2 range color values into a UNORM buffer. |
| 786 | return (force_hdr || can_be_storage) ? 1.0 : 2.0; |
| 787 | } |