diff --git a/Assets/Engine/SeedAssetList.seed b/Assets/Engine/SeedAssetList.seed index 77ec509721..579fd3c444 100644 --- a/Assets/Engine/SeedAssetList.seed +++ b/Assets/Engine/SeedAssetList.seed @@ -64,30 +64,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -160,686 +136,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1384,166 +680,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1632,46 +768,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/AutomatedTesting/AutomatedTesting_Dependencies.xml b/AutomatedTesting/AutomatedTesting_Dependencies.xml index 50a5caea73..98e00a2914 100644 --- a/AutomatedTesting/AutomatedTesting_Dependencies.xml +++ b/AutomatedTesting/AutomatedTesting_Dependencies.xml @@ -1,5 +1,4 @@ - \ No newline at end of file diff --git a/AutomatedTesting/Gem/PythonTests/Atom/TestSuite_Main_GPU.py b/AutomatedTesting/Gem/PythonTests/Atom/TestSuite_Main_GPU.py index 249b9c7096..3403d8e9b1 100644 --- a/AutomatedTesting/Gem/PythonTests/Atom/TestSuite_Main_GPU.py +++ b/AutomatedTesting/Gem/PythonTests/Atom/TestSuite_Main_GPU.py @@ -226,9 +226,9 @@ class TestMaterialEditor(object): self, request, workspace, project, launcher_platform, generic_launcher, exe_file_name, cfg_args): """ Tests each valid RHI option (Null RHI excluded) can be launched with the MaterialEditor. - Checks for the "Finished loading viewport configurtions." success message post lounch. + Checks for the "Finished loading viewport configurations." success message post launch. """ - expected_lines = ["Finished loading viewport configurtions."] + expected_lines = ["Finished loading viewport configurations."] unexpected_lines = [ # "Trace::Assert", # "Trace::Error", @@ -241,7 +241,7 @@ class TestMaterialEditor(object): generic_launcher, editor_script="", run_python="--runpython", - timeout=30, + timeout=60, expected_lines=expected_lines, unexpected_lines=unexpected_lines, halt_on_unexpected=False, diff --git a/AutomatedTesting/Gem/PythonTests/prefab/Prefab.py b/AutomatedTesting/Gem/PythonTests/prefab/Prefab.py index 14a1ab62f0..9b4d2d1393 100644 --- a/AutomatedTesting/Gem/PythonTests/prefab/Prefab.py +++ b/AutomatedTesting/Gem/PythonTests/prefab/Prefab.py @@ -25,28 +25,39 @@ import prefab.Prefab_Test_Utils as prefab_test_utils # This is a helper class which contains some of the useful information about a prefab instance. class PrefabInstance: - def __init__(self, name: str=None, prefab_file_name: str=None, container_entity: EditorEntity=EntityId()): - self.name = name + def __init__(self, prefab_file_name: str=None, container_entity: EditorEntity=EntityId()): self.prefab_file_name: str = prefab_file_name self.container_entity: EditorEntity = container_entity + def __eq__(self, other): + return other and self.container_entity.id == other.container_entity.id + + def __ne__(self, other): + return not self.__eq__(other) + + def __hash__(self): + return hash(self.container_entity.id) + """ See if this instance is valid to be used with other prefab operations. :return: Whether the target instance is valid or not. """ def is_valid() -> bool: - return self.container_entity.id.IsValid() and self.name is not None and self.prefab_file_name in Prefab.existing_prefabs + return self.container_entity.id.IsValid() and self.prefab_file_name in Prefab.existing_prefabs - """ Reparent this instance to target parent entity. The function will also check pop up dialog ui in editor to see if there's prefab cyclical dependency error while reparenting prefabs. :param parent_entity_id: The id of the entity this instance should be a child of in the transform hierarchy next. """ async def ui_reparent_prefab_instance(self, parent_entity_id: EntityId): - container_entity_name = self.container_entity.get_name() - current_children_entity_ids_having_prefab_name = prefab_test_utils.get_children_ids_by_name(parent_entity_id, container_entity_name) - Report.info(f'current_children_entity_ids_having_prefab_name: {current_children_entity_ids_having_prefab_name}') + container_entity_id_before_reparent = self.container_entity.id + + original_parent = EditorEntity(self.container_entity.get_parent_id()) + original_parent_before_reparent_children_ids = set(original_parent.get_children_ids()) + + new_parent = EditorEntity(parent_entity_id) + new_parent_before_reparent_children_ids = set(new_parent.get_children_ids()) pyside_utils.run_soon(lambda: self.container_entity.set_parent_entity(parent_entity_id)) pyside_utils.run_soon(lambda: prefab_test_utils.wait_for_propagation()) @@ -60,18 +71,23 @@ class PrefabInstance: except pyside_utils.EventLoopTimeoutException: pass - updated_children_entity_ids_having_prefab_name = prefab_test_utils.get_children_ids_by_name(parent_entity_id, container_entity_name) - Report.info(f'updated_children_entity_ids_having_prefab_name: {updated_children_entity_ids_having_prefab_name}') - new_child_with_reparented_prefab_name_added = len(updated_children_entity_ids_having_prefab_name) == len(current_children_entity_ids_having_prefab_name) + 1 - assert new_child_with_reparented_prefab_name_added, "No entity with reparented prefab name become a child of target parent entity" + original_parent_after_reparent_children_ids = set(original_parent.get_children_ids()) + assert len(original_parent_after_reparent_children_ids) == len(original_parent_before_reparent_children_ids) - 1, \ + "The children count of the Prefab Instance's original parent should be decreased by 1." + assert not container_entity_id_before_reparent in original_parent_after_reparent_children_ids, \ + "This Prefab Instance is still a child entity of its original parent entity." + + new_parent_after_reparent_children_ids = set(new_parent.get_children_ids()) + assert len(new_parent_after_reparent_children_ids) == len(new_parent_before_reparent_children_ids) + 1, \ + "The children count of the Prefab Instance's new parent should be increased by 1." - updated_container_entity_id = set(updated_children_entity_ids_having_prefab_name).difference(current_children_entity_ids_having_prefab_name).pop() - updated_container_entity = EditorEntity(updated_container_entity_id) - updated_container_entity_parent_id = updated_container_entity.get_parent_id() - has_correct_parent = updated_container_entity_parent_id.ToString() == parent_entity_id.ToString() - assert has_correct_parent, "Prefab reparented is *not* under the expected parent entity" + container_entity_id_after_reparent = set(new_parent_after_reparent_children_ids).difference(new_parent_before_reparent_children_ids).pop() + reparented_container_entity = EditorEntity(container_entity_id_after_reparent) + reparented_container_entity_parent_id = reparented_container_entity.get_parent_id() + has_correct_parent = reparented_container_entity_parent_id.ToString() == parent_entity_id.ToString() + assert has_correct_parent, "Prefab Instance reparented is *not* under the expected parent entity" - self.container_entity = EditorEntity(updated_container_entity_id) + self.container_entity = reparented_container_entity # This is a helper class which contains some of the useful information about a prefab template. class Prefab: @@ -81,7 +97,7 @@ class Prefab: def __init__(self, file_name: str): self.file_name:str = file_name self.file_path: str = prefab_test_utils.get_prefab_file_path(file_name) - self.instances: dict = {} + self.instances: set[PrefabInstance] = set() """ Check if a prefab is ready to be used to generate its instances. @@ -122,10 +138,10 @@ class Prefab: :param entities: The entities that should form the new prefab (along with their descendants). :param file_name: A unique file name of new prefab. :param prefab_instance_name: A name for the very first instance generated while prefab creation. The default instance name is the same as file_name. - :return: An outcome object with an entityId of the new prefab's container entity; on failure, it comes with an error message detailing the cause of the error. + :return: Created Prefab object and the very first PrefabInstance object owned by the prefab. """ @classmethod - def create_prefab(cls, entities: list[EditorEntity], file_name: str, prefab_instance_name: str=None) -> Prefab: + def create_prefab(cls, entities: list[EditorEntity], file_name: str, prefab_instance_name: str=None) -> (Prefab, PrefabInstance): assert not Prefab.is_prefab_loaded(file_name), f"Can't create Prefab '{file_name}' since the prefab already exists" new_prefab = Prefab(file_name) @@ -133,18 +149,18 @@ class Prefab: create_prefab_result = prefab.PrefabPublicRequestBus(bus.Broadcast, 'CreatePrefabInMemory', entity_ids, new_prefab.file_path) assert create_prefab_result.IsSuccess(), f"Prefab operation 'CreatePrefab' failed. Error: {create_prefab_result.GetError()}" - container_entity = EditorEntity(create_prefab_result.GetValue()) + container_entity_id = create_prefab_result.GetValue() + container_entity = EditorEntity(container_entity_id) if prefab_instance_name: container_entity.set_name(prefab_instance_name) - else: - prefab_instance_name = file_name prefab_test_utils.wait_for_propagation() - container_entity_id = prefab_test_utils.find_entity_by_unique_name(prefab_instance_name) - new_prefab.instances[prefab_instance_name] = PrefabInstance(prefab_instance_name, file_name, EditorEntity(container_entity_id)) + + new_prefab_instance = PrefabInstance(file_name, EditorEntity(container_entity_id)) + new_prefab.instances.add(new_prefab_instance) Prefab.existing_prefabs[file_name] = new_prefab - return new_prefab + return new_prefab, new_prefab_instance """ Remove target prefab instances. @@ -152,22 +168,15 @@ class Prefab: """ @classmethod def remove_prefabs(cls, prefab_instances: list[PrefabInstance]): - instances_to_remove_name_counts = Counter() - instances_removed_expected_name_counts = Counter() - - entities_to_remove = [prefab_instance.container_entity for prefab_instance in prefab_instances] - while entities_to_remove: - entity = entities_to_remove.pop(-1) - entity_name = entity.get_name() - instances_to_remove_name_counts[entity_name] += 1 - + entity_ids_to_remove = [] + entity_id_queue = [prefab_instance.container_entity for prefab_instance in prefab_instances] + while entity_id_queue: + entity = entity_id_queue.pop(0) children_entity_ids = entity.get_children_ids() for child_entity_id in children_entity_ids: - entities_to_remove.append(EditorEntity(child_entity_id)) + entity_id_queue.append(EditorEntity(child_entity_id)) - for entity_name, entity_count in instances_to_remove_name_counts.items(): - entities = prefab_test_utils.find_entities_by_name(entity_name) - instances_removed_expected_name_counts[entity_name] = len(entities) - entity_count + entity_ids_to_remove.append(entity.id) container_entity_ids = [prefab_instance.container_entity.id for prefab_instance in prefab_instances] delete_prefab_result = prefab.PrefabPublicRequestBus(bus.Broadcast, 'DeleteEntitiesAndAllDescendantsInInstance', container_entity_ids) @@ -175,28 +184,24 @@ class Prefab: prefab_test_utils.wait_for_propagation() - prefab_entities_deleted = True - for entity_name, expected_entity_count in instances_removed_expected_name_counts.items(): - actual_entity_count = len(prefab_test_utils.find_entities_by_name(entity_name)) - if actual_entity_count is not expected_entity_count: - prefab_entities_deleted = False - break - - assert prefab_entities_deleted, "Not all entities and descendants in target prefabs are deleted." + entity_ids_after_delete = set(prefab_test_utils.get_all_entities()) + for entity_id_removed in entity_ids_to_remove: + if entity_id_removed in entity_ids_after_delete: + assert prefab_entities_deleted, "Not all entities and descendants in target prefabs are deleted." for instance in prefab_instances: instance_deleted_prefab = Prefab.get_prefab(instance.prefab_file_name) - instance_deleted_prefab.instances.pop(instance.name) + instance_deleted_prefab.instances.remove(instance) instance = PrefabInstance() """ Instantiate an instance of this prefab. - :param name: A name for newly instantiated prefab instance. The default instance name is the same as this prefab's file name. :param parent_entity: The entity the prefab should be a child of in the transform hierarchy. + :param name: A name for newly instantiated prefab instance. The default instance name is the same as this prefab's file name. :param prefab_position: The position in world space the prefab should be instantiated in. - :return: An outcome object with an entityId of the new prefab's container entity; on failure, it comes with an error message detailing the cause of the error. + :return: Instantiated PrefabInstance object owned by this prefab. """ - def instantiate(self, name: str=None, parent_entity: EditorEntity=None, prefab_position: Vector3=Vector3()) -> PrefabInstance: + def instantiate(self, parent_entity: EditorEntity=None, name: str=None, prefab_position: Vector3=Vector3()) -> PrefabInstance: parent_entity_id = parent_entity.id if parent_entity is not None else EntityId() instantiate_prefab_result = prefab.PrefabPublicRequestBus( @@ -209,13 +214,13 @@ class Prefab: if name: container_entity.set_name(name) - else: - name = self.file_name prefab_test_utils.wait_for_propagation() - container_entity_id = prefab_test_utils.find_entity_by_unique_name(name) - self.instances[name] = PrefabInstance(name, self.file_name, EditorEntity(container_entity_id)) + + new_prefab_instance = PrefabInstance(self.file_name, EditorEntity(container_entity_id)) + assert not new_prefab_instance in self.instances, "This prefab instance is already existed before this instantiation." + self.instances.add(new_prefab_instance) prefab_test_utils.check_entity_at_position(container_entity_id, prefab_position) - return container_entity_id + return new_prefab_instance diff --git a/AutomatedTesting/Gem/PythonTests/prefab/Prefab_BasicWorkflow_CreateAndDeletePrefab.py b/AutomatedTesting/Gem/PythonTests/prefab/Prefab_BasicWorkflow_CreateAndDeletePrefab.py index c6e0daa4dd..f3fbcfa6ad 100644 --- a/AutomatedTesting/Gem/PythonTests/prefab/Prefab_BasicWorkflow_CreateAndDeletePrefab.py +++ b/AutomatedTesting/Gem/PythonTests/prefab/Prefab_BasicWorkflow_CreateAndDeletePrefab.py @@ -22,11 +22,10 @@ def Prefab_BasicWorkflow_CreateAndDeletePrefab(): car_prefab_entities = [car_entity] # Checks for prefab creation passed or not - car_prefab = Prefab.create_prefab( + _, car = Prefab.create_prefab( car_prefab_entities, CAR_PREFAB_FILE_NAME) # Checks for prefab deletion passed or not - car = car_prefab.instances[CAR_PREFAB_FILE_NAME] Prefab.remove_prefabs([car]) if __name__ == "__main__": diff --git a/AutomatedTesting/Gem/PythonTests/prefab/Prefab_BasicWorkflow_CreateAndReparentPrefab.py b/AutomatedTesting/Gem/PythonTests/prefab/Prefab_BasicWorkflow_CreateAndReparentPrefab.py index 04f7b97628..e5a9d9930a 100644 --- a/AutomatedTesting/Gem/PythonTests/prefab/Prefab_BasicWorkflow_CreateAndReparentPrefab.py +++ b/AutomatedTesting/Gem/PythonTests/prefab/Prefab_BasicWorkflow_CreateAndReparentPrefab.py @@ -28,7 +28,7 @@ def Prefab_BasicWorkflow_CreateAndReparentPrefab(): car_prefab_entities = [car_entity] # Checks for prefab creation passed or not - car_prefab = Prefab.create_prefab( + _, car = Prefab.create_prefab( car_prefab_entities, CAR_PREFAB_FILE_NAME) # Creates another new Entity at the root level @@ -36,12 +36,10 @@ def Prefab_BasicWorkflow_CreateAndReparentPrefab(): wheel_prefab_entities = [wheel_entity] # Checks for wheel prefab creation passed or not - wheel_prefab = Prefab.create_prefab( + _, wheel = Prefab.create_prefab( wheel_prefab_entities, WHEEL_PREFAB_FILE_NAME) # Checks for prefab reparenting passed or not - car = car_prefab.instances[CAR_PREFAB_FILE_NAME] - wheel = wheel_prefab.instances[WHEEL_PREFAB_FILE_NAME] await wheel.ui_reparent_prefab_instance(car.container_entity.id) run_test() diff --git a/AutomatedTesting/Gem/PythonTests/prefab/Prefab_BasicWorkflow_InstantiatePrefab.py b/AutomatedTesting/Gem/PythonTests/prefab/Prefab_BasicWorkflow_InstantiatePrefab.py index b9015ab556..46be669697 100644 --- a/AutomatedTesting/Gem/PythonTests/prefab/Prefab_BasicWorkflow_InstantiatePrefab.py +++ b/AutomatedTesting/Gem/PythonTests/prefab/Prefab_BasicWorkflow_InstantiatePrefab.py @@ -22,11 +22,11 @@ def Prefab_BasicWorkflow_InstantiatePrefab(): # Checks for prefab instantiation passed or not test_prefab = Prefab.get_prefab(EXISTING_TEST_PREFAB_FILE_NAME) - instantiated_test_container_entity_id = test_prefab.instantiate( + test_instance = test_prefab.instantiate( prefab_position=INSTANTIATED_TEST_PREFAB_POSITION) prefab_test_utils.check_entity_children_count( - instantiated_test_container_entity_id, + test_instance.container_entity.id, EXPECTED_TEST_PREFAB_CHILDREN_COUNT) if __name__ == "__main__": diff --git a/AutomatedTesting/Gem/PythonTests/prefab/Prefab_Test_Utils.py b/AutomatedTesting/Gem/PythonTests/prefab/Prefab_Test_Utils.py index 8cd59ed077..3e19911449 100644 --- a/AutomatedTesting/Gem/PythonTests/prefab/Prefab_Test_Utils.py +++ b/AutomatedTesting/Gem/PythonTests/prefab/Prefab_Test_Utils.py @@ -29,20 +29,8 @@ def find_entities_by_name(entity_name): searchFilter.names = [entity_name] return entity.SearchBus(bus.Broadcast, 'SearchEntities', searchFilter) -def find_entity_by_unique_name(entity_name): - unique_name_entity_found_result = ( - "Entity with a unique name found", - "Entity with a unique name *not* found") - - entities = find_entities_by_name(entity_name) - unique_name_entity_found = len(entities) == 1 - Report.result(unique_name_entity_found_result, unique_name_entity_found) - - if unique_name_entity_found: - return entities[0] - else: - Report.info(f"{len(entities)} entities with name '{entity_name}' found") - return EntityId() +def get_all_entities(): + return entity.SearchBus(bus.Broadcast, 'SearchEntities', entity.SearchFilter()) def check_entity_at_position(entity_id, expected_entity_position): entity_at_expected_position_result = ( diff --git a/Code/Framework/AzCore/AzCore/Asset/AssetManager.cpp b/Code/Framework/AzCore/AzCore/Asset/AssetManager.cpp index 8eb620f69e..06bb0b0cac 100644 --- a/Code/Framework/AzCore/AzCore/Asset/AssetManager.cpp +++ b/Code/Framework/AzCore/AzCore/Asset/AssetManager.cpp @@ -551,8 +551,6 @@ namespace AZ { PrepareShutDown(); - DispatchEvents(); - // Acquire the asset lock to make sure nobody else is trying to do anything fancy with assets AZStd::scoped_lock assetLock(m_assetMutex); @@ -575,7 +573,10 @@ namespace AZ { AZ_PROFILE_FUNCTION(AzCore); AssetManagerNotificationBus::Broadcast(&AssetManagerNotificationBus::Events::OnAssetEventsDispatchBegin); - AssetBus::ExecuteQueuedEvents(); + while (AssetBus::QueuedEventCount()) + { + AssetBus::ExecuteQueuedEvents(); + } AssetManagerNotificationBus::Broadcast(&AssetManagerNotificationBus::Events::OnAssetEventsDispatchEnd); } diff --git a/Code/Framework/AzCore/AzCore/AzCoreModule.cpp b/Code/Framework/AzCore/AzCore/AzCoreModule.cpp index c60ea1bd72..ec45335f95 100644 --- a/Code/Framework/AzCore/AzCore/AzCoreModule.cpp +++ b/Code/Framework/AzCore/AzCore/AzCoreModule.cpp @@ -22,6 +22,7 @@ #include #include #include +#include namespace AZ { @@ -41,6 +42,7 @@ namespace AZ TimeSystemComponent::CreateDescriptor(), LoggerSystemComponent::CreateDescriptor(), EventSchedulerSystemComponent::CreateDescriptor(), + TaskGraphSystemComponent::CreateDescriptor(), #if !defined(AZCORE_EXCLUDE_LUA) ScriptSystemComponent::CreateDescriptor(), @@ -55,6 +57,7 @@ namespace AZ azrtti_typeid(), azrtti_typeid(), azrtti_typeid(), + azrtti_typeid(), }; } } diff --git a/Code/Framework/AzCore/AzCore/Debug/Trace.h b/Code/Framework/AzCore/AzCore/Debug/Trace.h index a1334d334e..507ba48e53 100644 --- a/Code/Framework/AzCore/AzCore/Debug/Trace.h +++ b/Code/Framework/AzCore/AzCore/Debug/Trace.h @@ -262,17 +262,17 @@ namespace AZ #else // !AZ_ENABLE_TRACING - #define AZ_Assert(...) AZ_UNUSED(__VA_ARGS__); - #define AZ_Error(...) AZ_UNUSED(__VA_ARGS__); - #define AZ_ErrorOnce(...) AZ_UNUSED(__VA_ARGS__); - #define AZ_Warning(...) AZ_UNUSED(__VA_ARGS__); - #define AZ_WarningOnce(...) AZ_UNUSED(__VA_ARGS__); - #define AZ_TracePrintf(...) AZ_UNUSED(__VA_ARGS__); - #define AZ_TracePrintfOnce(...) AZ_UNUSED(__VA_ARGS__); + #define AZ_Assert(...) + #define AZ_Error(...) + #define AZ_ErrorOnce(...) + #define AZ_Warning(...) + #define AZ_WarningOnce(...) + #define AZ_TracePrintf(...) + #define AZ_TracePrintfOnce(...) - #define AZ_Verify(...) AZ_UNUSED(__VA_ARGS__); - #define AZ_VerifyError(...) AZ_UNUSED(__VA_ARGS__); - #define AZ_VerifyWarning(...) AZ_UNUSED(__VA_ARGS__); + #define AZ_Verify(expression, ...) AZ_UNUSED(expression) + #define AZ_VerifyError(window, expression, ...) AZ_UNUSED(expression) + #define AZ_VerifyWarning(window, expression, ...) AZ_UNUSED(expression) #endif // AZ_ENABLE_TRACING diff --git a/Code/Framework/AzCore/AzCore/IO/Streamer/Scheduler.cpp b/Code/Framework/AzCore/AzCore/IO/Streamer/Scheduler.cpp index 9b4996ad49..9ee0fefc99 100644 --- a/Code/Framework/AzCore/AzCore/IO/Streamer/Scheduler.cpp +++ b/Code/Framework/AzCore/AzCore/IO/Streamer/Scheduler.cpp @@ -43,10 +43,12 @@ namespace AZ::IO m_mainLoopDesc = threadDesc; m_mainLoopDesc.m_name = "IO Scheduler"; - m_mainLoop = AZStd::thread([this]() - { - Thread_MainLoop(); - }, &m_mainLoopDesc); + m_mainLoop = AZStd::thread( + m_mainLoopDesc, + [this]() + { + Thread_MainLoop(); + }); } } diff --git a/Code/Framework/AzCore/AzCore/Jobs/Internal/JobManagerWorkStealing.cpp b/Code/Framework/AzCore/AzCore/Jobs/Internal/JobManagerWorkStealing.cpp index f76946a667..230bf959f6 100644 --- a/Code/Framework/AzCore/AzCore/Jobs/Internal/JobManagerWorkStealing.cpp +++ b/Code/Framework/AzCore/AzCore/Jobs/Internal/JobManagerWorkStealing.cpp @@ -644,11 +644,11 @@ JobManagerWorkStealing::ThreadList JobManagerWorkStealing::CreateWorkerThreads(c } info->m_thread = AZStd::thread( + threadDesc, [this, info]() { this->ProcessJobsWorker(info); - }, - &threadDesc + } ); info->m_threadId = info->m_thread.get_id(); diff --git a/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.cpp b/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.cpp index da7110e36e..113fdd433e 100644 --- a/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.cpp +++ b/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.cpp @@ -717,7 +717,9 @@ namespace AZ::SettingsRegistryMergeUtils if (registry.Get(cacheRootPath, FilePathKey_CacheRootFolder)) { mergePath = AZStd::move(cacheRootPath); - mergePath /= SettingsRegistryInterface::RegistryFolder; + AZStd::fixed_string<32> registryFolderLower(SettingsRegistryInterface::RegistryFolder); + AZStd::to_lower(registryFolderLower.begin(), registryFolderLower.end()); + mergePath /= registryFolderLower; registry.MergeSettingsFolder(mergePath.Native(), specializations, platform, "", scratchBuffer); } diff --git a/Code/Framework/AzCore/AzCore/Task/TaskExecutor.cpp b/Code/Framework/AzCore/AzCore/Task/TaskExecutor.cpp index 2bb88fbfa2..7da04d7301 100644 --- a/Code/Framework/AzCore/AzCore/Task/TaskExecutor.cpp +++ b/Code/Framework/AzCore/AzCore/Task/TaskExecutor.cpp @@ -190,11 +190,13 @@ namespace AZ class TaskWorker { public: - void Spawn(::AZ::TaskExecutor& executor, size_t id, AZStd::semaphore& initSemaphore, bool affinitize) + static thread_local TaskWorker* t_worker; + + void Spawn(::AZ::TaskExecutor& executor, uint32_t id, AZStd::semaphore& initSemaphore, bool affinitize) { m_executor = &executor; - AZStd::string threadName = AZStd::string::format("TaskWorker %zu", id); + AZStd::string threadName = AZStd::string::format("TaskWorker %u", id); AZStd::thread_desc desc = {}; desc.m_name = threadName.c_str(); if (affinitize) @@ -203,12 +205,29 @@ namespace AZ } m_active.store(true, AZStd::memory_order_release); - m_thread = AZStd::thread{ [this, &initSemaphore] + m_thread = AZStd::thread{ desc, + [this, &initSemaphore] { + t_worker = this; initSemaphore.release(); Run(); - }, - &desc }; + } }; + } + + // Threads that wait on a graph to complete are disqualified from receiving tasks until the wait finishes + void Disable() + { + m_enabled = false; + } + + void Enable() + { + m_enabled = true; + } + + bool Enabled() const + { + return m_enabled; } void Join() @@ -222,11 +241,7 @@ namespace AZ { m_queue.Enqueue(task); - if (!m_busy.exchange(true)) - { - // The worker was idle prior to enqueueing the task, release the semaphore - m_semaphore.release(); - } + m_semaphore.release(); } private: @@ -234,7 +249,6 @@ namespace AZ { while (m_active) { - m_busy = false; m_semaphore.acquire(); if (!m_active) @@ -242,8 +256,6 @@ namespace AZ return; } - m_busy = true; - Task* task = m_queue.TryDequeue(); while (task) { @@ -271,12 +283,15 @@ namespace AZ AZStd::thread m_thread; AZStd::atomic m_active; - AZStd::atomic m_busy; + AZStd::atomic m_enabled = true; AZStd::binary_semaphore m_semaphore; ::AZ::TaskExecutor* m_executor; TaskQueue m_queue; + friend class ::AZ::TaskExecutor; }; + + thread_local TaskWorker* TaskWorker::t_worker = nullptr; } // namespace Internal static EnvironmentVariable s_executor; @@ -291,13 +306,16 @@ namespace AZ return **s_executor; } - // TODO: Create the default executor as part of a component (as in TaskManagerComponent) void TaskExecutor::SetInstance(TaskExecutor* executor) { - AZ_Assert(!s_executor, "Attempting to set the global task executor more than once"); - - s_executor = AZ::Environment::CreateVariable("GlobalTaskExecutor"); - s_executor.Set(executor); + if (!executor) + { + s_executor.Reset(); + } + else if (!s_executor) // ignore any calls to set after the first (this happens in unit tests that create new system entities) + { + s_executor = AZ::Environment::CreateVariable(s_executorName, executor); + } } TaskExecutor::TaskExecutor(uint32_t threadCount) @@ -307,14 +325,12 @@ namespace AZ m_workers = reinterpret_cast(azmalloc(m_threadCount * sizeof(Internal::TaskWorker))); - bool affinitize = m_threadCount == AZStd::thread::hardware_concurrency(); - AZStd::semaphore initSemaphore; - for (size_t i = 0; i != m_threadCount; ++i) + for (uint32_t i = 0; i != m_threadCount; ++i) { new (m_workers + i) Internal::TaskWorker{}; - m_workers[i].Spawn(*this, i, initSemaphore, affinitize); + m_workers[i].Spawn(*this, i, initSemaphore, false); } for (size_t i = 0; i != m_threadCount; ++i) @@ -334,9 +350,21 @@ namespace AZ azfree(m_workers); } - void TaskExecutor::Submit(Internal::CompiledTaskGraph& graph) + Internal::TaskWorker* TaskExecutor::GetTaskWorker() + { + if (Internal::TaskWorker::t_worker && Internal::TaskWorker::t_worker->m_executor == this) + { + return Internal::TaskWorker::t_worker; + } + return nullptr; + } + + void TaskExecutor::Submit(Internal::CompiledTaskGraph& graph, TaskGraphEvent* event) { ++m_graphsRemaining; + + event->m_executor = this; // Used to validate event is not waited for inside a job + // Submit all tasks that have no inbound edges for (Internal::Task& task : graph.Tasks()) { @@ -352,11 +380,24 @@ namespace AZ // TODO: Something more sophisticated is likely needed here. // First, we are completely ignoring affinity. // Second, some heuristics on core availability will help distribute work more effectively - m_workers[++m_lastSubmission % m_threadCount].Enqueue(&task); + uint32_t nextWorker = ++m_lastSubmission % m_threadCount; + while (!m_workers[nextWorker].Enabled()) + { + // Graphs that are waiting for the completion of a task graph cannot enqueue tasks onto + // the thread issuing the wait. + nextWorker = ++m_lastSubmission % m_threadCount; + } + + m_workers[nextWorker].Enqueue(&task); } void TaskExecutor::ReleaseGraph() { --m_graphsRemaining; } + + void TaskExecutor::ReactivateTaskWorker() + { + GetTaskWorker()->Enable(); + } } // namespace AZ diff --git a/Code/Framework/AzCore/AzCore/Task/TaskExecutor.h b/Code/Framework/AzCore/AzCore/Task/TaskExecutor.h index dc2fa5a4c8..7e1ff80902 100644 --- a/Code/Framework/AzCore/AzCore/Task/TaskExecutor.h +++ b/Code/Framework/AzCore/AzCore/Task/TaskExecutor.h @@ -72,14 +72,19 @@ namespace AZ explicit TaskExecutor(uint32_t threadCount = 0); ~TaskExecutor(); - void Submit(Internal::CompiledTaskGraph& graph); + // Submit a task graph for execution. Waitable task graphs cannot enqueue work on the task thread + // that is currently active + void Submit(Internal::CompiledTaskGraph& graph, TaskGraphEvent* event); void Submit(Internal::Task& task); private: friend class Internal::TaskWorker; + friend class TaskGraphEvent; + Internal::TaskWorker* GetTaskWorker(); void ReleaseGraph(); + void ReactivateTaskWorker(); Internal::TaskWorker* m_workers; uint32_t m_threadCount = 0; diff --git a/Code/Framework/AzCore/AzCore/Task/TaskGraph.cpp b/Code/Framework/AzCore/AzCore/Task/TaskGraph.cpp index 3fb93903c9..f57b06890a 100644 --- a/Code/Framework/AzCore/AzCore/Task/TaskGraph.cpp +++ b/Code/Framework/AzCore/AzCore/Task/TaskGraph.cpp @@ -14,6 +14,12 @@ namespace AZ { using Internal::CompiledTaskGraph; + void TaskGraphEvent::Wait() + { + AZ_Assert(m_executor->GetTaskWorker() == nullptr, "Waiting in a task is unsupported"); + m_semaphore.acquire(); + } + void TaskToken::PrecedesInternal(TaskToken& comesAfter) { AZ_Assert(!m_parent.m_submitted, "Cannot mutate a TaskGraph that was previously submitted."); @@ -71,7 +77,7 @@ namespace AZ m_compiledTaskGraph->m_tasks[i].Init(); } - executor.Submit(*m_compiledTaskGraph); + executor.Submit(*m_compiledTaskGraph, waitEvent); if (m_retained) { diff --git a/Code/Framework/AzCore/AzCore/Task/TaskGraph.h b/Code/Framework/AzCore/AzCore/Task/TaskGraph.h index 4b454c63de..9553013a4b 100644 --- a/Code/Framework/AzCore/AzCore/Task/TaskGraph.h +++ b/Code/Framework/AzCore/AzCore/Task/TaskGraph.h @@ -22,10 +22,19 @@ namespace AZ namespace Internal { class CompiledTaskGraph; + class TaskWorker; } class TaskExecutor; class TaskGraph; + class TaskGraphActiveInterface + { + public: + AZ_RTTI(TaskGraphActiveInterface, "{08118074-B139-4EF9-B8FD-29F1D6DC9233}"); + + virtual bool IsTaskGraphActive() const = 0; + }; + // A TaskToken is returned each time a Task is added to the TaskGraph. TaskTokens are used to // express dependencies between tasks within the graph, and have no purpose after the graph // is submitted (simply let them go out of scope) @@ -70,9 +79,12 @@ namespace AZ private: friend class ::AZ::Internal::CompiledTaskGraph; friend class TaskGraph; + friend class TaskExecutor; + void Signal(); AZStd::binary_semaphore m_semaphore; + TaskExecutor* m_executor = nullptr; }; // The TaskGraph encapsulates a set of tasks and their interdependencies. After adding @@ -89,6 +101,9 @@ namespace AZ // Reset the state of the task graph to begin recording tasks and edges again // NOTE: Graph must be in a "settled" state (cannot be in-flight) void Reset(); + + // Returns false if 1 or more tasks have been added to the graph + bool IsEmpty(); // Add a task to the graph, retrieiving a token that can be used to express dependencies // between tasks. The first argument specifies the TaskKind, used for tracking the task. diff --git a/Code/Framework/AzCore/AzCore/Task/TaskGraph.inl b/Code/Framework/AzCore/AzCore/Task/TaskGraph.inl index e0ac74ba9d..7b2f0cefdc 100644 --- a/Code/Framework/AzCore/AzCore/Task/TaskGraph.inl +++ b/Code/Framework/AzCore/AzCore/Task/TaskGraph.inl @@ -33,11 +33,6 @@ namespace AZ return m_semaphore.try_acquire_for(AZStd::chrono::milliseconds{ 0 }); } - inline void TaskGraphEvent::Wait() - { - m_semaphore.acquire(); - } - inline void TaskGraphEvent::Signal() { m_semaphore.release(); @@ -59,6 +54,11 @@ namespace AZ return { AddTask(descriptor, AZStd::forward(lambdas))... }; } + inline bool TaskGraph::IsEmpty() + { + return m_tasks.empty(); + } + inline void TaskGraph::Detach() { m_retained = false; diff --git a/Code/Framework/AzCore/AzCore/Task/TaskGraphSystemComponent.cpp b/Code/Framework/AzCore/AzCore/Task/TaskGraphSystemComponent.cpp new file mode 100644 index 0000000000..eed461ecb4 --- /dev/null +++ b/Code/Framework/AzCore/AzCore/Task/TaskGraphSystemComponent.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#include +#include +#include +#include +#include + +// Create a cvar as a central location for experimentation with switching from the Job system to TaskGraph system. +AZ_CVAR(bool, cl_activateTaskGraph, false, nullptr, AZ::ConsoleFunctorFlags::Null, "Flag clients of TaskGraph to switch between jobs/taskgraph (Note does not disable task graph system)"); +static constexpr uint32_t TaskExecutorServiceCrc = AZ_CRC_CE("TaskExecutorService"); + +namespace AZ +{ + void TaskGraphSystemComponent::Activate() + { + AZ_Assert(m_taskExecutor == nullptr, "Error multiple activation of the TaskGraphSystemComponent"); + + if (Interface::Get() == nullptr) + { + Interface::Register(this); + m_taskExecutor = aznew TaskExecutor(); + TaskExecutor::SetInstance(m_taskExecutor); + } + } + + void TaskGraphSystemComponent::Deactivate() + { + if (&TaskExecutor::Instance() == m_taskExecutor) // check that our instance is the global instance (not always true in unit tests) + { + m_taskExecutor->SetInstance(nullptr); + } + if (m_taskExecutor) + { + azdestroy(m_taskExecutor); + m_taskExecutor = nullptr; + } + if (Interface::Get() == this) + { + Interface::Unregister(this); + } + } + + void TaskGraphSystemComponent::GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided) + { + provided.push_back(TaskExecutorServiceCrc); + } + + void TaskGraphSystemComponent::GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible) + { + incompatible.push_back(TaskExecutorServiceCrc); + } + + void TaskGraphSystemComponent::GetDependentServices([[maybe_unused]] ComponentDescriptor::DependencyArrayType& dependent) + { + } + + void TaskGraphSystemComponent::Reflect(ReflectContext* context) + { + if (SerializeContext* serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(1) + ; + + if (AZ::EditContext* ec = serializeContext->GetEditContext()) + { + ec->Class + ("TaskGraph", "System component to create the default executor") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::Category, "Engine") + ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("System")) + ; + } + } + } + + bool TaskGraphSystemComponent::IsTaskGraphActive() const + { + return cl_activateTaskGraph; + } +} // namespace AZ diff --git a/Code/Framework/AzCore/AzCore/Task/TaskGraphSystemComponent.h b/Code/Framework/AzCore/AzCore/Task/TaskGraphSystemComponent.h new file mode 100644 index 0000000000..a4c6da9539 --- /dev/null +++ b/Code/Framework/AzCore/AzCore/Task/TaskGraphSystemComponent.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ +#pragma once + +#include +#include +#include +#include + +namespace AZ +{ + class TaskGraphSystemComponent + : public Component + , public TaskGraphActiveInterface + { + public: + AZ_COMPONENT(AZ::TaskGraphSystemComponent, "{5D56B829-1FEB-43D5-A0BD-E33C0497EFE2}") + + TaskGraphSystemComponent() = default; + + // Implement TaskGraphActiveInterface + bool IsTaskGraphActive() const override; + + private: + ////////////////////////////////////////////////////////////////////////// + // Component base + void Activate() override; + void Deactivate() override; + ////////////////////////////////////////////////////////////////////////// + + /// \ref ComponentDescriptor::GetProvidedServices + static void GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided); + /// \ref ComponentDescriptor::GetIncompatibleServices + static void GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible); + /// \ref ComponentDescriptor::GetDependentServices + static void GetDependentServices(ComponentDescriptor::DependencyArrayType& dependent); + /// \red ComponentDescriptor::Reflect + static void Reflect(ReflectContext* reflection); + + AZ::TaskExecutor* m_taskExecutor = nullptr; + }; +} diff --git a/Code/Framework/AzCore/AzCore/azcore_files.cmake b/Code/Framework/AzCore/AzCore/azcore_files.cmake index aa07959997..14579cbf33 100644 --- a/Code/Framework/AzCore/AzCore/azcore_files.cmake +++ b/Code/Framework/AzCore/AzCore/azcore_files.cmake @@ -633,6 +633,8 @@ set(FILES Task/TaskGraph.cpp Task/TaskGraph.h Task/TaskGraph.inl + Task/TaskGraphSystemComponent.h + Task/TaskGraphSystemComponent.cpp Threading/ThreadSafeDeque.h Threading/ThreadSafeDeque.inl Threading/ThreadSafeObject.h diff --git a/Code/Framework/AzCore/AzCore/std/parallel/thread.h b/Code/Framework/AzCore/AzCore/std/parallel/thread.h index 15d8c9dc8e..eef269c8ac 100644 --- a/Code/Framework/AzCore/AzCore/std/parallel/thread.h +++ b/Code/Framework/AzCore/AzCore/std/parallel/thread.h @@ -87,12 +87,6 @@ namespace AZStd // construct/copy/destroy: thread(); - /** - * \note thread_desc is AZStd extension. - */ - template - explicit thread(F&& f, const thread_desc* desc = 0); - ~thread(); thread(thread&& rhs) @@ -108,6 +102,15 @@ namespace AZStd return *this; } + template, thread_desc>>> + explicit thread(F&& f, Args&&... args); + + /** + * \note thread_desc is AZStd extension. + */ + template + thread(const thread_desc& desc, F&& f, Args&&... args); + // Till we fully have RVALUES template explicit thread(Internal::thread_move_t f); @@ -138,8 +141,8 @@ namespace AZStd //thread(AZStd::delegate d,const thread_desc* desc = 0); private: - thread(thread&); - thread& operator=(thread&); + thread(const thread&) = delete; + thread& operator=(const thread&) = delete; native_thread_data_type m_thread; }; diff --git a/Code/Framework/AzCore/Platform/Common/UnixLike/AzCore/std/parallel/internal/thread_UnixLike.h b/Code/Framework/AzCore/Platform/Common/UnixLike/AzCore/std/parallel/internal/thread_UnixLike.h index 499caebac0..d9a4982a0a 100644 --- a/Code/Framework/AzCore/Platform/Common/UnixLike/AzCore/std/parallel/internal/thread_UnixLike.h +++ b/Code/Framework/AzCore/Platform/Common/UnixLike/AzCore/std/parallel/internal/thread_UnixLike.h @@ -10,6 +10,8 @@ #include #include +#include + namespace AZStd { namespace Internal @@ -22,12 +24,20 @@ namespace AZStd ////////////////////////////////////////////////////////////////////////// // thread - template - inline thread::thread(F&& f, const thread_desc* desc) + template + thread::thread(F&& f, Args&&... args) + : thread(thread_desc{}, AZStd::forward(f), AZStd::forward(args)...) + {} + + template + thread::thread(const thread_desc& desc, F&& f, Args&&... args) { - Internal::thread_info* ti = Internal::create_thread_info(AZStd::forward(f)); - ti->m_name = desc ? desc->m_name : nullptr; - m_thread = Internal::create_thread(desc, ti); + auto threadfunc = [fn = AZStd::forward(f), argsTuple = AZStd::make_tuple(AZStd::forward(args)...)]() mutable -> void + { + AZStd::apply(AZStd::move(fn), AZStd::move(argsTuple)); + }; + Internal::thread_info* ti = Internal::create_thread_info(AZStd::move(threadfunc)); + m_thread = Internal::create_thread(&desc, ti); } inline bool thread::joinable() const diff --git a/Code/Framework/AzCore/Platform/Common/WinAPI/AzCore/std/parallel/internal/thread_WinAPI.h b/Code/Framework/AzCore/Platform/Common/WinAPI/AzCore/std/parallel/internal/thread_WinAPI.h index 46986521e7..c79381a74a 100644 --- a/Code/Framework/AzCore/Platform/Common/WinAPI/AzCore/std/parallel/internal/thread_WinAPI.h +++ b/Code/Framework/AzCore/Platform/Common/WinAPI/AzCore/std/parallel/internal/thread_WinAPI.h @@ -18,6 +18,8 @@ extern "C" AZ_DLL_IMPORT unsigned long __stdcall GetCurrentThreadId(void); } +#include + namespace AZStd { namespace Internal @@ -30,11 +32,20 @@ namespace AZStd ////////////////////////////////////////////////////////////////////////// // thread - template - inline thread::thread(F&& f, const thread_desc* desc) + template + thread::thread(F&& f, Args&&... args) + : thread(thread_desc{}, AZStd::forward(f), AZStd::forward(args)...) + {} + + template + thread::thread(const thread_desc& desc, F&& f, Args&&... args) { - Internal::thread_info* ti = Internal::create_thread_info(AZStd::forward(f)); - m_thread.m_handle = Internal::create_thread(desc, ti, &m_thread.m_id); + auto threadfunc = [fn = AZStd::forward(f), argsTuple = AZStd::make_tuple(AZStd::forward(args)...)]() mutable -> void + { + AZStd::apply(AZStd::move(fn), AZStd::move(argsTuple)); + }; + Internal::thread_info* ti = Internal::create_thread_info(AZStd::move(threadfunc)); + m_thread.m_handle = Internal::create_thread(&desc, ti, &m_thread.m_id); } inline bool thread::joinable() const diff --git a/Code/Framework/AzCore/Tests/AZStd/Parallel.cpp b/Code/Framework/AzCore/Tests/AZStd/Parallel.cpp index f3d4f58250..407cd3c258 100644 --- a/Code/Framework/AzCore/Tests/AZStd/Parallel.cpp +++ b/Code/Framework/AzCore/Tests/AZStd/Parallel.cpp @@ -195,18 +195,18 @@ namespace UnitTest void test_thread_id_for_running_thread_is_not_default_constructed_id() { - const thread_desc* desc = m_numThreadDesc ? &m_desc[0] : nullptr; - AZStd::thread t(AZStd::bind(&Parallel_Thread::do_nothing, this), desc); + const thread_desc desc = m_numThreadDesc ? m_desc[0] : thread_desc{}; + AZStd::thread t(desc, AZStd::bind(&Parallel_Thread::do_nothing, this)); AZ_TEST_ASSERT(t.get_id() != AZStd::thread::id()); t.join(); } void test_different_threads_have_different_ids() { - const thread_desc* desc1 = m_numThreadDesc ? &m_desc[0] : nullptr; - const thread_desc* desc2 = m_numThreadDesc ? &m_desc[1] : nullptr; - AZStd::thread t(AZStd::bind(&Parallel_Thread::do_nothing, this), desc1); - AZStd::thread t2(AZStd::bind(&Parallel_Thread::do_nothing, this), desc2); + const thread_desc desc1 = m_numThreadDesc ? m_desc[0] : thread_desc{}; + const thread_desc desc2 = m_numThreadDesc ? m_desc[1] : thread_desc{}; + AZStd::thread t(desc1, AZStd::bind(&Parallel_Thread::do_nothing, this)); + AZStd::thread t2(desc2, AZStd::bind(&Parallel_Thread::do_nothing, this)); AZ_TEST_ASSERT(t.get_id() != t2.get_id()); t.join(); t2.join(); @@ -214,13 +214,13 @@ namespace UnitTest void test_thread_ids_have_a_total_order() { - const thread_desc* desc1 = m_numThreadDesc ? &m_desc[0] : nullptr; - const thread_desc* desc2 = m_numThreadDesc ? &m_desc[1] : nullptr; - const thread_desc* desc3 = m_numThreadDesc ? &m_desc[2] : nullptr; + const thread_desc desc1 = m_numThreadDesc ? m_desc[0] : thread_desc{}; + const thread_desc desc2 = m_numThreadDesc ? m_desc[1] : thread_desc{}; + const thread_desc desc3 = m_numThreadDesc ? m_desc[2] : thread_desc{}; - AZStd::thread t(AZStd::bind(&Parallel_Thread::do_nothing, this), desc1); - AZStd::thread t2(AZStd::bind(&Parallel_Thread::do_nothing, this), desc2); - AZStd::thread t3(AZStd::bind(&Parallel_Thread::do_nothing, this), desc3); + AZStd::thread t(desc1, AZStd::bind(&Parallel_Thread::do_nothing, this)); + AZStd::thread t2(desc2, AZStd::bind(&Parallel_Thread::do_nothing, this)); + AZStd::thread t3(desc3, AZStd::bind(&Parallel_Thread::do_nothing, this)); AZ_TEST_ASSERT(t.get_id() != t2.get_id()); AZ_TEST_ASSERT(t.get_id() != t3.get_id()); AZ_TEST_ASSERT(t2.get_id() != t3.get_id()); @@ -313,10 +313,10 @@ namespace UnitTest void test_thread_id_of_running_thread_returned_by_this_thread_get_id() { - const thread_desc* desc1 = m_numThreadDesc ? &m_desc[0] : nullptr; + const thread_desc desc1 = m_numThreadDesc ? m_desc[0] : thread_desc{}; AZStd::thread::id id; - AZStd::thread t(AZStd::bind(&Parallel_Thread::get_thread_id, this, &id), desc1); + AZStd::thread t(desc1, AZStd::bind(&Parallel_Thread::get_thread_id, this, &id)); AZStd::thread::id t_id = t.get_id(); t.join(); AZ_TEST_ASSERT(id == t_id); @@ -366,10 +366,10 @@ namespace UnitTest void test_move_on_construction() { - const thread_desc* desc1 = m_numThreadDesc ? &m_desc[0] : nullptr; + const thread_desc desc1 = m_numThreadDesc ? m_desc[0] : thread_desc{}; AZStd::thread::id the_id; AZStd::thread x; - x = AZStd::thread(AZStd::bind(&Parallel_Thread::do_nothing_id, this, &the_id), desc1); + x = AZStd::thread(desc1, AZStd::bind(&Parallel_Thread::do_nothing_id, this, &the_id)); AZStd::thread::id x_id = x.get_id(); x.join(); AZ_TEST_ASSERT(the_id == x_id); @@ -377,8 +377,8 @@ namespace UnitTest AZStd::thread make_thread(AZStd::thread::id* the_id) { - const thread_desc* desc1 = m_numThreadDesc ? &m_desc[0] : nullptr; - return AZStd::thread(AZStd::bind(&Parallel_Thread::do_nothing_id, this, the_id), desc1); + const thread_desc desc1 = m_numThreadDesc ? m_desc[0] : thread_desc{}; + return AZStd::thread(desc1, AZStd::bind(&Parallel_Thread::do_nothing_id, this, the_id)); } void test_move_from_function_return() @@ -430,9 +430,9 @@ namespace UnitTest void do_test_creation() { - const thread_desc* desc1 = m_numThreadDesc ? &m_desc[0] : nullptr; + const thread_desc desc1 = m_numThreadDesc ? m_desc[0] : thread_desc{}; m_data = 0; - AZStd::thread t(AZStd::bind(&Parallel_Thread::simple_thread, this), desc1); + AZStd::thread t(desc1, AZStd::bind(&Parallel_Thread::simple_thread, this)); t.join(); AZ_TEST_ASSERT(m_data == 999); } @@ -445,9 +445,9 @@ namespace UnitTest void do_test_id_comparison() { - const thread_desc* desc1 = m_numThreadDesc ? &m_desc[0] : nullptr; + const thread_desc desc1 = m_numThreadDesc ? m_desc[0] : thread_desc{}; AZStd::thread::id self = this_thread::get_id(); - AZStd::thread thrd(AZStd::bind(&Parallel_Thread::comparison_thread, this, self), desc1); + AZStd::thread thrd(desc1, AZStd::bind(&Parallel_Thread::comparison_thread, this, self)); thrd.join(); } @@ -476,10 +476,10 @@ namespace UnitTest void do_test_creation_through_reference_wrapper() { - const thread_desc* desc1 = m_numThreadDesc ? &m_desc[0] : nullptr; + const thread_desc desc1 = m_numThreadDesc ? m_desc[0] : thread_desc{}; non_copyable_functor f; - AZStd::thread thrd(AZStd::ref(f), desc1); + AZStd::thread thrd(desc1, AZStd::ref(f)); thrd.join(); AZ_TEST_ASSERT(f.value == 999); } @@ -491,10 +491,10 @@ namespace UnitTest void test_swap() { - const thread_desc* desc1 = m_numThreadDesc ? &m_desc[0] : nullptr; - const thread_desc* desc2 = m_numThreadDesc ? &m_desc[1] : nullptr; - AZStd::thread t(AZStd::bind(&Parallel_Thread::simple_thread, this), desc1); - AZStd::thread t2(AZStd::bind(&Parallel_Thread::simple_thread, this), desc2); + const thread_desc desc1 = m_numThreadDesc ? m_desc[0] : thread_desc{}; + const thread_desc desc2 = m_numThreadDesc ? m_desc[1] : thread_desc{}; + AZStd::thread t(desc1, AZStd::bind(&Parallel_Thread::simple_thread, this)); + AZStd::thread t2(desc2, AZStd::bind(&Parallel_Thread::simple_thread, this)); AZStd::thread::id id1 = t.get_id(); AZStd::thread::id id2 = t2.get_id(); @@ -512,7 +512,7 @@ namespace UnitTest void run() { - const thread_desc* desc1 = m_numThreadDesc ? &m_desc[0] : nullptr; + const thread_desc desc1 = m_numThreadDesc ? m_desc[0] : thread_desc{}; // We need to have at least one processor AZ_TEST_ASSERT(AZStd::thread::hardware_concurrency() >= 1); @@ -520,18 +520,18 @@ namespace UnitTest // Create thread to increment data till we need to m_data = 0; m_dataMax = 10; - AZStd::thread tr(AZStd::bind(&Parallel_Thread::increment_data, this), desc1); + AZStd::thread tr(desc1, AZStd::bind(&Parallel_Thread::increment_data, this)); tr.join(); AZ_TEST_ASSERT(m_data == m_dataMax); m_data = 0; - AZStd::thread trDel(make_delegate(this, &Parallel_Thread::increment_data), desc1); + AZStd::thread trDel(desc1, make_delegate(this, &Parallel_Thread::increment_data)); trDel.join(); AZ_TEST_ASSERT(m_data == m_dataMax); chrono::system_clock::time_point startTime = chrono::system_clock::now(); { - AZStd::thread tr1(AZStd::bind(&Parallel_Thread::sleep_thread, this, chrono::milliseconds(100)), desc1); + AZStd::thread tr1(desc1, AZStd::bind(&Parallel_Thread::sleep_thread, this, chrono::milliseconds(100))); tr1.join(); } auto sleepTime = chrono::system_clock::now() - startTime; @@ -563,71 +563,71 @@ namespace UnitTest { MfTest x; AZStd::function func = AZStd::bind(&MfTest::f0, &x); - AZStd::thread(func, desc1).join(); + AZStd::thread(desc1, func).join(); func = AZStd::bind(&MfTest::f0, AZStd::ref(x)); - AZStd::thread(func, desc1).join(); + AZStd::thread(desc1, func).join(); func = AZStd::bind(&MfTest::g0, &x); - AZStd::thread(func, desc1).join(); + AZStd::thread(desc1, func).join(); func = AZStd::bind(&MfTest::g0, x); - AZStd::thread(func, desc1).join(); + AZStd::thread(desc1, func).join(); func = AZStd::bind(&MfTest::g0, AZStd::ref(x)); - AZStd::thread(func, desc1).join(); + AZStd::thread(desc1, func).join(); //// 1 - //thread( AZStd::bind(&MfTest::f1, &x, 1) , desc1).join(); - //thread( AZStd::bind(&MfTest::f1, AZStd::ref(x), 1) , desc1).join(); - //thread( AZStd::bind(&MfTest::g1, &x, 1) , desc1).join(); - //thread( AZStd::bind(&MfTest::g1, x, 1) , desc1).join(); - //thread( AZStd::bind(&MfTest::g1, AZStd::ref(x), 1) , desc1).join(); + //thread( AZStd::bind(desc1, &MfTest::f1, &x, 1)).join(); + //thread( AZStd::bind(desc1, &MfTest::f1, AZStd::ref(x), 1)).join(); + //thread( AZStd::bind(desc1, &MfTest::g1, &x, 1)).join(); + //thread( AZStd::bind(desc1, &MfTest::g1, x, 1)).join(); + //thread( AZStd::bind(desc1, &MfTest::g1, AZStd::ref(x), 1)).join(); //// 2 - //thread( AZStd::bind(&MfTest::f2, &x, 1, 2) , desc1).join(); - //thread( AZStd::bind(&MfTest::f2, AZStd::ref(x), 1, 2) , desc1).join(); - //thread( AZStd::bind(&MfTest::g2, &x, 1, 2) , desc1).join(); - //thread( AZStd::bind(&MfTest::g2, x, 1, 2) , desc1).join(); - //thread( AZStd::bind(&MfTest::g2, AZStd::ref(x), 1, 2) , desc1).join(); + //thread( AZStd::bind(desc1, &MfTest::f2, &x, 1, 2)).join(); + //thread( AZStd::bind(desc1, &MfTest::f2, AZStd::ref(x), 1, 2)).join(); + //thread( AZStd::bind(desc1, &MfTest::g2, &x, 1, 2)).join(); + //thread( AZStd::bind(desc1, &MfTest::g2, x, 1, 2)).join(); + //thread( AZStd::bind(desc1, &MfTest::g2, AZStd::ref(x), 1, 2)).join(); //// 3 - //thread( AZStd::bind(&MfTest::f3, &x, 1, 2, 3) , desc1).join(); - //thread( AZStd::bind(&MfTest::f3, AZStd::ref(x), 1, 2, 3) , desc1).join(); - //thread( AZStd::bind(&MfTest::g3, &x, 1, 2, 3) , desc1).join(); - //thread( AZStd::bind(&MfTest::g3, x, 1, 2, 3) , desc1).join(); - //thread( AZStd::bind(&MfTest::g3, AZStd::ref(x), 1, 2, 3) , desc1).join(); + //thread( AZStd::bind(desc1, &MfTest::f3, &x, 1, 2, 3)).join(); + //thread( AZStd::bind(desc1, &MfTest::f3, AZStd::ref(x), 1, 2, 3)).join(); + //thread( AZStd::bind(desc1, &MfTest::g3, &x, 1, 2, 3)).join(); + //thread( AZStd::bind(desc1, &MfTest::g3, x, 1, 2, 3)).join(); + //thread( AZStd::bind(desc1, &MfTest::g3, AZStd::ref(x), 1, 2, 3)).join(); //// 4 - //thread( AZStd::bind(&MfTest::f4, &x, 1, 2, 3, 4) , desc1).join(); - //thread( AZStd::bind(&MfTest::f4, AZStd::ref(x), 1, 2, 3, 4) , desc1).join(); - //thread( AZStd::bind(&MfTest::g4, &x, 1, 2, 3, 4) , desc1).join(); - //thread( AZStd::bind(&MfTest::g4, x, 1, 2, 3, 4) , desc1).join(); - //thread( AZStd::bind(&MfTest::g4, AZStd::ref(x), 1, 2, 3, 4) , desc1).join(); + //thread( AZStd::bind(desc1, &MfTest::f4, &x, 1, 2, 3, 4)).join(); + //thread( AZStd::bind(desc1, &MfTest::f4, AZStd::ref(x), 1, 2, 3, 4)).join(); + //thread( AZStd::bind(desc1, &MfTest::g4, &x, 1, 2, 3, 4)).join(); + //thread( AZStd::bind(desc1, &MfTest::g4, x, 1, 2, 3, 4)).join(); + //thread( AZStd::bind(desc1, &MfTest::g4, AZStd::ref(x), 1, 2, 3, 4)).join(); //// 5 - //thread( AZStd::bind(&MfTest::f5, &x, 1, 2, 3, 4, 5) , desc1).join(); - //thread( AZStd::bind(&MfTest::f5, AZStd::ref(x), 1, 2, 3, 4, 5) , desc1).join(); - //thread( AZStd::bind(&MfTest::g5, &x, 1, 2, 3, 4, 5) , desc1).join(); - //thread( AZStd::bind(&MfTest::g5, x, 1, 2, 3, 4, 5) , desc1).join(); - //thread( AZStd::bind(&MfTest::g5, AZStd::ref(x), 1, 2, 3, 4, 5) , desc1).join(); + //thread( AZStd::bind(desc1, &MfTest::f5, &x, 1, 2, 3, 4, 5)).join(); + //thread( AZStd::bind(desc1, &MfTest::f5, AZStd::ref(x), 1, 2, 3, 4, 5)).join(); + //thread( AZStd::bind(desc1, &MfTest::g5, &x, 1, 2, 3, 4, 5)).join(); + //thread( AZStd::bind(desc1, &MfTest::g5, x, 1, 2, 3, 4, 5)).join(); + //thread( AZStd::bind(desc1, &MfTest::g5, AZStd::ref(x), 1, 2, 3, 4, 5)).join(); //// 6 - //thread( AZStd::bind(&MfTest::f6, &x, 1, 2, 3, 4, 5, 6) , desc1).join(); - //thread( AZStd::bind(&MfTest::f6, AZStd::ref(x), 1, 2, 3, 4, 5, 6) , desc1).join(); - //thread( AZStd::bind(&MfTest::g6, &x, 1, 2, 3, 4, 5, 6) , desc1).join(); - //thread( AZStd::bind(&MfTest::g6, x, 1, 2, 3, 4, 5, 6) , desc1).join(); - //thread( AZStd::bind(&MfTest::g6, AZStd::ref(x), 1, 2, 3, 4, 5, 6) , desc1).join(); + //thread( AZStd::bind(desc1, &MfTest::f6, &x, 1, 2, 3, 4, 5, 6)).join(); + //thread( AZStd::bind(desc1, &MfTest::f6, AZStd::ref(x), 1, 2, 3, 4, 5, 6)).join(); + //thread( AZStd::bind(desc1, &MfTest::g6, &x, 1, 2, 3, 4, 5, 6)).join(); + //thread( AZStd::bind(desc1, &MfTest::g6, x, 1, 2, 3, 4, 5, 6)).join(); + //thread( AZStd::bind(desc1, &MfTest::g6, AZStd::ref(x), 1, 2, 3, 4, 5, 6)).join(); //// 7 - //thread( AZStd::bind(&MfTest::f7, &x, 1, 2, 3, 4, 5, 6, 7), desc1).join(); - //thread( AZStd::bind(&MfTest::f7, AZStd::ref(x), 1, 2, 3, 4, 5, 6, 7), desc1).join(); - //thread( AZStd::bind(&MfTest::g7, &x, 1, 2, 3, 4, 5, 6, 7), desc1).join(); - //thread( AZStd::bind(&MfTest::g7, x, 1, 2, 3, 4, 5, 6, 7), desc1).join(); - //thread( AZStd::bind(&MfTest::g7, AZStd::ref(x), 1, 2, 3, 4, 5, 6, 7), desc1).join(); + //thread( AZStd::bind(desc1, &MfTest::f7, &x, 1, 2, 3, 4, 5, 6, 7)).join(); + //thread( AZStd::bind(desc1, &MfTest::f7, AZStd::ref(x), 1, 2, 3, 4, 5, 6, 7)).join(); + //thread( AZStd::bind(desc1, &MfTest::g7, &x, 1, 2, 3, 4, 5, 6, 7)).join(); + //thread( AZStd::bind(desc1, &MfTest::g7, x, 1, 2, 3, 4, 5, 6, 7)).join(); + //thread( AZStd::bind(desc1, &MfTest::g7, AZStd::ref(x), 1, 2, 3, 4, 5, 6, 7)).join(); //// 8 - //thread( AZStd::bind(&MfTest::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8) , desc1).join(); - //thread( AZStd::bind(&MfTest::f8, AZStd::ref(x), 1, 2, 3, 4, 5, 6, 7, 8) , desc1).join(); - //thread( AZStd::bind(&MfTest::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8) , desc1).join(); - //thread( AZStd::bind(&MfTest::g8, x, 1, 2, 3, 4, 5, 6, 7, 8) , desc1).join(); - //thread( AZStd::bind(&MfTest::g8, AZStd::ref(x), 1, 2, 3, 4, 5, 6, 7, 8) , desc1).join(); + //thread( AZStd::bind(desc1, &MfTest::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)).join(); + //thread( AZStd::bind(desc1, &MfTest::f8, AZStd::ref(x), 1, 2, 3, 4, 5, 6, 7, 8)).join(); + //thread( AZStd::bind(desc1, &MfTest::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)).join(); + //thread( AZStd::bind(desc1, &MfTest::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)).join(); + //thread( AZStd::bind(desc1, &MfTest::g8, AZStd::ref(x), 1, 2, 3, 4, 5, 6, 7, 8)).join(); AZ_TEST_ASSERT(x.m_hash == 1366); } diff --git a/Code/Framework/AzCore/Tests/Memory.cpp b/Code/Framework/AzCore/Tests/Memory.cpp index eb854050b6..5a483c1ed1 100644 --- a/Code/Framework/AzCore/Tests/Memory.cpp +++ b/Code/Framework/AzCore/Tests/Memory.cpp @@ -151,7 +151,7 @@ namespace UnitTest AZStd::thread m_threads[m_maxNumThreads]; for (unsigned int i = 0; i < m_maxNumThreads; ++i) { - m_threads[i] = AZStd::thread(AZStd::bind(&SystemAllocatorTest::ThreadFunc, this), &m_desc[i]); + m_threads[i] = AZStd::thread(m_desc[i], AZStd::bind(&SystemAllocatorTest::ThreadFunc, this)); // give some time offset to the threads so we can test alloc and dealloc at the same time. //AZStd::this_thread::sleep_for(AZStd::chrono::microseconds(500)); } @@ -286,7 +286,7 @@ namespace UnitTest AZStd::thread m_threads[m_maxNumThreads]; for (unsigned int i = 0; i < m_maxNumThreads; ++i) { - m_threads[i] = AZStd::thread(AZStd::bind(&SystemAllocatorTest::ThreadFunc, this), &m_desc[i]); + m_threads[i] = AZStd::thread(m_desc[i], AZStd::bind(&SystemAllocatorTest::ThreadFunc, this)); // give some time offset to the threads so we can test alloc and dealloc at the same time. AZStd::this_thread::sleep_for(AZStd::chrono::microseconds(500)); } @@ -724,7 +724,7 @@ namespace UnitTest AZStd::thread m_threads[m_maxNumThreads]; for (unsigned int i = 0; i < m_maxNumThreads; ++i) { - m_threads[i] = AZStd::thread(AZStd::bind(&ThreadPoolAllocatorTest::AllocDeallocFunc, this), &m_desc[i]); + m_threads[i] = AZStd::thread(m_desc[i], AZStd::bind(&ThreadPoolAllocatorTest::AllocDeallocFunc, this)); } for (unsigned int i = 0; i < m_maxNumThreads; ++i) @@ -743,12 +743,12 @@ namespace UnitTest for (unsigned int i = m_maxNumThreads/2; i ::Create(); AZ::AllocatorInstance::Create(); - m_executor = aznew TaskExecutor(4); + m_executor = aznew TaskExecutor(); } void TearDown() override @@ -236,6 +236,82 @@ namespace UnitTest EXPECT_EQ(x, 1); } + TEST_F(TaskGraphTestFixture, SingleTask) + { + AZStd::atomic_int32_t x = 0; + + TaskGraph graph; + graph.AddTask( + defaultTD, + [&x] + { + x = 1; + }); + + TaskGraphEvent ev; + graph.SubmitOnExecutor(*m_executor, &ev); + ev.Wait(); + + EXPECT_EQ(1, x); + } + + + TEST_F(TaskGraphTestFixture, SingleTaskChain) + { + AZStd::atomic_int32_t x = 0; + + TaskGraph graph; + auto a = graph.AddTask( + defaultTD, + [&x] + { + x += 1; + }); + auto b = graph.AddTask( + defaultTD, + [&x] + { + x += 1; + }); + b.Precedes(a); + + TaskGraphEvent ev; + graph.SubmitOnExecutor(*m_executor, &ev); + ev.Wait(); + + EXPECT_EQ(2, x); + } + + TEST_F(TaskGraphTestFixture, MultipleIndependentTaskChains) + { + AZStd::atomic_int32_t x = 0; + constexpr int numChains = 5; + + TaskGraph graph; + for( int i = 0; i < numChains; ++i) + { + auto a = graph.AddTask( + defaultTD, + [&x] + { + x += 1; + }); + auto b = graph.AddTask( + defaultTD, + [&x] + { + x += 1; + }); + b.Precedes(a); + } + + TaskGraphEvent ev; + graph.SubmitOnExecutor(*m_executor, &ev); + ev.Wait(); + + EXPECT_EQ(2*numChains, x); + } + TEST_F(TaskGraphTestFixture, VariadicInterface) { int x = 0; @@ -388,6 +464,7 @@ namespace UnitTest EXPECT_EQ(3, x); } + // Waiting inside a task is disallowed , test that it fails correctly TEST_F(TaskGraphTestFixture, SpawnSubgraph) { AZStd::atomic x = 0; @@ -434,7 +511,10 @@ namespace UnitTest f.Precedes(g); TaskGraphEvent ev; subgraph.SubmitOnExecutor(*m_executor, &ev); + // TaskGraphEvent::Wait asserts if called on a worker thread, suppress & validate assert + AZ_TEST_START_TRACE_SUPPRESSION; ev.Wait(); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); }); auto d = graph.AddTask( defaultTD, @@ -464,8 +544,6 @@ namespace UnitTest TaskGraphEvent ev; graph.SubmitOnExecutor(*m_executor, &ev); ev.Wait(); - - EXPECT_EQ(3 | 0b100000, x); } TEST_F(TaskGraphTestFixture, RetainedGraph) diff --git a/Code/Framework/AzFramework/AzFramework/Application/Application.cpp b/Code/Framework/AzFramework/AzFramework/Application/Application.cpp index 12974d03cf..e72e2de472 100644 --- a/Code/Framework/AzFramework/AzFramework/Application/Application.cpp +++ b/Code/Framework/AzFramework/AzFramework/Application/Application.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -295,6 +296,7 @@ namespace AzFramework azrtti_typeid(), azrtti_typeid(), azrtti_typeid(), + azrtti_typeid(), azrtti_typeid(), azrtti_typeid(), @@ -477,14 +479,16 @@ namespace AzFramework newThreadDesc.m_cpuId = AFFINITY_MASK_USERTHREADS; newThreadDesc.m_name = newThreadName; AZStd::binary_semaphore binarySemaphore; - AZStd::thread newThread([&workForNewThread, &binarySemaphore, &newThreadName] - { - AZ_PROFILE_SCOPE(AzFramework, - "Application::PumpSystemEventLoopWhileDoingWorkInNewThread:ThreadWorker %s", newThreadName); + AZStd::thread newThread( + newThreadDesc, + [&workForNewThread, &binarySemaphore, &newThreadName] + { + AZ_PROFILE_SCOPE(AzFramework, + "Application::PumpSystemEventLoopWhileDoingWorkInNewThread:ThreadWorker %s", newThreadName); - workForNewThread(); - binarySemaphore.release(); - }, &newThreadDesc); + workForNewThread(); + binarySemaphore.release(); + }); while (!binarySemaphore.try_acquire_for(eventPumpFrequency)) { PumpSystemEventLoopUntilEmpty(); diff --git a/Code/Framework/AzFramework/AzFramework/Archive/Archive.cpp b/Code/Framework/AzFramework/AzFramework/Archive/Archive.cpp index d2a81102dc..8064ba6669 100644 --- a/Code/Framework/AzFramework/AzFramework/Archive/Archive.cpp +++ b/Code/Framework/AzFramework/AzFramework/Archive/Archive.cpp @@ -1631,7 +1631,20 @@ namespace AZ::IO return nullptr; } - ZipDir::CacheFactory factory(ZipDir::ZD_INIT_FAST, nFactoryFlags); + ZipDir::InitMethod initType = ZipDir::InitMethod::Default; + if (!ZipDir::IsReleaseConfig) + { + if ((nFlags & INestedArchive::FLAGS_FULL_VALIDATE) != 0) + { + initType = ZipDir::InitMethod::FullValidation; + } + else if ((nFlags & INestedArchive::FLAGS_VALIDATE_HEADERS) != 0) + { + initType = ZipDir::InitMethod::ValidateHeaders; + } + } + + ZipDir::CacheFactory factory(initType, nFactoryFlags); ZipDir::CachePtr cache = factory.New(szFullPath->c_str()); if (cache) diff --git a/Code/Framework/AzFramework/AzFramework/Archive/INestedArchive.h b/Code/Framework/AzFramework/AzFramework/Archive/INestedArchive.h index f85fd273ce..e89d16ee5d 100644 --- a/Code/Framework/AzFramework/AzFramework/Archive/INestedArchive.h +++ b/Code/Framework/AzFramework/AzFramework/Archive/INestedArchive.h @@ -11,7 +11,9 @@ #include #include +#include #include +#include #include namespace AZ::IO @@ -71,6 +73,13 @@ namespace AZ::IO // multiple times FLAGS_DONT_COMPACT = 1 << 5, + // if this is set, validate header data when opening the archive + FLAGS_VALIDATE_HEADERS = 1 << 9, + + // if this is set, validate header data when opening the archive and validate CRCs when decompressing + // & reading files. + FLAGS_FULL_VALIDATE = 1 << 10, + // Disable a pak file without unloading it, this flag is used in combination with patches and multiplayer // to ensure that specific paks stay in the position(to keep the same priority) but being disabled // when running multiplayer @@ -128,6 +137,10 @@ namespace AZ::IO // Deletes all files and directories in the archive. virtual int RemoveAll() = 0; + // Summary: + // Lists all the files in the archive. + virtual int ListAllFiles(AZStd::vector& outFileEntries) = 0; + // Summary: // Finds the file; you don't have to close the returned handle. // Returns: diff --git a/Code/Framework/AzFramework/AzFramework/Archive/NestedArchive.cpp b/Code/Framework/AzFramework/AzFramework/Archive/NestedArchive.cpp index 1e0f237df5..49a44b76fa 100644 --- a/Code/Framework/AzFramework/AzFramework/Archive/NestedArchive.cpp +++ b/Code/Framework/AzFramework/AzFramework/Archive/NestedArchive.cpp @@ -89,11 +89,51 @@ namespace AZ::IO return m_pCache->RemoveDir(fullPath); } + ////////////////////////////////////////////////////////////////////////// int NestedArchive::RemoveAll() { return m_pCache->RemoveAll(); } + ////////////////////////////////////////////////////////////////////////// + // Helper for 'ListAllFiles' to recursively traverse the FileEntryTree and gather all the files + void EnumerateFilesRecursive(AZ::IO::Path currentPath, ZipDir::FileEntryTree* currentTree, AZStd::vector& fileList) + { + // Drill down directories first... + for (auto dirIter = currentTree->GetDirBegin(); dirIter != currentTree->GetDirEnd(); ++dirIter) + { + if (ZipDir::FileEntryTree* subTree = currentTree->GetDirEntry(dirIter); + subTree != nullptr) + { + EnumerateFilesRecursive(currentPath / currentTree->GetDirName(dirIter), subTree, fileList); + } + } + + // Then enumerate the files in current directory... + for (auto fileIter = currentTree->GetFileBegin(); fileIter != currentTree->GetFileEnd(); ++fileIter) + { + fileList.emplace_back(currentPath / currentTree->GetFileName(fileIter)); + } + } + + ////////////////////////////////////////////////////////////////////////// + // lists all files in the archive + int NestedArchive::ListAllFiles(AZStd::vector& outFileEntries) + { + AZStd::vector filesInArchive; + + ZipDir::FileEntryTree* tree = m_pCache->GetRoot(); + if (!tree) + { + return ZipDir::ZD_ERROR_UNEXPECTED; + } + + EnumerateFilesRecursive(AZ::IO::Path{ AZ::IO::PosixPathSeparator }, tree, filesInArchive); + + AZStd::swap(outFileEntries, filesInArchive); + return ZipDir::ZD_ERROR_SUCCESS; + } + ////////////////////////////////////////////////////////////////////////// // Adds a new file to the zip or update an existing one // adds a directory (creates several nested directories if needed) diff --git a/Code/Framework/AzFramework/AzFramework/Archive/NestedArchive.h b/Code/Framework/AzFramework/AzFramework/Archive/NestedArchive.h index 34bbcdc201..59722703f2 100644 --- a/Code/Framework/AzFramework/AzFramework/Archive/NestedArchive.h +++ b/Code/Framework/AzFramework/AzFramework/Archive/NestedArchive.h @@ -39,7 +39,7 @@ namespace AZ::IO NestedArchive(IArchive* pArchive, AZStd::string_view strBindRoot, ZipDir::CachePtr pCache, uint32_t nFlags = 0); ~NestedArchive() override; - + auto GetRootFolderHandle() -> Handle override; // Adds a new file to the zip or update an existing one @@ -68,6 +68,9 @@ namespace AZ::IO // deletes all files from the archive int RemoveAll() override; + // lists all the files in the archive + int ListAllFiles(AZStd::vector& outFileEntries) override; + // finds the file; you don't have to close the returned handle Handle FindFile(AZStd::string_view szRelativePath) override; @@ -79,7 +82,6 @@ namespace AZ::IO // returns the full path to the archive file AZ::IO::PathView GetFullPath() const override; - ZipDir::Cache* GetCache(); uint32_t GetFlags() const override; bool SetFlags(uint32_t nFlagsToSet) override; @@ -87,12 +89,15 @@ namespace AZ::IO bool SetPackAccessible(bool bAccessible) override; + ZipDir::Cache* GetCache(); + protected: // returns the pointer to the relative file path to be passed // to the underlying Cache pointer. Uses the given buffer to construct the path. // returns nullptr if the file path is invalid AZ::IO::FixedMaxPathString AdjustPath(AZStd::string_view szRelativePath); + ZipDir::CachePtr m_pCache; // the binding root may be empty string - in this case, the absolute path binding won't work AZ::IO::Path m_strBindRoot; diff --git a/Code/Framework/AzFramework/AzFramework/Archive/ZipDirCache.cpp b/Code/Framework/AzFramework/AzFramework/Archive/ZipDirCache.cpp index d17dbd0837..13d5b0f723 100644 --- a/Code/Framework/AzFramework/AzFramework/Archive/ZipDirCache.cpp +++ b/Code/Framework/AzFramework/AzFramework/Archive/ZipDirCache.cpp @@ -101,10 +101,11 @@ namespace AZ::IO::ZipDir FileEntry* operator -> () { return m_pFileEntry; } FileEntryTransactionAdd(Cache* pCache, AZStd::string_view szRelativePath) : m_pCache(pCache) + , m_szRelativePath(AZ::IO::PosixPathSeparator) , m_bCommitted(false) { // Update the cache string pool with the relative path to the file - auto pathIt = m_pCache->m_relativePathPool.emplace(AZ::IO::PathView(szRelativePath).LexicallyNormal()); + auto pathIt = m_pCache->m_relativePathPool.emplace(AZ::IO::PathView(szRelativePath, AZ::IO::PosixPathSeparator).LexicallyNormal()); m_szRelativePath = *pathIt.first; // this is the name of the directory - create it or find it m_pFileEntry = m_pCache->GetRoot()->Add(m_szRelativePath.Native()); @@ -740,6 +741,16 @@ namespace AZ::IO::ZipDir { return ZD_ERROR_CORRUPTED_DATA; } + if (pFileEntry->bCheckCRCNextRead) + { + pFileEntry->bCheckCRCNextRead = false; + uLong uCRC32 = AZ::Crc32((Bytef*)pUncompressed, nSizeUncompressed); + if (uCRC32 != pFileEntry->desc.lCRC32) + { + AZ_Warning("Archive", false, "ZD_ERROR_CRC32_CHECK: Uncompressed stream CRC32 check failed"); + return ZD_ERROR_CRC32_CHECK; + } + } } } diff --git a/Code/Framework/AzFramework/AzFramework/Archive/ZipDirCacheFactory.cpp b/Code/Framework/AzFramework/AzFramework/Archive/ZipDirCacheFactory.cpp index 5c5e93d441..d5bd4d2840 100644 --- a/Code/Framework/AzFramework/AzFramework/Archive/ZipDirCacheFactory.cpp +++ b/Code/Framework/AzFramework/AzFramework/Archive/ZipDirCacheFactory.cpp @@ -29,7 +29,7 @@ namespace AZ::IO::ZipDir // this sets the window size of the blocks of data read from the end of the file to find the Central Directory Record // since normally there are no static constexpr size_t CDRSearchWindowSize = 0x100; - CacheFactory::CacheFactory(InitMethodEnum nInitMethod, uint32_t nFlags) + CacheFactory::CacheFactory(InitMethod nInitMethod, uint32_t nFlags) { m_nCDREndPos = 0; m_bBuildFileEntryMap = false; // we only need it for validation/debugging @@ -448,7 +448,6 @@ namespace AZ::IO::ZipDir // builds up the m_mapFileEntries bool CacheFactory::BuildFileEntryMap() { - Seek(m_CDREnd.lCDROffset); if (m_CDREnd.lCDRSize == 0) @@ -530,14 +529,6 @@ namespace AZ::IO::ZipDir { // Add this file entry. char* str = reinterpret_cast(pFileName); - for (int i = 0; i < pFile->nFileNameLength; i++) - { - str[i] = std::tolower(str[i], std::locale()); - if (str[i] == AZ_WRONG_FILESYSTEM_SEPARATOR) - { - str[i] = AZ_CORRECT_FILESYSTEM_SEPARATOR; - } - } str[pFile->nFileNameLength] = 0; // Not standard!, may overwrite signature of the next memory record data in zip. AddFileEntry(str, pFile, extra); } @@ -574,11 +565,7 @@ namespace AZ::IO::ZipDir FileEntryBase fileEntry(*pFileHeader, extra); - // when using encrypted headers we should always initialize data offsets from CDR - if ((m_encryptedHeaders != ZipFile::HEADERS_NOT_ENCRYPTED || m_nInitMethod >= ZD_INIT_FULL) && pFileHeader->desc.lSizeCompressed) - { - InitDataOffset(fileEntry, pFileHeader); - } + InitDataOffset(fileEntry, pFileHeader); if (m_bBuildFileEntryMap) { @@ -606,142 +593,81 @@ namespace AZ::IO::ZipDir { Seek(pFileHeader->lLocalHeaderOffset); - // read the local file header and the name (for validation) into the buffer - AZStd::vectorpBuffer; - uint32_t nBufferLength = sizeof(ZipFile::LocalFileHeader) + pFileHeader->nFileNameLength; - pBuffer.resize(nBufferLength); - Read(&pBuffer[0], nBufferLength); + // Read only the LocalFileHeader w/ no additional bytes ('name' or 'extra' fields) + AZStd::vector buffer; + uint32_t bufferLen = sizeof(ZipFile::LocalFileHeader); + buffer.resize_no_construct(bufferLen); + Read(buffer.data(), bufferLen); - // validate the local file header (compare with the CDR file header - they should contain basically the same information) - const auto* pLocalFileHeader = reinterpret_cast(&pBuffer[0]); - if (pFileHeader->desc != pLocalFileHeader->desc - || pFileHeader->nMethod != pLocalFileHeader->nMethod - || pFileHeader->nFileNameLength != pLocalFileHeader->nFileNameLength - // for a tough validation, we can compare the timestamps of the local and central directory entries - // but we won't do that for backward compatibility with ZipDir - //|| pFileHeader->nLastModDate != pLocalFileHeader->nLastModDate - //|| pFileHeader->nLastModTime != pLocalFileHeader->nLastModTime - ) + const auto* localFileHeader = reinterpret_cast(buffer.data()); + + // set the correct file data offset... + fileEntry.nFileDataOffset = pFileHeader->lLocalHeaderOffset + sizeof(ZipFile::LocalFileHeader) + + localFileHeader->nFileNameLength + localFileHeader->nExtraFieldLength; + + fileEntry.nEOFOffset = fileEntry.nFileDataOffset + fileEntry.desc.lSizeCompressed; + + if (m_nInitMethod != ZipDir::InitMethod::Default) { - AZ_Warning("Archive", false, "ZD_ERROR_VALIDATION_FAILED:" - " The local file header descriptor doesn't match the basic parameters declared in the global file header in the file." - " The archive content is misconsistent and may be damaged. Please try to repair the archive"); - return; + if (m_nInitMethod == ZipDir::InitMethod::FullValidation) + { + // Mark the FileEntry to check CRC when the next read occurs + fileEntry.bCheckCRCNextRead = true; + } + + // Timestamps + if (pFileHeader->nLastModDate != localFileHeader->nLastModDate + || pFileHeader->nLastModTime != localFileHeader->nLastModTime) + { + AZ_Warning("Archive", false, "ZD_ERROR_VALIDATION_FAILED: (%s)\n" + " The local file header's modification timestamps don't match that of the global file header in the archive." + " The archive timestamps are inconsistent and may be damaged. Check the archive file.", m_szFilename.c_str()); + // don't return here, it may be ok. + } + + // Validate data + if (pFileHeader->desc != localFileHeader->desc // this checks CRCs and compressed/uncompressed sizes + || pFileHeader->nMethod != localFileHeader->nMethod + || pFileHeader->nFileNameLength != localFileHeader->nFileNameLength) + { + AZ_Warning("Archive", false, "ZD_ERROR_VALIDATION_FAILED: (%s)\n" + " The local file header descriptor doesn't match basic parameters declared in the global file header in the file." + " The archive content is inconsistent and may be damaged. Please try to repair the archive.", m_szFilename.c_str()); + // return here because further checks aren't worse than this. + return; + } + + // Read extra data + uint32_t extraDataLen = localFileHeader->nFileNameLength + localFileHeader->nExtraFieldLength; + buffer.resize_no_construct(buffer.size() + extraDataLen); + Read(buffer.data() + buffer.size(), extraDataLen); + + // Compare local file name with the CDR file name, they should match + AZStd::string_view zipFileName{ buffer.data() + sizeof(ZipFile::LocalFileHeader), localFileHeader->nFileNameLength }; + AZStd::string_view cdrFileName{ reinterpret_cast(pFileHeader + 1), pFileHeader->nFileNameLength }; + if (zipFileName != cdrFileName) + { + AZ_Warning("Archive", false, "ZD_ERROR_VALIDATION_FAILED: (%s)\n" + " The file name in the local file header doesn't match the name in the global file header." + " The archive content is inconsisten with the directory. Please check the archive.", m_szFilename.c_str()); + } + + // CDR and local "extra field" lengths may be different, should we compare them if they are equal? + + // make sure it's the same file and the fileEntry structure is properly initialized + AZ_Assert(fileEntry.nFileHeaderOffset == pFileHeader->lLocalHeaderOffset, + "The file entry header offset doesn't match the file header local offst (%s)", m_szFilename.c_str()); + + if (fileEntry.nFileDataOffset >= m_nCDREndPos) + { + AZ_Warning("Archive", false, "ZD_ERROR_VALIDATION_FAILED: (%s)\n" + " The global file header declares the file which crosses the boundaries of the archive." + " The archive is either corrupted or truncated, please try to repair it", m_szFilename.c_str()); + } + + // End Validation } - - // now compare the local file name with the one recorded in CDR: they must match. - auto CompareNoCase = [](const char lhs, const char rhs) { return std::tolower(lhs, std::locale()) == std::tolower(rhs, std::locale()); }; - auto zipFileDataBegin = pBuffer.begin() + sizeof(ZipFile::LocalFileHeader); - auto zipFileDataEnd = zipFileDataBegin + pFileHeader->nFileNameLength; - if (!AZStd::equal(zipFileDataBegin, zipFileDataEnd, reinterpret_cast(pFileHeader + 1), CompareNoCase)) - { - // either file name, or the extra field do not match - AZ_Warning("Archive", false, "ZD_ERROR_VALIDATION_FAILED:" - " The local file header contains file name which does not match the file name of the global file header." - " The archive content is misconsistent with its directory. Please repair the archive"); - return; - } - - fileEntry.nFileDataOffset = pFileHeader->lLocalHeaderOffset + sizeof(ZipFile::LocalFileHeader) + pLocalFileHeader->nFileNameLength + pLocalFileHeader->nExtraFieldLength; } - - // make sure it's the same file and the fileEntry structure is properly initialized - AZ_Assert(fileEntry.nFileHeaderOffset == pFileHeader->lLocalHeaderOffset, "The file entry header offset doesn't match the file header local offst"); - - fileEntry.nEOFOffset = fileEntry.nFileDataOffset + fileEntry.desc.lSizeCompressed; - - if (fileEntry.nFileDataOffset >= m_nCDREndPos) - { - AZ_Warning("Archive", false, "ZD_ERROR_VALIDATION_FAILED:" - " The global file header declares the file which crosses the boundaries of the archive." - " The archive is either corrupted or truncated, please try to repair it"); - return; - } - - if (m_nInitMethod >= ZD_INIT_VALIDATE) - { - Validate(fileEntry); - } - } - - ////////////////////////////////////////////////////////////////////////// - // reads the file pointed by the given header and entry (they must be coherent) - // and decompresses it; then calculates and validates its CRC32 - void CacheFactory::Validate(const FileEntryBase& fileEntry) - { - AZStd::vector pBuffer; - // validate the file contents - // allocate memory for both the compressed data and uncompressed data - pBuffer.resize(fileEntry.desc.lSizeCompressed + fileEntry.desc.lSizeUncompressed); - char* pUncompressed = &pBuffer[fileEntry.desc.lSizeCompressed]; - char* pCompressed = &pBuffer[0]; - - AZ_Assert(fileEntry.nFileDataOffset != FileEntry::INVALID_DATA_OFFSET, "File entry has invalid data offset of %" PRIx32, FileEntry::INVALID_DATA_OFFSET); - Seek(fileEntry.nFileDataOffset); - - Read(pCompressed, fileEntry.desc.lSizeCompressed); - - size_t nDestSize = fileEntry.desc.lSizeUncompressed; - int nError = Z_OK; - if (fileEntry.nMethod) - { - nError = ZipRawUncompress(pUncompressed, &nDestSize, pCompressed, fileEntry.desc.lSizeCompressed); - } - else - { - AZ_Assert(fileEntry.desc.lSizeCompressed == fileEntry.desc.lSizeUncompressed, "Uncompressed file does not have the same commpressed %u and uncompressed file sizes %u", - fileEntry.desc.lSizeCompressed, fileEntry.desc.lSizeUncompressed); - memcpy(pUncompressed, pCompressed, fileEntry.desc.lSizeUncompressed); - } - switch (nError) - { - case Z_OK: - break; - case Z_MEM_ERROR: - AZ_Warning("Archive", false, "ZD_ERROR_ZLIB_NO_MEMORY: ZLib reported out-of-memory error"); - return; - case Z_BUF_ERROR: - AZ_Warning("Archive", false, "ZD_ERROR_ZLIB_CORRUPTED_DATA: ZLib reported compressed stream buffer error"); - return; - case Z_DATA_ERROR: - AZ_Warning("Archive", false, "ZD_ERROR_ZLIB_CORRUPTED_DATA: ZLib reported compressed stream data error"); - return; - default: - AZ_Warning("Archive", false, "ZD_ERROR_ZLIB_FAILED: ZLib reported an unexpected unknown error"); - return; - } - - if (nDestSize != fileEntry.desc.lSizeUncompressed) - { - AZ_Warning("Archive", false, "ZD_ERROR_CORRUPTED_DATA: Uncompressed stream doesn't match the size of uncompressed file stored in the archive file headers"); - return; - } - - uLong uCRC32 = AZ::Crc32((Bytef*)pUncompressed, nDestSize); - if (uCRC32 != fileEntry.desc.lCRC32) - { - AZ_Warning("Archive", false, "ZD_ERROR_CRC32_CHECK: Uncompressed stream CRC32 check failed"); - return; - } - } - - - ////////////////////////////////////////////////////////////////////////// - // extracts the file path from the file header with subsequent information - // may, or may not, put all letters to lower-case (depending on whether the system is to be case-sensitive or not) - // it's the responsibility of the caller to ensure that the file name is in readable valid memory - char* CacheFactory::GetFilePath(const char* pFileName, uint16_t nFileNameLength) - { - static char strResult[AZ_MAX_PATH_LEN]; - AZ_Assert(nFileNameLength < AZ_MAX_PATH_LEN, "Only filenames shorter than %zu can be copied from filename parameter", AZ_MAX_PATH_LEN); - memcpy(strResult, pFileName, nFileNameLength); - strResult[nFileNameLength] = 0; - for (int i = 0; i < nFileNameLength; i++) - { - strResult[i] = std::tolower(strResult[i], std::locale{}); - } - - return strResult; } // seeks in the file relative to the starting position diff --git a/Code/Framework/AzFramework/AzFramework/Archive/ZipDirCacheFactory.h b/Code/Framework/AzFramework/AzFramework/Archive/ZipDirCacheFactory.h index c31d4d7dfd..1612829f13 100644 --- a/Code/Framework/AzFramework/AzFramework/Archive/ZipDirCacheFactory.h +++ b/Code/Framework/AzFramework/AzFramework/Archive/ZipDirCacheFactory.h @@ -39,7 +39,7 @@ namespace AZ::IO::ZipDir // initializes the internal structures // nFlags can have FLAGS_READ_ONLY flag, in this case the object will be opened only for reading - CacheFactory(InitMethodEnum nInitMethod, uint32_t nFlags = 0); + CacheFactory(InitMethod nInitMethod, uint32_t nFlags = 0); ~CacheFactory(); // the new function creates a new cache @@ -66,28 +66,6 @@ namespace AZ::IO::ZipDir // This function can actually modify strFilePath variable, make sure you use a copy of the real path. void AddFileEntry(char* strFilePath, const ZipFile::CDRFileHeader* pFileHeader, const SExtraZipFileData& extra);// throw (ErrorEnum); - // extracts the file path from the file header with subsequent information - // may, or may not, put all letters to lower-case (depending on whether the system is to be case-sensitive or not) - // it's the responsibility of the caller to ensure that the file name is in readable valid memory - char* GetFilePath(const ZipFile::CDRFileHeader* pFileHeader) - { - return GetFilePath((const char*)(pFileHeader + 1), pFileHeader->nFileNameLength); - } - // extracts the file path from the file header with subsequent information - // may, or may not, put all letters to lower-case (depending on whether the system is to be case-sensitive or not) - // it's the responsibility of the caller to ensure that the file name is in readable valid memory - char* GetFilePath(const ZipFile::LocalFileHeader* pFileHeader) - { - return GetFilePath((const char*)(pFileHeader + 1), pFileHeader->nFileNameLength); - } - // extracts the file path from the file header with subsequent information - // may, or may not, put all letters to lower-case (depending on whether the system is to be case-sensitive or not) - // it's the responsibility of the caller to ensure that the file name is in readable valid memory - char* GetFilePath(const char* pFileName, uint16_t nFileNameLength); - - // validates (if the init method has the corresponding value) the given file/header - void Validate(const FileEntryBase& fileEntry); - // initializes the actual data offset in the file in the fileEntry structure // searches to the local file header, reads it and calculates the actual offset in the file void InitDataOffset(FileEntryBase& fileEntry, const ZipFile::CDRFileHeader* pFileHeader); @@ -104,7 +82,7 @@ namespace AZ::IO::ZipDir AZStd::string m_szFilename; CZipFile m_fileExt; - InitMethodEnum m_nInitMethod; + InitMethod m_nInitMethod; uint32_t m_nFlags; ZipFile::CDREnd m_CDREnd; @@ -129,7 +107,7 @@ namespace AZ::IO::ZipDir ZipFile::CryCustomEncryptionHeader m_headerEncryption; ZipFile::CrySignedCDRHeader m_headerSignature; ZipFile::CryCustomExtendedHeader m_headerExtended; - }; + } diff --git a/Code/Framework/AzFramework/AzFramework/Archive/ZipDirList.cpp b/Code/Framework/AzFramework/AzFramework/Archive/ZipDirList.cpp index 729f394b9d..ab9c356d7f 100644 --- a/Code/Framework/AzFramework/AzFramework/Archive/ZipDirList.cpp +++ b/Code/Framework/AzFramework/AzFramework/Archive/ZipDirList.cpp @@ -68,14 +68,14 @@ namespace AZ::IO::ZipDir { for (FileEntryTree::SubdirMap::iterator it = pTree->GetDirBegin(); it != pTree->GetDirEnd(); ++it) { - AddAllFiles(it->second.get(), (AZ::IO::Path(strRoot) / it->first).Native()); + AddAllFiles(it->second.get(), (AZ::IO::Path(strRoot, AZ::IO::PosixPathSeparator) / it->first).Native()); } for (FileEntryTree::FileMap::iterator it = pTree->GetFileBegin(); it != pTree->GetFileEnd(); ++it) { FileRecord rec; rec.pFileEntryBase = pTree->GetFileEntry(it); - rec.strPath = (AZ::IO::Path(strRoot) / it->first).Native(); + rec.strPath = (AZ::IO::Path(strRoot, AZ::IO::PosixPathSeparator) / it->first).Native(); push_back(rec); } } diff --git a/Code/Framework/AzFramework/AzFramework/Archive/ZipDirStructures.h b/Code/Framework/AzFramework/AzFramework/Archive/ZipDirStructures.h index 9295a7dd95..c890d498e4 100644 --- a/Code/Framework/AzFramework/AzFramework/Archive/ZipDirStructures.h +++ b/Code/Framework/AzFramework/AzFramework/Archive/ZipDirStructures.h @@ -119,19 +119,28 @@ namespace AZ::IO::ZipDir const char* m_szDescription; }; +#if defined(_RELEASE) + inline static constexpr bool IsReleaseConfig{ true }; +#else + inline static constexpr bool IsReleaseConfig{}; +#endif // _RELEASE + // possible initialization methods - enum InitMethodEnum + enum class InitMethod { - // initialize as fast as possible, with minimal validation - ZD_INIT_FAST, - // after initialization, scan through all file headers, precache the actual file data offset values and validate the headers - ZD_INIT_FULL, - // scan all file headers and try to decompress the data, searching for corrupted files - ZD_INIT_VALIDATE_IN_MEMORY, - // store archive in memory - ZD_INIT_VALIDATE, - // maximum level of validation, checks for integrity of the archive - ZD_INIT_VALIDATE_MAX = ZD_INIT_VALIDATE + // initializes without any sort of extra validation steps + Default, + + // initializes with extra validation steps + // not available in RELEASE + // will check CDR and local headers data match + ValidateHeaders, + + // initializes with extra validation steps + // not available in RELEASE + // will check CDR and local headers data match + // will check file data CRC matches (when file is read) + FullValidation, }; // Uncompresses raw (without wrapping) data that is compressed with method 8 (deflated) in the Zip file @@ -184,7 +193,11 @@ namespace AZ::IO::ZipDir // the offset to the start of the next file's header - this // can be used to calculate the available space in zip file uint32_t nEOFOffset{}; + + // whether to check the CRC upon the next data read + bool bCheckCRCNextRead{}; }; + // this is the record about the file in the Zip file. struct FileEntry : FileEntryBase diff --git a/Code/Framework/AzFramework/AzFramework/Network/AssetProcessorConnection.cpp b/Code/Framework/AzFramework/AzFramework/Network/AssetProcessorConnection.cpp index 2e1cde443c..74b92a5681 100644 --- a/Code/Framework/AzFramework/AzFramework/Network/AssetProcessorConnection.cpp +++ b/Code/Framework/AzFramework/AzFramework/Network/AssetProcessorConnection.cpp @@ -593,7 +593,7 @@ namespace AzFramework DebugMessage("StartThread: Starting %s", thread.m_desc.m_name); thread.m_join = false; - thread.m_thread = AZStd::thread(thread.m_main, &thread.m_desc); + thread.m_thread = AZStd::thread(thread.m_desc, thread.m_main); } void AssetProcessorConnection::JoinThread(ThreadState& thread, AZStd::condition_variable* wakeUpCondition /* = nullptr */) diff --git a/Code/Framework/AzFramework/AzFramework/TargetManagement/TargetManagementComponent.cpp b/Code/Framework/AzFramework/AzFramework/TargetManagement/TargetManagementComponent.cpp index 1c26cbc744..8e6bacda2b 100644 --- a/Code/Framework/AzFramework/AzFramework/TargetManagement/TargetManagementComponent.cpp +++ b/Code/Framework/AzFramework/AzFramework/TargetManagement/TargetManagementComponent.cpp @@ -319,7 +319,7 @@ namespace AzFramework AZStd::thread_desc td; td.m_name = "TargetManager Thread"; td.m_cpuId = AFFINITY_MASK_USERTHREADS; - m_threadHandle = AZStd::thread(AZStd::bind(&TargetManagementComponent::TickThread, this), &td); + m_threadHandle = AZStd::thread(td, AZStd::bind(&TargetManagementComponent::TickThread, this)); } void TargetManagementComponent::Deactivate() diff --git a/Code/Framework/AzNetworking/AzNetworking/Utilities/TimedThread.cpp b/Code/Framework/AzNetworking/AzNetworking/Utilities/TimedThread.cpp index c85d15ae45..565b37202a 100644 --- a/Code/Framework/AzNetworking/AzNetworking/Utilities/TimedThread.cpp +++ b/Code/Framework/AzNetworking/AzNetworking/Utilities/TimedThread.cpp @@ -26,27 +26,29 @@ namespace AzNetworking { m_running = true; m_joinable = true; - m_thread = AZStd::thread([this]() - { - OnStart(); - while (m_running) + m_thread = AZStd::thread( + m_threadDesc, + [this]() { - const AZ::TimeMs startTimeMs = AZ::GetElapsedTimeMs(); - OnUpdate(m_updateRate); - const AZ::TimeMs updateTimeMs = AZ::GetElapsedTimeMs() - startTimeMs; + OnStart(); + while (m_running) + { + const AZ::TimeMs startTimeMs = AZ::GetElapsedTimeMs(); + OnUpdate(m_updateRate); + const AZ::TimeMs updateTimeMs = AZ::GetElapsedTimeMs() - startTimeMs; - if (m_updateRate > updateTimeMs) - { - AZStd::chrono::milliseconds sleepTimeMs(static_cast(m_updateRate - updateTimeMs)); - AZStd::this_thread::sleep_for(sleepTimeMs); + if (m_updateRate > updateTimeMs) + { + AZStd::chrono::milliseconds sleepTimeMs(static_cast(m_updateRate - updateTimeMs)); + AZStd::this_thread::sleep_for(sleepTimeMs); + } + else if (m_updateRate < updateTimeMs) + { + AZLOG(NET_TimedThread, "TimedThread bled %d ms", aznumeric_cast(updateTimeMs - m_updateRate)); + } } - else if (m_updateRate < updateTimeMs) - { - AZLOG(NET_TimedThread, "TimedThread bled %d ms", aznumeric_cast(updateTimeMs - m_updateRate)); - } - } - OnStop(); - }, &m_threadDesc); + OnStop(); + }); } void TimedThread::Stop() diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/ArchiveAPI.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/ArchiveAPI.h index fa8c2c14ff..11c4c85722 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/ArchiveAPI.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/ArchiveAPI.h @@ -12,95 +12,84 @@ #include #include #include +#include namespace AzToolsFramework { - // use bind if you need additional context. - // Parameters: - // bool - If the archive command was successful or not. - typedef AZStd::function ArchiveResponseCallback; - // bool - If the archive command was successful or not. - // AZStd::string - The console output from the command. - typedef AZStd::function ArchiveResponseOutputCallback; - - //! ArchiveCommands //! This bus handles messages relating to archive commands //! archive commands are ASYNCHRONOUS //! archive formats officially supported are .zip - //! do not block the main thread waiting for a response, it is not okay - //! you will not get a message delivered unless you tick the tickbus anyway! class ArchiveCommands : public AZ::EBusTraits { public: - - using Bus = AZ::EBus; - + // EBus Traits static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; typedef AZStd::recursive_mutex MutexType; static const bool LocklessDispatch = true; - virtual ~ArchiveCommands() {} - //! Start an async task to extract an archive to the target directory - //! taskHandles are used to cancel a task at some point in the future and are provided by the caller per task. - //! Multiple tasks can be associated with the same handle - virtual void ExtractArchive(const AZStd::string& archivePath, const AZStd::string& destinationPath, AZ::Uuid taskHandle, const ArchiveResponseCallback& respCallback) = 0; - virtual void ExtractArchiveOutput(const AZStd::string& archivePath, const AZStd::string& destinationPath, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) = 0; - // Maintaining backwards API compatibility - ExtractArchiveBlocking below passes in extractWithRoot as an option - virtual void ExtractArchiveWithoutRoot(const AZStd::string& archivePath, const AZStd::string& destinationPath, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) = 0; + virtual ~ArchiveCommands() = default; - //! Start a sync task to extract an archive to the target directory - //! If you do not want to extract the root folder then set extractWithRootDirectory to false. - virtual bool ExtractArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& destinationPath, bool extractWithRootDirectory) = 0; + //! Create an archive of the target directory (all files and subdirectories) + //! @param archivePath The path of the archive to create + //! @dirToArchive The directory to be added to the archive + //! @return Future (bool) which can obtain the success value of the operation + [[nodiscard]] virtual std::future CreateArchive( + const AZStd::string& archivePath, + const AZStd::string& dirToArchive) = 0; - //! Extract a single file asynchronously from the archive to the destination. - //! Uses cwd if destinationPath empty. overWrite = true for overwrite existing files, false for skipExisting - //! taskHandles are used to cancel a task at some point in the future and are provided by the caller per task. - //! Multiple tasks can be associated with the same handle - virtual void ExtractFile(const AZStd::string& archivePath, const AZStd::string& fileInArchive, const AZStd::string& destinationPath, bool overWrite, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) = 0; + //! Extract an archive to the target directory + //! @param archivePath The path of the archive to extract + //! @param destinationPath The directory where files will be extracted to + //! @return Future (bool) which can obtain the success value of the operation + [[nodiscard]] virtual std::future ExtractArchive( + const AZStd::string& archivePath, + const AZStd::string& destinationPath) = 0; - //! Extract a single file from the archive to the destination and block until finished. - //! Uses cwd if destinationPath empty. overWrite = true for overwrite existing files, false for skipExisting - virtual bool ExtractFileBlocking(const AZStd::string& archivePath, const AZStd::string& fileInArchive, const AZStd::string& destinationPath, bool overWrite) = 0; + //! Extract a single file from the archive to the destination + //! Destination path should not be empty + //! @param archivePath The path of the archive to extract from + //! @param fileInArchive A path to a file, relative to root of archive + //! @param destinationPath The directory where file will be extracted to + //! @return Future (bool) which can obtain the success value of the operation + [[nodiscard]] virtual std::future ExtractFile( + const AZStd::string& archivePath, + const AZStd::string& fileInArchive, + const AZStd::string& destinationPath) = 0; - //! Start an async task to create an archive of the target directory (recursively) - //! taskHandles are used to cancel a task at some point in the future and are provided by the caller per task. - //! Multiple tasks can be associated with the same handle. - virtual void CreateArchive(const AZStd::string& archivePath, const AZStd::string& dirToArchive, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) = 0; + //! Retrieve the list of files contained in an archive (all files and subdirectories) + //! @param archivePath The path of the archive to list + //! @param outFileEntries An out parameter that will contain the file paths found + //! @return True if successful, false otherwise + virtual bool ListFilesInArchive(const AZStd::string& archivePath, AZStd::vector& outFileEntries) = 0; - //! Start a sync task to create an archive of the target directory (recursively) - virtual bool CreateArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& dirToArchive) = 0; - - //! Start an async task to retrieve the list of files and their relative paths within an archive (recursively) - //! taskHandles are used to cancel a task at some point in the future and are provided by the caller per task. - //! Multiple tasks can be associated with the same handle. - virtual void ListFilesInArchive(const AZStd::string& archivePath, AZStd::vector& fileEntries, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) = 0; + //! Add a file to an archive + //! The archive might not exist yet + //! The file path relative to the working directory will be replicated in the archive + //! @param archivePath The path of the archive to add to + //! @param workingDirectory A directory that will be the starting path of the file to be added + //! @param fileToAdd A path to the file relative to the working directory + //! @return Future (bool) which can obtain the success value of the operation + [[nodiscard]] virtual std::future AddFileToArchive( + const AZStd::string& archivePath, + const AZStd::string& workingDirectory, + const AZStd::string& fileToAdd) = 0; - //! Start a sync task to retrieve the list of files and their relative paths within an archive (recursively) - virtual bool ListFilesInArchiveBlocking(const AZStd::string& archivePath, AZStd::vector& fileEntries) = 0; - - //! Start an async task to add a file to a preexisting archive. - //! fileToAdd must be a relative path to the file from the working directory. The path to the file from the root of the archive will be the same as the relative path to the file on disk. - //! taskHandles are used to cancel a task at some point in the future and are provided by the caller per task. - //! Multiple tasks can be associated with the same handle. - virtual void AddFileToArchive(const AZStd::string& archivePath, const AZStd::string& workingDirectory, const AZStd::string& fileToAdd, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) = 0; - - //! Start a sync task to add a file to a preexisting archive. - //! fileToAdd must be a relative path to the file from the working directory. The path to the file from the root of the archive will be the same as the relative path to the file on disk. - virtual bool AddFileToArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& workingDirectory, const AZStd::string& fileToAdd) = 0; - - //! Start an async task to add files to a archive. - //! File paths inside the list file must either be a relative path from the working directory or an absolute path. - virtual void AddFilesToArchive(const AZStd::string& archivePath, const AZStd::string& workingDirectory, const AZStd::string& listFilePath, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) = 0; - - //! Start a sync task to add files to an archive. - //! File paths inside the list file must either be a relative path from the working directory or an absolute path. - virtual bool AddFilesToArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& workingDirectory, const AZStd::string& listFilePath) = 0; - - //! Cancels tasks associtated with the given handle. Blocks until all tasks are cancelled. - virtual void CancelTasks(AZ::Uuid taskHandle) = 0; + //! Add files to an archive provided from a file listing + //! The archive might not exist yet + //! File paths in the file list should be relative to root of the archive + //! @param archivePath The path of the archive to add to + //! @param workingDirectory A directory that will be the starting path of the list of files to add + //! @param listFilePath Full path to a text file that contains the list of files to add + //! @return Future (bool) which can obtain the success value of the operation + [[nodiscard]] virtual std::future AddFilesToArchive( + const AZStd::string& archivePath, + const AZStd::string& workingDirectory, + const AZStd::string& listFilePath) = 0; }; + using ArchiveCommandsBus = AZ::EBus; + }; // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/ArchiveComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/ArchiveComponent.cpp index 5004108132..8e07794c33 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/ArchiveComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/ArchiveComponent.cpp @@ -12,118 +12,98 @@ #include #include -#include - +#include +#include #include #include #include + namespace AzToolsFramework { - // Forward declare platform specific functions - namespace Platform + constexpr const char s_traceName[] = "ArchiveComponent"; + constexpr AZ::u32 s_compressionMethod = AZ::IO::INestedArchive::METHOD_DEFLATE; + constexpr AZ::s32 s_compressionLevel = AZ::IO::INestedArchive::LEVEL_NORMAL; + constexpr CompressionCodec::Codec s_compressionCodec = CompressionCodec::Codec::ZLIB; + + namespace ArchiveUtils { - AZStd::string GetZipExePath(); - AZStd::string GetUnzipExePath(); - - AZStd::string GetCreateArchiveCommand(const AZStd::string& archivePath, const AZStd::string& dirToArchive); - AZStd::string GetExtractArchiveCommand(const AZStd::string& archivePath, const AZStd::string& destinationPath, bool includeRoot); - AZStd::string GetAddFileToArchiveCommand(const AZStd::string& archivePath, const AZStd::string& file); - AZStd::string GetAddFilesToArchiveCommand(const AZStd::string& archivePath, const AZStd::string& listFilePath); - AZStd::string GetExtractFileCommand(const AZStd::string& archivePath, const AZStd::string& fileInArchive, const AZStd::string& destinationPath, bool overWrite); - AZStd::string GetListFilesInArchiveCommand(const AZStd::string& archivePath); - void ParseConsoleOutputFromListFilesInArchive(const AZStd::string& consoleOutput, AZStd::vector& fileEntries); - } - - const char s_traceName[] = "ArchiveComponent"; - const unsigned int g_sleepDuration = 1; - - // Echoes all results of stdout and stderr to console and never blocks - class ConsoleEchoCommunicator - { - public: - ConsoleEchoCommunicator(AzFramework::ProcessCommunicator* communicator) - : m_communicator(communicator) + // Read a file's contents into a provided buffer. + // Does not add a zero byte at the end of the buffer. + // returns true if read was successful, false otherwise. + bool ReadFile(const AZ::IO::Path& filePath, AZ::IO::OpenMode openMode, AZStd::vector& outBuffer) { - } - - ~ConsoleEchoCommunicator() - { - } - - // Call this periodically to drain the buffers - void Pump() - { - if (m_communicator->IsValid()) + auto fileIO = AZ::IO::FileIOBase::GetDirectInstance(); + if (!fileIO) { - AZ::u32 readBufferSize = 0; - AZStd::string readBuffer; - // Don't call readOutput unless there is output or else it will block... - readBufferSize = m_communicator->PeekOutput(); - if (readBufferSize) - { - readBuffer.resize_no_construct(readBufferSize + 1); - readBuffer[readBufferSize] = '\0'; - m_communicator->ReadOutput(readBuffer.data(), readBufferSize); - EchoBuffer(readBuffer); - } - readBufferSize = m_communicator->PeekError(); - if (readBufferSize) - { - readBuffer.resize_no_construct(readBufferSize + 1); - readBuffer[readBufferSize] = '\0'; - m_communicator->ReadError(readBuffer.data(), readBufferSize); - EchoBuffer(readBuffer); - } + return false; } - } - private: - void EchoBuffer(const AZStd::string& buffer) - { - size_t startIndex = 0; - size_t endIndex = 0; - const size_t bufferSize = buffer.size(); - for (size_t i = 0; i < bufferSize; ++i) + bool success = false; + AZ::IO::HandleType fileHandle = AZ::IO::InvalidHandle; + if (fileIO->Open(filePath.c_str(), openMode, fileHandle)) { - if (buffer[i] == '\n' || buffer[i] == '\0') + AZ::u64 fileSize = 0; + if (fileIO->Size(fileHandle, fileSize) && fileSize != 0) { - endIndex = i; - bool isEmptyMessage = (endIndex - startIndex == 1) && (buffer[startIndex] == '\r'); - if (!isEmptyMessage) + outBuffer.resize_no_construct(fileSize); + + AZ::u64 bytesRead = 0; + if (fileIO->Read(fileHandle, outBuffer.data(), fileSize, true, &bytesRead)) { - AZ_Printf(s_traceName, "%s", buffer.substr(startIndex, endIndex - startIndex).c_str()); + success = (fileSize == bytesRead); } - startIndex = endIndex + 1; } + + fileIO->Close(fileHandle); + } + + return success; + } + + // Reads a text file that contains a list of file paths. + // Tokenize the file by lines. + // Calls the lineVisitor function for each line of the file. + void ProcessFileList(const AZ::IO::Path& filePath, AZStd::function lineVisitor) + { + AZStd::vector fileBuffer; + if (ReadFile(filePath, AZ::IO::OpenMode::ModeText | AZ::IO::OpenMode::ModeRead, fileBuffer)) + { + AZ::StringFunc::TokenizeVisitor(AZStd::string_view{ fileBuffer.data(), fileBuffer.size() }, lineVisitor, "\n"); } } - AzFramework::ProcessCommunicator* m_communicator = nullptr; - }; + } // namespace ArchiveUtils void ArchiveComponent::Activate() { - m_zipExePath = Platform::GetZipExePath(); - m_unzipExePath = Platform::GetUnzipExePath(); + m_fileIO = AZ::IO::FileIOBase::GetDirectInstance(); + if (m_fileIO == nullptr) + { + AZ_Error(s_traceName, false, "Failed to create a LocalFileIO instance!"); + } - ArchiveCommands::Bus::Handler::BusConnect(); + m_archive = AZ::Interface::Get(); + if (m_archive == nullptr) + { + AZ_Error(s_traceName, false, "Failed to get IArchive interface!"); + } + + ArchiveCommandsBus::Handler::BusConnect(); } void ArchiveComponent::Deactivate() { - ArchiveCommands::Bus::Handler::BusDisconnect(); + ArchiveCommandsBus::Handler::BusDisconnect(); - AZStd::unique_lock lock(m_threadControlMutex); - for (auto pair : m_threadInfoMap) + m_fileIO = nullptr; + m_archive = nullptr; + + for (AZStd::thread& t : m_threads) { - ThreadInfo& info = pair.second; - info.shouldStop = true; - m_cv.wait(lock, [&info]() { - return info.threads.size() == 0; - }); + t.join(); } - m_threadInfoMap.clear(); + m_threads = {}; } void ArchiveComponent::Reflect(AZ::ReflectContext * context) @@ -132,7 +112,7 @@ namespace AzToolsFramework { serializeContext->Class() ->Version(2) - ->Attribute(AZ::Edit::Attributes::SystemComponentTags, AZStd::vector({ AZ_CRC("AssetBuilder", 0xc739c7d7) })) + ->Attribute(AZ::Edit::Attributes::SystemComponentTags, AZStd::vector({ AZ_CRC_CE("AssetBuilder") })) ; if (AZ::EditContext* editContext = serializeContext->GetEditContext()) @@ -141,320 +121,480 @@ namespace AzToolsFramework "Archive", "Handles creation and extraction of zip archives.") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::Category, "Editor") - ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System", 0xc94d118b)) + ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("System")) ; } } } - void ArchiveComponent::CreateArchive(const AZStd::string& archivePath, const AZStd::string& dirToArchive, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) + std::future ArchiveComponent::CreateArchive( + const AZStd::string& archivePath, + const AZStd::string& dirToArchive) { - AZStd::string commandLineArgs = AZStd::string::format(R"(a -tzip -mx=1 "%s" -r "%s\*")", archivePath.c_str(), dirToArchive.c_str()); - LaunchZipExe(m_zipExePath, commandLineArgs, respCallback, taskHandle); - } - - bool ArchiveComponent::CreateArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& dirToArchive) - { - bool success = false; - auto createArchiveCallback = [&success](bool result, AZStd::string consoleOutput) { - success = result; - }; - - AZStd::string commandLineArgs = Platform::GetCreateArchiveCommand(archivePath, dirToArchive); - - if (commandLineArgs.empty()) + if (!CheckParamsForCreate(archivePath, dirToArchive)) { - // The platform-specific implementation has already thrown its own error, no need to throw another one - return false; + std::promise p; + p.set_value(false); + return p.get_future(); } - LaunchZipExe(m_zipExePath, commandLineArgs, createArchiveCallback, AZ::Uuid::CreateNull(), dirToArchive, false); - return success; - } - - void ArchiveComponent::ExtractArchive(const AZStd::string& archivePath, const AZStd::string& destinationPath, AZ::Uuid taskHandle, const ArchiveResponseCallback& respCallback) - { - ArchiveResponseOutputCallback responseHandler = [respCallback](bool result, AZStd::string /*outputStr*/) { respCallback(result); }; - ExtractArchiveOutput(archivePath, destinationPath, taskHandle, responseHandler); - } - - void ArchiveComponent::ExtractArchiveOutput(const AZStd::string& archivePath, const AZStd::string& destinationPath, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) - { - AZStd::string commandLineArgs = Platform::GetExtractArchiveCommand(archivePath, destinationPath, true); - - if (commandLineArgs.empty()) + auto FnCreateArchive = [this, archivePath, dirToArchive](std::promise&& p) -> void { - // The platform-specific implementation has already thrown its own error, no need to throw another one - return; - } - - LaunchZipExe(m_unzipExePath, commandLineArgs, respCallback, taskHandle); - } - - void ArchiveComponent::ExtractArchiveWithoutRoot(const AZStd::string& archivePath, const AZStd::string& destinationPath, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) - { - AZStd::string commandLineArgs = Platform::GetExtractArchiveCommand(archivePath, destinationPath, false); - - if (commandLineArgs.empty()) - { - // The platform-specific implementation has already thrown its own error, no need to throw another one - return; - } - - LaunchZipExe(m_unzipExePath, commandLineArgs, respCallback, taskHandle); - } - - void ArchiveComponent::ExtractFile(const AZStd::string& archivePath, const AZStd::string& fileInArchive, const AZStd::string& destinationPath, bool overWrite, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) - { - AZStd::string commandLineArgs = AzToolsFramework::Platform::GetExtractFileCommand(archivePath, fileInArchive, destinationPath, overWrite); - if (commandLineArgs.empty()) - { - // The platform-specific implementation has already thrown its own error, no need to throw another one - return; - } - LaunchZipExe(m_unzipExePath, commandLineArgs, respCallback, taskHandle); - } - - bool ArchiveComponent::ExtractFileBlocking(const AZStd::string& archivePath, const AZStd::string& fileInArchive, const AZStd::string& destinationPath, bool overWrite) - { - AZStd::string commandLineArgs = AzToolsFramework::Platform::GetExtractFileCommand(archivePath, fileInArchive, destinationPath, overWrite); - if (commandLineArgs.empty()) - { - // The platform-specific implementation has already thrown its own error, no need to throw another one - return false; - } - - bool success = false; - auto createArchiveCallback = [&success](bool result, AZStd::string consoleOutput) { - success = result; - }; - LaunchZipExe(m_unzipExePath, commandLineArgs, createArchiveCallback); - return success; - } - - void ArchiveComponent::ListFilesInArchive(const AZStd::string& archivePath, AZStd::vector& fileEntries, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) - { - AZStd::string commandLineArgs = Platform::GetListFilesInArchiveCommand(archivePath); - - auto parseOutput = [respCallback, &fileEntries](bool exitCode, AZStd::string consoleOutput) - { - Platform::ParseConsoleOutputFromListFilesInArchive(consoleOutput, fileEntries); - AZ::TickBus::QueueFunction(respCallback, exitCode, AZStd::move(consoleOutput)); - }; - LaunchZipExe(m_unzipExePath, commandLineArgs, parseOutput, taskHandle, "", true); - } - - bool ArchiveComponent::ListFilesInArchiveBlocking(const AZStd::string& archivePath, AZStd::vector& fileEntries) - { - AZStd::string listOutput; - AZStd::string commandLineArgs = Platform::GetListFilesInArchiveCommand(archivePath.c_str()); - bool success = false; - - auto parseOutput = [&success, &fileEntries](bool result, AZStd::string consoleOutput) - { - Platform::ParseConsoleOutputFromListFilesInArchive(consoleOutput, fileEntries); - success = result; - }; - LaunchZipExe(m_unzipExePath, commandLineArgs, parseOutput, AZ::Uuid::CreateNull(), "", true); - return success; - } - - void ArchiveComponent::AddFileToArchive(const AZStd::string& archivePath, const AZStd::string& workingDirectory, const AZStd::string& fileToAdd, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) - { - AZStd::string commandLineArgs = Platform::GetAddFileToArchiveCommand(archivePath, fileToAdd); - if (commandLineArgs.empty()) - { - // The platform-specific implementation has already thrown its own error, no need to throw another one - return; - } - - LaunchZipExe(m_zipExePath, commandLineArgs, respCallback, taskHandle, workingDirectory); - } - - bool ArchiveComponent::AddFileToArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& workingDirectory, const AZStd::string& fileToAdd) - { - AZStd::string commandLineArgs = Platform::GetAddFileToArchiveCommand(archivePath, fileToAdd); - if (commandLineArgs.empty()) - { - // The platform-specific implementation has already thrown its own error, no need to throw another one - return false; - } - bool success = false; - auto addFileToArchiveCallback = [&success](bool result, AZStd::string consoleOutput) { - success = result; - }; - - LaunchZipExe(m_zipExePath, commandLineArgs, addFileToArchiveCallback, AZ::Uuid::CreateNull(), workingDirectory); - return success; - } - - bool ArchiveComponent::AddFilesToArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& workingDirectory, const AZStd::string& listFilePath) - { - bool success = false; - - auto addFileToArchiveCallback = [&success](bool result, AZStd::string consoleOutput) { - success = result; - }; - - AZStd::string commandLineArgs = Platform::GetAddFilesToArchiveCommand(archivePath.c_str(), listFilePath.c_str()); - - if (commandLineArgs.empty()) - { - // The platform-specific implementation has already thrown its own error, no need to throw another one - return false; - } - LaunchZipExe(m_zipExePath, commandLineArgs, addFileToArchiveCallback, AZ::Uuid::CreateNull(), workingDirectory); - return success; - } - - void ArchiveComponent::AddFilesToArchive(const AZStd::string& archivePath, const AZStd::string& workingDirectory, const AZStd::string& listFilePath, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) - { - AZStd::string commandLineArgs = Platform::GetAddFilesToArchiveCommand(archivePath, listFilePath); - if (commandLineArgs.empty()) - { - // The platform-specific implementation has already thrown its own error, no need to throw another one - return; - } - - LaunchZipExe(m_zipExePath, commandLineArgs, respCallback, taskHandle, workingDirectory); - } - - - bool ArchiveComponent::ExtractArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& destinationPath, bool extractWithRootDirectory) - { - AZStd::string commandLineArgs = Platform::GetExtractArchiveCommand(archivePath, destinationPath, extractWithRootDirectory); - - if (commandLineArgs.empty()) - { - // The platform-specific implementation has already thrown its own error, no need to throw another one - return false; - } - - bool success = false; - auto extractArchiveCallback = [&success](bool result, AZStd::string consoleOutput) { - success = result; - }; - - LaunchZipExe(m_unzipExePath, commandLineArgs, extractArchiveCallback); - return success; - } - - void ArchiveComponent::CancelTasks(AZ::Uuid taskHandle) - { - AZStd::unique_lock lock(m_threadControlMutex); - - auto it = m_threadInfoMap.find(taskHandle); - if (it == m_threadInfoMap.end()) - { - return; - } - - ThreadInfo& info = it->second; - info.shouldStop = true; - m_cv.wait(lock, [&info]() { - return info.threads.size() == 0; - }); - m_threadInfoMap.erase(it); - } - - void ArchiveComponent::LaunchZipExe(const AZStd::string& exePath, const AZStd::string& commandLineArgs, const ArchiveResponseOutputCallback& respCallback, AZ::Uuid taskHandle, const AZStd::string& workingDir, bool captureOutput) - { - auto sevenZJob = [=]() - { - if (!taskHandle.IsNull()) + auto archive = m_archive->OpenArchive(archivePath, {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW); + if (!archive) { - AZStd::unique_lock lock(m_threadControlMutex); - m_threadInfoMap[taskHandle].threads.insert(AZStd::this_thread::get_id()); - m_cv.notify_all(); + AZ_Error(s_traceName, false, "Failed to create archive file '%s'", archivePath.c_str()); + p.set_value(false); + return; } - AzFramework::ProcessLauncher::ProcessLaunchInfo info; - info.m_commandlineParameters = exePath + " " + commandLineArgs; - - info.m_showWindow = false; - if (!workingDir.empty()) + auto foundFiles = AzFramework::FileFunc::FindFilesInPath(dirToArchive, "*", true); + if (!foundFiles.IsSuccess()) { - info.m_workingDirectory = workingDir; + AZ_Error(s_traceName, false, "Failed to find file listing under directory '%d'", dirToArchive.c_str()); + p.set_value(false); + return; } - AZStd::unique_ptr watcher(AzFramework::ProcessWatcher::LaunchProcess(info, AzFramework::ProcessCommunicationType::COMMUNICATOR_TYPE_STDINOUT)); - AZStd::string consoleOutput; - AZ::u32 exitCode = static_cast(SevenZipExitCode::UserStoppedProcess); - if (watcher) + bool success = true; + AZStd::vector fileBuffer; + const AZ::IO::Path workingPath{ dirToArchive }; + + for (const auto& fileName : foundFiles.GetValue()) { - // callback requires output captured from 7z - if (captureOutput) + bool thisSuccess = false; + + AZ::IO::PathView relativePath = AZ::IO::PathView{ fileName }.LexicallyRelative(workingPath); + + AZ::IO::Path fullPath = (workingPath / relativePath); + if (ArchiveUtils::ReadFile(fullPath, AZ::IO::OpenMode::ModeRead, fileBuffer)) { - AZStd::string consoleBuffer; - while (watcher->IsProcessRunning(&exitCode)) - { - if (!taskHandle.IsNull()) - { - AZStd::unique_lock lock(m_threadControlMutex); - if (m_threadInfoMap[taskHandle].shouldStop) - { - watcher->TerminateProcess(static_cast(SevenZipExitCode::UserStoppedProcess)); - } - } - watcher->WaitForProcessToExit(g_sleepDuration, &exitCode); - AZ::u32 outputSize = watcher->GetCommunicator()->PeekOutput(); - if (outputSize) - { - consoleBuffer.resize(outputSize); - watcher->GetCommunicator()->ReadOutput(consoleBuffer.data(), outputSize); - consoleOutput += consoleBuffer; - } - } + int result = archive->UpdateFile( + relativePath.Native(), fileBuffer.data(), fileBuffer.size(), s_compressionMethod, + s_compressionLevel, s_compressionCodec); + + thisSuccess = (result == AZ::IO::ZipDir::ZD_ERROR_SUCCESS); + AZ_Error( + s_traceName, thisSuccess, "Error %d encountered while adding '%s' to archive '%.*s'", result, fileName.c_str(), + AZ_STRING_ARG(archive->GetFullPath().Native())); } else { - ConsoleEchoCommunicator echoCommunicator(watcher->GetCommunicator()); - while (watcher->IsProcessRunning(&exitCode)) - { - if (!taskHandle.IsNull()) - { - AZStd::unique_lock lock(m_threadControlMutex); - if (m_threadInfoMap[taskHandle].shouldStop) - { - watcher->TerminateProcess(static_cast(SevenZipExitCode::UserStoppedProcess)); - } - } - watcher->WaitForProcessToExit(g_sleepDuration, &exitCode); - echoCommunicator.Pump(); - } + AZ_Error( + s_traceName, false, "Error encountered while reading '%s' to add to archive '%.*s'", fileName.c_str(), + AZ_STRING_ARG(archive->GetFullPath().Native())); } + + success = (success && thisSuccess); } - if (taskHandle.IsNull()) + archive.reset(); + p.set_value(success); + }; + + // Async task... + std::promise p; + std::future f = p.get_future(); + + AZStd::thread_desc threadDesc; + threadDesc.m_name = "Archive Task (Create)"; + m_threads.emplace_back(threadDesc, FnCreateArchive, AZStd::move(p)); + return f; + } + + + std::future ArchiveComponent::ExtractArchive( + const AZStd::string& archivePath, + const AZStd::string& destinationPath) + { + if (!CheckParamsForExtract(archivePath, destinationPath)) + { + std::promise p; + p.set_value(false); + return p.get_future(); + } + + auto FnExtractArchive = [this, archivePath, destinationPath](std::promise&& p) -> void + { + auto archive = m_archive->OpenArchive(archivePath, {}, AZ::IO::INestedArchive::FLAGS_READ_ONLY); + if (!archive) { - respCallback(exitCode == static_cast(SevenZipExitCode::NoError), AZStd::move(consoleOutput)); + AZ_Error(s_traceName, false, "Failed to open archive file '%s'", archivePath.c_str()); + p.set_value(false); + return; + } + + AZStd::vector filesInArchive; + if (int result = archive->ListAllFiles(filesInArchive); result != AZ::IO::ZipDir::ZD_ERROR_SUCCESS) + { + AZ_Error(s_traceName, false, "Failed to get list of files in archive '%s'", archivePath.c_str()); + p.set_value(false); + return; + } + + AZStd::vector fileBuffer; + AZ::IO::Path destination{ destinationPath }; + AZ::u64 fileSize = 0; + AZ::u64 numFilesWritten = 0; + AZ::u64 bytesWritten = 0; + AZ::IO::INestedArchive::Handle srcHandle{}; + AZ::IO::HandleType dstHandle = AZ::IO::InvalidHandle; + constexpr AZ::IO::OpenMode openMode = + (AZ::IO::OpenMode::ModeCreatePath | AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeUpdate); + + for (const auto& filePath : filesInArchive) + { + srcHandle = archive->FindFile(filePath.Native()); + AZ_Assert(srcHandle != nullptr, "File '%s' does not exist inside archive '%s'", filePath.c_str(), archivePath.c_str()); + + fileSize = (srcHandle != nullptr) ? archive->GetFileSize(srcHandle) : 0; + fileBuffer.resize_no_construct(fileSize); + if (auto result = archive->ReadFile(srcHandle, fileBuffer.data()); result != AZ::IO::ZipDir::ZD_ERROR_SUCCESS) + { + AZ_Error( + s_traceName, false, "Failed to read file '%s' in archive '%s' with error %d", filePath.c_str(), archivePath.c_str(), + result); + continue; + } + + AZ::IO::Path destinationFile = destination / filePath; + if (!m_fileIO->Open(destinationFile.c_str(), openMode, dstHandle)) + { + AZ_Error(s_traceName, false, "Failed to open '%s' for writing", destinationFile.c_str()); + continue; + } + + if (!m_fileIO->Write(dstHandle, fileBuffer.data(), fileSize, &bytesWritten)) + { + AZ_Error(s_traceName, false, "Failed to write destination file '%s'", destinationFile.c_str()); + } + else if (bytesWritten == fileSize) + { + ++numFilesWritten; + } + + m_fileIO->Close(dstHandle); + } + + p.set_value(numFilesWritten == filesInArchive.size()); + }; + + // Async task... + std::promise p; + std::future f = p.get_future(); + + AZStd::thread_desc threadDesc; + threadDesc.m_name = "Archive Task (Extract)"; + m_threads.emplace_back(threadDesc, FnExtractArchive, AZStd::move(p)); + return f; + } + + + std::future ArchiveComponent::ExtractFile( + const AZStd::string& archivePath, + const AZStd::string& fileInArchive, + const AZStd::string& destinationPath) + { + if (!CheckParamsForExtract(archivePath, destinationPath)) + { + std::promise p; + p.set_value(false); + return p.get_future(); + } + + auto FnExtractFile = [this, archivePath, fileInArchive, destinationPath](std::promise&& p) -> void + { + auto archive = m_archive->OpenArchive(archivePath, {}, AZ::IO::INestedArchive::FLAGS_READ_ONLY); + if (!archive) + { + AZ_Error(s_traceName, false, "Failed to open archive file '%s'", archivePath.c_str()); + p.set_value(false); + return; + } + + AZ::IO::INestedArchive::Handle fileHandle = archive->FindFile(fileInArchive); + if (!fileHandle) + { + AZ_Error(s_traceName, false, "File '%s' does not exist inside archive '%s'", fileInArchive.c_str(), archivePath.c_str()); + p.set_value(false); + return; + } + + AZ::u64 fileSize = archive->GetFileSize(fileHandle); + AZStd::vector fileBuffer; + fileBuffer.resize_no_construct(fileSize); + + if (auto result = archive->ReadFile(fileHandle, fileBuffer.data()); result != AZ::IO::ZipDir::ZD_ERROR_SUCCESS) + { + AZ_Error( + s_traceName, false, "Failed to read file '%s' in archive '%s' with error %d", fileInArchive.c_str(), + archivePath.c_str(), result); + p.set_value(false); + return; + } + + AZ::IO::HandleType destFileHandle = AZ::IO::InvalidHandle; + AZ::IO::Path destinationFile{ destinationPath }; + destinationFile /= fileInArchive; + AZ::IO::OpenMode openMode = (AZ::IO::OpenMode::ModeCreatePath | AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeUpdate); + if (!m_fileIO->Open(destinationFile.c_str(), openMode, destFileHandle)) + { + AZ_Error(s_traceName, false, "Failed to open destination file '%s' for writing", destinationFile.c_str()); + p.set_value(false); + return; + } + + AZ::u64 bytesWritten = 0; + if (!m_fileIO->Write(destFileHandle, fileBuffer.data(), fileSize, &bytesWritten)) + { + AZ_Error(s_traceName, false, "Failed to write destination file '%s'", destinationFile.c_str()); + } + + m_fileIO->Close(destFileHandle); + p.set_value(bytesWritten == fileSize); + }; + + // Async task... + std::promise p; + std::future f = p.get_future(); + + AZStd::thread_desc threadDesc; + threadDesc.m_name = "Archive Task (Extract Single)"; + m_threads.emplace_back(threadDesc, FnExtractFile, AZStd::move(p)); + return f; + } + + + bool ArchiveComponent::ListFilesInArchive(const AZStd::string& archivePath, AZStd::vector& outFileEntries) + { + if (!m_fileIO || !m_archive) + { + return false; + } + + if (!m_fileIO->Exists(archivePath.c_str())) + { + AZ_Error(s_traceName, false, "Archive '%s' does not exist!", archivePath.c_str()); + return false; + } + + auto archive = m_archive->OpenArchive(archivePath, {}, AZ::IO::INestedArchive::FLAGS_READ_ONLY); + if (!archive) + { + AZ_Error(s_traceName, false, "Failed to open archive file '%s'", archivePath.c_str()); + return false; + } + + AZStd::vector fileEntries; + int result = archive->ListAllFiles(fileEntries); + outFileEntries.clear(); + for (const auto& path : fileEntries) + { + outFileEntries.emplace_back(path.String()); + } + return (result == AZ::IO::ZipDir::ZD_ERROR_SUCCESS); + } + + + std::future ArchiveComponent::AddFileToArchive( + const AZStd::string& archivePath, + const AZStd::string& workingDirectory, + const AZStd::string& fileToAdd) + { + if (!CheckParamsForAdd(workingDirectory, fileToAdd)) + { + std::promise p; + p.set_value(false); + return p.get_future(); + } + + auto FnAddFileToArchive = [this, archivePath, workingDirectory, fileToAdd](std::promise&& p) -> void + { + auto archive = m_archive->OpenArchive(archivePath); + if (!archive) + { + AZ_Error(s_traceName, false, "Failed to open archive file '%s'", archivePath.c_str()); + p.set_value(false); + return; + } + + AZ::IO::Path workingPath{ workingDirectory }; + AZ::IO::Path fullPath = workingPath / fileToAdd; + AZ::IO::PathView relativePath = AZ::IO::PathView{ fullPath }.LexicallyRelative(workingPath); + + AZStd::vector fileBuffer; + bool success = false; + if (ArchiveUtils::ReadFile(fullPath, AZ::IO::OpenMode::ModeRead, fileBuffer)) + { + int result = archive->UpdateFile( + relativePath.Native(), fileBuffer.data(), fileBuffer.size(), s_compressionMethod, + s_compressionLevel, s_compressionCodec); + + success = (result == AZ::IO::ZipDir::ZD_ERROR_SUCCESS); + AZ_Error( + s_traceName, success, "Error %d encountered while adding '%s' to archive '%.*s'", result, fileToAdd.c_str(), + AZ_STRING_ARG(archive->GetFullPath().Native())); } else { - AZ::TickBus::QueueFunction(respCallback, (exitCode == static_cast(SevenZipExitCode::NoError)), AZStd::move(consoleOutput)); + AZ_Error( + s_traceName, false, "Error encountered while reading '%s' to add to archive '%.*s'", fileToAdd.c_str(), + AZ_STRING_ARG(archive->GetFullPath().Native())); } - if (!taskHandle.IsNull()) - { - AZStd::unique_lock lock(m_threadControlMutex); - ThreadInfo& tInfo = m_threadInfoMap[taskHandle]; - tInfo.threads.erase(AZStd::this_thread::get_id()); - m_cv.notify_all(); - } + archive.reset(); + p.set_value(success); }; - if (!taskHandle.IsNull()) - { - AZStd::thread processThread(sevenZJob); - AZStd::unique_lock lock(m_threadControlMutex); - ThreadInfo& info = m_threadInfoMap[taskHandle]; - m_cv.wait(lock, [&info, &processThread]() { - return info.threads.find(processThread.get_id()) != info.threads.end(); - }); - processThread.detach(); - } - else - { - sevenZJob(); - } + + // Async task... + std::promise p; + std::future f = p.get_future(); + + AZStd::thread_desc threadDesc; + threadDesc.m_name = "Archive Task (Add Single)"; + m_threads.emplace_back(threadDesc, FnAddFileToArchive, AZStd::move(p)); + return f; } + + + std::future ArchiveComponent::AddFilesToArchive( + const AZStd::string& archivePath, + const AZStd::string& workingDirectory, + const AZStd::string& listFilePath) + { + if (!CheckParamsForAdd(workingDirectory, listFilePath)) + { + std::promise p; + p.set_value(false); + return p.get_future(); + } + + auto FnAddFilesToArchive = [this, archivePath, workingDirectory, listFilePath](std::promise&& p) -> void + { + auto archive = m_archive->OpenArchive(archivePath); + if (!archive) + { + AZ_Error(s_traceName, false, "Failed to open archive file '%s'", archivePath.c_str()); + p.set_value(false); + return; + } + + bool success = true; // starts true and turns false when any error is encountered. + AZ::IO::Path basePath{ workingDirectory }; + + auto PerLineCallback = [&success, &basePath, &archive](AZStd::string_view filePathLine) -> void + { + AZStd::vector fileBuffer; + AZ::IO::Path fullPath = (basePath / filePathLine); + if (ArchiveUtils::ReadFile(fullPath, AZ::IO::OpenMode::ModeRead, fileBuffer)) + { + int result = archive->UpdateFile( + filePathLine, fileBuffer.data(), fileBuffer.size(), s_compressionMethod, + s_compressionLevel, s_compressionCodec); + + bool thisSuccess = (result == AZ::IO::ZipDir::ZD_ERROR_SUCCESS); + success = (success && thisSuccess); + AZ_Error( + s_traceName, thisSuccess, "Error %d encountered while adding '%.*s' to archive '%.*s'", result, + AZ_STRING_ARG(filePathLine), AZ_STRING_ARG(archive->GetFullPath().Native())); + } + else + { + AZ_Error( + s_traceName, false, "Error encountered while reading '%.*s' to add to archive '%.*s'", AZ_STRING_ARG(filePathLine), + AZ_STRING_ARG(archive->GetFullPath().Native())); + } + }; + + ArchiveUtils::ProcessFileList(listFilePath, PerLineCallback); + + archive.reset(); + p.set_value(success); + }; + + // Async task... + std::promise p; + std::future f = p.get_future(); + + AZStd::thread_desc threadDesc; + threadDesc.m_name = "Archive Task (Add)"; + m_threads.emplace_back(threadDesc, FnAddFilesToArchive, AZStd::move(p)); + return f; + } + + + bool ArchiveComponent::CheckParamsForAdd(const AZStd::string& directory, const AZStd::string& file) + { + if (!m_fileIO || !m_archive) + { + return false; + } + + if (!m_fileIO->IsDirectory(directory.c_str())) + { + AZ_Error( + s_traceName, false, "Working directory '%s' is not a directory or doesn't exist!", directory.c_str()); + return false; + } + + if (!file.empty()) + { + auto filePath = AZ::IO::Path{ directory } / file; + if (!m_fileIO->Exists(filePath.c_str()) || m_fileIO->IsDirectory(filePath.c_str())) + { + AZ_Error(s_traceName, false, "File list '%s' is a directory or doesn't exist!", filePath.c_str()); + return false; + } + } + + return true; + } + + bool ArchiveComponent::CheckParamsForExtract(const AZStd::string& archive, const AZStd::string& directory) + { + if (!m_fileIO || !m_archive) + { + return false; + } + + if (!m_fileIO->Exists(archive.c_str())) + { + AZ_Error(s_traceName, false, "Archive '%s' does not exist!", archive.c_str()); + return false; + } + + if (!m_fileIO->Exists(directory.c_str())) + { + if (!m_fileIO->CreatePath(directory.c_str())) + { + AZ_Error(s_traceName, false, "Failed to create destination directory '%s'", directory.c_str()); + return false; + } + } + + return true; + } + + bool ArchiveComponent::CheckParamsForCreate(const AZStd::string& archive, const AZStd::string& directory) + { + if (!m_fileIO || !m_archive) + { + return false; + } + + if (m_fileIO->Exists(archive.c_str())) + { + AZ_Error(s_traceName, false, "Archive file '%s' already exists, cannot create a new archive there!"); + return false; + } + + if (!m_fileIO->IsDirectory(directory.c_str())) + { + AZ_Error(s_traceName, false, "Directory '%s' is not a directory or doesn't exist!", directory.c_str()); + return false; + } + + return true; + } + } // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/ArchiveComponent.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/ArchiveComponent.h index fc344fc5a6..e2b437bcf2 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/ArchiveComponent.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/ArchiveComponent.h @@ -10,80 +10,76 @@ #include #include +#include #include #include #include #include +#include #include namespace AzToolsFramework { - enum class SevenZipExitCode : AZ::u32 - { - NoError = 0, - Warning = 1, - FatalError = 2, - CommandLineError = 7, - NotEnoughMemory = 8, - UserStoppedProcess = 255 - }; - - // the ArchiveComponent's job is to execute zip commands. - // it parses the status of zip commands and returns results. + // the ArchiveComponent's job is to create and manipulate zip archives. class ArchiveComponent : public AZ::Component - , private ArchiveCommands::Bus::Handler + , private ArchiveCommandsBus::Handler { public: - AZ_COMPONENT(ArchiveComponent, "{A19EEA33-3736-447F-ACF7-DAA4B6A179AA}") + AZ_COMPONENT(ArchiveComponent, "{A19EEA33-3736-447F-ACF7-DAA4B6A179AA}"); ArchiveComponent() = default; ~ArchiveComponent() override = default; + ArchiveComponent(const ArchiveComponent&) = delete; + ArchiveComponent& operator=(const ArchiveComponent&) = delete; + ////////////////////////////////////////////////////////////////////////// // AZ::Component overrides void Activate() override; void Deactivate() override; ////////////////////////////////////////////////////////////////////////// - private: + + protected: static void Reflect(AZ::ReflectContext* context); ////////////////////////////////////////////////////////////////////////// - // ArchiveCommands::Bus::Handler overrides - void CreateArchive(const AZStd::string& archivePath, const AZStd::string& dirToArchive, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) override; - bool CreateArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& dirToArchive) override; - bool ExtractArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& destinationPath, bool extractWithRootDirectory) override; - void ExtractArchive(const AZStd::string& archivePath, const AZStd::string& destinationPath, AZ::Uuid taskHandle, const ArchiveResponseCallback& respCallback) override; - void ExtractArchiveOutput(const AZStd::string& archivePath, const AZStd::string& destinationPath, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) override; - void ExtractArchiveWithoutRoot(const AZStd::string& archivePath, const AZStd::string& destinationPath, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) override; - void ExtractFile(const AZStd::string& archivePath, const AZStd::string& fileInArchive, const AZStd::string& destinationPath, bool overWrite, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) override; - bool ExtractFileBlocking(const AZStd::string& archivePath, const AZStd::string& fileInArchive, const AZStd::string& destinationPath, bool overWrite) override; - void ListFilesInArchive(const AZStd::string& archivePath, AZStd::vector& fileEntries, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) override; - bool ListFilesInArchiveBlocking(const AZStd::string& archivePath, AZStd::vector& fileEntries) override; - void AddFileToArchive(const AZStd::string& archivePath, const AZStd::string& workingDirectory, const AZStd::string& fileToAdd, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) override; - bool AddFileToArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& workingDirectory, const AZStd::string& fileToAdd) override; - bool AddFilesToArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& workingDirectory, const AZStd::string& listFilePath) override; - void AddFilesToArchive(const AZStd::string& archivePath, const AZStd::string& workingDirectory, const AZStd::string& listFilePath, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) override; - void CancelTasks(AZ::Uuid taskHandle) override; + // ArchiveCommandsBus::Handler overrides + [[nodiscard]] std::future CreateArchive( + const AZStd::string& archivePath, + const AZStd::string& dirToArchive) override; + + [[nodiscard]] std::future ExtractArchive( + const AZStd::string& archivePath, + const AZStd::string& destinationPath) override; + + [[nodiscard]] std::future ExtractFile( + const AZStd::string& archivePath, + const AZStd::string& fileInArchive, + const AZStd::string& destinationPath) override; + + bool ListFilesInArchive(const AZStd::string& archivePath, AZStd::vector& outFileEntries) override; + + [[nodiscard]] std::future AddFileToArchive( + const AZStd::string& archivePath, + const AZStd::string& workingDirectory, + const AZStd::string& fileToAdd) override; + + [[nodiscard]] std::future AddFilesToArchive( + const AZStd::string& archivePath, + const AZStd::string& workingDirectory, + const AZStd::string& listFilePath) override; ////////////////////////////////////////////////////////////////////////// - - // Launches the input zip exe as a background child process in a detached background thread, if the task handle is not null - // otherwise launches input zip exe in the calling thread. - void LaunchZipExe(const AZStd::string& exePath, const AZStd::string& commandLineArgs, const ArchiveResponseOutputCallback& respCallback, AZ::Uuid taskHandle = AZ::Uuid::CreateNull(), const AZStd::string& workingDir = "", bool captureOutput = false); - AZStd::string m_zipExePath; - AZStd::string m_unzipExePath; + private: + AZ::IO::FileIOBase* m_fileIO = nullptr; + AZ::IO::IArchive* m_archive = nullptr; + AZStd::vector m_threads; - // Struct for tracking background threads/tasks - struct ThreadInfo - { - bool shouldStop = false; - AZStd::set threads; - }; - - AZStd::mutex m_threadControlMutex; // Guards m_threadInfoMap - AZStd::condition_variable m_cv; - AZStd::unordered_map m_threadInfoMap; + bool CheckParamsForAdd(const AZStd::string& directory, const AZStd::string& file); + bool CheckParamsForExtract(const AZStd::string& archive, const AZStd::string& directory); + bool CheckParamsForCreate(const AZStd::string& archive, const AZStd::string& directory); }; + } // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/NullArchiveComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/NullArchiveComponent.cpp index f82724a721..972e9d588f 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/NullArchiveComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/NullArchiveComponent.cpp @@ -16,91 +16,62 @@ namespace AzToolsFramework void NullArchiveComponent::Activate() { - ArchiveCommands::Bus::Handler::BusConnect(); + ArchiveCommandsBus::Handler::BusConnect(); } void NullArchiveComponent::Deactivate() { - ArchiveCommands::Bus::Handler::BusDisconnect(); + ArchiveCommandsBus::Handler::BusDisconnect(); } - bool NullArchiveComponent::ExtractArchiveBlocking(const AZStd::string& /*archivePath*/, const AZStd::string& /*destinationPath*/, bool /*extractWithRootDirectory*/) + std::future DefaultFuture() + { + std::promise p; + p.set_value(false); + return p.get_future(); + } + + std::future NullArchiveComponent::CreateArchive( + const AZStd::string& /*archivePath*/, + const AZStd::string& /*dirToArchive*/) + { + return DefaultFuture(); + } + + std::future NullArchiveComponent::ExtractArchive( + const AZStd::string& /*archivePath*/, + const AZStd::string& /*destinationPath*/) + { + return DefaultFuture(); + } + + std::future NullArchiveComponent::ExtractFile( + const AZStd::string& /*archivePath*/, + const AZStd::string& /*fileInArchive*/, + const AZStd::string& /*destinationPath*/) + { + return DefaultFuture(); + } + + bool NullArchiveComponent::ListFilesInArchive(const AZStd::string& /*archivePath*/, AZStd::vector& /*outFileEntries*/) { return false; } - void NullArchiveComponent::ExtractArchive(const AZStd::string& /*archivePath*/, const AZStd::string& /*destinationPath*/, AZ::Uuid /*taskHandle*/, const ArchiveResponseCallback& respCallback) + std::future NullArchiveComponent::AddFileToArchive( + const AZStd::string& /*archivePath*/, + const AZStd::string& /*fileToAdd*/, + const AZStd::string& /*pathInArchive*/) { - AZ::TickBus::QueueFunction(respCallback, false); + return DefaultFuture(); } - void NullArchiveComponent::ExtractArchiveOutput(const AZStd::string& /*archivePath*/, const AZStd::string& /*destinationPath*/, AZ::Uuid /*taskHandle*/, const ArchiveResponseOutputCallback& respCallback) - { - AZ::TickBus::QueueFunction(respCallback, false, AZStd::string()); - } - - void NullArchiveComponent::ExtractArchiveWithoutRoot(const AZStd::string& /*archivePath*/, const AZStd::string& /*destinationPath*/, AZ::Uuid /*taskHandle*/, const ArchiveResponseOutputCallback& respCallback) - { - AZ::TickBus::QueueFunction(respCallback, false, AZStd::string()); - } - - void NullArchiveComponent::ExtractFile(const AZStd::string& /*archivePath*/, const AZStd::string& /*fileInArchive*/, const AZStd::string& /*destinationPath*/, bool /*overWrite*/, AZ::Uuid /*taskHandle*/, const ArchiveResponseOutputCallback& respCallback) - { - // Always report we failed to extract - AZ::TickBus::QueueFunction(respCallback, false, AZStd::string()); - } - - bool NullArchiveComponent::ExtractFileBlocking(const AZStd::string& /*archivePath*/, const AZStd::string& /*fileInArchive*/, const AZStd::string& /*destinationPath*/, bool /*overWrite*/) - { - return false; - } - - void NullArchiveComponent::ListFilesInArchive(const AZStd::string& /*archivePath*/, AZStd::vector& /*consoleOutput*/, AZ::Uuid /*taskHandle*/, const ArchiveResponseOutputCallback& respCallback) - { - // Always report we failed to extract - AZ::TickBus::QueueFunction(respCallback, false, AZStd::string()); - } - - bool NullArchiveComponent::ListFilesInArchiveBlocking(const AZStd::string& /*archivePath*/, AZStd::vector& /*consoleOutput*/) - { - return false; - } - - void NullArchiveComponent::AddFileToArchive(const AZStd::string& /*archivePath*/, const AZStd::string& /*fileToAdd*/, const AZStd::string& /*pathInArchive*/, AZ::Uuid /*taskHandle*/, const ArchiveResponseOutputCallback& respCallback) - { - // Always report we failed to extract - AZ::TickBus::QueueFunction(respCallback, false, AZStd::string()); - } - - bool NullArchiveComponent::AddFileToArchiveBlocking(const AZStd::string& /*archivePath*/, const AZStd::string& /*fileToAdd*/, const AZStd::string& /*pathInArchive*/) - { - return false; - } - - bool NullArchiveComponent::AddFilesToArchiveBlocking(const AZStd::string& /*archivePath*/, const AZStd::string& /*workingDirectory*/, const AZStd::string& /*listFilePath*/) - { - return false; - } - - void NullArchiveComponent::AddFilesToArchive(const AZStd::string& /*archivePath*/, const AZStd::string& /*workingDirectory*/, const AZStd::string& /*listFilePath*/, AZ::Uuid /*taskHandle*/, const ArchiveResponseOutputCallback& respCallback) - { - // Always report we failed to extract - AZ::TickBus::QueueFunction(respCallback, false, AZStd::string()); - } - - void NullArchiveComponent::CreateArchive(const AZStd::string& /*archivePath*/, const AZStd::string& /*dirToArchive*/, AZ::Uuid /*taskHandle*/, const ArchiveResponseOutputCallback& respCallback) - { - // Always report we failed to extract - AZ::TickBus::QueueFunction(respCallback, false, AZStd::string()); - } - - bool NullArchiveComponent::CreateArchiveBlocking(const AZStd::string& /*archivePath*/, const AZStd::string& /*dirToArchive*/) - { - return false; - } - - void NullArchiveComponent::CancelTasks(AZ::Uuid /*taskHandle*/) + std::future NullArchiveComponent::AddFilesToArchive( + const AZStd::string& /*archivePath*/, + const AZStd::string& /*workingDirectory*/, + const AZStd::string& /*listFilePath*/) { + return DefaultFuture(); } void NullArchiveComponent::Reflect(AZ::ReflectContext* context) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/NullArchiveComponent.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/NullArchiveComponent.h index 2023490351..9ce33d0c85 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/NullArchiveComponent.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Archive/NullArchiveComponent.h @@ -15,7 +15,7 @@ namespace AzToolsFramework { class NullArchiveComponent : public AZ::Component - , private ArchiveCommands::Bus::Handler + , private ArchiveCommandsBus::Handler { public: AZ_COMPONENT(NullArchiveComponent, "{D665B6B1-5FF4-4203-B19F-BBDB82587129}") @@ -32,23 +32,31 @@ namespace AzToolsFramework static void Reflect(AZ::ReflectContext* context); ////////////////////////////////////////////////////////////////////////// - // ArchiveCommands::Bus::Handler overrides - // ArchiveCommands::Bus::Handler overrides - void CreateArchive(const AZStd::string& archivePath, const AZStd::string& dirToArchive, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) override; - bool CreateArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& dirToArchive) override; - bool ExtractArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& destinationPath, bool extractWithRootDirectory) override; - void ExtractArchive(const AZStd::string& archivePath, const AZStd::string& destinationPath, AZ::Uuid taskHandle, const ArchiveResponseCallback& respCallback) override; - void ExtractArchiveOutput(const AZStd::string& archivePath, const AZStd::string& destinationPath, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) override; - void ExtractArchiveWithoutRoot(const AZStd::string& archivePath, const AZStd::string& destinationPath, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) override; - void ExtractFile(const AZStd::string& archivePath, const AZStd::string& fileInArchive, const AZStd::string& destinationPath, bool overWrite, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) override; - bool ExtractFileBlocking(const AZStd::string& archivePath, const AZStd::string& fileInArchive, const AZStd::string& destinationPath, bool overWrite) override; - void ListFilesInArchive(const AZStd::string& archivePath, AZStd::vector& consoleOutput, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) override; - bool ListFilesInArchiveBlocking(const AZStd::string& archivePath, AZStd::vector& consoleOutput) override; - void AddFileToArchive(const AZStd::string& archivePath, const AZStd::string& fileToAdd, const AZStd::string& pathInArchive, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) override; - bool AddFileToArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& fileToAdd, const AZStd::string& pathInArchive) override; - bool AddFilesToArchiveBlocking(const AZStd::string& archivePath, const AZStd::string& workingDirectory, const AZStd::string& listFilePath) override; - void AddFilesToArchive(const AZStd::string& archivePath, const AZStd::string& workingDirectory, const AZStd::string& listFilePath, AZ::Uuid taskHandle, const ArchiveResponseOutputCallback& respCallback) override; - void CancelTasks(AZ::Uuid taskHandle) override; + // ArchiveCommandsBus::Handler overrides + [[nodiscard]] std::future CreateArchive( + const AZStd::string& archivePath, + const AZStd::string& dirToArchive) override; + + [[nodiscard]] std::future ExtractArchive( + const AZStd::string& archivePath, + const AZStd::string& destinationPath) override; + + [[nodiscard]] std::future ExtractFile( + const AZStd::string& archivePath, + const AZStd::string& fileInArchive, + const AZStd::string& destinationPath) override; + + bool ListFilesInArchive(const AZStd::string& archivePath, AZStd::vector& outFileEntries) override; + + [[nodiscard]] std::future AddFileToArchive( + const AZStd::string& archivePath, + const AZStd::string& workingDirectory, + const AZStd::string& fileToAdd) override; + + [[nodiscard]] std::future AddFilesToArchive( + const AZStd::string& archivePath, + const AZStd::string& workingDirectory, + const AZStd::string& listFilePath) override; ////////////////////////////////////////////////////////////////////////// }; } // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/AssetBrowserFilterModel.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/AssetBrowserFilterModel.cpp index c6772ea2d7..acf935e6dc 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/AssetBrowserFilterModel.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/AssetBrowserFilterModel.cpp @@ -20,7 +20,7 @@ AZ_PUSH_DISABLE_WARNING(4251, "-Wunknown-warning-option") AZ_POP_DISABLE_WARNING AZ_CVAR( - bool, ed_useNewAssetBrowserTableView, true, nullptr, AZ::ConsoleFunctorFlags::Null, + bool, ed_useNewAssetBrowserTableView, false, nullptr, AZ::ConsoleFunctorFlags::Null, "Use the new AssetBrowser TableView for searching assets."); namespace AzToolsFramework { diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Views/EntryDelegate.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Views/EntryDelegate.cpp index 755c59b55b..b463381638 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Views/EntryDelegate.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/Views/EntryDelegate.cpp @@ -290,7 +290,7 @@ namespace AzToolsFramework absoluteIconPath = AZ::IO::FixedMaxPath(AZ::Utils::GetEnginePath()) / TreeIconPathOneChild; break; } - bool pixmapLoadedSuccess = pixmap.load(absoluteIconPath.c_str()); + [[maybe_unused]] bool pixmapLoadedSuccess = pixmap.load(absoluteIconPath.c_str()); AZ_Assert(pixmapLoadedSuccess, "Error loading Branch Icons in SearchEntryDelegate"); m_branchIcons[static_cast(branchType)] = pixmap; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBundle/AssetBundleComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBundle/AssetBundleComponent.cpp index 7083737cf7..8924907e81 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBundle/AssetBundleComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBundle/AssetBundleComponent.cpp @@ -32,12 +32,10 @@ namespace AzToolsFramework const int NumOfBytesInMB = 1024 * 1024; const int ManifestFileSizeBufferInBytes = 10 * 1024; // 10 KB const float AssetCatalogFileSizeBufferPercentage = 1.0f; - using ArchiveCommandsBus = AzToolsFramework::ArchiveCommands::Bus; using AssetCatalogRequestBus = AZ::Data::AssetCatalogRequestBus; const char AssetBundleComponent::DeltaCatalogName[] = "DeltaCatalog.xml"; - constexpr int SleepTimeMS = 250; constexpr int InjectFileRetryCount = 4; @@ -136,7 +134,7 @@ namespace AzToolsFramework AZ_TracePrintf(logWindowName, "Gathering file entries in source pak file \"%s\".\n", sourcePak.c_str()); bool result = false; AZStd::vector fileEntries; - ArchiveCommandsBus::BroadcastResult(result, &AzToolsFramework::ArchiveCommands::ListFilesInArchiveBlocking, normalizedSourcePakPath, fileEntries); + ArchiveCommandsBus::BroadcastResult(result, &AzToolsFramework::ArchiveCommandsBus::Events::ListFilesInArchive, normalizedSourcePakPath, fileEntries); // This ebus currently always returns false as the result, as it is believed that the 7z process is // being terminated by the user instead of ending gracefully. Check against an empty fileList instead // as a result. @@ -606,15 +604,17 @@ namespace AzToolsFramework { AZ_TracePrintf(logWindowName, "Injecting file (%s) into bundle (%s).\n", filePath.c_str(), archiveFilePath.c_str()); bool fileAddedToArchive = false; + std::future fileAdded; int retryCount = InjectFileRetryCount; + while (!fileAddedToArchive && retryCount) { - ArchiveCommandsBus::BroadcastResult(fileAddedToArchive, &AzToolsFramework::ArchiveCommands::AddFileToArchiveBlocking, archiveFilePath, workingDirectory, filePath); + ArchiveCommandsBus::BroadcastResult(fileAdded, &AzToolsFramework::ArchiveCommandsBus::Events::AddFileToArchive, archiveFilePath, workingDirectory, filePath); --retryCount; + fileAddedToArchive = fileAdded.get(); if (!fileAddedToArchive && retryCount) { AZ_Error(logWindowName, false, "Failed to insert file (%s) into bundle (%s). Retrying.", filePath.c_str(), archiveFilePath.c_str()); - AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(SleepTimeMS)); } } @@ -627,7 +627,11 @@ namespace AzToolsFramework bool AssetBundleComponent::InjectFile(const AZStd::string& filePath, const AZStd::string& sourcePak) { - return InjectFile(filePath, sourcePak, ""); + // When no working directory is specified, assume that the file being injected goes into the root of the archive. + // The filePath should be an absolute path, making the workingDirectory be the path leading up to the file. + AZ::IO::PathView fullFilePath{ filePath, AZ::IO::PosixPathSeparator }; + AZ::IO::Path workingDir{ fullFilePath.ParentPath() }; + return InjectFile(filePath, sourcePak, workingDir.c_str()); } bool AssetBundleComponent::InjectFiles(const AZStd::vector& fileEntries, const AZStd::string& sourcePak, const char* workingDirectory) @@ -668,8 +672,9 @@ namespace AzToolsFramework } } - bool filesAddedToArchive = false; - AzToolsFramework::ArchiveCommandsBus::BroadcastResult(filesAddedToArchive, &AzToolsFramework::ArchiveCommands::AddFilesToArchiveBlocking, sourcePak, workingDirectory, listFilePath); + std::future filesAdded; + AzToolsFramework::ArchiveCommandsBus::BroadcastResult(filesAdded, &AzToolsFramework::ArchiveCommands::AddFilesToArchive, sourcePak, workingDirectory, listFilePath); + bool filesAddedToArchive = filesAdded.get(); if (!filesAddedToArchive) { AZ_Error(logWindowName, false, "Failed to insert files into bundle (%s).\n", sourcePak.c_str()); @@ -688,7 +693,6 @@ namespace AzToolsFramework { // open the manifest and deserialize it bool manifestExtracted = false; - const bool overwriteExisting = true; TemporaryDir tempDir(sourcePak); if (!tempDir.m_result) @@ -698,7 +702,10 @@ namespace AzToolsFramework AZStd::string manifestFilePath; AzFramework::StringFunc::Path::ConstructFull(tempDir.m_tempFolderPath.c_str(), AzFramework::AssetBundleManifest::s_manifestFileName, manifestFilePath, true); - ArchiveCommandsBus::BroadcastResult(manifestExtracted, &ArchiveCommandsBus::Events::ExtractFileBlocking, sourcePak, AzFramework::AssetBundleManifest::s_manifestFileName, tempDir.m_tempFolderPath, overwriteExisting); + + std::future extractResult; + ArchiveCommandsBus::BroadcastResult(extractResult, &ArchiveCommandsBus::Events::ExtractFile, sourcePak, AzFramework::AssetBundleManifest::s_manifestFileName, tempDir.m_tempFolderPath); + manifestExtracted = extractResult.get(); if (!manifestExtracted) { AZ_Error(logWindowName, false, "Failed to extract existing manifest from archive \"%s\".", sourcePak.c_str()); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBundle/AssetBundleComponent.h b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBundle/AssetBundleComponent.h index 307777cc1b..17a9dd40f5 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBundle/AssetBundleComponent.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBundle/AssetBundleComponent.h @@ -57,7 +57,7 @@ namespace AzToolsFramework //! Returns true if the file at filePath was successfully injected into the bundle at sourcePak static bool InjectFile(const AZStd::string& filePath, const AZStd::string& sourcePak, const char* workingDirectory); - //! Inject the files with relative filePaths which espect to the working directory into the bundle at sourcePak + //! Inject the files with relative filePaths with respect to the working directory into the bundle at sourcePak //! Returns true if the file at filePath was successfully injected into the bundle at sourcePak static bool InjectFiles(const AZStd::vector& fileEntries, const AZStd::string& sourcePak, const char* workingDirectory); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp index e5daf2674d..7db507e751 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp @@ -18,8 +18,9 @@ #include #include #include -#include #include +#include +#include #include #include #include @@ -317,17 +318,18 @@ namespace AzToolsFramework const AZStd::vector& entities, AZStd::vector>&& nestedPrefabInstances, AZ::IO::PathView filePath, Prefab::InstanceOptionalReference instanceToParentUnder) { - AZStd::unique_ptr createdPrefabInstance = - m_prefabSystemComponent->CreatePrefab(entities, AZStd::move(nestedPrefabInstances), filePath, nullptr, false); + if (!instanceToParentUnder) + { + instanceToParentUnder = *m_rootInstance; + } + + AZStd::unique_ptr createdPrefabInstance = m_prefabSystemComponent->CreatePrefab( + entities, AZStd::move(nestedPrefabInstances), filePath, nullptr, instanceToParentUnder, false); if (createdPrefabInstance) { - if (!instanceToParentUnder) - { - instanceToParentUnder = *m_rootInstance; - } - - Prefab::Instance& addedInstance = instanceToParentUnder->get().AddInstance(AZStd::move(createdPrefabInstance)); + Prefab::Instance& addedInstance = instanceToParentUnder->get().AddInstance( + AZStd::move(createdPrefabInstance)); AZ::Entity* containerEntity = addedInstance.m_containerEntity.get(); containerEntity->AddComponent(aznew Prefab::EditorPrefabComponent()); HandleEntitiesAdded({containerEntity}); @@ -341,16 +343,18 @@ namespace AzToolsFramework Prefab::InstanceOptionalReference PrefabEditorEntityOwnershipService::InstantiatePrefab( AZ::IO::PathView filePath, Prefab::InstanceOptionalReference instanceToParentUnder) { - AZStd::unique_ptr createdPrefabInstance = m_prefabSystemComponent->InstantiatePrefab(filePath); - - if (createdPrefabInstance) + if (!instanceToParentUnder) { - if (!instanceToParentUnder) - { - instanceToParentUnder = *m_rootInstance; - } + instanceToParentUnder = *m_rootInstance; + } - Prefab::Instance& addedInstance = instanceToParentUnder->get().AddInstance(AZStd::move(createdPrefabInstance)); + AZStd::unique_ptr instantiatedPrefabInstance = + m_prefabSystemComponent->InstantiatePrefab(filePath, instanceToParentUnder); + + if (instantiatedPrefabInstance) + { + Prefab::Instance& addedInstance = instanceToParentUnder->get().AddInstance( + AZStd::move(instantiatedPrefabInstance)); HandleEntitiesAdded({addedInstance.m_containerEntity.get()}); return addedInstance; } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/FocusMode/FocusModeSystemComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/FocusMode/FocusModeSystemComponent.cpp index d1c4d37821..ceb516d86f 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/FocusMode/FocusModeSystemComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/FocusMode/FocusModeSystemComponent.cpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace AzToolsFramework { @@ -73,7 +74,18 @@ namespace AzToolsFramework m_focusRoot = entityId; FocusModeNotificationBus::Broadcast(&FocusModeNotifications::OnEditorFocusChanged, m_focusRoot); - // TODO - If m_focusRoot != AZ::EntityId(), activate focus mode via ViewportEditorModeTrackerInterface; else, deactivate focus mode + if (auto tracker = AZ::Interface::Get(); + tracker != nullptr) + { + if (!m_focusRoot.IsValid() && entityId.IsValid()) + { + tracker->ActivateMode({ /* DefaultViewportId */ }, ViewportEditorMode::Focus); + } + else if (m_focusRoot.IsValid() && !entityId.IsValid()) + { + tracker->DeactivateMode({ /* DefaultViewportId */ }, ViewportEditorMode::Focus); + } + } } void FocusModeSystemComponent::ClearFocusRoot([[maybe_unused]] AzFramework::EntityContextId entityContextId) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp index 54e7f7608c..b5db46d0db 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -28,24 +29,52 @@ namespace AzToolsFramework } Instance::Instance(AZStd::unique_ptr containerEntity) + : Instance(AZStd::move(containerEntity), AZStd::nullopt, GenerateInstanceAlias()) { - m_instanceEntityMapper = AZ::Interface::Get(); + } + Instance::Instance(InstanceOptionalReference parent) + : Instance(nullptr, parent, GenerateInstanceAlias()) + { + } + + Instance::Instance(InstanceAlias alias) + : Instance(nullptr, AZStd::nullopt, AZStd::move(alias)) + { + } + + Instance::Instance(AZStd::unique_ptr containerEntity, InstanceOptionalReference parent) + : Instance(AZStd::move(containerEntity), parent, GenerateInstanceAlias()) + { + } + + Instance::Instance(AZStd::unique_ptr containerEntity, InstanceOptionalReference parent, InstanceAlias alias) + : m_parent(parent.has_value() ? &parent->get() : nullptr) + , m_alias(AZStd::move(alias)) + , m_containerEntity(containerEntity ? AZStd::move(containerEntity) : AZStd::make_unique()) + , m_instanceEntityMapper(AZ::Interface::Get()) + , m_templateInstanceMapper(AZ::Interface::Get()) + { AZ_Assert(m_instanceEntityMapper, "Instance Entity Mapper Interface could not be found. " "It is a requirement for the Prefab Instance class. " "Check that it is being correctly initialized."); - m_templateInstanceMapper = AZ::Interface::Get(); - AZ_Assert(m_templateInstanceMapper, "Template Instance Mapper Interface could not be found. " "It is a requirement for the Prefab Instance class. " "Check that it is being correctly initialized."); - m_alias = GenerateInstanceAlias(); - m_containerEntity = containerEntity ? AZStd::move(containerEntity) - : AZStd::make_unique(); + if (parent) + { + AliasPath absoluteInstancePath = m_parent->GetAbsoluteInstanceAliasPath(); + absoluteInstancePath.Append(m_alias); + absoluteInstancePath.Append(PrefabDomUtils::ContainerEntityName); + + AZ::EntityId newContainerEntityId = InstanceEntityIdMapper::GenerateEntityIdForAliasPath(absoluteInstancePath); + m_containerEntity->SetId(newContainerEntityId); + } + RegisterEntity(m_containerEntity->GetId(), PrefabDomUtils::ContainerEntityName); } @@ -69,12 +98,12 @@ namespace AzToolsFramework } } - const TemplateId& Instance::GetTemplateId() const + TemplateId Instance::GetTemplateId() const { return m_templateId; } - void Instance::SetTemplateId(const TemplateId& templateId) + void Instance::SetTemplateId(TemplateId templateId) { // If we aren't changing the template Id, there's no need to unregister / re-register if (templateId == m_templateId) @@ -295,20 +324,21 @@ namespace AzToolsFramework } Instance& Instance::AddInstance(AZStd::unique_ptr instance) - { - InstanceAlias newInstanceAlias = GenerateInstanceAlias(); - return AddInstance(AZStd::move(instance), newInstanceAlias); - } - - Instance& Instance::AddInstance(AZStd::unique_ptr instance, InstanceAlias newInstanceAlias) { AZ_Assert(instance.get(), "instance argument is nullptr"); + + if (instance->GetInstanceAlias().empty()) + { + instance->m_alias = GenerateInstanceAlias(); + } + AZ_Assert( - m_nestedInstances.find(newInstanceAlias) == m_nestedInstances.end(), + m_nestedInstances.find(instance->GetInstanceAlias()) == m_nestedInstances.end(), "InstanceAlias' unique id collision, this should never happen."); + instance->m_parent = this; - instance->m_alias = newInstanceAlias; - return *(m_nestedInstances[newInstanceAlias] = std::move(instance)); + auto& alias = instance->GetInstanceAlias(); + return *(m_nestedInstances[alias] = AZStd::move(instance)); } void Instance::DetachNestedInstances(const AZStd::function)>& callback) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.h index 39d364b4bb..50a39268fe 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/Instance.h @@ -65,6 +65,9 @@ namespace AzToolsFramework Instance(); explicit Instance(AZStd::unique_ptr containerEntity); + explicit Instance(InstanceOptionalReference parent); + explicit Instance(AZStd::unique_ptr containerEntity, InstanceOptionalReference parent); + explicit Instance(InstanceAlias alias); virtual ~Instance(); Instance(const Instance& rhs) = delete; @@ -72,8 +75,8 @@ namespace AzToolsFramework static void Reflect(AZ::ReflectContext* context); - const TemplateId& GetTemplateId() const; - void SetTemplateId(const TemplateId& templateId); + TemplateId GetTemplateId() const; + void SetTemplateId(TemplateId templateId); const AZ::IO::Path& GetTemplateSourcePath() const; void SetTemplateSourcePath(AZ::IO::PathView sourcePath); @@ -97,7 +100,6 @@ namespace AzToolsFramework void Reset(); Instance& AddInstance(AZStd::unique_ptr instance); - Instance& AddInstance(AZStd::unique_ptr instance, InstanceAlias instanceAlias); AZStd::unique_ptr DetachNestedInstance(const InstanceAlias& instanceAlias); void DetachNestedInstances(const AZStd::function)>& callback); @@ -184,6 +186,8 @@ namespace AzToolsFramework private: static constexpr const char s_aliasPathSeparator = '/'; + Instance(AZStd::unique_ptr containerEntity, InstanceOptionalReference parent, InstanceAlias alias); + void ClearEntities(); void RemoveEntities(const AZStd::function&)>& filter); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceToTemplateInterface.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceToTemplateInterface.h index b944ef159a..a8c717d6b0 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceToTemplateInterface.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceToTemplateInterface.h @@ -46,10 +46,11 @@ namespace AzToolsFramework //! Updates the template links (updating instances) for the given template and triggers propagation on its instances. //! @param providedPatch The patch to apply to the template. //! @param templateId The id of the template to update. + //! @param immediate An optional flag whether to apply the patch immediately (needed for Undo/Redos) or wait until next system tick. //! @param instanceToExclude An optional reference to an instance of the template being updated that should not be refreshes as part of propagation. //! Defaults to nullopt, which means that all instances will be refreshed. //! @return True if the template was patched correctly, false if the operation failed. - virtual bool PatchTemplate(PrefabDomValue& providedPatch, TemplateId templateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt) = 0; + virtual bool PatchTemplate(PrefabDomValue& providedPatch, TemplateId templateId, bool immediate = false, InstanceOptionalReference instanceToExclude = AZStd::nullopt) = 0; virtual void ApplyPatchesToInstance(const AZ::EntityId& entityId, PrefabDom& patches, const Instance& instanceToAddPatches) = 0; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceToTemplatePropagator.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceToTemplatePropagator.cpp index 6b281bcbae..73acb9b8a4 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceToTemplatePropagator.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceToTemplatePropagator.cpp @@ -156,7 +156,7 @@ namespace AzToolsFramework } } - bool InstanceToTemplatePropagator::PatchTemplate(PrefabDomValue& providedPatch, TemplateId templateId, InstanceOptionalReference instanceToExclude) + bool InstanceToTemplatePropagator::PatchTemplate(PrefabDomValue& providedPatch, TemplateId templateId, bool immediate, InstanceOptionalReference instanceToExclude) { PrefabDom& templateDomReference = m_prefabSystemComponentInterface->FindTemplateDom(templateId); @@ -178,7 +178,7 @@ namespace AzToolsFramework (result.GetOutcome() != AZ::JsonSerializationResult::Outcomes::PartialSkip), "Some of the patches were not successfully applied."); m_prefabSystemComponentInterface->SetTemplateDirtyFlag(templateId, true); - m_prefabSystemComponentInterface->PropagateTemplateChanges(templateId, instanceToExclude); + m_prefabSystemComponentInterface->PropagateTemplateChanges(templateId, immediate, instanceToExclude); return true; } } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceToTemplatePropagator.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceToTemplatePropagator.h index 75acb410c9..80fe7de8d5 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceToTemplatePropagator.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceToTemplatePropagator.h @@ -33,7 +33,7 @@ namespace AzToolsFramework InstanceOptionalReference GetTopMostInstanceInHierarchy(AZ::EntityId entityId) override; - bool PatchTemplate(PrefabDomValue& providedPatch, TemplateId templateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt) override; + bool PatchTemplate(PrefabDomValue& providedPatch, TemplateId templateId, bool immediate = false, InstanceOptionalReference instanceToExclude = AZStd::nullopt) override; void ApplyPatchesToInstance(const AZ::EntityId& entityId, PrefabDom& patches, const Instance& instanceToAddPatches) override; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp index 9ef74167a6..feea3ce25b 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.cpp @@ -52,7 +52,7 @@ namespace AzToolsFramework AZ::Interface::Unregister(this); } - void InstanceUpdateExecutor::AddTemplateInstancesToQueue(TemplateId instanceTemplateId, InstanceOptionalReference instanceToExclude) + void InstanceUpdateExecutor::AddTemplateInstancesToQueue(TemplateId instanceTemplateId, bool immediate, InstanceOptionalReference instanceToExclude) { auto findInstancesResult = m_templateInstanceMapperInterface->FindInstancesOwnedByTemplate(instanceTemplateId); @@ -79,6 +79,11 @@ namespace AzToolsFramework m_instancesUpdateQueue.emplace_back(instance); } } + + if (immediate) + { + UpdateTemplateInstancesInQueue(); + } } void InstanceUpdateExecutor::RemoveTemplateInstanceFromQueue(const Instance* instance) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.h index ee461eae88..de2b483c4d 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutor.h @@ -31,7 +31,7 @@ namespace AzToolsFramework explicit InstanceUpdateExecutor(int instanceCountToUpdateInBatch = 0); - void AddTemplateInstancesToQueue(TemplateId instanceTemplateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt) override; + void AddTemplateInstancesToQueue(TemplateId instanceTemplateId, bool immediate = false, InstanceOptionalReference instanceToExclude = AZStd::nullopt) override; bool UpdateTemplateInstancesInQueue() override; virtual void RemoveTemplateInstanceFromQueue(const Instance* instance) override; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutorInterface.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutorInterface.h index 8ad032e1d0..3b894efd21 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutorInterface.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceUpdateExecutorInterface.h @@ -23,7 +23,7 @@ namespace AzToolsFramework virtual ~InstanceUpdateExecutorInterface() = default; // Add all Instances of Template with given Id into a queue for updating them later. - virtual void AddTemplateInstancesToQueue(TemplateId instanceTemplateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt) = 0; + virtual void AddTemplateInstancesToQueue(TemplateId instanceTemplateId, bool immediate = false, InstanceOptionalReference instanceToExclude = AZStd::nullopt) = 0; // Update Instances in the waiting queue. virtual bool UpdateTemplateInstancesInQueue() = 0; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/TemplateInstanceMapper.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/TemplateInstanceMapper.cpp index 65c498499d..5c7e5070f0 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/TemplateInstanceMapper.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/TemplateInstanceMapper.cpp @@ -27,7 +27,7 @@ namespace AzToolsFramework } - bool TemplateInstanceMapper::RegisterTemplate(const TemplateId& templateId) + bool TemplateInstanceMapper::RegisterTemplate(TemplateId templateId) { const bool result = m_templateIdToInstancesMap.emplace(templateId, InstanceSet()).second; AZ_Assert(result, @@ -39,7 +39,7 @@ namespace AzToolsFramework return result; } - bool TemplateInstanceMapper::UnregisterTemplate(const TemplateId& templateId) + bool TemplateInstanceMapper::UnregisterTemplate(TemplateId templateId) { const bool result = m_templateIdToInstancesMap.erase(templateId) != 0; AZ_Assert(result, @@ -53,7 +53,7 @@ namespace AzToolsFramework bool TemplateInstanceMapper::RegisterInstanceToTemplate(Instance& instance) { - const TemplateId& templateId = instance.GetTemplateId(); + TemplateId templateId = instance.GetTemplateId(); if (templateId == InvalidTemplateId) { return false; @@ -79,7 +79,7 @@ namespace AzToolsFramework found->second.erase(&instance) != 0; } - InstanceSetConstReference TemplateInstanceMapper::FindInstancesOwnedByTemplate(const TemplateId& templateId) const + InstanceSetConstReference TemplateInstanceMapper::FindInstancesOwnedByTemplate(TemplateId templateId) const { auto found = m_templateIdToInstancesMap.find(templateId); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/TemplateInstanceMapper.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/TemplateInstanceMapper.h index 307996b381..a2330c30d2 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/TemplateInstanceMapper.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/TemplateInstanceMapper.h @@ -26,10 +26,10 @@ namespace AzToolsFramework TemplateInstanceMapper(); ~TemplateInstanceMapper() override; - InstanceSetConstReference FindInstancesOwnedByTemplate(const TemplateId& templateId) const override; + InstanceSetConstReference FindInstancesOwnedByTemplate(TemplateId templateId) const override; - bool RegisterTemplate(const TemplateId& templateId); - bool UnregisterTemplate(const TemplateId& templateId); + bool RegisterTemplate(TemplateId templateId); + bool UnregisterTemplate(TemplateId templateId); protected: bool RegisterInstanceToTemplate(Instance& instance) override; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/TemplateInstanceMapperInterface.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/TemplateInstanceMapperInterface.h index 6473d5e937..475b456425 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/TemplateInstanceMapperInterface.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/TemplateInstanceMapperInterface.h @@ -24,7 +24,7 @@ namespace AzToolsFramework AZ_RTTI(TemplateInstanceMapperInterface, "{5DCCCDAA-3441-4266-9670-B349386E0129}"); virtual ~TemplateInstanceMapperInterface() = default; - virtual InstanceSetConstReference FindInstancesOwnedByTemplate(const TemplateId& templateId) const = 0; + virtual InstanceSetConstReference FindInstancesOwnedByTemplate(TemplateId templateId) const = 0; protected: // Only the Instance class is allowed to register and unregister Instances. diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Link/Link.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Link/Link.cpp index 800a90c622..8efb62d7e8 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Link/Link.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Link/Link.cpp @@ -122,12 +122,12 @@ namespace AzToolsFramework !m_instanceName.empty(); } - const TemplateId& Link::GetSourceTemplateId() const + TemplateId Link::GetSourceTemplateId() const { return m_sourceTemplateId; } - const TemplateId& Link::GetTargetTemplateId() const + TemplateId Link::GetTargetTemplateId() const { return m_targetTemplateId; } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Link/Link.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Link/Link.h index 00530c4337..aa11262bdf 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Link/Link.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Link/Link.h @@ -48,8 +48,8 @@ namespace AzToolsFramework bool IsValid() const; - const TemplateId& GetSourceTemplateId() const; - const TemplateId& GetTargetTemplateId() const; + TemplateId GetSourceTemplateId() const; + TemplateId GetTargetTemplateId() const; LinkId GetId() const; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp index 41538d54e8..038f36eac9 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp @@ -1041,7 +1041,7 @@ namespace AzToolsFramework PrefabUndoInstance* command = aznew PrefabUndoInstance("Entity/Instance duplication"); command->SetParent(undoBatch.GetUndoBatch()); command->Capture(instanceDomBefore, instanceDomAfter, commonOwningInstance->get().GetTemplateId()); - command->Redo(); + command->RedoBatched(); DuplicateNestedInstancesInInstance(commonOwningInstance->get(), instances, instanceDomAfter, duplicatedEntityAndInstanceIds, newInstanceAliasToOldInstanceMap); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp index 6ef2d756fb..4f8f575a7b 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.cpp @@ -92,7 +92,17 @@ namespace AzToolsFramework AZStd::unique_ptr PrefabSystemComponent::CreatePrefab( const AZStd::vector& entities, AZStd::vector>&& instancesToConsume, - AZ::IO::PathView filePath, AZStd::unique_ptr containerEntity, bool shouldCreateLinks) + AZ::IO::PathView filePath, AZStd::unique_ptr containerEntity, InstanceOptionalReference parent, + bool shouldCreateLinks) + { + AZStd::unique_ptr newInstance = AZStd::make_unique(AZStd::move(containerEntity), parent); + CreatePrefab(entities, AZStd::move(instancesToConsume), filePath, newInstance, shouldCreateLinks); + return newInstance; + } + + void PrefabSystemComponent::CreatePrefab( + const AZStd::vector& entities, AZStd::vector>&& instancesToConsume, + AZ::IO::PathView filePath, AZStd::unique_ptr& newInstance, bool shouldCreateLinks) { AZ::IO::Path relativeFilePath = m_prefabLoader.GenerateRelativePath(filePath); if (GetTemplateIdFromFilePath(relativeFilePath) != InvalidTemplateId) @@ -101,11 +111,9 @@ namespace AzToolsFramework "Filepath %s has already been registered with the Prefab System Component", relativeFilePath.c_str()); - return nullptr; + return; } - AZStd::unique_ptr newInstance = AZStd::make_unique(AZStd::move(containerEntity)); - for (AZ::Entity* entity : entities) { AZ_Assert(entity, "Prefab - Null entity passed in during Create Prefab"); @@ -136,13 +144,11 @@ namespace AzToolsFramework { newInstance->SetTemplateId(newTemplateId); } - - return newInstance; } - void PrefabSystemComponent::PropagateTemplateChanges(TemplateId templateId, InstanceOptionalReference instanceToExclude) + void PrefabSystemComponent::PropagateTemplateChanges(TemplateId templateId, bool immediate, InstanceOptionalReference instanceToExclude) { - UpdatePrefabInstances(templateId, instanceToExclude); + UpdatePrefabInstances(templateId, immediate, instanceToExclude); auto templateIdToLinkIdsIterator = m_templateToLinkIdsMap.find(templateId); if (templateIdToLinkIdsIterator != m_templateToLinkIdsMap.end()) @@ -171,9 +177,9 @@ namespace AzToolsFramework } } - void PrefabSystemComponent::UpdatePrefabInstances(const TemplateId& templateId, InstanceOptionalReference instanceToExclude) + void PrefabSystemComponent::UpdatePrefabInstances(TemplateId templateId, bool immediate, InstanceOptionalReference instanceToExclude) { - m_instanceUpdateExecutor.AddTemplateInstancesToQueue(templateId, instanceToExclude); + m_instanceUpdateExecutor.AddTemplateInstancesToQueue(templateId, immediate, instanceToExclude); } void PrefabSystemComponent::UpdateLinkedInstances(AZStd::queue& linkIdsQueue) @@ -256,7 +262,8 @@ namespace AzToolsFramework } } - AZStd::unique_ptr PrefabSystemComponent::InstantiatePrefab(AZ::IO::PathView filePath) + AZStd::unique_ptr PrefabSystemComponent::InstantiatePrefab( + AZ::IO::PathView filePath, InstanceOptionalReference parent) { // Retrieve the template id for the source prefab filepath Prefab::TemplateId templateId = GetTemplateIdFromFilePath(filePath); @@ -276,10 +283,11 @@ namespace AzToolsFramework return nullptr; } - return InstantiatePrefab(templateId); + return InstantiatePrefab(templateId, parent); } - AZStd::unique_ptr PrefabSystemComponent::InstantiatePrefab(const TemplateId& templateId) + AZStd::unique_ptr PrefabSystemComponent::InstantiatePrefab( + TemplateId templateId, InstanceOptionalReference parent) { TemplateReference instantiatingTemplate = FindTemplate(templateId); @@ -292,7 +300,7 @@ namespace AzToolsFramework return nullptr; } - auto newInstance = AZStd::make_unique(); + auto newInstance = AZStd::make_unique(parent); Instance::EntityList newEntities; if (!PrefabDomUtils::LoadInstanceFromPrefabDom(*newInstance, newEntities, instantiatingTemplate->get().GetPrefabDom())) { @@ -354,7 +362,7 @@ namespace AzToolsFramework return newTemplateId; } - TemplateReference PrefabSystemComponent::FindTemplate(const TemplateId& id) + TemplateReference PrefabSystemComponent::FindTemplate(TemplateId id) { auto found = m_templateIdMap.find(id); if (found != m_templateIdMap.end()) @@ -466,7 +474,7 @@ namespace AzToolsFramework templateToChange.SetFilePath(filePath); } - void PrefabSystemComponent::RemoveTemplate(const TemplateId& templateId) + void PrefabSystemComponent::RemoveTemplate(TemplateId templateId) { auto findTemplateResult = FindTemplate(templateId); if (!findTemplateResult.has_value()) @@ -553,8 +561,8 @@ namespace AzToolsFramework } LinkId PrefabSystemComponent::AddLink( - const TemplateId& sourceTemplateId, - const TemplateId& targetTemplateId, + TemplateId sourceTemplateId, + TemplateId targetTemplateId, PrefabDomValue::MemberIterator& instanceIterator, InstanceOptionalReference instance) { @@ -571,10 +579,13 @@ namespace AzToolsFramework Template& targetTemplate = targetTemplateReference->get(); +#if defined(AZ_ENABLE_TRACING) Template& sourceTemplate = sourceTemplateReference->get(); AZStd::string_view instanceName(instanceIterator->name.GetString(), instanceIterator->name.GetStringLength()); + const AZStd::string& targetTemplateFilePath = targetTemplate.GetFilePath().Native(); const AZStd::string& sourceTemplateFilePath = sourceTemplate.GetFilePath().Native(); +#endif LinkId newLinkId = CreateUniqueLinkId(); Link newLink(newLinkId); @@ -616,8 +627,8 @@ namespace AzToolsFramework } LinkId PrefabSystemComponent::CreateLink( - const TemplateId& linkTargetId, - const TemplateId& linkSourceId, + TemplateId linkTargetId, + TemplateId linkSourceId, const InstanceAlias& instanceAlias, const PrefabDomConstReference linkPatches, const LinkId& linkId) @@ -774,7 +785,7 @@ namespace AzToolsFramework } } - bool PrefabSystemComponent::IsTemplateDirty(const TemplateId& templateId) + bool PrefabSystemComponent::IsTemplateDirty(TemplateId templateId) { auto templateRef = FindTemplate(templateId); @@ -786,7 +797,7 @@ namespace AzToolsFramework return false; } - void PrefabSystemComponent::SetTemplateDirtyFlag(const TemplateId& templateId, bool dirty) + void PrefabSystemComponent::SetTemplateDirtyFlag(TemplateId templateId, bool dirty) { auto templateRef = FindTemplate(templateId); @@ -903,8 +914,10 @@ namespace AzToolsFramework return false; } +#if defined(AZ_ENABLE_TRACING) Template& sourceTemplate = sourceTemplateReference->get(); Template& targetTemplate = targetTemplateReference->get(); +#endif AZStd::string_view instanceName(instanceIterator->name.GetString(), instanceIterator->name.GetStringLength()); @@ -940,7 +953,7 @@ namespace AzToolsFramework return true; } - bool PrefabSystemComponent::GenerateLinksForNewTemplate(const TemplateId& newTemplateId, Instance& instance) + bool PrefabSystemComponent::GenerateLinksForNewTemplate(TemplateId newTemplateId, Instance& instance) { TemplateReference newTemplateReference = FindTemplate(newTemplateId); if (!newTemplateReference.has_value()) @@ -980,7 +993,7 @@ namespace AzToolsFramework } const PrefabDomValue& source = instanceSourceReference->get(); - const TemplateId& nestedTemplateId = GetTemplateIdFromFilePath(source.GetString()); + TemplateId nestedTemplateId = GetTemplateIdFromFilePath(source.GetString()); if (nestedTemplateId == InvalidTemplateId) { AZ_Error("Prefab", false, diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.h index 746c306c2b..f640eb2f1b 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponent.h @@ -84,7 +84,7 @@ namespace AzToolsFramework * @param id A unique id of a Template. * @return Reference of Template if the Template exists. */ - TemplateReference FindTemplate(const TemplateId& id) override; + TemplateReference FindTemplate(TemplateId id) override; /** * Find Link with given Link id from Prefab System Component. @@ -112,7 +112,7 @@ namespace AzToolsFramework * Remove the Template associated with the given id from Prefab System Component. * @param templateId A unique id of a Template. */ - void RemoveTemplate(const TemplateId& templateId) override; + void RemoveTemplate(TemplateId templateId) override; /** * Remove all Templates from the Prefab System Component. @@ -121,17 +121,21 @@ namespace AzToolsFramework /** * Generates a new Prefab Instance based on the Template whose source is stored in filepath. - * @param filePath the path to the prefab source file containing the template being instantiated. + * @param filePath The path to the prefab source file containing the template being instantiated. + * @param parent Reference of the target instance the instantiated instance will be placed under. * @return A unique_ptr to the newly instantiated instance. Null if operation failed. */ - AZStd::unique_ptr InstantiatePrefab(AZ::IO::PathView filePath) override; + AZStd::unique_ptr InstantiatePrefab( + AZ::IO::PathView filePath, InstanceOptionalReference parent = AZStd::nullopt) override; /** - * Generates a new Prefab Instance based on the Template referenced by templateId - * @param templateId the id of the template being instantiated. + * Generates a new Prefab Instance based on the Template referenced by templateId. + * @param templateId The id of the template being instantiated. + * @param parent Reference of the target instance the instantiated instance will be placed under. * @return A unique_ptr to the newly instantiated instance. Null if operation failed. */ - AZStd::unique_ptr InstantiatePrefab(const TemplateId& templateId) override; + AZStd::unique_ptr InstantiatePrefab( + TemplateId templateId, InstanceOptionalReference parent = AZStd::nullopt) override; /** * Add a new Link into Prefab System Component and create a unique id for it. @@ -142,8 +146,8 @@ namespace AzToolsFramework * @return A unique id for the new Link. */ LinkId AddLink( - const TemplateId& sourceTemplateId, - const TemplateId& targetTemplateId, + TemplateId sourceTemplateId, + TemplateId targetTemplateId, PrefabDomValue::MemberIterator& instanceIterator, InstanceOptionalReference instance) override; @@ -157,8 +161,8 @@ namespace AzToolsFramework * @return A unique id for the new Link. */ LinkId CreateLink( - const TemplateId& linkTargetId, - const TemplateId& linkSourceId, + TemplateId linkTargetId, + TemplateId linkSourceId, const InstanceAlias& instanceAlias, const PrefabDomConstReference linkPatches, const LinkId& linkId = InvalidLinkId) override; @@ -181,14 +185,14 @@ namespace AzToolsFramework * @param templateId The id of the template to query. * @return The value of the dirty flag on the template. */ - bool IsTemplateDirty(const TemplateId& templateId) override; + bool IsTemplateDirty(TemplateId templateId) override; /** * Sets the dirty flag of the template to the value provided. * @param templateId The id of the template to flag. * @param dirty The new value of the dirty flag. */ - void SetTemplateDirtyFlag(const TemplateId& templateId, bool dirty) override; + void SetTemplateDirtyFlag(TemplateId templateId, bool dirty) override; bool AreDirtyTemplatesPresent(TemplateId rootTemplateId) override; @@ -200,20 +204,21 @@ namespace AzToolsFramework /** * Builds a new Prefab Template out of entities and instances and returns the first instance comprised of - * these entities and instances - * @param entities A vector of entities that will be used in the new instance. May be empty + * these entities and instances. + * @param entities A vector of entities that will be used in the new instance. May be empty. * @param instances A vector of Prefab Instances that will be nested in the new instance, will be consumed and moved. - * May be empty - * @param filePath the path to associate the template of the new instance to. + * May be empty. + * @param filePath The path to associate the template of the new instance to. * @param containerEntity The container entity for the prefab to be created. It will be created if a nullptr is provided. + * @param parent Reference of an instance the created instance will be placed under, if given. * @param shouldCreateLinks The flag indicating if links should be created between the templates of the instance * and its nested instances. - * @return A pointer to the newly created instance. nullptr on failure + * @return A pointer to the newly created instance. nullptr on failure. */ AZStd::unique_ptr CreatePrefab( const AZStd::vector& entities, AZStd::vector>&& instancesToConsume, AZ::IO::PathView filePath, AZStd::unique_ptr containerEntity = nullptr, - bool ShouldCreateLinks = true) override; + InstanceOptionalReference parent = AZStd::nullopt, bool shouldCreateLinks = true) override; PrefabDom& FindTemplateDom(TemplateId templateId) override; @@ -225,18 +230,36 @@ namespace AzToolsFramework */ void UpdatePrefabTemplate(TemplateId templateId, const PrefabDom& updatedDom) override; - void PropagateTemplateChanges(TemplateId templateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt) override; + void PropagateTemplateChanges(TemplateId templateId, bool immediate = false, InstanceOptionalReference instanceToExclude = AZStd::nullopt) override; /** * Updates all Instances owned by a Template. * * @param templateId The id of the Template owning Instances to update. + * @param immediate An optional flag whether to apply the patch immediately (needed for Undo/Redos) or wait until next system tick. + * @param instanceToExclude An optional reference to an instance of the template being updated that should not be refreshes as part of propagation. + * Defaults to nullopt, which means that all instances will be refreshed. */ - void UpdatePrefabInstances(const TemplateId& templateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt); + void UpdatePrefabInstances(TemplateId templateId, bool immediate = false, InstanceOptionalReference instanceToExclude = AZStd::nullopt); private: AZ_DISABLE_COPY_MOVE(PrefabSystemComponent); + /** + * Builds a new Prefab Template out of entities and instances and returns the first instance comprised of + * these entities and instances. + * @param entities A vector of entities that will be used in the new instance. May be empty. + * @param instances A vector of Prefab Instances that will be nested in the new instance, will be consumed and moved. + * May be empty. + * @param filePath The path to associate the template of the new instance to. + * @param instance Reference of a pointer to the newly created instance which needs initiation. + * @param shouldCreateLinks The flag indicating if links should be created between the templates of the instance + * and its nested instances. + */ + void CreatePrefab(const AZStd::vector& entities, + AZStd::vector>&& instancesToConsume, AZ::IO::PathView filePath, + AZStd::unique_ptr& instance, bool shouldCreateLinks); + /** * Updates all the linked Instances corresponding to the linkIds in the provided queue. * Queue gets populated with more linkId lists as linked instances are updated. Updating stops when the queue is empty. @@ -310,7 +333,7 @@ namespace AzToolsFramework * @param instance The instance that the template was created from. This needs to be editable for inserting linkId into it. * @return bool on whether the operation succeeded */ - bool GenerateLinksForNewTemplate(const TemplateId& newTemplateId, Instance& instance); + bool GenerateLinksForNewTemplate(TemplateId newTemplateId, Instance& instance); /** * Create a unique Template id for newly created Template. diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponentInterface.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponentInterface.h index 1f59088518..54ca951841 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponentInterface.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabSystemComponentInterface.h @@ -29,28 +29,28 @@ namespace AzToolsFramework public: AZ_RTTI(PrefabSystemComponentInterface, "{8E95A029-67F9-4F74-895F-DDBFE29516A0}"); - virtual TemplateReference FindTemplate(const TemplateId& id) = 0; + virtual TemplateReference FindTemplate(TemplateId id) = 0; virtual LinkReference FindLink(const LinkId& id) = 0; virtual TemplateId AddTemplate(const AZ::IO::Path& filePath, PrefabDom prefabDom) = 0; virtual void UpdateTemplateFilePath(TemplateId templateId, const AZ::IO::PathView& filePath) = 0; - virtual void RemoveTemplate(const TemplateId& templateId) = 0; + virtual void RemoveTemplate(TemplateId templateId) = 0; virtual void RemoveAllTemplates() = 0; - virtual LinkId AddLink(const TemplateId& sourceTemplateId, const TemplateId& targetTemplateId, + virtual LinkId AddLink(TemplateId sourceTemplateId, TemplateId targetTemplateId, PrefabDomValue::MemberIterator& instanceIterator, InstanceOptionalReference instance) = 0; //creates a new Link virtual LinkId CreateLink( - const TemplateId& linkTargetId, const TemplateId& linkSourceId, const InstanceAlias& instanceAlias, + TemplateId linkTargetId, TemplateId linkSourceId, const InstanceAlias& instanceAlias, const PrefabDomConstReference linkPatches, const LinkId& linkId = InvalidLinkId) = 0; virtual void RemoveLink(const LinkId& linkId) = 0; virtual TemplateId GetTemplateIdFromFilePath(AZ::IO::PathView filePath) const = 0; - virtual bool IsTemplateDirty(const TemplateId& templateId) = 0; - virtual void SetTemplateDirtyFlag(const TemplateId& templateId, bool dirty) = 0; + virtual bool IsTemplateDirty(TemplateId templateId) = 0; + virtual void SetTemplateDirtyFlag(TemplateId templateId, bool dirty) = 0; //! Recursive function to check if the template is dirty or if any dirty templates are presents in the links of the template. //! @param rootTemplateId The id of the template provided as the beginning template to check the outgoing links. @@ -67,13 +67,16 @@ namespace AzToolsFramework virtual PrefabDom& FindTemplateDom(TemplateId templateId) = 0; virtual void UpdatePrefabTemplate(TemplateId templateId, const PrefabDom& updatedDom) = 0; - virtual void PropagateTemplateChanges(TemplateId templateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt) = 0; + virtual void PropagateTemplateChanges(TemplateId templateId, bool immediate = false, InstanceOptionalReference instanceToExclude = AZStd::nullopt) = 0; - virtual AZStd::unique_ptr InstantiatePrefab(AZ::IO::PathView filePath) = 0; - virtual AZStd::unique_ptr InstantiatePrefab(const TemplateId& templateId) = 0; + virtual AZStd::unique_ptr InstantiatePrefab( + AZ::IO::PathView filePath, InstanceOptionalReference parent = AZStd::nullopt) = 0; + virtual AZStd::unique_ptr InstantiatePrefab( + TemplateId templateId, InstanceOptionalReference parent = AZStd::nullopt) = 0; virtual AZStd::unique_ptr CreatePrefab(const AZStd::vector& entities, AZStd::vector>&& instancesToConsume, AZ::IO::PathView filePath, - AZStd::unique_ptr containerEntity = nullptr, bool ShouldCreateLinks = true) = 0; + AZStd::unique_ptr containerEntity = nullptr, InstanceOptionalReference parent = AZStd::nullopt, + bool shouldCreateLinks = true) = 0; }; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.cpp index fe3555a853..b298304e3b 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.cpp @@ -33,7 +33,7 @@ namespace AzToolsFramework void PrefabUndoInstance::Capture( const PrefabDom& initialState, const PrefabDom& endState, - const TemplateId& templateId) + TemplateId templateId) { m_templateId = templateId; @@ -43,10 +43,15 @@ namespace AzToolsFramework void PrefabUndoInstance::Undo() { - m_instanceToTemplateInterface->PatchTemplate(m_undoPatch, m_templateId); + m_instanceToTemplateInterface->PatchTemplate(m_undoPatch, m_templateId, true); } void PrefabUndoInstance::Redo() + { + m_instanceToTemplateInterface->PatchTemplate(m_redoPatch, m_templateId, true); + } + + void PrefabUndoInstance::RedoBatched() { m_instanceToTemplateInterface->PatchTemplate(m_redoPatch, m_templateId); } @@ -91,7 +96,7 @@ namespace AzToolsFramework void PrefabUndoEntityUpdate::Undo() { [[maybe_unused]] bool isPatchApplicationSuccessful = - m_instanceToTemplateInterface->PatchTemplate(m_undoPatch, m_templateId); + m_instanceToTemplateInterface->PatchTemplate(m_undoPatch, m_templateId, true); AZ_Error( "Prefab", isPatchApplicationSuccessful, @@ -102,7 +107,7 @@ namespace AzToolsFramework void PrefabUndoEntityUpdate::Redo() { [[maybe_unused]] bool isPatchApplicationSuccessful = - m_instanceToTemplateInterface->PatchTemplate(m_redoPatch, m_templateId); + m_instanceToTemplateInterface->PatchTemplate(m_redoPatch, m_templateId, true); AZ_Error( "Prefab", isPatchApplicationSuccessful, @@ -113,7 +118,7 @@ namespace AzToolsFramework void PrefabUndoEntityUpdate::Redo(InstanceOptionalReference instanceToExclude) { [[maybe_unused]] bool isPatchApplicationSuccessful = - m_instanceToTemplateInterface->PatchTemplate(m_redoPatch, m_templateId, instanceToExclude); + m_instanceToTemplateInterface->PatchTemplate(m_redoPatch, m_templateId, false, instanceToExclude); AZ_Error( "Prefab", isPatchApplicationSuccessful, @@ -136,8 +141,8 @@ namespace AzToolsFramework } void PrefabUndoInstanceLink::Capture( - const TemplateId& targetId, - const TemplateId& sourceId, + TemplateId targetId, + TemplateId sourceId, const InstanceAlias& instanceAlias, PrefabDom linkPatches, const LinkId linkId) @@ -329,7 +334,7 @@ namespace AzToolsFramework //propagate the link changes link->get().UpdateTarget(); - m_prefabSystemComponentInterface->PropagateTemplateChanges(link->get().GetTargetTemplateId(), instanceToExclude); + m_prefabSystemComponentInterface->PropagateTemplateChanges(link->get().GetTargetTemplateId(), false, instanceToExclude); //mark as dirty m_prefabSystemComponentInterface->SetTemplateDirtyFlag(link->get().GetTargetTemplateId(), true); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.h index 1b04852c37..8669024df7 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndo.h @@ -49,10 +49,11 @@ namespace AzToolsFramework void Capture( const PrefabDom& initialState, const PrefabDom& endState, - const TemplateId& templateId); + TemplateId templateId); void Undo() override; void Redo() override; + void RedoBatched(); }; //! handles entity updates, such as when the values on an entity change @@ -95,8 +96,8 @@ namespace AzToolsFramework //capture for add/remove void Capture( - const TemplateId& targetId, - const TemplateId& sourceId, + TemplateId targetId, + TemplateId sourceId, const InstanceAlias& instanceAlias, PrefabDom linkPatches = PrefabDom(), const LinkId linkId = InvalidLinkId); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp index 9c44fc7ffd..9803b55324 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabUndoHelpers.cpp @@ -26,7 +26,7 @@ namespace AzToolsFramework PrefabUndoInstance* state = aznew Prefab::PrefabUndoInstance(undoMessage); state->Capture(instanceDomBeforeUpdate, instanceDomAfterUpdate, instance.GetTemplateId()); state->SetParent(undoBatch); - state->Redo(); + state->RedoBatched(); } LinkId CreateLink( diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp index 9b7f2fff10..34152f8287 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp @@ -1160,7 +1160,7 @@ namespace AzToolsFramework AZStd::string unsavedPrefabFileName = unsavedPrefabFileLabel->property("FilePath").toString().toUtf8().data(); AzToolsFramework::Prefab::TemplateId unsavedPrefabTemplateId = s_prefabSystemComponentInterface->GetTemplateIdFromFilePath(unsavedPrefabFileName.data()); - bool isTemplateSavedSuccessfully = s_prefabLoaderInterface->SaveTemplate(unsavedPrefabTemplateId); + [[maybe_unused]] bool isTemplateSavedSuccessfully = s_prefabLoaderInterface->SaveTemplate(unsavedPrefabTemplateId); AZ_Error("Prefab", isTemplateSavedSuccessfully, "Prefab '%s' could not be saved successfully.", unsavedPrefabFileName.c_str()); } } diff --git a/Code/Framework/AzToolsFramework/Platform/Linux/AzToolsFramework/Archive/ArchiveComponent_Linux.cpp b/Code/Framework/AzToolsFramework/Platform/Linux/AzToolsFramework/Archive/ArchiveComponent_Linux.cpp deleted file mode 100644 index cc8b9492e8..0000000000 --- a/Code/Framework/AzToolsFramework/Platform/Linux/AzToolsFramework/Archive/ArchiveComponent_Linux.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -#include -#include -#include -#include - -namespace AzToolsFramework -{ - namespace Platform - { - [[maybe_unused]] static const char ErrorChannel[] = "ArchiveComponent_Linux"; - - static const char ZipExePath[] = R"(/usr/bin/zip)"; - static const char UnzipExePath[] = R"(/usr/bin/unzip)"; - - static const char CreateArchiveCmd[] = "-r \"%s\" . -i *"; - - static const char ExtractArchiveCmd[] = R"(-o "%s" -d "%s")"; - - static const char AddFileCmd[] = R"("%s" "%s")"; - - static const char ExtractFileCmd[] = R"(%s "%s" %s)"; - static const char ExtractFileDestination[] = R"(%s "%s" "%s" -d "%s")"; - static const char ExtractOverwrite[] = "-o"; - static const char ExtractSkipExisting[] = "-n"; - static const char ListFilesInArchiveCmd[] = "-l %s"; - - AZStd::string GetZipExePath() - { - return ZipExePath; - } - - AZStd::string GetUnzipExePath() - { - return UnzipExePath; - } - - AZ::Outcome MakePath(const AZStd::string& path) - { - // Create the folder if it does not already exist - if (!AZ::IO::FileIOBase::GetInstance()->Exists(path.c_str())) - { - auto result = AZ::IO::FileIOBase::GetInstance()->CreatePath(path.c_str()); - if (!result) - { - return AZ::Failure(AZStd::string::format("Path creation failed. Input path: %s \n", path.c_str())); - } - } - - return AZ::Success(path); - } - - AZ::Outcome MakeCreateArchivePath(const AZStd::string& archivePath) - { - // Remove the file name from the input path - // /some/folder/path/archive.zip -> /some/folder/path/ - AZStd::string strippedArchivePath = archivePath; - AzFramework::StringFunc::Path::StripFullName(strippedArchivePath); - - if (strippedArchivePath.empty()) - { - return AZ::Failure(AZStd::string::format("Stripped path name is empty. Cancelling path creation. Input path: %s\n", archivePath.c_str())); - } - - return MakePath(strippedArchivePath); - } - - AZ::Outcome MakeExtractArchivePath(const AZStd::string& archivePath, const AZStd::string& destinationPath, bool includeRoot) - { - if(!includeRoot) - { - // Create the folder for the input destination path with no modifications - // /path/to/destination/ - return MakePath(destinationPath); - } - - // Get the name of the input archive. This will be the name of the root folder for the archive extraction - // /some/folder/path/archive.zip -> archive - AZStd::string zipFileName; - bool result = AzFramework::StringFunc::Path::GetFileName(archivePath.c_str(), zipFileName); - if(!result) - { - return AZ::Failure(AZStd::string::format("Failed to get name of zip file from the archive path. Cancelling path creation. \n Input Archive Path: %s \n", archivePath.c_str())); - } - - // Append the root folder name to the end of the destination path - // /path/to/destination/ + archive -> /path/to/destination/archive - AZStd::string destinationPathWithRoot; - result = AzFramework::StringFunc::Path::Join(destinationPath.c_str(), zipFileName.c_str(), destinationPathWithRoot); - if(!result) - { - return AZ::Failure(AZStd::string::format("Failed to append zip file name to the destination path. Cancelling path creation. \n Destination Path: %s \n Zip file name: %s \n", destinationPath.c_str(), zipFileName.c_str())); - } - - // Append a separator so that it is formatted like a folder - // /path/to/destination/archive -> /path/to/destination/archive/ - AzFramework::StringFunc::Path::AppendSeparator(destinationPathWithRoot); - return MakePath(destinationPathWithRoot); - } - - AZStd::string GetCreateArchiveCommand(const AZStd::string& archivePath, const AZStd::string& dirToArchive) - { - auto pathCreationResult = MakeCreateArchivePath(archivePath); - if (!pathCreationResult) - { - AZ_Error(ErrorChannel, false, "%s", pathCreationResult.GetError().c_str()); - return ""; - } - AZ_UNUSED(dirToArchive); - return AZStd::string::format(CreateArchiveCmd, archivePath.c_str()); - } - - AZStd::string GetExtractArchiveCommand(const AZStd::string& archivePath, const AZStd::string& destinationPath, bool includeRoot) - { - auto pathCreationResult = MakeExtractArchivePath(archivePath, destinationPath, includeRoot); - if (!pathCreationResult) - { - AZ_Error(ErrorChannel, false, "%s", pathCreationResult.GetError().c_str()); - return ""; - } - - return AZStd::string::format(ExtractArchiveCmd, archivePath.c_str(), pathCreationResult.GetValue().c_str()); - } - - AZStd::string GetAddFilesToArchiveCommand(const AZStd::string& /*archivePath*/, const AZStd::string& /*listFilePath*/) - { - // Adding files into a archive using a list file is not currently supported - return {}; - } - - bool IsAddFilesToArchiveCommandSupported() - { - // Adding files into a archive using a list file is not currently supported - return false; - } - - AZStd::string GetAddFileToArchiveCommand(const AZStd::string& archivePath, const AZStd::string& file) - { - if (!MakeCreateArchivePath(archivePath).IsSuccess()) - { - AZ_Error(ErrorChannel, false, "Unable to make path for ( %s ).\n", archivePath.c_str()); - return {}; - } - return AZStd::string::format(AddFileCmd, archivePath.c_str(), file.c_str()); - } - - AZStd::string GetExtractFileCommand(const AZStd::string& archivePath, const AZStd::string& fileInArchive, const AZStd::string& destinationPath, bool overWrite) - { - AZStd::string commandLineArgs; - if (destinationPath.empty()) - { - // Extract file in archive from archive path to the current directory, overwriting a file of the same name that exists there. - commandLineArgs = AZStd::string::format(ExtractFileCmd, overWrite ? ExtractOverwrite : ExtractSkipExisting, archivePath.c_str(), fileInArchive.c_str()); - } - else - { - if (!MakePath(destinationPath).IsSuccess()) - { - AZ_Error(ErrorChannel, false, "Unable to make path ( %s ).\n", destinationPath.c_str()); - return {}; - } - // Extract file in archive from archive path to destinationPath, overwriting a file of the same name that exists there. - commandLineArgs = AZStd::string::format(ExtractFileDestination, overWrite ? ExtractOverwrite : ExtractSkipExisting, archivePath.c_str(), fileInArchive.c_str(), destinationPath.c_str()); - } - - return commandLineArgs; - } - - AZStd::string GetListFilesInArchiveCommand(const AZStd::string& archivePath) - { - AZStd::string commandLineArgs = AZStd::string::format(ListFilesInArchiveCmd, archivePath.c_str()); - return commandLineArgs; - } - - /* - Sample Console Output of the unzip list command - - Archive: /var/folders/1q/12nyzqc913qgm532y2c98mnm6w4_qv/T/ArchiveTests-ra8oMy/TestArchive.pak - Length Date Time Name - --------- ---------- ----- ---- - 0 10-14-2019 15:22 testfolder/ - 1 10-14-2019 15:22 testfolder/folderfile.txt - 1 10-14-2019 15:22 basicfile.txt - 1 10-14-2019 15:22 basicfile2.txt - 0 10-14-2019 15:22 testfolder2/ - 1 10-14-2019 15:22 testfolder2/sharedfolderfile2.txt - 1 10-14-2019 15:22 testfolder2/sharedfolderfile.txt - 0 10-14-2019 15:22 testfolder3/ - 0 10-14-2019 15:22 testfolder3/testfolder4/ - 1 10-14-2019 15:22 testfolder3/testfolder4/depthfile.bat - --------- ------- - 6 10 files - */ - - void ParseConsoleOutputFromListFilesInArchive(const AZStd::string& consoleOutput, AZStd::vector& fileEntries) - { - AZStd::vector fileEntryData; - AzFramework::StringFunc::Tokenize(consoleOutput.c_str(), fileEntryData, "\n"); - int startingLineIdx = 3; // first line that might contain the file name - for (size_t lineIdx = startingLineIdx; lineIdx < fileEntryData.size(); ++lineIdx) - { - AZStd::string& line = fileEntryData[lineIdx]; - AZStd::vector lineEntryData; - AzFramework::StringFunc::Tokenize(line.c_str(), lineEntryData, " "); - AZStd::string& fileName = lineEntryData.back(); - - if(fileName.back() == AZ_CORRECT_FILESYSTEM_SEPARATOR) - { - // if the filename ends with a separator - // than it indicates that this is a directory - continue; - } - - if(fileName.compare("-------") == 0) - { - return; - } - - fileEntries.emplace_back(fileName); - } - } - } // namespace Platform -} // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/Platform/Linux/platform_linux_files.cmake b/Code/Framework/AzToolsFramework/Platform/Linux/platform_linux_files.cmake index 84d1cf808f..c2c5a11c4c 100644 --- a/Code/Framework/AzToolsFramework/Platform/Linux/platform_linux_files.cmake +++ b/Code/Framework/AzToolsFramework/Platform/Linux/platform_linux_files.cmake @@ -7,5 +7,4 @@ # set(FILES - AzToolsFramework/Archive/ArchiveComponent_Linux.cpp ) diff --git a/Code/Framework/AzToolsFramework/Platform/Mac/AzToolsFramework/Archive/ArchiveComponent_Mac.cpp b/Code/Framework/AzToolsFramework/Platform/Mac/AzToolsFramework/Archive/ArchiveComponent_Mac.cpp deleted file mode 100644 index 67b7b9cf66..0000000000 --- a/Code/Framework/AzToolsFramework/Platform/Mac/AzToolsFramework/Archive/ArchiveComponent_Mac.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -#include -#include -#include -#include - -namespace AzToolsFramework -{ - namespace Platform - { - const char ErrorChannel[] = "ArchiveComponent_OSX"; - - const char ZipExePath[] = R"(/usr/bin/zip)"; - const char UnzipExePath[] = R"(/usr/bin/unzip)"; - - // v Requires investigation, the correct cmd should be R"(-r "%s" "%s/")" but tests fail - const char CreateArchiveCmd[] = R"(-r "%s" .)"; - - const char ExtractArchiveCmd[] = R"(-o "%s" -d "%s")"; - - const char AddFileCmd[] = R"("%s" "%s" -X)"; - const char AddFilesCmd[] = R"("%s" -X %s)"; - - const char ExtractFileCmd[] = R"(%s "%s" %s)"; - const char ExtractFileDestination[] = R"(%s "%s" "%s" -d "%s")"; - const char ExtractOverwrite[] = "-o"; - const char ExtractSkipExisting[] = "-n"; - const char ListFilesInArchiveCmd[] = "-l %s"; - - AZStd::string GetZipExePath() - { - return ZipExePath; - } - - AZStd::string GetUnzipExePath() - { - return UnzipExePath; - } - - AZ::Outcome MakePath(const AZStd::string& path) - { - // Create the folder if it does not already exist - if (!AZ::IO::FileIOBase::GetInstance()->Exists(path.c_str())) - { - auto result = AZ::IO::FileIOBase::GetInstance()->CreatePath(path.c_str()); - if (!result) - { - return AZ::Failure(AZStd::string::format("Path creation failed. Input path: %s \n", path.c_str())); - } - } - - return AZ::Success(path); - } - - AZ::Outcome MakeCreateArchivePath(const AZStd::string& archivePath) - { - // Remove the file name from the input path - // /some/folder/path/archive.zip -> /some/folder/path/ - AZStd::string strippedArchivePath = archivePath; - AzFramework::StringFunc::Path::StripFullName(strippedArchivePath); - - if (strippedArchivePath.empty()) - { - return AZ::Failure(AZStd::string::format("Stripped path name is empty. Cancelling path creation. Input path: %s\n", archivePath.c_str())); - } - - return MakePath(strippedArchivePath); - } - - AZ::Outcome MakeExtractArchivePath(const AZStd::string& archivePath, const AZStd::string& destinationPath, bool includeRoot) - { - if(!includeRoot) - { - // Create the folder for the input destination path with no modifications - // /path/to/destination/ - return MakePath(destinationPath); - } - - // Get the name of the input archive. This will be the name of the root folder for the archive extraction - // /some/folder/path/archive.zip -> archive - AZStd::string zipFileName; - bool result = AzFramework::StringFunc::Path::GetFileName(archivePath.c_str(), zipFileName); - if(!result) - { - return AZ::Failure(AZStd::string::format("Failed to get name of zip file from the archive path. Cancelling path creation. \n Input Archive Path: %s \n", archivePath.c_str())); - } - - // Append the root folder name to the end of the destination path - // /path/to/destination/ + archive -> /path/to/destination/archive - AZStd::string destinationPathWithRoot; - result = AzFramework::StringFunc::Path::Join(destinationPath.c_str(), zipFileName.c_str(), destinationPathWithRoot); - if(!result) - { - return AZ::Failure(AZStd::string::format("Failed to append zip file name to the destination path. Cancelling path creation. \n Destination Path: %s \n Zip file name: %s \n", destinationPath.c_str(), zipFileName.c_str())); - } - - // Append a separator so that it is formatted like a folder - // /path/to/destination/archive -> /path/to/destination/archive/ - AzFramework::StringFunc::Path::AppendSeparator(destinationPathWithRoot); - return MakePath(destinationPathWithRoot); - } - - AZStd::string GetCreateArchiveCommand(const AZStd::string& archivePath, const AZStd::string& dirToArchive) - { - auto pathCreationResult = MakeCreateArchivePath(archivePath); - if (!pathCreationResult.IsSuccess()) - { - AZ_Error(ErrorChannel, false, pathCreationResult.GetError().c_str()); - return ""; - } - - // LY-116692. Requires proper investigation, the correct format should be: - // AZStd::string::format(CreateArchiveCmd, archivePath.c_str(), dirToArchive.c_str()); - // but unit test ArchiveTest.ListFilesInArchiveBlocking_FilesAtThreeDepths_FilesFound fails - AZ_UNUSED(dirToArchive); - return AZStd::string::format(CreateArchiveCmd, archivePath.c_str()); - } - - AZStd::string GetExtractArchiveCommand(const AZStd::string& archivePath, const AZStd::string& destinationPath, bool includeRoot) - { - auto pathCreationResult = MakeExtractArchivePath(archivePath, destinationPath, includeRoot); - if (!pathCreationResult) - { - AZ_Error(ErrorChannel, false, pathCreationResult.GetError().c_str()); - return ""; - } - - return AZStd::string::format(ExtractArchiveCmd, archivePath.c_str(), pathCreationResult.GetValue().c_str()); - } - - AZStd::string GetAddFilesToArchiveCommand(const AZStd::string& archivePath, const AZStd::string& listFilePath) - { - auto pathCreationResult = MakeCreateArchivePath(archivePath); - if (!pathCreationResult) - { - AZ_Error(ErrorChannel, false, pathCreationResult.GetError().c_str()); - return ""; - } - AZStd::string fileListStr; - - { - AZ::IO::FileIOStream fileStream(listFilePath.c_str(), AZ::IO::OpenMode::ModeRead | AZ::IO::OpenMode::ModeText); - if (fileStream.IsOpen()) - { - AZ::IO::SizeType length = fileStream.GetLength(); - AZStd::vector charBuffer; - charBuffer.resize_no_construct(length + 1); - - fileStream.Read(length, charBuffer.data()); - charBuffer.back() = 0; - - fileListStr.append("\""); - fileListStr.insert(1, charBuffer.data()); - AzFramework::StringFunc::Replace(fileListStr, "\n", "\" \""); - fileListStr.append("\""); - } - else - { - AZ_Error(ErrorChannel, false, "Unable to read list file ( %s ) \n", listFilePath.c_str()); - return ""; - } - } - - return AZStd::string::format(AddFilesCmd, archivePath.c_str(), fileListStr.c_str()); - } - - AZStd::string GetAddFileToArchiveCommand(const AZStd::string& archivePath, const AZStd::string& file) - { - auto pathCreationResult = MakeCreateArchivePath(archivePath); - if (!pathCreationResult) - { - AZ_Error(ErrorChannel, false, pathCreationResult.GetError().c_str()); - return ""; - } - - return AZStd::string::format(AddFileCmd, archivePath.c_str(), file.c_str()); - } - - AZStd::string GetExtractFileCommand(const AZStd::string& archivePath, const AZStd::string& fileInArchive, const AZStd::string& destinationPath, bool overWrite) - { - AZStd::string commandLineArgs; - if (destinationPath.empty()) - { - // Extract file in archive from archive path to the current directory, overwriting a file of the same name that exists there. - commandLineArgs = AZStd::string::format(ExtractFileCmd, overWrite ? ExtractOverwrite : ExtractSkipExisting, archivePath.c_str(), fileInArchive.c_str()); - } - else - { - if (!MakePath(destinationPath).IsSuccess()) - { - AZ_Error(ErrorChannel, false, "Unable to make path ( %s ).\n", destinationPath.c_str()); - return ""; - } - // Extract file in archive from archive path to destinationPath, overwriting a file of the same name that exists there. - commandLineArgs = AZStd::string::format(ExtractFileDestination, overWrite ? ExtractOverwrite : ExtractSkipExisting, archivePath.c_str(), fileInArchive.c_str(), destinationPath.c_str()); - } - - return commandLineArgs; - } - - AZStd::string GetListFilesInArchiveCommand(const AZStd::string& archivePath) - { - AZStd::string commandLineArgs = AZStd::string::format(ListFilesInArchiveCmd, archivePath.c_str()); - return commandLineArgs; - } - - /* - Sample Console Output of the unzip list command - - Archive: /var/folders/1q/12nyzqc913qgm532y2c98mnm6w4_qv/T/ArchiveTests-ra8oMy/TestArchive.pak - Length Date Time Name - --------- ---------- ----- ---- - 0 10-14-2019 15:22 testfolder/ - 1 10-14-2019 15:22 testfolder/folderfile.txt - 1 10-14-2019 15:22 basicfile.txt - 1 10-14-2019 15:22 basicfile2.txt - 0 10-14-2019 15:22 testfolder2/ - 1 10-14-2019 15:22 testfolder2/sharedfolderfile2.txt - 1 10-14-2019 15:22 testfolder2/sharedfolderfile.txt - 0 10-14-2019 15:22 testfolder3/ - 0 10-14-2019 15:22 testfolder3/testfolder4/ - 1 10-14-2019 15:22 testfolder3/testfolder4/depthfile.bat - --------- ------- - 6 10 files - */ - - void ParseConsoleOutputFromListFilesInArchive(const AZStd::string& consoleOutput, AZStd::vector& fileEntries) - { - AZStd::vector fileEntryData; - AzFramework::StringFunc::Tokenize(consoleOutput.c_str(), fileEntryData, "\n"); - int startingLineIdx = 3; // first line that might contain the file name - for (size_t lineIdx = startingLineIdx; lineIdx < fileEntryData.size(); ++lineIdx) - { - AZStd::string& line = fileEntryData[lineIdx]; - AZStd::vector lineEntryData; - AzFramework::StringFunc::Tokenize(line.c_str(), lineEntryData, " "); - AZStd::string& fileName = lineEntryData.back(); - - if(fileName.back() == AZ_CORRECT_FILESYSTEM_SEPARATOR) - { - // if the filename ends with a separator - // than it indicates that this is a directory - continue; - } - - if(fileName.compare("-------") == 0) - { - return; - } - - fileEntries.emplace_back(fileName); - } - } - - } // namespace Platform -} // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/Platform/Mac/platform_mac_files.cmake b/Code/Framework/AzToolsFramework/Platform/Mac/platform_mac_files.cmake index 9928584f86..c2c5a11c4c 100644 --- a/Code/Framework/AzToolsFramework/Platform/Mac/platform_mac_files.cmake +++ b/Code/Framework/AzToolsFramework/Platform/Mac/platform_mac_files.cmake @@ -7,5 +7,4 @@ # set(FILES - AzToolsFramework/Archive/ArchiveComponent_Mac.cpp ) diff --git a/Code/Framework/AzToolsFramework/Platform/Windows/AzToolsFramework/Archive/ArchiveComponent_Windows.cpp b/Code/Framework/AzToolsFramework/Platform/Windows/AzToolsFramework/Archive/ArchiveComponent_Windows.cpp deleted file mode 100644 index 20f53af18b..0000000000 --- a/Code/Framework/AzToolsFramework/Platform/Windows/AzToolsFramework/Archive/ArchiveComponent_Windows.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -#include -#include -#include -#include - -namespace AzToolsFramework -{ - namespace Platform - { - const char CreateArchiveCmd[] = R"(a -tzip -mx=1 "%s" -r "%s\*")"; - - // -aos is for skipping extract on existing files - const char ExtractArchiveCmd[] = R"(x -mmt=off "%s" -o"%s\*" -aos)"; - const char ExtractArchiveWithoutRootCmd[] = R"(x -mmt=off "%s" -o"%s" -aos)"; - const char AddFilesCmd[] = R"(a -tzip "%s" @"%s")"; - const char AddFileCmd[] = R"(a -tzip "%s" "%s")"; - const char ExtractFileCmd[] = R"(e -mmt=off "%s" "%s" %s)"; - const char ExtractFileDestination[] = R"(e -mmt=off "%s" -o"%s" "%s" %s)"; - const char ExtractOverwrite[] = "-aoa"; - const char ExtractSkipExisting[] = "-aos"; - const char ListFilesInArchiveCmd[] = R"(l -r -slt "%s")"; - - AZStd::string Get7zExePath() - { - const char* rootPath = nullptr; - AZ::ComponentApplicationBus::BroadcastResult(rootPath, &AZ::ComponentApplicationRequests::GetEngineRoot); - AZStd::string exePath; - AzFramework::StringFunc::Path::ConstructFull(rootPath, "Tools", "7za", ".exe", exePath); - return exePath; - } - - AZStd::string GetZipExePath() - { - return Get7zExePath(); - } - - AZStd::string GetUnzipExePath() - { - return Get7zExePath(); - } - - AZStd::string GetCreateArchiveCommand(const AZStd::string& archivePath, const AZStd::string& dirToArchive) - { - return AZStd::string::format(CreateArchiveCmd, archivePath.c_str(), dirToArchive.c_str()); - } - - AZStd::string GetExtractArchiveCommand(const AZStd::string& archivePath, const AZStd::string& destinationPath, bool includeRoot) - { - if (includeRoot) - { - // Extract archive path to destinationPath\ and skipping extracting of existing files - return AZStd::string::format(ExtractArchiveCmd, archivePath.c_str(), destinationPath.c_str()); - } - else - { - // Extract archive path to destinationPath and skipping extracting of existing files - return AZStd::string::format(ExtractArchiveWithoutRootCmd, archivePath.c_str(), destinationPath.c_str()); - } - } - - AZStd::string GetAddFilesToArchiveCommand(const AZStd::string& archivePath, const AZStd::string& listFilePath) - { - return AZStd::string::format(AddFilesCmd, archivePath.c_str(), listFilePath.c_str()); - } - - AZStd::string GetAddFileToArchiveCommand(const AZStd::string& archivePath, const AZStd::string& file) - { - return AZStd::string::format(AddFileCmd, archivePath.c_str(), file.c_str()); - } - - AZStd::string GetExtractFileCommand(const AZStd::string& archivePath, const AZStd::string& fileInArchive, const AZStd::string& destinationPath, bool overWrite) - { - AZStd::string commandLineArgs; - if (destinationPath.empty()) - { - // Extract file in archive from archive path to the current directory, overwriting a file of the same name that exists there. - commandLineArgs = AZStd::string::format(ExtractFileCmd, archivePath.c_str(), fileInArchive.c_str(), overWrite ? ExtractOverwrite : ExtractSkipExisting); - } - else - { - // Extract file in archive from archive path to destinationPath, overwriting a file of the same name that exists there. - commandLineArgs = AZStd::string::format(ExtractFileDestination, archivePath.c_str(), destinationPath.c_str(), fileInArchive.c_str(), overWrite ? ExtractOverwrite : ExtractSkipExisting); - } - - return commandLineArgs; - } - - AZStd::string GetListFilesInArchiveCommand(const AZStd::string& archivePath) - { - AZStd::string commandLineArgs = AZStd::string::format(ListFilesInArchiveCmd, archivePath.c_str()); - return commandLineArgs; - } - - /* - File output for our list archive commands takes the following two patterns for files vs directories: - - Path = basicfile2.txt - Folder = - - Size = 1 - Packed Size = 1 - Modified = 2019-03-26 18:31:10 - Created = 2019-03-26 18:31:10 - Accessed = 2019-03-26 18:31:10 - Attributes = A - Encrypted = - - Comment = - CRC = 32D70693 - Method = Store - Characteristics = NTFS - Host OS = FAT - Version = 10 - Volume Index = 0 - Offset = 44 - - Path = testfolder - Folder = + - Size = 0 - Packed Size = 0 - Modified = 2019-03-26 18:31:10 - Created = 2019-03-26 18:31:10 - Accessed = 2019-03-26 18:31:10 - Attributes = D - Encrypted = - - Comment = - CRC = - Method = Store - Characteristics = NTFS - Host OS = FAT - Version = 20 - Volume Index = 0 - Offset = 89 - - */ - - void ParseConsoleOutputFromListFilesInArchive(const AZStd::string& consoleOutput, AZStd::vector& fileEntries) - { - AZStd::vector fileEntryData; - AzFramework::StringFunc::Tokenize(consoleOutput.c_str(), fileEntryData, "\r\n"); - for (size_t slotNum = 0; slotNum < fileEntryData.size(); ++slotNum) - { - AZStd::string& line = fileEntryData[slotNum]; - if (AzFramework::StringFunc::StartsWith(line, "Path = ")) - { - if ((slotNum + 1) < fileEntryData.size()) - { - // We're checking one past each entry we find for the Folder entry and skipping anything marked as a folder - // See sample output above - if (AzFramework::StringFunc::StartsWith(fileEntryData[slotNum + 1], "Folder = -")) - { - AzFramework::StringFunc::Replace(line, "Path = ", "", false, true); - fileEntries.emplace_back(AZStd::move(line)); - slotNum++; - } - } - } - } - } - } // namespace Platform -} // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/Platform/Windows/platform_windows_files.cmake b/Code/Framework/AzToolsFramework/Platform/Windows/platform_windows_files.cmake index d4fc29984c..c2c5a11c4c 100644 --- a/Code/Framework/AzToolsFramework/Platform/Windows/platform_windows_files.cmake +++ b/Code/Framework/AzToolsFramework/Platform/Windows/platform_windows_files.cmake @@ -7,5 +7,4 @@ # set(FILES - AzToolsFramework/Archive/ArchiveComponent_Windows.cpp ) diff --git a/Code/Framework/AzToolsFramework/Tests/ArchiveTests.cpp b/Code/Framework/AzToolsFramework/Tests/ArchiveTests.cpp index e7dad4b72f..66520c804c 100644 --- a/Code/Framework/AzToolsFramework/Tests/ArchiveTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/ArchiveTests.cpp @@ -31,7 +31,6 @@ namespace UnitTest { namespace { - bool CreateDummyFile(const QString& fullPathToFile, const QString& tempStr = {}) { QFileInfo fi(fullPathToFile); @@ -50,7 +49,7 @@ namespace UnitTest return true; } - class ArchiveTest : + class ArchiveComponentTest : public ::testing::Test { @@ -73,7 +72,12 @@ namespace UnitTest return "Archive"; } - void CreateArchiveFolder( QString archiveFolderName, QStringList fileList ) + QString GetExtractFolderName() + { + return "Extracted"; + } + + void CreateArchiveFolder(QString archiveFolderName, QStringList fileList) { QDir tempPath = QDir(m_tempDir.GetDirectory()).filePath(archiveFolderName); @@ -84,6 +88,14 @@ namespace UnitTest } } + QString CreateArchiveListTextFile() + { + QString listFilePath = QDir(m_tempDir.GetDirectory()).absoluteFilePath("FileList.txt"); + QString textContent = CreateArchiveFileList().join("\n"); + EXPECT_TRUE(CreateDummyFile(listFilePath, textContent)); + return listFilePath; + } + void CreateArchiveFolder() { CreateArchiveFolder(GetArchiveFolderName(), CreateArchiveFileList()); @@ -99,16 +111,24 @@ namespace UnitTest return QDir(m_tempDir.GetDirectory()).filePath(GetArchiveFolderName()); } + QString GetExtractFolder() + { + return QDir(m_tempDir.GetDirectory()).filePath(GetExtractFolderName()); + } + bool CreateArchive() { - bool createResult{ false }; - AzToolsFramework::ArchiveCommandsBus::BroadcastResult(createResult, &AzToolsFramework::ArchiveCommandsBus::Events::CreateArchiveBlocking, GetArchivePath().toStdString().c_str(), GetArchiveFolder().toStdString().c_str()); - return createResult; + std::future createResult; + AzToolsFramework::ArchiveCommandsBus::BroadcastResult(createResult, + &AzToolsFramework::ArchiveCommandsBus::Events::CreateArchive, + GetArchivePath().toUtf8().constData(), GetArchiveFolder().toUtf8().constData()); + bool result = createResult.get(); + return result; } void SetUp() override { - m_app.reset(aznew ToolsTestApplication("ArchiveTest")); + m_app.reset(aznew ToolsTestApplication("ArchiveComponentTest")); m_app->Start(AzFramework::Application::Descriptor()); // Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is // shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash @@ -132,76 +152,138 @@ namespace UnitTest }; #if AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS - TEST_F(ArchiveTest, DISABLED_CreateArchiveBlocking_FilesAtThreeDepths_ArchiveCreated) + TEST_F(ArchiveComponentTest, DISABLED_CreateArchive_FilesAtThreeDepths_ArchiveCreated) #else - TEST_F(ArchiveTest, CreateArchiveBlocking_FilesAtThreeDepths_ArchiveCreated) + TEST_F(ArchiveComponentTest, CreateArchive_FilesAtThreeDepths_ArchiveCreated) #endif // AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS { EXPECT_TRUE(m_tempDir.IsValid()); CreateArchiveFolder(); + AZ_TEST_START_TRACE_SUPPRESSION; bool createResult = CreateArchive(); + AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; - EXPECT_EQ(createResult, true); + EXPECT_TRUE(createResult); } #if AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS - TEST_F(ArchiveTest, DISABLED_ListFilesInArchiveBlocking_FilesAtThreeDepths_FilesFound) + TEST_F(ArchiveComponentTest, DISABLED_ListFilesInArchive_FilesAtThreeDepths_FilesFound) #else - TEST_F(ArchiveTest, ListFilesInArchiveBlocking_FilesAtThreeDepths_FilesFound) + TEST_F(ArchiveComponentTest, ListFilesInArchive_FilesAtThreeDepths_FilesFound) #endif // AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS { EXPECT_TRUE(m_tempDir.IsValid()); CreateArchiveFolder(); - + + AZ_TEST_START_TRACE_SUPPRESSION; EXPECT_EQ(CreateArchive(), true); AZStd::vector fileList; bool listResult{ false }; - AzToolsFramework::ArchiveCommandsBus::BroadcastResult(listResult, &AzToolsFramework::ArchiveCommandsBus::Events::ListFilesInArchiveBlocking, GetArchivePath().toStdString().c_str(), fileList); + AzToolsFramework::ArchiveCommandsBus::BroadcastResult(listResult, + &AzToolsFramework::ArchiveCommandsBus::Events::ListFilesInArchive, + GetArchivePath().toUtf8().constData(), fileList); + AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; + EXPECT_TRUE(listResult); EXPECT_EQ(fileList.size(), 6); } #if AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS - TEST_F(ArchiveTest, DISABLED_CreateDeltaCatalog_AssetsNotRegistered_Failure) + TEST_F(ArchiveComponentTest, DISABLED_CreateDeltaCatalog_AssetsNotRegistered_Failure) #else - TEST_F(ArchiveTest, CreateDeltaCatalog_AssetsNotRegistered_Failure) + TEST_F(ArchiveComponentTest, CreateDeltaCatalog_AssetsNotRegistered_Failure) #endif // AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS { QStringList fileList = CreateArchiveFileList(); CreateArchiveFolder(GetArchiveFolderName(), fileList); - + AZ_TEST_START_TRACE_SUPPRESSION; bool createResult = CreateArchive(); + AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; EXPECT_EQ(createResult, true); bool catalogCreated{ true }; AZ::Test::AssertAbsorber assertAbsorber; - AzToolsFramework::AssetBundleCommandsBus::BroadcastResult(catalogCreated, &AzToolsFramework::AssetBundleCommandsBus::Events::CreateDeltaCatalog, GetArchivePath().toStdString().c_str(), true); + AzToolsFramework::AssetBundleCommandsBus::BroadcastResult(catalogCreated, + &AzToolsFramework::AssetBundleCommandsBus::Events::CreateDeltaCatalog, GetArchivePath().toUtf8().constData(), true); EXPECT_EQ(catalogCreated, false); } #if AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS - TEST_F(ArchiveTest, DISABLED_CreateDeltaCatalog_ArchiveWithoutCatalogAssetsRegistered_Success) + TEST_F(ArchiveComponentTest, DISABLED_AddFilesToArchive_FromListFile_Success) #else - TEST_F(ArchiveTest, CreateDeltaCatalog_ArchiveWithoutCatalogAssetsRegistered_Success) + TEST_F(ArchiveComponentTest, AddFilesToArchive_FromListFile_Success) +#endif // AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS + { + QString listFile = CreateArchiveListTextFile(); + CreateArchiveFolder(GetArchiveFolderName(), CreateArchiveFileList()); + + AZ_TEST_START_TRACE_SUPPRESSION; + std::future addResult; + AzToolsFramework::ArchiveCommandsBus::BroadcastResult( + addResult, &AzToolsFramework::ArchiveCommandsBus::Events::AddFilesToArchive, GetArchivePath().toUtf8().constData(), + GetArchiveFolder().toUtf8().constData(), listFile.toUtf8().constData()); + bool result = addResult.get(); + AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; + + EXPECT_TRUE(result); + } + +#if AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS + TEST_F(ArchiveComponentTest, DISABLED_ExtractArchive_AllFiles_Success) +#else + TEST_F(ArchiveComponentTest, ExtractArchive_AllFiles_Success) +#endif // AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS + { + CreateArchiveFolder(); + AZ_TEST_START_TRACE_SUPPRESSION; + bool createResult = CreateArchive(); + AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; + EXPECT_TRUE(createResult); + + AZ_TEST_START_TRACE_SUPPRESSION; + std::future extractResult; + AzToolsFramework::ArchiveCommandsBus::BroadcastResult( + extractResult, &AzToolsFramework::ArchiveCommandsBus::Events::ExtractArchive, GetArchivePath().toUtf8().constData(), + GetExtractFolder().toUtf8().constData()); + bool result = extractResult.get(); + AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; + + EXPECT_TRUE(result); + + QStringList archiveFiles = CreateArchiveFileList(); + for (const auto& file : archiveFiles) + { + QString fullFilePath = QDir(GetExtractFolder()).absoluteFilePath(file); + QFileInfo fi(fullFilePath); + EXPECT_TRUE(fi.exists()); + } + } + +#if AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS + TEST_F(ArchiveComponentTest, DISABLED_CreateDeltaCatalog_ArchiveWithoutCatalogAssetsRegistered_Success) +#else + TEST_F(ArchiveComponentTest, CreateDeltaCatalog_ArchiveWithoutCatalogAssetsRegistered_Success) #endif // AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS { QStringList fileList = CreateArchiveFileList(); CreateArchiveFolder(GetArchiveFolderName(), fileList); + AZ_TEST_START_TRACE_SUPPRESSION; bool createResult = CreateArchive(); + AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; EXPECT_EQ(createResult, true); for (const auto& thisPath : fileList) { AZ::Data::AssetInfo newInfo; - newInfo.m_relativePath = thisPath.toStdString().c_str(); + newInfo.m_relativePath = thisPath.toUtf8().constData(); newInfo.m_assetType = AZ::Uuid::CreateRandom(); newInfo.m_sizeBytes = 100; // Arbitrary AZ::Data::AssetId generatedID(AZ::Uuid::CreateRandom()); @@ -212,7 +294,7 @@ namespace UnitTest bool catalogCreated{ false }; AZ_TEST_START_TRACE_SUPPRESSION; - AzToolsFramework::AssetBundleCommandsBus::BroadcastResult(catalogCreated, &AzToolsFramework::AssetBundleCommandsBus::Events::CreateDeltaCatalog, GetArchivePath().toStdString().c_str(), true); + AzToolsFramework::AssetBundleCommandsBus::BroadcastResult(catalogCreated, &AzToolsFramework::AssetBundleCommandsBus::Events::CreateDeltaCatalog, GetArchivePath().toUtf8().constData(), true); AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // produces different counts in different platforms EXPECT_EQ(catalogCreated, true); } diff --git a/Code/Framework/AzToolsFramework/Tests/Prefab/Benchmark/PrefabCreateBenchmarks.cpp b/Code/Framework/AzToolsFramework/Tests/Prefab/Benchmark/PrefabCreateBenchmarks.cpp index 64c4058a47..8cc5e5f4d2 100644 --- a/Code/Framework/AzToolsFramework/Tests/Prefab/Benchmark/PrefabCreateBenchmarks.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Prefab/Benchmark/PrefabCreateBenchmarks.cpp @@ -72,7 +72,7 @@ namespace Benchmark AZStd::unique_ptr instance = m_prefabSystemComponent->CreatePrefab( entities , {} - , m_pathString); + , m_pathString); state.PauseTiming(); @@ -165,7 +165,7 @@ namespace Benchmark { nestedInstanceRoot = m_prefabSystemComponent->CreatePrefab( {}, - MakeInstanceList( AZStd::move(nestedInstanceRoot) ), + MakeInstanceList(AZStd::move(nestedInstanceRoot)), m_paths[instanceCounter]); } diff --git a/Code/Framework/AzToolsFramework/Tests/Prefab/Benchmark/PrefabUpdateInstancesBenchmarks.cpp b/Code/Framework/AzToolsFramework/Tests/Prefab/Benchmark/PrefabUpdateInstancesBenchmarks.cpp index 0d95049e76..92a30b89f2 100644 --- a/Code/Framework/AzToolsFramework/Tests/Prefab/Benchmark/PrefabUpdateInstancesBenchmarks.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Prefab/Benchmark/PrefabUpdateInstancesBenchmarks.cpp @@ -36,7 +36,7 @@ namespace Benchmark AZStd::unique_ptr enclosingInstance = m_prefabSystemComponent->CreatePrefab( {}, - MakeInstanceList( AZStd::move(nestedInstance) ), + MakeInstanceList(AZStd::move(nestedInstance)), enclosingTemplatePath); TemplateId templateToInstantiateId = enclosingInstance->GetTemplateId(); @@ -99,7 +99,7 @@ namespace Benchmark { currentInstanceRoot = m_prefabSystemComponent->CreatePrefab( {}, - MakeInstanceList( AZStd::move(currentInstanceRoot) ), + MakeInstanceList(AZStd::move(currentInstanceRoot)), m_paths[currentDepth - 1]); } @@ -151,7 +151,7 @@ namespace Benchmark { currentInstanceRoot = m_prefabSystemComponent->CreatePrefab( {}, - MakeInstanceList( AZStd::move(currentInstanceRoot) ), + MakeInstanceList(AZStd::move(currentInstanceRoot)), m_paths[currentDepth]); } @@ -214,7 +214,7 @@ namespace Benchmark currentInstanceRoot = m_prefabSystemComponent->CreatePrefab( {}, - MakeInstanceList( AZStd::move(currentInstanceRoot), AZStd::move(extraNestedInstance) ), + MakeInstanceList(AZStd::move(currentInstanceRoot), AZStd::move(extraNestedInstance)), m_paths[currentDepth]); } diff --git a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabFocus/PrefabFocusTests.cpp b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabFocus/PrefabFocusTests.cpp index 14eee84b7d..72489b07a1 100644 --- a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabFocus/PrefabFocusTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabFocus/PrefabFocusTests.cpp @@ -54,7 +54,7 @@ namespace UnitTest // Create a street prefab that nests the car and sportscar instances created above. The container entity will be created as part of the process. AZStd::unique_ptr streetInstance = - m_prefabSystemComponent->CreatePrefab({}, MakeInstanceList( AZStd::move(carInstance), AZStd::move(sportsCarInstance) ), "test/street"); + m_prefabSystemComponent->CreatePrefab({}, MakeInstanceList(AZStd::move(carInstance), AZStd::move(sportsCarInstance)), "test/street"); ASSERT_TRUE(streetInstance); m_instanceMap[StreetEntityName] = streetInstance.get(); diff --git a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabInstanceToTemplatePropagatorTests.cpp b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabInstanceToTemplatePropagatorTests.cpp index ebe35a5402..a08b0bf6c2 100644 --- a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabInstanceToTemplatePropagatorTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabInstanceToTemplatePropagatorTests.cpp @@ -320,7 +320,7 @@ namespace UnitTest Instance& addedInstance = *addedInstancePtr; //create a first instance where the instance will be removed - AZStd::unique_ptr firstInstance = m_prefabSystemComponent->CreatePrefab({}, MakeInstanceList( AZStd::move(addedInstancePtr) ), "test/path"); + AZStd::unique_ptr firstInstance = m_prefabSystemComponent->CreatePrefab({}, MakeInstanceList(AZStd::move(addedInstancePtr)), "test/path"); ASSERT_TRUE(firstInstance); //get added instance alias diff --git a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabInstantiateTests.cpp b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabInstantiateTests.cpp index 09aac8dcf5..cc8217a915 100644 --- a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabInstantiateTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabInstantiateTests.cpp @@ -44,11 +44,11 @@ namespace UnitTest ASSERT_TRUE(firstInstance); AZStd::unique_ptr secondInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(firstInstance) ), "test/path2"); + MakeInstanceList(AZStd::move(firstInstance)), "test/path2"); ASSERT_TRUE(secondInstance); AZStd::unique_ptr thirdInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(secondInstance) ), "test/path3"); + MakeInstanceList(AZStd::move(secondInstance)), "test/path3"); ASSERT_TRUE(thirdInstance); //Instantiate it diff --git a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDataUtils.cpp b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDataUtils.cpp index b805e224bf..55e3c158a1 100644 --- a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDataUtils.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDataUtils.cpp @@ -21,8 +21,8 @@ namespace UnitTest using namespace AzToolsFramework::Prefab; LinkData CreateLinkData( const InstanceData& instanceData, - const TemplateId& sourceTemplateId, - const TemplateId& targetTemplateId) + TemplateId sourceTemplateId, + TemplateId targetTemplateId) { LinkData newLinkData; newLinkData.m_instanceData = instanceData; diff --git a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDataUtils.h b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDataUtils.h index e3048469c5..0082ad5951 100644 --- a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDataUtils.h +++ b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDataUtils.h @@ -17,8 +17,8 @@ namespace UnitTest { LinkData CreateLinkData( const InstanceData& instanceData, - const AzToolsFramework::Prefab::TemplateId& sourceTemplateId, - const AzToolsFramework::Prefab::TemplateId& targetTemplateId); + AzToolsFramework::Prefab::TemplateId sourceTemplateId, + AzToolsFramework::Prefab::TemplateId targetTemplateId); InstanceData CreateInstanceDataWithNoPatches( const AZStd::string& name, diff --git a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDomUtils.cpp b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDomUtils.cpp index 334f01fc3a..c71013320f 100644 --- a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDomUtils.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDomUtils.cpp @@ -56,7 +56,7 @@ namespace UnitTest } void ValidateInstances( - const TemplateId& templateId, + TemplateId templateId, const PrefabDomValue& expectedContent, const PrefabDomPath& contentPath, bool isContentAnInstance, @@ -204,7 +204,7 @@ namespace UnitTest } void ValidateEntitiesOfInstances( - const AzToolsFramework::Prefab::TemplateId& templateId, + AzToolsFramework::Prefab::TemplateId templateId, const AzToolsFramework::Prefab::PrefabDom& expectedPrefabDom, const AZStd::vector& entityAliases) { @@ -219,7 +219,7 @@ namespace UnitTest } void ValidateNestedInstancesOfInstances( - const AzToolsFramework::Prefab::TemplateId& templateId, + AzToolsFramework::Prefab::TemplateId templateId, const AzToolsFramework::Prefab::PrefabDom& expectedPrefabDom, const AZStd::vector& nestedInstanceAliases) { diff --git a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDomUtils.h b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDomUtils.h index f90a91ea3c..b1ba7fbca0 100644 --- a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDomUtils.h +++ b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestDomUtils.h @@ -118,7 +118,7 @@ namespace UnitTest const PrefabDomValue& patches); void ValidateInstances( - const TemplateId& templateId, + TemplateId templateId, const PrefabDomValue& expectedContent, const PrefabDomPath& contentPath, bool isContentAnInstance = false, @@ -147,12 +147,12 @@ namespace UnitTest void ComparePrefabDomValues(PrefabDomValueConstReference valueA, PrefabDomValueConstReference valueB); void ValidateEntitiesOfInstances( - const AzToolsFramework::Prefab::TemplateId& templateId, + AzToolsFramework::Prefab::TemplateId templateId, const AzToolsFramework::Prefab::PrefabDom& expectedPrefabDom, const AZStd::vector& entityAliases); void ValidateNestedInstancesOfInstances( - const AzToolsFramework::Prefab::TemplateId& templateId, + AzToolsFramework::Prefab::TemplateId templateId, const AzToolsFramework::Prefab::PrefabDom& expectedPrefabDom, const AZStd::vector& nestedInstanceAliases); diff --git a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestUndoFixture.cpp b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestUndoFixture.cpp index cb44f9c401..2420b14d6c 100644 --- a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestUndoFixture.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabTestUndoFixture.cpp @@ -18,14 +18,14 @@ namespace UnitTest { //create two prefabs for test //create prefab 1 - firstInstance = AZStd::move(m_prefabSystemComponent->CreatePrefab({ }, {}, "test/path0")); + firstInstance = AZStd::move(m_prefabSystemComponent->CreatePrefab({}, {}, "test/path0")); ASSERT_TRUE(firstInstance); //get template id ownerId = firstInstance->GetTemplateId(); //create prefab 2 - secondInstance = AZStd::move(m_prefabSystemComponent->CreatePrefab({ }, {}, "test/path1")); + secondInstance = AZStd::move(m_prefabSystemComponent->CreatePrefab({}, {}, "test/path1")); ASSERT_TRUE(secondInstance); //get template id diff --git a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabUpdateInstancesTests.cpp b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabUpdateInstancesTests.cpp index baded6d43e..7427c06f43 100644 --- a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabUpdateInstancesTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabUpdateInstancesTests.cpp @@ -120,7 +120,7 @@ namespace UnitTest // Create an enclosing Template with 0 entities and 1 nested Instance. AZStd::unique_ptr nestedInstance1 = m_prefabSystemComponent->InstantiatePrefab(newNestedTemplateId); - AZStd::unique_ptr newEnclosingInstance = m_prefabSystemComponent->CreatePrefab({}, MakeInstanceList( AZStd::move(nestedInstance1) ), PrefabMockFilePath); + AZStd::unique_ptr newEnclosingInstance = m_prefabSystemComponent->CreatePrefab({}, MakeInstanceList(AZStd::move(nestedInstance1)), PrefabMockFilePath); TemplateId newEnclosingTemplateId = newEnclosingInstance->GetTemplateId(); EXPECT_TRUE(newEnclosingTemplateId != InvalidTemplateId); PrefabDom& newEnclosingTemplateDom = m_prefabSystemComponent->FindTemplateDom(newEnclosingTemplateId); @@ -284,7 +284,7 @@ namespace UnitTest AZStd::unique_ptr nestedInstance2 = m_prefabSystemComponent->InstantiatePrefab(newNestedTemplateId); AZStd::unique_ptr newEnclosingInstance = m_prefabSystemComponent->CreatePrefab( {}, - MakeInstanceList( AZStd::move(nestedInstance1), AZStd::move(nestedInstance2) ), + MakeInstanceList(AZStd::move(nestedInstance1), AZStd::move(nestedInstance2)), PrefabMockFilePath); TemplateId newEnclosingTemplateId = newEnclosingInstance->GetTemplateId(); EXPECT_TRUE(newEnclosingTemplateId != InvalidTemplateId); diff --git a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabUpdateTemplateTests.cpp b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabUpdateTemplateTests.cpp index 6f90e245f7..242c226c7e 100644 --- a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabUpdateTemplateTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabUpdateTemplateTests.cpp @@ -41,7 +41,7 @@ namespace UnitTest AZStd::unique_ptr wheel1UnderAxle = m_prefabSystemComponent->InstantiatePrefab(wheelTemplateId); AZStd::unique_ptr wheel2UnderAxle = m_prefabSystemComponent->InstantiatePrefab(wheelTemplateId); AZStd::unique_ptr axleInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(wheel1UnderAxle), AZStd::move(wheel2UnderAxle) ), AxlePrefabMockFilePath); + MakeInstanceList(AZStd::move(wheel1UnderAxle), AZStd::move(wheel2UnderAxle)), AxlePrefabMockFilePath); const TemplateId axleTemplateId = axleInstance->GetTemplateId(); const AZStd::vector wheelInstanceAliasesUnderAxle = axleInstance->GetNestedInstanceAliases(wheelTemplateId); PrefabDom& axleTemplateDom = m_prefabSystemComponent->FindTemplateDom(axleTemplateId); @@ -51,7 +51,7 @@ namespace UnitTest AZStd::unique_ptr axle2UnderCar = m_prefabSystemComponent->InstantiatePrefab(axleTemplateId); AZStd::unique_ptr spareWheelUnderCar = m_prefabSystemComponent->InstantiatePrefab(wheelTemplateId); AZStd::unique_ptr carInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(axle1UnderCar), AZStd::move(axle2UnderCar), AZStd::move(spareWheelUnderCar) ), CarPrefabMockFilePath); + MakeInstanceList(AZStd::move(axle1UnderCar), AZStd::move(axle2UnderCar), AZStd::move(spareWheelUnderCar)), CarPrefabMockFilePath); const TemplateId carTemplateId = carInstance->GetTemplateId(); const AZStd::vector axleInstanceAliasesUnderCar = carInstance->GetNestedInstanceAliases(axleTemplateId); const AZStd::vector wheelInstanceAliasesUnderCar = carInstance->GetNestedInstanceAliases(wheelTemplateId); @@ -93,7 +93,7 @@ namespace UnitTest // Create an axle with 0 entities and 1 wheel instance. AZStd::unique_ptr wheel1UnderAxle = m_prefabSystemComponent->InstantiatePrefab(wheelTemplateId); AZStd::unique_ptr axleInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(wheel1UnderAxle) ), AxlePrefabMockFilePath); + MakeInstanceList(AZStd::move(wheel1UnderAxle)), AxlePrefabMockFilePath); const TemplateId axleTemplateId = axleInstance->GetTemplateId(); PrefabDom& axleTemplateDom = m_prefabSystemComponent->FindTemplateDom(axleTemplateId); AZStd::vector wheelInstanceAliasesUnderAxle = axleInstance->GetNestedInstanceAliases(wheelTemplateId); @@ -105,7 +105,7 @@ namespace UnitTest AZStd::unique_ptr axle1UnderCar = m_prefabSystemComponent->InstantiatePrefab(axleTemplateId); AZStd::unique_ptr axle2UnderCar = m_prefabSystemComponent->InstantiatePrefab(axleTemplateId); AZStd::unique_ptr carInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(axle1UnderCar), AZStd::move(axle2UnderCar) ), CarPrefabMockFilePath); + MakeInstanceList(AZStd::move(axle1UnderCar), AZStd::move(axle2UnderCar)), CarPrefabMockFilePath); const TemplateId carTemplateId = carInstance->GetTemplateId(); const AZStd::vector axleInstanceAliasesUnderCar = carInstance->GetNestedInstanceAliases(axleTemplateId); PrefabDom& carTemplateDom = m_prefabSystemComponent->FindTemplateDom(carTemplateId); @@ -151,7 +151,7 @@ namespace UnitTest // Create an axle with 0 entities and 1 wheel instance. AZStd::unique_ptr wheel1UnderAxle = m_prefabSystemComponent->InstantiatePrefab(wheelTemplateId); AZStd::unique_ptr axleInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(wheel1UnderAxle) ), AxlePrefabMockFilePath); + MakeInstanceList(AZStd::move(wheel1UnderAxle)), AxlePrefabMockFilePath); const TemplateId axleTemplateId = axleInstance->GetTemplateId(); PrefabDom& axleTemplateDom = m_prefabSystemComponent->FindTemplateDom(axleTemplateId); const AZStd::vector wheelInstanceAliasesUnderAxle = axleInstance->GetNestedInstanceAliases(wheelTemplateId); @@ -159,7 +159,7 @@ namespace UnitTest // Create a car with 0 entities and 1 axle instance. AZStd::unique_ptr axleUnderCar = m_prefabSystemComponent->InstantiatePrefab(axleTemplateId); AZStd::unique_ptr carInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(axleUnderCar) ), CarPrefabMockFilePath); + MakeInstanceList(AZStd::move(axleUnderCar)), CarPrefabMockFilePath); const TemplateId carTemplateId = carInstance->GetTemplateId(); const AZStd::vector axleInstanceAliasesUnderCar = carInstance->GetNestedInstanceAliases(axleTemplateId); PrefabDom& carTemplateDom = m_prefabSystemComponent->FindTemplateDom(carTemplateId); @@ -205,7 +205,7 @@ namespace UnitTest // Create an axle with 0 entities and 1 wheel instance. AZStd::unique_ptr wheel1UnderAxle = m_prefabSystemComponent->InstantiatePrefab(wheelTemplateId); AZStd::unique_ptr axleInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(wheel1UnderAxle) ), AxlePrefabMockFilePath); + MakeInstanceList(AZStd::move(wheel1UnderAxle)), AxlePrefabMockFilePath); const TemplateId axleTemplateId = axleInstance->GetTemplateId(); PrefabDom& axleTemplateDom = m_prefabSystemComponent->FindTemplateDom(axleTemplateId); const AZStd::vector wheelInstanceAliasesUnderAxle = axleInstance->GetNestedInstanceAliases(wheelTemplateId); @@ -213,7 +213,7 @@ namespace UnitTest // Create a car with 0 entities and 1 axle instance. AZStd::unique_ptr axleUnderCar = m_prefabSystemComponent->InstantiatePrefab(axleTemplateId); AZStd::unique_ptr carInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(axleUnderCar) ), CarPrefabMockFilePath); + MakeInstanceList(AZStd::move(axleUnderCar)), CarPrefabMockFilePath); const TemplateId carTemplateId = carInstance->GetTemplateId(); const AZStd::vector axleInstanceAliasesUnderCar = carInstance->GetNestedInstanceAliases(axleTemplateId); PrefabDom& carTemplateDom = m_prefabSystemComponent->FindTemplateDom(carTemplateId); @@ -253,7 +253,7 @@ namespace UnitTest AZStd::unique_ptr wheel1UnderAxle = m_prefabSystemComponent->InstantiatePrefab(wheelTemplateId); AZStd::unique_ptr wheel2UnderAxle = m_prefabSystemComponent->InstantiatePrefab(wheelTemplateId); AZStd::unique_ptr axleInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(wheel1UnderAxle), AZStd::move(wheel2UnderAxle) ), + MakeInstanceList(AZStd::move(wheel1UnderAxle), AZStd::move(wheel2UnderAxle) ), AxlePrefabMockFilePath); const TemplateId axleTemplateId = axleInstance->GetTemplateId(); PrefabDom& axleTemplateDom = m_prefabSystemComponent->FindTemplateDom(axleTemplateId); @@ -265,7 +265,7 @@ namespace UnitTest // Create a car with 0 entities and 1 axle instance. AZStd::unique_ptr axle1UnderCar = m_prefabSystemComponent->InstantiatePrefab(axleTemplateId); AZStd::unique_ptr carInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(axle1UnderCar) ), CarPrefabMockFilePath); + MakeInstanceList(AZStd::move(axle1UnderCar)), CarPrefabMockFilePath); const TemplateId carTemplateId = carInstance->GetTemplateId(); const AZStd::vector axleInstanceAliasesUnderCar = carInstance->GetNestedInstanceAliases(axleTemplateId); PrefabDom& carTemplateDom = m_prefabSystemComponent->FindTemplateDom(carTemplateId); @@ -320,7 +320,7 @@ namespace UnitTest // Create an axle with 0 entities and 1 wheel instance. AZStd::unique_ptr wheel1UnderAxle = m_prefabSystemComponent->InstantiatePrefab(wheelTemplateId); AZStd::unique_ptr axleInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(wheel1UnderAxle) ), AxlePrefabMockFilePath); + MakeInstanceList(AZStd::move(wheel1UnderAxle)), AxlePrefabMockFilePath); const TemplateId axleTemplateId = axleInstance->GetTemplateId(); PrefabDom& axleTemplateDom = m_prefabSystemComponent->FindTemplateDom(axleTemplateId); const AZStd::vector wheelInstanceAliasesUnderAxle = axleInstance->GetNestedInstanceAliases(wheelTemplateId); @@ -328,7 +328,7 @@ namespace UnitTest // Create a car with 0 entities and 1 axle instance. AZStd::unique_ptr axleUnderCar = m_prefabSystemComponent->InstantiatePrefab(axleTemplateId); AZStd::unique_ptr carInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(axleUnderCar) ), CarPrefabMockFilePath); + MakeInstanceList(AZStd::move(axleUnderCar)), CarPrefabMockFilePath); const TemplateId carTemplateId = carInstance->GetTemplateId(); const AZStd::vector axleInstanceAliasesUnderCar = carInstance->GetNestedInstanceAliases(axleTemplateId); PrefabDom& carTemplateDom = m_prefabSystemComponent->FindTemplateDom(carTemplateId); @@ -381,7 +381,7 @@ namespace UnitTest // Create an axle with 0 entities and 1 wheel instance. AZStd::unique_ptr wheel1UnderAxle = m_prefabSystemComponent->InstantiatePrefab(wheelTemplateId); AZStd::unique_ptr axleInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(wheel1UnderAxle) ), AxlePrefabMockFilePath); + MakeInstanceList(AZStd::move(wheel1UnderAxle)), AxlePrefabMockFilePath); const TemplateId axleTemplateId = axleInstance->GetTemplateId(); PrefabDom& axleTemplateDom = m_prefabSystemComponent->FindTemplateDom(axleTemplateId); const AZStd::vector wheelInstanceAliasesUnderAxle = axleInstance->GetNestedInstanceAliases(wheelTemplateId); @@ -389,7 +389,7 @@ namespace UnitTest // Create a car with 0 entities and 1 axle instance. AZStd::unique_ptr axleUnderCar = m_prefabSystemComponent->InstantiatePrefab(axleTemplateId); AZStd::unique_ptr carInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(axleUnderCar) ), CarPrefabMockFilePath); + MakeInstanceList(AZStd::move(axleUnderCar)), CarPrefabMockFilePath); const TemplateId carTemplateId = carInstance->GetTemplateId(); const AZStd::vector axleInstanceAliasesUnderCar = carInstance->GetNestedInstanceAliases(axleTemplateId); PrefabDom& carTemplateDom = m_prefabSystemComponent->FindTemplateDom(carTemplateId); diff --git a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabUpdateWithPatchesTests.cpp b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabUpdateWithPatchesTests.cpp index c17763f778..1fa638bc29 100644 --- a/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabUpdateWithPatchesTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Prefab/PrefabUpdateWithPatchesTests.cpp @@ -68,7 +68,7 @@ namespace UnitTest // Create a car with 0 entities and 1 axle instance. AZStd::unique_ptr axleUnderCar = m_prefabSystemComponent->InstantiatePrefab(axleTemplateId); AZStd::unique_ptr carInstance = m_prefabSystemComponent->CreatePrefab({}, - MakeInstanceList( AZStd::move(axleUnderCar) ), CarPrefabMockFilePath); + MakeInstanceList(AZStd::move(axleUnderCar)), CarPrefabMockFilePath); const TemplateId carTemplateId = carInstance->GetTemplateId(); const AZStd::vector axleInstanceAliasesUnderCar = carInstance->GetNestedInstanceAliases(axleTemplateId); PrefabDom& carTemplateDom = m_prefabSystemComponent->FindTemplateDom(carTemplateId); diff --git a/Code/Framework/GridMate/GridMate/Carrier/Carrier.cpp b/Code/Framework/GridMate/GridMate/Carrier/Carrier.cpp index 095f392501..2922cc2891 100644 --- a/Code/Framework/GridMate/GridMate/Carrier/Carrier.cpp +++ b/Code/Framework/GridMate/GridMate/Carrier/Carrier.cpp @@ -1316,7 +1316,7 @@ CarrierThread::CarrierThread(const CarrierDesc& desc, AZStd::shared_ptr(&DetachEnvironment); } -#endif // !defined(SOFTCODE) - bool g_bProfilerEnabled = false; ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Tools/AssetBundler/source/models/SeedListTableModel.cpp b/Code/Tools/AssetBundler/source/models/SeedListTableModel.cpp index 86818432bc..e0b9d9f5d8 100644 --- a/Code/Tools/AssetBundler/source/models/SeedListTableModel.cpp +++ b/Code/Tools/AssetBundler/source/models/SeedListTableModel.cpp @@ -69,7 +69,8 @@ namespace AssetBundler assetInfo = AzToolsFramework::AssetSeedManager::GetAssetInfoById( seed.m_assetId, AzFramework::PlatformHelper::GetPlatformIndicesInterpreted(seed.m_platformFlags)[0], - absolutePath); + absolutePath, + seed.m_assetRelativePath); platformList = QString(m_seedListManager->GetReadablePlatformList(seed).c_str()); m_additionalSeedInfoMap[seed.m_assetId].reset(new AdditionalSeedInfo(assetInfo.m_relativePath.c_str(), platformList)); diff --git a/Code/Tools/AssetProcessor/AssetBuilder/AssetBuilderComponent.cpp b/Code/Tools/AssetProcessor/AssetBuilder/AssetBuilderComponent.cpp index eb6cc4033c..42a43ef84e 100644 --- a/Code/Tools/AssetProcessor/AssetBuilder/AssetBuilderComponent.cpp +++ b/Code/Tools/AssetProcessor/AssetBuilder/AssetBuilderComponent.cpp @@ -411,7 +411,7 @@ bool AssetBuilderComponent::RunInResidentMode() m_running = true; m_jobThreadDesc.m_name = "Builder Job Thread"; - m_jobThread = AZStd::thread(AZStd::bind(&AssetBuilderComponent::JobThread, this), &m_jobThreadDesc); + m_jobThread = AZStd::thread(m_jobThreadDesc, AZStd::bind(&AssetBuilderComponent::JobThread, this)); AzFramework::EngineConnectionEvents::Bus::Handler::BusConnect(); // Listen for disconnects diff --git a/Code/Tools/AssetProcessor/native/tests/AssetCatalog/AssetCatalogUnitTests.cpp b/Code/Tools/AssetProcessor/native/tests/AssetCatalog/AssetCatalogUnitTests.cpp index 4257457291..5d2d0e77d3 100644 --- a/Code/Tools/AssetProcessor/native/tests/AssetCatalog/AssetCatalogUnitTests.cpp +++ b/Code/Tools/AssetProcessor/native/tests/AssetCatalog/AssetCatalogUnitTests.cpp @@ -1063,10 +1063,10 @@ namespace AssetProcessor AZStd::thread_desc threadDesc; threadDesc.m_name = "AssetCatalog Thread"; - AZStd::thread catalogThread([this]() + AZStd::thread catalogThread(threadDesc, [this]() { m_data->m_assetCatalog->BuildRegistry(); - }, &threadDesc + } ); AssetNotificationMessage message("some/path/image.png", AssetNotificationMessage::NotificationType::AssetChanged, AZ::Data::AssetType::CreateRandom(), "pc"); diff --git a/Code/Tools/AssetProcessor/native/utilities/AssetServerHandler.cpp b/Code/Tools/AssetProcessor/native/utilities/AssetServerHandler.cpp index 3d87c11488..3fa4b1cacd 100644 --- a/Code/Tools/AssetProcessor/native/utilities/AssetServerHandler.cpp +++ b/Code/Tools/AssetProcessor/native/utilities/AssetServerHandler.cpp @@ -74,8 +74,11 @@ namespace AssetProcessor AZ_TracePrintf(AssetProcessor::DebugChannel, "Extracting archive for job (%s, %s, %s) with fingerprint (%u).\n", builderParams.m_rcJob->GetJobEntry().m_pathRelativeToWatchFolder.toUtf8().data(), builderParams.m_rcJob->GetJobKey().toUtf8().data(), builderParams.m_rcJob->GetPlatformInfo().m_identifier.c_str(), builderParams.m_rcJob->GetOriginalFingerprint()); - bool success = false; - AzToolsFramework::ArchiveCommands::Bus::BroadcastResult(success, &AzToolsFramework::ArchiveCommands::ExtractArchiveBlocking, archiveAbsFilePath.toUtf8().data(), builderParams.GetTempJobDirectory(), false); + std::future extractResult; + AzToolsFramework::ArchiveCommandsBus::BroadcastResult(extractResult, + &AzToolsFramework::ArchiveCommandsBus::Events::ExtractArchive, + archiveAbsFilePath.toUtf8().data(), builderParams.GetTempJobDirectory()); + bool success = extractResult.get(); AZ_Error(AssetProcessor::DebugChannel, success, "Extracting archive operation failed.\n"); return success; } @@ -106,12 +109,15 @@ namespace AssetProcessor return false; } - bool success = false; - AZ_TracePrintf(AssetProcessor::DebugChannel, "Creating archive for job (%s, %s, %s) with fingerprint (%u).\n", builderParams.m_rcJob->GetJobEntry().m_pathRelativeToWatchFolder.toUtf8().data(), builderParams.m_rcJob->GetJobKey().toUtf8().data(), builderParams.m_rcJob->GetPlatformInfo().m_identifier.c_str(), builderParams.m_rcJob->GetOriginalFingerprint()); - AzToolsFramework::ArchiveCommands::Bus::BroadcastResult(success, &AzToolsFramework::ArchiveCommands::CreateArchiveBlocking, archiveAbsFilePath.toUtf8().data(), builderParams.GetTempJobDirectory()); + + std::future createResult; + AzToolsFramework::ArchiveCommandsBus::BroadcastResult(createResult, + &AzToolsFramework::ArchiveCommandsBus::Events::CreateArchive, + archiveAbsFilePath.toUtf8().data(), builderParams.GetTempJobDirectory()); + bool success = createResult.get(); AZ_Error(AssetProcessor::DebugChannel, success, "Creating archive operation failed. \n"); if (success && sourceFileList.size()) @@ -137,14 +143,16 @@ namespace AssetProcessor allSuccess = false; continue; } - bool success{ false }; - AzToolsFramework::ArchiveCommands::Bus::BroadcastResult(success, &AzToolsFramework::ArchiveCommands::AddFileToArchiveBlocking, archivePath.toUtf8().data(), sourceDir.path().toUtf8().data(), thisProduct.c_str()); + std::future addResult; + AzToolsFramework::ArchiveCommandsBus::BroadcastResult(addResult, + &AzToolsFramework::ArchiveCommandsBus::Events::AddFileToArchive, + archivePath.toUtf8().data(), sourceDir.path().toUtf8().data(), thisProduct.c_str()); + bool success = addResult.get(); if (!success) { AZ_Warning(AssetProcessor::DebugChannel, false, "Failed to add %s to %s", thisProduct.c_str(), archivePath.toUtf8().data()); allSuccess = false; } - } return allSuccess; } diff --git a/Code/Tools/AssetProcessor/native/utilities/assetUtils.cpp b/Code/Tools/AssetProcessor/native/utilities/assetUtils.cpp index c0e907f2d5..cacd6c4cc9 100644 --- a/Code/Tools/AssetProcessor/native/utilities/assetUtils.cpp +++ b/Code/Tools/AssetProcessor/native/utilities/assetUtils.cpp @@ -164,7 +164,10 @@ namespace AssetUtilsInternal AZ::SettingsRegistryMergeUtils::DumperSettings apDumperSettings; apDumperSettings.m_prettifyOutput = true; + AZ_PUSH_DISABLE_WARNING(5233, "-Wunknown-warning-option") // Older versions of MSVC toolchain require to pass constexpr in the + // capture. Newer versions issue unused warning apDumperSettings.m_includeFilter = [&AssetProcessorUserSettingsRootKey](AZStd::string_view path) + AZ_POP_DISABLE_WARNING { // The AssetUtils only updates the following keys in the registry // Dump them all out to the setreg file diff --git a/Code/Tools/RemoteConsole/Core/RemoteConsoleCore.cpp b/Code/Tools/RemoteConsole/Core/RemoteConsoleCore.cpp index 0a8d9d8eb7..f0c1d765e5 100644 --- a/Code/Tools/RemoteConsole/Core/RemoteConsoleCore.cpp +++ b/Code/Tools/RemoteConsole/Core/RemoteConsoleCore.cpp @@ -99,7 +99,7 @@ void SRemoteThreadedObject::Start(const char* name) desc.m_name = name; auto function = AZStd::bind(&SRemoteThreadedObject::ThreadFunction, this); - m_thread = AZStd::thread(function, &desc); + m_thread = AZStd::thread(desc, function); } void SRemoteThreadedObject::WaitForThread() diff --git a/Code/Tools/SerializeContextTools/SliceConverter.cpp b/Code/Tools/SerializeContextTools/SliceConverter.cpp index df4f394cc5..c815af3b7a 100644 --- a/Code/Tools/SerializeContextTools/SliceConverter.cpp +++ b/Code/Tools/SerializeContextTools/SliceConverter.cpp @@ -558,7 +558,7 @@ namespace AZ AZStd::string instanceAlias = GetInstanceAlias(instance); // Create a new unmodified prefab Instance for the nested slice instance. - auto nestedInstance = AZStd::make_unique(); + auto nestedInstance = AZStd::make_unique(AZStd::move(instanceAlias)); AzToolsFramework::Prefab::Instance::EntityList newEntities; if (!AzToolsFramework::Prefab::PrefabDomUtils::LoadInstanceFromPrefabDom( *nestedInstance, newEntities, nestedTemplate->get().GetPrefabDom())) @@ -742,7 +742,7 @@ namespace AZ instanceToTemplateInterface->GenerateDomForInstance(topLevelInstanceDomBefore, *topLevelInstance); // Use the deterministic instance alias for this new instance - AzToolsFramework::Prefab::Instance& addedInstance = topLevelInstance->AddInstance(AZStd::move(nestedInstance), instanceAlias); + AzToolsFramework::Prefab::Instance& addedInstance = topLevelInstance->AddInstance(AZStd::move(nestedInstance)); AzToolsFramework::Prefab::PrefabDom topLevelInstanceDomAfter; instanceToTemplateInterface->GenerateDomForInstance(topLevelInstanceDomAfter, *topLevelInstance); diff --git a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestRunSuiteFactory.cpp b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestRunSuiteFactory.cpp index b7a44d43ea..f39cfaaf10 100644 --- a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestRunSuiteFactory.cpp +++ b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestRunSuiteFactory.cpp @@ -64,9 +64,11 @@ namespace TestImpact return !name.starts_with("DISABLED_") && name.find("/DISABLED_") == AZStd::string::npos; }; + AZ_PUSH_DISABLE_WARNING(5233, "-Wunknown-warning-option") // Older versions of MSVC toolchain require to pass constexpr + // in the capture. Newer versions issue unused warning const auto getDuration = [Keys](const AZ::rapidxml::xml_node<>* node) + AZ_POP_DISABLE_WARNING { - AZ_UNUSED(Keys); const AZStd::string duration = node->first_attribute(Keys[DurationKey])->value(); return AZStd::chrono::milliseconds(static_cast(AZStd::stof(duration) * 1000.f)); }; @@ -79,9 +81,11 @@ namespace TestImpact for (auto testcase_node = testsuite_node->first_node(Keys[TestCaseKey]); testcase_node; testcase_node = testcase_node->next_sibling()) { + AZ_PUSH_DISABLE_WARNING(5233, "-Wunknown-warning-option") // Older versions of MSVC toolchain require to pass constexpr in the capture. + // Newer versions issue unused warning const auto getStatus = [Keys](const AZ::rapidxml::xml_node<>* node) + AZ_POP_DISABLE_WARNING { - AZ_UNUSED(Keys); const AZStd::string status = node->first_attribute(Keys[StatusKey])->value(); if (status == Keys[RunKey]) { diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Code/Tests/ImageProcessing_Test.cpp b/Gems/Atom/Asset/ImageProcessingAtom/Code/Tests/ImageProcessing_Test.cpp index c4240306c4..c72e1dc309 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Code/Tests/ImageProcessing_Test.cpp +++ b/Gems/Atom/Asset/ImageProcessingAtom/Code/Tests/ImageProcessing_Test.cpp @@ -860,8 +860,9 @@ namespace UnitTest { continue; } - +#if defined(AZ_ENABLE_TRACING) auto formatInfo = CPixelFormats::GetInstance().GetPixelFormatInfo(pixelFormat); +#endif ColorSpace sourceColorSpace = srcImage->HasImageFlags(EIF_SRGBRead) ? ColorSpace::sRGB : ColorSpace::linear; ICompressorPtr compressor = ICompressor::FindCompressor(pixelFormat, sourceColorSpace, true); diff --git a/Gems/Atom/Asset/Shader/Code/Source/Editor/ShaderAssetBuilder.cpp b/Gems/Atom/Asset/Shader/Code/Source/Editor/ShaderAssetBuilder.cpp index 2babba1ecc..3bc63b89a0 100644 --- a/Gems/Atom/Asset/Shader/Code/Source/Editor/ShaderAssetBuilder.cpp +++ b/Gems/Atom/Asset/Shader/Code/Source/Editor/ShaderAssetBuilder.cpp @@ -228,9 +228,9 @@ namespace AZ response.m_createJobOutputs.push_back(jobDescriptor); } // for all request.m_enabledPlatforms - const AZStd::sys_time_t createJobsEndStamp = AZStd::GetTimeNowMicroSecond(); - const u64 createJobDurationMicros = createJobsEndStamp - shaderAssetBuildTimestamp; - AZ_TracePrintf(ShaderAssetBuilderName, "CreateJobs for %s took %llu microseconds", fullPath.c_str(), createJobDurationMicros ); + AZ_TracePrintf( + ShaderAssetBuilderName, "CreateJobs for %s took %llu microseconds", fullPath.c_str(), + AZStd::GetTimeNowMicroSecond() - shaderAssetBuildTimestamp); response.m_result = AssetBuilderSDK::CreateJobsResultCode::Success; } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Decals.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Decals.azsli index 1bd8e0b9a5..5e7088617b 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Decals.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Decals.azsli @@ -16,6 +16,7 @@ #include #include #include +#include void ApplyDecal(uint currDecalIndex, inout Surface surface); @@ -47,9 +48,10 @@ void ApplyDecal(uint currDecalIndex, inout Surface surface) ViewSrg::Decal decal = ViewSrg::m_decals[currDecalIndex]; float3x3 decalRot = MatrixFromQuaternion(decal.m_quaternion); - + decalRot = transpose(decalRot); + float3 localPos = surface.position - decal.m_position; - localPos = mul(localPos, decalRot); + localPos = mul(decalRot, localPos); float3 decalUVW = localPos * rcp(decal.m_halfSize); if(decalUVW.x >= -1.0f && decalUVW.x <= 1.0f && @@ -63,30 +65,39 @@ void ApplyDecal(uint currDecalIndex, inout Surface surface) decalUVW.y *= -1; float3 decalUV = float3(decalUVW.xy * 0.5f + 0.5f, textureIndex); - + float3 decalSample; float4 baseMap = 0; + float2 normalMap = 0; switch(textureArrayIndex) { case 0: - baseMap = ViewSrg::m_decalTextureArray0.Sample(PassSrg::LinearSampler, decalUV); + baseMap = ViewSrg::m_decalTextureArrayDiffuse0.Sample(PassSrg::LinearSampler, decalUV); + normalMap = ViewSrg::m_decalTextureArrayNormalMaps0.Sample(PassSrg::LinearSampler, decalUV); break; case 1: - baseMap = ViewSrg::m_decalTextureArray1.Sample(PassSrg::LinearSampler, decalUV); + baseMap = ViewSrg::m_decalTextureArrayDiffuse1.Sample(PassSrg::LinearSampler, decalUV); + normalMap = ViewSrg::m_decalTextureArrayNormalMaps1.Sample(PassSrg::LinearSampler, decalUV); break; case 2: - baseMap = ViewSrg::m_decalTextureArray2.Sample(PassSrg::LinearSampler, decalUV); + baseMap = ViewSrg::m_decalTextureArrayDiffuse2.Sample(PassSrg::LinearSampler, decalUV); + normalMap = ViewSrg::m_decalTextureArrayNormalMaps2.Sample(PassSrg::LinearSampler, decalUV); break; case 3: - baseMap = ViewSrg::m_decalTextureArray3.Sample(PassSrg::LinearSampler, decalUV); + baseMap = ViewSrg::m_decalTextureArrayDiffuse3.Sample(PassSrg::LinearSampler, decalUV); + normalMap = ViewSrg::m_decalTextureArrayNormalMaps3.Sample(PassSrg::LinearSampler, decalUV); break; case 4: - baseMap = ViewSrg::m_decalTextureArray4.Sample(PassSrg::LinearSampler, decalUV); - break; + baseMap = ViewSrg::m_decalTextureArrayDiffuse4.Sample(PassSrg::LinearSampler, decalUV); + normalMap = ViewSrg::m_decalTextureArrayNormalMaps4.Sample(PassSrg::LinearSampler, decalUV); + break; } float opacity = baseMap.a * decal.m_opacity * GetDecalAttenuation(surface.normal, decalRot[2], decal.m_angleAttenuation); - surface.albedo = lerp(surface.albedo, baseMap.rgb, opacity); + surface.albedo = lerp(surface.albedo, baseMap.rgb, opacity); + + float3 normalMapWS = GetWorldSpaceNormal(normalMap, decalRot[2], decalRot[0], decalRot[1], 1.0f); + surface.normal = normalize(lerp(surface.normal, normalMapWS, opacity)); } } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/Decals/ViewSrg.azsli b/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/Decals/ViewSrg.azsli index 16b23432e1..260614b0f7 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/Decals/ViewSrg.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/Decals/ViewSrg.azsli @@ -31,12 +31,18 @@ partial ShaderResourceGroup ViewSrg // e.g. m_decalTextureArray0 might store 24 textures @128x128, // m_decalTextureArray1 might store 16 * 256x256 // and m_decalTextureArray2 might store 4 @ 512x512 - - Texture2DArray m_decalTextureArray0; - Texture2DArray m_decalTextureArray1; - Texture2DArray m_decalTextureArray2; - Texture2DArray m_decalTextureArray3; - Texture2DArray m_decalTextureArray4; + // This must match the variable NumTextureArrays in DecalTextureArrayFeatureProcessor.h + Texture2DArray m_decalTextureArrayDiffuse0; + Texture2DArray m_decalTextureArrayDiffuse1; + Texture2DArray m_decalTextureArrayDiffuse2; + Texture2DArray m_decalTextureArrayDiffuse3; + Texture2DArray m_decalTextureArrayDiffuse4; + + Texture2DArray m_decalTextureArrayNormalMaps0; + Texture2DArray m_decalTextureArrayNormalMaps1; + Texture2DArray m_decalTextureArrayNormalMaps2; + Texture2DArray m_decalTextureArrayNormalMaps3; + Texture2DArray m_decalTextureArrayNormalMaps4; uint m_decalCount; } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance.azshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance.azshader index 596f9a383e..31fae5d98b 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance.azshader and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance.azshader differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance_dx12_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance_dx12_0.azshadervariant index 8481bdb15b..19e9fdfc8d 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance_dx12_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance_dx12_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance_null_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance_null_0.azshadervariant index 2f2cd5cccf..43c4a615cf 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance_null_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance_null_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance_vulkan_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance_vulkan_0.azshadervariant index cb5de53e97..75f070a03e 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance_vulkan_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblenddistance_vulkan_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance.azshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance.azshader index fc11f9de64..0025388bc1 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance.azshader and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance.azshader differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance_dx12_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance_dx12_0.azshadervariant index a35179ef7f..34a9b3659f 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance_dx12_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance_dx12_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance_null_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance_null_0.azshadervariant index 2f2cd5cccf..4a2b0e9944 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance_null_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance_null_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance_vulkan_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance_vulkan_0.azshadervariant index 450f5595a4..c053a7db19 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance_vulkan_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridblendirradiance_vulkan_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn.azshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn.azshader index 3f3d113787..c507b12563 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn.azshader and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn.azshader differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn_dx12_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn_dx12_0.azshadervariant index 76f61d2fd4..f60c713597 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn_dx12_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn_dx12_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn_null_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn_null_0.azshadervariant index 2f2cd5cccf..3e810bcfb5 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn_null_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn_null_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn_vulkan_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn_vulkan_0.azshadervariant index 8b6ec377a6..5918f277b5 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn_vulkan_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdatecolumn_vulkan_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow.azshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow.azshader index 9050f90943..120eb70e54 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow.azshader and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow.azshader differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow_dx12_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow_dx12_0.azshadervariant index 89ab946fd0..d38d779696 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow_dx12_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow_dx12_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow_null_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow_null_0.azshadervariant index 2f2cd5cccf..6d7a604701 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow_null_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow_null_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow_vulkan_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow_vulkan_0.azshadervariant index 8fb8e92117..dee941cfae 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow_vulkan_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridborderupdaterow_vulkan_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification.azshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification.azshader index b9552a85db..e2e0fa90f5 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification.azshader and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification.azshader differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification_dx12_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification_dx12_0.azshadervariant index c5d569a0a6..7a92fc2de5 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification_dx12_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification_dx12_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification_null_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification_null_0.azshadervariant index 2f2cd5cccf..43408b26f3 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification_null_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification_null_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification_vulkan_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification_vulkan_0.azshadervariant index ae1bae8220..877085446d 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification_vulkan_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridclassification_vulkan_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing.azshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing.azshader index 66895758de..2c403c77f8 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing.azshader and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing.azshader differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_dx12_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_dx12_0.azshadervariant index fd22ac4fd3..4bcc47ee43 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_dx12_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_dx12_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_null_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_null_0.azshadervariant index 0bf9ac53d7..f173416210 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_null_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_null_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_vulkan_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_vulkan_0.azshadervariant index 58ce16948b..0eb04a25b8 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_vulkan_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracing_vulkan_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit.azshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit.azshader index 44a8b1426d..2847d0035a 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit.azshader and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit.azshader differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_dx12_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_dx12_0.azshadervariant index acfb2aa716..93cfb47819 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_dx12_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_dx12_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_null_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_null_0.azshadervariant index 0bf9ac53d7..4a16e24211 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_null_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_null_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_vulkan_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_vulkan_0.azshadervariant index 8c66d30c98..df52c9c8d2 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_vulkan_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingclosesthit_vulkan_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss.azshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss.azshader index fad06893e9..d95fd5b3b2 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss.azshader and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss.azshader differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_dx12_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_dx12_0.azshadervariant index 1c0894bd23..c853de4d14 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_dx12_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_dx12_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_null_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_null_0.azshadervariant index 0bf9ac53d7..40e18c215c 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_null_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_null_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_vulkan_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_vulkan_0.azshadervariant index cf8bbbd824..34761ccf98 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_vulkan_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridraytracingmiss_vulkan_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation.azshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation.azshader index b46a476221..c19020dc84 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation.azshader and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation.azshader differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation_dx12_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation_dx12_0.azshadervariant index d0287e91ec..a7d44b5541 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation_dx12_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation_dx12_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation_null_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation_null_0.azshadervariant index 2f2cd5cccf..82e0065216 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation_null_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation_null_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation_vulkan_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation_vulkan_0.azshadervariant index f74f35eb99..20b81aee6c 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation_vulkan_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrelocation_vulkan_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender.azshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender.azshader index e309733d11..aec2786540 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender.azshader and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender.azshader differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender_dx12_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender_dx12_0.azshadervariant index d015d52280..de851f187e 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender_dx12_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender_dx12_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender_null_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender_null_0.azshadervariant index 7922055a82..5d8207dfdb 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender_null_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender_null_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender_vulkan_0.azshadervariant b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender_vulkan_0.azshadervariant index 780163eb07..c819e57c4c 100644 Binary files a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender_vulkan_0.azshadervariant and b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/diffuseprobegridrender_vulkan_0.azshadervariant differ diff --git a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArray.cpp b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArray.cpp index ebdc884ecf..87ac0a9679 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArray.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArray.cpp @@ -5,7 +5,6 @@ * SPDX-License-Identifier: Apache-2.0 OR MIT * */ - #include "DecalTextureArray.h" #include #include @@ -24,7 +23,16 @@ namespace AZ { namespace { - static const char* BaseColorTextureMapName = "baseColor.textureMap"; + static AZ::Name GetMapName(const DecalMapType mapType) + { + // Using local static to avoid cost of creating AZ::Name. Also so that this can be called from other static functions + static AZStd::array mapNames = + { + AZ::Name("baseColor.textureMap"), + AZ::Name("normal.textureMap") + }; + return mapNames[mapType]; + } static AZ::Data::AssetId GetImagePoolId() { @@ -40,6 +48,7 @@ namespace AZ return asset; } + // Extract exactly which texture asset we need to load from the given material and map type (diffuse, normal, etc). static AZ::Data::Asset GetStreamingImageAsset(const AZ::RPI::MaterialAsset& materialAsset, const AZ::Name& propertyName) { if (!materialAsset.IsReady()) @@ -78,11 +87,6 @@ namespace AZ const AZ::RPI::MaterialAsset* materialAsset = materialAssetData.GetAs(); return GetStreamingImageAsset(*materialAsset, propertyName); } - - AZ::Data::Asset GetBaseColorImageAsset(const AZ::Data::Asset materialAssetData) - { - return GetStreamingImageAsset(materialAssetData, AZ::Name(BaseColorTextureMapName)); - } } int DecalTextureArray::FindMaterial(const AZ::Data::AssetId materialAssetId) const @@ -103,7 +107,7 @@ namespace AZ { AZ_Error("DecalTextureArray", FindMaterial(materialAssetId) == -1, "Adding material when it already exists in the array"); // Invalidate the existing texture array, as we need to repack it taking into account the new material. - m_textureArrayPacked = nullptr; + AZStd::fill(m_textureArrayPacked.begin(), m_textureArrayPacked.end(), nullptr); MaterialData materialData; materialData.m_materialAssetId = materialAssetId; @@ -122,42 +126,42 @@ namespace AZ return m_materials[index].m_materialAssetId; } - RHI::Size DecalTextureArray::GetImageDimensions() const + RHI::Size DecalTextureArray::GetImageDimensions(const DecalMapType mapType) const { AZ_Assert(m_materials.size() > 0, "GetImageDimensions() cannot be called until at least one material has been added"); const int iter = m_materials.begin(); // All textures in a texture array must have the same size, so just pick the first const MaterialData& firstMaterial = m_materials[iter]; - const auto& baseColorAsset = GetBaseColorImageAsset(firstMaterial.m_materialAssetData); + const auto& baseColorAsset = GetStreamingImageAsset(firstMaterial.m_materialAssetData, GetMapName(mapType)); return baseColorAsset->GetImageDescriptor().m_size; } - const AZ::Data::Instance& DecalTextureArray::GetPackedTexture() const + const AZ::Data::Instance& DecalTextureArray::GetPackedTexture(const DecalMapType mapType) const { - return m_textureArrayPacked; + return m_textureArrayPacked[mapType]; } bool DecalTextureArray::IsValidDecalMaterial(const AZ::RPI::MaterialAsset& materialAsset) { - return GetStreamingImageAsset(materialAsset, AZ::Name(BaseColorTextureMapName)).IsReady(); + return GetStreamingImageAsset(materialAsset, GetMapName(DecalMapType_Diffuse)).IsReady(); } - AZ::Data::Asset DecalTextureArray::BuildPackedMipChainAsset(const size_t numTexturesToCreate) + AZ::Data::Asset DecalTextureArray::BuildPackedMipChainAsset(const DecalMapType mapType, const size_t numTexturesToCreate) { RPI::ImageMipChainAssetCreator assetCreator; - const uint32_t mipLevels = GetNumMipLevels(); + const uint32_t mipLevels = GetNumMipLevels(mapType); - assetCreator.Begin(Data::AssetId(AZ::Uuid::CreateRandom()), static_cast(mipLevels), aznumeric_cast(numTexturesToCreate)); + assetCreator.Begin(Data::AssetId(AZ::Uuid::CreateRandom()), aznumeric_cast(mipLevels), aznumeric_cast(numTexturesToCreate)); for (uint32_t mipLevel = 0; mipLevel < mipLevels; ++mipLevel) { - const auto& layout = GetLayout(mipLevel); + const auto& layout = GetLayout(mapType, mipLevel); assetCreator.BeginMip(layout); for (int i = 0; i < m_materials.array_size(); ++i) { - const auto rawData = GetRawImageData(i, mipLevel); - assetCreator.AddSubImage(rawData.data(), rawData.size()); + const auto imageData = GetRawImageData(GetMapName(mapType), i, mipLevel); + assetCreator.AddSubImage(imageData.data(), imageData.size()); } assetCreator.EndMip(); @@ -169,10 +173,12 @@ namespace AZ return AZStd::move(asset); } - RHI::ImageDescriptor DecalTextureArray::CreatePackedImageDescriptor(const uint16_t arraySize, const uint16_t mipLevels) const + RHI::ImageDescriptor DecalTextureArray::CreatePackedImageDescriptor( + const DecalMapType mapType, const uint16_t arraySize, const uint16_t mipLevels) const { - const RHI::Size imageDimensions = GetImageDimensions(); - RHI::ImageDescriptor imageDescriptor = RHI::ImageDescriptor::Create2DArray(RHI::ImageBindFlags::ShaderRead, imageDimensions.m_width, imageDimensions.m_height, arraySize, GetFormat()); + const RHI::Size imageDimensions = GetImageDimensions(mapType); + RHI::ImageDescriptor imageDescriptor = RHI::ImageDescriptor::Create2DArray( + RHI::ImageBindFlags::ShaderRead, imageDimensions.m_width, imageDimensions.m_height, arraySize, GetFormat(mapType)); imageDescriptor.m_mipLevels = mipLevels; return imageDescriptor; } @@ -189,21 +195,34 @@ namespace AZ } const size_t numTexturesToCreate = m_materials.array_size(); - const auto mipChainAsset = BuildPackedMipChainAsset(numTexturesToCreate); - RHI::ImageViewDescriptor imageViewDescriptor; - imageViewDescriptor.m_isArray = true; + for (int i = 0; i < DecalMapType_Num; ++i) + { + const DecalMapType mapType = aznumeric_cast(i); + if (!AreAllTextureMapsPresent(mapType)) + { + AZ_Warning("DecalTextureArray", true, "Missing decal texture maps for %s. Please make sure all maps of this type are present.\n", GetMapName(mapType).GetCStr()); + m_textureArrayPacked[i] = nullptr; + continue; + } - RPI::StreamingImageAssetCreator assetCreator; - assetCreator.Begin(Data::AssetId(Uuid::CreateRandom())); - assetCreator.SetPoolAssetId(GetImagePoolId()); - assetCreator.SetFlags(RPI::StreamingImageFlags::None); - assetCreator.SetImageDescriptor(CreatePackedImageDescriptor(aznumeric_cast(numTexturesToCreate), GetNumMipLevels())); - assetCreator.SetImageViewDescriptor(imageViewDescriptor); - assetCreator.AddMipChainAsset(*mipChainAsset); - Data::Asset packedAsset; - const bool createdOk = assetCreator.End(packedAsset); - AZ_Error("TextureArrayData", createdOk, "Pack() call failed."); - m_textureArrayPacked = createdOk ? RPI::StreamingImage::FindOrCreate(packedAsset) : nullptr; + const auto mipChainAsset = BuildPackedMipChainAsset(mapType, numTexturesToCreate); + RHI::ImageViewDescriptor imageViewDescriptor; + imageViewDescriptor.m_isArray = true; + + RPI::StreamingImageAssetCreator assetCreator; + assetCreator.Begin(Data::AssetId(Uuid::CreateRandom())); + assetCreator.SetPoolAssetId(GetImagePoolId()); + assetCreator.SetFlags(RPI::StreamingImageFlags::None); + assetCreator.SetImageDescriptor( + CreatePackedImageDescriptor(mapType, aznumeric_cast(numTexturesToCreate), GetNumMipLevels(mapType))); + assetCreator.SetImageViewDescriptor(imageViewDescriptor); + assetCreator.AddMipChainAsset(*mipChainAsset); + Data::Asset packedAsset; + const bool createdOk = assetCreator.End(packedAsset); + AZ_Error("TextureArrayData", createdOk, "Pack() call failed."); + m_textureArrayPacked[i] = createdOk ? RPI::StreamingImage::FindOrCreate(packedAsset) : nullptr; + + } // Free unused memory ClearAssets(); @@ -225,29 +244,30 @@ namespace AZ } } - uint16_t DecalTextureArray::GetNumMipLevels() const + uint16_t DecalTextureArray::GetNumMipLevels(const DecalMapType mapType) const { AZ_Assert(m_materials.size() > 0, "GetNumMipLevels() cannot be called until at least one material has been added"); // All decals in a texture array must have the same number of mips, so just pick the first const int iter = m_materials.begin(); const MaterialData& firstMaterial = m_materials[iter]; - const auto& baseColorAsset = GetBaseColorImageAsset(firstMaterial.m_materialAssetData); - return baseColorAsset->GetImageDescriptor().m_mipLevels; + const auto& imageAsset = GetStreamingImageAsset(firstMaterial.m_materialAssetData, GetMapName(mapType)); + return imageAsset->GetImageDescriptor().m_mipLevels; } - RHI::ImageSubresourceLayout DecalTextureArray::GetLayout(int mip) const + RHI::ImageSubresourceLayout DecalTextureArray::GetLayout(const DecalMapType mapType, int mip) const { AZ_Assert(m_materials.size() > 0, "GetLayout() cannot be called unless at least one material has been added"); const int iter = m_materials.begin(); - const auto& descriptor = GetBaseColorImageAsset(m_materials[iter].m_materialAssetData)->GetImageDescriptor(); + const auto& descriptor = + GetStreamingImageAsset(m_materials[iter].m_materialAssetData, GetMapName(mapType))->GetImageDescriptor(); RHI::Size mipSize = descriptor.m_size; mipSize.m_width >>= mip; mipSize.m_height >>= mip; return AZ::RHI::GetImageSubresourceLayout(mipSize, descriptor.m_format); } - AZStd::array_view DecalTextureArray::GetRawImageData(int arrayLevel, const int mip) const + AZStd::array_view DecalTextureArray::GetRawImageData(const AZ::Name& mapName, int arrayLevel, const int mip) const { // We always want to provide valid data to the AssetCreator for each texture. // If this spot in the array is empty, just provide some random image as filler. @@ -257,17 +277,20 @@ namespace AZ { arrayLevel = m_materials.begin(); } - - const auto image = GetBaseColorImageAsset(m_materials[arrayLevel].m_materialAssetData); + const auto image = GetStreamingImageAsset(m_materials[arrayLevel].m_materialAssetData, mapName); + if (!image) + { + return {}; + } const auto srcData = image->GetSubImageData(mip, 0); return srcData; } - AZ::RHI::Format DecalTextureArray::GetFormat() const + AZ::RHI::Format DecalTextureArray::GetFormat(const DecalMapType mapType) const { AZ_Assert(m_materials.size() > 0, "GetFormat() can only be called after at least one material has been added."); const int iter = m_materials.begin(); - const auto& baseColorAsset = GetBaseColorImageAsset(m_materials[iter].m_materialAssetData); + const auto& baseColorAsset = GetStreamingImageAsset(m_materials[iter].m_materialAssetData, GetMapName(mapType)); return baseColorAsset->GetImageDescriptor().m_format; } @@ -290,6 +313,25 @@ namespace AZ return id.IsValid() && materialData.m_materialAssetData.IsReady(); } + bool DecalTextureArray::AreAllTextureMapsPresent(const DecalMapType mapType) const + { + int iter = m_materials.begin(); + while (iter != -1) + { + if (!IsTextureMapPresentInMaterial(m_materials[iter], mapType)) + { + return false; + } + iter = m_materials.next(iter); + } + return true; + } + + bool DecalTextureArray::IsTextureMapPresentInMaterial(const MaterialData& materialData, const DecalMapType mapType) const + { + return GetStreamingImageAsset(materialData.m_materialAssetData, GetMapName(mapType)).IsReady(); + } + void DecalTextureArray::ClearAssets() { int iter = m_materials.begin(); @@ -330,7 +372,8 @@ namespace AZ if (m_materials.size() == 0) return false; - return m_textureArrayPacked == nullptr; + // We pack all diffuse/normal/etc in one go, so just check to see if the diffusemaps need packing + return m_textureArrayPacked[DecalMapType_Diffuse] == nullptr; } } diff --git a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArray.h b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArray.h index eb0f825e08..97bd8b9cbe 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArray.h +++ b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArray.h @@ -28,8 +28,18 @@ namespace AZ namespace Render { + enum DecalMapType : uint32_t + { + DecalMapType_Diffuse, + DecalMapType_Normal, + DecalMapType_Num + }; + //! Helper class used by DecalTextureArrayFeatureProcessor. //! Given a set of images (all with the same dimensions and format), it can pack them together into a single textureArray that can be sent to the GPU. + //! Note that once textures are packed, this class will release any material references + //! This might free memory if nothing else is holding onto them + //! The class DOES keep note of which material asset ids were added, so it can load them again if necessary if the whole thing needs to be repacked class DecalTextureArray : public Data::AssetBus::MultiHandler { public: @@ -40,8 +50,12 @@ namespace AZ AZ::Data::AssetId GetMaterialAssetId(const int index) const; + // Packs all the added materials into one texture array per DecalMapType. void Pack(); - const Data::Instance& GetPackedTexture() const; + + // Note that we pack each type into a separate texture array. This is because formats are + // often different (BC5 for normals, BC7 for diffuse, etc) + const Data::Instance& GetPackedTexture(const DecalMapType mapType) const; static bool IsValidDecalMaterial(const RPI::MaterialAsset& materialAsset); @@ -56,22 +70,25 @@ namespace AZ void OnAssetReady(Data::Asset asset) override; + // Returns the index of the material in the m_materials container. -1 if not present. int FindMaterial(const AZ::Data::AssetId materialAssetId) const; // packs the contents of the source images into a texture array readable by the GPU and returns it - AZ::Data::Asset BuildPackedMipChainAsset(const size_t numTexturesToCreate); + AZ::Data::Asset BuildPackedMipChainAsset(const DecalMapType mapType, const size_t numTexturesToCreate); + RHI::ImageDescriptor CreatePackedImageDescriptor(const DecalMapType mapType, const uint16_t arraySize, const uint16_t mipLevels) const; - RHI::ImageDescriptor CreatePackedImageDescriptor(const uint16_t arraySize, const uint16_t mipLevels) const; - - uint16_t GetNumMipLevels() const; - RHI::Size GetImageDimensions() const; - RHI::Format GetFormat() const; - RHI::ImageSubresourceLayout GetLayout(int mip) const; - AZStd::array_view GetRawImageData(int arrayLevel, int mip) const; + uint16_t GetNumMipLevels(const DecalMapType mapType) const; + RHI::Size GetImageDimensions(const DecalMapType mapType) const; + RHI::Format GetFormat(const DecalMapType mapType) const; + RHI::ImageSubresourceLayout GetLayout(const DecalMapType mapType, int mip) const; + AZStd::array_view GetRawImageData(const AZ::Name& mapName, int arrayLevel, int mip) const; bool AreAllAssetsReady() const; bool IsAssetReady(const MaterialData& materialData) const; + bool AreAllTextureMapsPresent(const DecalMapType mapType) const; + bool IsTextureMapPresentInMaterial(const MaterialData& materialData, const DecalMapType mapType) const; + void ClearAssets(); void ClearAsset(MaterialData& materialData); @@ -81,7 +98,7 @@ namespace AZ bool NeedsPacking() const; IndexableList m_materials; - Data::Instance m_textureArrayPacked; + AZStd::array, DecalMapType_Num> m_textureArrayPacked; AZStd::unordered_set m_assetsCurrentlyLoading; }; diff --git a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.cpp b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.cpp index c0b8f3315a..e5bf0bd9fa 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.cpp @@ -322,13 +322,30 @@ namespace AZ void DecalTextureArrayFeatureProcessor::CacheShaderIndices() { - for (int i = 0; i < NumTextureArrays; ++i) - { - const RHI::ShaderResourceGroupLayout* viewSrgLayout = RPI::RPISystemInterface::Get()->GetViewSrgLayout().get(); - const AZStd::string baseName = "m_decalTextureArray" + AZStd::to_string(i); + // The azsl shader should define several texture arrays such as: + // Texture2DArray m_decalTextureArrayDiffuse0; + // Texture2DArray m_decalTextureArrayDiffuse1; + // Texture2DArray m_decalTextureArrayDiffuse2; + // and + // Texture2DArray m_decalTextureArrayNormalMaps0; + // Texture2DArray m_decalTextureArrayNormalMaps1; + // Texture2DArray m_decalTextureArrayNormalMaps2; + static const AZStd::array ShaderNames = { "m_decalTextureArrayDiffuse", + "m_decalTextureArrayNormalMaps" }; - m_decalTextureArrayIndices[i] = viewSrgLayout->FindShaderInputImageIndex(Name(baseName.c_str())); - AZ_Warning("DecalTextureArrayFeatureProcessor", m_decalTextureArrayIndices[i].IsValid(), "Unable to find %s in decal shader.", baseName.c_str()); + for (int mapType = 0; mapType < DecalMapType_Num; ++mapType) + { + for (int texArrayIdx = 0; texArrayIdx < NumTextureArrays; ++texArrayIdx) + { + const RHI::ShaderResourceGroupLayout* viewSrgLayout = RPI::RPISystemInterface::Get()->GetViewSrgLayout().get(); + const AZStd::string baseName = ShaderNames[mapType] + AZStd::to_string(texArrayIdx); + + m_decalTextureArrayIndices[texArrayIdx][mapType] = viewSrgLayout->FindShaderInputImageIndex(Name(baseName.c_str())); + AZ_Warning( + "DecalTextureArrayFeatureProcessor", m_decalTextureArrayIndices[texArrayIdx][mapType].IsValid(), + "Unable to find %s in decal shader.", + baseName.c_str()); + } } } @@ -411,8 +428,11 @@ namespace AZ int iter = m_textureArrayList.begin(); while (iter != -1) { - const auto& packedTexture = m_textureArrayList[iter].second.GetPackedTexture(); - view->GetShaderResourceGroup()->SetImage(m_decalTextureArrayIndices[iter], packedTexture); + for (int mapType = 0 ; mapType < DecalMapType_Num ; ++mapType) + { + const auto& packedTexture = m_textureArrayList[iter].second.GetPackedTexture(aznumeric_cast(mapType)); + view->GetShaderResourceGroup()->SetImage(m_decalTextureArrayIndices[iter][mapType], packedTexture); + } iter = m_textureArrayList.next(iter); } } diff --git a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.h index 57c5c69e0d..13a6682629 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.h @@ -89,6 +89,7 @@ namespace AZ private: // Number of size and format permutations + // This number should match the number of texture arrays in Decals/ViewSrg.azsli static constexpr int NumTextureArrays = 5; static constexpr const char* FeatureProcessorName = "DecalTextureArrayFeatureProcessor"; @@ -128,7 +129,7 @@ namespace AZ // 4 textures @ 512x512 IndexableList < AZStd::pair < AZ::RHI::Size, DecalTextureArray>> m_textureArrayList; - AZStd::array m_decalTextureArrayIndices; + AZStd::array, NumTextureArrays> m_decalTextureArrayIndices; GpuBufferHandler m_decalBufferHandler; AsyncLoadTracker m_materialLoadTracker; diff --git a/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGrid.cpp b/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGrid.cpp index 4d58948b98..b4f91e58d9 100644 --- a/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGrid.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGrid.cpp @@ -128,8 +128,8 @@ namespace AZ void DiffuseProbeGrid::SetTransform(const AZ::Transform& transform) { - m_position = transform.GetTranslation(); - m_aabbWs = Aabb::CreateCenterHalfExtents(m_position, m_extents / 2.0f); + m_transform = transform; + m_obbWs = Obb::CreateFromPositionRotationAndHalfLengths(m_transform.GetTranslation(), m_transform.GetRotation(), m_extents / 2.0f); // probes need to be relocated since the grid position changed m_remainingRelocationIterations = DefaultNumRelocationIterations; @@ -145,7 +145,7 @@ namespace AZ void DiffuseProbeGrid::SetExtents(const AZ::Vector3& extents) { m_extents = extents; - m_aabbWs = Aabb::CreateCenterHalfExtents(m_position, m_extents / 2.0f); + m_obbWs = Obb::CreateFromPositionRotationAndHalfLengths(m_transform.GetTranslation(), m_transform.GetRotation(), m_extents / 2.0f); // recompute the number of probes since the extents changed UpdateProbeCount(); @@ -467,7 +467,10 @@ namespace AZ RHI::ShaderInputConstantIndex constantIndex; constantIndex = srgLayout->FindShaderInputConstantIndex(AZ::Name("m_probeGrid.origin")); - srg->SetConstant(constantIndex, m_position); + srg->SetConstant(constantIndex, m_transform.GetTranslation()); + + constantIndex = srgLayout->FindShaderInputConstantIndex(AZ::Name("m_probeGrid.rotation")); + srg->SetConstant(constantIndex, m_transform.GetRotation()); constantIndex = srgLayout->FindShaderInputConstantIndex(AZ::Name("m_probeGrid.numRaysPerProbe")); srg->SetConstant(constantIndex, m_numRaysPerProbe); @@ -760,14 +763,15 @@ namespace AZ RHI::ShaderInputImageIndex imageIndex; constantIndex = srgLayout->FindShaderInputConstantIndex(Name("m_modelToWorld")); - AZ::Matrix3x4 modelToWorld = AZ::Matrix3x4::CreateFromMatrix3x3AndTranslation(Matrix3x3::CreateIdentity(), m_position) * AZ::Matrix3x4::CreateScale(m_extents); + AZ::Matrix3x4 modelToWorld = AZ::Matrix3x4::CreateFromTransform(m_transform) * AZ::Matrix3x4::CreateScale(m_extents); m_renderObjectSrg->SetConstant(constantIndex, modelToWorld); - constantIndex = srgLayout->FindShaderInputConstantIndex(Name("m_aabbMin")); - m_renderObjectSrg->SetConstant(constantIndex, m_aabbWs.GetMin()); + constantIndex = srgLayout->FindShaderInputConstantIndex(Name("m_modelToWorldInverse")); + AZ::Matrix3x4 modelToWorldInverse = AZ::Matrix3x4::CreateFromTransform(m_transform).GetInverseFull(); + m_renderObjectSrg->SetConstant(constantIndex, modelToWorldInverse); - constantIndex = srgLayout->FindShaderInputConstantIndex(Name("m_aabbMax")); - m_renderObjectSrg->SetConstant(constantIndex, m_aabbWs.GetMax()); + constantIndex = srgLayout->FindShaderInputConstantIndex(Name("m_obbHalfLengths")); + m_renderObjectSrg->SetConstant(constantIndex, m_obbWs.GetHalfLengths()); constantIndex = srgLayout->FindShaderInputConstantIndex(Name("m_enableDiffuseGI")); m_renderObjectSrg->SetConstant(constantIndex, m_enabled); @@ -821,13 +825,14 @@ namespace AZ lod.m_screenCoverageMax = 1.0f; // update cullable bounds + Aabb aabbWs = Aabb::CreateFromObb(m_obbWs); Vector3 center; float radius; - m_aabbWs.GetAsSphere(center, radius); + aabbWs.GetAsSphere(center, radius); m_cullable.m_cullData.m_boundingSphere = Sphere(center, radius); - m_cullable.m_cullData.m_boundingObb = m_aabbWs.GetTransformedObb(AZ::Transform::CreateIdentity()); - m_cullable.m_cullData.m_visibilityEntry.m_boundingVolume = m_aabbWs; + m_cullable.m_cullData.m_boundingObb = m_obbWs; + m_cullable.m_cullData.m_visibilityEntry.m_boundingVolume = aabbWs; m_cullable.m_cullData.m_visibilityEntry.m_userData = &m_cullable; m_cullable.m_cullData.m_visibilityEntry.m_typeFlags = AzFramework::VisibilityEntry::TYPE_RPI_Cullable; diff --git a/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGrid.h b/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGrid.h index 89e7173dd5..97c336ed41 100644 --- a/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGrid.h +++ b/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGrid.h @@ -72,7 +72,7 @@ namespace AZ const AZ::Vector3& GetExtents() const { return m_extents; } void SetExtents(const AZ::Vector3& extents); - const AZ::Aabb& GetAabbWs() const { return m_aabbWs; } + const AZ::Obb& GetObbWs() const { return m_obbWs; } bool ValidateProbeSpacing(const AZ::Vector3& newSpacing); const AZ::Vector3& GetProbeSpacing() const { return m_probeSpacing; } @@ -183,14 +183,14 @@ namespace AZ // scene RPI::Scene* m_scene = nullptr; - // probe grid position - AZ::Vector3 m_position = AZ::Vector3(0.0f, 0.0f, 0.0f); + // probe grid transform + AZ::Transform m_transform = AZ::Transform::CreateIdentity(); // extents of the probe grid AZ::Vector3 m_extents = AZ::Vector3(0.0f, 0.0f, 0.0f); - // probe grid AABB (world space), built from position and extents - AZ::Aabb m_aabbWs = AZ::Aabb::CreateNull(); + // probe grid OBB (world space), built from transform and extents + AZ::Obb m_obbWs; // per-axis spacing of probes in the grid AZ::Vector3 m_probeSpacing; diff --git a/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGridFeatureProcessor.cpp b/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGridFeatureProcessor.cpp index d79240d4f1..4329fd556c 100644 --- a/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGridFeatureProcessor.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/DiffuseGlobalIllumination/DiffuseProbeGridFeatureProcessor.cpp @@ -154,10 +154,11 @@ namespace AZ // sort the probes by descending inner volume size, so the smallest volumes are rendered last auto sortFn = [](AZStd::shared_ptr const& probe1, AZStd::shared_ptr const& probe2) -> bool { - const Aabb& aabb1 = probe1->GetAabbWs(); - const Aabb& aabb2 = probe2->GetAabbWs(); - float size1 = aabb1.GetXExtent() * aabb1.GetZExtent() * aabb1.GetYExtent(); - float size2 = aabb2.GetXExtent() * aabb2.GetZExtent() * aabb2.GetYExtent(); + const Obb& obb1 = probe1->GetObbWs(); + const Obb& obb2 = probe2->GetObbWs(); + float size1 = obb1.GetHalfLengthX() * obb1.GetHalfLengthZ() * obb1.GetHalfLengthY(); + float size2 = obb2.GetHalfLengthX() * obb2.GetHalfLengthZ() * obb2.GetHalfLengthY(); + return (size1 > size2); }; diff --git a/Gems/Atom/Feature/Common/Code/Tests/Decals/DecalTextureArrayTests.cpp b/Gems/Atom/Feature/Common/Code/Tests/Decals/DecalTextureArrayTests.cpp index fcbcec0256..84c2b88507 100644 --- a/Gems/Atom/Feature/Common/Code/Tests/Decals/DecalTextureArrayTests.cpp +++ b/Gems/Atom/Feature/Common/Code/Tests/Decals/DecalTextureArrayTests.cpp @@ -42,7 +42,7 @@ namespace UnitTest { AZ::Render::DecalTextureArray decalTextureArray; decalTextureArray.Pack(); - auto nothing = decalTextureArray.GetPackedTexture(); + auto nothing = decalTextureArray.GetPackedTexture(AZ::Render::DecalMapType_Diffuse); EXPECT_EQ(nothing, nullptr); } diff --git a/Gems/Atom/RHI/Code/Include/Atom/RHI/FrameScheduler.h b/Gems/Atom/RHI/Code/Include/Atom/RHI/FrameScheduler.h index ddcee53e69..48e7e0f339 100644 --- a/Gems/Atom/RHI/Code/Include/Atom/RHI/FrameScheduler.h +++ b/Gems/Atom/RHI/Code/Include/Atom/RHI/FrameScheduler.h @@ -23,6 +23,7 @@ namespace AZ { class Job; + class TaskGraphActiveInterface; namespace RHI { @@ -228,6 +229,8 @@ namespace AZ // list of RayTracingShaderTables that should be built this frame AZStd::vector> m_rayTracingShaderTablesToBuild; + + AZ::TaskGraphActiveInterface* m_taskGraphActive = nullptr; }; } } diff --git a/Gems/Atom/RHI/Code/Source/RHI/AsyncWorkQueue.cpp b/Gems/Atom/RHI/Code/Source/RHI/AsyncWorkQueue.cpp index a076bf3e58..61f05306be 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/AsyncWorkQueue.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/AsyncWorkQueue.cpp @@ -26,7 +26,7 @@ namespace AZ m_workItemIndex = 0; m_lastCompletedWorkItem = AsyncWorkHandle::Null; AZStd::thread_desc threadDesc{ "AsyncWorkQueue" }; - m_thread = AZStd::thread([&]() { ProcessQueue(); }, &threadDesc); + m_thread = AZStd::thread(threadDesc, [&]() { ProcessQueue(); }); m_isInitialized = true; } diff --git a/Gems/Atom/RHI/Code/Source/RHI/CommandQueue.cpp b/Gems/Atom/RHI/Code/Source/RHI/CommandQueue.cpp index b50c36d3f9..f65c36f2ed 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/CommandQueue.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/CommandQueue.cpp @@ -43,7 +43,7 @@ namespace AZ m_isWorkQueueEmpty = true; AZStd::thread_desc threadDesc{ GetName().GetCStr() }; - m_thread = AZStd::thread([&]() { ProcessQueue(); }, &threadDesc); + m_thread = AZStd::thread(threadDesc, [&]() { ProcessQueue(); }); } return resultCode; } diff --git a/Gems/Atom/RHI/Code/Source/RHI/Fence.cpp b/Gems/Atom/RHI/Code/Source/RHI/Fence.cpp index d030ff8d2b..162b07406e 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/Fence.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/Fence.cpp @@ -108,7 +108,7 @@ namespace AZ AZStd::thread_desc threadDesc{ "Fence WaitOnCpu Thread" }; - m_waitThread = AZStd::thread([this, callback]() + m_waitThread = AZStd::thread(threadDesc, [this, callback]() { ResultCode resultCode = WaitOnCpu(); if (resultCode != ResultCode::Success) @@ -116,7 +116,7 @@ namespace AZ AZ_Error("Fence", false, "Failed to call WaitOnCpu in async thread."); } callback(); - }, &threadDesc); + }); return ResultCode::Success; } diff --git a/Gems/Atom/RHI/Code/Source/RHI/FrameScheduler.cpp b/Gems/Atom/RHI/Code/Source/RHI/FrameScheduler.cpp index 5d2feb1e34..0d3ac8216b 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/FrameScheduler.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/FrameScheduler.cpp @@ -25,9 +25,11 @@ #include #include +#include #include #include #include +#include namespace AZ { @@ -77,6 +79,8 @@ namespace AZ m_rootScope = m_rootScopeProducer->GetScope(); m_device = &device; + m_taskGraphActive = AZ::Interface::Get(); + m_lastFrameEndTime = AZStd::GetTimeNowTicks(); return ResultCode::Success; @@ -85,6 +89,7 @@ namespace AZ void FrameScheduler::Shutdown() { m_device = nullptr; + m_taskGraphActive = nullptr; m_rootScopeProducer = nullptr; m_rootScope = nullptr; m_frameGraphExecuter = nullptr; @@ -258,50 +263,98 @@ namespace AZ if (m_compileRequest.m_jobPolicy == JobPolicy::Parallel) { - const auto compileGroupsBeginFunction = [](ShaderResourceGroupPool* srgPool) - { - srgPool->CompileGroupsBegin(); - }; - - resourcePoolDatabase.ForEachShaderResourceGroupPool(compileGroupsBeginFunction); - // Iterate over each SRG pool and fork jobs to compile SRGs. const uint32_t compilesPerJob = m_compileRequest.m_shaderResourceGroupCompilesPerJob; - AZ::JobCompletion jobCompletion; - - const auto compileIntervalsFunction = [compilesPerJob, &jobCompletion](ShaderResourceGroupPool* srgPool) + if (m_taskGraphActive && m_taskGraphActive->IsTaskGraphActive()) { - const uint32_t compilesInPool = srgPool->GetGroupsToCompileCount(); - const uint32_t jobCount = DivideByMultiple(compilesInPool, compilesPerJob); + AZ::TaskGraph taskGraph; - for (uint32_t i = 0; i < jobCount; ++i) + const auto compileIntervalsFunction = [compilesPerJob, &taskGraph](ShaderResourceGroupPool* srgPool) { - Interval interval; - interval.m_min = i * compilesPerJob; - interval.m_max = AZStd::min(interval.m_min + compilesPerJob, compilesInPool); + srgPool->CompileGroupsBegin(); + const uint32_t compilesInPool = srgPool->GetGroupsToCompileCount(); + const uint32_t jobCount = DivideByMultiple(compilesInPool, compilesPerJob); + AZ::TaskDescriptor srgCompileDesc{"SrgCompile", "Graphics"}; + AZ::TaskDescriptor srgCompileEndDesc{"SrgCompileEnd", "Graphics"}; - const auto compileGroupsForIntervalLambda = [srgPool, interval]() + auto srgCompileEndTask = taskGraph.AddTask( + srgCompileEndDesc, + [srgPool]() + { + srgPool->CompileGroupsEnd(); + }); + + for (uint32_t i = 0; i < jobCount; ++i) { - AZ_PROFILE_SCOPE(RHI, "FrameScheduler : compileGroupsForIntervalLambda"); - srgPool->CompileGroupsForInterval(interval); - }; + Interval interval; + interval.m_min = i * compilesPerJob; + interval.m_max = AZStd::min(interval.m_min + compilesPerJob, compilesInPool); - AZ::Job* executeGroupJob = AZ::CreateJobFunction(AZStd::move(compileGroupsForIntervalLambda), true, nullptr); - executeGroupJob->SetDependent(&jobCompletion); - executeGroupJob->Start(); + auto compileTask = taskGraph.AddTask( + srgCompileDesc, + [srgPool, interval]() + { + AZ_PROFILE_SCOPE(RHI, "FrameScheduler : compileGroupsForIntervalLambda"); + srgPool->CompileGroupsForInterval(interval); + }); + compileTask.Precedes(srgCompileEndTask); + } + }; + + resourcePoolDatabase.ForEachShaderResourceGroupPool(AZStd::move(compileIntervalsFunction)); + if (!taskGraph.IsEmpty()) + { + AZ::TaskGraphEvent finishedEvent; + taskGraph.Submit(&finishedEvent); + finishedEvent.Wait(); } - }; - - resourcePoolDatabase.ForEachShaderResourceGroupPool(AZStd::move(compileIntervalsFunction)); - - jobCompletion.StartAndWaitForCompletion(); - - const auto compileGroupsEndFunction = [](ShaderResourceGroupPool* srgPool) + } + else // use Job system { - srgPool->CompileGroupsEnd(); - }; + const auto compileGroupsBeginFunction = [](ShaderResourceGroupPool* srgPool) + { + srgPool->CompileGroupsBegin(); + }; - resourcePoolDatabase.ForEachShaderResourceGroupPool(compileGroupsEndFunction); + resourcePoolDatabase.ForEachShaderResourceGroupPool(compileGroupsBeginFunction); + + // Iterate over each SRG pool and fork jobs to compile SRGs. + AZ::JobCompletion jobCompletion; + + const auto compileIntervalsFunction = [compilesPerJob, &jobCompletion](ShaderResourceGroupPool* srgPool) + { + const uint32_t compilesInPool = srgPool->GetGroupsToCompileCount(); + const uint32_t jobCount = DivideByMultiple(compilesInPool, compilesPerJob); + + for (uint32_t i = 0; i < jobCount; ++i) + { + Interval interval; + interval.m_min = i * compilesPerJob; + interval.m_max = AZStd::min(interval.m_min + compilesPerJob, compilesInPool); + + const auto compileGroupsForIntervalLambda = [srgPool, interval]() + { + AZ_PROFILE_SCOPE(RHI, "FrameScheduler : compileGroupsForIntervalLambda"); + srgPool->CompileGroupsForInterval(interval); + }; + + AZ::Job* executeGroupJob = AZ::CreateJobFunction(AZStd::move(compileGroupsForIntervalLambda), true, nullptr); + executeGroupJob->SetDependent(&jobCompletion); + executeGroupJob->Start(); + } + }; + + resourcePoolDatabase.ForEachShaderResourceGroupPool(AZStd::move(compileIntervalsFunction)); + + jobCompletion.StartAndWaitForCompletion(); + + const auto compileGroupsEndFunction = [](ShaderResourceGroupPool* srgPool) + { + srgPool->CompileGroupsEnd(); + }; + + resourcePoolDatabase.ForEachShaderResourceGroupPool(compileGroupsEndFunction); + } } else { @@ -317,7 +370,7 @@ namespace AZ //It is possible for certain back ends to run out of SRG memory (due to fragmentation) in which case //we try to compact and re-compile SRGs. - RHI::ResultCode resultCode = m_device->CompactSRGMemory(); + [[maybe_unused]] RHI::ResultCode resultCode = m_device->CompactSRGMemory(); AZ_Assert(resultCode == RHI::ResultCode::Success, "SRG compaction failed and this can lead to a gpu crash."); } diff --git a/Gems/Atom/RHI/Code/Source/RHI/RHISystem.cpp b/Gems/Atom/RHI/Code/Source/RHI/RHISystem.cpp index ad3ab119ef..744b688c60 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/RHISystem.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/RHISystem.cpp @@ -18,6 +18,7 @@ #include #include #include +#include AZ_DEFINE_BUDGET(RHI); @@ -101,6 +102,8 @@ namespace AZ } AZStd::string preferredUserAdapterName = RHI::GetCommandLineValue("forceAdapter"); + AZStd::to_lower(preferredUserAdapterName.begin(), preferredUserAdapterName.end()); + bool findPreferredUserDevice = preferredUserAdapterName.size() > 0; RHI::PhysicalDevice* preferredUserDevice{}; RHI::PhysicalDevice* preferredVendorDevice{}; @@ -110,12 +113,15 @@ namespace AZ const RHI::PhysicalDeviceDescriptor& descriptor = physicalDevice->GetDescriptor(); AZ_Printf("RHISystem", "\tEnumerated physical device: %s\n", descriptor.m_description.c_str()); - - if (!preferredUserDevice && descriptor.m_description == preferredUserAdapterName) + if (findPreferredUserDevice) { - preferredUserDevice = physicalDevice.get(); + AZStd::string descriptorLowerCase = descriptor.m_description; + AZStd::to_lower( descriptorLowerCase.begin(), descriptorLowerCase.end()); + if (!preferredUserDevice && descriptorLowerCase.contains(preferredUserAdapterName)) + { + preferredUserDevice = physicalDevice.get(); + } } - // Record the first nVidia or AMD device we find. if (!preferredVendorDevice && (descriptor.m_vendorId == RHI::VendorId::AMD || descriptor.m_vendorId == RHI::VendorId::nVidia)) { diff --git a/Gems/Atom/RHI/Metal/Code/Source/RHI/AsyncUploadQueue.cpp b/Gems/Atom/RHI/Metal/Code/Source/RHI/AsyncUploadQueue.cpp index bd163f1419..eadd571452 100644 --- a/Gems/Atom/RHI/Metal/Code/Source/RHI/AsyncUploadQueue.cpp +++ b/Gems/Atom/RHI/Metal/Code/Source/RHI/AsyncUploadQueue.cpp @@ -33,6 +33,7 @@ namespace AZ // Use separate work submission queue from the hw copy queue to avoid the per frame sync. m_copyQueue = CommandQueue::Create(); + m_copyQueue->SetName(AZ::Name("AsyncUpload Queue")); RHI::CommandQueueDescriptor commandQueueDescriptor; commandQueueDescriptor.m_hardwareQueueClass = RHI::HardwareQueueClass::Copy; diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Scene.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Scene.h index b1c6aac92d..fc81368331 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Scene.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Scene.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -194,6 +195,9 @@ namespace AZ // This function is called every time scene's render pipelines change. void RebuildPipelineStatesLookup(); + // Helper function to wait for end of TaskGraph + void WaitTGEvent(AZ::TaskGraphEvent& completionTGEvent, AZStd::atomic_bool* workToWaitOn = nullptr); + // Helper function for wait and clean up a completion job void WaitAndCleanCompletionJob(AZ::JobCompletion*& completionJob); @@ -204,12 +208,26 @@ namespace AZ // This happens in UpdateSrgs() void PrepareSceneSrg(); + // Implementation functions that allow scene to switch between using Jobs or TaskGraphs + void SimulateTaskGraph(); + void SimulateJobs(); + + void CollectDrawPacketsTaskGraph(); + void CollectDrawPacketsJobs(); + + void FinalizeDrawListsTaskGraph(); + void FinalizeDrawListsJobs(); + // List of feature processors that are active for this scene AZStd::vector m_featureProcessors; // List of pipelines of this scene. Each pipeline has an unique pipeline Id. AZStd::vector m_pipelines; + // CPU simulation TaskGraphEvent to wait for completion of all the simulation tasks + AZ::TaskGraphEvent m_simulationFinishedTGEvent; + AZStd::atomic_bool m_simulationFinishedWorkActive = false; + // CPU simulation job completion for track all feature processors' simulation jobs AZ::JobCompletion* m_simulationCompletion = nullptr; @@ -228,6 +246,7 @@ namespace AZ SceneId m_id; bool m_activated = false; + bool m_taskGraphActive = false; // update during tick, to ensure it only changes on frame boundaries RenderPipelinePtr m_defaultPipeline; diff --git a/Gems/Atom/RPI/Code/Source/RPI.Builders/Model/ModelAssetBuilderComponent.cpp b/Gems/Atom/RPI/Code/Source/RPI.Builders/Model/ModelAssetBuilderComponent.cpp index 1da16b44b6..9fc99e3ea4 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Builders/Model/ModelAssetBuilderComponent.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Builders/Model/ModelAssetBuilderComponent.cpp @@ -1078,7 +1078,9 @@ namespace AZ template void ModelAssetBuilderComponent::ValidateStreamSize([[maybe_unused]] size_t expectedVertexCount, [[maybe_unused]] const AZStd::vector& bufferData, [[maybe_unused]] AZ::RHI::Format format, [[maybe_unused]] const char* streamName) const { +#if defined(AZ_ENABLE_TRACING) size_t actualVertexCount = (bufferData.size() * sizeof(T)) / RHI::GetFormatSize(format); +#endif AZ_Error(s_builderName, expectedVertexCount == actualVertexCount, "VertexStream '%s' does not match the expected vertex count. This typically means multiple sub-meshes have mis-matched vertex stream layouts (such as one having more uv sets than the other) but are assigned the same material in the dcc tool so they were merged.", streamName); } diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Scene.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Scene.cpp index 646cba1999..c5d82c6f29 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Scene.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Scene.cpp @@ -23,6 +23,8 @@ #include #include +#include + #include namespace AZ @@ -92,7 +94,14 @@ namespace AZ Scene::~Scene() { - WaitAndCleanCompletionJob(m_simulationCompletion); + if (m_taskGraphActive) + { + WaitTGEvent(m_simulationFinishedTGEvent, &m_simulationFinishedWorkActive); + } + else + { + WaitAndCleanCompletionJob(m_simulationCompletion); + } SceneRequestBus::Handler::BusDisconnect(); // Remove all the render pipelines. Need to process queued changes with pass system before and after remove render pipelines @@ -346,6 +355,47 @@ namespace AZ return nullptr; } + void Scene::SimulateTaskGraph() + { + static const AZ::TaskDescriptor simulationTGDesc{"RPI::Scene::Simulate", "Graphics"}; + AZ::TaskGraph simulationTG; + + for (FeatureProcessorPtr& fp : m_featureProcessors) + { + FeatureProcessor* featureProcessor = fp.get(); + simulationTG.AddTask( + simulationTGDesc, + [this, featureProcessor]() + { + featureProcessor->Simulate(m_simulatePacket); + }); + } + simulationTG.Detach(); + m_simulationFinishedWorkActive = true; + simulationTG.Submit(&m_simulationFinishedTGEvent); + } + + void Scene::SimulateJobs() + { + // Create a new job to track completion. + m_simulationCompletion = aznew AZ::JobCompletion(); + + for (FeatureProcessorPtr& fp : m_featureProcessors) + { + FeatureProcessor* featureProcessor = fp.get(); + const auto jobLambda = [this, featureProcessor]() + { + + featureProcessor->Simulate(m_simulatePacket); + }; + + AZ::Job* simulationJob = AZ::CreateJobFunction(AZStd::move(jobLambda), true, nullptr); //auto-deletes + simulationJob->SetDependent(m_simulationCompletion); + simulationJob->Start(); + } + //[GFX TODO]: the completion job should start here + } + void Scene::Simulate([[maybe_unused]] const TickTimeInfo& tickInfo, RHI::JobPolicy jobPolicy) { AZ_PROFILE_SCOPE(RPI, "Scene: Simulate"); @@ -353,7 +403,17 @@ namespace AZ m_simulationTime = tickInfo.m_currentGameTime; // If previous simulation job wasn't done, wait for it to finish. - WaitAndCleanCompletionJob(m_simulationCompletion); + if (m_taskGraphActive) + { + WaitTGEvent(m_simulationFinishedTGEvent, &m_simulationFinishedWorkActive); + } + else + { + WaitAndCleanCompletionJob(m_simulationCompletion); + } + + auto taskGraphActiveInterface = AZ::Interface::Get(); + m_taskGraphActive = taskGraphActiveInterface && taskGraphActiveInterface->IsTaskGraphActive(); if (jobPolicy == RHI::JobPolicy::Serial) { @@ -364,22 +424,27 @@ namespace AZ } else { - // Create a new job to track completion. - m_simulationCompletion = aznew AZ::JobCompletion(); - - for (FeatureProcessorPtr& fp : m_featureProcessors) + if (m_taskGraphActive) { - FeatureProcessor* featureProcessor = fp.get(); - const auto jobLambda = [this, featureProcessor]() - { - featureProcessor->Simulate(m_simulatePacket); - }; - - AZ::Job* simulationJob = AZ::CreateJobFunction(AZStd::move(jobLambda), true, nullptr); //auto-deletes - simulationJob->SetDependent(m_simulationCompletion); - simulationJob->Start(); + SimulateTaskGraph(); } - //[GFX TODO]: the completion job should start here + else + { + SimulateJobs(); + } + } + } + + void Scene::WaitTGEvent(AZ::TaskGraphEvent& completionTGEvent, AZStd::atomic_bool* workToWaitOn ) + { + AZ_PROFILE_SCOPE(RPI, "Scene: WaitAndCleanCompletionJob"); + if (!workToWaitOn || workToWaitOn->load()) + { + completionTGEvent.Wait(); + } + if (workToWaitOn) + { + workToWaitOn->store(false); } } @@ -394,7 +459,7 @@ namespace AZ completionJob = nullptr; } } - + void Scene::ConnectEvent(PrepareSceneSrgEvent::Handler& handler) { handler.Connect(m_prepareSrgEvent); @@ -418,12 +483,139 @@ namespace AZ } } + void Scene::CollectDrawPacketsTaskGraph() + { + AZ_PROFILE_SCOPE(RPI, "CollectDrawPackets"); + AZ::TaskGraphEvent collectDrawPacketsTGEvent; + static const AZ::TaskDescriptor collectDrawPacketsTGDesc{"RPI_Scene_PrepareRender_CollectDrawPackets", "Graphics"}; + + AZ::TaskGraph collectDrawPacketsTG; + // Launch FeatureProcessor::Render() jobs + for (auto& fp : m_featureProcessors) + { + collectDrawPacketsTG.AddTask( + collectDrawPacketsTGDesc, + [this, &fp]() + { + fp->Render(m_renderPacket); + }); + + } + collectDrawPacketsTG.Submit(&collectDrawPacketsTGEvent); + + // Launch CullingSystem::ProcessCullables() jobs (will run concurrently with FeatureProcessor::Render() jobs if m_parallelOctreeTraversal) + bool parallelOctreeTraversal = m_cullingScene->GetDebugContext().m_parallelOctreeTraversal; + m_cullingScene->BeginCulling(m_renderPacket.m_views); + AZ::JobCompletion processCullablesCompletion; + for (ViewPtr& viewPtr : m_renderPacket.m_views) + { + AZ::Job* processCullablesJob = AZ::CreateJobFunction([this, &viewPtr](AZ::Job& thisJob) + { + m_cullingScene->ProcessCullables(*this, *viewPtr, thisJob); // can't call directly because ProcessCullables needs a parent job + }, + true, nullptr); //auto-deletes + if (parallelOctreeTraversal) + { + processCullablesJob->SetDependent(&processCullablesCompletion); + processCullablesJob->Start(); + } + else + { + processCullablesJob->StartAndWaitForCompletion(); + } + } + + WaitTGEvent(collectDrawPacketsTGEvent); + processCullablesCompletion.StartAndWaitForCompletion(); + } + + void Scene::CollectDrawPacketsJobs() + { + AZ_PROFILE_SCOPE(RPI, "CollectDrawPackets"); + AZ::JobCompletion* collectDrawPacketsCompletion = aznew AZ::JobCompletion(); + + // Launch FeatureProcessor::Render() jobs + for (auto& fp : m_featureProcessors) + { + const auto renderLambda = [this, &fp]() + { + fp->Render(m_renderPacket); + }; + + AZ::Job* renderJob = AZ::CreateJobFunction(AZStd::move(renderLambda), true, nullptr); //auto-deletes + renderJob->SetDependent(collectDrawPacketsCompletion); + renderJob->Start(); + } + + // Launch CullingSystem::ProcessCullables() jobs (will run concurrently with FeatureProcessor::Render() jobs) + m_cullingScene->BeginCulling(m_renderPacket.m_views); + for (ViewPtr& viewPtr : m_renderPacket.m_views) + { + AZ::Job* processCullablesJob = AZ::CreateJobFunction([this, &viewPtr](AZ::Job& thisJob) + { + m_cullingScene->ProcessCullables(*this, *viewPtr, thisJob); // can't call directly because ProcessCullables needs a parent job + }, + true, nullptr); //auto-deletes + if (m_cullingScene->GetDebugContext().m_parallelOctreeTraversal) + { + processCullablesJob->SetDependent(collectDrawPacketsCompletion); + processCullablesJob->Start(); + } + else + { + processCullablesJob->StartAndWaitForCompletion(); + } + } + + WaitAndCleanCompletionJob(collectDrawPacketsCompletion); + } + + void Scene::FinalizeDrawListsTaskGraph() + { + AZ::TaskGraphEvent finalizeDrawListsTGEvent; + static const AZ::TaskDescriptor finalizeDrawListsTGDesc{"RPI_Scene_PrepareRender_FinalizeDrawLists", "Graphics"}; + + AZ::TaskGraph finalizeDrawListsTG; + for (auto& view : m_renderPacket.m_views) + { + finalizeDrawListsTG.AddTask( + finalizeDrawListsTGDesc, + [view]() + { + view->FinalizeDrawLists(); + }); + } + finalizeDrawListsTG.Submit(&finalizeDrawListsTGEvent); + WaitTGEvent(finalizeDrawListsTGEvent); + } + + void Scene::FinalizeDrawListsJobs() + { + AZ::JobCompletion* finalizeDrawListsCompletion = aznew AZ::JobCompletion(); + for (auto& view : m_renderPacket.m_views) + { + const auto finalizeDrawListsLambda = [view]() + { + view->FinalizeDrawLists(); + }; + + AZ::Job* finalizeDrawListsJob = AZ::CreateJobFunction(AZStd::move(finalizeDrawListsLambda), true, nullptr); //auto-deletes + finalizeDrawListsJob->SetDependent(finalizeDrawListsCompletion); + finalizeDrawListsJob->Start(); + } + WaitAndCleanCompletionJob(finalizeDrawListsCompletion); + } + void Scene::PrepareRender(const TickTimeInfo& tickInfo, RHI::JobPolicy jobPolicy) { AZ_PROFILE_SCOPE(RPI, "Scene: PrepareRender"); + if (m_taskGraphActive) + { + WaitTGEvent(m_simulationFinishedTGEvent, &m_simulationFinishedWorkActive); + } + else { - AZ_PROFILE_SCOPE(RPI, "WaitForSimulationCompletion"); WaitAndCleanCompletionJob(m_simulationCompletion); } @@ -496,44 +688,16 @@ namespace AZ } { - AZ_PROFILE_SCOPE(RPI, "CollectDrawPackets"); - AZ::JobCompletion* collectDrawPacketsCompletion = aznew AZ::JobCompletion(); - // Launch FeatureProcessor::Render() jobs - for (auto& fp : m_featureProcessors) + if (m_taskGraphActive) { - const auto renderLambda = [this, &fp]() - { - fp->Render(m_renderPacket); - }; - - AZ::Job* renderJob = AZ::CreateJobFunction(AZStd::move(renderLambda), true, nullptr); //auto-deletes - renderJob->SetDependent(collectDrawPacketsCompletion); - renderJob->Start(); + CollectDrawPacketsTaskGraph(); } - - // Launch CullingSystem::ProcessCullables() jobs (will run concurrently with FeatureProcessor::Render() jobs) - m_cullingScene->BeginCulling(m_renderPacket.m_views); - for (ViewPtr& viewPtr : m_renderPacket.m_views) + else { - AZ::Job* processCullablesJob = AZ::CreateJobFunction([this, &viewPtr](AZ::Job& thisJob) - { - m_cullingScene->ProcessCullables(*this, *viewPtr, thisJob); - }, - true, nullptr); //auto-deletes - if (m_cullingScene->GetDebugContext().m_parallelOctreeTraversal) - { - processCullablesJob->SetDependent(collectDrawPacketsCompletion); - processCullablesJob->Start(); - } - else - { - processCullablesJob->StartAndWaitForCompletion(); - } + CollectDrawPacketsJobs(); } - WaitAndCleanCompletionJob(collectDrawPacketsCompletion); - m_cullingScene->EndCulling(); // Add dynamic draw data for all the views @@ -556,20 +720,15 @@ namespace AZ } else { - AZ::JobCompletion* finalizeDrawListsCompletion = aznew AZ::JobCompletion(); - for (auto& view : m_renderPacket.m_views) + if (m_taskGraphActive) { - const auto finalizeDrawListsLambda = [view]() - { - view->FinalizeDrawLists(); - }; - - AZ::Job* finalizeDrawListsJob = AZ::CreateJobFunction(AZStd::move(finalizeDrawListsLambda), true, nullptr); //auto-deletes - finalizeDrawListsJob->SetDependent(finalizeDrawListsCompletion); - finalizeDrawListsJob->Start(); + FinalizeDrawListsTaskGraph(); + } + else + { + FinalizeDrawListsJobs(); } AZ_PROFILE_END(RPI); - WaitAndCleanCompletionJob(finalizeDrawListsCompletion); } } diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/ShaderVariantAsyncLoader.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/ShaderVariantAsyncLoader.cpp index 4855fbd864..36109b7b82 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/ShaderVariantAsyncLoader.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/ShaderVariantAsyncLoader.cpp @@ -24,12 +24,11 @@ namespace AZ threadDesc.m_name = "ShaderVariantAsyncLoader"; m_serviceThread = AZStd::thread( + threadDesc, [this]() { this->ThreadServiceLoop(); - }, - &threadDesc - ); + }); } void ShaderVariantAsyncLoader::ThreadServiceLoop() diff --git a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Material/MaterialFunctor.cpp b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Material/MaterialFunctor.cpp index 0f70d0af35..52b6349ca0 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Material/MaterialFunctor.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Material/MaterialFunctor.cpp @@ -417,14 +417,16 @@ namespace AZ template const Color& MaterialFunctor::EditorContext::GetMaterialPropertyValue (const MaterialPropertyIndex& index) const; template const Data::Instance& MaterialFunctor::EditorContext::GetMaterialPropertyValue> (const MaterialPropertyIndex& index) const; - void CheckPropertyAccess(const MaterialPropertyIndex& index, const MaterialPropertyFlags& materialPropertyDependencies, [[maybe_unused]] const MaterialPropertiesLayout& materialPropertiesLayout) + void CheckPropertyAccess([[maybe_unused]] const MaterialPropertyIndex& index, [[maybe_unused]] const MaterialPropertyFlags& materialPropertyDependencies, [[maybe_unused]] const MaterialPropertiesLayout& materialPropertiesLayout) { +#if defined(AZ_ENABLE_TRACING) if (!materialPropertyDependencies.test(index.GetIndex())) { const MaterialPropertyDescriptor* propertyDescriptor = materialPropertiesLayout.GetPropertyDescriptor(index); AZ_Error("MaterialFunctor", false, "Material functor accessing an unregistered material property '%s'.", propertyDescriptor ? propertyDescriptor->GetName().GetCStr() : ""); } +#endif } const MaterialPropertyValue& MaterialFunctor::RuntimeContext::GetMaterialPropertyValue(const MaterialPropertyIndex& index) const diff --git a/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/001_DefaultWhite.material b/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/001_DefaultWhite.material index 8fe732cb09..2e4eee7f8e 100644 --- a/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/001_DefaultWhite.material +++ b/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/001_DefaultWhite.material @@ -1,6 +1,6 @@ { "description": "", - "materialType": "Materials\\Types\\StandardPBR.materialtype", + "materialType": "Materials/Types/StandardPBR.materialtype", "parentMaterial": "", "propertyLayoutVersion": 3 -} +} \ No newline at end of file diff --git a/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/002_BaseColorLerp.material b/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/002_BaseColorLerp.material index 8509e08d78..f8214e1b2e 100644 --- a/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/002_BaseColorLerp.material +++ b/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/002_BaseColorLerp.material @@ -1,6 +1,6 @@ { "description": "", - "materialType": "Materials\\Types\\StandardPBR.materialtype", + "materialType": "Materials/Types/StandardPBR.materialtype", "parentMaterial": "", "propertyLayoutVersion": 3, "properties": { @@ -16,4 +16,4 @@ "textureMap": "TestData/Textures/TextureHaven/4k_castle_brick_02_red/4k_castle_brick_02_red_hp_bc.png" } } -} +} \ No newline at end of file diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp index 24e78b5ad3..a8f41917f9 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp @@ -190,7 +190,7 @@ namespace MaterialEditor void MaterialViewportComponent::ReloadContent() { - AZ_TracePrintf("Material Editor", "Started loading viewport configurtions.\n"); + AZ_TracePrintf("Material Editor", "Started loading viewport configurations.\n"); MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnBeginReloadContent); @@ -239,7 +239,7 @@ namespace MaterialEditor { auto presetPtr = AddLightingPreset(*preset); m_lightingPresetLastSavePathMap[presetPtr] = AZ::RPI::AssetUtils::GetSourcePathByAssetId(info.m_assetId); - AZ_TracePrintf("Material Editor", "Loaded viewport configurtion: %s.\n", info.m_relativePath.c_str()); + AZ_TracePrintf("Material Editor", "Loaded viewport configuration: %s.\n", info.m_relativePath.c_str()); } } } @@ -258,7 +258,7 @@ namespace MaterialEditor { auto presetPtr = AddModelPreset(*preset); m_modelPresetLastSavePathMap[presetPtr] = AZ::RPI::AssetUtils::GetSourcePathByAssetId(info.m_assetId); - AZ_TracePrintf("Material Editor", "Loaded viewport configurtion: %s.\n", info.m_relativePath.c_str()); + AZ_TracePrintf("Material Editor", "Loaded viewport configuration: %s.\n", info.m_relativePath.c_str()); } } } @@ -271,7 +271,7 @@ namespace MaterialEditor MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnEndReloadContent); - AZ_TracePrintf("Material Editor", "Finished loading viewport configurtions.\n"); + AZ_TracePrintf("Material Editor", "Finished loading viewport configurations.\n"); } AZ::Render::LightingPresetPtr MaterialViewportComponent::AddLightingPreset(const AZ::Render::LightingPreset& preset) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/Icons/skybox.svg b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/Icons/skybox.svg new file mode 100644 index 0000000000..83df996198 --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/Icons/skybox.svg @@ -0,0 +1,15 @@ + + + + icon / Environmental / Sky Highlight + Created with Sketch. + + + + + + + + + + \ No newline at end of file diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditor.qrc b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditor.qrc index cde48079ac..902201e792 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditor.qrc +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditor.qrc @@ -19,6 +19,7 @@ Icons/texture_edit.png Icons/grid.svg Icons/shadow.svg + Icons/skybox.svg Icons/toneMapping.svg Icons/View.svg diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp index 55829fd744..1e189168da 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp @@ -50,8 +50,16 @@ namespace MaterialEditor }); m_toggleShadowCatcher->setChecked(viewportSettings->m_enableShadowCatcher); - // Add mapping selection button + // Add toggle alternate skybox button + m_toggleAlternateSkybox = addAction(QIcon(":/Icons/skybox.svg"), "Toggle Alternate Skybox"); + m_toggleAlternateSkybox->setCheckable(true); + connect(m_toggleAlternateSkybox, &QAction::triggered, [this]() { + MaterialViewportRequestBus::Broadcast( + &MaterialViewportRequestBus::Events::SetAlternateSkyboxEnabled, m_toggleAlternateSkybox->isChecked()); + }); + m_toggleAlternateSkybox->setChecked(viewportSettings->m_enableAlternateSkybox); + // Add mapping selection button QToolButton* toneMappingButton = new QToolButton(this); QMenu* toneMappingMenu = new QMenu(toneMappingButton); @@ -105,6 +113,11 @@ namespace MaterialEditor m_toggleGrid->setChecked(enable); } + void MaterialEditorToolBar::OnAlternateSkyboxEnabledChanged(bool enable) + { + m_toggleAlternateSkybox->setChecked(enable); + } + void MaterialEditorToolBar::OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) { for (auto operationActionPair : m_operationActions) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h index d68c23665f..c25b90eb80 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.h @@ -29,10 +29,12 @@ namespace MaterialEditor // MaterialViewportNotificationBus::Handler overrides... void OnShadowCatcherEnabledChanged([[maybe_unused]] bool enable) override; void OnGridEnabledChanged([[maybe_unused]] bool enable) override; + void OnAlternateSkyboxEnabledChanged([[maybe_unused]] bool enable) override; void OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) override; QAction* m_toggleGrid = {}; QAction* m_toggleShadowCatcher = {}; + QAction* m_toggleAlternateSkybox = {}; AZStd::unordered_map m_operationNames; AZStd::unordered_map m_operationActions; diff --git a/Gems/Atom/Utils/Code/Source/PngFile.cpp b/Gems/Atom/Utils/Code/Source/PngFile.cpp index 09a5d950e5..28f5374d88 100644 --- a/Gems/Atom/Utils/Code/Source/PngFile.cpp +++ b/Gems/Atom/Utils/Code/Source/PngFile.cpp @@ -21,7 +21,7 @@ namespace AZ (*errorHandler)(error_msg); } - void PngImage_user_warning_fn(png_structp /*png_ptr*/, png_const_charp warning_msg) + void PngImage_user_warning_fn(png_structp /*png_ptr*/, [[maybe_unused]] png_const_charp warning_msg) { AZ_Warning("PngFile", false, "%s", warning_msg); } @@ -301,7 +301,7 @@ AZ_POP_DISABLE_WARNING return true; } - void PngFile::DefaultErrorHandler(const char* message) + void PngFile::DefaultErrorHandler([[maybe_unused]] const char* message) { AZ_Error("PngFile", false, "%s", message); } diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp index 83ddbf46c5..a6b595940f 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp @@ -137,7 +137,7 @@ namespace AZ arguments.append(QString("--project-path=%1").arg(projectPath.c_str())); } - AtomToolsFramework::LaunchTool("MaterialEditor", ".exe", arguments); + AtomToolsFramework::LaunchTool("MaterialEditor", AZ_TRAIT_OS_EXECUTABLE_EXTENSION, arguments); } void EditorMaterialSystemComponent::OpenMaterialInspector( diff --git a/Gems/AudioSystem/Code/Source/Engine/AudioSystem.cpp b/Gems/AudioSystem/Code/Source/Engine/AudioSystem.cpp index 5f3603c956..67c5325be9 100644 --- a/Gems/AudioSystem/Code/Source/Engine/AudioSystem.cpp +++ b/Gems/AudioSystem/Code/Source/Engine/AudioSystem.cpp @@ -56,7 +56,7 @@ namespace Audio threadDesc.m_cpuId = AZ_TRAIT_AUDIOSYSTEM_AUDIO_THREAD_AFFINITY; auto threadFunc = AZStd::bind(&CAudioThread::Run, this); - m_thread = AZStd::thread(threadFunc, &threadDesc); + m_thread = AZStd::thread(threadDesc, threadFunc); } /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Gems/BarrierInput/Code/Source/BarrierInputClient.cpp b/Gems/BarrierInput/Code/Source/BarrierInputClient.cpp index e6d5399561..ec4cbcfbd1 100644 --- a/Gems/BarrierInput/Code/Source/BarrierInputClient.cpp +++ b/Gems/BarrierInput/Code/Source/BarrierInputClient.cpp @@ -347,7 +347,7 @@ namespace BarrierInput { AZStd::thread_desc threadDesc; threadDesc.m_name = "BarrierInputClientThread"; - m_threadHandle = AZStd::thread(AZStd::bind(&BarrierClient::Run, this), &threadDesc); + m_threadHandle = AZStd::thread(threadDesc, AZStd::bind(&BarrierClient::Run, this)); } //////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.cpp index 8ca4e1de81..06088790d9 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.cpp @@ -69,6 +69,9 @@ AZ_PUSH_DISABLE_WARNING(4267, "-Wconversion") AZ_POP_DISABLE_WARNING #include +#include +#include + namespace EMStudio { class SaveDirtyWorkspaceCallback @@ -257,10 +260,10 @@ namespace EMStudio m_saveWorkspaceCallback = nullptr; } - - // destructor MainWindow::~MainWindow() { + DisableUpdatingPlugins(); + if (m_nativeEventFilter) { QAbstractEventDispatcher::instance()->removeNativeEventFilter(m_nativeEventFilter); @@ -577,6 +580,8 @@ namespace EMStudio AZ_Assert(!m_nativeEventFilter, "Double initialization?"); m_nativeEventFilter = new NativeEventFilter(this); QAbstractEventDispatcher::instance()->installNativeEventFilter(m_nativeEventFilter); + + EnableUpdatingPlugins(); } MainWindow::MainWindowCommandManagerCallback::MainWindowCommandManagerCallback() @@ -2813,6 +2818,53 @@ namespace EMStudio } } -} // namespace EMStudio + void MainWindow::UpdatePlugins(float timeDelta) + { + EMStudio::PluginManager* pluginManager = EMStudio::GetPluginManager(); + if (!pluginManager) + { + return; + } -#include + const size_t numPlugins = pluginManager->GetNumActivePlugins(); + for (size_t i = 0; i < numPlugins; ++i) + { + EMStudio::EMStudioPlugin* plugin = pluginManager->GetActivePlugin(i); + plugin->ProcessFrame(timeDelta); + } + } + + void MainWindow::EnableUpdatingPlugins() + { + AZ::TickBus::Handler::BusConnect(); + } + + void MainWindow::DisableUpdatingPlugins() + { + AZ::TickBus::Handler::BusDisconnect(); + } + + void MainWindow::OnTick(float delta, AZ::ScriptTimePoint timePoint) + { + AZ_UNUSED(timePoint); + + // Check if we are in game mode. + IEditor* editor = nullptr; + AzToolsFramework::EditorRequestBus::BroadcastResult(editor, &AzToolsFramework::EditorRequests::GetEditor); + const bool inGameMode = editor ? editor->IsInGameMode() : false; + + // Update all the animation editor plugins (redraw viewports, timeline, and graph windows etc). + // But only update this when the main window is visible and we are in game mode. + const bool isEditorActive = !visibleRegion().isEmpty() && !inGameMode; + + if (isEditorActive) + { + UpdatePlugins(delta); + } + } + + int MainWindow::GetTickOrder() + { + return AZ::TICK_UI; + } +} // namespace EMStudio diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.h index a11f11c6a8..585101f7d2 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MainWindow.h @@ -9,6 +9,7 @@ #pragma once #if !defined(Q_MOC_RUN) +#include #include #include #include @@ -99,8 +100,9 @@ namespace EMStudio : public AzQtComponents::DockMainWindow , private PluginOptionsNotificationsBus::Router , public EMotionFX::ActorEditorRequestBus::Handler + , private AZ::TickBus::Handler { - Q_OBJECT + Q_OBJECT // AUTOMOC MCORE_MEMORYOBJECTCATEGORY(MainWindow, MCore::MCORE_DEFAULT_ALIGNMENT, MEMCATEGORY_EMSTUDIOSDK) public: @@ -304,6 +306,16 @@ namespace EMStudio MainWindowCommandManagerCallback m_mainWindowCommandManagerCallback; + private: + // AZ::TickBus::Handler overrides + void OnTick(float delta, AZ::ScriptTimePoint timePoint) override; + int GetTickOrder() override; + + void UpdatePlugins(float timeDelta); + + void EnableUpdatingPlugins(); + void DisableUpdatingPlugins(); + public slots: void OnFileOpenActor(); void OnFileSaveSelectedActors(); diff --git a/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.cpp b/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.cpp index 56c22bb1ff..0f87c488b9 100644 --- a/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.cpp @@ -62,7 +62,6 @@ #if defined(EMOTIONFXANIMATION_EDITOR) // EMFX tools / editor includes -# include // Qt # include // EMStudio tools and main window registration @@ -603,31 +602,6 @@ namespace EMotionFX #endif } - ////////////////////////////////////////////////////////////////////////// -#if defined (EMOTIONFXANIMATION_EDITOR) - void SystemComponent::UpdateAnimationEditorPlugins(float delta) - { - if (!EMStudio::GetManager()) - { - return; - } - - EMStudio::PluginManager* pluginManager = EMStudio::GetPluginManager(); - if (!pluginManager) - { - return; - } - - // Process the plugins. - const size_t numPlugins = pluginManager->GetNumActivePlugins(); - for (size_t i = 0; i < numPlugins; ++i) - { - EMStudio::EMStudioPlugin* plugin = pluginManager->GetActivePlugin(i); - plugin->ProcessFrame(delta); - } - } -#endif - ////////////////////////////////////////////////////////////////////////// void SystemComponent::OnTick(float delta, AZ::ScriptTimePoint timePoint) { @@ -635,47 +609,18 @@ namespace EMotionFX #if defined (EMOTIONFXANIMATION_EDITOR) AZ_UNUSED(delta); - const float realDelta = m_updateTimer.StampAndGetDeltaTimeInSeconds(); + delta = m_updateTimer.StampAndGetDeltaTimeInSeconds(); +#endif // Flush events prior to updating EMotion FX. ActorNotificationBus::ExecuteQueuedEvents(); - if (CVars::emfx_updateEnabled) - { - // Main EMotionFX runtime update. - GetEMotionFX().Update(realDelta); - } - - // Check if we are in game mode. - IEditor* editor = nullptr; - EBUS_EVENT_RESULT(editor, AzToolsFramework::EditorRequests::Bus, GetEditor); - const bool inGameMode = editor ? editor->IsInGameMode() : false; - - // Update all the animation editor plugins (redraw viewports, timeline, and graph windows etc). - // But only update this when the main window is visible and we are in game mode. - const bool isEditorActive = - EMotionFX::GetEMotionFX().GetIsInEditorMode() && - EMStudio::GetManager() && - EMStudio::HasMainWindow() && - !EMStudio::GetMainWindow()->visibleRegion().isEmpty() && - !inGameMode; - - if (isEditorActive) - { - UpdateAnimationEditorPlugins(realDelta); - } -#else - // Flush events prior to updating EMotion FX. - ActorNotificationBus::ExecuteQueuedEvents(); - if (CVars::emfx_updateEnabled) { // Main EMotionFX runtime update. GetEMotionFX().Update(delta); } -#endif - const float timeDelta = delta; const ActorManager* actorManager = GetEMotionFX().GetActorManager(); const size_t numActorInstances = actorManager->GetNumActorInstances(); for (size_t i = 0; i < numActorInstances; ++i) @@ -704,7 +649,7 @@ namespace EMotionFX // If we have a physics controller. if (hasCustomMotionExtractionController || hasPhysicsController) { - const float deltaTimeInv = (timeDelta > 0.0f) ? (1.0f / timeDelta) : 0.0f; + const float deltaTimeInv = (delta > 0.0f) ? (1.0f / delta) : 0.0f; AZ::Transform currentTransform = AZ::Transform::CreateIdentity(); AZ::TransformBus::EventResult(currentTransform, entityId, &AZ::TransformBus::Events::GetWorldTM); @@ -719,7 +664,7 @@ namespace EMotionFX } else if (hasCustomMotionExtractionController) { - MotionExtractionRequestBus::Event(entityId, &MotionExtractionRequestBus::Events::ExtractMotion, positionDelta, timeDelta); + MotionExtractionRequestBus::Event(entityId, &MotionExtractionRequestBus::Events::ExtractMotion, positionDelta, delta); AZ::TransformBus::EventResult(currentTransform, entityId, &AZ::TransformBus::Events::GetWorldTM); } @@ -884,7 +829,7 @@ namespace EMotionFX // Register EMotionFX window with the main editor. AzToolsFramework::ViewPaneOptions emotionFXWindowOptions; - emotionFXWindowOptions.isPreview = true; + emotionFXWindowOptions.isPreview = false; emotionFXWindowOptions.isDeletable = true; emotionFXWindowOptions.isDockable = false; #if AZ_TRAIT_EMOTIONFX_MAIN_WINDOW_DETACHED diff --git a/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.h b/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.h index a716f0aa9b..5e30820ca3 100644 --- a/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.h +++ b/Gems/EMotionFX/Code/Source/Integration/System/SystemComponent.h @@ -108,7 +108,6 @@ namespace EMotionFX void SetMediaRoot(const char* alias); #if defined (EMOTIONFXANIMATION_EDITOR) - void UpdateAnimationEditorPlugins(float delta); void NotifyRegisterViews() override; bool IsSystemActive(EditorAnimationSystemRequests::AnimationSystem systemType) override; diff --git a/Gems/HttpRequestor/Code/Source/HttpRequestManager.cpp b/Gems/HttpRequestor/Code/Source/HttpRequestManager.cpp index d33f37a2d7..06cf018f76 100644 --- a/Gems/HttpRequestor/Code/Source/HttpRequestManager.cpp +++ b/Gems/HttpRequestor/Code/Source/HttpRequestManager.cpp @@ -37,7 +37,7 @@ namespace HttpRequestor m_runThread = true; AWSNativeSDKInit::InitializationManager::InitAwsApi(); auto function = AZStd::bind(&Manager::ThreadFunction, this); - m_thread = AZStd::thread(function, &desc); + m_thread = AZStd::thread(desc, function); } Manager::~Manager() diff --git a/Gems/LmbrCentral/Code/Source/Builders/BenchmarkAssetBuilder/BenchmarkAssetBuilderWorker.cpp b/Gems/LmbrCentral/Code/Source/Builders/BenchmarkAssetBuilder/BenchmarkAssetBuilderWorker.cpp index 22be22265a..da7181ae04 100644 --- a/Gems/LmbrCentral/Code/Source/Builders/BenchmarkAssetBuilder/BenchmarkAssetBuilderWorker.cpp +++ b/Gems/LmbrCentral/Code/Source/Builders/BenchmarkAssetBuilder/BenchmarkAssetBuilderWorker.cpp @@ -253,10 +253,12 @@ namespace BenchmarkAssetBuilder // and 2 bytes of storage for text-based formats. // This is just an approximate total size because there's a bit of additional overhead // for asset headers and the other fields in the generated asset. +#if defined(AZ_ENABLE_TRACING) uint64_t approximateTotalStorageBytes = (settingsPtr->m_assetStorageType == AZ::DataStream::StreamType::ST_BINARY) ? UINT64_C(1) * totalGeneratedBytes : UINT64_C(2) * totalGeneratedBytes; +#endif AZ_TracePrintf(AssetBuilderSDK::InfoWindow, "Benchmark asset generation will generate %" PRIu64 " assets " diff --git a/Gems/LmbrCentral/Code/Source/Builders/LevelBuilder/LevelBuilderWorker.cpp b/Gems/LmbrCentral/Code/Source/Builders/LevelBuilder/LevelBuilderWorker.cpp index 95a908b20c..631bc41358 100644 --- a/Gems/LmbrCentral/Code/Source/Builders/LevelBuilder/LevelBuilderWorker.cpp +++ b/Gems/LmbrCentral/Code/Source/Builders/LevelBuilder/LevelBuilderWorker.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -155,35 +156,17 @@ namespace LevelBuilder { PopulateOptionalLevelDependencies(sourceRelativeFile, productPathDependencies); - AZStd::binary_semaphore extractionCompleteSemaphore; - auto extractResponseLambda = [&]([[maybe_unused]] bool success) { - AZStd::string levelsubfolder; - AzFramework::StringFunc::Path::Join(tempDirectory.c_str(), "level", levelsubfolder); + std::future extractResult; + AzToolsFramework::ArchiveCommandsBus::BroadcastResult( + extractResult, &AzToolsFramework::ArchiveCommandsBus::Events::ExtractArchive, levelPakFile, tempDirectory); - PopulateLevelSliceDependencies(levelsubfolder, productDependencies, productPathDependencies); - PopulateMissionDependencies(levelPakFile, levelsubfolder, productPathDependencies); - PopulateLevelAudioControlDependencies(levelPakFile, productPathDependencies); + extractResult.wait(); - extractionCompleteSemaphore.release(); - }; + auto levelsubfolder = AZ::IO::Path(tempDirectory) / "level"; - AZ::Uuid handle = AZ::Uuid::Create(); - AzToolsFramework::ArchiveCommands::Bus::Broadcast( - &AzToolsFramework::ArchiveCommands::ExtractArchive, - levelPakFile, - tempDirectory, - handle, - extractResponseLambda); - - const int archiveExtractSleepMS = 20; - bool extractionCompleted = false; - while (!extractionCompleted) - { - extractionCompleted = extractionCompleteSemaphore.try_acquire_for(AZStd::chrono::milliseconds(archiveExtractSleepMS)); - // When the archive extraction is completed, the response lambda is queued on the the tick bus. - // This loop will keep executing queued events on the tickbus until the response unlocks the semaphore. - AZ::TickBus::ExecuteQueuedEvents(); - } + PopulateLevelSliceDependencies(levelsubfolder.Native(), productDependencies, productPathDependencies); + PopulateMissionDependencies(levelPakFile, levelsubfolder.Native(), productPathDependencies); + PopulateLevelAudioControlDependencies(levelPakFile, productPathDependencies); } AZStd::string GetLastFolderFromPath(const AZStd::string& path) diff --git a/Gems/Microphone/Code/Source/Platform/Windows/MicrophoneSystemComponent_Windows.cpp b/Gems/Microphone/Code/Source/Platform/Windows/MicrophoneSystemComponent_Windows.cpp index c182ec4f3b..e0b1f1ae36 100644 --- a/Gems/Microphone/Code/Source/Platform/Windows/MicrophoneSystemComponent_Windows.cpp +++ b/Gems/Microphone/Code/Source/Platform/Windows/MicrophoneSystemComponent_Windows.cpp @@ -225,7 +225,7 @@ namespace Audio AZStd::thread_desc threadDesc; threadDesc.m_name = "MicrophoneCapture-WASAPI"; auto captureFunc = AZStd::bind(&MicrophoneSystemComponentWindows::RunAudioCapture, this); - m_captureThread = AZStd::thread(captureFunc, &threadDesc); + m_captureThread = AZStd::thread(threadDesc, captureFunc); return true; } diff --git a/Gems/PhysX/Code/Tests/PhysXMultithreadingTest.cpp b/Gems/PhysX/Code/Tests/PhysXMultithreadingTest.cpp index a0013402b1..205ad4f377 100644 --- a/Gems/PhysX/Code/Tests/PhysXMultithreadingTest.cpp +++ b/Gems/PhysX/Code/Tests/PhysXMultithreadingTest.cpp @@ -119,7 +119,7 @@ namespace PhysX void Start(int waitTimeMilliseconds) { m_waitTimeMilliseconds = waitTimeMilliseconds; - m_thread = AZStd::thread(AZStd::bind(&SceneQueryBase::Tick, this), &m_threadDesc); + m_thread = AZStd::thread(m_threadDesc, AZStd::bind(&SceneQueryBase::Tick, this)); } void Join() diff --git a/Gems/SaveData/Code/Source/SaveDataSystemComponent.cpp b/Gems/SaveData/Code/Source/SaveDataSystemComponent.cpp index dad6e24abc..e92df0da68 100644 --- a/Gems/SaveData/Code/Source/SaveDataSystemComponent.cpp +++ b/Gems/SaveData/Code/Source/SaveDataSystemComponent.cpp @@ -172,14 +172,15 @@ namespace SaveData // This is safe access outside the lock guard because we only remove elements from the list // after the thread completion flag has been set to true (see also JoinAllCompletedThreads). - threadCompletionPair->m_thread = AZStd::make_unique([&threadCompleteFlag = threadCompletionPair->m_threadComplete, - dataBuffer = AZStd::move(saveDataBufferParams.dataBuffer), - dataBufferSize = saveDataBufferParams.dataBufferSize, - dataBufferName = saveDataBufferParams.dataBufferName, - onSavedCallback = saveDataBufferParams.callback, - localUserId = saveDataBufferParams.localUserId, - absoluteFilePath, - useTemporaryFile]() + threadCompletionPair->m_thread = AZStd::make_unique(saveThreadDesc, + [&threadCompleteFlag = threadCompletionPair->m_threadComplete, + dataBuffer = AZStd::move(saveDataBufferParams.dataBuffer), + dataBufferSize = saveDataBufferParams.dataBufferSize, + dataBufferName = saveDataBufferParams.dataBufferName, + onSavedCallback = saveDataBufferParams.callback, + localUserId = saveDataBufferParams.localUserId, + absoluteFilePath, + useTemporaryFile]() { SaveDataNotifications::Result result = SaveDataNotifications::Result::ErrorUnspecified; @@ -234,7 +235,7 @@ namespace SaveData // Set the thread completion flag so it will be joined in JoinAllCompletedThreads. threadCompleteFlag = true; - }, &saveThreadDesc); + }); if (waitForCompletion) { @@ -301,9 +302,10 @@ namespace SaveData // This is safe access outside the lock guard because we only remove elements from the list // after the thread completion flag has been set to true (see also JoinAllCompletedThreads). - threadCompletionPair->m_thread = AZStd::make_unique([&threadCompleteFlag = threadCompletionPair->m_threadComplete, - loadDataBufferParams, - absoluteFilePath]() + threadCompletionPair->m_thread = AZStd::make_unique(loadThreadDesc, + [&threadCompleteFlag = threadCompletionPair->m_threadComplete, + loadDataBufferParams, + absoluteFilePath]() { SaveDataNotifications::DataBuffer dataBuffer = nullptr; AZ::u64 dataBufferSize = 0; @@ -352,7 +354,7 @@ namespace SaveData // Set the thread completion flag so it will be joined in JoinAllCompletedThreads. threadCompleteFlag = true; - }, &loadThreadDesc); + }); if (waitForCompletion) { diff --git a/Gems/ScriptCanvas/Code/Builder/ScriptCanvasBuilder.cpp b/Gems/ScriptCanvas/Code/Builder/ScriptCanvasBuilder.cpp index 3c168855d8..0eb748b2f1 100644 --- a/Gems/ScriptCanvas/Code/Builder/ScriptCanvasBuilder.cpp +++ b/Gems/ScriptCanvas/Code/Builder/ScriptCanvasBuilder.cpp @@ -182,12 +182,15 @@ namespace ScriptCanvasBuilder continue; } - // copy to override unused list for editor display - m_overridesUnused.push_back(*graphVariable); - auto& overrideValue = m_overridesUnused.back(); - overrideValue.DeepCopy(*graphVariable); - overrideValue.SetScriptInputControlVisibility(AZ::Edit::PropertyVisibility::Hide); - overrideValue.SetAllowSignalOnChange(false); + if (graphVariable->IsComponentProperty()) + { + // copy to override unused list for editor display + m_overridesUnused.push_back(*graphVariable); + auto& overrideValue = m_overridesUnused.back(); + overrideValue.DeepCopy(*graphVariable); + overrideValue.SetScriptInputControlVisibility(AZ::Edit::PropertyVisibility::Hide); + overrideValue.SetAllowSignalOnChange(false); + } } } diff --git a/Gems/ScriptCanvas/Code/Editor/View/Widgets/NodePalette/ScriptEventsNodePaletteTreeItemTypes.cpp b/Gems/ScriptCanvas/Code/Editor/View/Widgets/NodePalette/ScriptEventsNodePaletteTreeItemTypes.cpp index 704f67e034..da0e9c6045 100644 --- a/Gems/ScriptCanvas/Code/Editor/View/Widgets/NodePalette/ScriptEventsNodePaletteTreeItemTypes.cpp +++ b/Gems/ScriptCanvas/Code/Editor/View/Widgets/NodePalette/ScriptEventsNodePaletteTreeItemTypes.cpp @@ -154,7 +154,9 @@ namespace ScriptCanvasEditor const ScriptEvents::ScriptEvent& definition = data->m_definition; +#if defined(AZ_ENABLE_TRACING) bool recategorize = previousDefinition ? definition.GetCategory().compare(previousDefinition->GetCategory()) != 0 : false; +#endif AZ_Warning("ScriptCanvas", !recategorize, "Unable to recategorize ScriptEvents events while open. Please close and re-open the Script Canvas Editor to see the new categorization"); if (definition.GetName().empty()) diff --git a/Gems/ScriptEvents/Code/Include/ScriptEvents/ScriptEventDefinition.h b/Gems/ScriptEvents/Code/Include/ScriptEvents/ScriptEventDefinition.h index bc8112802b..a56e9b422b 100644 --- a/Gems/ScriptEvents/Code/Include/ScriptEvents/ScriptEventDefinition.h +++ b/Gems/ScriptEvents/Code/Include/ScriptEvents/ScriptEventDefinition.h @@ -11,7 +11,7 @@ #include #include -#include +#include #include namespace ScriptEvents diff --git a/Gems/ScriptEvents/Code/Include/ScriptEvents/ScriptEventMethod.h b/Gems/ScriptEvents/Code/Include/ScriptEvents/ScriptEventsMethod.h similarity index 100% rename from Gems/ScriptEvents/Code/Include/ScriptEvents/ScriptEventMethod.h rename to Gems/ScriptEvents/Code/Include/ScriptEvents/ScriptEventsMethod.h diff --git a/Gems/ScriptEvents/Code/Source/ScriptEventMethod.cpp b/Gems/ScriptEvents/Code/Source/ScriptEventsMethod.cpp similarity index 99% rename from Gems/ScriptEvents/Code/Source/ScriptEventMethod.cpp rename to Gems/ScriptEvents/Code/Source/ScriptEventsMethod.cpp index 5b7bb590af..579c51a782 100644 --- a/Gems/ScriptEvents/Code/Source/ScriptEventMethod.cpp +++ b/Gems/ScriptEvents/Code/Source/ScriptEventsMethod.cpp @@ -6,7 +6,7 @@ * */ -#include "ScriptEvents/ScriptEventMethod.h" +#include "ScriptEvents/ScriptEventsMethod.h" #include #include diff --git a/Gems/ScriptEvents/Code/Tests/ScriptEventsTestFixture.h b/Gems/ScriptEvents/Code/Tests/ScriptEventsTestFixture.h index 78c7308dde..53d4fd58b9 100644 --- a/Gems/ScriptEvents/Code/Tests/ScriptEventsTestFixture.h +++ b/Gems/ScriptEvents/Code/Tests/ScriptEventsTestFixture.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include "ScriptEventTestUtilities.h" diff --git a/Gems/ScriptEvents/Code/scriptevents_common_files.cmake b/Gems/ScriptEvents/Code/scriptevents_common_files.cmake index 5938050f5d..a7ecd9e049 100644 --- a/Gems/ScriptEvents/Code/scriptevents_common_files.cmake +++ b/Gems/ScriptEvents/Code/scriptevents_common_files.cmake @@ -10,7 +10,7 @@ set(FILES Source/ScriptEventsSystemComponent.h Source/ScriptEventsSystemComponent.cpp Source/ScriptEventParameter.cpp - Source/ScriptEventMethod.cpp + Source/ScriptEventsMethod.cpp Source/ScriptEventsAssetRef.cpp Include/ScriptEvents/ScriptEventsGem.h Include/ScriptEvents/ScriptEventsAsset.h @@ -23,7 +23,7 @@ set(FILES Include/ScriptEvents/ScriptEventDefinition.h Include/ScriptEvents/ScriptEventDefinition.cpp Include/ScriptEvents/ScriptEvent.h - Include/ScriptEvents/ScriptEventMethod.h + Include/ScriptEvents/ScriptEventsMethod.h Include/ScriptEvents/ScriptEvent.cpp Include/ScriptEvents/ScriptEventParameter.h Include/ScriptEvents/ScriptEventSystem.h diff --git a/Gems/Vegetation/Code/Tests/DynamicSliceInstanceSpawnerTests.cpp b/Gems/Vegetation/Code/Tests/DynamicSliceInstanceSpawnerTests.cpp index 9838a7b6a1..26d8028522 100644 --- a/Gems/Vegetation/Code/Tests/DynamicSliceInstanceSpawnerTests.cpp +++ b/Gems/Vegetation/Code/Tests/DynamicSliceInstanceSpawnerTests.cpp @@ -50,80 +50,25 @@ namespace UnitTest } }; - // To test Dynamic Slice spawning, we need to mock up enough of the asset management system and the dynamic slice - // asset handling to pretend like we're loading/unloading dynamic slices successfully. - class DynamicSliceInstanceSpawnerTests - : public VegetationComponentTests - , public UnitTest::SetRestoreFileIOBaseRAII - , public Vegetation::DescriptorNotificationBus::Handler + class DynamicSliceAssetCatalogAndHandler + : public Vegetation::DescriptorNotificationBus::Handler , public AZ::Data::AssetCatalogRequestBus::Handler , public AZ::Data::AssetHandler , public AZ::Data::AssetCatalog , public AzFramework::SliceGameEntityOwnershipServiceRequestBus::Handler { public: - DynamicSliceInstanceSpawnerTests() - : UnitTest::SetRestoreFileIOBaseRAII(m_fileIOMock) + DynamicSliceAssetCatalogAndHandler() { - AZ::IO::MockFileIOBase::InstallDefaultReturns(m_fileIOMock); - } - - void RegisterComponentDescriptors() override - { - m_app.RegisterComponentDescriptor(MockDynamicSliceInstanceVegetationSystemComponent::CreateDescriptor()); - } - - void SetUp() override - { - VegetationComponentTests::SetUp(); - - // Create a real Asset Mananger, and point to ourselves as the handler for DynamicSliceAsset. - AZ::AllocatorInstance::Create(); - AZ::AllocatorInstance::Create(); - - - // Initialize the job manager with 1 thread for the AssetManager to use. - AZ::JobManagerDesc jobDesc; - AZ::JobManagerThreadDesc threadDesc; - jobDesc.m_workerThreads.push_back(threadDesc); - m_jobManager = aznew AZ::JobManager(jobDesc); - m_jobContext = aznew AZ::JobContext(*m_jobManager); - AZ::JobContext::SetGlobalContext(m_jobContext); - - AZ::Data::AssetManager::Descriptor descriptor; - AZ::Data::AssetManager::Create(descriptor); - AZ::Data::AssetManager::Instance().RegisterHandler(this, AZ::AzTypeInfo::Uuid()); - AZ::Data::AssetManager::Instance().RegisterCatalog(this, AZ::AzTypeInfo::Uuid()); - - m_app.RegisterComponentDescriptor(AZ::SliceComponent::CreateDescriptor()); - // Intercept messages for finding assets by name and creating/destroying slices. AZ::Data::AssetCatalogRequestBus::Handler::BusConnect(); AzFramework::SliceGameEntityOwnershipServiceRequestBus::Handler::BusConnect(); } - void TearDown() override + ~DynamicSliceAssetCatalogAndHandler() { - // Give the AssetManager a chance to fire off any lingering events and perform cleanup for any - // dynamic slice assets we loaded. - AZ::Data::AssetManager::Instance().DispatchEvents(); - AzFramework::SliceGameEntityOwnershipServiceRequestBus::Handler::BusDisconnect(); - AZ::Data::AssetManager::Instance().UnregisterCatalog(this); - AZ::Data::AssetManager::Instance().UnregisterHandler(this); - AZ::Data::AssetCatalogRequestBus::Handler::BusDisconnect(); - - AZ::Data::AssetManager::Destroy(); - - AZ::JobContext::SetGlobalContext(nullptr); - delete m_jobContext; - delete m_jobManager; - - AZ::AllocatorInstance::Destroy(); - AZ::AllocatorInstance::Destroy(); - - VegetationComponentTests::TearDown(); } // Helper methods: @@ -207,7 +152,7 @@ namespace UnitTest AZStd::string GetAssetPathById(const AZ::Data::AssetId& /*id*/) override { return m_assetPath; } AZ::Data::AssetId GetAssetIdByPath(const char* /*path*/, const AZ::Data::AssetType& /*typeToRegister*/, bool /*autoRegisterIfNotFound*/) override { return m_assetId; } AZ::Data::AssetInfo GetAssetInfoById(const AZ::Data::AssetId& /*id*/) override - { + { AZ::Data::AssetInfo assetInfo; assetInfo.m_assetId = m_assetId; assetInfo.m_assetType = AZ::AzTypeInfo::Uuid(); @@ -244,9 +189,77 @@ namespace UnitTest AZStd::string m_assetPath; AZ::Data::AssetId m_assetId; int m_numOnLoadedCalls = 0; + }; + // To test Dynamic Slice spawning, we need to mock up enough of the asset management system and the dynamic slice + // asset handling to pretend like we're loading/unloading dynamic slices successfully. + class DynamicSliceInstanceSpawnerTests + : public VegetationComponentTests + { + public: + DynamicSliceInstanceSpawnerTests() + : m_restoreFileIO(m_fileIOMock) + { + AZ::IO::MockFileIOBase::InstallDefaultReturns(m_fileIOMock); + } + void SetUp() override + { + VegetationComponentTests::SetUp(); + + // Create a real Asset Mananger, and point to ourselves as the handler for DynamicSliceAsset. + AZ::AllocatorInstance::Create(); + AZ::AllocatorInstance::Create(); + + // Initialize the job manager with 1 thread for the AssetManager to use. + AZ::JobManagerDesc jobDesc; + AZ::JobManagerThreadDesc threadDesc; + jobDesc.m_workerThreads.push_back(threadDesc); + m_jobManager = aznew AZ::JobManager(jobDesc); + m_jobContext = aznew AZ::JobContext(*m_jobManager); + AZ::JobContext::SetGlobalContext(m_jobContext); + + AZ::Data::AssetManager::Descriptor descriptor; + AZ::Data::AssetManager::Create(descriptor); + m_testHandler = AZStd::make_unique(); + AZ::Data::AssetManager::Instance().RegisterHandler(m_testHandler.get(), AZ::AzTypeInfo::Uuid()); + AZ::Data::AssetManager::Instance().RegisterCatalog(m_testHandler.get(), AZ::AzTypeInfo::Uuid()); + + m_app.RegisterComponentDescriptor(AZ::SliceComponent::CreateDescriptor()); + } + + void TearDown() override + { + // Clear out the list of queued AssetBus Events before unregistering the AssetHandler + // to make sure pending references to Asset instances are cleared + AZ::Data::AssetManager::Instance().DispatchEvents(); + AZ::Data::AssetManager::Instance().UnregisterHandler(m_testHandler.get()); + AZ::Data::AssetManager::Instance().UnregisterCatalog(m_testHandler.get()); + AZ::Data::AssetManager::Destroy(); + + m_testHandler.reset(); + + AZ::JobContext::SetGlobalContext(nullptr); + delete m_jobContext; + delete m_jobManager; + + AZ::AllocatorInstance::Destroy(); + AZ::AllocatorInstance::Destroy(); + + VegetationComponentTests::TearDown(); + } + + void RegisterComponentDescriptors() override + { + m_app.RegisterComponentDescriptor(MockDynamicSliceInstanceVegetationSystemComponent::CreateDescriptor()); + } + + protected: + AZStd::unique_ptr m_testHandler; + + private: AZ::JobManager* m_jobManager{ nullptr }; AZ::JobContext* m_jobContext{ nullptr }; + SetRestoreFileIOBaseRAII m_restoreFileIO; ::testing::NiceMock m_fileIOMock; }; @@ -276,7 +289,7 @@ namespace UnitTest Vegetation::DynamicSliceInstanceSpawner instanceSpawner2; // Give the second instance spawner a non-default asset reference. - CreateAndSetMockAsset(instanceSpawner2, AZ::Uuid::CreateRandom(), "test"); + m_testHandler->CreateAndSetMockAsset(instanceSpawner2, AZ::Uuid::CreateRandom(), "test"); // The test is written this way because only the == operator is overloaded. EXPECT_TRUE(!(instanceSpawner1 == instanceSpawner2)); @@ -292,14 +305,14 @@ namespace UnitTest EXPECT_TRUE(instanceSpawner.HasEmptyAssetReferences()); // This will test the asset load. - CreateAndSetMockAsset(instanceSpawner, AZ::Uuid::CreateRandom(), "test"); + m_testHandler->CreateAndSetMockAsset(instanceSpawner, AZ::Uuid::CreateRandom(), "test"); // Test the asset unload works too. - Vegetation::DescriptorNotificationBus::Handler::BusConnect(&instanceSpawner); + m_testHandler->Vegetation::DescriptorNotificationBus::Handler::BusConnect(&instanceSpawner); instanceSpawner.UnloadAssets(); EXPECT_FALSE(instanceSpawner.IsLoaded()); EXPECT_FALSE(instanceSpawner.IsSpawnable()); - Vegetation::DescriptorNotificationBus::Handler::BusDisconnect(); + m_testHandler->Vegetation::DescriptorNotificationBus::Handler::BusDisconnect(); } TEST_F(DynamicSliceInstanceSpawnerTests, CreateAndDestroyInstance) @@ -308,7 +321,7 @@ namespace UnitTest Vegetation::DynamicSliceInstanceSpawner instanceSpawner; - CreateAndSetMockAsset(instanceSpawner, AZ::Uuid::CreateRandom(), "test"); + m_testHandler->CreateAndSetMockAsset(instanceSpawner, AZ::Uuid::CreateRandom(), "test"); instanceSpawner.OnRegisterUniqueDescriptor(); diff --git a/Gems/Vegetation/Code/Tests/PrefabInstanceSpawnerTests.cpp b/Gems/Vegetation/Code/Tests/PrefabInstanceSpawnerTests.cpp index b0d88f2d63..3398dba20f 100644 --- a/Gems/Vegetation/Code/Tests/PrefabInstanceSpawnerTests.cpp +++ b/Gems/Vegetation/Code/Tests/PrefabInstanceSpawnerTests.cpp @@ -51,76 +51,21 @@ namespace UnitTest } }; - // To test prefab spawning, we need to mock up enough of the asset management system and the spawnable - // asset handling to pretend like we're loading/unloading spawnables successfully. - class PrefabInstanceSpawnerTests - : public VegetationComponentTests - , public UnitTest::SetRestoreFileIOBaseRAII - , public Vegetation::DescriptorNotificationBus::Handler + class PrefabInstanceHandlerAndCatalog + : public Vegetation::DescriptorNotificationBus::Handler , public AZ::Data::AssetCatalogRequestBus::Handler , public AZ::Data::AssetHandler , public AZ::Data::AssetCatalog { public: - PrefabInstanceSpawnerTests() - : UnitTest::SetRestoreFileIOBaseRAII(m_fileIOMock) + PrefabInstanceHandlerAndCatalog() { - AZ::IO::MockFileIOBase::InstallDefaultReturns(m_fileIOMock); - AzFramework::MockSpawnableEntitiesInterface::InstallDefaultReturns(m_spawnableEntitiesInterfaceMock); - } - - void RegisterComponentDescriptors() override - { - m_app.RegisterComponentDescriptor(MockPrefabInstanceVegetationSystemComponent::CreateDescriptor()); - } - - void SetUp() override - { - VegetationComponentTests::SetUp(); - - // Create a real Asset Mananger, and point to ourselves as the handler for Spawnable. - AZ::AllocatorInstance::Create(); - AZ::AllocatorInstance::Create(); - - - // Initialize the job manager with 1 thread for the AssetManager to use. - AZ::JobManagerDesc jobDesc; - AZ::JobManagerThreadDesc threadDesc; - jobDesc.m_workerThreads.push_back(threadDesc); - m_jobManager = aznew AZ::JobManager(jobDesc); - m_jobContext = aznew AZ::JobContext(*m_jobManager); - AZ::JobContext::SetGlobalContext(m_jobContext); - - AZ::Data::AssetManager::Descriptor descriptor; - AZ::Data::AssetManager::Create(descriptor); - AZ::Data::AssetManager::Instance().RegisterHandler(this, AZ::AzTypeInfo::Uuid()); - AZ::Data::AssetManager::Instance().RegisterCatalog(this, AZ::AzTypeInfo::Uuid()); - - // Intercept messages for finding assets by name. AZ::Data::AssetCatalogRequestBus::Handler::BusConnect(); } - void TearDown() override + ~PrefabInstanceHandlerAndCatalog() { - // Give the AssetManager a chance to fire off any lingering events and perform cleanup for any - // spawnable assets we loaded. - AZ::Data::AssetManager::Instance().DispatchEvents(); - - AZ::Data::AssetManager::Instance().UnregisterCatalog(this); - AZ::Data::AssetManager::Instance().UnregisterHandler(this); - AZ::Data::AssetCatalogRequestBus::Handler::BusDisconnect(); - - AZ::Data::AssetManager::Destroy(); - - AZ::JobContext::SetGlobalContext(nullptr); - delete m_jobContext; - delete m_jobManager; - - AZ::AllocatorInstance::Destroy(); - AZ::AllocatorInstance::Destroy(); - - VegetationComponentTests::TearDown(); } // Helper methods: @@ -227,9 +172,79 @@ namespace UnitTest AZStd::string m_assetPath; AZ::Data::AssetId m_assetId; int m_numOnLoadedCalls = 0; + }; + // To test Dynamic Slice spawning, we need to mock up enough of the asset management system and the dynamic slice + // asset handling to pretend like we're loading/unloading dynamic slices successfully. + class PrefabInstanceSpawnerTests + : public VegetationComponentTests + { + public: + PrefabInstanceSpawnerTests() + : m_restoreFileIO(m_fileIOMock) + { + AZ::IO::MockFileIOBase::InstallDefaultReturns(m_fileIOMock); + AzFramework::MockSpawnableEntitiesInterface::InstallDefaultReturns(m_spawnableEntitiesInterfaceMock); + } + + void SetUp() override + { + VegetationComponentTests::SetUp(); + + // Create a real Asset Mananger, and point to ourselves as the handler for DynamicSliceAsset. + AZ::AllocatorInstance::Create(); + AZ::AllocatorInstance::Create(); + + // Initialize the job manager with 1 thread for the AssetManager to use. + AZ::JobManagerDesc jobDesc; + AZ::JobManagerThreadDesc threadDesc; + jobDesc.m_workerThreads.push_back(threadDesc); + m_jobManager = aznew AZ::JobManager(jobDesc); + m_jobContext = aznew AZ::JobContext(*m_jobManager); + AZ::JobContext::SetGlobalContext(m_jobContext); + + AZ::Data::AssetManager::Descriptor descriptor; + AZ::Data::AssetManager::Create(descriptor); + m_testHandler = AZStd::make_unique(); + AZ::Data::AssetManager::Instance().RegisterHandler(m_testHandler.get(), AZ::AzTypeInfo::Uuid()); + AZ::Data::AssetManager::Instance().RegisterCatalog(m_testHandler.get(), AZ::AzTypeInfo::Uuid()); + + m_app.RegisterComponentDescriptor(AZ::SliceComponent::CreateDescriptor()); + } + + void TearDown() override + { + // Clear out the list of queued AssetBus Events before unregistering the AssetHandler + // to make sure pending references to Asset instances are cleared + AZ::Data::AssetManager::Instance().DispatchEvents(); + AZ::Data::AssetManager::Instance().UnregisterHandler(m_testHandler.get()); + AZ::Data::AssetManager::Instance().UnregisterCatalog(m_testHandler.get()); + AZ::Data::AssetManager::Destroy(); + + m_testHandler.reset(); + + AZ::JobContext::SetGlobalContext(nullptr); + delete m_jobContext; + delete m_jobManager; + + AZ::AllocatorInstance::Destroy(); + AZ::AllocatorInstance::Destroy(); + + VegetationComponentTests::TearDown(); + } + + void RegisterComponentDescriptors() override + { + m_app.RegisterComponentDescriptor(MockPrefabInstanceVegetationSystemComponent::CreateDescriptor()); + } + + protected: + AZStd::unique_ptr m_testHandler; + + private: AZ::JobManager* m_jobManager{ nullptr }; AZ::JobContext* m_jobContext{ nullptr }; + SetRestoreFileIOBaseRAII m_restoreFileIO; ::testing::NiceMock m_fileIOMock; ::testing::NiceMock m_spawnableEntitiesInterfaceMock; }; @@ -259,7 +274,7 @@ namespace UnitTest Vegetation::PrefabInstanceSpawner instanceSpawner2; // Give the second instance spawner a non-default asset reference. - CreateAndSetMockAsset(instanceSpawner2, AZ::Uuid::CreateRandom(), "test"); + m_testHandler->CreateAndSetMockAsset(instanceSpawner2, AZ::Uuid::CreateRandom(), "test"); // The test is written this way because only the == operator is overloaded. EXPECT_TRUE(!(instanceSpawner1 == instanceSpawner2)); @@ -275,14 +290,14 @@ namespace UnitTest EXPECT_TRUE(instanceSpawner.HasEmptyAssetReferences()); // This will test the asset load. - CreateAndSetMockAsset(instanceSpawner, AZ::Uuid::CreateRandom(), "test"); + m_testHandler->CreateAndSetMockAsset(instanceSpawner, AZ::Uuid::CreateRandom(), "test"); // Test the asset unload works too. - Vegetation::DescriptorNotificationBus::Handler::BusConnect(&instanceSpawner); + m_testHandler->Vegetation::DescriptorNotificationBus::Handler::BusConnect(&instanceSpawner); instanceSpawner.UnloadAssets(); EXPECT_FALSE(instanceSpawner.IsLoaded()); EXPECT_FALSE(instanceSpawner.IsSpawnable()); - Vegetation::DescriptorNotificationBus::Handler::BusDisconnect(); + m_testHandler->Vegetation::DescriptorNotificationBus::Handler::BusDisconnect(); } TEST_F(PrefabInstanceSpawnerTests, CreateAndDestroyInstance) @@ -291,7 +306,7 @@ namespace UnitTest Vegetation::PrefabInstanceSpawner instanceSpawner; - CreateAndSetMockAsset(instanceSpawner, AZ::Uuid::CreateRandom(), "test"); + m_testHandler->CreateAndSetMockAsset(instanceSpawner, AZ::Uuid::CreateRandom(), "test"); instanceSpawner.OnRegisterUniqueDescriptor(); diff --git a/Gems/Vegetation/Code/Tests/VegetationTest.h b/Gems/Vegetation/Code/Tests/VegetationTest.h index cf7c9b70a1..2ae8ac9cca 100644 --- a/Gems/Vegetation/Code/Tests/VegetationTest.h +++ b/Gems/Vegetation/Code/Tests/VegetationTest.h @@ -21,21 +21,34 @@ namespace UnitTest { class VegetationComponentTests - : public ::testing::Test + : public ScopedAllocatorSetupFixture { protected: + VegetationComponentTests() + : ScopedAllocatorSetupFixture( + []() { + AZ::SystemAllocator::Descriptor desc; + desc.m_heap.m_fixedMemoryBlocksByteSize[0] = 20 * 1024 * 1024; + desc.m_stackRecordLevels = 20; + return desc; + }() + ) + { + } + AZ::ComponentApplication m_app; virtual void RegisterComponentDescriptors() {} void SetUp() override { - AZ::ComponentApplication::Descriptor appDesc; - appDesc.m_memoryBlocksByteSize = 20 * 1024 * 1024; - appDesc.m_recordingMode = AZ::Debug::AllocationRecords::RECORD_NO_RECORDS; - appDesc.m_stackRecordLevels = 20; + if (AZ::Debug::AllocationRecords* records = AZ::AllocatorInstance::GetAllocator().GetRecords(); + records != nullptr) + { + records->SetMode(AZ::Debug::AllocationRecords::RECORD_NO_RECORDS); + } - m_app.Create(appDesc); + m_app.Create({}); RegisterComponentDescriptors(); } diff --git a/Gems/WhiteBox/Code/Source/Rendering/Atom/TangentSpaceHelper.cpp b/Gems/WhiteBox/Code/Source/Rendering/Atom/TangentSpaceHelper.cpp index a43b48d3b9..913778cc44 100644 --- a/Gems/WhiteBox/Code/Source/Rendering/Atom/TangentSpaceHelper.cpp +++ b/Gems/WhiteBox/Code/Source/Rendering/Atom/TangentSpaceHelper.cpp @@ -73,7 +73,9 @@ namespace WhiteBox for (AZ::u32 i = 0; i < triangleCount; ++i) { +#if defined(AZ_ENABLE_TRACING) const auto& trianglePositions = trianglesPositions[i]; +#endif const auto& triangleUVs = trianglesUVs[i]; const auto& triangleEdges = trianglesEdges[i]; diff --git a/Registry/CMakeLists.txt b/Registry/CMakeLists.txt index 100867010d..773adac07f 100644 --- a/Registry/CMakeLists.txt +++ b/Registry/CMakeLists.txt @@ -12,8 +12,6 @@ endif() ly_install_directory(DIRECTORIES .) -cmake_path(RELATIVE_PATH CMAKE_RUNTIME_OUTPUT_DIRECTORY BASE_DIRECTORY ${CMAKE_BINARY_DIR} OUTPUT_VARIABLE runtime_output_directory) - ly_install_directory(DIRECTORIES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$/Registry - DESTINATION ${runtime_output_directory}/${PAL_PLATFORM_NAME}/$ + DESTINATION ${runtime_output_directory} ) diff --git a/Tools/7za.exe b/Tools/7za.exe deleted file mode 100644 index 8a7a9ab6fb..0000000000 --- a/Tools/7za.exe +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:77613cca716edf68b9d5bab951463ed7fade5bc0ec465b36190a76299c50f117 -size 733696 diff --git a/Tools/7za_legal_notice.txt b/Tools/7za_legal_notice.txt deleted file mode 100644 index 6bcdfb1e31..0000000000 --- a/Tools/7za_legal_notice.txt +++ /dev/null @@ -1,36 +0,0 @@ -Amazon note: Source for 7-zip is hosted at -https://s3-us-west-2.amazonaws.com/ly-legal/LicenseConformance/7-zip/18.05/7z1805-src.7z - - - - 7-Zip Extra - ~~~~~~~~~~~ - License for use and distribution - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - Copyright (C) 1999-2015 Igor Pavlov. - - 7-Zip Extra files are under the GNU LGPL license. - - - Notes: - You can use 7-Zip Extra on any computer, including a computer in a commercial - organization. You don't need to register or pay for 7-Zip. - - - GNU LGPL information - -------------------- - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You can receive a copy of the GNU Lesser General Public License from - http://www.gnu.org/ - diff --git a/cmake/Packaging.cmake b/cmake/Packaging.cmake index 477a5f24ea..006689549b 100644 --- a/cmake/Packaging.cmake +++ b/cmake/Packaging.cmake @@ -89,37 +89,49 @@ endif() set(_cmake_package_dest ${CPACK_BINARY_DIR}/${CPACK_CMAKE_PACKAGE_FILE}) -string(REPLACE "." ";" _version_componets "${CPACK_DESIRED_CMAKE_VERSION}") -list(GET _version_componets 0 _major_version) -list(GET _version_componets 1 _minor_version) - -set(_url_version_tag "v${_major_version}.${_minor_version}") -set(_package_url "https://cmake.org/files/${_url_version_tag}/${CPACK_CMAKE_PACKAGE_FILE}") - -message(STATUS "Downloading CMake ${CPACK_DESIRED_CMAKE_VERSION} for packaging...") -download_file( - URL ${_package_url} - TARGET_FILE ${_cmake_package_dest} - EXPECTED_HASH ${CPACK_CMAKE_PACKAGE_HASH} - RESULTS _results -) -list(GET _results 0 _status_code) - -if (${_status_code} EQUAL 0 AND EXISTS ${_cmake_package_dest}) - message(STATUS "Package found and verified!") -else() - file(REMOVE ${_cmake_package_dest}) - list(REMOVE_AT _results 0) - - set(_error_message "An error occurred, code ${_status_code}. URL ${_package_url} - ${_results}") - - if(${_status_code} EQUAL 1) - string(APPEND _error_message - " Please double check the CPACK_CMAKE_PACKAGE_FILE and " - "CPACK_CMAKE_PACKAGE_HASH properties before trying again.") +if(EXISTS ${_cmake_package_dest}) + file(SHA256 ${_cmake_package_dest} hash_of_downloaded_file) + if (NOT "${hash_of_downloaded_file}" STREQUAL "${CPACK_CMAKE_PACKAGE_HASH}") + message(STATUS "CMake ${CPACK_DESIRED_CMAKE_VERSION} found at ${_cmake_package_dest} but expected hash missmatches, re-downloading...") + file(REMOVE ${_cmake_package_dest}) + else() + message(STATUS "CMake ${CPACK_DESIRED_CMAKE_VERSION} found") endif() +endif() +if(NOT EXISTS ${_cmake_package_dest}) + # download it + string(REPLACE "." ";" _version_componets "${CPACK_DESIRED_CMAKE_VERSION}") + list(GET _version_componets 0 _major_version) + list(GET _version_componets 1 _minor_version) - message(FATAL_ERROR ${_error_message}) + set(_url_version_tag "v${_major_version}.${_minor_version}") + set(_package_url "https://cmake.org/files/${_url_version_tag}/${CPACK_CMAKE_PACKAGE_FILE}") + + message(STATUS "Downloading CMake ${CPACK_DESIRED_CMAKE_VERSION} for packaging...") + download_file( + URL ${_package_url} + TARGET_FILE ${_cmake_package_dest} + EXPECTED_HASH ${CPACK_CMAKE_PACKAGE_HASH} + RESULTS _results + ) + list(GET _results 0 _status_code) + + if (${_status_code} EQUAL 0 AND EXISTS ${_cmake_package_dest}) + message(STATUS "CMake ${CPACK_DESIRED_CMAKE_VERSION} found") + else() + file(REMOVE ${_cmake_package_dest}) + list(REMOVE_AT _results 0) + + set(_error_message "An error occurred, code ${_status_code}. URL ${_package_url} - ${_results}") + + if(${_status_code} EQUAL 1) + string(APPEND _error_message + " Please double check the CPACK_CMAKE_PACKAGE_FILE and " + "CPACK_CMAKE_PACKAGE_HASH properties before trying again.") + endif() + + message(FATAL_ERROR ${_error_message}) + endif() endif() install(FILES ${_cmake_package_dest} diff --git a/cmake/Platform/Common/Install_common.cmake b/cmake/Platform/Common/Install_common.cmake index 8fb2effe29..5fa7f21939 100644 --- a/cmake/Platform/Common/Install_common.cmake +++ b/cmake/Platform/Common/Install_common.cmake @@ -430,6 +430,21 @@ function(ly_setup_cmake_install) DESTINATION . COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME} ) + string(CONFIGURE [=[ +if("${CMAKE_INSTALL_CONFIG_NAME}" MATCHES "^([Rr][Ee][Ll][Ee][Aa][Ss][Ee])$") + set(install_output_folder "${CMAKE_INSTALL_PREFIX}/@runtime_output_directory@") + file(WRITE ${install_output_folder}/engine.json +"{ + \"engine_name\": \"@LY_VERSION_ENGINE_NAME@\" +}") +endif() +]=] + install_engine_json_release + @ONLY + ) + install(CODE ${install_engine_json_release} + COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME} # use the default for the time being + ) # Collect all Find files that were added with ly_add_external_target_path unset(additional_find_files) diff --git a/cmake/Platform/Windows/PackagingPostBuild.cmake b/cmake/Platform/Windows/PackagingPostBuild.cmake index 5e09743373..377a9fb221 100644 --- a/cmake/Platform/Windows/PackagingPostBuild.cmake +++ b/cmake/Platform/Windows/PackagingPostBuild.cmake @@ -32,6 +32,9 @@ set(_addtional_defines -dCPACK_RESOURCE_PATH=${CPACK_SOURCE_DIR}/Platform/Windows/Packaging ) +file(REAL_PATH "${CPACK_SOURCE_DIR}/.." _root_path) +file(TO_NATIVE_PATH "${_root_path}/scripts/signer/Platform/Windows/signer.ps1" _sign_script) + if(CPACK_LICENSE_URL) list(APPEND _addtional_defines -dCPACK_LICENSE_URL=${CPACK_LICENSE_URL}) endif() @@ -55,6 +58,30 @@ set(_light_command -o "${_bootstrap_output_file}" ) +set(_signing_command + psexec.exe + -accepteula + -nobanner + -s + powershell.exe + -NoLogo + -ExecutionPolicy Bypass + -File ${_sign_script} +) + +message(STATUS "Signing package files in ${_cpack_wix_out_dir}") +execute_process( + COMMAND ${_signing_command} -packagePath ${_cpack_wix_out_dir} + RESULT_VARIABLE _signing_result + ERROR_VARIABLE _signing_errors + OUTPUT_VARIABLE _signing_output + ECHO_OUTPUT_VARIABLE +) + +if(NOT ${_signing_result} EQUAL 0) + message(FATAL_ERROR "An error occurred during signing package files. ${_signing_errors}") +endif() + message(STATUS "Creating Bootstrap Installer...") execute_process( COMMAND ${_candle_command} @@ -80,6 +107,19 @@ file(COPY ${_bootstrap_output_file} message(STATUS "Bootstrap installer generated to ${CPACK_PACKAGE_DIRECTORY}/${_bootstrap_filename}") +message(STATUS "Signing bootstrap installer in ${CPACK_PACKAGE_DIRECTORY}") +execute_process( + COMMAND ${_signing_command} -bootstrapPath ${CPACK_PACKAGE_DIRECTORY}/${_bootstrap_filename} + RESULT_VARIABLE _signing_result + ERROR_VARIABLE _signing_errors + OUTPUT_VARIABLE _signing_output + ECHO_OUTPUT_VARIABLE +) + +if(NOT ${_signing_result} EQUAL 0) + message(FATAL_ERROR "An error occurred during signing bootstrap installer. ${_signing_errors}") +endif() + # use the internal default path if somehow not specified from cpack_configure_downloads if(NOT CPACK_UPLOAD_DIRECTORY) set(CPACK_UPLOAD_DIRECTORY ${CPACK_PACKAGE_DIRECTORY}/CPackUploads) @@ -100,11 +140,9 @@ if(NOT CPACK_UPLOAD_URL) return() endif() -file(REAL_PATH "${CPACK_SOURCE_DIR}/.." _root_path) - +file(TO_NATIVE_PATH "${_cpack_wix_out_dir}" _cpack_wix_out_dir) file(TO_NATIVE_PATH "${_root_path}/python/python.cmd" _python_cmd) file(TO_NATIVE_PATH "${_root_path}/scripts/build/tools/upload_to_s3.py" _upload_script) -file(TO_NATIVE_PATH "${_cpack_wix_out_dir}" _cpack_wix_out_dir) function(upload_to_s3 in_url in_local_path in_file_regex) diff --git a/cmake/Platform/Windows/PackagingPreBuild.cmake b/cmake/Platform/Windows/PackagingPreBuild.cmake new file mode 100644 index 0000000000..d3924c7a02 --- /dev/null +++ b/cmake/Platform/Windows/PackagingPreBuild.cmake @@ -0,0 +1,37 @@ +# +# Copyright (c) Contributors to the Open 3D Engine Project. +# For complete copyright and license terms please see the LICENSE at the root of this distribution. +# +# SPDX-License-Identifier: Apache-2.0 OR MIT +# +# + +file(REAL_PATH "${CPACK_SOURCE_DIR}/.." _root_path) +set(_cpack_wix_out_dir ${CPACK_TOPLEVEL_DIRECTORY}) +file(TO_NATIVE_PATH "${_root_path}/scripts/signer/Platform/Windows/signer.ps1" _sign_script) + +set(_signing_command + psexec.exe + -accepteula + -nobanner + -s + powershell.exe + -NoLogo + -ExecutionPolicy Bypass + -File ${_sign_script} +) + +message(STATUS "Signing executable files in ${_cpack_wix_out_dir}") +execute_process( + COMMAND ${_signing_command} -exePath ${_cpack_wix_out_dir} + RESULT_VARIABLE _signing_result + ERROR_VARIABLE _signing_errors + OUTPUT_VARIABLE _signing_output + ECHO_OUTPUT_VARIABLE +) + +if(NOT ${_signing_result} EQUAL 0) + message(FATAL_ERROR "An error occurred during signing executable files. ${_signing_errors}") +endif() + +message(STATUS "Signing exes complete!") diff --git a/cmake/Platform/Windows/Packaging_windows.cmake b/cmake/Platform/Windows/Packaging_windows.cmake index 5bb9928b61..4a03df2fd2 100644 --- a/cmake/Platform/Windows/Packaging_windows.cmake +++ b/cmake/Platform/Windows/Packaging_windows.cmake @@ -23,6 +23,7 @@ set(CPACK_WIX_ROOT ${LY_INSTALLER_WIX_ROOT}) set(CPACK_GENERATOR WIX) +set(CPACK_THREADS 0) set(_cmake_package_name "cmake-${CPACK_DESIRED_CMAKE_VERSION}-windows-x86_64") set(CPACK_CMAKE_PACKAGE_FILE "${_cmake_package_name}.zip") set(CPACK_CMAKE_PACKAGE_HASH "15a49e2ab81c1822d75b1b1a92f7863f58e31f6d6aac1c4103eef2b071be3112") @@ -108,7 +109,6 @@ set(_raw_text_license [[ ]]) if(LY_INSTALLER_DOWNLOAD_URL) - set(WIX_THEME_WARNING_IMAGE ${CPACK_SOURCE_DIR}/Platform/Windows/Packaging/warning.png) if(LY_INSTALLER_LICENSE_URL) @@ -138,6 +138,10 @@ if(LY_INSTALLER_DOWNLOAD_URL) # the bootstrapper will at the very least need a different upgrade guid generate_wix_guid(CPACK_WIX_BOOTSTRAP_UPGRADE_GUID "${_guid_seed_base}_Bootstrap_UpgradeCode") + set(CPACK_PRE_BUILD_SCRIPTS + ${CPACK_SOURCE_DIR}/Platform/Windows/PackagingPreBuild.cmake + ) + set(CPACK_POST_BUILD_SCRIPTS ${CPACK_SOURCE_DIR}/Platform/Windows/PackagingPostBuild.cmake ) diff --git a/cmake/Projects.cmake b/cmake/Projects.cmake index 61cb101909..6109229e72 100644 --- a/cmake/Projects.cmake +++ b/cmake/Projects.cmake @@ -10,6 +10,10 @@ include_guard() +# Passing ${LY_PROJECTS} as the default since in project-centric LY_PROJECTS is defined by the project and +# we want to pick up that one as the value of the variable. +# Ideally this cache variable would be defined before the project sets LY_PROJECTS, but that would mean +# it would have to be defined in each project. set(LY_PROJECTS "${LY_PROJECTS}" CACHE STRING "List of projects to enable, this can be a relative path to the engine root or an absolute path") #! ly_add_target_dependencies: adds module load dependencies for this target. @@ -143,21 +147,25 @@ foreach(project ${LY_PROJECTS}) ly_generate_project_build_path_setreg(${full_directory_path}) add_project_json_external_subdirectories(${full_directory_path}) + # Get project name + o3de_read_json_key(project_name ${full_directory_path}/project.json "project_name") + # Generate pak for project in release installs - cmake_path(RELATIVE_PATH CMAKE_RUNTIME_OUTPUT_DIRECTORY BASE_DIRECTORY ${CMAKE_BINARY_DIR} OUTPUT_VARIABLE runtime_output_directory) + cmake_path(RELATIVE_PATH CMAKE_RUNTIME_OUTPUT_DIRECTORY BASE_DIRECTORY ${CMAKE_BINARY_DIR} OUTPUT_VARIABLE install_base_runtime_output_directory) set(install_engine_pak_template [=[ if("${CMAKE_INSTALL_CONFIG_NAME}" MATCHES "^([Rr][Ee][Ll][Ee][Aa][Ss][Ee])$") - set(install_output_folder "${CMAKE_INSTALL_PREFIX}/@runtime_output_directory@/@PAL_PLATFORM_NAME@/${CMAKE_INSTALL_CONFIG_NAME}/@LY_BUILD_PERMUTATION@") + set(install_output_folder "${CMAKE_INSTALL_PREFIX}/@install_base_runtime_output_directory@/@PAL_PLATFORM_NAME@/${CMAKE_INSTALL_CONFIG_NAME}/@LY_BUILD_PERMUTATION@") + set(install_pak_output_folder "${install_output_folder}/Cache/@LY_ASSET_DEPLOY_ASSET_TYPE@") if(NOT DEFINED LY_ASSET_DEPLOY_ASSET_TYPE) set(LY_ASSET_DEPLOY_ASSET_TYPE @LY_ASSET_DEPLOY_ASSET_TYPE@) endif() - message(STATUS "Generating ${install_output_folder}/engine.pak from @full_directory_path@/Cache/${LY_ASSET_DEPLOY_ASSET_TYPE}") - file(MAKE_DIRECTORY "${install_output_folder}") + message(STATUS "Generating ${install_pak_output_folder}/engine.pak from @full_directory_path@/Cache/${LY_ASSET_DEPLOY_ASSET_TYPE}") + file(MAKE_DIRECTORY "${install_pak_output_folder}") cmake_path(SET cache_product_path "@full_directory_path@/Cache/${LY_ASSET_DEPLOY_ASSET_TYPE}") file(GLOB product_assets "${cache_product_path}/*") if(product_assets) execute_process( - COMMAND ${CMAKE_COMMAND} -E tar "cf" "${install_output_folder}/engine.pak" --format=zip -- ${product_assets} + COMMAND ${CMAKE_COMMAND} -E tar "cf" "${install_pak_output_folder}/engine.pak" --format=zip -- ${product_assets} WORKING_DIRECTORY "${cache_product_path}" RESULT_VARIABLE archive_creation_result ) @@ -165,6 +173,10 @@ if("${CMAKE_INSTALL_CONFIG_NAME}" MATCHES "^([Rr][Ee][Ll][Ee][Aa][Ss][Ee])$") message(STATUS "${install_output_folder}/engine.pak generated") endif() endif() + file(WRITE ${install_output_folder}/project.json +"{ + \"project_name\": \"@project_name@\" +}") endif() ]=]) string(CONFIGURE "${install_engine_pak_template}" install_engine_pak_code @ONLY) diff --git a/cmake/Tools/Platform/Android/android_support.py b/cmake/Tools/Platform/Android/android_support.py index 77c8a37a35..54f1a4c8f4 100755 --- a/cmake/Tools/Platform/Android/android_support.py +++ b/cmake/Tools/Platform/Android/android_support.py @@ -381,6 +381,23 @@ CUSTOM_GRADLE_COPY_NATIVE_CONFIG_BUILD_ARTIFACTS_DEPENDENCY_FORMAT_STR = """ }} """ +CUSTOM_GRADLE_COPY_REGISTRY_FOLDER_FORMAT_STR = """ + task copyRegistryFolder{config}(type: Copy) {{ + from ('build/intermediates/cmake/{config_lower}/obj/arm64-v8a/{config_lower}/Registry') + into ('{asset_layout_folder}/registry') + include ('*.setreg') + }} + + compile{config}Sources.dependsOn copyRegistryFolder{config} +""" + +CUSTOM_GRADLE_COPY_REGISTRY_FOLDER_DEPENDENCY_FORMAT_STR = """ + + copyRegistryFolder{config}.mustRunAfter {{ + tasks.findAll {{ task->task.name.contains('syncLYLayoutMode{config}') }} + }} +""" + CUSTOM_APPLY_ASSET_LAYOUT_TASK_FORMAT_STR = """ task syncLYLayoutMode{config}(type:Exec) {{ workingDir '{working_dir}' @@ -851,14 +868,13 @@ class AndroidProjectGenerator(object): config=native_config) # Copy over settings registry files from the Registry folder with build output directory gradle_build_env[f'CUSTOM_APPLY_ASSET_LAYOUT_{native_config_upper}_TASK'] += \ - CUSTOM_GRADLE_COPY_NATIVE_CONFIG_BUILD_ARTIFACTS_FORMAT_STR.format(config=native_config, - config_lower=native_config_lower, - asset_layout_folder=(self.build_dir / 'app/src/main/assets').resolve().as_posix(), - file_includes='**/Registry/*.setreg') + CUSTOM_GRADLE_COPY_REGISTRY_FOLDER_FORMAT_STR.format(config=native_config, + config_lower=native_config_lower, + asset_layout_folder=(self.build_dir / 'app/src/main/assets').resolve().as_posix()) if self.include_assets_in_apk: # This is a dependency of the layout sync only if we are including assets in the APK gradle_build_env[f'CUSTOM_APPLY_ASSET_LAYOUT_{native_config_upper}_TASK'] += \ - CUSTOM_GRADLE_COPY_NATIVE_CONFIG_BUILD_ARTIFACTS_DEPENDENCY_FORMAT_STR.format(config=native_config) + CUSTOM_GRADLE_COPY_REGISTRY_FOLDER_DEPENDENCY_FORMAT_STR.format(config=native_config) diff --git a/scripts/build/Platform/Windows/build_config.json b/scripts/build/Platform/Windows/build_config.json index 3848e6f980..c607c3d821 100644 --- a/scripts/build/Platform/Windows/build_config.json +++ b/scripts/build/Platform/Windows/build_config.json @@ -306,6 +306,7 @@ }, "release_vs2019": { "TAGS": [ + "default", "nightly-incremental", "nightly-clean", "weekly-build-metrics" @@ -351,17 +352,21 @@ "CMAKE_NATIVE_BUILD_ARGS": "/m /nologo" } }, - "windows_installer": { + "installer_vs2019": { "TAGS": [ - "nightly-clean" + "nightly-clean", + "nightly-installer" ], + "PIPELINE_ENV":{ + "NODE_LABEL":"windows-packaging" + }, "COMMAND": "build_installer_windows.cmd", "PARAMETERS": { "CONFIGURATION": "profile", "OUTPUT_DIRECTORY": "build\\windows_vs2019", "CMAKE_OPTIONS": "-G \"Visual Studio 16 2019\" -DCMAKE_SYSTEM_VERSION=10.0 -DLY_UNITY_BUILD=TRUE -DLY_DISABLE_TEST_MODULES=TRUE -DLY_VERSION_ENGINE_NAME=o3de-sdk -DLY_INSTALLER_WIX_ROOT=\"!WIX! \"", - "EXTRA_CMAKE_OPTIONS": "-DLY_INSTALLER_AUTO_GEN_TAG=ON -DLY_INSTALLER_DOWNLOAD_URL=https://www.o3debinaries.org -DLY_INSTALLER_LICENSE_URL=https://www.o3debinaries.org/license", - "CPACK_BUCKET": "spectra-prism-staging-us-west-2", + "EXTRA_CMAKE_OPTIONS": "-DLY_INSTALLER_AUTO_GEN_TAG=ON -DLY_INSTALLER_DOWNLOAD_URL=!INSTALLER_DOWNLOAD_URL! -DLY_INSTALLER_LICENSE_URL=!INSTALLER_DOWNLOAD_URL!/license", + "CPACK_BUCKET": "!INSTALLER_BUCKET!", "CMAKE_LY_PROJECTS": "", "CMAKE_TARGET": "ALL_BUILD", "CMAKE_NATIVE_BUILD_ARGS": "/m /nologo" diff --git a/scripts/signer/Platform/Windows/signer.ps1 b/scripts/signer/Platform/Windows/signer.ps1 new file mode 100644 index 0000000000..5366564140 --- /dev/null +++ b/scripts/signer/Platform/Windows/signer.ps1 @@ -0,0 +1,99 @@ +# +# Copyright (c) Contributors to the Open 3D Engine Project. +# For complete copyright and license terms please see the LICENSE at the root of this distribution. +# +# SPDX-License-Identifier: Apache-2.0 OR MIT +# +# + +param ( + [String[]] $exePath, + [String[]] $packagePath, + [String[]] $bootstrapPath, + [String[]] $certificate +) + +# Get prerequisites, certs, and paths ready +$tempPath = [System.IO.Path]::GetTempPath() # Order of operations defined here: https://docs.microsoft.com/en-us/dotnet/api/system.io.path.gettemppath?view=net-5.0&tabs=windows#remarks +$certThumbprint = Get-ChildItem -Path Cert:LocalMachine\MY -CodeSigningCert -ErrorAction Stop | Select-Object -ExpandProperty Thumbprint # Grab first certificate from local machine store + +if ($certificate) { + Write-Output "Checking certificate thumbprint $certificate" + Get-ChildItem -Path Cert:LocalMachine\MY -ErrorAction SilentlyContinue | Where-Object {$_.Thumbprint -eq $certificate} # Prints certificate Thumbprint and Subject if found + if($?) { + $certThumbprint = $certificate + } + else { + Write-Error "$certificate thumbprint not found, using $certThumbprint thumbprint instead" + } +} + +Try { + $signtoolPath = Resolve-Path "C:\Program Files*\Windows Kits\10\bin\*\x64\signtool.exe" -ErrorAction Stop | Select-Object -Last 1 -ExpandProperty Path + $insigniaPath = Resolve-Path "C:\Program Files*\WiX*\bin\insignia.exe" -ErrorAction Stop | Select-Object -Last 1 -ExpandProperty Path +} +Catch { + Write-Error "Signtool or Wix insignia not found! Exiting." +} + +function Write-Signature { + param ( + $signtool, + $thumbprint, + $filename + ) + + $attempts = 2 + $sleepSec = 5 + + Do { + $attempts-- + Try { + & $signtool sign /tr http://timestamp.digicert.com /td sha256 /fd sha256 /sha1 $thumbprint /sm $filename + & $signtool verify /pa /v $filename + return + } + Catch { + Write-Error $_.Exception.InnerException.Message -ErrorAction Continue + Start-Sleep -Seconds $sleepSec + } + } while ($attempts -lt 0) + + throw "Failed to sign $filename" # Bypassed in try block if the command is successful +} + +# Looping through each path insteaad of globbing to prevent hitting maximum command string length limit +if ($exePath) { + Write-Output "### Signing EXE files ###" + $files = @(Get-ChildItem $exePath -Recurse *.exe | % { $_.FullName }) + foreach ($file in $files) { + Write-Signature -signtool $signtoolPath -thumbprint $certThumbprint -filename $file + } +} + +if ($packagePath) { + Write-Output "### Signing CAB files ###" + $files = @(Get-ChildItem $packagePath -Recurse *.cab | % { $_.FullName }) + foreach ($file in $files) { + Write-Signature -signtool $signtoolPath -thumbprint $certThumbprint -filename $file + } + + Write-Output "### Signing MSI files ###" + $files = @(Get-ChildItem $packagePath -Recurse *.msi | % { $_.FullName }) + foreach ($file in $files) { + & $insigniaPath -im $files + Write-Signature -signtool $signtoolPath -thumbprint $certThumbprint -filename $file + } +} + +if ($bootstrapPath) { + Write-Output "### Signing bootstrapper EXE ###" + $files = @(Get-ChildItem $bootstrapPath -Recurse *.exe | % { $_.FullName }) + foreach ($file in $files) { + & $insigniaPath -ib $file -o $tempPath\engine.exe + Write-Signature -signtool $signtoolPath -thumbprint $certThumbprint -filename $tempPath\engine.exe + & $insigniaPath -ab $tempPath\engine.exe $file -o $file + Write-Signature -signtool $signtoolPath -thumbprint $certThumbprint -filename $file + Remove-Item -Force $tempPath\engine.exe + } +} \ No newline at end of file