mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-30 01:29:42 -06:00
VideoBackends:Metal: Support multiple compute textures
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
|
||||
#include "Common/MsgHandler.h"
|
||||
|
||||
#include "VideoCommon/Constants.h"
|
||||
#include "VideoCommon/DriverDetails.h"
|
||||
#include "VideoCommon/Spirv.h"
|
||||
|
||||
@ -365,10 +366,10 @@ static const std::string_view COMPUTE_SHADER_HEADER = R"(
|
||||
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require
|
||||
#extension GL_EXT_shader_explicit_arithmetic_types_int16 : require
|
||||
|
||||
// All resources are packed into one descriptor set for compute.
|
||||
#define UBO_BINDING(packing, x) layout(packing, set = 0, binding = (x - 1))
|
||||
#define SAMPLER_BINDING(x) layout(set = 1, binding = x)
|
||||
#define SSBO_BINDING(x) layout(std430, set = 2, binding = x)
|
||||
#define IMAGE_BINDING(format, x) layout(format, set = 1, binding = x)
|
||||
#define IMAGE_BINDING(format, x) layout(format, set = 3, binding = x)
|
||||
|
||||
// hlsl to glsl function translation
|
||||
#define API_METAL 1
|
||||
@ -462,20 +463,13 @@ std::optional<std::string> Metal::Util::TranslateShaderToMSL(ShaderStage stage,
|
||||
MakeResourceBinding(spv::ExecutionModelVertex, 2, 1, 0, 0, 0), // vs/ssbo
|
||||
MakeResourceBinding(spv::ExecutionModelFragment, 0, 0, 0, 0, 0), // vs/ubo
|
||||
MakeResourceBinding(spv::ExecutionModelFragment, 0, 1, 1, 0, 0), // vs/ubo
|
||||
MakeResourceBinding(spv::ExecutionModelFragment, 1, 0, 0, 0, 0), // ps/samp0
|
||||
MakeResourceBinding(spv::ExecutionModelFragment, 1, 1, 0, 1, 1), // ps/samp1
|
||||
MakeResourceBinding(spv::ExecutionModelFragment, 1, 2, 0, 2, 2), // ps/samp2
|
||||
MakeResourceBinding(spv::ExecutionModelFragment, 1, 3, 0, 3, 3), // ps/samp3
|
||||
MakeResourceBinding(spv::ExecutionModelFragment, 1, 4, 0, 4, 4), // ps/samp4
|
||||
MakeResourceBinding(spv::ExecutionModelFragment, 1, 5, 0, 5, 5), // ps/samp5
|
||||
MakeResourceBinding(spv::ExecutionModelFragment, 1, 6, 0, 6, 6), // ps/samp6
|
||||
MakeResourceBinding(spv::ExecutionModelFragment, 1, 7, 0, 7, 7), // ps/samp7
|
||||
MakeResourceBinding(spv::ExecutionModelFragment, 1, 8, 0, 8, 8), // ps/samp8
|
||||
// Dynamic list initialized below Fragment, 1, N, 0, N, N // ps/samp0-N
|
||||
MakeResourceBinding(spv::ExecutionModelFragment, 2, 0, 2, 0, 0), // ps/ssbo
|
||||
MakeResourceBinding(spv::ExecutionModelGLCompute, 0, 1, 0, 0, 0), // cs/ubo
|
||||
MakeResourceBinding(spv::ExecutionModelGLCompute, 1, 0, 0, 0, 0), // cs/output_image
|
||||
// Dynamic list initialized below GLCompute, 1, N, 0, N, N, // cs/samp0-N
|
||||
MakeResourceBinding(spv::ExecutionModelGLCompute, 2, 0, 2, 0, 0), // cs/ssbo
|
||||
MakeResourceBinding(spv::ExecutionModelGLCompute, 2, 1, 3, 0, 0), // cs/ssbo
|
||||
// Dynamic list initialized below GLCompute, 3, N, 0, N, 0, // cs/img0-N
|
||||
};
|
||||
|
||||
spirv_cross::CompilerMSL::Options options;
|
||||
@ -503,6 +497,29 @@ std::optional<std::string> Metal::Util::TranslateShaderToMSL(ShaderStage stage,
|
||||
|
||||
for (auto& binding : resource_bindings)
|
||||
compiler.add_msl_resource_binding(binding);
|
||||
if (stage == ShaderStage::Pixel)
|
||||
{
|
||||
for (u32 i = 0; i < VideoCommon::MAX_PIXEL_SHADER_SAMPLERS; i++) // ps/samp0-N
|
||||
{
|
||||
compiler.add_msl_resource_binding(
|
||||
MakeResourceBinding(spv::ExecutionModelFragment, 1, i, 0, i, i));
|
||||
}
|
||||
}
|
||||
else if (stage == ShaderStage::Compute)
|
||||
{
|
||||
u32 img = 0;
|
||||
u32 smp = 0;
|
||||
for (u32 i = 0; i < VideoCommon::MAX_COMPUTE_SHADER_SAMPLERS; i++) // cs/samp0-N
|
||||
{
|
||||
compiler.add_msl_resource_binding(
|
||||
MakeResourceBinding(spv::ExecutionModelGLCompute, 1, i, 0, img++, smp++));
|
||||
}
|
||||
for (u32 i = 0; i < VideoCommon::MAX_COMPUTE_SHADER_SAMPLERS; i++) // cs/img0-N
|
||||
{
|
||||
compiler.add_msl_resource_binding(
|
||||
MakeResourceBinding(spv::ExecutionModelGLCompute, 3, i, 0, img++, 0));
|
||||
}
|
||||
}
|
||||
|
||||
std::string output(MSL_HEADER);
|
||||
std::string compiled = compiler.compile();
|
||||
|
Reference in New Issue
Block a user