Skip to content

Commit bb6c6c7

Browse files
Support for Metal backend.
Co-authored-by: Isaac Marovitz <isaacryu@icloud.com>
1 parent 990829a commit bb6c6c7

72 files changed

Lines changed: 1158 additions & 132 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@
5757
url = https://github.com/KhronosGroup/SPIRV-Cross.git
5858
[submodule "thirdparty/plume"]
5959
path = thirdparty/plume
60-
url = https://github.com/squidbus/plume
60+
url = https://github.com/renderbag/plume

MarathonRecomp/CMakeLists.txt

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ if (WIN32)
44
option(MARATHON_RECOMP_D3D12 "Add D3D12 support for rendering" ON)
55
endif()
66

7+
if (APPLE)
8+
option(MARATHON_RECOMP_METAL "Add Metal support for rendering" ON)
9+
endif()
10+
711
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
812
option(MARATHON_RECOMP_FLATPAK "Configure the build for Flatpak compatibility." OFF)
913
endif()
@@ -259,6 +263,10 @@ if (NOT ${CMAKE_BUILD_TYPE} MATCHES "Release")
259263
set(SHOW_GIT_INFO_AND_BUILD_TYPE 1)
260264
endif()
261265

266+
if (MARATHON_RECOMP_METAL)
267+
set(XCRUN_TOOL "/usr/bin/xcrun")
268+
endif()
269+
262270
GenerateVersionSources(
263271
OUTPUT_DIR ${PROJECT_SOURCE_DIR}
264272
VERSION_TXT ${VERSION_TXT}
@@ -362,6 +370,10 @@ if (MARATHON_RECOMP_D3D12)
362370
target_compile_definitions(MarathonRecomp PRIVATE MARATHON_RECOMP_D3D12)
363371
endif()
364372

373+
if (MARATHON_RECOMP_METAL)
374+
target_compile_definitions(MarathonRecomp PRIVATE MARATHON_RECOMP_METAL)
375+
endif()
376+
365377
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
366378
target_compile_definitions(MarathonRecomp PRIVATE SDL_VULKAN_ENABLED)
367379
endif()
@@ -438,22 +450,37 @@ endif()
438450
target_precompile_headers(MarathonRecomp PUBLIC ${MARATHON_RECOMP_PRECOMPILED_HEADERS})
439451

440452
function(compile_shader FILE_PATH TARGET_NAME)
441-
set(FILE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/gpu/shader/${FILE_PATH}.hlsl)
442-
cmake_path(GET FILE_PATH STEM VARIABLE_NAME)
453+
set(HLSL_FILE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/gpu/shader/hlsl/${FILE_PATH}.hlsl)
454+
set(MSL_FILE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/gpu/shader/msl/${FILE_PATH}.metal)
455+
cmake_path(GET HLSL_FILE_PATH STEM HLSL_NAME)
456+
cmake_path(GET MSL_FILE_PATH STEM MSL_NAME)
457+
if (MARATHON_RECOMP_METAL)
458+
add_custom_command(
459+
OUTPUT ${MSL_FILE_PATH}.ir
460+
COMMAND ${XCRUN_TOOL} -sdk macosx metal -o ${MSL_FILE_PATH}.ir -c ${MSL_FILE_PATH} -D__air__ -frecord-sources -gline-tables-only
461+
DEPENDS ${MSL_FILE_PATH}
462+
)
463+
add_custom_command(
464+
OUTPUT ${MSL_FILE_PATH}.metallib
465+
COMMAND ${XCRUN_TOOL} -sdk macosx metallib -o ${MSL_FILE_PATH}.metallib ${MSL_FILE_PATH}.ir
466+
DEPENDS ${MSL_FILE_PATH}.ir
467+
)
468+
BIN2C(TARGET_OBJ MarathonRecomp SOURCE_FILE "${MSL_FILE_PATH}.metallib" DEST_FILE "${MSL_FILE_PATH}.metallib" ARRAY_NAME "g_${MSL_NAME}_air")
469+
endif()
443470
if (MARATHON_RECOMP_D3D12)
444471
add_custom_command(
445-
OUTPUT ${FILE_PATH}.dxil.h
446-
COMMAND ${DIRECTX_DXC_TOOL} -T ${TARGET_NAME} -HV 2021 -all-resources-bound -Wno-ignored-attributes -Fh ${FILE_PATH}.dxil.h ${FILE_PATH} -Vn g_${VARIABLE_NAME}_dxil
447-
DEPENDS ${FILE_PATH}
472+
OUTPUT ${HLSL_FILE_PATH}.dxil.h
473+
COMMAND ${DIRECTX_DXC_TOOL} -T ${TARGET_NAME} -HV 2021 -all-resources-bound -Wno-ignored-attributes -Fh ${HLSL_FILE_PATH}.dxil.h ${HLSL_FILE_PATH} -Vn g_${HLSL_NAME}_dxil
474+
DEPENDS ${HLSL_FILE_PATH}
448475
)
449-
target_sources(MarathonRecomp PRIVATE ${FILE_PATH}.dxil.h)
476+
target_sources(MarathonRecomp PRIVATE ${HLSL_FILE_PATH}.dxil.h)
450477
endif()
451478
add_custom_command(
452-
OUTPUT ${FILE_PATH}.spirv.h
453-
COMMAND ${DIRECTX_DXC_TOOL} -T ${TARGET_NAME} -HV 2021 -all-resources-bound -spirv -fvk-use-dx-layout ${ARGN} -Fh ${FILE_PATH}.spirv.h ${FILE_PATH} -Vn g_${VARIABLE_NAME}_spirv
454-
DEPENDS ${FILE_PATH}
479+
OUTPUT ${HLSL_FILE_PATH}.spirv.h
480+
COMMAND ${DIRECTX_DXC_TOOL} -T ${TARGET_NAME} -HV 2021 -all-resources-bound -spirv -fvk-use-dx-layout ${ARGN} -Fh ${HLSL_FILE_PATH}.spirv.h ${HLSL_FILE_PATH} -Vn g_${HLSL_NAME}_spirv
481+
DEPENDS ${HLSL_FILE_PATH}
455482
)
456-
target_sources(MarathonRecomp PRIVATE ${FILE_PATH}.spirv.h)
483+
target_sources(MarathonRecomp PRIVATE ${HLSL_FILE_PATH}.spirv.h)
457484
endfunction()
458485

459486
function(compile_vertex_shader FILE_PATH)

MarathonRecomp/gpu/imgui/imgui_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define IMGUI_SHADER_MODIFIER_RECTANGLE_BEVEL 7
1111
#define IMGUI_SHADER_MODIFIER_LOW_QUALITY_TEXT 8
1212

13-
#ifdef __cplusplus
13+
#if defined(__cplusplus) && !defined(__air__)
1414

1515
enum class ImGuiCallback : int32_t
1616
{

MarathonRecomp/gpu/shader/blend_color_alpha_ps.hlsl renamed to MarathonRecomp/gpu/shader/hlsl/blend_color_alpha_ps.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
1+
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
22

33
#ifdef __spirv__
44

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

MarathonRecomp/gpu/shader/csd_filter_ps.hlsl renamed to MarathonRecomp/gpu/shader/hlsl/csd_filter_ps.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
1+
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
22

33
#ifdef __spirv__
44

0 commit comments

Comments
 (0)