From 4701b84876ad9e33500e4cc278923ce60c071602 Mon Sep 17 00:00:00 2001 From: Jelly10086 Date: Sun, 15 Nov 2026 19:06:18 +0900 Subject: [PATCH] fix(metal): Preserve texture optimization policy across the bridge --- NativeBridgeMetalFrontend.mm | 3 ++- README.md | 4 ++++ bridge/NativeMetalObjects.h | 1 + bridge/NativeMetalObjects.rs | 24 ++++++++++++++++++++++++ bridge/interface_regressions_host.mm | 14 ++++++++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/NativeBridgeMetalFrontend.mm b/NativeBridgeMetalFrontend.mm index c955d67..9bd7ec9 100644 --- a/NativeBridgeMetalFrontend.mm +++ b/NativeBridgeMetalFrontend.mm @@ -1330,7 +1330,7 @@ static uint64_t packedSwizzle(MTLTextureSwizzleChannels s) { static bool textureDescriptor(MTLTextureDescriptor *d,NmbTextureDescriptor *out) { if(!d)return false; *out={(uint64_t)d.textureType,(uint64_t)d.pixelFormat,d.width,d.height,d.depth,d.mipmapLevelCount,d.sampleCount,d.arrayLength,(uint64_t)d.usage,(uint64_t)d.resourceOptions, - textureRotation(d),textureFlag(d,"framebufferOnly"),textureFlag(d,"isDrawable"),packedSwizzle(d.swizzle)}; + textureRotation(d),textureFlag(d,"framebufferOnly"),textureFlag(d,"isDrawable"),packedSwizzle(d.swizzle),(uint64_t)d.allowGPUOptimizedContents}; if(singleSample() && out->samples>1) { out->samples=1; if(out->type==MTLTextureType2DMultisample)out->type=MTLTextureType2D; @@ -1379,6 +1379,7 @@ static bool textureDescriptor(MTLTextureDescriptor *d,NmbTextureDescriptor *out) - (MTLCPUCacheMode)cpuCacheMode {return (MTLCPUCacheMode)((_descriptor.options&MTLResourceCPUCacheModeMask)>>MTLResourceCPUCacheModeShift);} - (BOOL)isFramebufferOnly {return _descriptor.framebuffer_only!=0;} - (BOOL)isDrawable {return _descriptor.is_drawable!=0;} +- (BOOL)allowGPUOptimizedContents {return _descriptor.allow_gpu_optimized_contents!=0;} - (IOSurfaceRef)iosurface {return _surface;} - (NSUInteger)iosurfacePlane {return 0;} - (id)buffer {return _surface?nil:(id)_buffer;} diff --git a/README.md b/README.md index e106652..9699a41 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,10 @@ The frontend uses metal2vulkan and Turnip with the kernel GPU interface and sele All clients use single-sample rendering by default. `NATIVE_METAL_SINGLE_SAMPLE=0` preserves a process's requested sample counts; `1` forces single-sample rendering. Texture types, pipeline sample counts and resolve outputs follow the selected policy. Same-user clients share writable shader caches. Resource aliasing, swizzles, range copies, function constants, specialized link names and allocation queries reach the runtime. Queue priorities aggregate current live requests without a process-name policy. +Texture creation, heap size queries and texture views preserve +`allowGPUOptimizedContents`. A caller that requests an unoptimized layout keeps +that layout through the frontend and runtime. + Build and interface details: [documentation](https://unixnu.com/drivers/adreno-metal). Component sources and dependencies: [catalog](https://unixnu.com/reference/components). ## Native half arithmetic diff --git a/bridge/NativeMetalObjects.h b/bridge/NativeMetalObjects.h index cf08925..aedfc97 100644 --- a/bridge/NativeMetalObjects.h +++ b/bridge/NativeMetalObjects.h @@ -153,6 +153,7 @@ struct NmbTextureDescriptor { uint64_t type, format, width, height, depth, levels, samples, array_length, usage, options; uint64_t rotation, framebuffer_only, is_drawable; uint64_t swizzle; /* RGBA bytes, bit 32 marks an explicit value; zero means identity */ + uint64_t allow_gpu_optimized_contents; }; /* Heaps: type 0 automatic / 1 placement; offset UINT64_MAX asks an automatic heap to place the resource. */ NmbHeap *nmb_heap_new(NmbDevice *, uint64_t type, uint64_t size, uint64_t options); diff --git a/bridge/NativeMetalObjects.rs b/bridge/NativeMetalObjects.rs index ef86e60..ba9c59b 100644 --- a/bridge/NativeMetalObjects.rs +++ b/bridge/NativeMetalObjects.rs @@ -1438,6 +1438,7 @@ pub struct NmbTextureDescriptor { pub framebuffer_only: u64, pub is_drawable: u64, pub swizzle: u64, + pub allow_gpu_optimized_contents: u64, } // Bit 32 distinguishes an explicit all-zero swizzle from an omitted descriptor field. @@ -1467,10 +1468,32 @@ fn texture_descriptor(d: *const NmbTextureDescriptor) -> Result *mut NmbTexture { guard(std::ptr::null_mut(), || { @@ -1642,6 +1665,7 @@ pub extern "C" fn nmb_texture_describe(texture: *const NmbTexture, out: *mut Nmb framebuffer_only: u64::from(t.framebuffer_only()), is_drawable: u64::from(t.is_drawable()), swizzle: swizzle_packed(t.swizzle()), + allow_gpu_optimized_contents: u64::from(t.allow_gpu_optimized_contents()), }; Ok(()) }) diff --git a/bridge/interface_regressions_host.mm b/bridge/interface_regressions_host.mm index 00e4e8a..fe96e01 100644 --- a/bridge/interface_regressions_host.mm +++ b/bridge/interface_regressions_host.mm @@ -53,6 +53,20 @@ int main(int argc,char **argv) {@autoreleasepool { td.storageMode=MTLStorageModePrivate;td.usage=MTLTextureUsageShaderRead|MTLTextureUsagePixelFormatView; auto ht=[heap newTextureWithDescriptor:td];CHECK(ht);used=heap.usedSize; [ht makeAliasable];CHECK(ht.isAliasable && heap.usedSize