do surface copy properly

This commit is contained in:
Samuliak 2024-08-28 13:43:06 +02:00
parent 1b44269d70
commit be76dadb90
4 changed files with 13 additions and 9 deletions

View File

@ -10,6 +10,7 @@ MetalLayerHandle::MetalLayerHandle(MTL::Device* device, const Vector2i& size)
m_layer = (CA::MetalLayer*)CreateMetalLayer(windowInfo.handle, m_layerScaleX, m_layerScaleY); m_layer = (CA::MetalLayer*)CreateMetalLayer(windowInfo.handle, m_layerScaleX, m_layerScaleY);
m_layer->setDevice(device); m_layer->setDevice(device);
m_layer->setDrawableSize(CGSize{(float)size.x * m_layerScaleX, (float)size.y * m_layerScaleY}); m_layer->setDrawableSize(CGSize{(float)size.x * m_layerScaleX, (float)size.y * m_layerScaleY});
m_layer->setFramebufferOnly(true);
} }
MetalLayerHandle::~MetalLayerHandle() MetalLayerHandle::~MetalLayerHandle()

View File

@ -159,7 +159,7 @@ MetalRenderer::MetalRenderer()
auto copyTextureToColorPipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init(); auto copyTextureToColorPipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init();
// Hybrid pipelines // Hybrid pipelines
m_copyTextureToTexturePipeline = new MetalHybridComputePipeline(this, utilityLibrary, "vertexCopyTextureToTexture"); //m_copyTextureToTexturePipeline = new MetalHybridComputePipeline(this, utilityLibrary, "vertexCopyTextureToTexture");
m_restrideBufferPipeline = new MetalHybridComputePipeline(this, utilityLibrary, "vertexRestrideBuffer"); m_restrideBufferPipeline = new MetalHybridComputePipeline(this, utilityLibrary, "vertexRestrideBuffer");
utilityLibrary->release(); utilityLibrary->release();
@ -168,7 +168,7 @@ MetalRenderer::MetalRenderer()
MetalRenderer::~MetalRenderer() MetalRenderer::~MetalRenderer()
{ {
delete m_copyTextureToTexturePipeline; //delete m_copyTextureToTexturePipeline;
delete m_restrideBufferPipeline; delete m_restrideBufferPipeline;
m_presentPipelineLinear->release(); m_presentPipelineLinear->release();
@ -686,9 +686,12 @@ void MetalRenderer::surfaceCopy_copySurfaceWithFormatConversion(LatteTexture* so
sint32 effectiveCopyWidth = width; sint32 effectiveCopyWidth = width;
sint32 effectiveCopyHeight = height; sint32 effectiveCopyHeight = height;
LatteTexture_scaleToEffectiveSize(sourceTexture, &effectiveCopyWidth, &effectiveCopyHeight, 0); LatteTexture_scaleToEffectiveSize(sourceTexture, &effectiveCopyWidth, &effectiveCopyHeight, 0);
sint32 sourceEffectiveWidth, sourceEffectiveHeight; //sint32 sourceEffectiveWidth, sourceEffectiveHeight;
sourceTexture->GetEffectiveSize(sourceEffectiveWidth, sourceEffectiveHeight, srcMip); //sourceTexture->GetEffectiveSize(sourceEffectiveWidth, sourceEffectiveHeight, srcMip);
texture_copyImageSubData(sourceTexture, srcMip, 0, 0, srcSlice, destinationTexture, dstMip, 0, 0, dstSlice, effectiveCopyWidth, effectiveCopyHeight, 0);
/*
sint32 texSrcMip = srcMip; sint32 texSrcMip = srcMip;
sint32 texSrcSlice = srcSlice; sint32 texSrcSlice = srcSlice;
sint32 texDstMip = dstMip; sint32 texDstMip = dstMip;
@ -729,8 +732,6 @@ void MetalRenderer::surfaceCopy_copySurfaceWithFormatConversion(LatteTexture* so
} }
else else
{ {
// TODO: uncomment
/*
bool copyingToWholeRegion = ((effectiveCopyWidth == dstTextureMtl->GetMipWidth(dstMip) && effectiveCopyHeight == dstTextureMtl->GetMipHeight(dstMip))); bool copyingToWholeRegion = ((effectiveCopyWidth == dstTextureMtl->GetMipWidth(dstMip) && effectiveCopyHeight == dstTextureMtl->GetMipHeight(dstMip)));
auto renderPassDescriptor = MTL::RenderPassDescriptor::alloc()->init(); auto renderPassDescriptor = MTL::RenderPassDescriptor::alloc()->init();
@ -753,10 +754,10 @@ void MetalRenderer::surfaceCopy_copySurfaceWithFormatConversion(LatteTexture* so
renderCommandEncoder->drawPrimitives(MTL::PrimitiveTypeTriangle, NS::UInteger(0), NS::UInteger(3)); renderCommandEncoder->drawPrimitives(MTL::PrimitiveTypeTriangle, NS::UInteger(0), NS::UInteger(3));
EndEncoding(); EndEncoding();
*/
debug_printf("surface copy with no render command encoder, skipping copy\n"); debug_printf("surface copy with no render command encoder, skipping copy\n");
} }
*/
} }
void MetalRenderer::bufferCache_init(const sint32 bufferSize) void MetalRenderer::bufferCache_init(const sint32 bufferSize)

View File

@ -440,7 +440,7 @@ private:
MTL::RenderPipelineState* m_presentPipelineSRGB; MTL::RenderPipelineState* m_presentPipelineSRGB;
// Hybrid pipelines // Hybrid pipelines
class MetalHybridComputePipeline* m_copyTextureToTexturePipeline; //class MetalHybridComputePipeline* m_copyTextureToTexturePipeline;
class MetalHybridComputePipeline* m_restrideBufferPipeline; class MetalHybridComputePipeline* m_restrideBufferPipeline;
// Resources // Resources

View File

@ -31,17 +31,19 @@ fragment float4 fragmentPresent(VertexOut in [[stage_in]], texture2d<float> tex
return tex.sample(samplr, in.texCoord); return tex.sample(samplr, in.texCoord);
} }
/*
vertex void vertexCopyTextureToTexture(uint vid [[vertex_id]], texture2d<float, access::read> src [[texture(GET_TEXTURE_BINDING(0))]], texture2d<float, access::write> dst [[texture(GET_TEXTURE_BINDING(1))]], constant uint32_t& width [[buffer(GET_BUFFER_BINDING(0))]]) { vertex void vertexCopyTextureToTexture(uint vid [[vertex_id]], texture2d<float, access::read> src [[texture(GET_TEXTURE_BINDING(0))]], texture2d<float, access::write> dst [[texture(GET_TEXTURE_BINDING(1))]], constant uint32_t& width [[buffer(GET_BUFFER_BINDING(0))]]) {
uint2 coord = uint2(vid % width, vid / width); uint2 coord = uint2(vid % width, vid / width);
return dst.write(float4(src.read(coord).r, 0.0, 0.0, 0.0), coord); return dst.write(float4(src.read(coord).r, 0.0, 0.0, 0.0), coord);
} }
*/
struct RestrideParams { struct RestrideParams {
uint oldStride; uint oldStride;
uint newStride; uint newStride;
}; };
/* TODO: use uint32? Since that would require less iterations */ // TODO: use uint32? Since that would require less iterations
vertex void vertexRestrideBuffer(uint vid [[vertex_id]], device uint8_t* src [[buffer(GET_BUFFER_BINDING(0))]], device uint8_t* dst [[buffer(GET_BUFFER_BINDING(1))]], constant RestrideParams& params [[buffer(GET_BUFFER_BINDING(2))]]) { vertex void vertexRestrideBuffer(uint vid [[vertex_id]], device uint8_t* src [[buffer(GET_BUFFER_BINDING(0))]], device uint8_t* dst [[buffer(GET_BUFFER_BINDING(1))]], constant RestrideParams& params [[buffer(GET_BUFFER_BINDING(2))]]) {
for (uint32_t i = 0; i < params.oldStride; i++) { for (uint32_t i = 0; i < params.oldStride; i++) {
dst[vid * params.newStride + i] = src[vid * params.oldStride + i]; dst[vid * params.newStride + i] = src[vid * params.oldStride + i];