Skip to content

Commit

Permalink
cocoaui: fix metal API validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy-Yakovenko committed Nov 2, 2024
1 parent 2752f8f commit ac84379
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ - (void)displayLayer:(CALayer *)layer {

#pragma mark - ShaderRendererDelegate

- (BOOL)canDraw {
return _draw_data.points != NULL;
}

- (void)applyFragParamsWithViewport:(vector_uint2)viewport device:(id<MTLDevice>)device encoder:(id<MTLRenderCommandEncoder>)encoder viewParams:(ShaderRendererParams)viewParams {
float scale = (float)(viewParams.backingScaleFactor / [self scaleFactorForBackingScaleFactor:viewParams.backingScaleFactor]);

Expand Down
1 change: 1 addition & 0 deletions plugins/cocoaui/Visualization/Shared/ShaderRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef struct {
} ShaderRendererParams;

@protocol ShaderRendererDelegate
- (BOOL)canDraw;
- (void)applyFragParamsWithViewport:(vector_uint2)viewport device:(nonnull id <MTLDevice>)device encoder:(nonnull id <MTLRenderCommandEncoder>)encoder viewParams:(ShaderRendererParams)params;
@end

Expand Down
4 changes: 3 additions & 1 deletion plugins/cocoaui/Visualization/Shared/ShaderRenderer.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ - (void)drawableResize:(CGSize)drawableSize
}

- (void)renderToMetalLayer:(nonnull CAMetalLayer*)metalLayer viewParams:(ShaderRendererParams)viewParams {
if (![self.delegate canDraw]) {
return;
}
if (_viewportSize.width == 0 || _viewportSize.height == 0) {
return;
}
Expand All @@ -132,7 +135,6 @@ - (void)renderToMetalLayer:(nonnull CAMetalLayer*)metalLayer viewParams:(ShaderR

id <MTLRenderCommandEncoder> renderEncoder =
[commandBuffer renderCommandEncoderWithDescriptor:_drawableRenderDescriptor];
renderEncoder.label = @"MyRenderEncoder";

// begin

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ - (void)displayLayer:(CALayer *)layer {

#pragma mark - ShaderRendererDelegate

- (BOOL)canDraw {
return _draw_data.bars != NULL;
}

- (void)applyFragParamsWithViewport:(vector_uint2)viewport device:(id<MTLDevice>)device encoder:(id<MTLRenderCommandEncoder>)encoder viewParams:(ShaderRendererParams)viewParams {

struct SpectrumFragParams params;
Expand Down Expand Up @@ -474,7 +478,9 @@ - (void)applyFragParamsWithViewport:(vector_uint2)viewport device:(id<MTLDevice>
// The buffer is not bigger than ~2.5KB (211 bars * 12 bytes),
// therefore it should be safe to use setFragmentBytes.
[encoder setFragmentBytes:_draw_data.bars length:_draw_data.bar_count * sizeof (struct SpectrumFragBar) atIndex:1];
}

// This buffer is unused in this scenario, but necessary to shut up API validator
[encoder setFragmentBytes:_draw_data.bars length:4 atIndex:2];
}
}
@end

0 comments on commit ac84379

Please sign in to comment.