mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-01-23 07:11:12 +01:00
fix: texture bindings
This commit is contained in:
parent
5030a2e84a
commit
f11526a244
@ -2193,7 +2193,7 @@ static void _emitTEXSampleTextureCode(LatteDecompilerShaderContext* shaderContex
|
|||||||
src->add(".");
|
src->add(".");
|
||||||
const char* resultElemTable[4] = {"x","y","z","w"};
|
const char* resultElemTable[4] = {"x","y","z","w"};
|
||||||
sint32 numWrittenElements = 0;
|
sint32 numWrittenElements = 0;
|
||||||
for(sint32 f=0; f<4; f++)
|
for(sint32 f = 0; f < 4; f++)
|
||||||
{
|
{
|
||||||
if( texInstruction->dstSel[f] < 4 )
|
if( texInstruction->dstSel[f] < 4 )
|
||||||
{
|
{
|
||||||
@ -2493,18 +2493,21 @@ static void _emitTEXSampleTextureCode(LatteDecompilerShaderContext* shaderContex
|
|||||||
// lod bias
|
// lod bias
|
||||||
if( texOpcode == GPU7_TEX_INST_SAMPLE_C || texOpcode == GPU7_TEX_INST_SAMPLE_C_LZ )
|
if( texOpcode == GPU7_TEX_INST_SAMPLE_C || texOpcode == GPU7_TEX_INST_SAMPLE_C_LZ )
|
||||||
{
|
{
|
||||||
src->add(")");
|
src->add(").");
|
||||||
|
|
||||||
if (numWrittenElements > 1)
|
if (numWrittenElements > 1)
|
||||||
{
|
{
|
||||||
// result is copied into multiple channels
|
// result is copied into multiple channels
|
||||||
src->add(".");
|
|
||||||
for (sint32 f = 0; f < numWrittenElements; f++)
|
for (sint32 f = 0; f < numWrittenElements; f++)
|
||||||
{
|
{
|
||||||
cemu_assert_debug(texInstruction->dstSel[f] == 0); // only x component is defined
|
cemu_assert_debug(texInstruction->dstSel[f] == 0); // only x component is defined
|
||||||
src->add("x");
|
src->add("x");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
src->add("x");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,6 @@ namespace LatteDecompiler
|
|||||||
{
|
{
|
||||||
auto src = decompilerContext->shaderSource;
|
auto src = decompilerContext->shaderSource;
|
||||||
|
|
||||||
LatteDecompilerShaderResourceMapping& resourceMapping = decompilerContext->output->resourceMappingGL;
|
|
||||||
auto& uniformOffsets = decompilerContext->output->uniformOffsetsVK;
|
auto& uniformOffsets = decompilerContext->output->uniformOffsetsVK;
|
||||||
|
|
||||||
src->add("struct SupportBuffer {" _CRLF);
|
src->add("struct SupportBuffer {" _CRLF);
|
||||||
@ -129,11 +128,8 @@ namespace LatteDecompiler
|
|||||||
if (!decompilerContext->analyzer.uniformBufferAccessTracker[i].HasAccess())
|
if (!decompilerContext->analyzer.uniformBufferAccessTracker[i].HasAccess())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
cemu_assert_debug(decompilerContext->output->resourceMappingGL.uniformBuffersBindingPoint[i] >= 0);
|
|
||||||
cemu_assert_debug(decompilerContext->output->resourceMappingVK.uniformBuffersBindingPoint[i] >= 0);
|
cemu_assert_debug(decompilerContext->output->resourceMappingVK.uniformBuffersBindingPoint[i] >= 0);
|
||||||
|
|
||||||
//shaderSrc->addFmt("UNIFORM_BUFFER_LAYOUT({}, {}, {}) ", (sint32)decompilerContext->output->resourceMappingGL.uniformBuffersBindingPoint[i], (sint32)decompilerContext->output->resourceMappingVK.setIndex, (sint32)decompilerContext->output->resourceMappingVK.uniformBuffersBindingPoint[i]);
|
|
||||||
|
|
||||||
shaderSrc->addFmt("struct UBuff{} {{" _CRLF, i);
|
shaderSrc->addFmt("struct UBuff{} {{" _CRLF, i);
|
||||||
shaderSrc->addFmt("float4 d[{}];" _CRLF, decompilerContext->analyzer.uniformBufferAccessTracker[i].DetermineSize(decompilerContext->shaderBaseHash, LATTE_GLSL_DYNAMIC_UNIFORM_BLOCK_SIZE));
|
shaderSrc->addFmt("float4 d[{}];" _CRLF, decompilerContext->analyzer.uniformBufferAccessTracker[i].DetermineSize(decompilerContext->shaderBaseHash, LATTE_GLSL_DYNAMIC_UNIFORM_BLOCK_SIZE));
|
||||||
shaderSrc->add("};" _CRLF _CRLF);
|
shaderSrc->add("};" _CRLF _CRLF);
|
||||||
@ -169,9 +165,7 @@ namespace LatteDecompiler
|
|||||||
{
|
{
|
||||||
if (decompilerContext->analyzer.inputAttributSemanticMask[i])
|
if (decompilerContext->analyzer.inputAttributSemanticMask[i])
|
||||||
{
|
{
|
||||||
cemu_assert_debug(decompilerContext->output->resourceMappingGL.attributeMapping[i] >= 0);
|
|
||||||
cemu_assert_debug(decompilerContext->output->resourceMappingVK.attributeMapping[i] >= 0);
|
cemu_assert_debug(decompilerContext->output->resourceMappingVK.attributeMapping[i] >= 0);
|
||||||
cemu_assert_debug(decompilerContext->output->resourceMappingGL.attributeMapping[i] == decompilerContext->output->resourceMappingVK.attributeMapping[i]);
|
|
||||||
|
|
||||||
src->addFmt("uint4 attrDataSem{} [[attribute({})]];" _CRLF, i, (sint32)decompilerContext->output->resourceMappingVK.attributeMapping[i]);
|
src->addFmt("uint4 attrDataSem{} [[attribute({})]];" _CRLF, i, (sint32)decompilerContext->output->resourceMappingVK.attributeMapping[i]);
|
||||||
}
|
}
|
||||||
@ -304,10 +298,9 @@ namespace LatteDecompiler
|
|||||||
if (!decompilerContext->analyzer.uniformBufferAccessTracker[i].HasAccess())
|
if (!decompilerContext->analyzer.uniformBufferAccessTracker[i].HasAccess())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
cemu_assert_debug(decompilerContext->output->resourceMappingGL.uniformBuffersBindingPoint[i] >= 0);
|
|
||||||
cemu_assert_debug(decompilerContext->output->resourceMappingVK.uniformBuffersBindingPoint[i] >= 0);
|
cemu_assert_debug(decompilerContext->output->resourceMappingVK.uniformBuffersBindingPoint[i] >= 0);
|
||||||
|
|
||||||
src->addFmt(", constant UBuff{}& ubuff{} [[buffer({})]]", i, i, (sint32)decompilerContext->output->resourceMappingGL.uniformBuffersBindingPoint[i]);
|
src->addFmt(", constant UBuff{}& ubuff{} [[buffer({})]]", i, i, (sint32)decompilerContext->output->resourceMappingVK.uniformBuffersBindingPoint[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -348,11 +341,11 @@ namespace LatteDecompiler
|
|||||||
cemu_assert_unimplemented();
|
cemu_assert_unimplemented();
|
||||||
}
|
}
|
||||||
|
|
||||||
// HACK
|
uint32 binding = shaderContext->output->resourceMappingVK.textureUnitToBindingPoint[i];
|
||||||
uint32 textureBinding = shaderContext->output->resourceMappingGL.textureUnitToBindingPoint[i] % 31;
|
//uint32 textureBinding = shaderContext->output->resourceMappingVK.textureUnitToBindingPoint[i] % 31;
|
||||||
uint32 samplerBinding = textureBinding % 16;
|
//uint32 samplerBinding = textureBinding % 16;
|
||||||
src->addFmt(" tex{} [[texture({})]]", i, textureBinding);
|
src->addFmt(" tex{} [[texture({})]]", i, binding);
|
||||||
src->addFmt(", sampler samplr{} [[sampler({})]]", i, samplerBinding);
|
src->addFmt(", sampler samplr{} [[sampler({})]]", i, binding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,9 +107,10 @@ void MetalRenderer::Shutdown()
|
|||||||
CommitCommandBuffer();
|
CommitCommandBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: what should this do?
|
||||||
bool MetalRenderer::IsPadWindowActive()
|
bool MetalRenderer::IsPadWindowActive()
|
||||||
{
|
{
|
||||||
debug_printf("MetalRenderer::IsPadWindowActive not implemented\n");
|
//debug_printf("MetalRenderer::IsPadWindowActive not implemented\n");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -805,6 +806,23 @@ void MetalRenderer::BindStageResources(MTL::RenderCommandEncoder* renderCommandE
|
|||||||
auto hostTextureUnit = relative_textureUnit;
|
auto hostTextureUnit = relative_textureUnit;
|
||||||
auto textureDim = shader->textureUnitDim[relative_textureUnit];
|
auto textureDim = shader->textureUnitDim[relative_textureUnit];
|
||||||
auto texUnitRegIndex = hostTextureUnit * 7;
|
auto texUnitRegIndex = hostTextureUnit * 7;
|
||||||
|
switch (shader->shaderType)
|
||||||
|
{
|
||||||
|
case LatteConst::ShaderType::Vertex:
|
||||||
|
hostTextureUnit += LATTE_CEMU_VS_TEX_UNIT_BASE;
|
||||||
|
texUnitRegIndex += Latte::REGADDR::SQ_TEX_RESOURCE_WORD0_N_VS;
|
||||||
|
break;
|
||||||
|
case LatteConst::ShaderType::Pixel:
|
||||||
|
hostTextureUnit += LATTE_CEMU_PS_TEX_UNIT_BASE;
|
||||||
|
texUnitRegIndex += Latte::REGADDR::SQ_TEX_RESOURCE_WORD0_N_PS;
|
||||||
|
break;
|
||||||
|
case LatteConst::ShaderType::Geometry:
|
||||||
|
hostTextureUnit += LATTE_CEMU_GS_TEX_UNIT_BASE;
|
||||||
|
texUnitRegIndex += Latte::REGADDR::SQ_TEX_RESOURCE_WORD0_N_GS;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
UNREACHABLE;
|
||||||
|
}
|
||||||
|
|
||||||
auto textureView = m_state.textures[hostTextureUnit];
|
auto textureView = m_state.textures[hostTextureUnit];
|
||||||
if (!textureView)
|
if (!textureView)
|
||||||
@ -821,9 +839,15 @@ void MetalRenderer::BindStageResources(MTL::RenderCommandEncoder* renderCommandE
|
|||||||
//auto imageViewObj = textureView->GetSamplerView(word4);
|
//auto imageViewObj = textureView->GetSamplerView(word4);
|
||||||
//info.imageView = imageViewObj->m_textureImageView;
|
//info.imageView = imageViewObj->m_textureImageView;
|
||||||
|
|
||||||
// HACK
|
// TODO: uncomment
|
||||||
uint32 textureBinding = (shader->resourceMapping.getTextureBaseBindingPoint() + i) % MAX_MTL_TEXTURES;
|
uint32 binding = shader->resourceMapping.getTextureBaseBindingPoint() + i;//shader->resourceMapping.textureUnitToBindingPoint[hostTextureUnit];
|
||||||
uint32 samplerBinding = textureBinding % MAX_MTL_SAMPLERS;
|
//uint32 textureBinding = binding % MAX_MTL_TEXTURES;
|
||||||
|
//uint32 samplerBinding = binding % MAX_MTL_SAMPLERS;
|
||||||
|
if (binding >= MAX_MTL_TEXTURES)
|
||||||
|
{
|
||||||
|
debug_printf("invalid texture binding %u\n", binding);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
uint32 stageSamplerIndex = shader->textureUnitSamplerAssignment[relative_textureUnit];
|
uint32 stageSamplerIndex = shader->textureUnitSamplerAssignment[relative_textureUnit];
|
||||||
if (stageSamplerIndex != LATTE_DECOMPILER_SAMPLER_NONE)
|
if (stageSamplerIndex != LATTE_DECOMPILER_SAMPLER_NONE)
|
||||||
@ -934,12 +958,12 @@ void MetalRenderer::BindStageResources(MTL::RenderCommandEncoder* renderCommandE
|
|||||||
{
|
{
|
||||||
case LatteConst::ShaderType::Vertex:
|
case LatteConst::ShaderType::Vertex:
|
||||||
{
|
{
|
||||||
renderCommandEncoder->setVertexSamplerState(sampler, samplerBinding);
|
renderCommandEncoder->setVertexSamplerState(sampler, binding);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LatteConst::ShaderType::Pixel:
|
case LatteConst::ShaderType::Pixel:
|
||||||
{
|
{
|
||||||
renderCommandEncoder->setFragmentSamplerState(sampler, samplerBinding);
|
renderCommandEncoder->setFragmentSamplerState(sampler, binding);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -952,12 +976,12 @@ void MetalRenderer::BindStageResources(MTL::RenderCommandEncoder* renderCommandE
|
|||||||
{
|
{
|
||||||
case LatteConst::ShaderType::Vertex:
|
case LatteConst::ShaderType::Vertex:
|
||||||
{
|
{
|
||||||
renderCommandEncoder->setVertexTexture(textureView->GetTexture(), textureBinding);
|
renderCommandEncoder->setVertexTexture(textureView->GetTexture(), binding);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LatteConst::ShaderType::Pixel:
|
case LatteConst::ShaderType::Pixel:
|
||||||
{
|
{
|
||||||
renderCommandEncoder->setFragmentTexture(textureView->GetTexture(), textureBinding);
|
renderCommandEncoder->setFragmentTexture(textureView->GetTexture(), binding);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user