Path: blob/master/servers/rendering/renderer_rd/effects/metal_fx.h
22517 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"42#include "servers/rendering/rendering_device_driver.h"4344namespace MTLFX {45class SpatialScalerBase;46class TemporalScalerBase;47} //namespace MTLFX4849namespace RendererRD {5051struct MFXSpatialContext {52MTLFX::SpatialScalerBase *scaler = nullptr;53MFXSpatialContext() = default;54~MFXSpatialContext();55};5657class MFXSpatialEffect : public SpatialUpscaler {58struct CallbackArgs {59MFXSpatialEffect *owner = nullptr;60MTLFX::SpatialScalerBase *scaler = nullptr;61RDD::TextureID src;62RDD::TextureID dst;6364CallbackArgs(MFXSpatialEffect *p_owner, RDD::TextureID p_src, RDD::TextureID p_dst, const MFXSpatialContext &p_ctx) :65owner(p_owner), scaler(p_ctx.scaler), src(p_src), dst(p_dst) {}6667static void free(CallbackArgs **p_args) {68(*p_args)->owner->args_allocator.free(*p_args);69*p_args = nullptr;70}71};7273PagedAllocator<CallbackArgs, true, 16> args_allocator;74static void callback(RDD *p_driver, RDD::CommandBufferID p_command_buffer, CallbackArgs *p_userdata);7576public:77virtual const Span<char> get_label() const final { return "MetalFX Spatial Upscale"; }78virtual void ensure_context(Ref<RenderSceneBuffersRD> p_render_buffers) final;79virtual void process(Ref<RenderSceneBuffersRD> p_render_buffers, RID p_src, RID p_dst) final;8081struct CreateParams {82Vector2i input_size;83Vector2i output_size;84RDD::DataFormat input_format;85RDD::DataFormat output_format;86};8788MFXSpatialContext *create_context(CreateParams p_params) const;8990MFXSpatialEffect();91~MFXSpatialEffect();92};9394#ifdef METAL_MFXTEMPORAL_ENABLED9596struct MFXTemporalContext {97MTLFX::TemporalScalerBase *scaler = nullptr;98MFXTemporalContext() = default;99~MFXTemporalContext();100};101102class MFXTemporalEffect {103struct CallbackArgs {104MFXTemporalEffect *owner = nullptr;105MTLFX::TemporalScalerBase *scaler = nullptr;106RDD::TextureID src;107RDD::TextureID depth;108RDD::TextureID motion;109RDD::TextureID exposure;110Vector2 jitter_offset;111RDD::TextureID dst;112bool reset = false;113114CallbackArgs(115MFXTemporalEffect *p_owner,116RDD::TextureID p_src,117RDD::TextureID p_depth,118RDD::TextureID p_motion,119RDD::TextureID p_exposure,120Vector2 p_jitter_offset,121RDD::TextureID p_dst,122const MFXTemporalContext &p_ctx,123bool p_reset) :124owner(p_owner),125scaler(p_ctx.scaler),126src(p_src),127depth(p_depth),128motion(p_motion),129exposure(p_exposure),130jitter_offset(p_jitter_offset),131dst(p_dst),132reset(p_reset) {}133134static void free(CallbackArgs **p_args) {135(*p_args)->owner->args_allocator.free(*p_args);136*p_args = nullptr;137}138};139140PagedAllocator<CallbackArgs, true, 16> args_allocator;141142static void callback(RDD *p_driver, RDD::CommandBufferID p_command_buffer, CallbackArgs *p_userdata);143144public:145MFXTemporalEffect();146~MFXTemporalEffect();147148struct CreateParams {149Vector2i input_size;150Vector2i output_size;151RDD::DataFormat input_format;152RDD::DataFormat depth_format;153RDD::DataFormat motion_format;154RDD::DataFormat reactive_format;155RDD::DataFormat output_format;156Vector2 motion_vector_scale;157};158159MFXTemporalContext *create_context(CreateParams p_params) const;160161struct Params {162RID src;163RID depth;164RID motion;165RID exposure;166RID dst;167Vector2 jitter_offset;168bool reset = false;169};170171void process(MFXTemporalContext *p_ctx, Params p_params);172};173174#endif175176} //namespace RendererRD177178#endif // METAL_ENABLED179180181