From c05b2d0b4831d5e7f84caaa7856c5077ca2c985a Mon Sep 17 00:00:00 2001 From: Samuliak Date: Thu, 22 Aug 2024 15:02:49 +0200 Subject: [PATCH] don't stringify shader source & move vertex buffer bindings by 1 --- src/Cafe/HW/Latte/Renderer/Metal/MetalCommon.h | 6 +++--- src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp | 11 +---------- .../HW/Latte/Renderer/Metal/UtilityShaderSource.h | 11 +++++++++-- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalCommon.h b/src/Cafe/HW/Latte/Renderer/Metal/MetalCommon.h index 84956786..44d4d873 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalCommon.h +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalCommon.h @@ -21,13 +21,13 @@ struct MetalPixelFormatSupport }; #define MAX_MTL_BUFFERS 31 -// Buffer index 30 is reserved for the support buffer, buffer indices 27-29 are reserved for the helper shaders -#define GET_MTL_VERTEX_BUFFER_INDEX(index) (MAX_MTL_BUFFERS - index - 5) +// Buffer indices 28-30 are reserved for the helper shaders +#define GET_MTL_VERTEX_BUFFER_INDEX(index) (MAX_MTL_BUFFERS - index - 4) #define MAX_MTL_TEXTURES 31 #define MAX_MTL_SAMPLERS 16 -#define GET_HELPER_BUFFER_BINDING(index) (27 + index) +#define GET_HELPER_BUFFER_BINDING(index) (28 + index) #define GET_HELPER_TEXTURE_BINDING(index) (29 + index) #define GET_HELPER_SAMPLER_BINDING(index) (14 + index) diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp index 1996ff46..7604406f 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp @@ -17,11 +17,8 @@ #include "Cafe/HW/Latte/Core/LatteShader.h" #include "Cafe/HW/Latte/Core/LatteIndices.h" #include "Cemu/Logging/CemuDebugLogging.h" -#include "Common/precompiled.h" #include "HW/Latte/Core/LatteConst.h" #include "HW/Latte/Renderer/Metal/MetalCommon.h" -#include "Metal/MTLDevice.hpp" -#include "Metal/MTLRenderCommandEncoder.hpp" #include "gui/guiWrapper.h" #define COMMIT_TRESHOLD 256 @@ -98,15 +95,9 @@ MetalRenderer::MetalRenderer() // Utility shader library - // Process the source first - std::string processedUtilityShaderSource = utilityShaderSource; - processedUtilityShaderSource.pop_back(); - processedUtilityShaderSource.erase(processedUtilityShaderSource.begin()); - processedUtilityShaderSource = "#include \nusing namespace metal;\n#define GET_BUFFER_BINDING(index) (27 + index)\n#define GET_TEXTURE_BINDING(index) (29 + index)\n#define GET_SAMPLER_BINDING(index) (14 + index)\n" + processedUtilityShaderSource; - // Create the library NS::Error* error = nullptr; - MTL::Library* utilityLibrary = m_device->newLibrary(ToNSString(processedUtilityShaderSource.c_str()), nullptr, &error); + MTL::Library* utilityLibrary = m_device->newLibrary(ToNSString(utilityShaderSource), nullptr, &error); if (error) { debug_printf("failed to create utility library (error: %s)\n", error->localizedDescription()->utf8String()); diff --git a/src/Cafe/HW/Latte/Renderer/Metal/UtilityShaderSource.h b/src/Cafe/HW/Latte/Renderer/Metal/UtilityShaderSource.h index c298150e..7f8f3dc7 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/UtilityShaderSource.h +++ b/src/Cafe/HW/Latte/Renderer/Metal/UtilityShaderSource.h @@ -3,7 +3,14 @@ #define __STRINGIFY(x) #x #define _STRINGIFY(x) __STRINGIFY(x) -constexpr const char* utilityShaderSource = _STRINGIFY(( +constexpr const char* utilityShaderSource = R"V0G0N( +#include +using namespace metal; + +#define GET_BUFFER_BINDING(index) (28 + index) +#define GET_TEXTURE_BINDING(index) (29 + index) +#define GET_SAMPLER_BINDING(index) (14 + index)\n + constant float2 positions[] = {float2(-1.0, -3.0), float2(-1.0, 1.0), float2(3.0, 1.0)}; struct VertexOut { @@ -48,4 +55,4 @@ vertex void vertexRestrideBuffer(uint vid [[vertex_id]], device uint8_t* src [[b dst[vid * params.newStride + i] = src[vid * params.oldStride + i]; } } -)); +)V0G0N";