JBR-4784 Extra allocations of MTLRenderPipelineDescriptor affects performance in metal pipeline

Remove extra allocations

(cherry picked from commit e1fe3a3807)
This commit is contained in:
Alexey Ushakov
2022-09-02 12:44:40 +02:00
committed by Nikita Gubarkov
parent 1ca0d0d4ea
commit 2f373d5c95

View File

@@ -216,10 +216,10 @@ jint _color;
if (renderOptions->isTexture) {
vertShader = @"vert_txt";
fragShader = @"frag_txt";
rpDesc = [[templateTexturePipelineDesc copy] autorelease];
rpDesc = templateTexturePipelineDesc;
if (renderOptions->isAA) {
fragShader = @"aa_frag_txt";
rpDesc = [[templateAATexturePipelineDesc copy] autorelease];
rpDesc = templateAATexturePipelineDesc;
}
if (renderOptions->isGMCText) {
fragShader = @"frag_gmc_text";
@@ -228,7 +228,7 @@ jint _color;
if (renderOptions->isLCD) {
vertShader = @"vert_txt_lcd";
fragShader = @"lcd_color";
rpDesc = [[templateLCDPipelineDesc copy] autorelease];
rpDesc = templateLCDPipelineDesc;
}
setTxtUniforms(mtlc, _color, encoder,
renderOptions->interpolation, NO, [mtlc.composite getExtraAlpha],
@@ -236,9 +236,9 @@ jint _color;
} else if (renderOptions->isAAShader) {
vertShader = @"vert_col_aa";
fragShader = @"frag_col_aa";
rpDesc = [[templateAAPipelineDesc copy] autorelease];
rpDesc = templateAAPipelineDesc;
} else {
rpDesc = [[templateRenderPipelineDesc copy] autorelease];
rpDesc = templateRenderPipelineDesc;
}
[MTLColorPaint setPipelineState:encoder
@@ -269,7 +269,7 @@ jint _color;
if (renderOptions->isTexture) {
vertShader = @"vert_txt_xorMode";
fragShader = @"frag_txt_xorMode";
rpDesc = [[templateTexturePipelineDesc copy] autorelease];
rpDesc = templateTexturePipelineDesc;
setTxtUniforms(mtlc, col, encoder,
renderOptions->interpolation, NO, [mtlc.composite getExtraAlpha],
@@ -279,7 +279,7 @@ jint _color;
[encoder setFragmentTexture:dstOps->pTexture atIndex:1];
} else {
struct FrameUniforms uf = {RGBA_TO_V4(col)};
rpDesc = [[templateRenderPipelineDesc copy] autorelease];
rpDesc = templateRenderPipelineDesc;
[encoder setVertexBytes:&uf length:sizeof(uf) atIndex:FrameUniformBuffer];
[encoder setFragmentTexture:dstOps->pTexture atIndex:0];
@@ -405,9 +405,9 @@ jint _color;
if (renderOptions->isTexture) {
vertShader = @"vert_txt_grad";
fragShader = @"frag_txt_grad";
rpDesc = [[templateTexturePipelineDesc copy] autorelease];
rpDesc = templateTexturePipelineDesc;
} else {
rpDesc = [[templateRenderPipelineDesc copy] autorelease];
rpDesc = templateRenderPipelineDesc;
}
id <MTLRenderPipelineState> pipelineState = [pipelineStateStorage getPipelineState:rpDesc
@@ -429,7 +429,7 @@ jint _color;
initTemplatePipelineDescriptors();
NSString* vertShader = @"vert_grad_xorMode";
NSString* fragShader = @"frag_grad_xorMode";
MTLRenderPipelineDescriptor *rpDesc = [[templateRenderPipelineDesc copy] autorelease];
MTLRenderPipelineDescriptor *rpDesc = templateRenderPipelineDesc;
jint xorColor = (jint) [mtlc.composite getXorColor];
struct GradFrameUniforms uf = {
@@ -533,9 +533,9 @@ jint _color;
if (renderOptions->isTexture) {
vertShader = @"vert_txt_grad";
fragShader = @"frag_txt_lin_grad";
rpDesc = [[templateTexturePipelineDesc copy] autorelease];
rpDesc = templateTexturePipelineDesc;
} else {
rpDesc = [[templateRenderPipelineDesc copy] autorelease];
rpDesc = templateRenderPipelineDesc;
}
struct LinGradFrameUniforms uf = {
@@ -697,9 +697,9 @@ jint _color;
if (renderOptions->isTexture) {
vertShader = @"vert_txt_grad";
fragShader = @"frag_txt_rad_grad";
rpDesc = [[templateTexturePipelineDesc copy] autorelease];
rpDesc = templateTexturePipelineDesc;
} else {
rpDesc = [[templateRenderPipelineDesc copy] autorelease];
rpDesc = templateRenderPipelineDesc;
}
struct RadGradFrameUniforms uf = {
@@ -805,10 +805,10 @@ jint _color;
if (renderOptions->isTexture) {
vertShader = @"vert_txt_tp";
fragShader = @"frag_txt_tp";
rpDesc = [[templateTexturePipelineDesc copy] autorelease];
rpDesc = templateTexturePipelineDesc;
[encoder setFragmentTexture:_paintTexture atIndex:1];
} else {
rpDesc = [[templateRenderPipelineDesc copy] autorelease];
rpDesc = templateRenderPipelineDesc;
[encoder setFragmentTexture:_paintTexture atIndex:0];
}
const SurfaceRasterFlags srcFlags = {_isOpaque, renderOptions->srcFlags.isPremultiplied};
@@ -835,7 +835,7 @@ jint _color;
// Texture paint XOR mode rendering uses a tile based rendering using a SW pipe (similar to OGL)
NSString* vertShader = @"vert_tp_xorMode";
NSString* fragShader = @"frag_tp_xorMode";
MTLRenderPipelineDescriptor *rpDesc = [[templateRenderPipelineDesc copy] autorelease];
MTLRenderPipelineDescriptor *rpDesc = templateRenderPipelineDesc;
jint xorColor = (jint) [mtlc.composite getXorColor];
[encoder setVertexBytes:&_anchor length:sizeof(_anchor) atIndex:FrameUniformBuffer];
@@ -954,7 +954,7 @@ setTxtUniforms(MTLContext *mtlc, int color, id <MTLRenderCommandEncoder> encoder
if (renderOptions->isTexture) {
NSString * vertShader = @"vert_txt";
NSString * fragShader = @"frag_txt";
MTLRenderPipelineDescriptor* rpDesc = [[templateTexturePipelineDesc copy] autorelease];
MTLRenderPipelineDescriptor* rpDesc = templateTexturePipelineDesc;
NSObject *bufImgOp = [mtlc getBufImgOp];
if (bufImgOp != nil) {
@@ -1013,7 +1013,7 @@ setTxtUniforms(MTLContext *mtlc, int color, id <MTLRenderCommandEncoder> encoder
context:mtlc
renderOptions:renderOptions
pipelineStateStorage:pipelineStateStorage
rpDesc:[[templateRenderPipelineDesc copy] autorelease]
rpDesc:templateRenderPipelineDesc
vertShader:@"vert_col"
fragShader:@"frag_col"
color:0];
@@ -1033,7 +1033,7 @@ setTxtUniforms(MTLContext *mtlc, int color, id <MTLRenderCommandEncoder> encoder
jint xorColor = (jint) [mtlc.composite getXorColor];
NSString * vertShader = @"vert_txt_xorMode";
NSString * fragShader = @"frag_txt_xorMode";
MTLRenderPipelineDescriptor * rpDesc = [[templateTexturePipelineDesc copy] autorelease];
MTLRenderPipelineDescriptor * rpDesc = templateTexturePipelineDesc;
const int col = 0 ^ xorColor;
setTxtUniforms(mtlc, col, encoder,
@@ -1061,7 +1061,7 @@ setTxtUniforms(MTLContext *mtlc, int color, id <MTLRenderCommandEncoder> encoder
context:mtlc
renderOptions:renderOptions
pipelineStateStorage:pipelineStateStorage
rpDesc:[[templateRenderPipelineDesc copy] autorelease]
rpDesc:templateRenderPipelineDesc
vertShader:@"vert_col"
fragShader:@"frag_col"
color:0];