Skip to content

Commit

Permalink
Resolve load and store ops automatically for render passes for transi…
Browse files Browse the repository at this point in the history
…ent textures.
  • Loading branch information
DarioSamo committed Oct 30, 2024
1 parent 8004c75 commit f8bcde9
Show file tree
Hide file tree
Showing 32 changed files with 687 additions and 469 deletions.
7 changes: 7 additions & 0 deletions doc/classes/RDTextureFormat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
<member name="height" type="int" setter="set_height" getter="get_height" default="1">
The texture's height (in pixels).
</member>
<member name="is_resolve_buffer" type="bool" setter="set_is_resolve_buffer" getter="get_is_resolve_buffer" default="false">
The texture will be used as the destination of a resolve operation.
</member>
<member name="is_transient" type="bool" setter="set_is_transient" getter="get_is_transient" default="false">
If a texture is transient, its contents do not need to be preserved between frames. This flag is only relevant when the texture is used as target in a draw list.
This information is used by [RenderingDevice] to figure out if a texture's contents can be discarded and eliminate unnecessary writes to memory and boosting performance.
</member>
<member name="mipmaps" type="int" setter="set_mipmaps" getter="get_mipmaps" default="1">
The number of mipmaps available in the texture.
</member>
Expand Down
1 change: 1 addition & 0 deletions doc/classes/RenderSceneBuffersRD.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<param index="6" name="layers" type="int" />
<param index="7" name="mipmaps" type="int" />
<param index="8" name="unique" type="bool" />
<param index="9" name="transient" type="bool" />
<description>
Create a new texture with the given definition and cache this under the given name. Will return the existing texture if it already exists.
</description>
Expand Down
99 changes: 74 additions & 25 deletions doc/classes/RenderingDevice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,22 @@
<method name="draw_list_begin">
<return type="int" />
<param index="0" name="framebuffer" type="RID" />
<param index="1" name="initial_color_action" type="int" enum="RenderingDevice.InitialAction" />
<param index="2" name="final_color_action" type="int" enum="RenderingDevice.FinalAction" />
<param index="3" name="initial_depth_action" type="int" enum="RenderingDevice.InitialAction" />
<param index="4" name="final_depth_action" type="int" enum="RenderingDevice.FinalAction" />
<param index="5" name="clear_color_values" type="PackedColorArray" default="PackedColorArray()" />
<param index="6" name="clear_depth" type="float" default="1.0" />
<param index="7" name="clear_stencil" type="int" default="0" />
<param index="8" name="region" type="Rect2" default="Rect2(0, 0, 0, 0)" />
<param index="9" name="breadcrumb" type="int" default="0" />
<param index="1" name="clear_colors" type="int" enum="RenderingDevice.ClearColorFlags" is_bitfield="true" default="0" />
<param index="2" name="clear_color_values" type="PackedColorArray" default="PackedColorArray()" />
<param index="3" name="clear_depth" type="bool" default="false" />
<param index="4" name="clear_depth_value" type="float" default="1.0" />
<param index="5" name="clear_stencil" type="bool" default="false" />
<param index="6" name="clear_stencil_value" type="int" default="0" />
<param index="7" name="region" type="Rect2" default="Rect2(0, 0, 0, 0)" />
<param index="8" name="breadcrumb" type="int" default="0" />
<description>
Starts a list of raster drawing commands created with the [code]draw_*[/code] methods. The returned value should be passed to other [code]draw_list_*[/code] functions.
Multiple draw lists cannot be created at the same time; you must finish the previous draw list first using [method draw_list_end].
A simple drawing operation might look like this (code is not a complete example):
[codeblock]
var rd = RenderingDevice.new()
var clear_colors = PackedColorArray([Color(0, 0, 0, 0), Color(0, 0, 0, 0), Color(0, 0, 0, 0)])
var draw_list = rd.draw_list_begin(framebuffers[i], RenderingDevice.INITIAL_ACTION_CLEAR, RenderingDevice.FINAL_ACTION_READ, RenderingDevice.INITIAL_ACTION_CLEAR, RenderingDevice.FINAL_ACTION_DISCARD, clear_colors, RenderingDevice.OPAQUE_PASS)
var draw_list = rd.draw_list_begin(framebuffers[i], RenderingDevice.CLEAR_COLOR_ALL, clear_colors, true, 1.0f, true, 0, Rect2(), RenderingDevice.OPAQUE_PASS)

# Draw opaque.
rd.draw_list_bind_render_pipeline(draw_list, raster_pipeline)
Expand All @@ -244,7 +243,7 @@
The [param breadcrumb] parameter can be an arbitrary 32-bit integer that is useful to diagnose GPU crashes. If Godot is built in dev or debug mode; when the GPU crashes Godot will dump all shaders that were being executed at the time of the crash and the breadcrumb is useful to diagnose what passes did those shaders belong to.
It does not affect rendering behavior and can be set to 0. It is recommended to use [enum BreadcrumbMarker] enumerations for consistency but it's not required. It is also possible to use bitwise operations to add extra data. e.g.
[codeblock]
rd.draw_list_begin(fb[i], RenderingDevice.INITIAL_ACTION_CLEAR, RenderingDevice.FINAL_ACTION_READ, RenderingDevice.INITIAL_ACTION_CLEAR, RenderingDevice.FINAL_ACTION_DISCARD, clear_colors, RenderingDevice.OPAQUE_PASS | 5)
rd.draw_list_begin(fb[i], RenderingDevice.CLEAR_COLOR_ALL, clear_colors, true, 1.0f, true, 0, Rect2(), RenderingDevice.OPAQUE_PASS | 5)
[/codeblock]
</description>
</method>
Expand Down Expand Up @@ -962,6 +961,13 @@
Returns [code]true[/code] if the [param texture] is shared, [code]false[/code] otherwise. See [RDTextureView].
</description>
</method>
<method name="texture_is_transient">
<return type="bool" />
<param index="0" name="texture" type="RID" />
<description>
Returns [code]true[/code] if the [param texture] is transient, [code]false[/code] otherwise. See [RDTextureFormat] or [method texture_set_transient].
</description>
</method>
<method name="texture_is_valid">
<return type="bool" />
<param index="0" name="texture" type="RID" />
Expand All @@ -984,6 +990,16 @@
[b]Note:[/b] [param to_texture] texture must [b]not[/b] be multisampled and must also be 2D (or a slice of a 3D/cubemap texture).
</description>
</method>
<method name="texture_set_transient">
<return type="void" />
<param index="0" name="texture" type="RID" />
<param index="1" name="transient" type="bool" />
<description>
Updates the transient property of [param texture].
If a texture is transient, its contents do not need to be preserved between frames. This flag is only relevant when the texture is used as target in a draw list.
This information is used by [RenderingDevice] to figure out if a texture's contents can be discarded and eliminate unnecessary writes to memory and boosting performance.
</description>
</method>
<method name="texture_update">
<return type="int" enum="Error" />
<param index="0" name="texture" type="RID" />
Expand Down Expand Up @@ -2279,40 +2295,40 @@
</constant>
<constant name="DYNAMIC_STATE_STENCIL_REFERENCE" value="64" enum="PipelineDynamicStateFlags" is_bitfield="true">
</constant>
<constant name="INITIAL_ACTION_LOAD" value="0" enum="InitialAction">
<constant name="INITIAL_ACTION_LOAD" value="0" enum="InitialAction" deprecated="Initial actions are solved automatically by RenderingDevice.">
Load the previous contents of the framebuffer.
</constant>
<constant name="INITIAL_ACTION_CLEAR" value="1" enum="InitialAction">
<constant name="INITIAL_ACTION_CLEAR" value="1" enum="InitialAction" deprecated="Initial actions are solved automatically by RenderingDevice.">
Clear the whole framebuffer or its specified region.
</constant>
<constant name="INITIAL_ACTION_DISCARD" value="2" enum="InitialAction">
<constant name="INITIAL_ACTION_DISCARD" value="2" enum="InitialAction" deprecated="Initial actions are solved automatically by RenderingDevice.">
Ignore the previous contents of the framebuffer. This is the fastest option if you'll overwrite all of the pixels and don't need to read any of them.
</constant>
<constant name="INITIAL_ACTION_MAX" value="3" enum="InitialAction">
<constant name="INITIAL_ACTION_MAX" value="3" enum="InitialAction" deprecated="Initial actions are solved automatically by RenderingDevice.">
Represents the size of the [enum InitialAction] enum.
</constant>
<constant name="INITIAL_ACTION_CLEAR_REGION" value="1" enum="InitialAction" deprecated="Use [constant INITIAL_ACTION_CLEAR] instead.">
<constant name="INITIAL_ACTION_CLEAR_REGION" value="1" enum="InitialAction" deprecated="Initial actions are solved automatically by RenderingDevice.">
</constant>
<constant name="INITIAL_ACTION_CLEAR_REGION_CONTINUE" value="1" enum="InitialAction" deprecated="Use [constant INITIAL_ACTION_LOAD] instead.">
<constant name="INITIAL_ACTION_CLEAR_REGION_CONTINUE" value="1" enum="InitialAction" deprecated="Initial actions are solved automatically by RenderingDevice.">
</constant>
<constant name="INITIAL_ACTION_KEEP" value="0" enum="InitialAction" deprecated="Use [constant INITIAL_ACTION_LOAD] instead.">
<constant name="INITIAL_ACTION_KEEP" value="0" enum="InitialAction" deprecated="Initial actions are solved automatically by RenderingDevice.">
</constant>
<constant name="INITIAL_ACTION_DROP" value="2" enum="InitialAction" deprecated="Use [constant INITIAL_ACTION_DISCARD] instead.">
<constant name="INITIAL_ACTION_DROP" value="2" enum="InitialAction" deprecated="Initial actions are solved automatically by RenderingDevice.">
</constant>
<constant name="INITIAL_ACTION_CONTINUE" value="0" enum="InitialAction" deprecated="Use [constant INITIAL_ACTION_LOAD] instead.">
<constant name="INITIAL_ACTION_CONTINUE" value="0" enum="InitialAction" deprecated="Initial actions are solved automatically by RenderingDevice.">
</constant>
<constant name="FINAL_ACTION_STORE" value="0" enum="FinalAction">
<constant name="FINAL_ACTION_STORE" value="0" enum="FinalAction" deprecated="Final actions are solved automatically by RenderingDevice.">
Store the result of the draw list in the framebuffer. This is generally what you want to do.
</constant>
<constant name="FINAL_ACTION_DISCARD" value="1" enum="FinalAction">
<constant name="FINAL_ACTION_DISCARD" value="1" enum="FinalAction" deprecated="Final actions are solved automatically by RenderingDevice.">
Discard the contents of the framebuffer. This is the fastest option if you don't need to use the results of the draw list.
</constant>
<constant name="FINAL_ACTION_MAX" value="2" enum="FinalAction">
<constant name="FINAL_ACTION_MAX" value="2" enum="FinalAction" deprecated="Final actions are solved automatically by RenderingDevice.">
Represents the size of the [enum FinalAction] enum.
</constant>
<constant name="FINAL_ACTION_READ" value="0" enum="FinalAction" deprecated="Use [constant FINAL_ACTION_STORE] instead.">
<constant name="FINAL_ACTION_READ" value="0" enum="FinalAction" deprecated="Final actions are solved automatically by RenderingDevice.">
</constant>
<constant name="FINAL_ACTION_CONTINUE" value="0" enum="FinalAction" deprecated="Use [constant FINAL_ACTION_STORE] instead.">
<constant name="FINAL_ACTION_CONTINUE" value="0" enum="FinalAction" deprecated="Final actions are solved automatically by RenderingDevice.">
</constant>
<constant name="SHADER_STAGE_VERTEX" value="0" enum="ShaderStage">
Vertex shader stage. This can be used to manipulate vertices from a shader (but not create new vertices).
Expand Down Expand Up @@ -2514,5 +2530,38 @@
</constant>
<constant name="DEBUG_PASS" value="786432" enum="BreadcrumbMarker">
</constant>
<constant name="CLEAR_COLOR_NONE" value="0" enum="ClearColorFlags" is_bitfield="true">
Do not clear any color attachments.
</constant>
<constant name="CLEAR_COLOR_0" value="1" enum="ClearColorFlags" is_bitfield="true">
Clear the first color attachment.
</constant>
<constant name="CLEAR_COLOR_1" value="2" enum="ClearColorFlags" is_bitfield="true">
Clear the second color attachment.
</constant>
<constant name="CLEAR_COLOR_2" value="4" enum="ClearColorFlags" is_bitfield="true">
Clear the third color attachment.
</constant>
<constant name="CLEAR_COLOR_3" value="8" enum="ClearColorFlags" is_bitfield="true">
Clear the fourth color attachment.
</constant>
<constant name="CLEAR_COLOR_4" value="16" enum="ClearColorFlags" is_bitfield="true">
Clear the fifth color attachment.
</constant>
<constant name="CLEAR_COLOR_5" value="32" enum="ClearColorFlags" is_bitfield="true">
Clear the sixth color attachment.
</constant>
<constant name="CLEAR_COLOR_6" value="64" enum="ClearColorFlags" is_bitfield="true">
Clear the seventh color attachment.
</constant>
<constant name="CLEAR_COLOR_7" value="128" enum="ClearColorFlags" is_bitfield="true">
Clear the eighth color attachment.
</constant>
<constant name="CLEAR_COLOR_MASK" value="255" enum="ClearColorFlags" is_bitfield="true">
Mask for all color attachments.
</constant>
<constant name="CLEAR_COLOR_ALL" value="255" enum="ClearColorFlags" is_bitfield="true">
Clear all color attachments.
</constant>
</constants>
</class>
22 changes: 22 additions & 0 deletions misc/extension_api_validation/4.3-stable.expected
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,25 @@ GH-97020
Validate extension JSON: Error: Field 'classes/AnimationNode/methods/_process': is_const changed value in new API, from true to false.

`_process` virtual method fixed to be non const instead.


GH-98670
--------
Validate extension JSON: Error: Field 'classes/RenderSceneBuffersRD/methods/create_texture/arguments': size changed value in new API, from 9 to 10.
Validate extension JSON: Error: Field 'classes/RenderingDevice/methods/draw_list_begin/arguments': meta was removed.
Validate extension JSON: Error: Field 'classes/RenderingDevice/methods/draw_list_begin/arguments/1': type changed value in new API, from "enum::RenderingDevice.InitialAction" to "bitfield::RenderingDevice.ClearColorFlags".
Validate extension JSON: Error: Field 'classes/RenderingDevice/methods/draw_list_begin/arguments/2': type changed value in new API, from "enum::RenderingDevice.FinalAction" to "PackedColorArray".
Validate extension JSON: Error: Field 'classes/RenderingDevice/methods/draw_list_begin/arguments/3': type changed value in new API, from "enum::RenderingDevice.InitialAction" to "bool".
Validate extension JSON: Error: Field 'classes/RenderingDevice/methods/draw_list_begin/arguments/4': type changed value in new API, from "enum::RenderingDevice.FinalAction" to "float".
Validate extension JSON: Error: Field 'classes/RenderingDevice/methods/draw_list_begin/arguments/5': default_value changed value in new API, from "PackedColorArray()" to "false".
Validate extension JSON: Error: Field 'classes/RenderingDevice/methods/draw_list_begin/arguments/5': type changed value in new API, from "PackedColorArray" to "bool".
Validate extension JSON: Error: Field 'classes/RenderingDevice/methods/draw_list_begin/arguments/6': default_value changed value in new API, from "1.0" to "0".
Validate extension JSON: Error: Field 'classes/RenderingDevice/methods/draw_list_begin/arguments/6': meta changed value in new API, from "float" to "uint32".
Validate extension JSON: Error: Field 'classes/RenderingDevice/methods/draw_list_begin/arguments/6': type changed value in new API, from "float" to "int".
Validate extension JSON: Error: Field 'classes/RenderingDevice/methods/draw_list_begin/arguments/7': default_value changed value in new API, from "0" to "Rect2(0, 0, 0, 0)".
Validate extension JSON: Error: Field 'classes/RenderingDevice/methods/draw_list_begin/arguments/7': type changed value in new API, from "int" to "Rect2".
Validate extension JSON: Error: Field 'classes/RenderingDevice/methods/draw_list_begin/arguments/8': default_value changed value in new API, from "Rect2(0, 0, 0, 0)" to "0".
Validate extension JSON: Error: Field 'classes/RenderingDevice/methods/draw_list_begin/arguments/8': type changed value in new API, from "Rect2" to "int".

Draw lists no longer require the initial and final action for color and depth attachments to be specified.
Draw lists can now specify if a particular color, depth or stencil attachment should be cleared.
7 changes: 3 additions & 4 deletions modules/lightmapper_rd/lightmapper_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ void LightmapperRD::_raster_geometry(RenderingDevice *rd, Size2i atlas_size, int
raster_push_constant.uv_offset[0] = -0.5f / float(atlas_size.x);
raster_push_constant.uv_offset[1] = -0.5f / float(atlas_size.y);

RD::DrawListID draw_list = rd->draw_list_begin(framebuffers[i], RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_DISCARD, clear_colors, 1.0, 0, Rect2(), RDD::BreadcrumbMarker::LIGHTMAPPER_PASS);
RD::DrawListID draw_list = rd->draw_list_begin(framebuffers[i], RD::CLEAR_COLOR_ALL, clear_colors, true, 1.0f, false, 0, Rect2(), RDD::BreadcrumbMarker::LIGHTMAPPER_PASS);
//draw opaque
rd->draw_list_bind_render_pipeline(draw_list, raster_pipeline);
rd->draw_list_bind_uniform_set(draw_list, raster_base_uniform, 0);
Expand Down Expand Up @@ -1405,6 +1405,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
tf.texture_type = RD::TEXTURE_TYPE_2D;
tf.usage_bits = RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
tf.format = RD::DATA_FORMAT_D32_SFLOAT;
tf.is_transient = true;

raster_depth_buffer = rd->texture_create(tf, RD::TextureView());
}
Expand Down Expand Up @@ -1956,8 +1957,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
uint32_t seam_offset = 0;
uint32_t triangle_offset = 0;

Vector<Color> clear_colors;
clear_colors.push_back(Color(0, 0, 0, 1));
for (int i = 0; i < atlas_slices; i++) {
int subslices = (p_bake_sh ? 4 : 1);

Expand All @@ -1971,7 +1970,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
seams_push_constant.debug = debug;

// Store the current subslice in the breadcrumb.
RD::DrawListID draw_list = rd->draw_list_begin(framebuffers[i * subslices + k], RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_DISCARD, clear_colors, 1.0, 0, Rect2(), RDD::BreadcrumbMarker::LIGHTMAPPER_PASS | seams_push_constant.slice);
RD::DrawListID draw_list = rd->draw_list_begin(framebuffers[i * subslices + k], RD::CLEAR_COLOR_NONE, Vector<Color>(), true, 1.0f, false, 0, Rect2(), RDD::BreadcrumbMarker::LIGHTMAPPER_PASS | seams_push_constant.slice);

rd->draw_list_bind_uniform_set(draw_list, raster_base_uniform, 0);
rd->draw_list_bind_uniform_set(draw_list, blendseams_raster_uniform, 1);
Expand Down
2 changes: 1 addition & 1 deletion servers/rendering/renderer_rd/cluster_builder_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ void ClusterBuilderRD::bake_cluster() {

// Render elements.
{
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(framebuffer, RD::INITIAL_ACTION_DISCARD, RD::FINAL_ACTION_DISCARD, RD::INITIAL_ACTION_DISCARD, RD::FINAL_ACTION_DISCARD);
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(framebuffer);
ClusterBuilderSharedDataRD::ClusterRender::PushConstant push_constant = {};

RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, shared->cluster_render.shader_pipelines[use_msaa ? ClusterBuilderSharedDataRD::ClusterRender::PIPELINE_MSAA : ClusterBuilderSharedDataRD::ClusterRender::PIPELINE_NORMAL]);
Expand Down
Loading

0 comments on commit f8bcde9

Please sign in to comment.