Skip to content

New picking framework - #96

Open
ccpisheden wants to merge 18 commits into
mainfrom
picking
Open

ccpisheden wants to merge 18 commits into
mainfrom
picking

Conversation

@ccpisheden

Copy link
Copy Markdown

Summary

Linked issue (optional)

Testing

AI assistance

Checklist

  • Read CONTRIBUTING.md.
    • Commits follow the commit-message style described there.
    • Added or updated tests where it made sense.
    • Updated docs / inline API comments for any behaviour change.

@ccpgames-carbon

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@ccpisheden ccpisheden changed the title Picking New picking framework Sep 23, 2026
@ccpisheden
ccpisheden marked this pull request as ready for review September 23, 2026 16:40
@filipppavlov
filipppavlov requested a balanced review from Copilot September 24, 2026 11:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Readback lifetime and region handling defects, duplicate instance identifiers, and changed object-resolution behavior can produce invalid or incorrect picking results.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 2 High severity · 3 Medium severity · 1 Low severity

Open (6)
What changed in this PR

Introduces asynchronous GPU readbacks and expands picking results to include 64-bit object pointers plus two additional data values.

Changes:

  • Adds cross-backend Tr2ReadbackAL support.
  • Reworks scene/debug/instanced-mesh picking and Python APIs.
  • Propagates 64-bit picking identifiers through render data.
File Description
trinityal/​stub/​Tr2TextureALStub.h Declares stub readback support.
trinityal/​stub/​Tr2TextureALStub.cpp Implements stub readbacks.
trinityal/​src/​Tr2TextureAL.cpp Adds public readback wrapper.
trinityal/​metal/​Tr2TextureALMetal.mm Implements Metal readbacks.
trinityal/​metal/​Tr2TextureALMetal.h Declares Metal readback resources.
trinityal/​include/​Tr2TextureAL.h Exposes the readback API.
trinityal/​dx12/​Tr2TextureALDx12.h Declares DX12 readback resources.
trinityal/​dx12/​Tr2TextureALDx12.cpp Implements DX12 readbacks.
trinityal/​dx11/​Tr2TextureALDx11.h Declares DX11 readback resources.
trinityal/​dx11/​Tr2TextureALDx11.cpp Implements DX11 readbacks.
trinity/​Utilities/​BVH.cpp Adds an explicit index cast.
trinity/​Tr2SkinnedModel.cpp Propagates picking pointers.
trinity/​Tr2RenderContext.h Stores split picking-pointer variables.
trinity/​Tr2RenderContext.cpp Uploads pointer halves and area data.
trinity/​Tr2PickBuffer.h Simplifies synchronous mapping API.
trinity/​Tr2PickBuffer.cpp Updates pick-buffer mapping.
trinity/​Tr2PerObjectData.h Replaces user data with 64-bit picking data.
trinity/​Tr2DebugRenderer.h Updates debug picking interface.
trinity/​Tr2DebugRenderer.cpp Integrates debug geometry into shared picking.
trinity/​ITr2PickableScene.cpp Adopts the updated picking API.
trinity/​Interior/​Tr2IntSkinnedObject.cpp Propagates picking pointers.
trinity/​Eve/​SpaceObject/​Children/​EveChildMesh.cpp Simplifies LOD lookup.
trinity/​Eve/​SpaceObject/​Children/​EveChildInstancedMeshes.cpp Adds per-instance picking metadata.
trinity/​Eve/​EveSpaceScene.h Declares new picking buffers and APIs.
trinity/​Eve/​EveSpaceScene.cpp Implements the new picking pipeline.
trinity/​Eve/​EveSpaceScene_Blue.cpp Exposes expanded Python picking results.
trinity/​Eve/​EvePicking.h Redesigns pending readback state.
trinity/​Eve/​EvePicking.cpp Stores two extra result values.
trinity/​Eve/​EveInstancedMeshManager.h Extends instance picking data.
trinity/​Eve/​EveInstancedMeshManager.cpp Uploads and renders new picking metadata.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

{
m_readScratch->Unmap( 0, nullptr );
}
m_readScratch = nullptr;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like it is an issue for reals

Comment on lines +42 to +46
if( !m_readback )
{
return E_INVALIDCALL;
}
return m_readback->Map( pointer, rowPitch, renderContext );

CR_RETURN( Tr2Renderer::BeginRenderContext() );
ON_BLOCK_EXIT( [&] { Tr2Renderer::EndRenderContext(); } );
Tr2Renderer::BeginRenderContext();
Comment on lines +512 to +513
instanceData.pickingMeshIndex = pickingMeshIndex;
instanceData.pickingInstanceIndex = static_cast<uint32_t>( i );
Comment on lines +209 to +210
std::shared_ptr<Tr2ReadbackAL> readback = std::make_shared<Tr2ReadbackAL>();
readback->Initialize( size, mipPitch ); //mipPitch here is probably wrong.

bool operator==( const Tr2TextureAL& other ) const;

Tr2ReadbackAL CreateReadback( const Tr2TextureSubresource& region, Tr2PrimaryRenderContextAL& renderContext );
class Tr2ReadbackAL : public Tr2DeviceResourceAL<Tr2ReadbackAL>
{
public:
void Initialize( size_t size, uint32_t rowPitch );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: missed this one Initialize->constructor

if( !objectOffsets.empty() )
{
objects.reserve( objectOffsets.size() );
blueObjects.reserve( objectOffsets.size() );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: the draw is called twice for lines and triangles with the same blueObjects argument, so this reserve seems misplaced. Would it be better to move it to the caller: line 811?

}

// ------------------------------------------------------------------------------------------------------
void EvePendingPickingReadback::ReleaseResources( TriStorage s )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since both ReleaseResources and OnPrepareResources are empty, the class doesn't need to inherit from Tr2DeviceResource

EveInstancedMeshManager::StaticPerInstanceData instanceData;
instanceData.worldTransform = Float4x3( instanceTransforms[i] );
instanceData.sphereIndex = static_cast<uint32_t>( existingCount + i );
instanceData.pickingMeshIndex = pickingMeshIndex;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This line, and the next one, look incorrect: we are adding instances to an already existing mesh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants