mirror of
https://github.com/obhq/obliteration.git
synced 2024-11-23 11:19:56 +00:00
Initializes Vulkan Instance (#927)
This commit is contained in:
parent
7f04eee962
commit
bee12a8d25
58
.github/workflows/ci-windows.yml
vendored
58
.github/workflows/ci-windows.yml
vendored
@ -15,24 +15,9 @@ jobs:
|
||||
- name: Generate cache keys
|
||||
run: |
|
||||
echo "cargo=${{ runner.os }}-cargo" >> $env:GITHUB_OUTPUT
|
||||
echo "vulkan=${{ runner.os }}-vulkan-1.3.239.0" >> $env:GITHUB_OUTPUT
|
||||
echo "qt=${{ runner.os }}-qt-6.7.2" >> $env:GITHUB_OUTPUT
|
||||
echo "vulkan=${{ runner.os }}-vulkan-1.3.290.0" >> $env:GITHUB_OUTPUT
|
||||
id: cache-keys
|
||||
- name: Install Qt
|
||||
run: |
|
||||
Invoke-WebRequest `
|
||||
-Uri "https://download.qt.io/online/qtsdkrepository/windows_x86/desktop/qt6_660/qt.qt6.660.win64_msvc2019_64/6.6.0-0-202310040911qtbase-Windows-Windows_10_22H2-MSVC2019-Windows-Windows_10_22H2-X86_64.7z" `
|
||||
-OutFile qt-base.7z
|
||||
Invoke-WebRequest `
|
||||
-Uri "https://download.qt.io/online/qtsdkrepository/windows_x86/desktop/qt6_660/qt.qt6.660.win64_msvc2019_64/6.6.0-0-202310040911qtsvg-Windows-Windows_10_22H2-MSVC2019-Windows-Windows_10_22H2-X86_64.7z" `
|
||||
-OutFile qt-svg.7z
|
||||
7z x qt-base.7z -oqt
|
||||
7z x qt-svg.7z -oqt
|
||||
echo "CMAKE_PREFIX_PATH=qt\6.6.0\msvc2019_64" >> $env:GITHUB_ENV
|
||||
- name: Restore Cargo home
|
||||
uses: actions/cache/restore@v4
|
||||
with:
|
||||
path: ~/.cargo
|
||||
key: ${{ steps.cache-keys.outputs.cargo }}
|
||||
- name: Restore Vulkan SDK
|
||||
uses: actions/cache/restore@v4
|
||||
with:
|
||||
@ -41,13 +26,42 @@ jobs:
|
||||
id: restore-vulkan
|
||||
- name: Install Vulkan SDK
|
||||
run: |
|
||||
Invoke-WebRequest -Uri "https://sdk.lunarg.com/sdk/download/1.3.239.0/windows/VulkanSDK-1.3.239.0-Installer.exe" -OutFile VulkanSDK.exe
|
||||
Invoke-WebRequest -Uri "https://sdk.lunarg.com/sdk/download/1.3.290.0/windows/VulkanSDK-1.3.290.0-Installer.exe" -OutFile VulkanSDK.exe
|
||||
.\VulkanSDK.exe --root C:\VulkanSDK --accept-licenses --default-answer --confirm-command install
|
||||
echo "new-install=true" >> $env:GITHUB_OUTPUT
|
||||
id: install-vulkan
|
||||
if: ${{ steps.restore-vulkan.outputs.cache-hit != 'true' }}
|
||||
- name: Set Vulkan SDK path
|
||||
run: echo "VULKAN_SDK=C:\VulkanSDK" >> $env:GITHUB_ENV
|
||||
run: echo "VULKAN_SDK=C:\VulkanSDK" >> $env:GITHUB_ENV
|
||||
- name: Restore Qt
|
||||
uses: actions/cache/restore@v4
|
||||
with:
|
||||
path: qt
|
||||
key: ${{ steps.cache-keys.outputs.qt }}
|
||||
id: restore-qt
|
||||
- name: Download Qt
|
||||
run: |
|
||||
Invoke-WebRequest `
|
||||
-Uri "https://download.qt.io/official_releases/qt/6.7/6.7.2/single/qt-everywhere-src-6.7.2.tar.xz" `
|
||||
-OutFile qt.tar.xz
|
||||
7z x -so qt.tar.xz | 7z x -si -ttar
|
||||
rm qt.tar.xz
|
||||
mkdir qt-build
|
||||
if: ${{ steps.restore-qt.outputs.cache-hit != 'true' }}
|
||||
- name: Build Qt
|
||||
run: |
|
||||
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" amd64
|
||||
${{ github.workspace }}\qt-everywhere-src-6.7.2\configure.bat -prefix "${{ github.workspace }}\qt" -no-openssl && cmake --build . --parallel && cmake --install .
|
||||
shell: cmd
|
||||
working-directory: qt-build
|
||||
if: ${{ steps.restore-qt.outputs.cache-hit != 'true' }}
|
||||
- name: Set Qt path
|
||||
run: echo "CMAKE_PREFIX_PATH=qt" >> $env:GITHUB_ENV
|
||||
- name: Restore Cargo home
|
||||
uses: actions/cache/restore@v4
|
||||
with:
|
||||
path: ~/.cargo
|
||||
key: ${{ steps.cache-keys.outputs.cargo }}
|
||||
- name: Update Rust
|
||||
run: rustup update stable
|
||||
- name: Add additional Rust targets
|
||||
@ -78,3 +92,9 @@ jobs:
|
||||
path: ~/.cargo
|
||||
key: ${{ steps.cache-keys.outputs.cargo }}-${{ github.run_id }}
|
||||
if: startsWith(github.ref, 'refs/heads/')
|
||||
- name: Cache Qt
|
||||
uses: actions/cache/save@v4
|
||||
with:
|
||||
path: qt
|
||||
key: ${{ steps.cache-keys.outputs.qt }}
|
||||
if: startsWith(github.ref, 'refs/heads/') && steps.restore-qt.outputs.cache-hit != 'true'
|
||||
|
@ -32,7 +32,7 @@ We have a Discord server for discussion about Obliteration and its development.
|
||||
## System requirements
|
||||
|
||||
- Windows 10, Linux or macOS 11+.
|
||||
- On Windows and Linux make sure you have Vulkan installed. If you encountered `Failed to initialize Vulkan (-9)` that mean you don't have a Vulkan installed.
|
||||
- On Windows and Linux make sure you have Vulkan 1.3 installed. If you encountered `Failed to initialize Vulkan (-9)` that mean you don't have a Vulkan installed.
|
||||
- x86-64 CPU. We want to support non-x86 but currently we don't have any developers who are willing to work on this.
|
||||
- CPU with hardware virtualization supports.
|
||||
- Windows and Linux users may need to enable this feature on the BIOS/UEFI settings.
|
||||
|
@ -72,11 +72,11 @@ add_executable(obliteration WIN32 MACOSX_BUNDLE
|
||||
system.cpp)
|
||||
|
||||
if(WIN32)
|
||||
target_sources(obliteration PRIVATE resources.rc)
|
||||
target_sources(obliteration PRIVATE resources.rc vulkan.cpp)
|
||||
elseif(APPLE)
|
||||
target_sources(obliteration PRIVATE resources/obliteration.icns)
|
||||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
target_sources(obliteration PRIVATE kvm.cpp)
|
||||
target_sources(obliteration PRIVATE kvm.cpp vulkan.cpp)
|
||||
endif()
|
||||
|
||||
add_dependencies(obliteration core)
|
||||
|
20
src/core.h
20
src/core.h
@ -29,6 +29,24 @@ struct RustError;
|
||||
*/
|
||||
struct Vmm;
|
||||
|
||||
/**
|
||||
* Contains objects required to render the screen.
|
||||
*/
|
||||
struct VmmScreen {
|
||||
#if !defined(__APPLE__)
|
||||
size_t vk_instance
|
||||
#endif
|
||||
;
|
||||
#if !defined(__APPLE__)
|
||||
size_t vk_surface
|
||||
#endif
|
||||
;
|
||||
#if defined(__APPLE__)
|
||||
size_t view
|
||||
#endif
|
||||
;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
@ -74,7 +92,7 @@ struct RustError *update_firmware(const char *root,
|
||||
|
||||
void vmm_free(struct Vmm *vmm);
|
||||
|
||||
struct Vmm *vmm_run(const char *kernel, size_t screen, struct RustError **err);
|
||||
struct Vmm *vmm_run(const char *kernel, const struct VmmScreen *screen, struct RustError **err);
|
||||
|
||||
struct RustError *vmm_draw(struct Vmm *vmm);
|
||||
|
||||
|
@ -16,6 +16,9 @@ param = { path = "../param" }
|
||||
pkg = { path = "../pkg" }
|
||||
thiserror = "1.0"
|
||||
|
||||
[target.'cfg(not(target_os = "macos"))'.dependencies]
|
||||
ash = "0.38.0"
|
||||
|
||||
[target.'cfg(windows)'.dependencies.windows-sys]
|
||||
version = "0.52.0"
|
||||
features = [
|
||||
|
@ -23,6 +23,7 @@ fn main() {
|
||||
|
||||
conf.after_includes = Some(buf);
|
||||
conf.pragma_once = true;
|
||||
conf.tab_width = 4;
|
||||
conf.language = Language::C;
|
||||
conf.cpp_compat = true;
|
||||
conf.style = Style::Tag;
|
||||
|
@ -34,7 +34,7 @@ pub unsafe extern "C" fn vmm_free(vmm: *mut Vmm) {
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn vmm_run(
|
||||
kernel: *const c_char,
|
||||
screen: usize,
|
||||
screen: *const VmmScreen,
|
||||
err: *mut *mut RustError,
|
||||
) -> *mut Vmm {
|
||||
// Check if path UTF-8.
|
||||
@ -525,6 +525,17 @@ impl Drop for Vmm {
|
||||
}
|
||||
}
|
||||
|
||||
/// Contains objects required to render the screen.
|
||||
#[repr(C)]
|
||||
pub struct VmmScreen {
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub vk_instance: usize,
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub vk_surface: usize,
|
||||
#[cfg(target_os = "macos")]
|
||||
pub view: usize,
|
||||
}
|
||||
|
||||
/// Object that has a physical address in the virtual machine.
|
||||
trait MemoryAddr {
|
||||
/// Physical address in the virtual machine.
|
||||
|
@ -1,5 +1,6 @@
|
||||
use self::buffer::MetalBuffer;
|
||||
use super::{Screen, ScreenBuffer, VmmError};
|
||||
use crate::vmm::VmmScreen;
|
||||
use metal::{CAMetalLayer, Device, MetalLayer};
|
||||
use objc::runtime::{Object, NO, YES};
|
||||
use objc::{msg_send, sel, sel_impl};
|
||||
@ -20,7 +21,7 @@ pub struct Metal {
|
||||
}
|
||||
|
||||
impl Metal {
|
||||
pub fn new(surface: usize) -> Result<Self, VmmError> {
|
||||
pub fn new(screen: *const VmmScreen) -> Result<Self, VmmError> {
|
||||
// Get Metal device.
|
||||
let device = match Device::system_default() {
|
||||
Some(v) => v,
|
||||
@ -33,7 +34,7 @@ impl Metal {
|
||||
layer.set_device(&device);
|
||||
|
||||
// Set view layer.
|
||||
let view = surface as *mut Object;
|
||||
let view = unsafe { (*screen).view as *mut Object };
|
||||
|
||||
let _: () = unsafe { msg_send![view, setLayer:layer.as_ref()] };
|
||||
let _: () = unsafe { msg_send![view, setWantsLayer:YES] };
|
||||
|
186
src/core/src/vmm/screen/vulkan/ffi.rs
Normal file
186
src/core/src/vmm/screen/vulkan/ffi.rs
Normal file
@ -0,0 +1,186 @@
|
||||
use ash::vk::{
|
||||
AllocationCallbacks, Device, DeviceCreateInfo, ExtensionProperties, ExternalBufferProperties,
|
||||
ExternalFenceProperties, ExternalSemaphoreProperties, Format, FormatProperties,
|
||||
FormatProperties2, ImageCreateFlags, ImageFormatProperties, ImageFormatProperties2,
|
||||
ImageTiling, ImageType, ImageUsageFlags, Instance, LayerProperties, PFN_vkVoidFunction,
|
||||
PhysicalDevice, PhysicalDeviceExternalBufferInfo, PhysicalDeviceExternalFenceInfo,
|
||||
PhysicalDeviceExternalSemaphoreInfo, PhysicalDeviceFeatures, PhysicalDeviceFeatures2,
|
||||
PhysicalDeviceGroupProperties, PhysicalDeviceImageFormatInfo2, PhysicalDeviceMemoryProperties,
|
||||
PhysicalDeviceMemoryProperties2, PhysicalDeviceProperties, PhysicalDeviceProperties2,
|
||||
PhysicalDeviceSparseImageFormatInfo2, PhysicalDeviceToolProperties, QueueFamilyProperties,
|
||||
QueueFamilyProperties2, Result, SampleCountFlags, SparseImageFormatProperties,
|
||||
SparseImageFormatProperties2,
|
||||
};
|
||||
use std::ffi::c_char;
|
||||
|
||||
extern "system" {
|
||||
#[link_name = "vmm_vk_create_device"]
|
||||
pub fn create_device(
|
||||
physical_device: PhysicalDevice,
|
||||
p_create_info: *const DeviceCreateInfo<'_>,
|
||||
p_allocator: *const AllocationCallbacks<'_>,
|
||||
p_device: *mut Device,
|
||||
) -> Result;
|
||||
|
||||
#[link_name = "vmm_vk_enumerate_device_extension_properties"]
|
||||
pub fn enumerate_device_extension_properties(
|
||||
physical_device: PhysicalDevice,
|
||||
p_layer_name: *const c_char,
|
||||
p_property_count: *mut u32,
|
||||
p_properties: *mut ExtensionProperties,
|
||||
) -> Result;
|
||||
|
||||
#[link_name = "vmm_vk_enumerate_device_layer_properties"]
|
||||
pub fn enumerate_device_layer_properties(
|
||||
physical_device: PhysicalDevice,
|
||||
p_property_count: *mut u32,
|
||||
p_properties: *mut LayerProperties,
|
||||
) -> Result;
|
||||
|
||||
#[link_name = "vmm_vk_enumerate_physical_device_groups"]
|
||||
pub fn enumerate_physical_device_groups(
|
||||
instance: Instance,
|
||||
p_physical_device_group_count: *mut u32,
|
||||
p_physical_device_group_properties: *mut PhysicalDeviceGroupProperties<'_>,
|
||||
) -> Result;
|
||||
|
||||
#[link_name = "vmm_vk_enumerate_physical_devices"]
|
||||
pub fn enumerate_physical_devices(
|
||||
instance: Instance,
|
||||
p_physical_device_count: *mut u32,
|
||||
p_physical_devices: *mut PhysicalDevice,
|
||||
) -> Result;
|
||||
|
||||
#[link_name = "vmm_vk_get_device_proc_addr"]
|
||||
pub fn get_device_proc_addr(device: Device, p_name: *const c_char) -> PFN_vkVoidFunction;
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_external_buffer_properties"]
|
||||
pub fn get_physical_device_external_buffer_properties(
|
||||
physical_device: PhysicalDevice,
|
||||
p_external_buffer_info: *const PhysicalDeviceExternalBufferInfo<'_>,
|
||||
p_external_buffer_properties: *mut ExternalBufferProperties<'_>,
|
||||
);
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_external_fence_properties"]
|
||||
pub fn get_physical_device_external_fence_properties(
|
||||
physical_device: PhysicalDevice,
|
||||
p_external_fence_info: *const PhysicalDeviceExternalFenceInfo<'_>,
|
||||
p_external_fence_properties: *mut ExternalFenceProperties<'_>,
|
||||
);
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_external_semaphore_properties"]
|
||||
pub fn get_physical_device_external_semaphore_properties(
|
||||
physical_device: PhysicalDevice,
|
||||
p_external_semaphore_info: *const PhysicalDeviceExternalSemaphoreInfo<'_>,
|
||||
p_external_semaphore_properties: *mut ExternalSemaphoreProperties<'_>,
|
||||
);
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_features"]
|
||||
pub fn get_physical_device_features(
|
||||
physical_device: PhysicalDevice,
|
||||
p_features: *mut PhysicalDeviceFeatures,
|
||||
);
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_features2"]
|
||||
pub fn get_physical_device_features2(
|
||||
physical_device: PhysicalDevice,
|
||||
p_features: *mut PhysicalDeviceFeatures2<'_>,
|
||||
);
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_format_properties"]
|
||||
pub fn get_physical_device_format_properties(
|
||||
physical_device: PhysicalDevice,
|
||||
format: Format,
|
||||
p_format_properties: *mut FormatProperties,
|
||||
);
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_format_properties2"]
|
||||
pub fn get_physical_device_format_properties2(
|
||||
physical_device: PhysicalDevice,
|
||||
format: Format,
|
||||
p_format_properties: *mut FormatProperties2<'_>,
|
||||
);
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_image_format_properties"]
|
||||
pub fn get_physical_device_image_format_properties(
|
||||
physical_device: PhysicalDevice,
|
||||
format: Format,
|
||||
ty: ImageType,
|
||||
tiling: ImageTiling,
|
||||
usage: ImageUsageFlags,
|
||||
flags: ImageCreateFlags,
|
||||
p_image_format_properties: *mut ImageFormatProperties,
|
||||
) -> Result;
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_image_format_properties2"]
|
||||
pub fn get_physical_device_image_format_properties2(
|
||||
physical_device: PhysicalDevice,
|
||||
p_image_format_info: *const PhysicalDeviceImageFormatInfo2<'_>,
|
||||
p_image_format_properties: *mut ImageFormatProperties2<'_>,
|
||||
) -> Result;
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_memory_properties"]
|
||||
pub fn get_physical_device_memory_properties(
|
||||
physical_device: PhysicalDevice,
|
||||
p_memory_properties: *mut PhysicalDeviceMemoryProperties,
|
||||
);
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_memory_properties2"]
|
||||
pub fn get_physical_device_memory_properties2(
|
||||
physical_device: PhysicalDevice,
|
||||
p_memory_properties: *mut PhysicalDeviceMemoryProperties2<'_>,
|
||||
);
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_properties"]
|
||||
pub fn get_physical_device_properties(
|
||||
physical_device: PhysicalDevice,
|
||||
p_properties: *mut PhysicalDeviceProperties,
|
||||
);
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_properties2"]
|
||||
pub fn get_physical_device_properties2(
|
||||
physical_device: PhysicalDevice,
|
||||
p_properties: *mut PhysicalDeviceProperties2<'_>,
|
||||
);
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_queue_family_properties"]
|
||||
pub fn get_physical_device_queue_family_properties(
|
||||
physical_device: PhysicalDevice,
|
||||
p_queue_family_property_count: *mut u32,
|
||||
p_queue_family_properties: *mut QueueFamilyProperties,
|
||||
);
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_queue_family_properties2"]
|
||||
pub fn get_physical_device_queue_family_properties2(
|
||||
physical_device: PhysicalDevice,
|
||||
p_queue_family_property_count: *mut u32,
|
||||
p_queue_family_properties: *mut QueueFamilyProperties2<'_>,
|
||||
);
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_sparse_image_format_properties"]
|
||||
pub fn get_physical_device_sparse_image_format_properties(
|
||||
physical_device: PhysicalDevice,
|
||||
format: Format,
|
||||
ty: ImageType,
|
||||
samples: SampleCountFlags,
|
||||
usage: ImageUsageFlags,
|
||||
tiling: ImageTiling,
|
||||
p_property_count: *mut u32,
|
||||
p_properties: *mut SparseImageFormatProperties,
|
||||
);
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_sparse_image_format_properties2"]
|
||||
pub fn get_physical_device_sparse_image_format_properties2(
|
||||
physical_device: PhysicalDevice,
|
||||
p_format_info: *const PhysicalDeviceSparseImageFormatInfo2<'_>,
|
||||
p_property_count: *mut u32,
|
||||
p_properties: *mut SparseImageFormatProperties2<'_>,
|
||||
);
|
||||
|
||||
#[link_name = "vmm_vk_get_physical_device_tool_properties"]
|
||||
pub fn get_physical_device_tool_properties(
|
||||
physical_device: PhysicalDevice,
|
||||
p_tool_count: *mut u32,
|
||||
p_tool_properties: *mut PhysicalDeviceToolProperties<'_>,
|
||||
) -> Result;
|
||||
}
|
@ -1,21 +1,86 @@
|
||||
use self::buffer::VulkanBuffer;
|
||||
use self::ffi::{
|
||||
create_device, enumerate_device_extension_properties, enumerate_device_layer_properties,
|
||||
enumerate_physical_device_groups, enumerate_physical_devices, get_device_proc_addr,
|
||||
get_physical_device_external_buffer_properties, get_physical_device_external_fence_properties,
|
||||
get_physical_device_external_semaphore_properties, get_physical_device_features,
|
||||
get_physical_device_features2, get_physical_device_format_properties,
|
||||
get_physical_device_format_properties2, get_physical_device_image_format_properties,
|
||||
get_physical_device_image_format_properties2, get_physical_device_memory_properties,
|
||||
get_physical_device_memory_properties2, get_physical_device_properties,
|
||||
get_physical_device_properties2, get_physical_device_queue_family_properties,
|
||||
get_physical_device_queue_family_properties2,
|
||||
get_physical_device_sparse_image_format_properties,
|
||||
get_physical_device_sparse_image_format_properties2, get_physical_device_tool_properties,
|
||||
};
|
||||
use super::{Screen, ScreenBuffer, VmmError};
|
||||
use crate::vmm::VmmScreen;
|
||||
use ash::vk::Handle;
|
||||
use ash::{Instance, InstanceFnV1_0, InstanceFnV1_1, InstanceFnV1_3};
|
||||
use std::sync::Arc;
|
||||
use thiserror::Error;
|
||||
|
||||
mod buffer;
|
||||
mod ffi;
|
||||
|
||||
/// Implementation of [`Screen`] using Vulkan.
|
||||
pub struct Vulkan {
|
||||
buffer: Arc<VulkanBuffer>,
|
||||
instance: Instance,
|
||||
}
|
||||
|
||||
impl Vulkan {
|
||||
pub fn new(surface: usize) -> Result<Self, VmmError> {
|
||||
pub fn new(screen: *const VmmScreen) -> Result<Self, VmmError> {
|
||||
// Wrap VkInstance.
|
||||
let instance = unsafe { (*screen).vk_instance.try_into().unwrap() };
|
||||
let instance = ash::vk::Instance::from_raw(instance);
|
||||
let instance = Instance::from_parts_1_3(
|
||||
instance,
|
||||
InstanceFnV1_0 {
|
||||
destroy_instance: Self::destroy_instance,
|
||||
enumerate_physical_devices,
|
||||
get_physical_device_features,
|
||||
get_physical_device_format_properties,
|
||||
get_physical_device_image_format_properties,
|
||||
get_physical_device_properties,
|
||||
get_physical_device_queue_family_properties,
|
||||
get_physical_device_memory_properties,
|
||||
get_device_proc_addr,
|
||||
create_device,
|
||||
enumerate_device_extension_properties,
|
||||
enumerate_device_layer_properties,
|
||||
get_physical_device_sparse_image_format_properties,
|
||||
},
|
||||
InstanceFnV1_1 {
|
||||
enumerate_physical_device_groups,
|
||||
get_physical_device_features2,
|
||||
get_physical_device_properties2,
|
||||
get_physical_device_format_properties2,
|
||||
get_physical_device_image_format_properties2,
|
||||
get_physical_device_queue_family_properties2,
|
||||
get_physical_device_memory_properties2,
|
||||
get_physical_device_sparse_image_format_properties2,
|
||||
get_physical_device_external_buffer_properties,
|
||||
get_physical_device_external_fence_properties,
|
||||
get_physical_device_external_semaphore_properties,
|
||||
},
|
||||
InstanceFnV1_3 {
|
||||
get_physical_device_tool_properties,
|
||||
},
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
buffer: Arc::new(VulkanBuffer::new()),
|
||||
instance,
|
||||
})
|
||||
}
|
||||
|
||||
unsafe extern "system" fn destroy_instance(
|
||||
_: ash::vk::Instance,
|
||||
_: *const ash::vk::AllocationCallbacks<'_>,
|
||||
) {
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
|
||||
impl Screen for Vulkan {
|
||||
|
@ -2,10 +2,14 @@
|
||||
#include "main_window.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "system.hpp"
|
||||
#ifndef __APPLE__
|
||||
#include "vulkan.hpp"
|
||||
#endif
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
#ifndef __APPLE__
|
||||
#include <QVersionNumber>
|
||||
#include <QVulkanInstance>
|
||||
#endif
|
||||
|
||||
@ -48,6 +52,8 @@ int main(int argc, char *argv[])
|
||||
#ifndef __APPLE__
|
||||
QVulkanInstance vulkan;
|
||||
|
||||
vulkan.setApiVersion(QVersionNumber(1, 3));
|
||||
|
||||
if (!vulkan.create()) {
|
||||
QMessageBox::critical(
|
||||
nullptr,
|
||||
@ -55,6 +61,8 @@ int main(int argc, char *argv[])
|
||||
QString("Failed to initialize Vulkan (%1)").arg(vulkan.errorCode()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
vkFunctions = vulkan.functions();
|
||||
#endif
|
||||
|
||||
// Check if no any required settings.
|
||||
|
@ -32,6 +32,8 @@
|
||||
#include <filesystem>
|
||||
#include <utility>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
MainWindow::MainWindow() :
|
||||
#else
|
||||
@ -307,20 +309,33 @@ void MainWindow::startKernel()
|
||||
#endif
|
||||
}
|
||||
|
||||
// Swap launch settings with the screen before getting a Vulkan surface otherwise it will fail.
|
||||
m_main->setCurrentIndex(1);
|
||||
|
||||
// Run.
|
||||
size_t screen;
|
||||
VmmScreen screen;
|
||||
Rust<RustError> error;
|
||||
Rust<Vmm> vmm;
|
||||
|
||||
memset(&screen, 0, sizeof(screen));
|
||||
|
||||
#ifdef __APPLE__
|
||||
screen = m_screen->winId();
|
||||
screen.view = m_screen->winId();
|
||||
#else
|
||||
screen = reinterpret_cast<size_t>(m_screen->vulkanInstance()->vkInstance());
|
||||
screen.vk_instance = reinterpret_cast<size_t>(m_screen->vulkanInstance()->vkInstance());
|
||||
screen.vk_surface = reinterpret_cast<size_t>(QVulkanInstance::surfaceForWindow(m_screen));
|
||||
|
||||
if (!screen.vk_surface) {
|
||||
m_main->setCurrentIndex(0);
|
||||
QMessageBox::critical(this, "Error", "Couldn't create VkSurfaceKHR.");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
vmm = vmm_run(kernel.c_str(), screen, &error);
|
||||
vmm = vmm_run(kernel.c_str(), &screen, &error);
|
||||
|
||||
if (!vmm) {
|
||||
m_main->setCurrentIndex(0);
|
||||
QMessageBox::critical(
|
||||
this,
|
||||
"Error",
|
||||
@ -329,9 +344,6 @@ void MainWindow::startKernel()
|
||||
}
|
||||
|
||||
m_kernel = std::move(vmm);
|
||||
|
||||
// Swap launch settings with the screen and start drawing loop.
|
||||
m_main->setCurrentIndex(1);
|
||||
m_screen->requestUpdate();
|
||||
}
|
||||
|
||||
|
253
src/vulkan.cpp
Normal file
253
src/vulkan.cpp
Normal file
@ -0,0 +1,253 @@
|
||||
#include "vulkan.hpp"
|
||||
|
||||
#include <QVulkanFunctions>
|
||||
|
||||
QVulkanFunctions *vkFunctions;
|
||||
|
||||
extern "C" VkResult vmm_vk_enumerate_physical_devices(
|
||||
VkInstance instance,
|
||||
uint32_t *p_physical_device_count,
|
||||
VkPhysicalDevice *p_physical_devices)
|
||||
{
|
||||
return vkFunctions->vkEnumeratePhysicalDevices(
|
||||
instance,
|
||||
p_physical_device_count,
|
||||
p_physical_devices);
|
||||
}
|
||||
|
||||
extern "C" void vmm_vk_get_physical_device_features(
|
||||
VkPhysicalDevice physical_device,
|
||||
VkPhysicalDeviceFeatures *p_features)
|
||||
{
|
||||
vkFunctions->vkGetPhysicalDeviceFeatures(physical_device, p_features);
|
||||
}
|
||||
|
||||
extern "C" void vmm_vk_get_physical_device_format_properties(
|
||||
VkPhysicalDevice physical_device,
|
||||
VkFormat format,
|
||||
VkFormatProperties *p_format_properties)
|
||||
{
|
||||
vkFunctions->vkGetPhysicalDeviceFormatProperties(physical_device, format, p_format_properties);
|
||||
}
|
||||
|
||||
extern "C" VkResult vmm_vk_get_physical_device_image_format_properties(
|
||||
VkPhysicalDevice physical_device,
|
||||
VkFormat format,
|
||||
VkImageType ty,
|
||||
VkImageTiling tiling,
|
||||
VkImageUsageFlags usage,
|
||||
VkImageCreateFlags flags,
|
||||
VkImageFormatProperties *p_image_format_properties)
|
||||
{
|
||||
return vkFunctions->vkGetPhysicalDeviceImageFormatProperties(
|
||||
physical_device,
|
||||
format,
|
||||
ty,
|
||||
tiling,
|
||||
usage,
|
||||
flags,
|
||||
p_image_format_properties);
|
||||
}
|
||||
|
||||
extern "C" void vmm_vk_get_physical_device_properties(
|
||||
VkPhysicalDevice physical_device,
|
||||
VkPhysicalDeviceProperties *p_properties)
|
||||
{
|
||||
vkFunctions->vkGetPhysicalDeviceProperties(physical_device, p_properties);
|
||||
}
|
||||
|
||||
extern "C" void vmm_vk_get_physical_device_queue_family_properties(
|
||||
VkPhysicalDevice physical_device,
|
||||
uint32_t *p_queue_family_property_count,
|
||||
VkQueueFamilyProperties *p_queue_family_properties)
|
||||
{
|
||||
vkFunctions->vkGetPhysicalDeviceQueueFamilyProperties(
|
||||
physical_device,
|
||||
p_queue_family_property_count,
|
||||
p_queue_family_properties);
|
||||
}
|
||||
|
||||
extern "C" void vmm_vk_get_physical_device_memory_properties(
|
||||
VkPhysicalDevice physical_device,
|
||||
VkPhysicalDeviceMemoryProperties *p_memory_properties)
|
||||
{
|
||||
vkFunctions->vkGetPhysicalDeviceMemoryProperties(physical_device, p_memory_properties);
|
||||
}
|
||||
|
||||
extern "C" PFN_vkVoidFunction vmm_vk_get_device_proc_addr(VkDevice device, const char *p_name)
|
||||
{
|
||||
return vkFunctions->vkGetDeviceProcAddr(device, p_name);
|
||||
}
|
||||
|
||||
extern "C" VkResult vmm_vk_create_device(
|
||||
VkPhysicalDevice physical_device,
|
||||
const VkDeviceCreateInfo *p_create_info,
|
||||
const VkAllocationCallbacks *p_allocator,
|
||||
VkDevice *p_device)
|
||||
{
|
||||
return vkFunctions->vkCreateDevice(physical_device, p_create_info, p_allocator, p_device);
|
||||
}
|
||||
|
||||
extern "C" VkResult vmm_vk_enumerate_device_extension_properties(
|
||||
VkPhysicalDevice physical_device,
|
||||
const char *p_layer_name,
|
||||
uint32_t *p_property_count,
|
||||
VkExtensionProperties *p_properties)
|
||||
{
|
||||
return vkFunctions->vkEnumerateDeviceExtensionProperties(
|
||||
physical_device,
|
||||
p_layer_name,
|
||||
p_property_count,
|
||||
p_properties);
|
||||
}
|
||||
|
||||
extern "C" VkResult vmm_vk_enumerate_device_layer_properties(
|
||||
VkPhysicalDevice physical_device,
|
||||
uint32_t *p_property_count,
|
||||
VkLayerProperties *p_properties)
|
||||
{
|
||||
return vkFunctions->vkEnumerateDeviceLayerProperties(
|
||||
physical_device,
|
||||
p_property_count,
|
||||
p_properties);
|
||||
}
|
||||
|
||||
extern "C" void vmm_vk_get_physical_device_sparse_image_format_properties(
|
||||
VkPhysicalDevice physical_device,
|
||||
VkFormat format,
|
||||
VkImageType ty,
|
||||
VkSampleCountFlagBits samples,
|
||||
VkImageUsageFlags usage,
|
||||
VkImageTiling tiling,
|
||||
uint32_t *p_property_count,
|
||||
VkSparseImageFormatProperties *p_properties)
|
||||
{
|
||||
vkFunctions->vkGetPhysicalDeviceSparseImageFormatProperties(
|
||||
physical_device,
|
||||
format,
|
||||
ty,
|
||||
samples,
|
||||
usage,
|
||||
tiling,
|
||||
p_property_count,
|
||||
p_properties);
|
||||
}
|
||||
|
||||
extern "C" VkResult vmm_vk_enumerate_physical_device_groups(
|
||||
VkInstance instance,
|
||||
uint32_t *p_physical_device_group_count,
|
||||
VkPhysicalDeviceGroupProperties *p_physical_device_group_properties)
|
||||
{
|
||||
return vkFunctions->vkEnumeratePhysicalDeviceGroups(
|
||||
instance,
|
||||
p_physical_device_group_count,
|
||||
p_physical_device_group_properties);
|
||||
}
|
||||
|
||||
extern "C" void vmm_vk_get_physical_device_features2(
|
||||
VkPhysicalDevice physical_device,
|
||||
VkPhysicalDeviceFeatures2 *p_features)
|
||||
{
|
||||
vkFunctions->vkGetPhysicalDeviceFeatures2(physical_device, p_features);
|
||||
}
|
||||
|
||||
extern "C" void vmm_vk_get_physical_device_properties2(
|
||||
VkPhysicalDevice physical_device,
|
||||
VkPhysicalDeviceProperties2 *p_properties)
|
||||
{
|
||||
vkFunctions->vkGetPhysicalDeviceProperties2(physical_device, p_properties);
|
||||
}
|
||||
|
||||
extern "C" void vmm_vk_get_physical_device_format_properties2(
|
||||
VkPhysicalDevice physical_device,
|
||||
VkFormat format,
|
||||
VkFormatProperties2 *p_format_properties)
|
||||
{
|
||||
vkFunctions->vkGetPhysicalDeviceFormatProperties2(physical_device, format, p_format_properties);
|
||||
}
|
||||
|
||||
extern "C" VkResult vmm_vk_get_physical_device_image_format_properties2(
|
||||
VkPhysicalDevice physical_device,
|
||||
const VkPhysicalDeviceImageFormatInfo2 *p_image_format_info,
|
||||
VkImageFormatProperties2 *p_image_format_properties)
|
||||
{
|
||||
return vkFunctions->vkGetPhysicalDeviceImageFormatProperties2(
|
||||
physical_device,
|
||||
p_image_format_info,
|
||||
p_image_format_properties);
|
||||
}
|
||||
|
||||
extern "C" void vmm_vk_get_physical_device_queue_family_properties2(
|
||||
VkPhysicalDevice physical_device,
|
||||
uint32_t *p_queue_family_property_count,
|
||||
VkQueueFamilyProperties2 *p_queue_family_properties)
|
||||
{
|
||||
vkFunctions->vkGetPhysicalDeviceQueueFamilyProperties2(
|
||||
physical_device,
|
||||
p_queue_family_property_count,
|
||||
p_queue_family_properties);
|
||||
}
|
||||
|
||||
extern "C" void vmm_vk_get_physical_device_memory_properties2(
|
||||
VkPhysicalDevice physical_device,
|
||||
VkPhysicalDeviceMemoryProperties2 *p_memory_properties)
|
||||
{
|
||||
vkFunctions->vkGetPhysicalDeviceMemoryProperties2(physical_device, p_memory_properties);
|
||||
}
|
||||
|
||||
extern "C" void vmm_vk_get_physical_device_sparse_image_format_properties2(
|
||||
VkPhysicalDevice physical_device,
|
||||
const VkPhysicalDeviceSparseImageFormatInfo2 *p_format_info,
|
||||
uint32_t *p_property_count,
|
||||
VkSparseImageFormatProperties2 *p_properties)
|
||||
{
|
||||
vkFunctions->vkGetPhysicalDeviceSparseImageFormatProperties2(
|
||||
physical_device,
|
||||
p_format_info,
|
||||
p_property_count,
|
||||
p_properties);
|
||||
}
|
||||
|
||||
extern "C" void vmm_vk_get_physical_device_external_buffer_properties(
|
||||
VkPhysicalDevice physical_device,
|
||||
const VkPhysicalDeviceExternalBufferInfo *p_external_buffer_info,
|
||||
VkExternalBufferProperties *p_external_buffer_properties)
|
||||
{
|
||||
vkFunctions->vkGetPhysicalDeviceExternalBufferProperties(
|
||||
physical_device,
|
||||
p_external_buffer_info,
|
||||
p_external_buffer_properties);
|
||||
}
|
||||
|
||||
extern "C" void vmm_vk_get_physical_device_external_fence_properties(
|
||||
VkPhysicalDevice physical_device,
|
||||
const VkPhysicalDeviceExternalFenceInfo *p_external_fence_info,
|
||||
VkExternalFenceProperties *p_external_fence_properties)
|
||||
{
|
||||
vkFunctions->vkGetPhysicalDeviceExternalFenceProperties(
|
||||
physical_device,
|
||||
p_external_fence_info,
|
||||
p_external_fence_properties);
|
||||
}
|
||||
|
||||
extern "C" void vmm_vk_get_physical_device_external_semaphore_properties(
|
||||
VkPhysicalDevice physical_device,
|
||||
const VkPhysicalDeviceExternalSemaphoreInfo *p_external_semaphore_info,
|
||||
VkExternalSemaphoreProperties *p_external_semaphore_properties)
|
||||
{
|
||||
vkFunctions->vkGetPhysicalDeviceExternalSemaphoreProperties(
|
||||
physical_device,
|
||||
p_external_semaphore_info,
|
||||
p_external_semaphore_properties);
|
||||
}
|
||||
|
||||
extern "C" VkResult vmm_vk_get_physical_device_tool_properties(
|
||||
VkPhysicalDevice physical_device,
|
||||
uint32_t *p_tool_count,
|
||||
VkPhysicalDeviceToolProperties *p_tool_properties)
|
||||
{
|
||||
return vkFunctions->vkGetPhysicalDeviceToolProperties(
|
||||
physical_device,
|
||||
p_tool_count,
|
||||
p_tool_properties);
|
||||
}
|
5
src/vulkan.hpp
Normal file
5
src/vulkan.hpp
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
class QVulkanFunctions;
|
||||
|
||||
extern QVulkanFunctions *vkFunctions;
|
Loading…
Reference in New Issue
Block a user