[Mesa-dev] [PATCH] i965: Unbind deleted shaders from brw_context, fixing malloc heisenbug.
Kenneth Graunke
kenneth at whitecape.org
Thu Jan 26 22:08:29 UTC 2017
On Thursday, January 26, 2017 12:00:14 PM PST Eric Anholt wrote:
> Kenneth Graunke <kenneth at whitecape.org> writes:
>
> > Applications may delete a shader program, create a new one, and bind it
> > before the next draw. With terrible luck, malloc may randomly return a
> > chunk of memory for the new gl_program that happened to be the exact
> > same pointer as our previously bound gl_program. In this case, our
> > logic to detect new programs in brw_upload_pipeline_state() would break:
> >
> > if (brw->vertex_program != ctx->VertexProgram._Current) {
> > brw->vertex_program = ctx->VertexProgram._Current;
> > brw->ctx.NewDriverState |= BRW_NEW_VERTEX_PROGRAM;
> > }
> >
> > Because the pointer is the same, we'd think it was the same program.
> > But it could be wildly different - a different stage altogether,
> > different sets of resources, and so on. This causes utter chaos.
>
> Any reason you're not just using _mesa_reference_program()?
That might be a better plan.
Conceptually, I thought of this more as a "weak reference" - we want to
know if the current program is the same as the last draw...but we don't
want to hold on to the program and prevent its deletion.
Plus, it would add a bit of reference counting overhead in the draw path
(though this is probably negligable - Mesa does a lot of it already).
I suppose using real references would mean that a deleted program would
remain alive until the next glDraw*() that used a different shader.
Which could theoretically be forever, but is likely not that long, so
it's probably acceptable.
I don't know. I'll probably go with this patch for now since it works
and I've done a lot of testing. If people prefer the other way, I can
write a patch to do that...
--Ken
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170126/2bc48dd7/attachment.sig>
More information about the mesa-dev
mailing list