Path: blob/master/servers/rendering/renderer_rd/effects/metal_fx.h
10279 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"4243#ifdef __OBJC__44@protocol MTLFXSpatialScaler;45@protocol MTLFXTemporalScaler;46#endif4748namespace RendererRD {4950struct MFXSpatialContext {51#ifdef __OBJC__52id<MTLFXSpatialScaler> scaler = nullptr;53#else54void *scaler = nullptr;55#endif56MFXSpatialContext() = default;57~MFXSpatialContext();58};5960class MFXSpatialEffect : public SpatialUpscaler {61struct CallbackArgs {62MFXSpatialEffect *owner;63RDD::TextureID src;64RDD::TextureID dst;65MFXSpatialContext ctx;6667CallbackArgs(MFXSpatialEffect *p_owner, RDD::TextureID p_src, RDD::TextureID p_dst, MFXSpatialContext p_ctx) :68owner(p_owner), src(p_src), dst(p_dst), ctx(p_ctx) {}6970static void free(CallbackArgs **p_args) {71(*p_args)->owner->args_allocator.free(*p_args);72*p_args = nullptr;73}74};7576PagedAllocator<CallbackArgs, true, 16> args_allocator;77static void callback(RDD *p_driver, RDD::CommandBufferID p_command_buffer, CallbackArgs *p_userdata);7879public:80virtual const Span<char> get_label() const final { return "MetalFX Spatial Upscale"; }81virtual void ensure_context(Ref<RenderSceneBuffersRD> p_render_buffers) final;82virtual void process(Ref<RenderSceneBuffersRD> p_render_buffers, RID p_src, RID p_dst) final;8384struct CreateParams {85Vector2i input_size;86Vector2i output_size;87RD::DataFormat input_format;88RD::DataFormat output_format;89};9091MFXSpatialContext *create_context(CreateParams p_params) const;9293MFXSpatialEffect();94~MFXSpatialEffect();95};9697#ifdef METAL_MFXTEMPORAL_ENABLED9899struct MFXTemporalContext {100#ifdef __OBJC__101id<MTLFXTemporalScaler> scaler = nullptr;102#else103void *scaler = nullptr;104#endif105MFXTemporalContext() = default;106~MFXTemporalContext();107};108109class MFXTemporalEffect {110struct CallbackArgs {111MFXTemporalEffect *owner;112RDD::TextureID src;113RDD::TextureID depth;114RDD::TextureID motion;115RDD::TextureID exposure;116Vector2 jitter_offset;117RDD::TextureID dst;118MFXTemporalContext ctx;119bool reset = false;120121CallbackArgs(122MFXTemporalEffect *p_owner,123RDD::TextureID p_src,124RDD::TextureID p_depth,125RDD::TextureID p_motion,126RDD::TextureID p_exposure,127Vector2 p_jitter_offset,128RDD::TextureID p_dst,129MFXTemporalContext p_ctx,130bool p_reset) :131owner(p_owner),132src(p_src),133depth(p_depth),134motion(p_motion),135exposure(p_exposure),136jitter_offset(p_jitter_offset),137dst(p_dst),138ctx(p_ctx),139reset(p_reset) {}140141static void free(CallbackArgs **p_args) {142(*p_args)->owner->args_allocator.free(*p_args);143*p_args = nullptr;144}145};146147PagedAllocator<CallbackArgs, true, 16> args_allocator;148149static void callback(RDD *p_driver, RDD::CommandBufferID p_command_buffer, CallbackArgs *p_userdata);150151public:152MFXTemporalEffect();153~MFXTemporalEffect();154155struct CreateParams {156Vector2i input_size;157Vector2i output_size;158RD::DataFormat input_format;159RD::DataFormat depth_format;160RD::DataFormat motion_format;161RD::DataFormat reactive_format;162RD::DataFormat output_format;163Vector2 motion_vector_scale;164};165166MFXTemporalContext *create_context(CreateParams p_params) const;167168struct Params {169RID src;170RID depth;171RID motion;172RID exposure;173RID dst;174Vector2 jitter_offset;175bool reset = false;176};177178void process(MFXTemporalContext *p_ctx, Params p_params);179};180181#endif182183} //namespace RendererRD184185#endif // METAL_ENABLED186187188