Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

8262115: Crash on graphics card switch when Metal API validation enabled

  • Loading branch information
aghaisas committed Feb 22, 2021
1 parent 80418ed commit 99874878f7b99c735eb56ee905840b9c6749a34e
@@ -65,6 +65,7 @@ enum Clip {
- (const MTLScissorRect *) getRect;

- (void)reset;
- (void)resetStencilState;
- (void)setClipRectX1:(jint)x1 Y1:(jint)y1 X2:(jint)x2 Y2:(jint)y2;
- (void)beginShapeClip:(BMTLSDOps *)dstOps context:(MTLContext *)mtlc;
- (void)endShapeClip:(BMTLSDOps *)dstOps context:(MTLContext *)mtlc;
@@ -29,6 +29,7 @@
#include "common.h"

static MTLRenderPipelineDescriptor * templateStencilPipelineDesc = nil;
static id<MTLDepthStencilState> stencilState = nil;

static void initTemplatePipelineDescriptors() {
if (templateStencilPipelineDesc != nil)
@@ -50,7 +51,6 @@ static void initTemplatePipelineDescriptors() {
}

static id<MTLDepthStencilState> getStencilState(id<MTLDevice> device) {
static id<MTLDepthStencilState> stencilState = nil;
if (stencilState == nil) {
MTLDepthStencilDescriptor* stencilDescriptor;
stencilDescriptor = [[MTLDepthStencilDescriptor new] autorelease];
@@ -138,6 +138,13 @@ - (void)reset {
_stencilMaskGenerationInProgress = JNI_FALSE;
}

- (void)resetStencilState {
if (stencilState != nil) {
[stencilState release];
stencilState = nil;
}
}

- (void)setClipRectX1:(jint)x1 Y1:(jint)y1 X2:(jint)x2 Y2:(jint)y2 {
if (_clipType == SHAPE_CLIP) {
_dstOps = NULL;
@@ -172,7 +172,7 @@
M01:(jdouble) m01 M11:(jdouble) m11
M02:(jdouble) m02 M12:(jdouble) m12;


- (void)reset;
- (void)resetPaint;
- (void)setColorPaint:(int)pixel;
- (void)setGradientPaintUseMask:(jboolean)useMask
@@ -173,6 +173,13 @@ - (void)dealloc {
[super dealloc];
}

- (void) reset {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLContext : reset");

// Add code for context state reset here
[_clip resetStencilState];
}

- (MTLCommandBufferWrapper *) getCommandBufferWrapper {
if (_commandBufferWrapper == nil) {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLContext : commandBuffer is NULL");
@@ -835,6 +835,7 @@ - (NSString *)description {
return @"unknown-paint";
}

static bool samplersInitialized = false;
static id<MTLSamplerState> samplerNearestClamp = nil;
static id<MTLSamplerState> samplerLinearClamp = nil;
static id<MTLSamplerState> samplerNearestRepeat = nil;
@@ -843,8 +844,15 @@ - (NSString *)description {
void initSamplers(id<MTLDevice> device) {
// TODO: move this code into SamplerManager (need implement)

if (samplerNearestClamp != nil)
return;
if (samplersInitialized) {
// Release old samplers if any
[samplerNearestClamp release];
[samplerLinearClamp release];
[samplerNearestRepeat release];
[samplerLinearRepeat release];

samplersInitialized = false;
}

MTLSamplerDescriptor *samplerDescriptor = [[MTLSamplerDescriptor new] autorelease];

@@ -871,6 +879,8 @@ void initSamplers(id<MTLDevice> device) {
samplerDescriptor.minFilter = MTLSamplerMinMagFilterLinear;
samplerDescriptor.magFilter = MTLSamplerMinMagFilterLinear;
samplerLinearRepeat = [device newSamplerStateWithDescriptor:samplerDescriptor];

samplersInitialized = true;
}

static void setSampler(id<MTLRenderCommandEncoder> encoder, int interpolation, bool repeat) {
@@ -663,10 +663,18 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
// invalidate the references to the current context and
// destination surface that are maintained at the native level
if (mtlc != NULL) {
[mtlc.encoderManager endEncoder];
commitEncodedCommands();
RESET_PREVIOUS_OP();
[mtlc reset];
}

MTLTR_FreeGlyphCaches();
if (dstOps != NULL) {
MTLSD_Delete(env, dstOps);
}

mtlc = NULL;
// dstOps = NULL;
dstOps = NULL;
break;
}
case sun_java2d_pipe_BufferedOpCodes_SYNC:

0 comments on commit 9987487

Please sign in to comment.