diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index 3eabba5..17a06ea 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -274,6 +274,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} @@ -374,6 +378,10 @@ if (UNLEASHED_RECOMP_D3D12) ) endif() +if (UNLEASHED_RECOMP_METAL) + target_compile_definitions(UnleashedRecomp PRIVATE UNLEASHED_RECOMP_METAL) +endif() + if (CMAKE_SYSTEM_NAME MATCHES "Linux") target_compile_definitions(UnleashedRecomp PRIVATE SDL_VULKAN_ENABLED) endif() @@ -441,22 +449,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 -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} -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) diff --git a/UnleashedRecomp/gpu/imgui/imgui_common.h b/UnleashedRecomp/gpu/imgui/imgui_common.h index 10c5ebb..c9d0f06 100644 --- a/UnleashedRecomp/gpu/imgui/imgui_common.h +++ b/UnleashedRecomp/gpu/imgui/imgui_common.h @@ -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 { diff --git a/UnleashedRecomp/gpu/shader/.gitignore b/UnleashedRecomp/gpu/shader/hlsl/.gitignore similarity index 100% rename from UnleashedRecomp/gpu/shader/.gitignore rename to UnleashedRecomp/gpu/shader/hlsl/.gitignore diff --git a/UnleashedRecomp/gpu/shader/blend_color_alpha_ps.hlsl b/UnleashedRecomp/gpu/shader/hlsl/blend_color_alpha_ps.hlsl similarity index 94% rename from UnleashedRecomp/gpu/shader/blend_color_alpha_ps.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/blend_color_alpha_ps.hlsl index 6c24290..edcdc47 100644 --- a/UnleashedRecomp/gpu/shader/blend_color_alpha_ps.hlsl +++ b/UnleashedRecomp/gpu/shader/hlsl/blend_color_alpha_ps.hlsl @@ -1,4 +1,4 @@ -#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h" +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" #ifdef __spirv__ diff --git a/UnleashedRecomp/gpu/shader/copy_color_ps.hlsl b/UnleashedRecomp/gpu/shader/hlsl/copy_color_ps.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/copy_color_ps.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/copy_color_ps.hlsl diff --git a/UnleashedRecomp/gpu/shader/copy_common.hlsli b/UnleashedRecomp/gpu/shader/hlsl/copy_common.hlsli similarity index 100% rename from UnleashedRecomp/gpu/shader/copy_common.hlsli rename to UnleashedRecomp/gpu/shader/hlsl/copy_common.hlsli diff --git a/UnleashedRecomp/gpu/shader/copy_depth_ps.hlsl b/UnleashedRecomp/gpu/shader/hlsl/copy_depth_ps.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/copy_depth_ps.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/copy_depth_ps.hlsl diff --git a/UnleashedRecomp/gpu/shader/copy_vs.hlsl b/UnleashedRecomp/gpu/shader/hlsl/copy_vs.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/copy_vs.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/copy_vs.hlsl diff --git a/UnleashedRecomp/gpu/shader/csd_filter_ps.hlsl b/UnleashedRecomp/gpu/shader/hlsl/csd_filter_ps.hlsl similarity index 95% rename from UnleashedRecomp/gpu/shader/csd_filter_ps.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/csd_filter_ps.hlsl index e1ecde3..99424ce 100644 --- a/UnleashedRecomp/gpu/shader/csd_filter_ps.hlsl +++ b/UnleashedRecomp/gpu/shader/hlsl/csd_filter_ps.hlsl @@ -1,4 +1,4 @@ -#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h" +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" #ifdef __spirv__ diff --git a/UnleashedRecomp/gpu/shader/csd_no_tex_vs.hlsl b/UnleashedRecomp/gpu/shader/hlsl/csd_no_tex_vs.hlsl similarity index 96% rename from UnleashedRecomp/gpu/shader/csd_no_tex_vs.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/csd_no_tex_vs.hlsl index 1654e73..16eca75 100644 --- a/UnleashedRecomp/gpu/shader/csd_no_tex_vs.hlsl +++ b/UnleashedRecomp/gpu/shader/hlsl/csd_no_tex_vs.hlsl @@ -1,4 +1,4 @@ -#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h" +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" #ifdef __spirv__ diff --git a/UnleashedRecomp/gpu/shader/csd_vs.hlsl b/UnleashedRecomp/gpu/shader/hlsl/csd_vs.hlsl similarity index 96% rename from UnleashedRecomp/gpu/shader/csd_vs.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/csd_vs.hlsl index 90b561f..3ec425b 100644 --- a/UnleashedRecomp/gpu/shader/csd_vs.hlsl +++ b/UnleashedRecomp/gpu/shader/hlsl/csd_vs.hlsl @@ -1,4 +1,4 @@ -#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h" +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" #ifdef __spirv__ diff --git a/UnleashedRecomp/gpu/shader/enhanced_motion_blur_ps.hlsl b/UnleashedRecomp/gpu/shader/hlsl/enhanced_motion_blur_ps.hlsl similarity index 97% rename from UnleashedRecomp/gpu/shader/enhanced_motion_blur_ps.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/enhanced_motion_blur_ps.hlsl index fd522da..c96900d 100644 --- a/UnleashedRecomp/gpu/shader/enhanced_motion_blur_ps.hlsl +++ b/UnleashedRecomp/gpu/shader/hlsl/enhanced_motion_blur_ps.hlsl @@ -1,4 +1,4 @@ -#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h" +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" #ifdef __spirv__ diff --git a/UnleashedRecomp/gpu/shader/gamma_correction_ps.hlsl b/UnleashedRecomp/gpu/shader/hlsl/gamma_correction_ps.hlsl similarity index 93% rename from UnleashedRecomp/gpu/shader/gamma_correction_ps.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/gamma_correction_ps.hlsl index 2f98b6e..17577a0 100644 --- a/UnleashedRecomp/gpu/shader/gamma_correction_ps.hlsl +++ b/UnleashedRecomp/gpu/shader/hlsl/gamma_correction_ps.hlsl @@ -1,4 +1,4 @@ -#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h" +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" #ifdef __spirv__ diff --git a/UnleashedRecomp/gpu/shader/gaussian_blur.hlsli b/UnleashedRecomp/gpu/shader/hlsl/gaussian_blur.hlsli similarity index 97% rename from UnleashedRecomp/gpu/shader/gaussian_blur.hlsli rename to UnleashedRecomp/gpu/shader/hlsl/gaussian_blur.hlsli index 10d76cf..6f1bc58 100644 --- a/UnleashedRecomp/gpu/shader/gaussian_blur.hlsli +++ b/UnleashedRecomp/gpu/shader/hlsl/gaussian_blur.hlsli @@ -1,4 +1,4 @@ -#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h" +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" #ifdef __spirv__ diff --git a/UnleashedRecomp/gpu/shader/gaussian_blur_3x3.hlsl b/UnleashedRecomp/gpu/shader/hlsl/gaussian_blur_3x3.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/gaussian_blur_3x3.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/gaussian_blur_3x3.hlsl diff --git a/UnleashedRecomp/gpu/shader/gaussian_blur_5x5.hlsl b/UnleashedRecomp/gpu/shader/hlsl/gaussian_blur_5x5.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/gaussian_blur_5x5.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/gaussian_blur_5x5.hlsl diff --git a/UnleashedRecomp/gpu/shader/gaussian_blur_7x7.hlsl b/UnleashedRecomp/gpu/shader/hlsl/gaussian_blur_7x7.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/gaussian_blur_7x7.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/gaussian_blur_7x7.hlsl diff --git a/UnleashedRecomp/gpu/shader/gaussian_blur_9x9.hlsl b/UnleashedRecomp/gpu/shader/hlsl/gaussian_blur_9x9.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/gaussian_blur_9x9.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/gaussian_blur_9x9.hlsl diff --git a/UnleashedRecomp/gpu/shader/imgui_common.hlsli b/UnleashedRecomp/gpu/shader/hlsl/imgui_common.hlsli similarity index 95% rename from UnleashedRecomp/gpu/shader/imgui_common.hlsli rename to UnleashedRecomp/gpu/shader/hlsl/imgui_common.hlsli index f4cbe3c..42bd94e 100644 --- a/UnleashedRecomp/gpu/shader/imgui_common.hlsli +++ b/UnleashedRecomp/gpu/shader/hlsl/imgui_common.hlsli @@ -1,6 +1,6 @@ #pragma once -#include "../imgui/imgui_common.h" +#include "../../imgui/imgui_common.h" struct PushConstants { diff --git a/UnleashedRecomp/gpu/shader/imgui_ps.hlsl b/UnleashedRecomp/gpu/shader/hlsl/imgui_ps.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/imgui_ps.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/imgui_ps.hlsl diff --git a/UnleashedRecomp/gpu/shader/imgui_vs.hlsl b/UnleashedRecomp/gpu/shader/hlsl/imgui_vs.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/imgui_vs.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/imgui_vs.hlsl diff --git a/UnleashedRecomp/gpu/shader/movie_common.hlsli b/UnleashedRecomp/gpu/shader/hlsl/movie_common.hlsli similarity index 97% rename from UnleashedRecomp/gpu/shader/movie_common.hlsli rename to UnleashedRecomp/gpu/shader/hlsl/movie_common.hlsli index 1294235..61cc3b3 100644 --- a/UnleashedRecomp/gpu/shader/movie_common.hlsli +++ b/UnleashedRecomp/gpu/shader/hlsl/movie_common.hlsli @@ -1,6 +1,6 @@ #pragma once -#include "../../../tools/XenosRecomp/XenosRecomp/shader_common.h" +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" #ifdef __spirv__ diff --git a/UnleashedRecomp/gpu/shader/movie_ps.hlsl b/UnleashedRecomp/gpu/shader/hlsl/movie_ps.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/movie_ps.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/movie_ps.hlsl diff --git a/UnleashedRecomp/gpu/shader/movie_vs.hlsl b/UnleashedRecomp/gpu/shader/hlsl/movie_vs.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/movie_vs.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/movie_vs.hlsl diff --git a/UnleashedRecomp/gpu/shader/resolve_msaa_color.hlsli b/UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_color.hlsli similarity index 100% rename from UnleashedRecomp/gpu/shader/resolve_msaa_color.hlsli rename to UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_color.hlsli diff --git a/UnleashedRecomp/gpu/shader/resolve_msaa_color_2x.hlsl b/UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_color_2x.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/resolve_msaa_color_2x.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_color_2x.hlsl diff --git a/UnleashedRecomp/gpu/shader/resolve_msaa_color_4x.hlsl b/UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_color_4x.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/resolve_msaa_color_4x.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_color_4x.hlsl diff --git a/UnleashedRecomp/gpu/shader/resolve_msaa_color_8x.hlsl b/UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_color_8x.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/resolve_msaa_color_8x.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_color_8x.hlsl diff --git a/UnleashedRecomp/gpu/shader/resolve_msaa_depth.hlsli b/UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_depth.hlsli similarity index 100% rename from UnleashedRecomp/gpu/shader/resolve_msaa_depth.hlsli rename to UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_depth.hlsli diff --git a/UnleashedRecomp/gpu/shader/resolve_msaa_depth_2x.hlsl b/UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_depth_2x.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/resolve_msaa_depth_2x.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_depth_2x.hlsl diff --git a/UnleashedRecomp/gpu/shader/resolve_msaa_depth_4x.hlsl b/UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_depth_4x.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/resolve_msaa_depth_4x.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_depth_4x.hlsl diff --git a/UnleashedRecomp/gpu/shader/resolve_msaa_depth_8x.hlsl b/UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_depth_8x.hlsl similarity index 100% rename from UnleashedRecomp/gpu/shader/resolve_msaa_depth_8x.hlsl rename to UnleashedRecomp/gpu/shader/hlsl/resolve_msaa_depth_8x.hlsl diff --git a/UnleashedRecomp/gpu/shader/msl/.gitignore b/UnleashedRecomp/gpu/shader/msl/.gitignore new file mode 100644 index 0000000..40d087f --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/.gitignore @@ -0,0 +1,4 @@ +*.ir +*.metallib +*.metal.*.c +*.metal.*.h \ No newline at end of file diff --git a/UnleashedRecomp/gpu/shader/msl/blend_color_alpha_ps.metal b/UnleashedRecomp/gpu/shader/msl/blend_color_alpha_ps.metal new file mode 100644 index 0000000..4071a0b --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/blend_color_alpha_ps.metal @@ -0,0 +1,31 @@ +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" + +#define g_SrcAlpha_DestAlpha (*(reinterpret_cast(g_PushConstants.PixelShaderConstants + 2400))) +#define s0_Texture2DDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 0))) +#define s0_SamplerDescriptorIndex (*(reinterpret_cast(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(4)]]) +{ + texture2d texture = g_Texture2DDescriptorHeap.g[s0_Texture2DDescriptorIndex]; + sampler samplerState = g_SamplerDescriptorHeap.g[s0_SamplerDescriptorIndex]; + + 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; +} diff --git a/UnleashedRecomp/gpu/shader/msl/copy_color_ps.metal b/UnleashedRecomp/gpu/shader/msl/copy_color_ps.metal new file mode 100644 index 0000000..6628937 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/copy_color_ps.metal @@ -0,0 +1,14 @@ +#include "copy_common.metali" + +struct Texture2DDescriptorHeap +{ + array, 1> g [[id(0)]]; +}; + +[[fragment]] +float4 shaderMain(float4 position [[position]], + constant Texture2DDescriptorHeap& g_Texture2DDescriptorHeap [[buffer(0)]], + constant PushConstants& g_PushConstants [[buffer(4)]]) +{ + return g_Texture2DDescriptorHeap.g[g_PushConstants.ResourceDescriptorIndex].read(uint2(position.xy), 0); +} diff --git a/UnleashedRecomp/gpu/shader/msl/copy_common.metali b/UnleashedRecomp/gpu/shader/msl/copy_common.metali new file mode 100644 index 0000000..2040a3a --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/copy_common.metali @@ -0,0 +1,9 @@ +#pragma once +#include + +using namespace metal; + +struct PushConstants +{ + uint ResourceDescriptorIndex; +}; diff --git a/UnleashedRecomp/gpu/shader/msl/copy_depth_ps.metal b/UnleashedRecomp/gpu/shader/msl/copy_depth_ps.metal new file mode 100644 index 0000000..bf9885a --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/copy_depth_ps.metal @@ -0,0 +1,23 @@ +#include "copy_common.metali" + +struct Texture2DDescriptorHeap +{ + array, 1> g [[id(0)]]; +}; + +struct PixelShaderOutput +{ + float oDepth [[depth(any)]]; +}; + +[[fragment]] +PixelShaderOutput shaderMain(float4 position [[position]], + constant Texture2DDescriptorHeap& g_Texture2DDescriptorHeap [[buffer(0)]], + constant PushConstants& g_PushConstants [[buffer(4)]]) +{ + PixelShaderOutput output = PixelShaderOutput{}; + + output.oDepth = g_Texture2DDescriptorHeap.g[g_PushConstants.ResourceDescriptorIndex].read(uint2(position.xy), 0).x; + + return output; +} diff --git a/UnleashedRecomp/gpu/shader/msl/copy_vs.metal b/UnleashedRecomp/gpu/shader/msl/copy_vs.metal new file mode 100644 index 0000000..5703be5 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/copy_vs.metal @@ -0,0 +1,16 @@ +struct Interpolators +{ + float4 position [[position]]; + float2 texCoord [[user(TEXCOORD)]]; +}; + +[[vertex]] +Interpolators shaderMain(uint vertexId [[vertex_id]]) +{ + Interpolators interpolators; + + interpolators.texCoord = float2((vertexId << 1) & 2, vertexId & 2); + interpolators.position = float4(interpolators.texCoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0); + + return interpolators; +} diff --git a/UnleashedRecomp/gpu/shader/msl/csd_filter_ps.metal b/UnleashedRecomp/gpu/shader/msl/csd_filter_ps.metal new file mode 100644 index 0000000..53acea3 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/csd_filter_ps.metal @@ -0,0 +1,38 @@ +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" + +#define s0_Texture2DDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 0))) +#define s0_SamplerDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 192))) + +struct Interpolators +{ + float4 iPosition [[position]]; + float4 iTexCoord0 [[user(TEXCOORD0)]]; + float4 iTexCoord1 [[user(TEXCOORD1)]]; +}; + +[[fragment]] +float4 shaderMain(Interpolators input [[stage_in]], + constant Texture2DDescriptorHeap& g_Texture2DDescriptorHeap [[buffer(0)]], + constant SamplerDescriptorHeap& g_SamplerDescriptorHeap [[buffer(3)]], + constant PushConstants& g_PushConstants [[buffer(4)]]) +{ + texture2d texture = g_Texture2DDescriptorHeap.g[s0_Texture2DDescriptorIndex]; + sampler samplerState = g_SamplerDescriptorHeap.g[s0_SamplerDescriptorIndex]; + + uint2 dimensions = getTexture2DDimensions(texture); + + // https://www.shadertoy.com/view/csX3RH + float2 uvTexspace = input.iTexCoord1.xy * float2(dimensions); + float2 seam = floor(uvTexspace + 0.5); + uvTexspace = (uvTexspace - seam) / fwidth(uvTexspace) + seam; + uvTexspace = clamp(uvTexspace, seam - 0.5, seam + 0.5); + float2 texCoord = uvTexspace / float2(dimensions); + + float4 color = texture.sample(samplerState, texCoord); + color *= input.iTexCoord0; + + // The game enables alpha test for CSD, but the alpha threshold doesn't seem to be assigned anywhere? Weird. + clip(color.a - g_AlphaThreshold); + + return color; +} diff --git a/UnleashedRecomp/gpu/shader/msl/csd_no_tex_vs.metal b/UnleashedRecomp/gpu/shader/msl/csd_no_tex_vs.metal new file mode 100644 index 0000000..4ec0748 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/csd_no_tex_vs.metal @@ -0,0 +1,64 @@ +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" + +#define g_ViewportSize (*(reinterpret_cast(g_PushConstants.VertexShaderConstants + 2880))) +#define g_Z (*(reinterpret_cast(g_PushConstants.VertexShaderConstants + 3936))) + +struct VertexShaderInput +{ + float4 iPosition0 [[attribute(0)]]; + float4 iColor0 [[attribute(8)]]; +}; + +struct Interpolators +{ + float4 oPos [[position]]; + float4 oTexCoord0 [[user(TEXCOORD0)]]; + float4 oTexCoord1 [[user(TEXCOORD1)]]; + float4 oTexCoord2 [[user(TEXCOORD2)]]; + float4 oTexCoord3 [[user(TEXCOORD3)]]; + float4 oTexCoord4 [[user(TEXCOORD4)]]; + float4 oTexCoord5 [[user(TEXCOORD5)]]; + float4 oTexCoord6 [[user(TEXCOORD6)]]; + float4 oTexCoord7 [[user(TEXCOORD7)]]; + float4 oTexCoord8 [[user(TEXCOORD8)]]; + float4 oTexCoord9 [[user(TEXCOORD9)]]; + float4 oTexCoord10 [[user(TEXCOORD10)]]; + float4 oTexCoord11 [[user(TEXCOORD11)]]; + float4 oTexCoord12 [[user(TEXCOORD12)]]; + float4 oTexCoord13 [[user(TEXCOORD13)]]; + float4 oTexCoord14 [[user(TEXCOORD14)]]; + float4 oTexCoord15 [[user(TEXCOORD15)]]; + float4 oColor0 [[user(COLOR0)]]; + float4 oColor1 [[user(COLOR1)]]; +}; + +[[vertex]] +Interpolators shaderMain(VertexShaderInput input [[stage_in]], + constant PushConstants& g_PushConstants [[buffer(4)]]) +{ + Interpolators output; + + output.oPos.xy = (input.iPosition0.xy - 0.5) * g_ViewportSize.zw * float2(2.0, -2.0) + float2(-1.0, 1.0); + output.oPos.z = g_Z.x; + output.oPos.w = 1.0; + output.oTexCoord0 = input.iColor0.wxyz; + output.oTexCoord1 = 0.0; + output.oTexCoord2 = 0.0; + output.oTexCoord3 = 0.0; + output.oTexCoord4 = 0.0; + output.oTexCoord5 = 0.0; + output.oTexCoord6 = 0.0; + output.oTexCoord7 = 0.0; + output.oTexCoord8 = 0.0; + output.oTexCoord9 = 0.0; + output.oTexCoord10 = 0.0; + output.oTexCoord11 = 0.0; + output.oTexCoord12 = 0.0; + output.oTexCoord13 = 0.0; + output.oTexCoord14 = 0.0; + output.oTexCoord15 = 0.0; + output.oColor0 = 0.0; + output.oColor1 = 0.0; + + return output; +} diff --git a/UnleashedRecomp/gpu/shader/msl/csd_vs.metal b/UnleashedRecomp/gpu/shader/msl/csd_vs.metal new file mode 100644 index 0000000..b8f8f6a --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/csd_vs.metal @@ -0,0 +1,66 @@ +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" + +#define g_ViewportSize (*(reinterpret_cast(g_PushConstants.VertexShaderConstants + 2880))) +#define g_Z (*(reinterpret_cast(g_PushConstants.VertexShaderConstants + 3936))) + +struct VertexShaderInput +{ + float4 iPosition0 [[attribute(0)]]; + float4 iColor0 [[attribute(8)]]; + float4 iTexCoord0 [[attribute(4)]]; +}; + +struct Interpolators +{ + float4 oPos [[position]]; + float4 oTexCoord0 [[user(TEXCOORD0)]]; + float4 oTexCoord1 [[user(TEXCOORD1)]]; + float4 oTexCoord2 [[user(TEXCOORD2)]]; + float4 oTexCoord3 [[user(TEXCOORD3)]]; + float4 oTexCoord4 [[user(TEXCOORD4)]]; + float4 oTexCoord5 [[user(TEXCOORD5)]]; + float4 oTexCoord6 [[user(TEXCOORD6)]]; + float4 oTexCoord7 [[user(TEXCOORD7)]]; + float4 oTexCoord8 [[user(TEXCOORD8)]]; + float4 oTexCoord9 [[user(TEXCOORD9)]]; + float4 oTexCoord10 [[user(TEXCOORD10)]]; + float4 oTexCoord11 [[user(TEXCOORD11)]]; + float4 oTexCoord12 [[user(TEXCOORD12)]]; + float4 oTexCoord13 [[user(TEXCOORD13)]]; + float4 oTexCoord14 [[user(TEXCOORD14)]]; + float4 oTexCoord15 [[user(TEXCOORD15)]]; + float4 oColor0 [[user(COLOR0)]]; + float4 oColor1 [[user(COLOR1)]]; +}; + +[[vertex]] +Interpolators shaderMain(VertexShaderInput input [[stage_in]], + constant PushConstants& g_PushConstants [[buffer(4)]]) +{ + Interpolators output; + + output.oPos.xy = (input.iPosition0.xy - 0.5) * g_ViewportSize.zw * float2(2.0, -2.0) + float2(-1.0, 1.0); + output.oPos.z = g_Z.x; + output.oPos.w = 1.0; + output.oTexCoord0 = input.iColor0.wxyz; + output.oTexCoord1.xy = input.iTexCoord0.xy; + output.oTexCoord1.zw = 0.0; + output.oTexCoord2 = 0.0; + output.oTexCoord3 = 0.0; + output.oTexCoord4 = 0.0; + output.oTexCoord5 = 0.0; + output.oTexCoord6 = 0.0; + output.oTexCoord7 = 0.0; + output.oTexCoord8 = 0.0; + output.oTexCoord9 = 0.0; + output.oTexCoord10 = 0.0; + output.oTexCoord11 = 0.0; + output.oTexCoord12 = 0.0; + output.oTexCoord13 = 0.0; + output.oTexCoord14 = 0.0; + output.oTexCoord15 = 0.0; + output.oColor0 = 0.0; + output.oColor1 = 0.0; + + return output; +} diff --git a/UnleashedRecomp/gpu/shader/msl/enhanced_motion_blur_ps.metal b/UnleashedRecomp/gpu/shader/msl/enhanced_motion_blur_ps.metal new file mode 100644 index 0000000..2c06829 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/enhanced_motion_blur_ps.metal @@ -0,0 +1,59 @@ +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" + +#define g_BlurRate (*(reinterpret_cast(g_PushConstants.PixelShaderConstants + 2400))) +#define g_ViewportSize (*(reinterpret_cast(g_PushConstants.PixelShaderConstants + 384))) + +#define sampColor_Texture2DDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 0))) +#define sampColor_SamplerDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 192))) + +#define sampVelocityMap_Texture2DDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 4))) +#define sampVelocityMap_SamplerDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 196))) + +#define sampZBuffer_Texture2DDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 8))) +#define sampZBuffer_SamplerDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 200))) + +struct Interpolators +{ + float4 texCoord [[user(TEXCOORD0)]]; +}; + +[[fragment]] +float4 shaderMain(float4 position [[position]], + Interpolators input [[stage_in]], + constant Texture2DDescriptorHeap& g_Texture2DDescriptorHeap [[buffer(0)]], + constant SamplerDescriptorHeap& g_SamplerDescriptorHeap [[buffer(3)]], + constant PushConstants& g_PushConstants [[buffer(4)]]) +{ + texture2d sampColor = g_Texture2DDescriptorHeap.g[sampColor_Texture2DDescriptorIndex]; + texture2d sampVelocityMap = g_Texture2DDescriptorHeap.g[sampVelocityMap_Texture2DDescriptorIndex]; + texture2d sampZBuffer = g_Texture2DDescriptorHeap.g[sampZBuffer_Texture2DDescriptorIndex]; + + sampler sampColor_s = g_SamplerDescriptorHeap.g[sampColor_SamplerDescriptorIndex]; + sampler sampVelocityMap_s = g_SamplerDescriptorHeap.g[sampVelocityMap_SamplerDescriptorIndex]; + sampler sampZBuffer_s = g_SamplerDescriptorHeap.g[sampZBuffer_SamplerDescriptorIndex]; + + float depth = sampZBuffer.sample(sampZBuffer_s, input.texCoord.xy, level(0)).x; + float4 velocityMap = sampVelocityMap.sample(sampVelocityMap_s, input.texCoord.xy, level(0)); + float2 velocity = (velocityMap.xz + velocityMap.yw / 255.0) * 2.0 - 1.0; + + int sampleCount = min(64, int(round(length(velocity * g_ViewportSize.xy)))); + float2 sampleOffset = velocity / (float) sampleCount; + + float3 color = sampColor.sample(sampColor_s, input.texCoord.xy, level(0)).rgb; + int count = 1; + + for (int i = 1; i <= sampleCount; i++) + { + float2 sampleCoord = input.texCoord.xy + sampleOffset * i; + float3 sampleColor = sampColor.sample(sampColor_s, sampleCoord, level(0)).rgb; + float sampleDepth = sampZBuffer.sample(sampZBuffer_s, sampleCoord, 0).x; + + if (sampleDepth - depth < 0.01) + { + color += sampleColor; + count += 1; + } + } + + return float4(color / count, g_BlurRate.x * saturate(dot(abs(velocity), g_ViewportSize.xy) / 8.0) * saturate(float(count - 1))); +} diff --git a/UnleashedRecomp/gpu/shader/msl/gamma_correction_ps.metal b/UnleashedRecomp/gpu/shader/msl/gamma_correction_ps.metal new file mode 100644 index 0000000..e8fffad --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/gamma_correction_ps.metal @@ -0,0 +1,23 @@ +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" + +#define g_Gamma (*(reinterpret_cast(g_PushConstants.SharedConstants + 0))) +#define g_TextureDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 12))) + +#define g_ViewportOffset (*(reinterpret_cast(g_PushConstants.SharedConstants + 16))) +#define g_ViewportSize (*(reinterpret_cast(g_PushConstants.SharedConstants + 24))) + +[[fragment]] +float4 shaderMain(float4 position [[position]], + constant Texture2DDescriptorHeap& g_Texture2DDescriptorHeap [[buffer(0)]], + constant PushConstants& g_PushConstants [[buffer(4)]]) +{ + texture2d texture = g_Texture2DDescriptorHeap.g[g_TextureDescriptorIndex]; + + int2 movedPosition = int2(position.xy) - g_ViewportOffset; + bool boxed = any(movedPosition < 0) || any(movedPosition >= g_ViewportSize); + if (boxed) movedPosition = 0; + + float4 color = boxed ? 0.0 : texture.read(uint2(movedPosition), 0); + color.rgb = pow(color.rgb, g_Gamma); + return color; +} diff --git a/UnleashedRecomp/gpu/shader/msl/gaussian_blur.metali b/UnleashedRecomp/gpu/shader/msl/gaussian_blur.metali new file mode 100644 index 0000000..7734aa8 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/gaussian_blur.metali @@ -0,0 +1,63 @@ +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" + +#define g_ViewportSize (*(reinterpret_cast(g_PushConstants.PixelShaderConstants + 384))) +#define g_offsets(INDEX) selectWrapper((INDEX) < 74,(*(reinterpret_cast(g_PushConstants.PixelShaderConstants + (150 + min(INDEX, 73)) * 16))), 0.0) +#define g_weights (*(reinterpret_cast(g_PushConstants.PixelShaderConstants + 2656))) + +#define s0_Texture2DDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 0))) +#define s0_SamplerDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 192))) + +#ifdef __INTELLISENSE__ +#define KERNEL_SIZE 5 +#endif + +#define PI 3.14159265358979323846 + +float ComputeWeight(float x) +{ + float std = 0.952; + return exp(-(x * x) / (2.0 * std * std)) / (std * sqrt(2.0 * PI)); +} + +struct Interpolators +{ + float4 iTexCoord0 [[user(TEXCOORD0)]]; +}; + +[[fragment]] +float4 shaderMain(float4 iPosition [[position]], + Interpolators input [[stage_in]], + constant Texture2DDescriptorHeap& g_Texture2DDescriptorHeap [[buffer(0)]], + constant SamplerDescriptorHeap& g_SamplerDescriptorHeap [[buffer(3)]], + constant PushConstants& g_PushConstants [[buffer(4)]]) +{ + texture2d texture = g_Texture2DDescriptorHeap.g[s0_Texture2DDescriptorIndex]; + sampler samplerState = g_SamplerDescriptorHeap.g[s0_SamplerDescriptorIndex]; + + float scale; + if ((g_ViewportSize.x * g_ViewportSize.w) >= (16.0 / 9.0)) + scale = g_ViewportSize.y / 360.0; + else + scale = g_ViewportSize.x / 640.0; + + float2 offsets[3]; + offsets[0] = g_offsets(0).xy * scale; + offsets[1] = g_offsets(0).zw * scale; + offsets[2] = g_offsets(1).xy * scale; + + float4 color = 0.0; + float weightSum = 0.0; + + for (int i = 0; i < KERNEL_SIZE; i++) + { + float step = i / float(KERNEL_SIZE - 1); + float scaled = step * 2; + float2 offset = mix(offsets[int(scaled)], offsets[min(int(scaled) + 1, 2)], frac(scaled)); + float offsetScale = 1.0 / 0.75; + float weight = ComputeWeight(mix(-offsetScale, offsetScale, step)); + color += texture.sample(samplerState, input.iTexCoord0.xy + offset, level(0)) * weight; + weightSum += weight; + } + + return color / weightSum; +} diff --git a/UnleashedRecomp/gpu/shader/msl/gaussian_blur_3x3.metal b/UnleashedRecomp/gpu/shader/msl/gaussian_blur_3x3.metal new file mode 100644 index 0000000..1f8dbf3 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/gaussian_blur_3x3.metal @@ -0,0 +1,2 @@ +#define KERNEL_SIZE 3 +#include "gaussian_blur.metali" diff --git a/UnleashedRecomp/gpu/shader/msl/gaussian_blur_5x5.metal b/UnleashedRecomp/gpu/shader/msl/gaussian_blur_5x5.metal new file mode 100644 index 0000000..5b1a2c2 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/gaussian_blur_5x5.metal @@ -0,0 +1,2 @@ +#define KERNEL_SIZE 5 +#include "gaussian_blur.metali" diff --git a/UnleashedRecomp/gpu/shader/msl/gaussian_blur_7x7.metal b/UnleashedRecomp/gpu/shader/msl/gaussian_blur_7x7.metal new file mode 100644 index 0000000..ba1bd73 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/gaussian_blur_7x7.metal @@ -0,0 +1,2 @@ +#define KERNEL_SIZE 7 +#include "gaussian_blur.metali" diff --git a/UnleashedRecomp/gpu/shader/msl/gaussian_blur_9x9.metal b/UnleashedRecomp/gpu/shader/msl/gaussian_blur_9x9.metal new file mode 100644 index 0000000..50198a7 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/gaussian_blur_9x9.metal @@ -0,0 +1,2 @@ +#define KERNEL_SIZE 9 +#include "gaussian_blur.metali" diff --git a/UnleashedRecomp/gpu/shader/msl/imgui_common.metali b/UnleashedRecomp/gpu/shader/msl/imgui_common.metali new file mode 100644 index 0000000..a103e7b --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/imgui_common.metali @@ -0,0 +1,41 @@ +#pragma once +#include + +using namespace metal; + +#include "../../imgui/imgui_common.h" + +struct PushConstants +{ + float2 BoundsMin; + float2 BoundsMax; + uint GradientTopLeft; + uint GradientTopRight; + uint GradientBottomRight; + uint GradientBottomLeft; + uint ShaderModifier; + uint Texture2DDescriptorIndex; + float2 DisplaySize; + float2 InverseDisplaySize; + float2 Origin; + float2 Scale; + float2 ProceduralOrigin; + float Outline; +}; + +struct Interpolators +{ + float4 Position [[position]]; + float2 UV; + float4 Color; +}; + +struct Texture2DDescriptorHeap +{ + array, 1> g [[id(0)]]; +}; + +struct SamplerDescriptorHeap +{ + array g [[id(0)]]; +}; \ No newline at end of file diff --git a/UnleashedRecomp/gpu/shader/msl/imgui_ps.metal b/UnleashedRecomp/gpu/shader/msl/imgui_ps.metal new file mode 100644 index 0000000..18e2fa8 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/imgui_ps.metal @@ -0,0 +1,235 @@ +#include "imgui_common.metali" + +float4 DecodeColor(uint color) +{ + return float4(color & 0xFF, (color >> 8) & 0xFF, (color >> 16) & 0xFF, (color >> 24) & 0xFF) / 255.0; +} + +float4 SamplePoint(int2 position, constant PushConstants& g_PushConstants) +{ + switch (g_PushConstants.ShaderModifier) + { + case IMGUI_SHADER_MODIFIER_SCANLINE: + { + if (int(position.y) % 2 == 0) + return float4(1.0, 1.0, 1.0, 0.0); + + break; + } + case IMGUI_SHADER_MODIFIER_CHECKERBOARD: + { + int remnantX = int(position.x) % 9; + int remnantY = int(position.y) % 9; + + float4 color = 1.0; + + if (remnantX == 0 || remnantY == 0) + color.a = 0.0; + + if ((remnantY % 2) == 0) + color.rgb = 0.5; + + return color; + } + case IMGUI_SHADER_MODIFIER_SCANLINE_BUTTON: + { + if (int(position.y) % 2 == 0) + return float4(1.0, 1.0, 1.0, 0.5); + + break; + } + } + + return 1.0; +} + +float4 SampleLinear(float2 uvTexspace, constant PushConstants& g_PushConstants) +{ + int2 integerPart = int2(floor(uvTexspace)); + float2 fracPart = fract(uvTexspace); + + float4 topLeft = SamplePoint(integerPart + int2(0, 0), g_PushConstants); + float4 topRight = SamplePoint(integerPart + int2(1, 0), g_PushConstants); + float4 bottomLeft = SamplePoint(integerPart + int2(0, 1), g_PushConstants); + float4 bottomRight = SamplePoint(integerPart + int2(1, 1), g_PushConstants); + + float4 top = mix(topLeft, topRight, fracPart.x); + float4 bottom = mix(bottomLeft, bottomRight, fracPart.x); + + return mix(top, bottom, fracPart.y); +} + +float4 PixelAntialiasing(float2 uvTexspace, constant PushConstants& g_PushConstants) +{ + if ((g_PushConstants.DisplaySize.x * g_PushConstants.InverseDisplaySize.y) >= (4.0 / 3.0)) + uvTexspace *= g_PushConstants.InverseDisplaySize.y * 720.0; + else + uvTexspace *= g_PushConstants.InverseDisplaySize.x * 960.0; + + float2 seam = floor(uvTexspace + 0.5); + uvTexspace = (uvTexspace - seam) / fwidth(uvTexspace) + seam; + uvTexspace = clamp(uvTexspace, seam - 0.5, seam + 0.5); + + return SampleLinear(uvTexspace - 0.5, g_PushConstants); +} + +float median(float r, float g, float b) +{ + return max(min(r, g), min(max(r, g), b)); +} + +float4 SampleSdfFont(float4 color, texture2d texture, float2 uv, float2 screenTexSize, + constant SamplerDescriptorHeap& g_SamplerDescriptorHeap, + constant PushConstants& g_PushConstants) +{ + float4 textureColor = texture.sample(g_SamplerDescriptorHeap.g[0], uv); + + uint width = texture.get_width(); + uint height = texture.get_height(); + + float pxRange = 8.0; + float2 unitRange = pxRange / float2(width, height); + float screenPxRange = max(0.5 * dot(unitRange, screenTexSize), 1.0); + + float sd = median(textureColor.r, textureColor.g, textureColor.b) - 0.5; + float screenPxDistance = screenPxRange * (sd + g_PushConstants.Outline / (pxRange * 1.5)); + + if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_TITLE_BEVEL) + { + float2 normal = normalize(float3(dfdx(sd), dfdy(sd), 0.01)).xy; + float3 rimColor = float3(1, 0.8, 0.29); + float3 shadowColor = float3(0.84, 0.57, 0); + + float cosTheta = dot(normal, normalize(float2(1, 1))); + float3 gradient = mix(color.rgb, cosTheta >= 0.0 ? rimColor : shadowColor, abs(cosTheta)); + color.rgb = mix(gradient, color.rgb, pow(saturate(sd + 0.77), 32.0)); + } + else if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_CATEGORY_BEVEL) + { + float2 normal = normalize(float3(dfdx(sd), dfdy(sd), 0.25)).xy; + float cosTheta = dot(normal, normalize(float2(1, 1))); + float gradient = 1.0 + cosTheta * 0.5; + color.rgb = saturate(color.rgb * gradient); + } + else if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_TEXT_SKEW) + { + float2 normal = normalize(float3(dfdx(sd), dfdy(sd), 0.5)).xy; + float cosTheta = dot(normal, normalize(float2(1, 1))); + float gradient = saturate(1.0 + cosTheta); + color.rgb = mix(color.rgb * gradient, color.rgb, pow(saturate(sd + 0.77), 32.0)); + } + + color.a *= saturate(screenPxDistance + 0.5); + color.a *= textureColor.a; + + return color; +} + +[[fragment]] +float4 shaderMain(Interpolators interpolators [[stage_in]], + constant Texture2DDescriptorHeap& g_Texture2DDescriptorHeap [[buffer(0)]], + constant SamplerDescriptorHeap& g_SamplerDescriptorHeap [[buffer(1)]], + constant PushConstants& g_PushConstants [[buffer(4)]]) +{ + float4 color = interpolators.Color; + color *= PixelAntialiasing(interpolators.Position.xy - g_PushConstants.ProceduralOrigin, g_PushConstants); + + if (g_PushConstants.Texture2DDescriptorIndex != 0) + { + texture2d texture = g_Texture2DDescriptorHeap.g[g_PushConstants.Texture2DDescriptorIndex & 0x7FFFFFFF]; + + if ((g_PushConstants.Texture2DDescriptorIndex & 0x80000000) != 0) + { + if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_LOW_QUALITY_TEXT) + { + float scale; + float invScale; + + if ((g_PushConstants.DisplaySize.x * g_PushConstants.InverseDisplaySize.y) >= (4.0 / 3.0)) + { + scale = g_PushConstants.InverseDisplaySize.y * 720.0; + invScale = g_PushConstants.DisplaySize.y / 720.0; + } + else + { + scale = g_PushConstants.InverseDisplaySize.x * 960.0; + invScale = g_PushConstants.DisplaySize.x / 960.0; + } + + float2 lowQualityPosition = (interpolators.Position.xy - 0.5) * scale; + float2 fracPart = fract(lowQualityPosition); + + float2 uvStep = fwidth(interpolators.UV) * invScale; + float2 lowQualityUV = interpolators.UV - fracPart * uvStep; + float2 screenTexSize = 1.0 / uvStep; + + float4 topLeft = SampleSdfFont(color, texture, lowQualityUV + float2(0, 0), screenTexSize, g_SamplerDescriptorHeap, g_PushConstants); + float4 topRight = SampleSdfFont(color, texture, lowQualityUV + float2(uvStep.x, 0), screenTexSize, g_SamplerDescriptorHeap, g_PushConstants); + float4 bottomLeft = SampleSdfFont(color, texture, lowQualityUV + float2(0, uvStep.y), screenTexSize, g_SamplerDescriptorHeap, g_PushConstants); + float4 bottomRight = SampleSdfFont(color, texture, lowQualityUV + uvStep.xy, screenTexSize, g_SamplerDescriptorHeap, g_PushConstants); + + float4 top = mix(topLeft, topRight, fracPart.x); + float4 bottom = mix(bottomLeft, bottomRight, fracPart.x); + + color = mix(top, bottom, fracPart.y); + } + else + { + color = SampleSdfFont(color, texture, interpolators.UV, 1.0 / fwidth(interpolators.UV), g_SamplerDescriptorHeap, g_PushConstants); + } + } + else + { + color *= texture.sample(g_SamplerDescriptorHeap.g[0], interpolators.UV); + } + } + + if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_HORIZONTAL_MARQUEE_FADE) + { + float minAlpha = saturate((interpolators.Position.x - g_PushConstants.BoundsMin.x) / g_PushConstants.Scale.x); + float maxAlpha = saturate((g_PushConstants.BoundsMax.x - interpolators.Position.x) / g_PushConstants.Scale.y); + + color.a *= minAlpha; + color.a *= maxAlpha; + } + else if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_VERTICAL_MARQUEE_FADE) + { + float minAlpha = saturate((interpolators.Position.y - g_PushConstants.BoundsMin.y) / g_PushConstants.Scale.x); + float maxAlpha = saturate((g_PushConstants.BoundsMax.y - interpolators.Position.y) / g_PushConstants.Scale.y); + + color.a *= minAlpha; + color.a *= maxAlpha; + } + else if (any(g_PushConstants.BoundsMin != g_PushConstants.BoundsMax)) + { + float2 factor = saturate((interpolators.Position.xy - g_PushConstants.BoundsMin) / (g_PushConstants.BoundsMax - g_PushConstants.BoundsMin)); + + if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_RECTANGLE_BEVEL) + { + float bevelSize = 0.9; + + float shadow = saturate((factor.x - bevelSize) / (1.0 - bevelSize)); + shadow = max(shadow, saturate((factor.y - bevelSize) / (1.0 - bevelSize))); + + float rim = saturate((1.0 - factor.x - bevelSize) / (1.0 - bevelSize)); + rim = max(rim, saturate((1.0 - factor.y - bevelSize) / (1.0 - bevelSize))); + + float3 rimColor = float3(1, 0.8, 0.29); + float3 shadowColor = float3(0.84, 0.57, 0); + + color.rgb = mix(color.rgb, rimColor, smoothstep(0.0, 1.0, rim)); + color.rgb = mix(color.rgb, shadowColor, smoothstep(0.0, 1.0, shadow)); + } + else + { + float4 top = mix(DecodeColor(g_PushConstants.GradientTopLeft), DecodeColor(g_PushConstants.GradientTopRight), smoothstep(0.0, 1.0, factor.x)); + float4 bottom = mix(DecodeColor(g_PushConstants.GradientBottomLeft), DecodeColor(g_PushConstants.GradientBottomRight), smoothstep(0.0, 1.0, factor.x)); + color *= mix(top, bottom, smoothstep(0.0, 1.0, factor.y)); + } + } + + if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_GRAYSCALE) + color.rgb = dot(color.rgb, float3(0.2126, 0.7152, 0.0722)); + + return color; +} diff --git a/UnleashedRecomp/gpu/shader/msl/imgui_vs.metal b/UnleashedRecomp/gpu/shader/msl/imgui_vs.metal new file mode 100644 index 0000000..67a3288 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/imgui_vs.metal @@ -0,0 +1,32 @@ +#include "imgui_common.metali" + +struct VertexStageIn +{ + float2 position [[attribute(0)]]; + float2 uv [[attribute(1)]]; + float4 color [[attribute(2)]]; +}; + +[[vertex]] +Interpolators shaderMain(VertexStageIn input [[stage_in]], + constant PushConstants& g_PushConstants [[buffer(4)]]) +{ + Interpolators interpolators = Interpolators{}; + + if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_TEXT_SKEW) + { + if (input.position.y < g_PushConstants.Origin.y) + input.position.x += g_PushConstants.Scale.x; + } + else if (g_PushConstants.ShaderModifier != IMGUI_SHADER_MODIFIER_HORIZONTAL_MARQUEE_FADE && + g_PushConstants.ShaderModifier != IMGUI_SHADER_MODIFIER_VERTICAL_MARQUEE_FADE) + { + input.position.xy = g_PushConstants.Origin + (input.position.xy - g_PushConstants.Origin) * g_PushConstants.Scale; + } + + interpolators.Position = float4(input.position.xy * g_PushConstants.InverseDisplaySize * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0); + interpolators.UV = input.uv; + interpolators.Color = input.color; + + return interpolators; +} diff --git a/UnleashedRecomp/gpu/shader/msl/movie_common.metali b/UnleashedRecomp/gpu/shader/msl/movie_common.metali new file mode 100644 index 0000000..9193155 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/movie_common.metali @@ -0,0 +1,39 @@ +#pragma once + +#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h" + +#define fZmin (*(reinterpret_cast(g_PushConstants.PixelShaderConstants + 0))) +#define fZmax (*(reinterpret_cast(g_PushConstants.PixelShaderConstants + 16))) + +#define Tex0_ResourceDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 0))) +#define Tex1_ResourceDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 4))) +#define Tex2_ResourceDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 8))) +#define Tex3_ResourceDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 12))) +#define Tex4_ResourceDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 16))) + +#define Tex0_SamplerDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 64))) +#define Tex1_SamplerDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 68))) +#define Tex2_SamplerDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 72))) +#define Tex3_SamplerDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 76))) +#define Tex4_SamplerDescriptorIndex (*(reinterpret_cast(g_PushConstants.SharedConstants + 80))) + +#define bCsc (g_Booleans & (1 << (16 + 0))) +#define bAmv (g_Booleans & (1 << (16 + 1))) +#define bZmv (g_Booleans & (1 << (16 + 2))) + +struct VertexShaderInput +{ + float4 ObjPos [[attribute(0)]]; + float2 UV [[attribute(4)]]; +}; + +struct Interpolators +{ + float4 ProjPos [[position]]; + float2 UV; +}; + +struct PixelShaderOutput +{ + float4 Color [[color(0)]]; +}; diff --git a/UnleashedRecomp/gpu/shader/msl/movie_ps.metal b/UnleashedRecomp/gpu/shader/msl/movie_ps.metal new file mode 100644 index 0000000..e6288b2 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/movie_ps.metal @@ -0,0 +1,104 @@ +#include "movie_common.metali" + +[[fragment]] +PixelShaderOutput shaderMain(Interpolators In [[stage_in]], + constant Texture2DDescriptorHeap& g_Texture2DDescriptorHeap [[buffer(0)]], + constant SamplerDescriptorHeap& g_SamplerDescriptorHeap [[buffer(3)]], + constant PushConstants& g_PushConstants [[buffer(4)]]) +{ + texture2d Tex0 = g_Texture2DDescriptorHeap.g[Tex0_ResourceDescriptorIndex]; + texture2d Tex1 = g_Texture2DDescriptorHeap.g[Tex1_ResourceDescriptorIndex]; + texture2d Tex2 = g_Texture2DDescriptorHeap.g[Tex2_ResourceDescriptorIndex]; + texture2d Tex3 = g_Texture2DDescriptorHeap.g[Tex3_ResourceDescriptorIndex]; + texture2d Tex4 = g_Texture2DDescriptorHeap.g[Tex4_ResourceDescriptorIndex]; + + sampler Tex0_s = g_SamplerDescriptorHeap.g[Tex0_SamplerDescriptorIndex]; + sampler Tex1_s = g_SamplerDescriptorHeap.g[Tex1_SamplerDescriptorIndex]; + sampler Tex2_s = g_SamplerDescriptorHeap.g[Tex2_SamplerDescriptorIndex]; + sampler Tex3_s = g_SamplerDescriptorHeap.g[Tex3_SamplerDescriptorIndex]; + sampler Tex4_s = g_SamplerDescriptorHeap.g[Tex4_SamplerDescriptorIndex]; + + PixelShaderOutput Out; + float ValY = Tex0.sample(Tex0_s, In.UV).r; + float ValU = Tex1.sample(Tex1_s, In.UV).r - 0.5; + float ValV = Tex2.sample(Tex2_s, In.UV).r - 0.5; + float ValA = 1.0; + float ValD = 0.0; + if (bAmv) + ValA = (Tex3.sample(Tex3_s, In.UV).r - 0.0625) * 1.164; + if (bZmv) + { + ValD = (Tex4.sample(Tex4_s, In.UV).r - 0.0625) * 1.164; + if (ValD < 9.0 / 255.0) + { + ValD = 0.0; + } + else if (ValD < 17.0 / 255.0) + { + ValD = fZmin; + } + else if (ValD < 224.0 / 255.0) + { + ValD = (ValD - 17.0 / 255.0) / (223.0 / 255.0 - 17.0 / 255.0) * (fZmax - fZmin) + fZmin; + } + else if (ValD < 240.0 / 255.0) + { + ValD = fZmax; + } + else + { + ValD = 1.0; + } + } + if (bCsc) + { + if (ValY < 16.0 / 255.0) + { + ValY = ValY * 3.0 / 2.0; + } + else if (ValY < 176.0 / 255.0) + { + ValY = 24.0 / 255.0 + (ValY - 16.0 / 255.0) / 2.0; + } + else if (ValY < 192.0 / 255.0) + { + ValY = 104.0 / 255.0 + (ValY - 176.0 / 255.0) / 1.0; + } + else + { + ValY = 120.0 / 255.0 + (ValY - 192.0 / 255.0) * 2.0; + } + if (abs(ValU) < 24.0 / 255.0) + { + ValU /= 3.0; + } + else + { + ValU = (8.0 / 255.0 + (abs(ValU) - 24.0 / 255.0) * (120.0 / 104.0)) * sign(ValU); + } + if (abs(ValV) < 24.0 / 255.0) + { + ValV /= 3.0; + } + else + { + ValV = (8.0 / 255.0 + (abs(ValV) - 24.0 / 255.0) * (120.0 / 104.0)) * sign(ValV); + } + Out.Color.r = ValY + ValV * 1.402; + Out.Color.g = ValY - ValU * 0.344 - ValV * 0.714; + Out.Color.b = ValY + ValU * 1.772; + } + else + { + ValY = (ValY - 0.0625) * 1.164; + Out.Color.r = ValY + ValV * 1.596; + Out.Color.g = ValY - ValU * 0.392 - ValV * 0.813; + Out.Color.b = ValY + ValU * 2.017; + } + Out.Color.a = ValA; + + if (any(In.UV < 0.0) || any(In.UV > 1.0)) + Out.Color.rgb = 0.0; + + return Out; +} diff --git a/UnleashedRecomp/gpu/shader/msl/movie_vs.metal b/UnleashedRecomp/gpu/shader/msl/movie_vs.metal new file mode 100644 index 0000000..1583d23 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/movie_vs.metal @@ -0,0 +1,10 @@ +#include "movie_common.metali" + +[[vertex]] +Interpolators shaderMain(VertexShaderInput In [[stage_in]]) +{ + Interpolators Out; + Out.ProjPos = In.ObjPos; + Out.UV = In.UV; + return Out; +} diff --git a/UnleashedRecomp/gpu/shader/msl/resolve_msaa_color.metali b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_color.metali new file mode 100644 index 0000000..7064fa7 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_color.metali @@ -0,0 +1,21 @@ +#pragma once + +#include "copy_common.metali" + +struct Texture2DMSDescriptorHeap +{ + array, 1> g [[id(0)]]; +}; + +[[fragment]] +float4 shaderMain(float4 position [[position]], + constant Texture2DMSDescriptorHeap& g_Texture2DMSDescriptorHeap [[buffer(0)]], + constant PushConstants& g_PushConstants [[buffer(4)]]) +{ + float4 result = g_Texture2DMSDescriptorHeap.g[g_PushConstants.ResourceDescriptorIndex].read(uint2(position.xy), 0); + + for (int i = 1; i < SAMPLE_COUNT; i++) + result += g_Texture2DMSDescriptorHeap.g[g_PushConstants.ResourceDescriptorIndex].read(uint2(position.xy), i); + + return result / SAMPLE_COUNT; +} diff --git a/UnleashedRecomp/gpu/shader/msl/resolve_msaa_color_2x.metal b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_color_2x.metal new file mode 100644 index 0000000..6aa43bb --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_color_2x.metal @@ -0,0 +1,2 @@ +#define SAMPLE_COUNT 2 +#include "resolve_msaa_color.metali" diff --git a/UnleashedRecomp/gpu/shader/msl/resolve_msaa_color_4x.metal b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_color_4x.metal new file mode 100644 index 0000000..1787888 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_color_4x.metal @@ -0,0 +1,2 @@ +#define SAMPLE_COUNT 4 +#include "resolve_msaa_color.metali" diff --git a/UnleashedRecomp/gpu/shader/msl/resolve_msaa_color_8x.metal b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_color_8x.metal new file mode 100644 index 0000000..497f2ed --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_color_8x.metal @@ -0,0 +1,2 @@ +#define SAMPLE_COUNT 8 +#include "resolve_msaa_color.metali" diff --git a/UnleashedRecomp/gpu/shader/msl/resolve_msaa_depth.metali b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_depth.metali new file mode 100644 index 0000000..5017dd2 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_depth.metali @@ -0,0 +1,30 @@ +#pragma once + +#include "copy_common.metali" + +struct Texture2DMSDescriptorHeap +{ + array, 1> g [[id(0)]]; +}; + +struct PixelShaderOutput +{ + float oDepth [[depth(any)]]; +}; + +[[fragment]] +PixelShaderOutput shaderMain(float4 position [[position]], + constant Texture2DMSDescriptorHeap& g_Texture2DMSDescriptorHeap [[buffer(0)]], + constant PushConstants& g_PushConstants [[buffer(4)]]) +{ + PixelShaderOutput output = PixelShaderOutput{}; + + float result = g_Texture2DMSDescriptorHeap.g[g_PushConstants.ResourceDescriptorIndex].read(uint2(position.xy), 0).x; + + for (int i = 1; i < SAMPLE_COUNT; i++) + result = min(result, g_Texture2DMSDescriptorHeap.g[g_PushConstants.ResourceDescriptorIndex].read(uint2(position.xy), i).x); + + output.oDepth = result; + + return output; +} diff --git a/UnleashedRecomp/gpu/shader/msl/resolve_msaa_depth_2x.metal b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_depth_2x.metal new file mode 100644 index 0000000..cd3be17 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_depth_2x.metal @@ -0,0 +1,2 @@ +#define SAMPLE_COUNT 2 +#include "resolve_msaa_depth.metali" diff --git a/UnleashedRecomp/gpu/shader/msl/resolve_msaa_depth_4x.metal b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_depth_4x.metal new file mode 100644 index 0000000..e69b2c0 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_depth_4x.metal @@ -0,0 +1,2 @@ +#define SAMPLE_COUNT 4 +#include "resolve_msaa_depth.metali" diff --git a/UnleashedRecomp/gpu/shader/msl/resolve_msaa_depth_8x.metal b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_depth_8x.metal new file mode 100644 index 0000000..eaa42e5 --- /dev/null +++ b/UnleashedRecomp/gpu/shader/msl/resolve_msaa_depth_8x.metal @@ -0,0 +1,2 @@ +#define SAMPLE_COUNT 8 +#include "resolve_msaa_depth.metali" diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index faa4a87..c759b61 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -41,54 +41,80 @@ #include "../../tools/XenosRecomp/XenosRecomp/shader_common.h" #ifdef UNLEASHED_RECOMP_D3D12 -#include "shader/blend_color_alpha_ps.hlsl.dxil.h" -#include "shader/copy_vs.hlsl.dxil.h" -#include "shader/copy_color_ps.hlsl.dxil.h" -#include "shader/copy_depth_ps.hlsl.dxil.h" -#include "shader/csd_filter_ps.hlsl.dxil.h" -#include "shader/csd_no_tex_vs.hlsl.dxil.h" -#include "shader/csd_vs.hlsl.dxil.h" -#include "shader/enhanced_motion_blur_ps.hlsl.dxil.h" -#include "shader/gamma_correction_ps.hlsl.dxil.h" -#include "shader/gaussian_blur_3x3.hlsl.dxil.h" -#include "shader/gaussian_blur_5x5.hlsl.dxil.h" -#include "shader/gaussian_blur_7x7.hlsl.dxil.h" -#include "shader/gaussian_blur_9x9.hlsl.dxil.h" -#include "shader/imgui_ps.hlsl.dxil.h" -#include "shader/imgui_vs.hlsl.dxil.h" -#include "shader/movie_ps.hlsl.dxil.h" -#include "shader/movie_vs.hlsl.dxil.h" -#include "shader/resolve_msaa_color_2x.hlsl.dxil.h" -#include "shader/resolve_msaa_color_4x.hlsl.dxil.h" -#include "shader/resolve_msaa_color_8x.hlsl.dxil.h" -#include "shader/resolve_msaa_depth_2x.hlsl.dxil.h" -#include "shader/resolve_msaa_depth_4x.hlsl.dxil.h" -#include "shader/resolve_msaa_depth_8x.hlsl.dxil.h" +#include "shader/hlsl/blend_color_alpha_ps.hlsl.dxil.h" +#include "shader/hlsl/copy_vs.hlsl.dxil.h" +#include "shader/hlsl/copy_color_ps.hlsl.dxil.h" +#include "shader/hlsl/copy_depth_ps.hlsl.dxil.h" +#include "shader/hlsl/csd_filter_ps.hlsl.dxil.h" +#include "shader/hlsl/csd_no_tex_vs.hlsl.dxil.h" +#include "shader/hlsl/csd_vs.hlsl.dxil.h" +#include "shader/hlsl/enhanced_motion_blur_ps.hlsl.dxil.h" +#include "shader/hlsl/gamma_correction_ps.hlsl.dxil.h" +#include "shader/hlsl/gaussian_blur_3x3.hlsl.dxil.h" +#include "shader/hlsl/gaussian_blur_5x5.hlsl.dxil.h" +#include "shader/hlsl/gaussian_blur_7x7.hlsl.dxil.h" +#include "shader/hlsl/gaussian_blur_9x9.hlsl.dxil.h" +#include "shader/hlsl/imgui_ps.hlsl.dxil.h" +#include "shader/hlsl/imgui_vs.hlsl.dxil.h" +#include "shader/hlsl/movie_ps.hlsl.dxil.h" +#include "shader/hlsl/movie_vs.hlsl.dxil.h" +#include "shader/hlsl/resolve_msaa_color_2x.hlsl.dxil.h" +#include "shader/hlsl/resolve_msaa_color_4x.hlsl.dxil.h" +#include "shader/hlsl/resolve_msaa_color_8x.hlsl.dxil.h" +#include "shader/hlsl/resolve_msaa_depth_2x.hlsl.dxil.h" +#include "shader/hlsl/resolve_msaa_depth_4x.hlsl.dxil.h" +#include "shader/hlsl/resolve_msaa_depth_8x.hlsl.dxil.h" #endif -#include "shader/blend_color_alpha_ps.hlsl.spirv.h" -#include "shader/copy_vs.hlsl.spirv.h" -#include "shader/copy_color_ps.hlsl.spirv.h" -#include "shader/copy_depth_ps.hlsl.spirv.h" -#include "shader/csd_filter_ps.hlsl.spirv.h" -#include "shader/csd_no_tex_vs.hlsl.spirv.h" -#include "shader/csd_vs.hlsl.spirv.h" -#include "shader/enhanced_motion_blur_ps.hlsl.spirv.h" -#include "shader/gamma_correction_ps.hlsl.spirv.h" -#include "shader/gaussian_blur_3x3.hlsl.spirv.h" -#include "shader/gaussian_blur_5x5.hlsl.spirv.h" -#include "shader/gaussian_blur_7x7.hlsl.spirv.h" -#include "shader/gaussian_blur_9x9.hlsl.spirv.h" -#include "shader/imgui_ps.hlsl.spirv.h" -#include "shader/imgui_vs.hlsl.spirv.h" -#include "shader/movie_ps.hlsl.spirv.h" -#include "shader/movie_vs.hlsl.spirv.h" -#include "shader/resolve_msaa_color_2x.hlsl.spirv.h" -#include "shader/resolve_msaa_color_4x.hlsl.spirv.h" -#include "shader/resolve_msaa_color_8x.hlsl.spirv.h" -#include "shader/resolve_msaa_depth_2x.hlsl.spirv.h" -#include "shader/resolve_msaa_depth_4x.hlsl.spirv.h" -#include "shader/resolve_msaa_depth_8x.hlsl.spirv.h" +#ifdef UNLEASHED_RECOMP_METAL +#include "shader/msl/blend_color_alpha_ps.metal.metallib.h" +#include "shader/msl/copy_vs.metal.metallib.h" +#include "shader/msl/copy_color_ps.metal.metallib.h" +#include "shader/msl/copy_depth_ps.metal.metallib.h" +#include "shader/msl/csd_filter_ps.metal.metallib.h" +#include "shader/msl/csd_no_tex_vs.metal.metallib.h" +#include "shader/msl/csd_vs.metal.metallib.h" +#include "shader/msl/enhanced_motion_blur_ps.metal.metallib.h" +#include "shader/msl/gamma_correction_ps.metal.metallib.h" +#include "shader/msl/gaussian_blur_3x3.metal.metallib.h" +#include "shader/msl/gaussian_blur_5x5.metal.metallib.h" +#include "shader/msl/gaussian_blur_7x7.metal.metallib.h" +#include "shader/msl/gaussian_blur_9x9.metal.metallib.h" +#include "shader/msl/imgui_ps.metal.metallib.h" +#include "shader/msl/imgui_vs.metal.metallib.h" +#include "shader/msl/movie_ps.metal.metallib.h" +#include "shader/msl/movie_vs.metal.metallib.h" +#include "shader/msl/resolve_msaa_color_2x.metal.metallib.h" +#include "shader/msl/resolve_msaa_color_4x.metal.metallib.h" +#include "shader/msl/resolve_msaa_color_8x.metal.metallib.h" +#include "shader/msl/resolve_msaa_depth_2x.metal.metallib.h" +#include "shader/msl/resolve_msaa_depth_4x.metal.metallib.h" +#include "shader/msl/resolve_msaa_depth_8x.metal.metallib.h" +#endif + +#include "shader/hlsl/blend_color_alpha_ps.hlsl.spirv.h" +#include "shader/hlsl/copy_vs.hlsl.spirv.h" +#include "shader/hlsl/copy_color_ps.hlsl.spirv.h" +#include "shader/hlsl/copy_depth_ps.hlsl.spirv.h" +#include "shader/hlsl/csd_filter_ps.hlsl.spirv.h" +#include "shader/hlsl/csd_no_tex_vs.hlsl.spirv.h" +#include "shader/hlsl/csd_vs.hlsl.spirv.h" +#include "shader/hlsl/enhanced_motion_blur_ps.hlsl.spirv.h" +#include "shader/hlsl/gamma_correction_ps.hlsl.spirv.h" +#include "shader/hlsl/gaussian_blur_3x3.hlsl.spirv.h" +#include "shader/hlsl/gaussian_blur_5x5.hlsl.spirv.h" +#include "shader/hlsl/gaussian_blur_7x7.hlsl.spirv.h" +#include "shader/hlsl/gaussian_blur_9x9.hlsl.spirv.h" +#include "shader/hlsl/imgui_ps.hlsl.spirv.h" +#include "shader/hlsl/imgui_vs.hlsl.spirv.h" +#include "shader/hlsl/movie_ps.hlsl.spirv.h" +#include "shader/hlsl/movie_vs.hlsl.spirv.h" +#include "shader/hlsl/resolve_msaa_color_2x.hlsl.spirv.h" +#include "shader/hlsl/resolve_msaa_color_4x.hlsl.spirv.h" +#include "shader/hlsl/resolve_msaa_color_8x.hlsl.spirv.h" +#include "shader/hlsl/resolve_msaa_depth_2x.hlsl.spirv.h" +#include "shader/hlsl/resolve_msaa_depth_4x.hlsl.spirv.h" +#include "shader/hlsl/resolve_msaa_depth_8x.hlsl.spirv.h" #ifdef _WIN32 extern "C" @@ -3858,7 +3884,7 @@ static RenderShader* GetOrLinkShader(GuestShader* guestShader, uint32_t specCons bool result = smolv::Decode(compressedSpirvData, guestShader->shaderCacheEntry->spirvSize, decoded.data(), decoded.size()); assert(result); - guestShader->shader = g_device->createShader(decoded.data(), decoded.size(), "main", RenderShaderFormat::SPIRV); + guestShader->shader = g_device->createShader(decoded.data(), decoded.size(), "shaderMain", RenderShaderFormat::SPIRV); } else {