Skip to content

Commit d64e64e

Browse files
committed
fix: texture updates and buffer bindings
1 parent f11526a commit d64e64e

File tree

5 files changed

+46
-30
lines changed

5 files changed

+46
-30
lines changed

src/Cafe/HW/Latte/Core/LatteTexture.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void LatteTexture_UnregisterTextureMemoryOccupancy(LatteTexture* texture)
170170
}
171171

172172
// calculate the actually accessed data range
173-
// the resulting range is an estimate and may be smaller than the actual slice size (but not larger)
173+
// the resulting range is an estimate and may be smaller than the actual slice size (but not larger)
174174
void LatteTexture_EstimateMipSliceAccessedDataRange(LatteTexture* texture, sint32 sliceIndex, sint32 mipIndex, LatteTextureSliceMipInfo* sliceMipInfo)
175175
{
176176
uint32 estAddrStart;
@@ -222,7 +222,7 @@ void LatteTexture_InitSliceAndMipInfo(LatteTexture* texture)
222222
LatteAddrLib::AddrSurfaceInfo_OUT surfaceInfo;
223223
LatteAddrLib::GX2CalculateSurfaceInfo(texture->format, texture->width, texture->height, texture->depth, texture->dim, Latte::MakeGX2TileMode(texture->tileMode), 0, mipIndex, &surfaceInfo);
224224
sliceMipInfo->tileMode = surfaceInfo.hwTileMode;
225-
225+
226226
if (mipIndex == 0)
227227
sliceMipInfo->pitch = texture->pitch; // for the base level, use the pitch value configured in hardware
228228
else
@@ -352,6 +352,7 @@ void LatteTexture_CopySlice(LatteTexture* srcTexture, sint32 srcSlice, sint32 sr
352352
if (srcTexture->isDepth != dstTexture->isDepth)
353353
{
354354
g_renderer->surfaceCopy_copySurfaceWithFormatConversion(srcTexture, srcMip, srcSlice, dstTexture, dstMip, dstSlice, width, height);
355+
throw std::runtime_error("1");
355356
return;
356357
}
357358
// rescale copy size
@@ -384,6 +385,7 @@ void LatteTexture_CopySlice(LatteTexture* srcTexture, sint32 srcSlice, sint32 sr
384385
cemuLog_log(LogType::Force, "Source: {:08x} origResolution {:4}/{:4} effectiveResolution {:4}/{:4} fmt {:04x} mipIndex {} ratioW/H: {:.4}/{:.4}", srcTexture->physAddress, srcTexture->width, srcTexture->height, effectiveWidth_src, effectiveHeight_src, (uint32)srcTexture->format, srcMip, ratioWidth_src, ratioHeight_src);
385386
cemuLog_log(LogType::Force, "Destination: {:08x} origResolution {:4}/{:4} effectiveResolution {:4}/{:4} fmt {:04x} mipIndex {} ratioW/H: {:.4}/{:.4}", dstTexture->physAddress, dstTexture->width, dstTexture->height, effectiveWidth_dst, effectiveHeight_dst, (uint32)dstTexture->format, dstMip, ratioWidth_dst, ratioHeight_dst);
386387
}
388+
throw std::runtime_error("2");
387389
//cemuLog_logDebug(LogType::Force, "If these textures are not meant to share data you can ignore this");
388390
return;
389391
}
@@ -877,7 +879,7 @@ VIEWCOMPATIBILITY LatteTexture_CanTextureBeRepresentedAsView(LatteTexture* baseT
877879
// check pitch
878880
if(sliceMipInfo->pitch != pitch)
879881
continue;
880-
// check all slices
882+
// check all slices
881883
if(LatteAddrLib::TM_IsThickAndMacroTiled(baseTexture->tileMode))
882884
continue; // todo - check only every 4th slice?
883885
for (sint32 s=0; s<baseTexture->GetMipDepth(m); s++)
@@ -978,7 +980,7 @@ LatteTextureView* LatteTexture_CreateMapping(MPTR physAddr, MPTR physMipAddr, si
978980
}
979981
// note: When creating an existing texture, we only allow mip and slice expansion at the end
980982
cemu_assert_debug(depth);
981-
983+
982984
cemu_assert_debug(!(depth > 1 && dimBase == Latte::E_DIM::DIM_2D));
983985
cemu_assert_debug(!(numSlice > 1 && dimView == Latte::E_DIM::DIM_2D));
984986
// todo, depth and numSlice are redundant

src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSLHeader.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ namespace LatteDecompiler
261261
// generate pixel outputs for pixel shader
262262
for (uint32 i = 0; i < LATTE_NUM_COLOR_TARGET; i++)
263263
{
264-
if ((decompilerContext->shader->pixelColorOutputMask&(1 << i)) != 0)
264+
if ((decompilerContext->shader->pixelColorOutputMask & (1 << i)) != 0)
265265
{
266266
src->addFmt("float4 passPixelColor{} [[color({})]];" _CRLF, i, i);
267267
}

src/Cafe/HW/Latte/Renderer/Metal/LatteToMtl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ MTL::PrimitiveType GetMtlPrimitiveType(LattePrimitiveMode mode)
260260
case LattePrimitiveMode::TRIANGLE_STRIP:
261261
return MTL::PrimitiveTypeTriangleStrip;
262262
default:
263-
printf("unimplemented primitive type %u\n", (uint32)mode);
263+
// TODO: uncomment
264+
//printf("unimplemented primitive type %u\n", (uint32)mode);
264265
return MTL::PrimitiveTypeTriangle;
265266
}
266267
}

src/Cafe/HW/Latte/Renderer/Metal/MetalPipelineCache.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ MTL::RenderPipelineState* MetalPipelineCache::GetPipelineState(const LatteFetchS
5858

5959
uint32 bufferIndex = bufferGroup.attributeBufferIndex;
6060
uint32 bufferBaseRegisterIndex = mmSQ_VTX_ATTRIBUTE_BLOCK_START + bufferIndex * 7;
61-
// TODO: is LatteGPUState.contextNew correct?
6261
uint32 bufferStride = (LatteGPUState.contextNew.GetRawView()[bufferBaseRegisterIndex + 2] >> 11) & 0xFFFF;
6362

6463
auto layout = vertexDescriptor->layouts()->object(GET_MTL_VERTEX_BUFFER_INDEX(bufferIndex));

src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,6 @@ void MetalRenderer::draw_execute(uint32 baseVertex, uint32 baseInstance, uint32
561561
auto renderCommandEncoder = GetRenderCommandEncoder(renderPassDescriptor, colorRenderTargets, depthRenderTarget);
562562

563563
// Shaders
564-
LatteSHRC_UpdateActiveShaders();
565564
LatteDecompilerShader* vertexShader = LatteSHRC_GetActiveVertexShader();
566565
LatteDecompilerShader* pixelShader = LatteSHRC_GetActivePixelShader();
567566
if (!vertexShader || !static_cast<RendererShaderMtl*>(vertexShader->shader)->GetFunction())
@@ -627,7 +626,16 @@ void MetalRenderer::draw_execute(uint32 baseVertex, uint32 baseInstance, uint32
627626

628627
void MetalRenderer::draw_endSequence()
629628
{
630-
// TODO: do something?
629+
LatteDecompilerShader* pixelShader = LatteSHRC_GetActivePixelShader();
630+
// post-drawcall logic
631+
if (pixelShader)
632+
LatteRenderTarget_trackUpdates();
633+
bool hasReadback = LatteTextureReadback_Update();
634+
//m_recordedDrawcalls++;
635+
//if (m_recordedDrawcalls >= m_submitThreshold || hasReadback)
636+
//{
637+
// SubmitCommandBuffer();
638+
//}
631639
}
632640

633641
void* MetalRenderer::indexData_reserveIndexMemory(uint32 size, uint32& offset, uint32& bufferIndex)
@@ -1095,33 +1103,39 @@ void MetalRenderer::BindStageResources(MTL::RenderCommandEncoder* renderCommandE
10951103
{
10961104
if (shader->resourceMapping.uniformBuffersBindingPoint[i] >= 0)
10971105
{
1098-
uint32 binding = shader->resourceMapping.uniformBuffersBindingPoint[i];
1099-
if (binding >= MAX_MTL_BUFFERS)
1100-
{
1101-
debug_printf("too big buffer index (%u), skipping binding\n", binding);
1102-
continue;
1103-
}
1104-
size_t offset = m_state.uniformBufferOffsets[(uint32)shader->shaderType][binding];
1105-
if (offset != INVALID_OFFSET)
1106-
{
1107-
switch (shader->shaderType)
1108-
{
1109-
case LatteConst::ShaderType::Vertex:
1110-
{
1106+
uint32 binding = shader->resourceMapping.uniformBuffersBindingPoint[i];
1107+
if (binding >= MAX_MTL_BUFFERS)
1108+
{
1109+
debug_printf("too big buffer index (%u), skipping binding\n", binding);
1110+
continue;
1111+
}
1112+
size_t offset = m_state.uniformBufferOffsets[(uint32)shader->shaderType][i];
1113+
if (offset != INVALID_OFFSET)
1114+
{
1115+
switch (shader->shaderType)
1116+
{
1117+
case LatteConst::ShaderType::Vertex:
1118+
{
11111119
renderCommandEncoder->setVertexBuffer(m_memoryManager->GetBufferCache(), offset, binding);
11121120
break;
1113-
}
1114-
case LatteConst::ShaderType::Pixel:
1115-
{
1116-
renderCommandEncoder->setFragmentBuffer(m_memoryManager->GetBufferCache(), offset, binding);
1121+
}
1122+
case LatteConst::ShaderType::Pixel:
1123+
{
1124+
renderCommandEncoder->setFragmentBuffer(m_memoryManager->GetBufferCache(), offset, binding);
11171125
break;
1118-
}
1119-
default:
1126+
}
1127+
default:
11201128
UNREACHABLE;
1121-
}
1122-
}
1129+
}
1130+
}
11231131
}
11241132
}
1133+
1134+
// Storage buffer
1135+
if (shader->resourceMapping.tfStorageBindingPoint >= 0)
1136+
{
1137+
debug_printf("storage buffer not implemented, index: %i\n", shader->resourceMapping.tfStorageBindingPoint);
1138+
}
11251139
}
11261140

11271141
void MetalRenderer::RebindRenderState(MTL::RenderCommandEncoder* renderCommandEncoder)

0 commit comments

Comments
 (0)