Fix iOS Metal vertical render orientation

This commit is contained in:
aperezro 2026-06-08 17:26:39 -06:00
parent 5a2ef3e855
commit 15cb87be1a

View file

@ -242,7 +242,7 @@ index 64e4dc9..1d14600 100644
}
}
diff --git a/plume_metal.cpp b/plume_metal.cpp
index ebbbaa3..c72adf6 100644
index ebbbaa3..6c91662 100644
--- a/plume_metal.cpp
+++ b/plume_metal.cpp
@@ -14,8 +14,12 @@
@ -258,7 +258,7 @@ index ebbbaa3..c72adf6 100644
#include "plume_metal.h"
@@ -38,6 +42,304 @@ namespace plume {
@@ -38,6 +42,307 @@ namespace plume {
return (n + alignment - 1) & ~(alignment - 1);
}
@ -496,6 +496,9 @@ index ebbbaa3..c72adf6 100644
+ options.platform = spirv_cross::CompilerMSL::Options::iOS;
+ options.ios_support_base_vertex_instance = true;
+ options.emulate_cube_array = true;
+ spirv_cross::CompilerGLSL::Options commonOptions = compiler.get_common_options();
+ commonOptions.vertex.flip_vert_y = true;
+ compiler.set_common_options(commonOptions);
+#else
+ options.platform = spirv_cross::CompilerMSL::Options::macOS;
+#endif
@ -563,7 +566,7 @@ index ebbbaa3..c72adf6 100644
uint64_t createClearPipelineKey(MTL::RenderPipelineDescriptor *pipelineDesc, bool depthWriteEnabled, bool stencilWriteEnabled) {
auto colorFormat = [&](uint32_t index) {
if (auto colorAttachment = pipelineDesc->colorAttachments()->object(index)) {
@@ -1133,7 +1435,7 @@ namespace plume {
@@ -1133,7 +1438,7 @@ namespace plume {
}
uint64_t MetalBuffer::getDeviceAddress() const {
@ -572,7 +575,7 @@ index ebbbaa3..c72adf6 100644
return mtl->gpuAddress();
}
@@ -1278,24 +1580,46 @@ namespace plume {
@@ -1278,24 +1583,46 @@ namespace plume {
assert(device != nullptr);
assert(data != nullptr);
assert(size > 0);
@ -625,7 +628,7 @@ index ebbbaa3..c72adf6 100644
if (debugName) {
debugName->release();
}
@@ -1306,10 +1630,16 @@ namespace plume {
@@ -1306,10 +1633,16 @@ namespace plume {
debugName->release();
}
debugName = NS::String::string(name.c_str(), NS::UTF8StringEncoding);
@ -643,7 +646,7 @@ index ebbbaa3..c72adf6 100644
MTL::FunctionConstantValues *values = MTL::FunctionConstantValues::alloc()->init();
if (specConstants != nullptr) {
for (uint32_t i = 0; i < specConstantsCount; i++) {
@@ -1325,6 +1655,10 @@ namespace plume {
@@ -1325,6 +1658,10 @@ namespace plume {
fprintf(stderr, "MTLLibrary newFunction: failed with error: %s.\n", error->localizedDescription()->utf8String());
return nullptr;
}
@ -654,7 +657,7 @@ index ebbbaa3..c72adf6 100644
if (debugName) {
function->setLabel(debugName);
@@ -1384,6 +1718,11 @@ namespace plume {
@@ -1384,6 +1721,11 @@ namespace plume {
MTL::ComputePipelineDescriptor *descriptor = MTL::ComputePipelineDescriptor::alloc()->init();
MTL::Function *function = computeShader->createFunction(desc.specConstants, desc.specConstantsCount);
@ -666,7 +669,7 @@ index ebbbaa3..c72adf6 100644
descriptor->setComputeFunction(function);
descriptor->setLabel(computeShader->functionName);
@@ -1437,6 +1776,13 @@ namespace plume {
@@ -1437,6 +1779,13 @@ namespace plume {
const MetalShader *metalShader = static_cast<const MetalShader *>(desc.vertexShader);
MTL::Function *vertexFunction = metalShader->createFunction(desc.specConstants, desc.specConstantsCount);
@ -680,7 +683,7 @@ index ebbbaa3..c72adf6 100644
descriptor->setVertexFunction(vertexFunction);
MTL::VertexDescriptor *vertexDescriptor = MTL::VertexDescriptor::alloc()->init();
@@ -1479,6 +1825,15 @@ namespace plume {
@@ -1479,6 +1828,15 @@ namespace plume {
if (desc.pixelShader != nullptr) {
const MetalShader *pixelShader = static_cast<const MetalShader *>(desc.pixelShader);
MTL::Function *fragmentFunction = pixelShader->createFunction(desc.specConstants, desc.specConstantsCount);
@ -696,7 +699,7 @@ index ebbbaa3..c72adf6 100644
descriptor->setFragmentFunction(fragmentFunction);
fragmentFunction->release();
}
@@ -1547,8 +1902,24 @@ namespace plume {
@@ -1547,8 +1905,24 @@ namespace plume {
state.depthBiasSlopeFactor = desc.slopeScaledDepthBias;
}
@ -723,7 +726,7 @@ index ebbbaa3..c72adf6 100644
return;
}
@@ -1793,6 +2164,11 @@ namespace plume {
@@ -1793,6 +2167,11 @@ namespace plume {
MetalSwapChain::MetalSwapChain(MetalCommandQueue *commandQueue, const RenderWindow renderWindow, uint32_t textureCount, const RenderFormat format) {
this->layer = static_cast<CA::MetalLayer*>(renderWindow.view);
@ -735,7 +738,7 @@ index ebbbaa3..c72adf6 100644
layer->setDevice(commandQueue->device->mtl);
layer->setPixelFormat(mapPixelFormat(format));
@@ -1819,7 +2195,10 @@ namespace plume {
@@ -1819,7 +2198,10 @@ namespace plume {
}
bool MetalSwapChain::present(const uint32_t textureIndex, RenderCommandSemaphore **waitSemaphores, const uint32_t waitSemaphoreCount) {
@ -747,7 +750,7 @@ index ebbbaa3..c72adf6 100644
NS::AutoreleasePool *releasePool = NS::AutoreleasePool::alloc()->init();
const MetalDrawable &drawable = drawables[textureIndex];
@@ -1861,7 +2240,7 @@ namespace plume {
@@ -1861,7 +2243,7 @@ namespace plume {
bool MetalSwapChain::resize() {
getWindowSize(width, height);
@ -756,7 +759,7 @@ index ebbbaa3..c72adf6 100644
return false;
}
@@ -1886,11 +2265,29 @@ namespace plume {
@@ -1886,11 +2268,29 @@ namespace plume {
}
void MetalSwapChain::setVsyncEnabled(const bool vsyncEnabled) {
@ -786,7 +789,7 @@ index ebbbaa3..c72adf6 100644
}
uint32_t MetalSwapChain::getWidth() const {
@@ -1910,6 +2307,10 @@ namespace plume {
@@ -1910,6 +2310,10 @@ namespace plume {
assert(textureIndex != nullptr);
assert(*textureIndex < MAX_DRAWABLES);
@ -797,7 +800,7 @@ index ebbbaa3..c72adf6 100644
NS::AutoreleasePool *releasePool = NS::AutoreleasePool::alloc()->init();
// Create a command buffer just to encode the signal
@@ -1923,6 +2324,7 @@ namespace plume {
@@ -1923,6 +2327,7 @@ namespace plume {
CA::MetalDrawable *nextDrawable = layer->nextDrawable();
if (nextDrawable == nullptr) {
fprintf(stderr, "No more drawables available for rendering.\n");
@ -805,7 +808,7 @@ index ebbbaa3..c72adf6 100644
return false;
}
@@ -1954,10 +2356,20 @@ namespace plume {
@@ -1954,10 +2359,20 @@ namespace plume {
}
uint32_t MetalSwapChain::getRefreshRate() const {
@ -826,7 +829,7 @@ index ebbbaa3..c72adf6 100644
CocoaWindowAttributes attributes;
windowWrapper->getWindowAttributes(&attributes);
dstWidth = attributes.width;
@@ -3308,6 +3720,9 @@ namespace plume {
@@ -3308,6 +3723,9 @@ namespace plume {
this->renderInterface = renderInterface;
// Device Selection
@ -836,7 +839,7 @@ index ebbbaa3..c72adf6 100644
const NS::Array* devices = MTL::CopyAllDevices();
MTL::Device *preferredDevice = nullptr;
for (NS::UInteger i = 0; i < devices->count(); i++) {
@@ -3320,12 +3735,31 @@ namespace plume {
@@ -3320,12 +3738,31 @@ namespace plume {
}
mtl = preferredDevice ? preferredDevice : MTL::CreateSystemDefaultDevice();;
@ -869,7 +872,7 @@ index ebbbaa3..c72adf6 100644
// Setup blit, clear and resolve shaders / pipelines
createClearShaderLibrary();
@@ -3337,7 +3771,7 @@ namespace plume {
@@ -3337,7 +3774,7 @@ namespace plume {
// TODO: Support Raytracing.
// capabilities.raytracing = mtl->supportsRaytracing();
capabilities.maxTextureSize = mtl->supportsFamily(MTL::GPUFamilyApple3) ? 16384 : 8192;
@ -878,7 +881,7 @@ index ebbbaa3..c72adf6 100644
capabilities.resolveModes = false;
#if PLUME_IOS
capabilities.descriptorIndexing = mtl->supportsFamily(MTL::GPUFamilyApple3);
@@ -3345,11 +3779,11 @@ namespace plume {
@@ -3345,11 +3782,11 @@ namespace plume {
capabilities.descriptorIndexing = true;
#endif
capabilities.scalarBlockLayout = true;
@ -893,7 +896,7 @@ index ebbbaa3..c72adf6 100644
capabilities.gpuUploadHeap = capabilities.uma;
capabilities.queryPools = false;
@@ -3357,17 +3791,19 @@ namespace plume {
@@ -3357,17 +3794,19 @@ namespace plume {
}
MetalDevice::~MetalDevice() {
@ -919,7 +922,7 @@ index ebbbaa3..c72adf6 100644
}
std::unique_ptr<RenderDescriptorSet> MetalDevice::createDescriptorSet(const RenderDescriptorSetDesc &desc) {
@@ -3635,16 +4071,24 @@ namespace plume {
@@ -3635,16 +4074,24 @@ namespace plume {
MetalInterface::MetalInterface() {
NS::AutoreleasePool *releasePool = NS::AutoreleasePool::alloc()->init();