Path: blob/master/drivers/metal/rendering_device_driver_metal3.h
21677 views
/**************************************************************************/1/* rendering_device_driver_metal3.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#include "metal3_objects.h"33#include "rendering_device_driver_metal.h"3435#include <Metal/Metal.hpp>3637namespace MTL3 {3839class API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) RenderingDeviceDriverMetal final : public ::RenderingDeviceDriverMetal {40friend class MDCommandBuffer;41#pragma mark - Generic4243NS::SharedPtr<MTL::CommandQueue> device_queue;4445struct Fence {46virtual void signal(MTL::CommandBuffer *p_cmd_buffer) = 0;47virtual Error wait(uint32_t p_timeout_ms) = 0;48virtual ~Fence() = default;49};5051struct FenceEvent : Fence {52NS::SharedPtr<MTL::SharedEvent> event;53uint64_t value = 0;54FenceEvent(NS::SharedPtr<MTL::SharedEvent> p_event) :55event(p_event) {}56void signal(MTL::CommandBuffer *p_cb) override;57Error wait(uint32_t p_timeout_ms) override;58};5960struct FenceSemaphore : Fence {61dispatch_semaphore_t semaphore;62FenceSemaphore() :63semaphore(dispatch_semaphore_create(0)) {}64void signal(MTL::CommandBuffer *p_cb) override;65Error wait(uint32_t p_timeout_ms) override;66};6768struct Semaphore {69NS::SharedPtr<MTL::Event> event;70uint64_t value = 0;71Semaphore(NS::SharedPtr<MTL::Event> p_event) :72event(p_event) {}73};7475Vector<MDCommandBuffer *> command_buffers;7677Error _create_device() override;78Error _execute_and_present_barriers(CommandQueueID p_cmd_queue, VectorView<SemaphoreID> p_wait_semaphores, VectorView<CommandBufferID> p_cmd_buffers, VectorView<SemaphoreID> p_cmd_semaphores, FenceID p_cmd_fence, VectorView<SwapChainID> p_swap_chains);79Error _execute_and_present(CommandQueueID p_cmd_queue, VectorView<SemaphoreID> p_wait_semaphores, VectorView<CommandBufferID> p_cmd_buffers, VectorView<SemaphoreID> p_cmd_semaphores, FenceID p_cmd_fence, VectorView<SwapChainID> p_swap_chains);8081protected:82MTL::CommandQueue *get_command_queue() const override { return device_queue.get(); }83void add_residency_set_to_main_queue(MTL::ResidencySet *p_set) override;84void remove_residency_set_to_main_queue(MTL::ResidencySet *p_set) override;8586public:87Error initialize(uint32_t p_device_index, uint32_t p_frame_count) override;8889FenceID fence_create() override;90Error fence_wait(FenceID p_fence) override;91void fence_free(FenceID p_fence) override;9293SemaphoreID semaphore_create() override;94void semaphore_free(SemaphoreID p_semaphore) override;9596CommandQueueID command_queue_create(CommandQueueFamilyID p_cmd_queue_family, bool p_identify_as_main_queue = false) override;97Error command_queue_execute_and_present(CommandQueueID p_cmd_queue, VectorView<SemaphoreID> p_wait_semaphores, VectorView<CommandBufferID> p_cmd_buffers, VectorView<SemaphoreID> p_cmd_semaphores, FenceID p_cmd_fence, VectorView<SwapChainID> p_swap_chains) override;98void command_queue_free(CommandQueueID p_cmd_queue) override;99100CommandPoolID command_pool_create(CommandQueueFamilyID p_cmd_queue_family, CommandBufferType p_cmd_buffer_type) override;101bool command_pool_reset(CommandPoolID p_cmd_pool) override;102void command_pool_free(CommandPoolID p_cmd_pool) override;103104CommandBufferID command_buffer_create(CommandPoolID p_cmd_pool) override;105106#pragma mark - Miscellaneous107108String get_api_name() const override { return "Metal"; }109110RenderingDeviceDriverMetal(RenderingContextDriverMetal *p_context_driver);111~RenderingDeviceDriverMetal();112};113114} // namespace MTL3115116117