Skip to content

Commit 8bf4868

Browse files
committed
Merge branch 'development' of https://github.com/o3de/o3de into daimini/SliceLevelUiRedCode/SliceLayers
Signed-off-by: Danilo Aimini <[email protected]>
2 parents 7839ba9 + 65e90ca commit 8bf4868

13 files changed

+98
-61
lines changed

Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
1919
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
2020
#include <AzToolsFramework/Entity/EditorEntityInfoBus.h>
21+
#include <AzToolsFramework/Entity/EditorEntitySortComponent.h>
2122
#include <AzToolsFramework/Entity/PrefabEditorEntityOwnershipInterface.h>
2223
#include <AzToolsFramework/Entity/ReadOnly/ReadOnlyEntityInterface.h>
2324
#include <AzToolsFramework/Prefab/EditorPrefabComponent.h>
@@ -36,14 +37,23 @@
3637
#include <AzToolsFramework/Prefab/Undo/PrefabUndoUpdateLink.h>
3738
#include <AzToolsFramework/Prefab/PrefabUndoHelpers.h>
3839
#include <AzToolsFramework/ToolsComponents/TransformComponent.h>
39-
#include <AzToolsFramework/Entity/EditorEntitySortComponent.h>
40+
#include <AzToolsFramework/ViewportSelection/EditorTransformComponentSelectionRequestBus.h>
4041

4142
#include <QString>
43+
#include <QTimer>
4244

4345
namespace AzToolsFramework
4446
{
4547
namespace Prefab
4648
{
49+
PrefabPublicHandler::PrefabPublicHandler()
50+
{
51+
// Detect whether this is being run in the Editor or during a Unit Test.
52+
AZ::ApplicationTypeQuery appType;
53+
AZ::ComponentApplicationBus::Broadcast(&AZ::ComponentApplicationBus::Events::QueryApplicationType, appType);
54+
m_isRunningInEditor = (!appType.IsValid() || appType.IsEditor());
55+
}
56+
4757
void PrefabPublicHandler::RegisterPrefabPublicHandlerInterface()
4858
{
4959
m_prefabFocusHandler.RegisterPrefabFocusInterface();
@@ -1340,8 +1350,25 @@ namespace AzToolsFramework
13401350
// Select the duplicated entities/instances
13411351
auto selectionUndo = aznew SelectionCommand(duplicatedEntityAndInstanceIds, "Select Duplicated Entities/Instances");
13421352
selectionUndo->SetParent(undoBatch.GetUndoBatch());
1343-
ToolsApplicationRequestBus::Broadcast(
1344-
&ToolsApplicationRequestBus::Events::SetSelectedEntities, duplicatedEntityAndInstanceIds);
1353+
1354+
// Only delay selection in the Editor to ensure the manipulators in the viewport are refreshed correctly.
1355+
if (m_isRunningInEditor)
1356+
{
1357+
QTimer::singleShot(
1358+
0,
1359+
[duplicatedEntityAndInstanceIds]()
1360+
{
1361+
ToolsApplicationRequestBus::Broadcast(
1362+
&ToolsApplicationRequestBus::Events::SetSelectedEntities, duplicatedEntityAndInstanceIds);
1363+
}
1364+
);
1365+
}
1366+
else
1367+
{
1368+
ToolsApplicationRequestBus::Broadcast(
1369+
&ToolsApplicationRequestBus::Events::SetSelectedEntities, duplicatedEntityAndInstanceIds);
1370+
}
1371+
13451372
}
13461373

13471374
return AZ::Success(AZStd::move(duplicatedEntityAndInstanceIds));

Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace AzToolsFramework
3939
AZ_CLASS_ALLOCATOR(PrefabPublicHandler, AZ::SystemAllocator);
4040
AZ_RTTI(PrefabPublicHandler, "{35802943-6B60-430F-9DED-075E3A576A25}", PrefabPublicInterface);
4141

42+
PrefabPublicHandler();
43+
4244
void RegisterPrefabPublicHandlerInterface();
4345
void UnregisterPrefabPublicHandlerInterface();
4446

@@ -212,6 +214,8 @@ namespace AzToolsFramework
212214
PrefabFocusHandler m_prefabFocusHandler;
213215

214216
uint64_t m_newEntityCounter = 1;
217+
218+
bool m_isRunningInEditor = true;
215219
};
216220
} // namespace Prefab
217221
} // namespace AzToolsFramework

Gems/Atom/RHI/Code/Include/Atom/RHI/IndirectArguments.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace AZ::RHI
2020

2121
IndirectArgumentsTemplate(
2222
uint32_t maxSequenceCount,
23-
const IndirectBufferView& indirectBuffer,
23+
const IndirectBufferViewClass& indirectBuffer,
2424
uint64_t indirectBufferByteOffset)
2525
: IndirectArgumentsTemplate(
2626
maxSequenceCount,
@@ -32,9 +32,9 @@ namespace AZ::RHI
3232

3333
IndirectArgumentsTemplate(
3434
uint32_t maxSequenceCount,
35-
const IndirectBufferView& indirectBuffer,
35+
const IndirectBufferViewClass& indirectBuffer,
3636
uint64_t indirectBufferByteOffset,
37-
const Buffer* countBuffer,
37+
const BufferClass* countBuffer,
3838
uint64_t countBufferByteOffset)
3939
: m_maxSequenceCount(maxSequenceCount)
4040
, m_indirectBufferView(&indirectBuffer)

Gems/Atom/RHI/Code/Include/Atom/RHI/MultiDeviceBufferPool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace AZ::RHI
2020
struct MultiDeviceBufferMapResponse
2121
{
2222
//! Will hold the mapped data for each device selected in the MultiDeviceBuffer
23-
AZStd::vector<void*> m_data;
23+
AZStd::unordered_map<int, void*> m_data;
2424
};
2525

2626
using MultiDeviceBufferInitRequest = BufferInitRequestTemplate<MultiDeviceBuffer>;

Gems/Atom/RHI/Code/Include/Atom/RHI/MultiDeviceDispatchItem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace AZ::RHI
5353
case DispatchType::Direct:
5454
return DispatchArguments(m_direct);
5555
case DispatchType::Indirect:
56-
return DispatchArguments(DispatchIndirect{m_mdIndirect.m_maxSequenceCount, m_mdIndirect.m_indirectBufferView->GetDeviceIndirectBufferView(deviceIndex), m_mdIndirect.m_indirectBufferByteOffset, m_mdIndirect.m_countBuffer->GetDeviceBuffer(deviceIndex).get(), m_mdIndirect.m_countBufferByteOffset});
56+
return DispatchArguments(DispatchIndirect{m_mdIndirect.m_maxSequenceCount, m_mdIndirect.m_indirectBufferView->GetDeviceIndirectBufferView(deviceIndex), m_mdIndirect.m_indirectBufferByteOffset, m_mdIndirect.m_countBuffer ? m_mdIndirect.m_countBuffer->GetDeviceBuffer(deviceIndex).get() : nullptr, m_mdIndirect.m_countBufferByteOffset});
5757
default:
5858
return DispatchArguments();
5959
}

Gems/Atom/RHI/Code/Include/Atom/RHI/MultiDeviceIndirectBufferView.h

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,55 @@ namespace AZ::RHI
3232
uint32_t byteCount,
3333
uint32_t byteStride);
3434

35+
//! The mutex stops the default generation
36+
MultiDeviceIndirectBufferView(const MultiDeviceIndirectBufferView& other)
37+
: m_hash{ other.m_hash }
38+
, m_mdBuffer{ other.m_mdBuffer }
39+
, m_mdSignature{ other.m_mdSignature }
40+
, m_byteOffset{ other.m_byteOffset }
41+
, m_byteCount{ other.m_byteCount }
42+
, m_byteStride{ other.m_byteStride }
43+
{
44+
}
45+
46+
MultiDeviceIndirectBufferView& operator=(const MultiDeviceIndirectBufferView& other)
47+
{
48+
this->m_hash = other.m_hash;
49+
this->m_mdBuffer = other.m_mdBuffer;
50+
this->m_mdSignature = other.m_mdSignature;
51+
this->m_byteOffset = other.m_byteOffset;
52+
this->m_byteCount = other.m_byteCount;
53+
this->m_byteStride = other.m_byteStride;
54+
55+
return *this;
56+
}
57+
3558
//! Returns the device-specific IndirectBufferView for the given index
36-
IndirectBufferView GetDeviceIndirectBufferView(int deviceIndex) const
59+
const IndirectBufferView& GetDeviceIndirectBufferView(int deviceIndex) const
3760
{
3861
AZ_Error("MultiDeviceIndirectBufferView", m_mdSignature, "No MultiDeviceIndirectBufferSignature available\n");
3962
AZ_Error("MultiDeviceIndirectBufferView", m_mdBuffer, "No MultiDeviceBuffer available\n");
4063

41-
return IndirectBufferView(
42-
*m_mdBuffer->GetDeviceBuffer(deviceIndex),
43-
*m_mdSignature->GetDeviceIndirectBufferSignature(deviceIndex),
44-
m_byteOffset,
45-
m_byteCount,
46-
m_byteStride);
64+
AZStd::lock_guard lock(m_bufferViewMutex);
65+
auto iterator{ m_cache.find(deviceIndex) };
66+
if (iterator == m_cache.end())
67+
{
68+
//! Buffer view is not yet in the cache
69+
auto [new_iterator, inserted]{ m_cache.insert(AZStd::make_pair(
70+
deviceIndex,
71+
IndirectBufferView(
72+
*m_mdBuffer->GetDeviceBuffer(deviceIndex),
73+
*m_mdSignature->GetDeviceIndirectBufferSignature(deviceIndex),
74+
m_byteOffset,
75+
m_byteCount,
76+
m_byteStride))) };
77+
if (inserted)
78+
{
79+
return new_iterator->second;
80+
}
81+
}
82+
83+
return iterator->second;
4784
}
4885

4986
//! Returns the hash of the view. This hash is precomputed at creation time.
@@ -72,5 +109,9 @@ namespace AZ::RHI
72109
uint32_t m_byteOffset = 0;
73110
uint32_t m_byteCount = 0;
74111
uint32_t m_byteStride = 0;
112+
113+
//! Safe-guard access to IndirectBufferView cache during parallel access
114+
mutable AZStd::mutex m_bufferViewMutex{};
115+
mutable AZStd::unordered_map<int, IndirectBufferView> m_cache;
75116
};
76117
} // namespace AZ::RHI

Gems/Atom/RHI/Code/Include/Atom/RHI/MultiDeviceShaderResourceGroupData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace AZ::RHI
5454
ShaderInputConstantIndex FindShaderInputConstantIndex(const Name& name) const;
5555

5656
//! Sets one image view for the given shader input index.
57-
bool SetImageView(ShaderInputImageIndex inputIndex, const MultiDeviceImageView* imageView, uint32_t arrayIndex);
57+
bool SetImageView(ShaderInputImageIndex inputIndex, const MultiDeviceImageView* imageView, uint32_t arrayIndex = 0);
5858

5959
//! Sets an array of image view for the given shader input index.
6060
bool SetImageViewArray(

Gems/Atom/RHI/Code/Include/Atom/RHI/MultiDeviceSwapChain.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ namespace AZ::RHI
4040
//! it is explicitly initialized with just a deviceIndex
4141
ResultCode Init(int deviceIndex, const SwapChainDescriptor& descriptor);
4242

43+
Ptr<SwapChain> GetDeviceSwapChain() const;
44+
4345
//! Presents the swap chain to the display, and rotates the images.
4446
void Present();
4547

Gems/Atom/RHI/Code/Source/RHI/MultiDeviceBufferPool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ namespace AZ::RHI
230230
}
231231
else
232232
{
233-
response.m_data.push_back(deviceMapResponse.m_data);
233+
response.m_data[deviceIndex] = deviceMapResponse.m_data;
234234
}
235235

236236
return resultCode;

Gems/Atom/RHI/Code/Source/RHI/MultiDeviceIndirectBufferSignature.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ namespace AZ::RHI
1616
IndirectBufferSignatureDescriptor MultiDeviceIndirectBufferSignatureDescriptor::GetDeviceIndirectBufferSignatureDescriptor(
1717
int deviceIndex) const
1818
{
19-
AZ_Assert(m_pipelineState, "No MultiDevicePipelineState available\n");
20-
2119
IndirectBufferSignatureDescriptor descriptor{ m_layout };
2220

2321
if (m_pipelineState)

0 commit comments

Comments
 (0)