what to do when counter sample buffers unavailable?

Counters seem an important tool, eg I don't know how else to use timestamps. But newCounterSampleBufferWithDescriptor:error: discussion says

The method may produce an error if the GPU driver has exhausted its underlying resources for counter sample buffers.

And indeed, when I make the call I get error code 14 with localized description "out of memory." How to resolve this? Might the counter buffers be exhausted by other applications or what? Is there no sharing of these resources like other GPU resources? I'd be surprised if tools as important as timestamps/counters can simply be unavailable at any time with no explanation.

If this is indeed the sad state of affairs, are there any tools like in Xcode I can use for timestamping?

If relevant, I have: Intel UHD Graphics 617 1536 MB

Answered by Graphics and Games Engineer in 739646022

Sorry, I meant attach it to the the feedback request you make with the Feedback Assistant app.

In this example, I'd expect sample_buffer to be.nil in any case since you haven't populated the counterSet and sampleCount properties in the descriptor. The odd part is that you're getting an "out of memory" error and not something more descriptive.

Are you getting nil even when you've set up properties in the descriptor with valid values?

Hi Joseph,

This should work. Can you create a report with Feedback assistant and reply with the number here? Of course, it would be most helpful if you can attach an Xcode project that will reproduce the problem, but any info would be helpful.

I'm not sure how to attach an Xcode project here, it won't let me select the Xcode project file (or folder) to attach. But creating a command line app with single file main.m below gives me the output:

2022-12-12 18:49:36.578621-0500 counter test[70895:1590946] Metal GPU Frame Capture Enabled
2022-12-12 18:49:36.581789-0500 counter test[70895:1590946] Metal API Validation Enabled
2022-12-12 18:49:36.652955-0500 counter test[70895:1590946] Error Domain=com.apple.mtlrenderer Code=14 "out of memory" UserInfo={NSLocalizedDescription=out of memory}
Program ended with exit code: 1

Here's the file

#import <Foundation/Foundation.h>
#import <Metal/Metal.h>

int main() {
    @autoreleasepool {
        id<MTLDevice> device = MTLCreateSystemDefaultDevice();

        MTLCounterSampleBufferDescriptor * descriptor = [MTLCounterSampleBufferDescriptor new];

        NSError * error = nil;
        id<MTLCounterSampleBuffer> sample_buffer = [device newCounterSampleBufferWithDescriptor:descriptor error:&error];

        if(sample_buffer == nil) {
            NSLog(@"%@", error);
            return 1;
        } else {
            return 0;
        }
    }
}

Let me know what else to provide. I also submitted the attachment on Feedback Assistant, but I'm not sure what numbers you're talking about.

Accepted Answer

Sorry, I meant attach it to the the feedback request you make with the Feedback Assistant app.

In this example, I'd expect sample_buffer to be.nil in any case since you haven't populated the counterSet and sampleCount properties in the descriptor. The odd part is that you're getting an "out of memory" error and not something more descriptive.

Are you getting nil even when you've set up properties in the descriptor with valid values?

Oops, outside of that sample I've been setting all properties but missed sampleCount, and setting that it works. Leaving out sampleCount or counterSet gives the same out of memory error. Thanks for your help

what to do when counter sample buffers unavailable?
 
 
Q