Skip to content

Commit bb9197a

Browse files
committed
Mark more textures as discardable
This allows the ARG to better optimize their usage for mobile devices. In particular, this allows the ARG to avoid loading the contents of the texture into tile memory when rendering into the texture if the contents won't be used anyway.
1 parent 2cadc4e commit bb9197a

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

servers/rendering/renderer_rd/effects/vrs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void VRS::copy_vrs(RID p_source_rd_texture, RID p_dest_framebuffer, bool p_multi
9898
RID shader = vrs_shader.shader.version_get_shader(vrs_shader.shader_version, mode);
9999
ERR_FAIL_COND(shader.is_null());
100100

101-
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer);
101+
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::DRAW_IGNORE_ALL);
102102
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, vrs_shader.pipelines[mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
103103
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
104104
RD::get_singleton()->draw_list_set_push_constant(draw_list, &push_constant, sizeof(VRSPushConstant));

servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,13 @@ void RenderSceneBuffersRD::configure(const RenderSceneBuffersConfiguration *p_co
179179

180180
// Create our color buffer.
181181
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));
182+
create_texture(RB_SCOPE_BUFFERS, RB_TEX_COLOR, get_base_data_format(), get_color_usage_bits(resolve_target, false, can_be_storage), RD::TEXTURE_SAMPLES_1, Size2i(), 0, 1, true, true);
183183

184184
// 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.
185185
// (it means we cannot sample from it, we cannot copy from/to it) to save VRAM (and maybe performance too).
186186

187187
// 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));
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), RD::TEXTURE_SAMPLES_1, Size2i(), 0, 1, true, true);
189189

190190
// Create our MSAA buffers.
191191
if (msaa_3d == RS::VIEWPORT_MSAA_DISABLED) {
@@ -199,7 +199,7 @@ void RenderSceneBuffersRD::configure(const RenderSceneBuffersConfiguration *p_co
199199
// VRS (note, our vrs object will only be set if VRS is supported)
200200
RID vrs_texture;
201201
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));
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), 0, 1, true, true);
203203
}
204204

205205
// (re-)configure any named buffers
@@ -527,8 +527,8 @@ void RenderSceneBuffersRD::allocate_blur_textures() {
527527
usage_bits += RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
528528
}
529529

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);
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, true, true);
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, true, true);
532532

533533
// TODO redo this:
534534
if (!can_be_storage) {
@@ -643,7 +643,7 @@ void RenderSceneBuffersRD::ensure_upscaled() {
643643
if (!has_upscaled_texture()) {
644644
uint32_t usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | (can_be_storage ? RD::TEXTURE_USAGE_STORAGE_BIT : 0) | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
645645
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);
646+
create_texture(RB_SCOPE_BUFFERS, RB_TEX_COLOR_UPSCALED, get_base_data_format(), usage_bits, RD::TEXTURE_SAMPLES_1, target_size, 0, 1, true, true);
647647
}
648648
}
649649

@@ -652,10 +652,10 @@ void RenderSceneBuffersRD::ensure_upscaled() {
652652
void RenderSceneBuffersRD::ensure_velocity() {
653653
if (!has_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY)) {
654654
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));
655+
create_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY, get_velocity_format(), get_velocity_usage_bits(msaa, false, can_be_storage), RD::TEXTURE_SAMPLES_1, Size2i(), 0, 1, true, true);
656656

657657
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);
658+
create_texture(RB_SCOPE_BUFFERS, RB_TEX_VELOCITY_MSAA, get_velocity_format(), get_velocity_usage_bits(false, msaa, can_be_storage), texture_samples, Size2i(), 0, 1, true, true);
659659
}
660660
}
661661
}

servers/rendering/renderer_rd/storage_rd/texture_storage.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3591,6 +3591,7 @@ void TextureStorage::_update_render_target(RenderTarget *rt) {
35913591
if (rt->msaa != RS::VIEWPORT_MSAA_DISABLED) {
35923592
rd_color_attachment_format.is_resolve_buffer = true;
35933593
}
3594+
rd_color_attachment_format.is_discardable = true;
35943595
}
35953596

35963597
// TODO see if we can lazy create this once we actually use it as we may not need to create this if we have an overridden color buffer...
@@ -3610,6 +3611,7 @@ void TextureStorage::_update_render_target(RenderTarget *rt) {
36103611
rd_color_multisample_format.usage_bits = render_target_get_color_usage_bits(true);
36113612
RD::TextureView rd_view_multisample;
36123613
rd_color_multisample_format.is_resolve_buffer = false;
3614+
rd_color_multisample_format.is_discardable = true;
36133615
rt->color_multisample = RD::get_singleton()->texture_create(rd_color_multisample_format, rd_view_multisample);
36143616
ERR_FAIL_COND(rt->color_multisample.is_null());
36153617
}
@@ -3670,6 +3672,7 @@ void TextureStorage::_create_render_target_backbuffer(RenderTarget *rt) {
36703672
tf.texture_type = RD::TEXTURE_TYPE_2D;
36713673
tf.usage_bits = RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_STORAGE_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_COPY_TO_BIT;
36723674
tf.mipmaps = mipmaps_required;
3675+
tf.is_discardable = true;
36733676

36743677
rt->backbuffer = RD::get_singleton()->texture_create(tf, RD::TextureView());
36753678
RD::get_singleton()->set_resource_name(rt->backbuffer, "Render Target Back Buffer");
@@ -4155,6 +4158,7 @@ void TextureStorage::_render_target_allocate_sdf(RenderTarget *rt) {
41554158
tformat.height = size.height;
41564159
tformat.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_STORAGE_BIT | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
41574160
tformat.texture_type = RD::TEXTURE_TYPE_2D;
4161+
tformat.is_discardable = true;
41584162

41594163
rt->sdf_buffer_write = RD::get_singleton()->texture_create(tformat, RD::TextureView());
41604164

0 commit comments

Comments
 (0)