mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-01-20 07:15:38 +00:00
MetalDevice: Explicitly bind fragment resources
Fixes adaptive downsampling with Metal renderer.
This commit is contained in:
parent
6fe2177ee7
commit
f4fb069216
|
@ -638,7 +638,7 @@ std::unique_ptr<GPUShader> MetalDevice::CreateShaderFromSource(GPUShaderStage st
|
|||
return {};
|
||||
}
|
||||
|
||||
std::optional<std::string> msl = SPIRVCompiler::CompileSPIRVToMSL(spirv.value());
|
||||
std::optional<std::string> msl = SPIRVCompiler::CompileSPIRVToMSL(stage, spirv.value());
|
||||
if (!msl.has_value())
|
||||
{
|
||||
Log_ErrorPrintf("Failed to compile SPIR-V to MSL.");
|
||||
|
|
|
@ -336,8 +336,8 @@ void ShaderGen::DeclareTexture(std::stringstream& ss, const char* name, u32 inde
|
|||
{
|
||||
if (m_glsl)
|
||||
{
|
||||
if (IsVulkan())
|
||||
ss << "layout(set = " << (m_has_uniform_buffer ? 1 : 0) << ", binding = " << index << ") ";
|
||||
if (m_spirv)
|
||||
ss << "layout(set = " << ((m_has_uniform_buffer || IsMetal()) ? 1 : 0) << ", binding = " << index << ") ";
|
||||
else if (m_use_glsl_binding_layout)
|
||||
ss << "layout(binding = " << index << ") ";
|
||||
|
||||
|
@ -354,8 +354,8 @@ void ShaderGen::DeclareTextureBuffer(std::stringstream& ss, const char* name, u3
|
|||
{
|
||||
if (m_glsl)
|
||||
{
|
||||
if (IsVulkan())
|
||||
ss << "layout(set = 0, binding = " << index << ") ";
|
||||
if (m_spirv)
|
||||
ss << "layout(set = " << ((m_has_uniform_buffer || IsMetal()) ? 1 : 0) << ", binding = " << index << ") ";
|
||||
else if (m_use_glsl_binding_layout)
|
||||
ss << "layout(binding = " << index << ") ";
|
||||
|
||||
|
|
|
@ -173,12 +173,29 @@ std::optional<SPIRVCompiler::SPIRVCodeVector> SPIRVCompiler::CompileShader(GPUSh
|
|||
|
||||
#ifdef __APPLE__
|
||||
|
||||
std::optional<std::string> SPIRVCompiler::CompileSPIRVToMSL(std::span<const SPIRVCodeType> spv)
|
||||
std::optional<std::string> SPIRVCompiler::CompileSPIRVToMSL(GPUShaderStage stage, std::span<const SPIRVCodeType> spv)
|
||||
{
|
||||
spirv_cross::CompilerMSL compiler(spv.data(), spv.size());
|
||||
|
||||
spirv_cross::CompilerMSL::Options options = compiler.get_msl_options();
|
||||
options.pad_fragment_output_components = true;
|
||||
|
||||
if (stage == GPUShaderStage::Fragment)
|
||||
{
|
||||
for (u32 i = 0; i < GPUDevice::MAX_TEXTURE_SAMPLERS; i++)
|
||||
{
|
||||
spirv_cross::MSLResourceBinding rb;
|
||||
rb.stage = spv::ExecutionModelFragment;
|
||||
rb.desc_set = 1;
|
||||
rb.binding = i;
|
||||
rb.count = 1;
|
||||
rb.msl_texture = i;
|
||||
rb.msl_sampler = i;
|
||||
rb.msl_buffer = i;
|
||||
compiler.add_msl_resource_binding(rb);
|
||||
}
|
||||
}
|
||||
|
||||
compiler.set_msl_options(options);
|
||||
|
||||
std::string msl = compiler.compile();
|
||||
|
|
|
@ -42,7 +42,7 @@ std::optional<SPIRVCodeVector> CompileShader(GPUShaderStage stage, std::string_v
|
|||
#ifdef __APPLE__
|
||||
|
||||
// Converts a SPIR-V shader into MSL.
|
||||
std::optional<std::string> CompileSPIRVToMSL(std::span<const SPIRVCodeType> spv);
|
||||
std::optional<std::string> CompileSPIRVToMSL(GPUShaderStage stage, std::span<const SPIRVCodeType> spv);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in a new issue