@@ -70,15 +70,17 @@ - (MetalTexture*) createTexture : (MetalContext*) ctx
70
70
mipmapped = false ;
71
71
}
72
72
TEX_LOG (@" useMipMap : %d " , useMipMap);
73
- MTLTextureDescriptor *texDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat: pixelFormat
73
+ @autoreleasepool {
74
+ MTLTextureDescriptor *texDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat: pixelFormat
74
75
width: width
75
76
height: height
76
77
mipmapped: mipmapped];
77
- texDescriptor.usage = usage;
78
+ texDescriptor.usage = usage;
78
79
79
- // Create buffer to store pixel data and then a texture using that buffer
80
- id <MTLDevice > device = [context getDevice ];
81
- texture = [device newTextureWithDescriptor: texDescriptor];
80
+ // Create buffer to store pixel data and then a texture using that buffer
81
+ id <MTLDevice > device = [context getDevice ];
82
+ texture = [device newTextureWithDescriptor: texDescriptor];
83
+ }
82
84
83
85
/*
84
86
// for testing purpose
@@ -129,37 +131,39 @@ - (MetalTexture*) createTexture : (MetalContext*) ctx
129
131
pixelFormat = MTLPixelFormatBGRA8Unorm ;
130
132
storageMode = MTLResourceStorageModeShared ;
131
133
132
- MTLTextureDescriptor *texDescriptor = [[MTLTextureDescriptor new ] autorelease ];
133
- texDescriptor.usage = usage;
134
- texDescriptor.width = width;
135
- texDescriptor.height = height;
136
- texDescriptor.textureType = type;
137
- texDescriptor.pixelFormat = pixelFormat;
138
- texDescriptor.sampleCount = 1 ;
139
- texDescriptor.hazardTrackingMode = MTLHazardTrackingModeTracked ;
140
-
141
- id <MTLDevice > device = [context getDevice ];
142
-
143
- texture = [device newTextureWithDescriptor: texDescriptor];
144
- if (msaa) {
145
- TEX_LOG (@" >>>> MetalTexture.createTexture()2 msaa texture" );
146
- MTLTextureDescriptor *msaaTexDescriptor = [[MTLTextureDescriptor new ] autorelease ];
147
- msaaTexDescriptor.storageMode = MTLStorageModePrivate ;
148
- msaaTexDescriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite ;
149
- msaaTexDescriptor.width = width;
150
- msaaTexDescriptor.height = height;
151
- msaaTexDescriptor.textureType = MTLTextureType2DMultisample ;
152
- msaaTexDescriptor.pixelFormat = pixelFormat;
153
- // By default all SoC's on macOS support 4 sample count
154
- msaaTexDescriptor.sampleCount = 4 ;
155
- msaaTexture = [device newTextureWithDescriptor: msaaTexDescriptor];
156
- } else {
157
- msaaTexture = nil ;
134
+ @autoreleasepool {
135
+ MTLTextureDescriptor *texDescriptor = [MTLTextureDescriptor new ];
136
+ texDescriptor.usage = usage;
137
+ texDescriptor.width = width;
138
+ texDescriptor.height = height;
139
+ texDescriptor.textureType = type;
140
+ texDescriptor.pixelFormat = pixelFormat;
141
+ texDescriptor.sampleCount = 1 ;
142
+ texDescriptor.hazardTrackingMode = MTLHazardTrackingModeTracked ;
143
+
144
+ id <MTLDevice > device = [context getDevice ];
145
+
146
+ texture = [device newTextureWithDescriptor: texDescriptor];
147
+ if (msaa) {
148
+ TEX_LOG (@" >>>> MetalTexture.createTexture()2 msaa texture" );
149
+ MTLTextureDescriptor *msaaTexDescriptor = [MTLTextureDescriptor new ];
150
+ msaaTexDescriptor.storageMode = MTLStorageModePrivate ;
151
+ msaaTexDescriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite ;
152
+ msaaTexDescriptor.width = width;
153
+ msaaTexDescriptor.height = height;
154
+ msaaTexDescriptor.textureType = MTLTextureType2DMultisample ;
155
+ msaaTexDescriptor.pixelFormat = pixelFormat;
156
+ // By default all SoC's on macOS support 4 sample count
157
+ msaaTexDescriptor.sampleCount = 4 ;
158
+ msaaTexture = [device newTextureWithDescriptor: msaaTexDescriptor];
159
+ } else {
160
+ msaaTexture = nil ;
161
+ }
162
+ isMSAA = msaa;
163
+
164
+ depthTexture = nil ;
165
+ depthMSAATexture = nil ;
158
166
}
159
- isMSAA = msaa;
160
-
161
- depthTexture = nil ;
162
- depthMSAATexture = nil ;
163
167
}
164
168
TEX_LOG (@" >>>> MetalTexture.createTexture()2 (buffer backed texture) -- width = %lu , height = %lu " , width, height);
165
169
TEX_LOG (@" >>>> MetalTexture.createTexture()2 created MetalTexture = %p " , texture);
@@ -195,22 +199,24 @@ - (void) createDepthTexture
195
199
depthTexture.height != height ||
196
200
lastDepthMSAA != isMSAA) {
197
201
lastDepthMSAA = isMSAA;
198
- MTLTextureDescriptor *depthDesc = [[MTLTextureDescriptor new ] autorelease ];
199
- depthDesc.width = width;
200
- depthDesc.height = height;
201
- depthDesc.pixelFormat = MTLPixelFormatDepth32Float ;
202
- depthDesc.textureType = MTLTextureType2D ;
203
- depthDesc.sampleCount = 1 ;
204
- depthDesc.usage = MTLTextureUsageRenderTarget ;
205
- depthDesc.storageMode = MTLStorageModePrivate ;
206
- depthTexture = [device newTextureWithDescriptor: depthDesc];
207
- if (isMSAA) {
208
- TEX_LOG (@" >>>> MetalTexture.createDepthMSAATexture()" );
209
- depthDesc.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite ;
210
- depthDesc.textureType = MTLTextureType2DMultisample ;
211
- // By default all SoC's on macOS support 4 sample count
212
- depthDesc.sampleCount = 4 ;
213
- depthMSAATexture = [device newTextureWithDescriptor: depthDesc];
202
+ @autoreleasepool {
203
+ MTLTextureDescriptor *depthDesc = [MTLTextureDescriptor new ];
204
+ depthDesc.width = width;
205
+ depthDesc.height = height;
206
+ depthDesc.pixelFormat = MTLPixelFormatDepth32Float ;
207
+ depthDesc.textureType = MTLTextureType2D ;
208
+ depthDesc.sampleCount = 1 ;
209
+ depthDesc.usage = MTLTextureUsageRenderTarget ;
210
+ depthDesc.storageMode = MTLStorageModePrivate ;
211
+ depthTexture = [device newTextureWithDescriptor: depthDesc];
212
+ if (isMSAA) {
213
+ TEX_LOG (@" >>>> MetalTexture.createDepthMSAATexture()" );
214
+ depthDesc.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite ;
215
+ depthDesc.textureType = MTLTextureType2DMultisample ;
216
+ // By default all SoC's on macOS support 4 sample count
217
+ depthDesc.sampleCount = 4 ;
218
+ depthMSAATexture = [device newTextureWithDescriptor: depthDesc];
219
+ }
214
220
}
215
221
}
216
222
}
@@ -564,6 +570,8 @@ static int copyPixelDataToRingBuffer(MetalContext* context, void* pixels, unsign
564
570
565
571
[computeEncoder endEncoding ];
566
572
573
+ [_computePipelineState release ];
574
+
567
575
[context commitCurrentCommandBuffer ];
568
576
}
569
577
0 commit comments