🐛 Make no buffer or texture with resource option bit 18

On macOS 26.7.1 the AMD 5300M and the Intel 630 answer nil to
newBufferWithLength:options:, newBufferWithBytes:length:options: and
newTextureWithDescriptor: when the options hold bit 18 (0x40000). That
holds in every storage mode; bits 17 and 19 make the resource as
usual. The bundle made every one of them.

Both Macs agree, so it is the contract, and those creates now answer nil.
The Macs make a no-copy buffer and a heap's buffer with bit 18, and so
does the bundle. On a Private heap they diverge (the AMD's is nil, the
Intel's is made), and the bundle keeps making it. What the bit means
nothing states.
This commit is contained in:
Anees Iqbal committed 2026-11-07 07:00:29 -08:00
1 parent 11672a2a5f
commit 3564633f28
4 files changed
+38 -3

No files matched your search

+15 -1
View File
@@ -75,6 +75,20 @@ NS_ASSUME_NONNULL_BEGIN
device:(nullable id<MTLDevice>)device
serializer:(nullable RgfxSerializer *)serializer;
/// Bit 18 of MTLResourceOptions (0x40000), whose meaning nothing states. Both x86 Macs make no
/// buffer of a length or of bytes, nor a texture of a descriptor, whose options hold it: nil in
/// each storage mode, where they make one with bit 17 or 19 instead (measured: macOS 26.7.1 on the
/// AMD 5300M and the Intel 630). They make a no-copy buffer and a heap's buffer with it, and
/// diverge on a Private heap (the AMD's is nil, the Intel's is made).
static const MTLResourceOptions kRgfxOptionBit18 = (MTLResourceOptions)1 << 18;
/// Whether the device makes no buffer of a length or of bytes, nor a texture, of `options`
/// (kRgfxOptionBit18).
static inline BOOL RgfxMakesNoResourceOf(MTLResourceOptions options)
{
return (options & kRgfxOptionBit18) != 0;
}
#ifdef __cplusplus
/// The buffer `newBufferWithLength:options:` (`bytes` null) and
/// `newBufferWithBytes:length:options:` make: a Shared one in a range of a slab of `slabs`, which
@@ -87,7 +101,7 @@ NS_ASSUME_NONNULL_BEGIN
/// maxBufferLength; 0 holds none back). Nil too where `slabs` has no room for a Shared or
/// Managed one, as Metal answers a buffer it cannot place, never memory the GPU does not see;
/// and for bytes with a mode whose contents the CPU never reaches (Private), which Metal's
/// validation refuses.
/// validation refuses; and for options with bit 18, as the x86 Macs (RgfxMakesNoResourceOf).
+ (nullable instancetype)bufferForDeviceWithLength:(NSUInteger)length
options:(MTLResourceOptions)options
bytes:(nullable const void *)bytes
+1 -1
View File
@@ -251,7 +251,7 @@ NSString *rgfxLinearTypeName(MTLTextureType type)
device:(id<MTLDevice>)device
serializer:(RgfxSerializer *)serializer
{
if (length == 0 || (maxLength != 0 && length > maxLength))
if (length == 0 || (maxLength != 0 && length > maxLength) || RgfxMakesNoResourceOf(options))
return nil;
if (!rgfxCpuStorage(options)) {
// The GPU's alone: no bytes reach it from here.
@@ -77,8 +77,11 @@
- (id<MTLTexture>)newTextureWithDescriptor:(MTLTextureDescriptor *)descriptor
{
// Where Metal's validation ends the process, so does the bundle, sending nothing.
// Where Metal's validation ends the process, so does the bundle, sending nothing; and none of
// options with bit 18, as the x86 Macs make none (RgfxMakesNoResourceOf).
rgfxEndAtInvalidTextureDescriptor(descriptor, self);
if (descriptor != nil && RgfxMakesNoResourceOf(descriptor.resourceOptions))
return nil;
// A Managed texture's CPU copy is a Shared buffer of the slabs where the host reads a copy
// wherever its buffer lies (RGFX_FEATURE_MANAGED_TEXTURE_SLABS), so the copies take the
// process's own pages and not the region every process shares; else a region block. One of
+18
View File
@@ -419,6 +419,24 @@ void test_device_buffers_take_pages_of_slabs()
// modes alone, as both x86 Macs do (0x200 for 0x100000, 0x210 for 0x100010).
CHECK(make(256, static_cast<MTLResourceOptions>(0x100000)).resourceOptions == 0x200);
CHECK(make(256, static_cast<MTLResourceOptions>(0x100010)).resourceOptions == 0x210);
// None with bit 18 (0x40000), of a length or of bytes, in any storage mode, as both x86
// Macs make none; bits 17 and 19 make one.
static const uint8_t seed[256] = {};
for (MTLResourceOptions mode : {MTLResourceStorageModeShared, MTLResourceStorageModeManaged,
MTLResourceStorageModePrivate}) {
CHECK(make(256, mode | kRgfxOptionBit18) == nil);
CHECK(make(256, mode | (kRgfxOptionBit18 >> 1)) != nil);
CHECK(make(256, mode | (kRgfxOptionBit18 << 1)) != nil);
CHECK([RgfxBuffer bufferForDeviceWithLength:256
options:mode | kRgfxOptionBit18
bytes:seed
maxLength:0
slabs:&slabs
device:nil
serializer:&fx.ser] == nil);
}
CHECK(RgfxMakesNoResourceOf(MTLResourceStorageModePrivate | kRgfxOptionBit18) &&
!RgfxMakesNoResourceOf(MTLResourceStorageModePrivate | 0x100000));
CHECK(make(0x10000, MTLResourceStorageModeShared).allocatedSize == 0x10000);
CHECK(make(0x10001, MTLResourceStorageModeShared).allocatedSize == 0x11000);
RgfxBuffer *mib = make(0x100001, MTLResourceStorageModeManaged);