Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,6 @@ jobs:
token: ${{ secrets.ASSET_REPO_TOKEN }}
path: ./private

- name: Setup latest Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable

- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
url = https://github.com/redorav/ddspp.git
[submodule "tools/XenosRecomp"]
path = tools/XenosRecomp
url = https://github.com/hedge-dev/XenosRecomp.git
url = https://github.com/squidbus/XenosRecomp.git
[submodule "UnleashedRecompResources"]
path = UnleashedRecompResources
url = https://github.com/hedge-dev/UnleashedRecompResources.git
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ if (UNLEASHED_RECOMP_ARCHITECTURE STREQUAL "x86_64" OR UNLEASHED_RECOMP_ARCHITEC
)
endif()

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# Normally only defined by Visual Studio, added for consistency
add_compile_definitions(_DEBUG)
endif()

add_subdirectory(${UNLEASHED_RECOMP_THIRDPARTY_ROOT})
add_subdirectory(${UNLEASHED_RECOMP_TOOLS_ROOT})

Expand Down
47 changes: 37 additions & 10 deletions UnleashedRecomp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ if (WIN32)
option(UNLEASHED_RECOMP_D3D12 "Add D3D12 support for rendering" ON)
endif()

if (APPLE)
option(UNLEASHED_RECOMP_METAL "Add Metal support for rendering" ON)
endif()

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
option(UNLEASHED_RECOMP_FLATPAK "Configure the build for Flatpak compatibility." OFF)
endif()
Expand Down Expand Up @@ -255,6 +259,10 @@ if (NOT ${CMAKE_BUILD_TYPE} MATCHES "Release")
set(SHOW_GIT_INFO_AND_BUILD_TYPE 1)
endif()

if (UNLEASHED_RECOMP_METAL)
set(XCRUN_TOOL "/usr/bin/xcrun")
endif()

GenerateVersionSources(
OUTPUT_DIR ${PROJECT_SOURCE_DIR}
VERSION_TXT ${VERSION_TXT}
Expand Down Expand Up @@ -375,6 +383,10 @@ if (UNLEASHED_RECOMP_D3D12)
)
endif()

if (UNLEASHED_RECOMP_METAL)
target_compile_definitions(UnleashedRecomp PRIVATE UNLEASHED_RECOMP_METAL)
endif()

if (WIN32)
target_link_libraries(UnleashedRecomp PRIVATE
comctl32
Expand Down Expand Up @@ -418,22 +430,37 @@ endif()
target_precompile_headers(UnleashedRecomp PUBLIC ${UNLEASHED_RECOMP_PRECOMPILED_HEADERS})

function(compile_shader FILE_PATH TARGET_NAME)
set(FILE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/gpu/shader/${FILE_PATH}.hlsl)
cmake_path(GET FILE_PATH STEM VARIABLE_NAME)
set(HLSL_FILE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/gpu/shader/hlsl/${FILE_PATH}.hlsl)
set(MSL_FILE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/gpu/shader/msl/${FILE_PATH}.metal)
cmake_path(GET HLSL_FILE_PATH STEM HLSL_NAME)
cmake_path(GET MSL_FILE_PATH STEM MSL_NAME)
if (UNLEASHED_RECOMP_METAL)
add_custom_command(
OUTPUT ${MSL_FILE_PATH}.ir
COMMAND ${XCRUN_TOOL} -sdk macosx metal -o ${MSL_FILE_PATH}.ir -c ${MSL_FILE_PATH} -D__air__ -frecord-sources -gline-tables-only
DEPENDS ${MSL_FILE_PATH}
)
add_custom_command(
OUTPUT ${MSL_FILE_PATH}.metallib
COMMAND ${XCRUN_TOOL} -sdk macosx metallib -o ${MSL_FILE_PATH}.metallib ${MSL_FILE_PATH}.ir
DEPENDS ${MSL_FILE_PATH}.ir
)
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${MSL_FILE_PATH}.metallib" DEST_FILE "${MSL_FILE_PATH}.metallib" ARRAY_NAME "g_${MSL_NAME}_air")
endif()
if (UNLEASHED_RECOMP_D3D12)
add_custom_command(
OUTPUT ${FILE_PATH}.dxil.h
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
DEPENDS ${FILE_PATH}
OUTPUT ${HLSL_FILE_PATH}.dxil.h
COMMAND ${DIRECTX_DXC_TOOL} -T ${TARGET_NAME} -HV 2021 -all-resources-bound -Wno-ignored-attributes -E shaderMain -Fh ${HLSL_FILE_PATH}.dxil.h ${HLSL_FILE_PATH} -Vn g_${HLSL_NAME}_dxil
DEPENDS ${HLSL_FILE_PATH}
)
target_sources(UnleashedRecomp PRIVATE ${FILE_PATH}.dxil.h)
target_sources(UnleashedRecomp PRIVATE ${HLSL_FILE_PATH}.dxil.h)
endif()
add_custom_command(
OUTPUT ${FILE_PATH}.spirv.h
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
DEPENDS ${FILE_PATH}
OUTPUT ${HLSL_FILE_PATH}.spirv.h
COMMAND ${DIRECTX_DXC_TOOL} -T ${TARGET_NAME} -HV 2021 -all-resources-bound -spirv -fvk-use-dx-layout ${ARGN} -E shaderMain -Fh ${HLSL_FILE_PATH}.spirv.h ${HLSL_FILE_PATH} -Vn g_${HLSL_NAME}_spirv
DEPENDS ${HLSL_FILE_PATH}
)
target_sources(UnleashedRecomp PRIVATE ${FILE_PATH}.spirv.h)
target_sources(UnleashedRecomp PRIVATE ${HLSL_FILE_PATH}.spirv.h)
endfunction()

function(compile_vertex_shader FILE_PATH)
Expand Down
2 changes: 1 addition & 1 deletion UnleashedRecomp/gpu/imgui/imgui_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define IMGUI_SHADER_MODIFIER_RECTANGLE_BEVEL 10
#define IMGUI_SHADER_MODIFIER_LOW_QUALITY_TEXT 11

#ifdef __cplusplus
#if defined(__cplusplus) && !defined(__air__)

enum class ImGuiCallback : int32_t
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"

#ifdef __spirv__

Expand All @@ -22,7 +22,7 @@ cbuffer SharedConstants : register(b2, space4)

#endif

float4 main(
float4 shaderMain(
in float4 iPos : SV_Position,
in float4 iTexCoord0 : TEXCOORD0) : SV_Target0
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Texture2D<float4> g_Texture2DDescriptorHeap[] : register(t0, space0);

float4 main(in float4 position : SV_Position) : SV_Target
float4 shaderMain(in float4 position : SV_Position) : SV_Target
{
return g_Texture2DDescriptorHeap[g_PushConstants.ResourceDescriptorIndex].Load(int3(position.xy, 0));
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Texture2D<float> g_Texture2DDescriptorHeap[] : register(t0, space0);

float main(in float4 position : SV_Position) : SV_Depth
float shaderMain(in float4 position : SV_Position) : SV_Depth
{
return g_Texture2DDescriptorHeap[g_PushConstants.ResourceDescriptorIndex].Load(int3(position.xy, 0));
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void main(in uint vertexId : SV_VertexID, out float4 position : SV_Position, out float2 texCoord : TEXCOORD)
void shaderMain(in uint vertexId : SV_VertexID, out float4 position : SV_Position, out float2 texCoord : TEXCOORD)
{
texCoord = float2((vertexId << 1) & 2, vertexId & 2);
position = float4(texCoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"

#ifdef __spirv__

Expand All @@ -16,7 +16,7 @@ cbuffer SharedConstants : register(b2, space4)

#endif

float4 main(
float4 shaderMain(
in float4 iPosition : SV_Position,
in float4 iTexCoord0 : TEXCOORD0,
in float4 iTexCoord1 : TEXCOORD1) : SV_Target
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"

#ifdef __spirv__

Expand All @@ -20,7 +20,7 @@ cbuffer SharedConstants : register(b2, space4)

#endif

void main(
void shaderMain(
[[vk::location(0)]] in float4 iPosition0 : POSITION0,
[[vk::location(8)]] in float4 iColor0 : COLOR0,
out float4 oPos : SV_Position,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"

#ifdef __spirv__

Expand All @@ -20,7 +20,7 @@ cbuffer SharedConstants : register(b2, space4)

#endif

void main(
void shaderMain(
[[vk::location(0)]] in float4 iPosition0 : POSITION0,
[[vk::location(8)]] in float4 iColor0 : COLOR0,
[[vk::location(4)]] in float4 iTexCoord0 : TEXCOORD0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"

#ifdef __spirv__

Expand Down Expand Up @@ -38,7 +38,7 @@ cbuffer SharedConstants : register(b2, space4)

#endif

float4 main(in float4 position : SV_Position, in float4 texCoord : TEXCOORD0) : SV_Target
float4 shaderMain(in float4 position : SV_Position, in float4 texCoord : TEXCOORD0) : SV_Target
{
Texture2D<float4> sampColor = g_Texture2DDescriptorHeap[sampColor_Texture2DDescriptorIndex];
Texture2D<float4> sampVelocityMap = g_Texture2DDescriptorHeap[sampVelocityMap_Texture2DDescriptorIndex];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"

#ifdef __spirv__

Expand All @@ -20,7 +20,7 @@ cbuffer SharedConstants : register(b2, space4)

#endif

float4 main(in float4 position : SV_Position) : SV_Target
float4 shaderMain(in float4 position : SV_Position) : SV_Target
{
Texture2D<float4> texture = g_Texture2DDescriptorHeap[g_TextureDescriptorIndex];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"

#ifdef __spirv__

Expand Down Expand Up @@ -40,7 +40,7 @@ float ComputeWeight(float x)
return exp(-(x * x) / (2.0 * std * std)) / (std * sqrt(2.0 * PI));
}

float4 main(in float4 iPosition : SV_Position, in float4 iTexCoord0 : TEXCOORD0) : SV_Target
float4 shaderMain(in float4 iPosition : SV_Position, in float4 iTexCoord0 : TEXCOORD0) : SV_Target
{
Texture2D<float4> texture = g_Texture2DDescriptorHeap[s0_Texture2DDescriptorIndex];
SamplerState samplerState = g_SamplerDescriptorHeap[s0_SamplerDescriptorIndex];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "../imgui/imgui_common.h"
#include "../../imgui/imgui_common.h"

struct PushConstants
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ float4 SampleSdfFont(float4 color, Texture2D<float4> texture, float2 uv, float2
return color;
}

float4 main(in Interpolators interpolators) : SV_Target
float4 shaderMain(in Interpolators interpolators) : SV_Target
{
float4 color = interpolators.Color;
color *= PixelAntialiasing(interpolators.Position.xy - g_PushConstants.ProceduralOrigin);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "imgui_common.hlsli"

void main(in float2 position : POSITION, in float2 uv : TEXCOORD, in float4 color : COLOR, out Interpolators interpolators)
void shaderMain(in float2 position : POSITION, in float2 uv : TEXCOORD, in float4 color : COLOR, out Interpolators interpolators)
{
if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_TEXT_SKEW)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"

#ifdef __spirv__

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "movie_common.hlsli"

PixelShaderOutput main(in Interpolators In)
PixelShaderOutput shaderMain(in Interpolators In)
{
Texture2D<float4> Tex0 = g_Texture2DDescriptorHeap[Tex0_ResourceDescriptorIndex];
Texture2D<float4> Tex1 = g_Texture2DDescriptorHeap[Tex1_ResourceDescriptorIndex];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "movie_common.hlsli"

Interpolators main(in VertexShaderInput In)
Interpolators shaderMain(in VertexShaderInput In)
{
Interpolators Out;
Out.ProjPos = In.ObjPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Texture2DMS<float4, SAMPLE_COUNT> g_Texture2DMSDescriptorHeap[] : register(t0, space0);

float4 main(in float4 position : SV_Position) : SV_Target
float4 shaderMain(in float4 position : SV_Position) : SV_Target
{
float4 result = g_Texture2DMSDescriptorHeap[g_PushConstants.ResourceDescriptorIndex].Load(int2(position.xy), 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Texture2DMS<float, SAMPLE_COUNT> g_Texture2DMSDescriptorHeap[] : register(t0, space0);

float main(in float4 position : SV_Position) : SV_Depth
float shaderMain(in float4 position : SV_Position) : SV_Depth
{
float result = g_Texture2DMSDescriptorHeap[g_PushConstants.ResourceDescriptorIndex].Load(int2(position.xy), 0);

Expand Down
4 changes: 4 additions & 0 deletions UnleashedRecomp/gpu/shader/msl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.ir
*.metallib
*.metal.*.c
*.metal.*.h
31 changes: 31 additions & 0 deletions UnleashedRecomp/gpu/shader/msl/blend_color_alpha_ps.metal
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"

#define g_SrcAlpha_DestAlpha (*(reinterpret_cast<device float4*>(g_PushConstants.PixelShaderConstants + 2400)))
#define s0_Texture2DDescriptorIndex (*(reinterpret_cast<device uint*>(g_PushConstants.SharedConstants + 0)))
#define s0_SamplerDescriptorIndex (*(reinterpret_cast<device uint*>(g_PushConstants.SharedConstants + 192)))

struct Interpolators
{
float4 iTexCoord0 [[user(TEXCOORD0)]];
};

[[fragment]]
float4 shaderMain(float4 iPos [[position]],
Interpolators input [[stage_in]],
constant Texture2DDescriptorHeap* g_Texture2DDescriptorHeap [[buffer(0)]],
constant SamplerDescriptorHeap* g_SamplerDescriptorHeap [[buffer(3)]],
constant PushConstants& g_PushConstants [[buffer(8)]])
{
texture2d<float> texture = g_Texture2DDescriptorHeap[s0_Texture2DDescriptorIndex].tex;
sampler samplerState = g_SamplerDescriptorHeap[s0_SamplerDescriptorIndex].samp;

float4 color = texture.sample(samplerState, input.iTexCoord0.xy);

if (any(input.iTexCoord0.xy < 0.0 || input.iTexCoord0.xy > 1.0))
color = float4(0.0, 0.0, 0.0, 1.0);

color.rgb *= color.a * g_SrcAlpha_DestAlpha.x;
color.a = g_SrcAlpha_DestAlpha.y + (1.0 - color.a) * g_SrcAlpha_DestAlpha.x;

return color;
}
14 changes: 14 additions & 0 deletions UnleashedRecomp/gpu/shader/msl/copy_color_ps.metal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "copy_common.metali"

struct Texture2DDescriptorHeap
{
texture2d<float> tex;
};

[[fragment]]
float4 shaderMain(float4 position [[position]],
constant Texture2DDescriptorHeap* g_Texture2DDescriptorHeap [[buffer(0)]],
constant PushConstants& g_PushConstants [[buffer(8)]])
{
return g_Texture2DDescriptorHeap[g_PushConstants.ResourceDescriptorIndex].tex.read(uint2(position.xy), 0);
}
9 changes: 9 additions & 0 deletions UnleashedRecomp/gpu/shader/msl/copy_common.metali
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#include <metal_stdlib>

using namespace metal;

struct PushConstants
{
uint ResourceDescriptorIndex;
};
Loading