This commit is contained in:
xsl
2025-09-04 10:54:47 +08:00
commit 6bc8f61b18
1808 changed files with 208268 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
/* Copyright (c) 2023-2024, Holochip Inc.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "platform/platform.h"
namespace vkb
{
class IosPlatform : public Platform
{
public:
IosPlatform(const PlatformContext &context);
virtual ~IosPlatform() = default;
virtual const char *get_surface_extension();
void* view;
protected:
virtual void create_window(const Window::Properties &properties) override;
};
} // namespace vkb
+90
View File
@@ -0,0 +1,90 @@
/* Copyright (c) 2023-2024, Holochip Inc.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ios_platform.h"
#include "common/error.h"
#include "ios/context.hpp"
#include "platform/headless_window.h"
#include "platform/ios/ios_window.h"
VKBP_DISABLE_WARNINGS()
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
VKBP_ENABLE_WARNINGS()
#import <objc/message.h>
#import <objc/runtime.h>
// This is equivalent to creating a @class with one public variable named 'window'.
struct AppDel
{
Class isa;
id window;
};
#ifndef VK_MVK_MACOS_SURFACE_EXTENSION_NAME
# define VK_MVK_MACOS_SURFACE_EXTENSION_NAME "VK_MVK_macos_surface"
#endif
#ifndef VK_EXT_METAL_SURFACE_EXTENSION_NAME
# define VK_EXT_METAL_SURFACE_EXTENSION_NAME "VK_EXT_metal_surface"
#endif
namespace vkb
{
namespace
{
inline const std::string get_temp_path_from_environment()
{
std::string temp_path = "/tmp/";
if (const char *env_ptr = std::getenv("TMPDIR"))
{
temp_path = std::string(env_ptr) + "/";
}
return temp_path;
}
} // namespace
IosPlatform::IosPlatform(const PlatformContext &context)
: Platform{context}
{
IosPlatformContext * cont = (IosPlatformContext*)&context;
view = cont->view;
}
const char *IosPlatform::get_surface_extension()
{
return VK_EXT_METAL_SURFACE_EXTENSION_NAME;
}
void IosPlatform::create_window(const Window::Properties &properties)
{
if (properties.mode == vkb::Window::Mode::Headless)
{
window = std::make_unique<HeadlessWindow>(properties);
}
else
{
window = std::make_unique<IosWindow>(this, properties);
((IosWindow*)window.get())->set_vulkan_view((VulkanView*) view);
}
}
} // namespace vkb
+81
View File
@@ -0,0 +1,81 @@
/* Copyright (c) 2023-2025, Holochip Inc.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "common/vk_common.h"
#include "platform/window.h"
#import <UIKit/UIKit.h>
@interface VulkanView : UIView
@end
namespace vkb
{
class IosPlatform;
/**
* @brief Wrapper for a ANativeWindow, handles the window behaviour (including headless mode on Android)
* This class should not be responsible for destroying the underlying data it points to
*/
class IosWindow : public Window
{
public:
/**
* @brief Constructor
* @param platform The platform this window is created for
* @param properties Window configuration
*/
IosWindow(IosPlatform *platform, const Window::Properties &properties);
~IosWindow() override = default;
/**
* @brief Creates a Vulkan surface to the native window
* If headless, this will return VK_NULL_HANDLE
*/
VkSurfaceKHR create_surface(vkb::core::InstanceC &instance) override;
/**
* @brief Creates a Vulkan surface to the native window
* If headless, this will return nullptr
*/
VkSurfaceKHR create_surface(VkInstance instance, VkPhysicalDevice physical_device) override;
void process_events() override;
bool should_close() override;
void close() override;
float get_dpi_factor() const override;
float get_content_scale_factor() const override;
std::vector<const char *> get_required_surface_extensions() const override;
VulkanView * get_vulkan_view() {return view;}
void set_vulkan_view(VulkanView* _view) { view = _view; }
private:
VulkanView * view;
IosPlatform *platform;
bool finish_called{false};
};
} // namespace vkb
+88
View File
@@ -0,0 +1,88 @@
/* Copyright (c) 2023-2025, Holochip Inc.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ios_window.h"
#include <UIKit/UIScreen.h>
#include <UIKit/UIWindow.h>
#include "platform/ios/ios_platform.h"
namespace vkb
{
IosWindow::IosWindow(IosPlatform *platform, const Window::Properties &properties) :
Window(properties),
platform{platform}
{
}
VkSurfaceKHR IosWindow::create_surface(vkb::core::InstanceC &instance)
{
return create_surface(instance.get_handle(), VK_NULL_HANDLE);
}
VkSurfaceKHR IosWindow::create_surface(VkInstance instance, VkPhysicalDevice)
{
if (instance == VK_NULL_HANDLE || properties.mode == Mode::Headless)
{
return VK_NULL_HANDLE;
}
VkSurfaceKHR surface{};
VkMetalSurfaceCreateInfoEXT info{VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT};
view = (VulkanView*)platform->view;
info.pLayer = (CAMetalLayer *) [view layer];
VK_CHECK(vkCreateMetalSurfaceEXT(instance, &info, nullptr, &surface));
return surface;
}
void IosWindow::process_events()
{
}
bool IosWindow::should_close()
{
return finish_called;
}
void IosWindow::close()
{
finish_called = true;
}
float IosWindow::get_dpi_factor() const
{
return 1.0;
}
float IosWindow::get_content_scale_factor() const
{
return [[UIScreen mainScreen] nativeScale];
}
std::vector<const char *> IosWindow::get_required_surface_extensions() const
{
return {VK_EXT_METAL_SURFACE_EXTENSION_NAME};
}
} // namespace vkb
@implementation VulkanView
+(Class) layerClass { return [CAMetalLayer class]; }
@end