change some stuff in texture creation

This commit is contained in:
Gregory Wells
2025-07-21 09:32:47 -04:00
parent 3da744342a
commit 3497e32e47

View File

@@ -16,13 +16,16 @@ NSUInteger mtlSampleCount(gnMultisampleCountFlags flags) {
gnReturnCode createMetalTexture(gnTexture texture, gnDevice device, const gnTextureInfo info) { gnReturnCode createMetalTexture(gnTexture texture, gnDevice device, const gnTextureInfo info) {
texture->texture = malloc(sizeof(struct gnPlatformTexture_t)); texture->texture = malloc(sizeof(struct gnPlatformTexture_t));
MTLTextureDescriptor *textureDescriptor = [[MTLTextureDescriptor alloc] init]; MTLTextureDescriptor *textureDescriptor = [[MTLTextureDescriptor alloc] init];
textureDescriptor.sampleCount = mtlSampleCount(info.samples);
textureDescriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead;
textureDescriptor.storageMode = MTLStorageModeShared; // Most efficient for GPU-only textures
textureDescriptor.depth = info.extent.depth;
textureDescriptor.width = info.extent.width; textureDescriptor.width = info.extent.width;
textureDescriptor.height = info.extent.height; textureDescriptor.height = info.extent.height;
textureDescriptor.depth = info.extent.depth;
textureDescriptor.sampleCount = mtlSampleCount(info.samples);
textureDescriptor.pixelFormat = mtlGryphnFormatToMetalFormat(info.format); textureDescriptor.pixelFormat = mtlGryphnFormatToMetalFormat(info.format);
textureDescriptor.usage = MTLTextureUsageRenderTarget;
if (textureDescriptor.sampleCount >= 2) { if (textureDescriptor.sampleCount >= 2) {
textureDescriptor.storageMode = MTLStorageModeShared;
textureDescriptor.textureType = MTLTextureType2DMultisample; textureDescriptor.textureType = MTLTextureType2DMultisample;
} }
else { else {
@@ -30,14 +33,15 @@ gnReturnCode createMetalTexture(gnTexture texture, gnDevice device, const gnText
} }
MTLSamplerDescriptor *samplerDesc = [[MTLSamplerDescriptor alloc] init]; MTLSamplerDescriptor *samplerDesc = [[MTLSamplerDescriptor alloc] init];
samplerDesc.minFilter = MTLSamplerMinMagFilterLinear; samplerDesc.minFilter = (info.minFilter == GN_FILTER_NEAREST) ? MTLSamplerMinMagFilterNearest : MTLSamplerMinMagFilterLinear;
samplerDesc.magFilter = MTLSamplerMinMagFilterLinear; samplerDesc.magFilter = (info.magFilter == GN_FILTER_NEAREST) ? MTLSamplerMinMagFilterNearest : MTLSamplerMinMagFilterLinear;;
samplerDesc.mipFilter = MTLSamplerMipFilterNotMipmapped; samplerDesc.mipFilter = MTLSamplerMipFilterNotMipmapped;
samplerDesc.sAddressMode = MTLSamplerAddressModeClampToEdge; samplerDesc.sAddressMode = MTLSamplerAddressModeClampToEdge;
samplerDesc.tAddressMode = MTLSamplerAddressModeClampToEdge; samplerDesc.tAddressMode = MTLSamplerAddressModeClampToEdge;
samplerDesc.normalizedCoordinates = YES; samplerDesc.supportArgumentBuffers = true;
texture->texture->sampler = [device->outputDevice->device newSamplerStateWithDescriptor:samplerDesc]; texture->texture->sampler = [device->outputDevice->device newSamplerStateWithDescriptor:samplerDesc];
texture->texture->texture = [device->outputDevice->device newTextureWithDescriptor:textureDescriptor]; texture->texture->texture = [device->outputDevice->device newTextureWithDescriptor:textureDescriptor];
[textureDescriptor release]; [textureDescriptor release];
[samplerDesc release]; [samplerDesc release];
return GN_SUCCESS; return GN_SUCCESS;