Skip to content

Commit

Permalink
Add FidelityFX Super Resolution 2.2 (FSR 2.2.1) support.
Browse files Browse the repository at this point in the history
Introduces support for FSR2 as a new upscaler option available from the project settings. Also introduces an specific render list for surfaces that require motion and the ability to derive motion vectors from depth buffer and camera motion.
  • Loading branch information
DarioSamo committed Sep 25, 2023
1 parent df0a822 commit 057367b
Show file tree
Hide file tree
Showing 102 changed files with 22,107 additions and 148 deletions.
5 changes: 5 additions & 0 deletions COPYRIGHT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ Comment: AMD FidelityFX Super Resolution
Copyright: 2021, Advanced Micro Devices, Inc.
License: Expat

Files: ./thirdparty/amd-fsr2/
Comment: AMD FidelityFX Super Resolution 2
Copyright: 2022-2023, Advanced Micro Devices, Inc.
License: Expat

Files: ./thirdparty/angle/
Comment: ANGLE
Copyright: 2018, The ANGLE Project Authors.
Expand Down
13 changes: 13 additions & 0 deletions doc/classes/RenderSceneBuffersRD.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@
Returns the texture size of a given slice of a cached texture.
</description>
</method>
<method name="get_texture_slice_view">
<return type="RID" />
<param index="0" name="context" type="StringName" />
<param index="1" name="name" type="StringName" />
<param index="2" name="layer" type="int" />
<param index="3" name="mipmap" type="int" />
<param index="4" name="layers" type="int" />
<param index="5" name="mipmaps" type="int" />
<param index="6" name="view" type="RDTextureView" />
<description>
Returns a specific view of a slice (layer or mipmap) for a cached texture.
</description>
</method>
<method name="get_use_taa" qualifiers="const">
<return type="bool" />
<description>
Expand Down
8 changes: 7 additions & 1 deletion doc/classes/RenderingServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4507,7 +4507,10 @@
<constant name="VIEWPORT_SCALING_3D_MODE_FSR" value="1" enum="ViewportScaling3DMode">
Use AMD FidelityFX Super Resolution 1.0 upscaling for the viewport's 3D buffer. The amount of scaling can be set using [member Viewport.scaling_3d_scale]. Values less than [code]1.0[/code] will be result in the viewport being upscaled using FSR. Values greater than [code]1.0[/code] are not supported and bilinear downsampling will be used instead. A value of [code]1.0[/code] disables scaling.
</constant>
<constant name="VIEWPORT_SCALING_3D_MODE_MAX" value="2" enum="ViewportScaling3DMode">
<constant name="VIEWPORT_SCALING_3D_MODE_FSR2" value="2" enum="ViewportScaling3DMode">
Use AMD FidelityFX Super Resolution 2.2 upscaling for the viewport's 3D buffer. The amount of scaling can be set using [member Viewport.scaling_3d_scale]. Values less than [code]1.0[/code] will be result in the viewport being upscaled using FSR2. Values greater than [code]1.0[/code] are not supported and bilinear downsampling will be used instead. A value of [code]1.0[/code] will use FSR2 at native resolution as a TAA solution.
</constant>
<constant name="VIEWPORT_SCALING_3D_MODE_MAX" value="3" enum="ViewportScaling3DMode">
Represents the size of the [enum ViewportScaling3DMode] enum.
</constant>
<constant name="VIEWPORT_UPDATE_DISABLED" value="0" enum="ViewportUpdateMode">
Expand Down Expand Up @@ -4708,6 +4711,9 @@
<constant name="VIEWPORT_DEBUG_DRAW_MOTION_VECTORS" value="25" enum="ViewportDebugDraw">
Draws the motion vectors buffer. This is used by temporal antialiasing to correct for motion that occurs during gameplay.
</constant>
<constant name="VIEWPORT_DEBUG_DRAW_INTERNAL_BUFFER" value="26" enum="ViewportDebugDraw">
Internal buffer is drawn instead of regular scene so you can see the per-pixel output that will be used by post-processing effects.
</constant>
<constant name="VIEWPORT_VRS_DISABLED" value="0" enum="ViewportVRSMode">
Variable rate shading is disabled.
</constant>
Expand Down
8 changes: 7 additions & 1 deletion doc/classes/Viewport.xml
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,10 @@
<constant name="SCALING_3D_MODE_FSR" value="1" enum="Scaling3DMode">
Use AMD FidelityFX Super Resolution 1.0 upscaling for the viewport's 3D buffer. The amount of scaling can be set using [member scaling_3d_scale]. Values less than [code]1.0[/code] will be result in the viewport being upscaled using FSR. Values greater than [code]1.0[/code] are not supported and bilinear downsampling will be used instead. A value of [code]1.0[/code] disables scaling.
</constant>
<constant name="SCALING_3D_MODE_MAX" value="2" enum="Scaling3DMode">
<constant name="SCALING_3D_MODE_FSR2" value="2" enum="Scaling3DMode">
Use AMD FidelityFX Super Resolution 2.2 upscaling for the viewport's 3D buffer. The amount of scaling can be set using [member Viewport.scaling_3d_scale]. Values less than [code]1.0[/code] will be result in the viewport being upscaled using FSR2. Values greater than [code]1.0[/code] are not supported and bilinear downsampling will be used instead. A value of [code]1.0[/code] will use FSR2 at native resolution as a TAA solution.
</constant>
<constant name="SCALING_3D_MODE_MAX" value="3" enum="Scaling3DMode">
Represents the size of the [enum Scaling3DMode] enum.
</constant>
<constant name="MSAA_DISABLED" value="0" enum="MSAA">
Expand Down Expand Up @@ -553,6 +556,9 @@
</constant>
<constant name="DEBUG_DRAW_MOTION_VECTORS" value="25" enum="DebugDraw">
</constant>
<constant name="DEBUG_DRAW_INTERNAL_BUFFER" value="26" enum="DebugDraw">
Draws the internal resolution buffer of the scene before post-processing is applied.
</constant>
<constant name="DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST" value="0" enum="DefaultCanvasItemTextureFilter">
The texture filter reads from the nearest pixel only. The simplest and fastest method of filtering, but the texture will look pixelized.
</constant>
Expand Down
12 changes: 10 additions & 2 deletions drivers/vulkan/rendering_device_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5750,8 +5750,8 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms,
Buffer *buffer = uniform_buffer_owner.get_or_null(uniform.get_id(0));
ERR_FAIL_NULL_V_MSG(buffer, RID(), "Uniform buffer supplied (binding: " + itos(uniform.binding) + ") is invalid.");

ERR_FAIL_COND_V_MSG(buffer->size != (uint32_t)set_uniform.length, RID(),
"Uniform buffer supplied (binding: " + itos(uniform.binding) + ") size (" + itos(buffer->size) + " does not match size of shader uniform: (" + itos(set_uniform.length) + ").");
ERR_FAIL_COND_V_MSG(buffer->size < (uint32_t)set_uniform.length, RID(),
"Uniform buffer supplied (binding: " + itos(uniform.binding) + ") size (" + itos(buffer->size) + " is smaller than size of shader uniform: (" + itos(set_uniform.length) + ").");

write.dstArrayElement = 0;
write.descriptorCount = 1;
Expand Down Expand Up @@ -9562,6 +9562,14 @@ uint64_t RenderingDeviceVulkan::limit_get(Limit p_limit) const {
VulkanContext::SubgroupCapabilities subgroup_capabilities = context->get_subgroup_capabilities();
return subgroup_capabilities.size;
}
case LIMIT_SUBGROUP_MIN_SIZE: {
VulkanContext::SubgroupCapabilities subgroup_capabilities = context->get_subgroup_capabilities();
return subgroup_capabilities.min_size;
}
case LIMIT_SUBGROUP_MAX_SIZE: {
VulkanContext::SubgroupCapabilities subgroup_capabilities = context->get_subgroup_capabilities();
return subgroup_capabilities.max_size;
}
case LIMIT_SUBGROUP_IN_SHADERS: {
VulkanContext::SubgroupCapabilities subgroup_capabilities = context->get_subgroup_capabilities();
return subgroup_capabilities.supported_stages_flags_rd();
Expand Down
23 changes: 23 additions & 0 deletions drivers/vulkan/vulkan_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ Error VulkanContext::_initialize_device_extensions() {
register_requested_device_extension(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME, false);
register_requested_device_extension(VK_KHR_MAINTENANCE_2_EXTENSION_NAME, false);
register_requested_device_extension(VK_EXT_PIPELINE_CREATION_CACHE_CONTROL_EXTENSION_NAME, false);
register_requested_device_extension(VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME, false);

if (Engine::get_singleton()->is_generate_spirv_debug_info_enabled()) {
register_requested_device_extension(VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME, true);
Expand Down Expand Up @@ -739,9 +740,12 @@ Error VulkanContext::_check_capabilities() {
multiview_capabilities.max_view_count = 0;
multiview_capabilities.max_instance_count = 0;
subgroup_capabilities.size = 0;
subgroup_capabilities.min_size = 0;
subgroup_capabilities.max_size = 0;
subgroup_capabilities.supportedStages = 0;
subgroup_capabilities.supportedOperations = 0;
subgroup_capabilities.quadOperationsInAllStages = false;
subgroup_capabilities.size_control_is_supported = false;
shader_capabilities.shader_float16_is_supported = false;
shader_capabilities.shader_int8_is_supported = false;
storage_buffer_capabilities.storage_buffer_16_bit_access_is_supported = false;
Expand Down Expand Up @@ -886,6 +890,7 @@ Error VulkanContext::_check_capabilities() {
VkPhysicalDeviceFragmentShadingRatePropertiesKHR vrsProperties{};
VkPhysicalDeviceMultiviewProperties multiviewProperties{};
VkPhysicalDeviceSubgroupProperties subgroupProperties{};
VkPhysicalDeviceSubgroupSizeControlProperties subgroupSizeControlProperties = {};
VkPhysicalDeviceProperties2 physicalDeviceProperties{};
void *nextptr = nullptr;

Expand All @@ -894,6 +899,15 @@ Error VulkanContext::_check_capabilities() {
subgroupProperties.pNext = nextptr;

nextptr = &subgroupProperties;

subgroup_capabilities.size_control_is_supported = is_device_extension_enabled(VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME);

if (subgroup_capabilities.size_control_is_supported) {
subgroupSizeControlProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES;
subgroupSizeControlProperties.pNext = nextptr;

nextptr = &subgroupSizeControlProperties;
}
}

if (multiview_capabilities.is_supported) {
Expand All @@ -916,13 +930,20 @@ Error VulkanContext::_check_capabilities() {
device_properties_func(gpu, &physicalDeviceProperties);

subgroup_capabilities.size = subgroupProperties.subgroupSize;
subgroup_capabilities.min_size = subgroupProperties.subgroupSize;
subgroup_capabilities.max_size = subgroupProperties.subgroupSize;
subgroup_capabilities.supportedStages = subgroupProperties.supportedStages;
subgroup_capabilities.supportedOperations = subgroupProperties.supportedOperations;
// Note: quadOperationsInAllStages will be true if:
// - supportedStages has VK_SHADER_STAGE_ALL_GRAPHICS + VK_SHADER_STAGE_COMPUTE_BIT.
// - supportedOperations has VK_SUBGROUP_FEATURE_QUAD_BIT.
subgroup_capabilities.quadOperationsInAllStages = subgroupProperties.quadOperationsInAllStages;

if (subgroup_capabilities.size_control_is_supported && (subgroupSizeControlProperties.requiredSubgroupSizeStages & VK_SHADER_STAGE_COMPUTE_BIT)) {
subgroup_capabilities.min_size = subgroupSizeControlProperties.minSubgroupSize;
subgroup_capabilities.max_size = subgroupSizeControlProperties.maxSubgroupSize;
}

if (vrs_capabilities.pipeline_vrs_supported || vrs_capabilities.primitive_vrs_supported || vrs_capabilities.attachment_vrs_supported) {
print_verbose("- Vulkan Variable Rate Shading supported:");
if (vrs_capabilities.pipeline_vrs_supported) {
Expand Down Expand Up @@ -962,6 +983,8 @@ Error VulkanContext::_check_capabilities() {

print_verbose("- Vulkan subgroup:");
print_verbose(" size: " + itos(subgroup_capabilities.size));
print_verbose(" min size: " + itos(subgroup_capabilities.min_size));
print_verbose(" max size: " + itos(subgroup_capabilities.max_size));
print_verbose(" stages: " + subgroup_capabilities.supported_stages_desc());
print_verbose(" supported ops: " + subgroup_capabilities.supported_operations_desc());
if (subgroup_capabilities.quadOperationsInAllStages) {
Expand Down
3 changes: 3 additions & 0 deletions drivers/vulkan/vulkan_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ class VulkanContext {
public:
struct SubgroupCapabilities {
uint32_t size;
uint32_t min_size;
uint32_t max_size;
VkShaderStageFlags supportedStages;
VkSubgroupFeatureFlags supportedOperations;
VkBool32 quadOperationsInAllStages;
bool size_control_is_supported;

uint32_t supported_stages_flags_rd() const;
String supported_stages_desc() const;
Expand Down
6 changes: 5 additions & 1 deletion editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3472,7 +3472,8 @@ void Node3DEditorViewport::_menu_option(int p_option) {
case VIEW_DISPLAY_DEBUG_CLUSTER_DECALS:
case VIEW_DISPLAY_DEBUG_CLUSTER_REFLECTION_PROBES:
case VIEW_DISPLAY_DEBUG_OCCLUDERS:
case VIEW_DISPLAY_MOTION_VECTORS: {
case VIEW_DISPLAY_MOTION_VECTORS:
case VIEW_DISPLAY_INTERNAL_BUFFER: {
static const int display_options[] = {
VIEW_DISPLAY_NORMAL,
VIEW_DISPLAY_WIREFRAME,
Expand Down Expand Up @@ -3500,6 +3501,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
VIEW_DISPLAY_DEBUG_CLUSTER_REFLECTION_PROBES,
VIEW_DISPLAY_DEBUG_OCCLUDERS,
VIEW_DISPLAY_MOTION_VECTORS,
VIEW_DISPLAY_INTERNAL_BUFFER,
VIEW_MAX
};
static const Viewport::DebugDraw debug_draw_modes[] = {
Expand Down Expand Up @@ -3529,6 +3531,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
Viewport::DEBUG_DRAW_CLUSTER_REFLECTION_PROBES,
Viewport::DEBUG_DRAW_OCCLUDERS,
Viewport::DEBUG_DRAW_MOTION_VECTORS,
Viewport::DEBUG_DRAW_INTERNAL_BUFFER,
};

for (int idx = 0; display_options[idx] != VIEW_MAX; idx++) {
Expand Down Expand Up @@ -5112,6 +5115,7 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p
display_submenu->add_radio_check_item(TTR("ReflectionProbe Cluster"), VIEW_DISPLAY_DEBUG_CLUSTER_REFLECTION_PROBES);
display_submenu->add_radio_check_item(TTR("Occlusion Culling Buffer"), VIEW_DISPLAY_DEBUG_OCCLUDERS);
display_submenu->add_radio_check_item(TTR("Motion Vectors"), VIEW_DISPLAY_MOTION_VECTORS);
display_submenu->add_radio_check_item(TTR("Internal Buffer"), VIEW_DISPLAY_INTERNAL_BUFFER);

display_submenu->set_name("display_advanced");
view_menu->get_popup()->add_submenu_item(TTR("Display Advanced..."), "display_advanced", VIEW_DISPLAY_ADVANCED);
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/node_3d_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class Node3DEditorViewport : public Control {
VIEW_DISPLAY_DEBUG_CLUSTER_REFLECTION_PROBES,
VIEW_DISPLAY_DEBUG_OCCLUDERS,
VIEW_DISPLAY_MOTION_VECTORS,
VIEW_DISPLAY_INTERNAL_BUFFER,
VIEW_DISPLAY_MAX,
// > Keep in sync with menu.

Expand Down
4 changes: 3 additions & 1 deletion scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4505,7 +4505,7 @@ void Viewport::_bind_methods() {

#ifndef _3D_DISABLED
ADD_GROUP("Scaling 3D", "");
ADD_PROPERTY(PropertyInfo(Variant::INT, "scaling_3d_mode", PROPERTY_HINT_ENUM, "Bilinear (Fastest),FSR 1.0 (Fast)"), "set_scaling_3d_mode", "get_scaling_3d_mode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "scaling_3d_mode", PROPERTY_HINT_ENUM, "Bilinear (Fastest),FSR 1.0 (Fast),FSR 2.2 (Slow)"), "set_scaling_3d_mode", "get_scaling_3d_mode");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "scaling_3d_scale", PROPERTY_HINT_RANGE, "0.25,2.0,0.01"), "set_scaling_3d_scale", "get_scaling_3d_scale");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "texture_mipmap_bias", PROPERTY_HINT_RANGE, "-2,2,0.001"), "set_texture_mipmap_bias", "get_texture_mipmap_bias");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fsr_sharpness", PROPERTY_HINT_RANGE, "0,2,0.1"), "set_fsr_sharpness", "get_fsr_sharpness");
Expand Down Expand Up @@ -4556,6 +4556,7 @@ void Viewport::_bind_methods() {

BIND_ENUM_CONSTANT(SCALING_3D_MODE_BILINEAR);
BIND_ENUM_CONSTANT(SCALING_3D_MODE_FSR);
BIND_ENUM_CONSTANT(SCALING_3D_MODE_FSR2);
BIND_ENUM_CONSTANT(SCALING_3D_MODE_MAX);

BIND_ENUM_CONSTANT(MSAA_DISABLED);
Expand Down Expand Up @@ -4603,6 +4604,7 @@ void Viewport::_bind_methods() {
BIND_ENUM_CONSTANT(DEBUG_DRAW_CLUSTER_REFLECTION_PROBES);
BIND_ENUM_CONSTANT(DEBUG_DRAW_OCCLUDERS)
BIND_ENUM_CONSTANT(DEBUG_DRAW_MOTION_VECTORS)
BIND_ENUM_CONSTANT(DEBUG_DRAW_INTERNAL_BUFFER);

BIND_ENUM_CONSTANT(DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST);
BIND_ENUM_CONSTANT(DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR);
Expand Down
2 changes: 2 additions & 0 deletions scene/main/viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class Viewport : public Node {
enum Scaling3DMode {
SCALING_3D_MODE_BILINEAR,
SCALING_3D_MODE_FSR,
SCALING_3D_MODE_FSR2,
SCALING_3D_MODE_MAX
};

Expand Down Expand Up @@ -167,6 +168,7 @@ class Viewport : public Node {
DEBUG_DRAW_CLUSTER_REFLECTION_PROBES,
DEBUG_DRAW_OCCLUDERS,
DEBUG_DRAW_MOTION_VECTORS,
DEBUG_DRAW_INTERNAL_BUFFER,
};

enum DefaultCanvasItemTextureFilter {
Expand Down
31 changes: 30 additions & 1 deletion servers/rendering/renderer_rd/effects/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,33 @@

Import("env")

env.add_source_files(env.servers_sources, "*.cpp")
env_effects = env.Clone()

# Thirdparty source files

thirdparty_obj = []

thirdparty_dir = "#thirdparty/amd-fsr2/"
thirdparty_sources = ["ffx_assert.cpp", "ffx_fsr2.cpp"]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]

env_effects.Prepend(CPPPATH=[thirdparty_dir])

# This flag doesn't actually control anything GCC specific in FSR2. It determines
# if symbols should be exported, which is not required for Godot.
env_effects.Append(CPPDEFINES=["FFX_GCC"])

env_thirdparty = env_effects.Clone()
env_thirdparty.disable_warnings()
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
env.servers_sources += thirdparty_obj

# Godot source files

module_obj = []

env_effects.add_source_files(module_obj, "*.cpp")
env.servers_sources += module_obj

# Needed to force rebuilding the module files when the thirdparty library is updated.
env.Depends(module_obj, thirdparty_obj)
4 changes: 2 additions & 2 deletions servers/rendering/renderer_rd/effects/copy_effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ CopyEffects::CopyEffects(bool p_prefer_raster_effects) {
ba.enable_blend = true;
ba.src_color_blend_factor = RD::BLEND_FACTOR_ONE;
ba.dst_color_blend_factor = RD::BLEND_FACTOR_ONE;
ba.src_alpha_blend_factor = RD::BLEND_FACTOR_ONE;
ba.dst_alpha_blend_factor = RD::BLEND_FACTOR_ONE;
ba.src_alpha_blend_factor = RD::BLEND_FACTOR_ZERO;
ba.dst_alpha_blend_factor = RD::BLEND_FACTOR_ZERO;
ba.color_blend_op = RD::BLEND_OP_ADD;
ba.alpha_blend_op = RD::BLEND_OP_ADD;

Expand Down
23 changes: 18 additions & 5 deletions servers/rendering/renderer_rd/effects/debug_effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,25 +340,38 @@ void DebugEffects::draw_shadow_frustum(RID p_light, const Projection &p_cam_proj
}
}

void DebugEffects::draw_motion_vectors(RID p_velocity, RID p_dest_fb, Size2i p_velocity_size) {
void DebugEffects::draw_motion_vectors(RID p_velocity, RID p_depth, RID p_dest_fb, const Projection &p_current_projection, const Transform3D &p_current_transform, const Projection &p_previous_projection, const Transform3D &p_previous_transform, Size2i p_resolution) {
MaterialStorage *material_storage = MaterialStorage::get_singleton();
ERR_FAIL_NULL(material_storage);

UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
ERR_FAIL_NULL(uniform_set_cache);

RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
RD::Uniform u_source_velocity(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_velocity }));
RD::Uniform u_source_depth(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 1, Vector<RID>({ default_sampler, p_depth }));

RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_fb, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_DROP, RD::FINAL_ACTION_DISCARD);
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, motion_vectors.pipeline.get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_fb), false, RD::get_singleton()->draw_list_get_current_pass()));

motion_vectors.push_constant.velocity_resolution[0] = p_velocity_size.width;
motion_vectors.push_constant.velocity_resolution[1] = p_velocity_size.height;
Projection reprojection = p_previous_projection.flipped_y() * p_previous_transform.affine_inverse() * p_current_transform * p_current_projection.flipped_y().inverse();
RendererRD::MaterialStorage::store_camera(reprojection, motion_vectors.push_constant.reprojection_matrix);

motion_vectors.push_constant.resolution[0] = p_resolution.width;
motion_vectors.push_constant.resolution[1] = p_resolution.height;
motion_vectors.push_constant.force_derive_from_depth = false;

RID shader = motion_vectors.shader.version_get_shader(motion_vectors.shader_version, 0);
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_source_velocity), 0);
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_source_velocity, u_source_depth), 0);
RD::get_singleton()->draw_list_set_push_constant(draw_list, &motion_vectors.push_constant, sizeof(MotionVectorsPushConstant));
RD::get_singleton()->draw_list_draw(draw_list, false, 1u, 3u);

#ifdef DRAW_DERIVATION_FROM_DEPTH_ON_TOP
motion_vectors.push_constant.force_derive_from_depth = true;

RD::get_singleton()->draw_list_set_push_constant(draw_list, &motion_vectors.push_constant, sizeof(MotionVectorsPushConstant));
RD::get_singleton()->draw_list_draw(draw_list, false, 1u, 3u);
#endif

RD::get_singleton()->draw_list_end();
}
Loading

0 comments on commit 057367b

Please sign in to comment.