diff --git a/plugins/cocoaui/Visualization/Scope/ScopeVisualizationViewController.m b/plugins/cocoaui/Visualization/Scope/ScopeVisualizationViewController.m index 492fd2c63b..c638c328cf 100644 --- a/plugins/cocoaui/Visualization/Scope/ScopeVisualizationViewController.m +++ b/plugins/cocoaui/Visualization/Scope/ScopeVisualizationViewController.m @@ -392,11 +392,7 @@ - (void)displayLayer:(CALayer *)layer { #pragma mark - ShaderRendererDelegate -- (BOOL)canDraw { - return _draw_data.points != NULL; -} - -- (void)applyFragParamsWithViewport:(vector_uint2)viewport device:(id)device encoder:(id)encoder viewParams:(ShaderRendererParams)viewParams { +- (BOOL)applyFragParamsWithViewport:(vector_uint2)viewport device:(id)device encoder:(id)encoder viewParams:(ShaderRendererParams)viewParams { float scale = (float)(viewParams.backingScaleFactor / [self scaleFactorForBackingScaleFactor:viewParams.backingScaleFactor]); struct ScopeFragParams params; @@ -416,11 +412,19 @@ - (void)applyFragParamsWithViewport:(vector_uint2)viewport device:(id params.scale = scale; [encoder setFragmentBytes:¶ms length:sizeof (params) atIndex:0]; - // Metal documentation states that MTLBuffer should be used for buffers larger than 4K in size. - // Alternative is to use setFragmentBytes, which also works, but could have compatibility issues on older hardware. - id buffer = [device newBufferWithBytes:_draw_data.points length:_draw_data.point_count * sizeof (ddb_scope_point_t) * params.channels options:0]; + if (_draw_data.points == NULL) { + char bytes[12] = {0}; + [encoder setFragmentBytes:bytes length:12 atIndex:1]; + } + else { + // Metal documentation states that MTLBuffer should be used for buffers larger than 4K in size. + // Alternative is to use setFragmentBytes, which also works, but could have compatibility issues on older hardware. + id buffer = [device newBufferWithBytes:_draw_data.points length:_draw_data.point_count * sizeof (ddb_scope_point_t) * params.channels options:0]; - [encoder setFragmentBuffer:buffer offset:0 atIndex:1]; + [encoder setFragmentBuffer:buffer offset:0 atIndex:1]; + } + + return YES; } @end diff --git a/plugins/cocoaui/Visualization/Shared/ShaderRenderer.h b/plugins/cocoaui/Visualization/Shared/ShaderRenderer.h index aa977153ef..d43c2e7bd9 100644 --- a/plugins/cocoaui/Visualization/Shared/ShaderRenderer.h +++ b/plugins/cocoaui/Visualization/Shared/ShaderRenderer.h @@ -32,8 +32,7 @@ typedef struct { } ShaderRendererParams; @protocol ShaderRendererDelegate -- (BOOL)canDraw; -- (void)applyFragParamsWithViewport:(vector_uint2)viewport device:(nonnull id )device encoder:(nonnull id )encoder viewParams:(ShaderRendererParams)params; +- (BOOL)applyFragParamsWithViewport:(vector_uint2)viewport device:(nonnull id )device encoder:(nonnull id )encoder viewParams:(ShaderRendererParams)params; @end @interface ShaderRenderer : NSObject diff --git a/plugins/cocoaui/Visualization/Shared/ShaderRenderer.m b/plugins/cocoaui/Visualization/Shared/ShaderRenderer.m index 8797e69cc7..3333f7ec09 100644 --- a/plugins/cocoaui/Visualization/Shared/ShaderRenderer.m +++ b/plugins/cocoaui/Visualization/Shared/ShaderRenderer.m @@ -110,9 +110,6 @@ - (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; } @@ -159,22 +156,23 @@ - (void)renderToMetalLayer:(nonnull CAMetalLayer*)metalLayer viewParams:(ShaderR [renderEncoder setRenderPipelineState:_pipelineState]; - // Pass in the parameter data. - [renderEncoder setVertexBytes:quadVertices - length:sizeof(quadVertices) - atIndex:ShaderRendererVertexInputIndexVertices]; - vector_uint2 vp = { (uint)_viewportSize.width, (uint)_viewportSize.height }; - [renderEncoder setVertexBytes:&vp - length:sizeof(vp) - atIndex:ShaderRendererVertexInputIndexViewportSize]; + if ([self.delegate applyFragParamsWithViewport:vp device:_device encoder:renderEncoder viewParams:viewParams]) { + // Pass in the parameter data. + [renderEncoder setVertexBytes:quadVertices + length:sizeof(quadVertices) + atIndex:ShaderRendererVertexInputIndexVertices]; - [self.delegate applyFragParamsWithViewport:vp device:_device encoder:renderEncoder viewParams:viewParams]; + [renderEncoder setVertexBytes:&vp + length:sizeof(vp) + atIndex:ShaderRendererVertexInputIndexViewportSize]; - // Draw the triangle. - [renderEncoder drawPrimitives:MTLPrimitiveTypeTriangleStrip - vertexStart:0 - vertexCount:4]; + // Draw the triangle. + [renderEncoder drawPrimitives:MTLPrimitiveTypeTriangleStrip + vertexStart:0 + vertexCount:4]; + + } // end diff --git a/plugins/cocoaui/Visualization/SpectrumAnalyzer/SpectrumAnalyzerVisualizationViewController.m b/plugins/cocoaui/Visualization/SpectrumAnalyzer/SpectrumAnalyzerVisualizationViewController.m index 496308296f..ce526fab7d 100644 --- a/plugins/cocoaui/Visualization/SpectrumAnalyzer/SpectrumAnalyzerVisualizationViewController.m +++ b/plugins/cocoaui/Visualization/SpectrumAnalyzer/SpectrumAnalyzerVisualizationViewController.m @@ -437,11 +437,7 @@ - (void)displayLayer:(CALayer *)layer { #pragma mark - ShaderRendererDelegate -- (BOOL)canDraw { - return _draw_data.bars != NULL; -} - -- (void)applyFragParamsWithViewport:(vector_uint2)viewport device:(id)device encoder:(id)encoder viewParams:(ShaderRendererParams)viewParams { +- (BOOL)applyFragParamsWithViewport:(vector_uint2)viewport device:(id)device encoder:(id)encoder viewParams:(ShaderRendererParams)viewParams { struct SpectrumFragParams params; @@ -462,8 +458,14 @@ - (void)applyFragParamsWithViewport:(vector_uint2)viewport device:(id assert(sizeof(struct SpectrumFragBar) == sizeof (ddb_analyzer_draw_bar_t)); // bar data + if (_draw_data.bars == NULL) { + char bytes[12] = {0}; + [encoder setFragmentBytes:bytes length:12 atIndex:1]; - if (_draw_data.mode == DDB_ANALYZER_MODE_FREQUENCIES) { + // This buffer is unused in this scenario, but necessary to shut up API validator + [encoder setFragmentBytes:bytes length:4 atIndex:2]; + } + else if (_draw_data.mode == DDB_ANALYZER_MODE_FREQUENCIES) { // In this scenario, the buffer is too large, need to use MTLBuffer. id buffer = [device newBufferWithBytes:_draw_data.bars length:_draw_data.bar_count * sizeof (struct SpectrumFragBar) options:0]; @@ -482,5 +484,7 @@ - (void)applyFragParamsWithViewport:(vector_uint2)viewport device:(id // This buffer is unused in this scenario, but necessary to shut up API validator [encoder setFragmentBytes:_draw_data.bars length:4 atIndex:2]; } + + return YES; } @end