8262751: RenderPipelineState assertion error in J2DDemo

Reviewed-by: jdv
This commit is contained in:
Alexey Ushakov 2021-08-26 07:28:26 +00:00
parent a3308af060
commit 49b2789a49
2 changed files with 59 additions and 10 deletions

View File

@ -63,7 +63,17 @@
@end
@interface MTLColorPaint : MTLPaint
+ (void)setPipelineState:(id <MTLRenderCommandEncoder>)encoder
context:(MTLContext *)mtlc
renderOptions:(const RenderOptions *)renderOptions
pipelineStateStorage:(MTLPipelineStatesStorage *)pipelineStateStorage
rpDesc:(MTLRenderPipelineDescriptor *)rpDesc
vertShader:(NSString *)vertShader
fragShader:(NSString *)fragShader
color:(jint)color;
- (id)initWithColor:(jint)color;
@property (nonatomic, readonly) jint color;
@end

View File

@ -141,6 +141,27 @@ static void initTemplatePipelineDescriptors() {
// color-mode
jint _color;
}
+ (void)setPipelineState:(id <MTLRenderCommandEncoder>)encoder
context:(MTLContext *)mtlc
renderOptions:(const RenderOptions *)renderOptions
pipelineStateStorage:(MTLPipelineStatesStorage *)pipelineStateStorage
rpDesc:(MTLRenderPipelineDescriptor *)rpDesc
vertShader:(NSString *)vertShader
fragShader:(NSString *)fragShader
color:(jint)color {
struct FrameUniforms uf = {RGBA_TO_V4(color)};
[encoder setVertexBytes:&uf length:sizeof(uf) atIndex:FrameUniformBuffer];
id <MTLRenderPipelineState> pipelineState = [pipelineStateStorage getPipelineState:rpDesc
vertexShaderId:vertShader
fragmentShaderId:fragShader
composite:mtlc.composite
renderOptions:renderOptions
stencilNeeded:[mtlc.clip isShape]];
[encoder setRenderPipelineState:pipelineState];
}
- (id)initWithColor:(jint)color {
self = [super initWithState:sun_java2d_SunGraphics2D_PAINT_ALPHACOLOR];
@ -217,16 +238,14 @@ jint _color;
rpDesc = [[templateRenderPipelineDesc copy] autorelease];
}
struct FrameUniforms uf = {RGBA_TO_V4(_color)};
[encoder setVertexBytes:&uf length:sizeof(uf) atIndex:FrameUniformBuffer];
id <MTLRenderPipelineState> pipelineState = [pipelineStateStorage getPipelineState:rpDesc
vertexShaderId:vertShader
fragmentShaderId:fragShader
composite:mtlc.composite
renderOptions:renderOptions
stencilNeeded:[mtlc.clip isShape]];
[encoder setRenderPipelineState:pipelineState];
[MTLColorPaint setPipelineState:encoder
context:mtlc
renderOptions:renderOptions
pipelineStateStorage:pipelineStateStorage
rpDesc:rpDesc
vertShader:vertShader
fragShader:fragShader
color:_color];
}
- (void)setXorModePipelineState:(id<MTLRenderCommandEncoder>)encoder
@ -948,6 +967,16 @@ setTxtUniforms(MTLContext *mtlc, int color, id <MTLRenderCommandEncoder> encoder
renderOptions:renderOptions
stencilNeeded:[mtlc.clip isShape]];
[encoder setRenderPipelineState:pipelineState];
} else {
// Fallback to default pipeline state
[MTLColorPaint setPipelineState:encoder
context:mtlc
renderOptions:renderOptions
pipelineStateStorage:pipelineStateStorage
rpDesc:[[templateRenderPipelineDesc copy] autorelease]
vertShader:@"vert_col"
fragShader:@"frag_col"
color:0];
}
}
@ -987,6 +1016,16 @@ setTxtUniforms(MTLContext *mtlc, int color, id <MTLRenderCommandEncoder> encoder
renderOptions:renderOptions
stencilNeeded:[mtlc.clip isShape]];
[encoder setRenderPipelineState:pipelineState];
} else {
// Fallback to default pipeline state
[MTLColorPaint setPipelineState:encoder
context:mtlc
renderOptions:renderOptions
pipelineStateStorage:pipelineStateStorage
rpDesc:[[templateRenderPipelineDesc copy] autorelease]
vertShader:@"vert_col"
fragShader:@"frag_col"
color:0];
}
}