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

[render_vtk] Create a new mapper per actor #21962

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sankhesh
Copy link
Contributor

@sankhesh sankhesh commented Sep 27, 2024

The vtkMapper is responsible for creating and uploading graphics resources per OpenGL context. Re-using vtkMapper instances across clones would cause unintentional side-effects like the ones described in #20002 and #21700 (comment)


This change is Reviewable

@jwnimmer-tri
Copy link
Collaborator

@drake-jenkins-bot ok to test

+@SeanCurtis-TRI for discussion and/or review, please.

@jwnimmer-tri jwnimmer-tri added the release notes: fix This pull request contains fixes (no new features) label Sep 27, 2024
@SeanCurtis-TRI
Copy link
Contributor

I'll get to this maybe today, definitely Monday. I can't say I'm surprised by the findings. My delay will give you a chance to address the CI woes.

@jwnimmer-tri jwnimmer-tri changed the title FIX: Create a new mapper per actor [render_vtk] Create a new mapper per actor Sep 27, 2024
Copy link
Contributor

@SeanCurtis-TRI SeanCurtis-TRI left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: 1 unresolved discussion, LGTM missing from assignee SeanCurtis-TRI(platform), needs at least two assigned reviewers


geometry/render_vtk/internal_render_engine_vtk.cc line 519 at r1 (raw file):

        vtkNew<vtkOpenGLPolyDataMapper> target_mapper;
        target_mapper->ShallowCopy(source_part.actor->GetMapper());
        target_actor->SetMapper(target_mapper);

I don't have permissions to push to your branch. So, instead of pushing a commit to resolve CI problems, I'll have to add the code here:

      for (const auto& source_part : source_prop.parts) {
        vtkNew<vtkActor> target_actor;
        target_actor->ShallowCopy(source_part.actor);
        vtkNew<vtkOpenGLPolyDataMapper> target_mapper;
        target_mapper->ShallowCopy(source_part.actor->GetMapper());
        target_actor->SetMapper(target_mapper);
        if (i == kDepth) {
          // The shallow copying doesn't fully reproduce the configuration of
          // depth shader.
          vtkOpenGLShaderProperty* shader_prop =
              vtkOpenGLShaderProperty::SafeDownCast(
                  target_actor->GetShaderProperty());
          DRAKE_DEMAND(shader_prop != nullptr);
          shader_prop->SetVertexShaderCode(render::shaders::kDepthVS);
          shader_prop->SetFragmentShaderCode(render::shaders::kDepthFS);
          target_mapper->AddObserver(vtkCommand::UpdateShaderEvent,
                                     uniform_setting_callback_.Get());
        }
        renderer.AddActor(target_actor);
        target_prop.parts.push_back(
            Part{.actor = std::move(target_actor), .T_GA = source_part.T_GA});
      }

Note: this is the same configuration work that is done in two other places: ImplementPolyData() and ImplementGltf(). This pushes us across the "rule of three" and it should be refactored for better re-use.

@sankhesh
Copy link
Contributor Author

sankhesh commented Oct 2, 2024

@SeanCurtis-TRI Thanks for the review. I should have prefaced this with WIP. It seems like drake copies the mapper by design

// Having "shared geometry" means having shared vtkPolyDataAlgorithm and
// vtkOpenGLPolyDataMapper instances. The shader callback gets registered to

But that leads to graphics resources being copied and shared and unintentional side-effects. What was the original use-case for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes: fix This pull request contains fixes (no new features)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants