New picking framework - #96
ccpisheden wants to merge 18 commits into
Conversation
|
|
There was a problem hiding this comment.
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
Open (6)
Defer DX12 readback resource release until GPU completion · New Reject invalid backend readbacks before mapping · New Handle BeginRenderContext failure before issuing readback commands · New Advance picking indices across merged mesh additions · New Initialize stub readbacks from the source texture data · New Add asynchronous readback coverage for regions and lifetimes · New
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
Tr2ReadbackALsupport. - 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; |
There was a problem hiding this comment.
Looks like it is an issue for reals
| if( !m_readback ) | ||
| { | ||
| return E_INVALIDCALL; | ||
| } | ||
| return m_readback->Map( pointer, rowPitch, renderContext ); |
|
|
||
| CR_RETURN( Tr2Renderer::BeginRenderContext() ); | ||
| ON_BLOCK_EXIT( [&] { Tr2Renderer::EndRenderContext(); } ); | ||
| Tr2Renderer::BeginRenderContext(); |
| instanceData.pickingMeshIndex = pickingMeshIndex; | ||
| instanceData.pickingInstanceIndex = static_cast<uint32_t>( i ); |
| 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 ); |
There was a problem hiding this comment.
Minor: missed this one Initialize->constructor
| if( !objectOffsets.empty() ) | ||
| { | ||
| objects.reserve( objectOffsets.size() ); | ||
| blueObjects.reserve( objectOffsets.size() ); |
There was a problem hiding this comment.
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 ) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
This line, and the next one, look incorrect: we are adding instances to an already existing mesh



Summary
Linked issue (optional)
Testing
AI assistance
Checklist