Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create use-after-free detector for Metal textures #7250

Merged
merged 12 commits into from
Oct 20, 2023
Merged

Conversation

bejado
Copy link
Member

@bejado bejado commented Oct 9, 2023

No description provided.

@bejado bejado requested a review from pixelflinger October 9, 2023 22:10
@bejado bejado added the internal Issue/PR does not affect clients label Oct 9, 2023
@google google deleted a comment from github-actions bot Oct 9, 2023
filament/backend/include/private/backend/DriverAPI.inc Outdated Show resolved Hide resolved
filament/backend/src/metal/MetalContext.h Outdated Show resolved Hide resolved
filament/backend/src/metal/MetalDriver.mm Outdated Show resolved Hide resolved
filament/backend/src/metal/MetalDriver.mm Outdated Show resolved Hide resolved
filament/backend/src/metal/MetalHandles.h Outdated Show resolved Hide resolved
filament/src/details/MaterialInstance.cpp Outdated Show resolved Hide resolved
@bejado bejado force-pushed the bjd/use-after-free branch from 5a7dfac to 943655f Compare October 16, 2023 18:28
metalTexture->terminate();

// Delay the destruction of this texture handle.
if (mContext->texturesToDestroy.full()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (mContext->texturesToDestroy.full()) {
if (UTILS_LIKELY(mContext->texturesToDestroy.full())) {

filament/backend/src/metal/MetalDriver.mm Outdated Show resolved Hide resolved
filament/backend/src/metal/MetalHandles.h Show resolved Hide resolved
filament/backend/src/metal/MetalHandles.mm Outdated Show resolved Hide resolved
filament/src/details/MaterialInstance.cpp Outdated Show resolved Hide resolved
metalTexture->terminate();

if (auto handleToFree = mContext->texturesToDestroy.push(th)) {
// Delay the destruction of this texture handle.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment confuses me a little shouldn't it be "delayed destruction of a previously destroyed handle" or something to that effect?

@@ -854,22 +870,26 @@
assert_invariant(sb->size == data.size / sizeof(SamplerDescriptor));
auto const* const samplers = (SamplerDescriptor const*) data.buffer;

#ifndef NDEBUG
// In debug builds, verify that all the textures in the sampler group are still alive.
// Verify that all the textures in the sampler group are still alive.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunate that this whole loop is technically not needed.

@bejado bejado merged commit 9d181a1 into main Oct 20, 2023
10 checks passed
@bejado bejado deleted the bjd/use-after-free branch October 20, 2023 21:15
plepers pushed a commit to plepers/filament that referenced this pull request Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Issue/PR does not affect clients
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants