Path: blob/master/servers/rendering/renderer_rd/effects/metal_fx.h
21520 views
/**************************************************************************/1/* metal_fx.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#if defined(METAL_ENABLED) && !defined(VISIONOS_ENABLED)33#define METAL_MFXTEMPORAL_ENABLED34#endif3536#ifdef METAL_ENABLED3738#include "spatial_upscaler.h"3940#include "core/templates/paged_allocator.h"41#include "servers/rendering/renderer_scene_render.h"4243namespace MTLFX {44class SpatialScalerBase;45class TemporalScalerBase;46} //namespace MTLFX4748namespace RendererRD {4950struct MFXSpatialContext {51MTLFX::SpatialScalerBase *scaler = nullptr;52MFXSpatialContext() = default;53~MFXSpatialContext();54};5556class MFXSpatialEffect : public SpatialUpscaler {57struct CallbackArgs {58MFXSpatialEffect *owner = nullptr;59MTLFX::SpatialScalerBase *scaler = nullptr;60RDD::TextureID src;61RDD::TextureID dst;6263CallbackArgs(MFXSpatialEffect *p_owner, RDD::TextureID p_src, RDD::TextureID p_dst, const MFXSpatialContext &p_ctx) :64owner(p_owner), scaler(p_ctx.scaler), src(p_src), dst(p_dst) {}6566static void free(CallbackArgs **p_args) {67(*p_args)->owner->args_allocator.free(*p_args);68*p_args = nullptr;69}70};7172PagedAllocator<CallbackArgs, true, 16> args_allocator;73static void callback(RDD *p_driver, RDD::CommandBufferID p_command_buffer, CallbackArgs *p_userdata);7475public:76virtual const Span<char> get_label() const final { return "MetalFX Spatial Upscale"; }77virtual void ensure_context(Ref<RenderSceneBuffersRD> p_render_buffers) final;78virtual void process(Ref<RenderSceneBuffersRD> p_render_buffers, RID p_src, RID p_dst) final;7980struct CreateParams {81Vector2i input_size;82Vector2i output_size;83RD::DataFormat input_format;84RD::DataFormat output_format;85};8687MFXSpatialContext *create_context(CreateParams p_params) const;8889MFXSpatialEffect();90~MFXSpatialEffect();91};9293#ifdef METAL_MFXTEMPORAL_ENABLED9495struct MFXTemporalContext {96MTLFX::TemporalScalerBase *scaler = nullptr;97MFXTemporalContext() = default;98~MFXTemporalContext();99};100101class MFXTemporalEffect {102struct CallbackArgs {103MFXTemporalEffect *owner = nullptr;104MTLFX::TemporalScalerBase *scaler = nullptr;105RDD::TextureID src;106RDD::TextureID depth;107RDD::TextureID motion;108RDD::TextureID exposure;109Vector2 jitter_offset;110RDD::TextureID dst;111bool reset = false;112113CallbackArgs(114MFXTemporalEffect *p_owner,115RDD::TextureID p_src,116RDD::TextureID p_depth,117RDD::TextureID p_motion,118RDD::TextureID p_exposure,119Vector2 p_jitter_offset,120RDD::TextureID p_dst,121const MFXTemporalContext &p_ctx,122bool p_reset) :123owner(p_owner),124scaler(p_ctx.scaler),125src(p_src),126depth(p_depth),127motion(p_motion),128exposure(p_exposure),129jitter_offset(p_jitter_offset),130dst(p_dst),131reset(p_reset) {}132133static void free(CallbackArgs **p_args) {134(*p_args)->owner->args_allocator.free(*p_args);135*p_args = nullptr;136}137};138139PagedAllocator<CallbackArgs, true, 16> args_allocator;140141static void callback(RDD *p_driver, RDD::CommandBufferID p_command_buffer, CallbackArgs *p_userdata);142143public:144MFXTemporalEffect();145~MFXTemporalEffect();146147struct CreateParams {148Vector2i input_size;149Vector2i output_size;150RD::DataFormat input_format;151RD::DataFormat depth_format;152RD::DataFormat motion_format;153RD::DataFormat reactive_format;154RD::DataFormat output_format;155Vector2 motion_vector_scale;156};157158MFXTemporalContext *create_context(CreateParams p_params) const;159160struct Params {161RID src;162RID depth;163RID motion;164RID exposure;165RID dst;166Vector2 jitter_offset;167bool reset = false;168};169170void process(MFXTemporalContext *p_ctx, Params p_params);171};172173#endif174175} //namespace RendererRD176177#endif // METAL_ENABLED178179180