This reverts commit 321e497048.
This commit is contained in:
@@ -1,214 +1,212 @@
|
||||
/*
|
||||
***********************************************************************************************************************
|
||||
*
|
||||
* Copyright (c) 2023-2025 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
**********************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "palGpaSession.h"
|
||||
#include "palGpuUtil.h"
|
||||
#include "palTraceSession.h"
|
||||
#include "palVector.h"
|
||||
#include "palHashSet.h"
|
||||
#include "palMutex.h"
|
||||
|
||||
namespace Pal
|
||||
{
|
||||
class IPlatform;
|
||||
class IDevice;
|
||||
class IShaderLibrary;
|
||||
} // namespace Pal
|
||||
|
||||
namespace GpuUtil
|
||||
{
|
||||
class GpaSession;
|
||||
} // namespace GpuUtil
|
||||
|
||||
namespace GpuUtil
|
||||
{
|
||||
|
||||
namespace TraceChunk
|
||||
{
|
||||
|
||||
/// "CodeObject" RDF chunk identifier & version
|
||||
constexpr char CodeObjectChunkId[TextIdentifierSize] = "CodeObject";
|
||||
constexpr Pal::uint32 CodeObjectChunkVersion = 2;
|
||||
|
||||
/// Header for the "CodeObject" RDF chunk
|
||||
struct CodeObjectHeader
|
||||
{
|
||||
Pal::uint32 pciId; /// The ID of the GPU the trace was run on
|
||||
Pal::ShaderHash codeObjectHash; /// Hash of the Code Object binary
|
||||
};
|
||||
|
||||
/// "COLoadEvent" RDF chunk identifier & version
|
||||
constexpr char CodeObjectLoadEventChunkId[TextIdentifierSize] = "COLoadEvent";
|
||||
constexpr Pal::uint32 CodeObjectLoadEventChunkVersion = 3;
|
||||
|
||||
struct CodeObjectLoadEventHeader
|
||||
{
|
||||
Pal::uint32 count; /// Number of load events in this chunk
|
||||
};
|
||||
|
||||
/// Describes whether a load event was into GPU memory or from.
|
||||
enum class CodeObjectLoadEventType : Pal::uint32
|
||||
{
|
||||
LoadToGpuMemory = 0, /// Code Object was loaded into GPU memory
|
||||
UnloadFromGpuMemory = 1 /// Code Object was unloaded from GPU memory
|
||||
};
|
||||
|
||||
/// Describes one or more GPU load/unload(s) of a Code Object. Payload for "COLoadEvent" RDF chunk.
|
||||
struct CodeObjectLoadEvent
|
||||
{
|
||||
Pal::uint32 pciId; /// The ID of the GPU the trace was run on
|
||||
CodeObjectLoadEventType eventType; /// Type of loader event
|
||||
Pal::uint64 baseAddress; /// Base address where the Code Object was loaded
|
||||
Pal::ShaderHash codeObjectHash; /// Hash of the (un)loaded Code Object binary
|
||||
Pal::uint64 timestamp; /// CPU timestamp of this event being triggered
|
||||
};
|
||||
|
||||
/// "PsoCorrelation" RDF chunk identifier & version
|
||||
constexpr char PsoCorrelationChunkId[TextIdentifierSize] = "PsoCorrelation";
|
||||
constexpr Pal::uint32 PsoCorrelationChunkVersion = 3;
|
||||
|
||||
struct PsoCorrelationHeader
|
||||
{
|
||||
Pal::uint32 count; /// Number of PSO correlations in this chunk
|
||||
};
|
||||
|
||||
/// Payload for the "PsoCorrelation" RDF chunks
|
||||
struct PsoCorrelation
|
||||
{
|
||||
Pal::uint32 pciId; /// The ID of the GPU the trace was run on
|
||||
Pal::uint64 apiPsoHash; /// Hash of the API-level Pipeline State Object
|
||||
Pal::PipelineHash internalPipelineHash; /// Hash of all inputs to the pipeline compiler
|
||||
char apiLevelObjectName[64]; /// Debug object name (null-terminated)
|
||||
};
|
||||
|
||||
/// "COCorrelation" RDF chunk identifier & version
|
||||
constexpr char CodeObjectCorrelationChunkId[TextIdentifierSize] = "COCorrelation";
|
||||
constexpr uint32_t CodeObjectCorrelationChunkVersion = 4;
|
||||
|
||||
struct CodeObjectCorrelationHeader
|
||||
{
|
||||
Pal::uint32 count; /// Number of Code Object Correlations in this chunk
|
||||
};
|
||||
|
||||
/// Payload for the "CodeObjectCorrelation" RDF chunks
|
||||
struct CodeObjectCorrelation
|
||||
{
|
||||
Pal::PipelineHash internalPipelineHash; /// Hash of all inputs to the pipeline compiler
|
||||
Pal::ShaderHash codeObjectHash; /// Hash of the Code Object binary in the CO Database
|
||||
Pal::uint32 containsMetadata : 1; /// 1 if the code object contains metadata, 0 otherwise
|
||||
Pal::uint32 reserved : 31; /// Bitflags reserved for future use
|
||||
};
|
||||
|
||||
} // namespace TraceChunk
|
||||
|
||||
/// CodeObject Trace Source name & version
|
||||
constexpr char CodeObjectTraceSourceName[] = "codeobject";
|
||||
constexpr Pal::uint32 CodeObjectTraceSourceVersion = 3;
|
||||
|
||||
// =====================================================================================================================
|
||||
class CodeObjectTraceSource : public ITraceSource
|
||||
{
|
||||
public:
|
||||
CodeObjectTraceSource(Pal::IPlatform* pPlatform);
|
||||
~CodeObjectTraceSource();
|
||||
|
||||
// ==== TraceSource Native Functions ========================================================================== //
|
||||
Pal::Result RegisterPipeline(const Pal::IPipeline* pPipeline, const RegisterPipelineInfo& clientInfo);
|
||||
Pal::Result UnregisterPipeline(const Pal::IPipeline* pPipeline);
|
||||
|
||||
Pal::Result RegisterLibrary(const Pal::IShaderLibrary* pLibrary, const RegisterLibraryInfo& clientInfo);
|
||||
Pal::Result UnregisterLibrary(const Pal::IShaderLibrary* pLibrary);
|
||||
|
||||
Pal::Result RegisterElfBinary(const ElfBinaryInfo& elfBinaryInfo);
|
||||
Pal::Result UnregisterElfBinary(const ElfBinaryInfo& elfBinaryInfo);
|
||||
|
||||
// ==== Base Class Overrides =================================================================================== //
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION < COMPRESSION_ARG_VERSION
|
||||
virtual void OnConfigUpdated(DevDriver::StructuredValue* pJsonConfig) override { }
|
||||
#endif
|
||||
|
||||
virtual Pal::uint64 QueryGpuWorkMask() const override { return 0; }
|
||||
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION >= 908
|
||||
virtual void OnTraceAccepted(Pal::uint32 gpuIndex, Pal::ICmdBuffer* pCmdBuf) override { }
|
||||
#else
|
||||
virtual void OnTraceAccepted() override { }
|
||||
#endif
|
||||
virtual void OnTraceBegin(Pal::uint32 gpuIndex, Pal::ICmdBuffer* pCmdBuf) override { }
|
||||
virtual void OnTraceEnd(Pal::uint32 gpuIndex, Pal::ICmdBuffer* pCmdBuf) override { }
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION >= 939
|
||||
virtual void OnPostambleEnd(
|
||||
Pal::uint32 gpuIndex,
|
||||
Pal::ICmdBuffer* pCmdBuf) override { }
|
||||
#endif
|
||||
virtual void OnTraceFinished() override;
|
||||
|
||||
virtual const char* GetName() const override { return CodeObjectTraceSourceName; }
|
||||
virtual Pal::uint32 GetVersion() const override { return CodeObjectTraceSourceVersion; }
|
||||
|
||||
private:
|
||||
Pal::Result RegisterSinglePipeline(const Pal::IPipeline* pPipeline, const RegisterPipelineInfo& clientInfo);
|
||||
Pal::Result UnregisterSinglePipeline(const Pal::IPipeline* pPipeline);
|
||||
|
||||
Pal::Result AddCodeObjectLoadEvent(
|
||||
const Pal::IShaderLibrary* pLibrary,
|
||||
TraceChunk::CodeObjectLoadEventType eventType);
|
||||
Pal::Result AddCodeObjectLoadEvent(
|
||||
const Pal::IPipeline* pLibrary,
|
||||
TraceChunk::CodeObjectLoadEventType eventType);
|
||||
Pal::Result AddCodeObjectLoadEvent(
|
||||
const ElfBinaryInfo& elfBinaryInfo,
|
||||
TraceChunk::CodeObjectLoadEventType eventType);
|
||||
|
||||
Pal::Result WriteCodeObjectChunks();
|
||||
Pal::Result WriteLoaderEventsChunk();
|
||||
Pal::Result WritePsoCorrelationChunk();
|
||||
Pal::Result WriteCoCorrelationChunk();
|
||||
|
||||
struct CodeObjectDatabaseRecord
|
||||
{
|
||||
Pal::uint32 recordSize;
|
||||
Pal::ShaderHash codeObjectHash;
|
||||
};
|
||||
|
||||
Pal::IPlatform* const m_pPlatform;
|
||||
|
||||
Util::RWLock m_registerPipelineLock;
|
||||
Util::Vector<CodeObjectDatabaseRecord*, 1, Pal::IPlatform> m_codeObjectRecords;
|
||||
Util::Vector<TraceChunk::CodeObjectLoadEvent, 1, Pal::IPlatform> m_loadEventRecords;
|
||||
Util::Vector<TraceChunk::PsoCorrelation, 1, Pal::IPlatform> m_psoCorrelationRecords;
|
||||
Util::Vector<TraceChunk::CodeObjectCorrelation, 1, Pal::IPlatform> m_coCorrelationRecords;
|
||||
|
||||
// API hashes -> internal pipeline hash (-> child code object hashes)
|
||||
Util::HashSet<Pal::uint64, Pal::IPlatform, Util::JenkinsHashFunc> m_registeredApiHashes;
|
||||
Util::HashSet<Pal::uint64, Pal::IPlatform, Util::JenkinsHashFunc> m_registeredPipelines;
|
||||
Util::HashSet<Pal::uint64, Pal::IPlatform, Util::JenkinsHashFunc> m_registeredCoHashes;
|
||||
|
||||
};
|
||||
|
||||
} // namespace GpuUtil
|
||||
|
||||
/*
|
||||
***********************************************************************************************************************
|
||||
*
|
||||
* Copyright (c) 2023-2025 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
**********************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "palGpaSession.h"
|
||||
#include "palGpuUtil.h"
|
||||
#include "palTraceSession.h"
|
||||
#include "palVector.h"
|
||||
#include "palHashSet.h"
|
||||
#include "palMutex.h"
|
||||
|
||||
namespace Pal
|
||||
{
|
||||
class IPlatform;
|
||||
class IDevice;
|
||||
class IShaderLibrary;
|
||||
} // namespace Pal
|
||||
|
||||
namespace GpuUtil
|
||||
{
|
||||
class GpaSession;
|
||||
} // namespace GpuUtil
|
||||
|
||||
namespace GpuUtil
|
||||
{
|
||||
|
||||
namespace TraceChunk
|
||||
{
|
||||
|
||||
/// "CodeObject" RDF chunk identifier & version
|
||||
constexpr char CodeObjectChunkId[TextIdentifierSize] = "CodeObject";
|
||||
constexpr Pal::uint32 CodeObjectChunkVersion = 2;
|
||||
|
||||
/// Header for the "CodeObject" RDF chunk
|
||||
struct CodeObjectHeader
|
||||
{
|
||||
Pal::uint32 pciId; /// The ID of the GPU the trace was run on
|
||||
Pal::ShaderHash codeObjectHash; /// Hash of the Code Object binary
|
||||
};
|
||||
|
||||
/// "COLoadEvent" RDF chunk identifier & version
|
||||
constexpr char CodeObjectLoadEventChunkId[TextIdentifierSize] = "COLoadEvent";
|
||||
constexpr Pal::uint32 CodeObjectLoadEventChunkVersion = 3;
|
||||
|
||||
struct CodeObjectLoadEventHeader
|
||||
{
|
||||
Pal::uint32 count; /// Number of load events in this chunk
|
||||
};
|
||||
|
||||
/// Describes whether a load event was into GPU memory or from.
|
||||
enum class CodeObjectLoadEventType : Pal::uint32
|
||||
{
|
||||
LoadToGpuMemory = 0, /// Code Object was loaded into GPU memory
|
||||
UnloadFromGpuMemory = 1 /// Code Object was unloaded from GPU memory
|
||||
};
|
||||
|
||||
/// Describes one or more GPU load/unload(s) of a Code Object. Payload for "COLoadEvent" RDF chunk.
|
||||
struct CodeObjectLoadEvent
|
||||
{
|
||||
Pal::uint32 pciId; /// The ID of the GPU the trace was run on
|
||||
CodeObjectLoadEventType eventType; /// Type of loader event
|
||||
Pal::uint64 baseAddress; /// Base address where the Code Object was loaded
|
||||
Pal::ShaderHash codeObjectHash; /// Hash of the (un)loaded Code Object binary
|
||||
Pal::uint64 timestamp; /// CPU timestamp of this event being triggered
|
||||
};
|
||||
|
||||
/// "PsoCorrelation" RDF chunk identifier & version
|
||||
constexpr char PsoCorrelationChunkId[TextIdentifierSize] = "PsoCorrelation";
|
||||
constexpr Pal::uint32 PsoCorrelationChunkVersion = 3;
|
||||
|
||||
struct PsoCorrelationHeader
|
||||
{
|
||||
Pal::uint32 count; /// Number of PSO correlations in this chunk
|
||||
};
|
||||
|
||||
/// Payload for the "PsoCorrelation" RDF chunks
|
||||
struct PsoCorrelation
|
||||
{
|
||||
Pal::uint32 pciId; /// The ID of the GPU the trace was run on
|
||||
Pal::uint64 apiPsoHash; /// Hash of the API-level Pipeline State Object
|
||||
Pal::PipelineHash internalPipelineHash; /// Hash of all inputs to the pipeline compiler
|
||||
char apiLevelObjectName[64]; /// Debug object name (null-terminated)
|
||||
};
|
||||
|
||||
/// "COCorrelation" RDF chunk identifier & version
|
||||
constexpr char CodeObjectCorrelationChunkId[TextIdentifierSize] = "COCorrelation";
|
||||
constexpr uint32_t CodeObjectCorrelationChunkVersion = 4;
|
||||
|
||||
struct CodeObjectCorrelationHeader
|
||||
{
|
||||
Pal::uint32 count; /// Number of Code Object Correlations in this chunk
|
||||
};
|
||||
|
||||
/// Payload for the "CodeObjectCorrelation" RDF chunks
|
||||
struct CodeObjectCorrelation
|
||||
{
|
||||
Pal::PipelineHash internalPipelineHash; /// Hash of all inputs to the pipeline compiler
|
||||
Pal::ShaderHash codeObjectHash; /// Hash of the Code Object binary in the CO Database
|
||||
Pal::uint32 containsMetadata : 1; /// 1 if the code object contains metadata, 0 otherwise
|
||||
Pal::uint32 reserved : 31; /// Bitflags reserved for future use
|
||||
};
|
||||
|
||||
} // namespace TraceChunk
|
||||
|
||||
/// CodeObject Trace Source name & version
|
||||
constexpr char CodeObjectTraceSourceName[] = "codeobject";
|
||||
constexpr Pal::uint32 CodeObjectTraceSourceVersion = 3;
|
||||
|
||||
// =====================================================================================================================
|
||||
class CodeObjectTraceSource : public ITraceSource
|
||||
{
|
||||
public:
|
||||
CodeObjectTraceSource(Pal::IPlatform* pPlatform);
|
||||
~CodeObjectTraceSource();
|
||||
|
||||
// ==== TraceSource Native Functions ========================================================================== //
|
||||
Pal::Result RegisterPipeline(const Pal::IPipeline* pPipeline, const RegisterPipelineInfo& clientInfo);
|
||||
Pal::Result UnregisterPipeline(const Pal::IPipeline* pPipeline);
|
||||
|
||||
Pal::Result RegisterLibrary(const Pal::IShaderLibrary* pLibrary, const RegisterLibraryInfo& clientInfo);
|
||||
Pal::Result UnregisterLibrary(const Pal::IShaderLibrary* pLibrary);
|
||||
|
||||
Pal::Result RegisterElfBinary(const ElfBinaryInfo& elfBinaryInfo);
|
||||
Pal::Result UnregisterElfBinary(const ElfBinaryInfo& elfBinaryInfo);
|
||||
|
||||
// ==== Base Class Overrides =================================================================================== //
|
||||
virtual void OnConfigUpdated(DevDriver::StructuredValue* pJsonConfig) override { }
|
||||
|
||||
virtual Pal::uint64 QueryGpuWorkMask() const override { return 0; }
|
||||
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION >= 908
|
||||
virtual void OnTraceAccepted(Pal::uint32 gpuIndex, Pal::ICmdBuffer* pCmdBuf) override { }
|
||||
#else
|
||||
virtual void OnTraceAccepted() override { }
|
||||
#endif
|
||||
virtual void OnTraceBegin(Pal::uint32 gpuIndex, Pal::ICmdBuffer* pCmdBuf) override { }
|
||||
virtual void OnTraceEnd(Pal::uint32 gpuIndex, Pal::ICmdBuffer* pCmdBuf) override { }
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION >= 939
|
||||
virtual void OnPostambleEnd(
|
||||
Pal::uint32 gpuIndex,
|
||||
Pal::ICmdBuffer* pCmdBuf) override { }
|
||||
#endif
|
||||
virtual void OnTraceFinished() override;
|
||||
|
||||
virtual const char* GetName() const override { return CodeObjectTraceSourceName; }
|
||||
virtual Pal::uint32 GetVersion() const override { return CodeObjectTraceSourceVersion; }
|
||||
|
||||
private:
|
||||
Pal::Result RegisterSinglePipeline(const Pal::IPipeline* pPipeline, const RegisterPipelineInfo& clientInfo);
|
||||
Pal::Result UnregisterSinglePipeline(const Pal::IPipeline* pPipeline);
|
||||
|
||||
Pal::Result AddCodeObjectLoadEvent(
|
||||
const Pal::IShaderLibrary* pLibrary,
|
||||
TraceChunk::CodeObjectLoadEventType eventType);
|
||||
Pal::Result AddCodeObjectLoadEvent(
|
||||
const Pal::IPipeline* pLibrary,
|
||||
TraceChunk::CodeObjectLoadEventType eventType);
|
||||
Pal::Result AddCodeObjectLoadEvent(
|
||||
const ElfBinaryInfo& elfBinaryInfo,
|
||||
TraceChunk::CodeObjectLoadEventType eventType);
|
||||
|
||||
Pal::Result WriteCodeObjectChunks();
|
||||
Pal::Result WriteLoaderEventsChunk();
|
||||
Pal::Result WritePsoCorrelationChunk();
|
||||
Pal::Result WriteCoCorrelationChunk();
|
||||
|
||||
struct CodeObjectDatabaseRecord
|
||||
{
|
||||
Pal::uint32 recordSize;
|
||||
Pal::ShaderHash codeObjectHash;
|
||||
};
|
||||
|
||||
Pal::IPlatform* const m_pPlatform;
|
||||
|
||||
Util::RWLock m_registerPipelineLock;
|
||||
Util::Vector<CodeObjectDatabaseRecord*, 1, Pal::IPlatform> m_codeObjectRecords;
|
||||
Util::Vector<TraceChunk::CodeObjectLoadEvent, 1, Pal::IPlatform> m_loadEventRecords;
|
||||
Util::Vector<TraceChunk::PsoCorrelation, 1, Pal::IPlatform> m_psoCorrelationRecords;
|
||||
Util::Vector<TraceChunk::CodeObjectCorrelation, 1, Pal::IPlatform> m_coCorrelationRecords;
|
||||
|
||||
// API hashes -> internal pipeline hash (-> child code object hashes)
|
||||
Util::HashSet<Pal::uint64, Pal::IPlatform, Util::JenkinsHashFunc> m_registeredApiHashes;
|
||||
Util::HashSet<Pal::uint64, Pal::IPlatform, Util::JenkinsHashFunc> m_registeredPipelines;
|
||||
Util::HashSet<Pal::uint64, Pal::IPlatform, Util::JenkinsHashFunc> m_registeredCoHashes;
|
||||
|
||||
};
|
||||
|
||||
} // namespace GpuUtil
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,141 +1,141 @@
|
||||
/*
|
||||
***********************************************************************************************************************
|
||||
*
|
||||
* Copyright (c) 2014-2025 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
**********************************************************************************************************************/
|
||||
/**
|
||||
***********************************************************************************************************************
|
||||
* @file palGpuUtil.h
|
||||
* @brief Common include for the PAL GPU utility collection. Defines common types, macros, enums, etc.
|
||||
***********************************************************************************************************************
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "pal.h"
|
||||
|
||||
// Forward declarations.
|
||||
namespace Pal
|
||||
{
|
||||
struct DeviceProperties;
|
||||
class IImage;
|
||||
class IGpuMemory;
|
||||
struct ImageCopyRegion;
|
||||
struct TypedBufferCopyRegion;
|
||||
struct MemoryImageCopyRegion;
|
||||
}
|
||||
|
||||
/// Library-wide namespace encapsulating all PAL GPU utility entities.
|
||||
namespace GpuUtil
|
||||
{
|
||||
|
||||
/// Validate image copy region.
|
||||
///
|
||||
/// @param [in] properties The device properties.
|
||||
/// @param [in] engineType Engine to validate.
|
||||
/// @param [in] src Src image.
|
||||
/// @param [in] dst Des image.
|
||||
/// @param [in] region Copy region.
|
||||
///
|
||||
/// @returns true if the image copy is supported by the specific engine, otherwise false.
|
||||
extern bool ValidateImageCopyRegion(
|
||||
const Pal::DeviceProperties& properties,
|
||||
Pal::EngineType engineType,
|
||||
const Pal::IImage& src,
|
||||
const Pal::IImage& dst,
|
||||
const Pal::ImageCopyRegion& region);
|
||||
|
||||
/// Validate typed buffer copy region.
|
||||
///
|
||||
/// @param [in] properties The device properties.
|
||||
/// @param [in] engineType Engine to validate.
|
||||
/// @param [in] region Copy region.
|
||||
///
|
||||
/// @returns true if the typed buffer copy is supported by the specific engine, otherwise false.
|
||||
extern bool ValidateTypedBufferCopyRegion(
|
||||
const Pal::DeviceProperties& properties,
|
||||
Pal::EngineType engineType,
|
||||
const Pal::TypedBufferCopyRegion& region);
|
||||
|
||||
/// Validate image-memory copy region.
|
||||
///
|
||||
/// @param [in] properties The device properties.
|
||||
/// @param [in] engineType Engine to validate.
|
||||
/// @param [in] image The IImage object.
|
||||
/// @param [in] region Copy region.
|
||||
///
|
||||
/// @returns true if the image-memory copy is supported by the specific engine, otherwise false.
|
||||
extern bool ValidateMemoryImageRegion(
|
||||
const Pal::DeviceProperties& properties,
|
||||
Pal::EngineType engineType,
|
||||
const Pal::IImage& image,
|
||||
const Pal::IGpuMemory& memory,
|
||||
const Pal::MemoryImageCopyRegion& region);
|
||||
|
||||
/// Generate a 64-bit uniqueId for a GPU memory allocation
|
||||
///
|
||||
/// @param [in] isInterprocess Indicates this uniqueId is for an externally shareable GPU memory allocation
|
||||
///
|
||||
/// @returns 64-bit uniqueId
|
||||
extern Pal::uint64 GenerateGpuMemoryUniqueId(
|
||||
bool isInterprocess);
|
||||
|
||||
} // GpuUtil
|
||||
|
||||
/**
|
||||
***********************************************************************************************************************
|
||||
* @page GpuUtilOverview GPU Utility Collection
|
||||
*
|
||||
* In addition to the generic, OS-abstracted software utilities, PAL provides GPU-specific utilities in the @ref GpuUtil
|
||||
* namespace. The PAL GPU Utility Collection relies on both PAL core and PAL Utility. They are also available for use by
|
||||
* its clients.
|
||||
*
|
||||
* All available PAL GPU utilities are defined in the @ref GpuUtil namespace, and are briefly summarized below. See the
|
||||
* Reference topics for more detailed information on specific classes, enums, etc.
|
||||
*
|
||||
* ### TextWriter
|
||||
* The TextWriter GPU utility class provides a method for clients to write text directly to an image. This can be used
|
||||
* for debugging purposes. PAL's internal DbgOverlay uses the TextWriter class to write information about the current
|
||||
* FPS and total allocated GPU video memory usage.
|
||||
*
|
||||
* The TextWriter class is broken up into palTextWriter.h and palTextWriterImpl.h. The intention is that palTextWriter.h
|
||||
* will be included from other header files that need a full TextWriter definition, while palTextWriterImpl.h will be
|
||||
* included by .cpp files that actually interact with the TextWriter. This should keep build times down versus putting
|
||||
* all implementations directly in palTextWriter.h.
|
||||
*
|
||||
* Also included in the TextWriter is the TextWriterFont namespace, which defines the shader IL for drawing the text via
|
||||
* a compute shader. It also defines the Font data, which is a packed binary that represents which pixels of a 10x16
|
||||
* rectangle to render. The font is monospaced.
|
||||
*
|
||||
* ### Helper Functions
|
||||
* ValidateImageCopyRegion - Validate the image copy region, returns true if the image copy is supported by the specific
|
||||
* engine, otherwise false.
|
||||
*
|
||||
* ValidateTypedBufferCopyRegion - Validate the typed buffer copy region, returns true if the typed buffer copy is
|
||||
* supported by the specific engine, otherwise false.
|
||||
*
|
||||
* ValidateMemoryImageRegion - Validate the image-memory copy region, returns true if the image-memory copy is supported
|
||||
* by the specific engine, otherwise false.
|
||||
*
|
||||
* Next: @ref Overview
|
||||
***********************************************************************************************************************
|
||||
*/
|
||||
/*
|
||||
***********************************************************************************************************************
|
||||
*
|
||||
* Copyright (c) 2014-2025 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
**********************************************************************************************************************/
|
||||
/**
|
||||
***********************************************************************************************************************
|
||||
* @file palGpuUtil.h
|
||||
* @brief Common include for the PAL GPU utility collection. Defines common types, macros, enums, etc.
|
||||
***********************************************************************************************************************
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "pal.h"
|
||||
|
||||
// Forward declarations.
|
||||
namespace Pal
|
||||
{
|
||||
struct DeviceProperties;
|
||||
class IImage;
|
||||
class IGpuMemory;
|
||||
struct ImageCopyRegion;
|
||||
struct TypedBufferCopyRegion;
|
||||
struct MemoryImageCopyRegion;
|
||||
}
|
||||
|
||||
/// Library-wide namespace encapsulating all PAL GPU utility entities.
|
||||
namespace GpuUtil
|
||||
{
|
||||
|
||||
/// Validate image copy region.
|
||||
///
|
||||
/// @param [in] properties The device properties.
|
||||
/// @param [in] engineType Engine to validate.
|
||||
/// @param [in] src Src image.
|
||||
/// @param [in] dst Des image.
|
||||
/// @param [in] region Copy region.
|
||||
///
|
||||
/// @returns true if the image copy is supported by the specific engine, otherwise false.
|
||||
extern bool ValidateImageCopyRegion(
|
||||
const Pal::DeviceProperties& properties,
|
||||
Pal::EngineType engineType,
|
||||
const Pal::IImage& src,
|
||||
const Pal::IImage& dst,
|
||||
const Pal::ImageCopyRegion& region);
|
||||
|
||||
/// Validate typed buffer copy region.
|
||||
///
|
||||
/// @param [in] properties The device properties.
|
||||
/// @param [in] engineType Engine to validate.
|
||||
/// @param [in] region Copy region.
|
||||
///
|
||||
/// @returns true if the typed buffer copy is supported by the specific engine, otherwise false.
|
||||
extern bool ValidateTypedBufferCopyRegion(
|
||||
const Pal::DeviceProperties& properties,
|
||||
Pal::EngineType engineType,
|
||||
const Pal::TypedBufferCopyRegion& region);
|
||||
|
||||
/// Validate image-memory copy region.
|
||||
///
|
||||
/// @param [in] properties The device properties.
|
||||
/// @param [in] engineType Engine to validate.
|
||||
/// @param [in] image The IImage object.
|
||||
/// @param [in] region Copy region.
|
||||
///
|
||||
/// @returns true if the image-memory copy is supported by the specific engine, otherwise false.
|
||||
extern bool ValidateMemoryImageRegion(
|
||||
const Pal::DeviceProperties& properties,
|
||||
Pal::EngineType engineType,
|
||||
const Pal::IImage& image,
|
||||
const Pal::IGpuMemory& memory,
|
||||
const Pal::MemoryImageCopyRegion& region);
|
||||
|
||||
/// Generate a 64-bit uniqueId for a GPU memory allocation
|
||||
///
|
||||
/// @param [in] isInterprocess Indicates this uniqueId is for an externally shareable GPU memory allocation
|
||||
///
|
||||
/// @returns 64-bit uniqueId
|
||||
extern Pal::uint64 GenerateGpuMemoryUniqueId(
|
||||
bool isInterprocess);
|
||||
|
||||
} // GpuUtil
|
||||
|
||||
/**
|
||||
***********************************************************************************************************************
|
||||
* @page GpuUtilOverview GPU Utility Collection
|
||||
*
|
||||
* In addition to the generic, OS-abstracted software utilities, PAL provides GPU-specific utilities in the @ref GpuUtil
|
||||
* namespace. The PAL GPU Utility Collection relies on both PAL core and PAL Utility. They are also available for use by
|
||||
* its clients.
|
||||
*
|
||||
* All available PAL GPU utilities are defined in the @ref GpuUtil namespace, and are briefly summarized below. See the
|
||||
* Reference topics for more detailed information on specific classes, enums, etc.
|
||||
*
|
||||
* ### TextWriter
|
||||
* The TextWriter GPU utility class provides a method for clients to write text directly to an image. This can be used
|
||||
* for debugging purposes. PAL's internal DbgOverlay uses the TextWriter class to write information about the current
|
||||
* FPS and total allocated GPU video memory usage.
|
||||
*
|
||||
* The TextWriter class is broken up into palTextWriter.h and palTextWriterImpl.h. The intention is that palTextWriter.h
|
||||
* will be included from other header files that need a full TextWriter definition, while palTextWriterImpl.h will be
|
||||
* included by .cpp files that actually interact with the TextWriter. This should keep build times down versus putting
|
||||
* all implementations directly in palTextWriter.h.
|
||||
*
|
||||
* Also included in the TextWriter is the TextWriterFont namespace, which defines the shader IL for drawing the text via
|
||||
* a compute shader. It also defines the Font data, which is a packed binary that represents which pixels of a 10x16
|
||||
* rectangle to render. The font is monospaced.
|
||||
*
|
||||
* ### Helper Functions
|
||||
* ValidateImageCopyRegion - Validate the image copy region, returns true if the image copy is supported by the specific
|
||||
* engine, otherwise false.
|
||||
*
|
||||
* ValidateTypedBufferCopyRegion - Validate the typed buffer copy region, returns true if the typed buffer copy is
|
||||
* supported by the specific engine, otherwise false.
|
||||
*
|
||||
* ValidateMemoryImageRegion - Validate the image-memory copy region, returns true if the image-memory copy is supported
|
||||
* by the specific engine, otherwise false.
|
||||
*
|
||||
* Next: @ref Overview
|
||||
***********************************************************************************************************************
|
||||
*/
|
||||
|
||||
@@ -1,238 +1,236 @@
|
||||
/*
|
||||
***********************************************************************************************************************
|
||||
*
|
||||
* Copyright (c) 2024-2025 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
**********************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "palGpuUtil.h"
|
||||
#include "palTraceSession.h"
|
||||
#include "palGpaSession.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
struct SqttQueueEventRecord;
|
||||
struct SqttQueueInfoRecord;
|
||||
|
||||
namespace Pal
|
||||
{
|
||||
class Platform;
|
||||
}
|
||||
|
||||
namespace GpuUtil
|
||||
{
|
||||
namespace TraceChunk
|
||||
{
|
||||
|
||||
/// "QueueInfo" RDF chunk identifier & version
|
||||
constexpr char QueueInfoChunkId[TextIdentifierSize] = "QueueInfo";
|
||||
constexpr Pal::uint32 QueueInfoChunkVersion = 1;
|
||||
|
||||
/// Enum describing logical queue types
|
||||
enum class QueueType : Pal::uint8
|
||||
{
|
||||
Unknown = 0,
|
||||
Universal = 1,
|
||||
Compute = 2,
|
||||
Dma = 3,
|
||||
Encode = 4,
|
||||
Decode = 5,
|
||||
Security = 6,
|
||||
VideoProcessor = 7
|
||||
};
|
||||
|
||||
/// Enum describing hardware engine types
|
||||
enum class HwEngineType : Pal::uint8
|
||||
{
|
||||
Unknown = 0,
|
||||
Universal = 1,
|
||||
Compute = 2,
|
||||
ExclusiveCompute = 3,
|
||||
Dma = 4,
|
||||
Decode = 5,
|
||||
Encode = 6,
|
||||
HighPriorityUniversal = 7,
|
||||
HighPriorityGraphics = 8,
|
||||
Security = 9,
|
||||
Vpe = 10
|
||||
};
|
||||
|
||||
/// Structure describing a queue's properties
|
||||
struct QueueInfo
|
||||
{
|
||||
Pal::uint32 pciId; ///< The ID of the GPU queried
|
||||
Pal::uint64 queueId; ///< API-specific queue ID
|
||||
Pal::uint64 queueContext; ///< OS-level queue context value from Windows KMD to correlate with ETW data.
|
||||
/// Only applicable to D3D on Windows; 0 otherwise.
|
||||
QueueType queueType; ///< The logical queue type
|
||||
HwEngineType engineType; ///< The hardware engine that the queue is mapped to
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------- //
|
||||
|
||||
/// "QueueEvent" RDF chunk identifier & version
|
||||
constexpr char QueueEventChunkId[TextIdentifierSize] = "QueueEvent";
|
||||
constexpr Pal::uint32 QueueEventChunkVersion = 1;
|
||||
|
||||
/// The type of queue-level timings event
|
||||
enum class QueueEventType : Pal::uint32
|
||||
{
|
||||
CmdBufSubmit = 0,
|
||||
SignalSemaphore = 1,
|
||||
WaitSemaphore = 2,
|
||||
Present = 3
|
||||
};
|
||||
|
||||
/// Structure describing a queue-level timings event
|
||||
struct QueueEvent
|
||||
{
|
||||
Pal::uint32 pciId; ///< The ID of the GPU queried
|
||||
Pal::uint64 queueId; ///< The API-specific queue ID which triggered the event
|
||||
QueueEventType eventType; ///< The type of the queue-timing event
|
||||
Pal::uint32 sqttCmdBufId; ///< [`CmdBufSubmit` only; 0 otherwise]
|
||||
/// SQTT command buffer ID matching CmdBufStart user data marker
|
||||
Pal::uint64 frameIndex; ///< [`CmdBufSubmit` & `Present` only; 0 otherwise]
|
||||
/// Global frame index incremented for each "Present" call
|
||||
Pal::uint32 submitSubIndex; ///< [`CmdBufSubmit` only; 0 otherwise]
|
||||
/// Sub-index of event within submission.
|
||||
/// When there is only one CmdBuffer per submission, `submitSubIndex` is 0.
|
||||
/// When there are multiple command buffers per submission, `submitSubIndex`
|
||||
/// is incremented by one for each command buffer within the submission.
|
||||
Pal::uint64 apiEventId; ///< [`CmdBufSubmit`] API-specific command buffer ID signaled
|
||||
/// [`SignalSemaphore`] API-specific semaphore ID signaled
|
||||
/// [`WaitSemaphore`] API-specific semaphore ID waited on
|
||||
/// [`Present`] N/A (set to 0)
|
||||
Pal::uint64 cpuTimestamp; ///< CPU start timestamp of when this event is triggered in clock cycle units
|
||||
Pal::uint64 gpuTimestamp1; ///< [`CmdBufSubmit`] GPU timestamp when the HW execution of command buffer began
|
||||
/// [`SignalSemaphore`] GPU timestamp when the HW signaled the queue semaphore
|
||||
/// [`WaitSemaphore`] GPU timestamp when HW finished waiting on the semaphore
|
||||
/// [`Present`] GPU timestamp when HW processed the Present call
|
||||
///
|
||||
/// All timestamps are expressed in clock cycle units.
|
||||
Pal::uint64 gpuTimestamp2; ///< [`CmdBufSubmit` only; 0 otherwise]
|
||||
/// GPU timestamp when the HW execution of command buffer finished
|
||||
};
|
||||
|
||||
} // namespace TraceChunk
|
||||
|
||||
// QueueTimings Trace Source name & version
|
||||
constexpr char QueueTimingsTraceSourceName[] = "queuetimings";
|
||||
constexpr Pal::uint32 QueueTimingsTraceSourceVersion = 2;
|
||||
|
||||
// =====================================================================================================================
|
||||
// This trace source captures queue timings data through GPA session & produces "QueueInfo" and "QueueEvent" RDF chunks
|
||||
class QueueTimingsTraceSource : public ITraceSource
|
||||
{
|
||||
public:
|
||||
explicit QueueTimingsTraceSource(Pal::IPlatform* pPlatform);
|
||||
virtual ~QueueTimingsTraceSource();
|
||||
|
||||
// ==== TraceSource Native Functions ========================================================================== //
|
||||
Pal::Result Init(Pal::IDevice* pDevice);
|
||||
|
||||
Pal::Result RegisterTimedQueue(Pal::IQueue* pQueue,
|
||||
Pal::uint64 queueId,
|
||||
Pal::uint64 queueContext);
|
||||
|
||||
Pal::Result UnregisterTimedQueue(Pal::IQueue* pQueue);
|
||||
|
||||
Pal::Result TimedSubmit(Pal::IQueue* pQueue,
|
||||
const Pal::MultiSubmitInfo& submitInfo,
|
||||
const TimedSubmitInfo& timedSubmitInfo);
|
||||
|
||||
Pal::Result TimedSignalQueueSemaphore(Pal::IQueue* pQueue,
|
||||
Pal::IQueueSemaphore* pQueueSemaphore,
|
||||
const TimedQueueSemaphoreInfo& timedSignalInfo,
|
||||
Pal::uint64 value = 0);
|
||||
|
||||
Pal::Result TimedWaitQueueSemaphore(Pal::IQueue* pQueue,
|
||||
Pal::IQueueSemaphore* pQueueSemaphore,
|
||||
const TimedQueueSemaphoreInfo& timedWaitInfo,
|
||||
Pal::uint64 value = 0);
|
||||
|
||||
Pal::Result TimedQueuePresent(Pal::IQueue* pQueue,
|
||||
const TimedQueuePresentInfo& timedPresentInfo);
|
||||
|
||||
Pal::Result ExternalTimedWaitQueueSemaphore(Pal::uint64 queueContext,
|
||||
Pal::uint64 cpuSubmissionTimestamp,
|
||||
Pal::uint64 cpuCompletionTimestamp,
|
||||
const TimedQueueSemaphoreInfo& timedWaitInfo);
|
||||
|
||||
Pal::Result ExternalTimedSignalQueueSemaphore(Pal::uint64 queueContext,
|
||||
Pal::uint64 cpuSubmissionTimestamp,
|
||||
Pal::uint64 cpuCompletionTimestamp,
|
||||
const TimedQueueSemaphoreInfo& timedSignalInfo);
|
||||
|
||||
bool IsTimingInProgress() const;
|
||||
|
||||
// ==== Base Class Overrides =================================================================================== //
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION < COMPRESSION_ARG_VERSION
|
||||
virtual void OnConfigUpdated(DevDriver::StructuredValue* pJsonConfig) override { }
|
||||
#endif
|
||||
|
||||
virtual Pal::uint64 QueryGpuWorkMask() const override { return 0; }
|
||||
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION >= 908
|
||||
virtual void OnTraceAccepted(Pal::uint32 gpuIndex, Pal::ICmdBuffer* pCmdBuf) override;
|
||||
#else
|
||||
virtual void OnTraceAccepted() override;
|
||||
#endif
|
||||
virtual void OnTraceBegin(Pal::uint32 gpuIndex, Pal::ICmdBuffer* pCmdBuf) override { };
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION >= 939
|
||||
virtual void OnPostambleEnd(
|
||||
Pal::uint32 gpuIndex,
|
||||
Pal::ICmdBuffer* pCmdBuf) override;
|
||||
virtual void OnTraceEnd(
|
||||
Pal::uint32 gpuIndex,
|
||||
Pal::ICmdBuffer* pCmdBuf) override {};
|
||||
#else
|
||||
virtual void OnTraceEnd(
|
||||
Pal::uint32 gpuIndex,
|
||||
Pal::ICmdBuffer* pCmdBuf) override;
|
||||
#endif
|
||||
virtual void OnTraceFinished() override;
|
||||
|
||||
virtual const char* GetName() const override { return QueueTimingsTraceSourceName; }
|
||||
virtual Pal::uint32 GetVersion() const override { return QueueTimingsTraceSourceVersion; }
|
||||
|
||||
private:
|
||||
void WriteQueueInfoChunks(
|
||||
const SqttQueueInfoRecord* pQueueInfoRecords,
|
||||
size_t numQueueInfoRecords);
|
||||
|
||||
void WriteQueueEventChunks(
|
||||
const SqttQueueInfoRecord* pQueueInfoRecords,
|
||||
size_t numQueueInfoRecords,
|
||||
const SqttQueueEventRecord* pQueueEventRecords,
|
||||
size_t numQueueEventRecords);
|
||||
|
||||
void ReportInternalError(const char* pErrorMsg, Pal::Result result);
|
||||
|
||||
Pal::IPlatform* const m_pPlatform; // IPlatform owning the parent TraceSession
|
||||
GpaSession* m_pGpaSession; // Handle to GpaSession object for tracking queue timings
|
||||
bool m_traceIsHealthy; // Internal flag for tracking resource and state health
|
||||
std::atomic<bool> m_timingInProgress; // Flag for tracking if queue timings operations are ongoing
|
||||
|
||||
};
|
||||
|
||||
} // namespace GpuUtil
|
||||
/*
|
||||
***********************************************************************************************************************
|
||||
*
|
||||
* Copyright (c) 2024-2025 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
**********************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "palGpuUtil.h"
|
||||
#include "palTraceSession.h"
|
||||
#include "palGpaSession.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
struct SqttQueueEventRecord;
|
||||
struct SqttQueueInfoRecord;
|
||||
|
||||
namespace Pal
|
||||
{
|
||||
class Platform;
|
||||
}
|
||||
|
||||
namespace GpuUtil
|
||||
{
|
||||
namespace TraceChunk
|
||||
{
|
||||
|
||||
/// "QueueInfo" RDF chunk identifier & version
|
||||
constexpr char QueueInfoChunkId[TextIdentifierSize] = "QueueInfo";
|
||||
constexpr Pal::uint32 QueueInfoChunkVersion = 1;
|
||||
|
||||
/// Enum describing logical queue types
|
||||
enum class QueueType : Pal::uint8
|
||||
{
|
||||
Unknown = 0,
|
||||
Universal = 1,
|
||||
Compute = 2,
|
||||
Dma = 3,
|
||||
Encode = 4,
|
||||
Decode = 5,
|
||||
Security = 6,
|
||||
VideoProcessor = 7
|
||||
};
|
||||
|
||||
/// Enum describing hardware engine types
|
||||
enum class HwEngineType : Pal::uint8
|
||||
{
|
||||
Unknown = 0,
|
||||
Universal = 1,
|
||||
Compute = 2,
|
||||
ExclusiveCompute = 3,
|
||||
Dma = 4,
|
||||
Decode = 5,
|
||||
Encode = 6,
|
||||
HighPriorityUniversal = 7,
|
||||
HighPriorityGraphics = 8,
|
||||
Security = 9,
|
||||
Vpe = 10
|
||||
};
|
||||
|
||||
/// Structure describing a queue's properties
|
||||
struct QueueInfo
|
||||
{
|
||||
Pal::uint32 pciId; ///< The ID of the GPU queried
|
||||
Pal::uint64 queueId; ///< API-specific queue ID
|
||||
Pal::uint64 queueContext; ///< OS-level queue context value from Windows KMD to correlate with ETW data.
|
||||
/// Only applicable to D3D on Windows; 0 otherwise.
|
||||
QueueType queueType; ///< The logical queue type
|
||||
HwEngineType engineType; ///< The hardware engine that the queue is mapped to
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------- //
|
||||
|
||||
/// "QueueEvent" RDF chunk identifier & version
|
||||
constexpr char QueueEventChunkId[TextIdentifierSize] = "QueueEvent";
|
||||
constexpr Pal::uint32 QueueEventChunkVersion = 1;
|
||||
|
||||
/// The type of queue-level timings event
|
||||
enum class QueueEventType : Pal::uint32
|
||||
{
|
||||
CmdBufSubmit = 0,
|
||||
SignalSemaphore = 1,
|
||||
WaitSemaphore = 2,
|
||||
Present = 3
|
||||
};
|
||||
|
||||
/// Structure describing a queue-level timings event
|
||||
struct QueueEvent
|
||||
{
|
||||
Pal::uint32 pciId; ///< The ID of the GPU queried
|
||||
Pal::uint64 queueId; ///< The API-specific queue ID which triggered the event
|
||||
QueueEventType eventType; ///< The type of the queue-timing event
|
||||
Pal::uint32 sqttCmdBufId; ///< [`CmdBufSubmit` only; 0 otherwise]
|
||||
/// SQTT command buffer ID matching CmdBufStart user data marker
|
||||
Pal::uint64 frameIndex; ///< [`CmdBufSubmit` & `Present` only; 0 otherwise]
|
||||
/// Global frame index incremented for each "Present" call
|
||||
Pal::uint32 submitSubIndex; ///< [`CmdBufSubmit` only; 0 otherwise]
|
||||
/// Sub-index of event within submission.
|
||||
/// When there is only one CmdBuffer per submission, `submitSubIndex` is 0.
|
||||
/// When there are multiple command buffers per submission, `submitSubIndex`
|
||||
/// is incremented by one for each command buffer within the submission.
|
||||
Pal::uint64 apiEventId; ///< [`CmdBufSubmit`] API-specific command buffer ID signaled
|
||||
/// [`SignalSemaphore`] API-specific semaphore ID signaled
|
||||
/// [`WaitSemaphore`] API-specific semaphore ID waited on
|
||||
/// [`Present`] N/A (set to 0)
|
||||
Pal::uint64 cpuTimestamp; ///< CPU start timestamp of when this event is triggered in clock cycle units
|
||||
Pal::uint64 gpuTimestamp1; ///< [`CmdBufSubmit`] GPU timestamp when the HW execution of command buffer began
|
||||
/// [`SignalSemaphore`] GPU timestamp when the HW signaled the queue semaphore
|
||||
/// [`WaitSemaphore`] GPU timestamp when HW finished waiting on the semaphore
|
||||
/// [`Present`] GPU timestamp when HW processed the Present call
|
||||
///
|
||||
/// All timestamps are expressed in clock cycle units.
|
||||
Pal::uint64 gpuTimestamp2; ///< [`CmdBufSubmit` only; 0 otherwise]
|
||||
/// GPU timestamp when the HW execution of command buffer finished
|
||||
};
|
||||
|
||||
} // namespace TraceChunk
|
||||
|
||||
// QueueTimings Trace Source name & version
|
||||
constexpr char QueueTimingsTraceSourceName[] = "queuetimings";
|
||||
constexpr Pal::uint32 QueueTimingsTraceSourceVersion = 2;
|
||||
|
||||
// =====================================================================================================================
|
||||
// This trace source captures queue timings data through GPA session & produces "QueueInfo" and "QueueEvent" RDF chunks
|
||||
class QueueTimingsTraceSource : public ITraceSource
|
||||
{
|
||||
public:
|
||||
explicit QueueTimingsTraceSource(Pal::IPlatform* pPlatform);
|
||||
virtual ~QueueTimingsTraceSource();
|
||||
|
||||
// ==== TraceSource Native Functions ========================================================================== //
|
||||
Pal::Result Init(Pal::IDevice* pDevice);
|
||||
|
||||
Pal::Result RegisterTimedQueue(Pal::IQueue* pQueue,
|
||||
Pal::uint64 queueId,
|
||||
Pal::uint64 queueContext);
|
||||
|
||||
Pal::Result UnregisterTimedQueue(Pal::IQueue* pQueue);
|
||||
|
||||
Pal::Result TimedSubmit(Pal::IQueue* pQueue,
|
||||
const Pal::MultiSubmitInfo& submitInfo,
|
||||
const TimedSubmitInfo& timedSubmitInfo);
|
||||
|
||||
Pal::Result TimedSignalQueueSemaphore(Pal::IQueue* pQueue,
|
||||
Pal::IQueueSemaphore* pQueueSemaphore,
|
||||
const TimedQueueSemaphoreInfo& timedSignalInfo,
|
||||
Pal::uint64 value = 0);
|
||||
|
||||
Pal::Result TimedWaitQueueSemaphore(Pal::IQueue* pQueue,
|
||||
Pal::IQueueSemaphore* pQueueSemaphore,
|
||||
const TimedQueueSemaphoreInfo& timedWaitInfo,
|
||||
Pal::uint64 value = 0);
|
||||
|
||||
Pal::Result TimedQueuePresent(Pal::IQueue* pQueue,
|
||||
const TimedQueuePresentInfo& timedPresentInfo);
|
||||
|
||||
Pal::Result ExternalTimedWaitQueueSemaphore(Pal::uint64 queueContext,
|
||||
Pal::uint64 cpuSubmissionTimestamp,
|
||||
Pal::uint64 cpuCompletionTimestamp,
|
||||
const TimedQueueSemaphoreInfo& timedWaitInfo);
|
||||
|
||||
Pal::Result ExternalTimedSignalQueueSemaphore(Pal::uint64 queueContext,
|
||||
Pal::uint64 cpuSubmissionTimestamp,
|
||||
Pal::uint64 cpuCompletionTimestamp,
|
||||
const TimedQueueSemaphoreInfo& timedSignalInfo);
|
||||
|
||||
bool IsTimingInProgress() const;
|
||||
|
||||
// ==== Base Class Overrides =================================================================================== //
|
||||
virtual void OnConfigUpdated(DevDriver::StructuredValue* pJsonConfig) override { };
|
||||
|
||||
virtual Pal::uint64 QueryGpuWorkMask() const override { return 0; }
|
||||
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION >= 908
|
||||
virtual void OnTraceAccepted(Pal::uint32 gpuIndex, Pal::ICmdBuffer* pCmdBuf) override;
|
||||
#else
|
||||
virtual void OnTraceAccepted() override;
|
||||
#endif
|
||||
virtual void OnTraceBegin(Pal::uint32 gpuIndex, Pal::ICmdBuffer* pCmdBuf) override { };
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION >= 939
|
||||
virtual void OnPostambleEnd(
|
||||
Pal::uint32 gpuIndex,
|
||||
Pal::ICmdBuffer* pCmdBuf) override;
|
||||
virtual void OnTraceEnd(
|
||||
Pal::uint32 gpuIndex,
|
||||
Pal::ICmdBuffer* pCmdBuf) override {};
|
||||
#else
|
||||
virtual void OnTraceEnd(
|
||||
Pal::uint32 gpuIndex,
|
||||
Pal::ICmdBuffer* pCmdBuf) override;
|
||||
#endif
|
||||
virtual void OnTraceFinished() override;
|
||||
|
||||
virtual const char* GetName() const override { return QueueTimingsTraceSourceName; }
|
||||
virtual Pal::uint32 GetVersion() const override { return QueueTimingsTraceSourceVersion; }
|
||||
|
||||
private:
|
||||
void WriteQueueInfoChunks(
|
||||
const SqttQueueInfoRecord* pQueueInfoRecords,
|
||||
size_t numQueueInfoRecords);
|
||||
|
||||
void WriteQueueEventChunks(
|
||||
const SqttQueueInfoRecord* pQueueInfoRecords,
|
||||
size_t numQueueInfoRecords,
|
||||
const SqttQueueEventRecord* pQueueEventRecords,
|
||||
size_t numQueueEventRecords);
|
||||
|
||||
void ReportInternalError(const char* pErrorMsg, Pal::Result result);
|
||||
|
||||
Pal::IPlatform* const m_pPlatform; // IPlatform owning the parent TraceSession
|
||||
GpaSession* m_pGpaSession; // Handle to GpaSession object for tracking queue timings
|
||||
bool m_traceIsHealthy; // Internal flag for tracking resource and state health
|
||||
std::atomic<bool> m_timingInProgress; // Flag for tracking if queue timings operations are ongoing
|
||||
|
||||
};
|
||||
|
||||
} // namespace GpuUtil
|
||||
|
||||
@@ -1,155 +1,150 @@
|
||||
/*
|
||||
***********************************************************************************************************************
|
||||
*
|
||||
* Copyright (c) 2024-2025 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
**********************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "palTraceSession.h"
|
||||
|
||||
namespace Pal
|
||||
{
|
||||
class IPlatform;
|
||||
class IQueue;
|
||||
class ICmdBuffer;
|
||||
class Device;
|
||||
}
|
||||
|
||||
namespace GpuUtil
|
||||
{
|
||||
|
||||
/// Supported render operations used to advance the trace
|
||||
enum RenderOp : Pal::uint8
|
||||
{
|
||||
RenderOpDraw = (1u << 0),
|
||||
RenderOpDispatch = (1u << 1)
|
||||
};
|
||||
|
||||
/// Structure used to batch submit render operations on queue submission
|
||||
/// This struct should have a `*Count` field for each @ref RenderOp enumeration above
|
||||
struct RenderOpCounts
|
||||
{
|
||||
Pal::uint32 drawCount;
|
||||
Pal::uint32 dispatchCount;
|
||||
};
|
||||
|
||||
constexpr Pal::uint32 RenderOpTraceControllerVersion = 4;
|
||||
constexpr char RenderOpTraceControllerName[] = "renderop";
|
||||
|
||||
// =====================================================================================================================
|
||||
class RenderOpTraceController : public ITraceController
|
||||
{
|
||||
public:
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION < 896
|
||||
using RenderOp = GpuUtil::RenderOp;
|
||||
#endif
|
||||
RenderOpTraceController(Pal::IPlatform* pPlatform, Pal::IDevice* pDevice);
|
||||
virtual ~RenderOpTraceController();
|
||||
|
||||
virtual const char* GetName() const override { return RenderOpTraceControllerName; }
|
||||
virtual Pal::uint32 GetVersion() const override { return RenderOpTraceControllerVersion; }
|
||||
|
||||
virtual void OnConfigUpdated(DevDriver::StructuredValue* pJsonConfig) override;
|
||||
virtual Pal::Result OnTraceRequested() override;
|
||||
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION >= 908
|
||||
virtual Pal::Result OnPreparationGpuWork(Pal::uint32 gpuIndex, Pal::ICmdBuffer** ppCmdBuf) override;
|
||||
#endif
|
||||
virtual Pal::Result OnBeginGpuWork(Pal::uint32 gpuIndex, Pal::ICmdBuffer** ppCmdBuffer) override;
|
||||
virtual Pal::Result OnEndGpuWork(Pal::uint32 gpuIndex, Pal::ICmdBuffer** ppCmdBuffer) override;
|
||||
virtual Pal::Result OnEndPostambleGpuWork(
|
||||
Pal::uint32 gpuIndex,
|
||||
Pal::ICmdBuffer** ppCmdBuffer) override;
|
||||
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION < 896
|
||||
void RecordRenderOp(Pal::IQueue* pQueue, RenderOp renderOp);
|
||||
#endif
|
||||
|
||||
void FinishTrace();
|
||||
|
||||
// Cancel the trace currently in progress.
|
||||
virtual Pal::Result OnTraceCanceled() override;
|
||||
|
||||
/// This function must be called by client drivers implementing the RenderOp controller.
|
||||
/// On every queue submission, this function is called with the cumulative counts of render operations
|
||||
/// recorded into that queue's command buffers.
|
||||
/// Based on the controller's internal mask, set by the user during trace configuration,
|
||||
/// the trace controller may advance its state.
|
||||
void RecordRenderOps(Pal::IQueue* pQueue, const RenderOpCounts& renderOpCounts);
|
||||
|
||||
// Force a controller update
|
||||
virtual void OnUpdated() override { OnRenderOpUpdated(0); }
|
||||
|
||||
virtual Pal::IQueue* GetTraceQueue() const override { return m_pQueue; }
|
||||
|
||||
private:
|
||||
/// Controls whether the trace proceeds on absolute render op counts or relative
|
||||
enum class CaptureMode : Pal::uint8
|
||||
{
|
||||
Relative = 0, ///< Relative to when the trace request is received
|
||||
Absolute ///< Absolute render op index
|
||||
};
|
||||
|
||||
Pal::Result AcceptTrace();
|
||||
Pal::Result BeginTrace();
|
||||
|
||||
Pal::Result SubmitBeginTraceGpuWork() const;
|
||||
Pal::Result SubmitEndTraceGpuWork();
|
||||
Pal::Result SubmitEndPostambleGpuWork();
|
||||
|
||||
Pal::Result WaitForTraceEndGpuWorkCompletion() const;
|
||||
Pal::Result CreateFence(Pal::IFence** ppFence) const;
|
||||
Pal::Result CreateCommandBuffer(bool traceEnd, Pal::ICmdBuffer** ppCmdBuf) const;
|
||||
Pal::Result CreateCmdAllocator();
|
||||
|
||||
void OnRenderOpUpdated(Pal::uint64 countRecorded);
|
||||
void FreeResources();
|
||||
void AbortTrace();
|
||||
|
||||
Pal::IPlatform* const m_pPlatform; // Platform associated with this TraceController
|
||||
Pal::IDevice* m_pDevice; // Device associated with this TraceController
|
||||
Pal::ICmdAllocator* m_pCmdAllocator; // Command allocator for the TraceController
|
||||
|
||||
TraceSession* m_pTraceSession; // TraceSession owning this TraceController
|
||||
Pal::uint64 m_supportedGpuMask; // Bit mask of GPU indices that are capable of participating in the trace
|
||||
Pal::uint8 m_renderOpMask; // Bitmask of RenderOp modes, indicating which are accepted
|
||||
CaptureMode m_captureMode; // Modality for determining the starting renderop index of the trace
|
||||
Pal::uint64 m_renderOpCount; // The "global" count, incremented on every render op
|
||||
Pal::uint64 m_prepStartRenderOp; // Relative or absolute render op number indicating trace begin
|
||||
Pal::uint64 m_numPrepRenderOps; // Number of "warm-up" frames before the start frame
|
||||
Pal::uint64 m_captureRenderOpCount; // Number of frames to wait before ending the trace
|
||||
Pal::uint64 m_renderOpTraceAccepted; // The frame number when the trace was accepted
|
||||
|
||||
Util::Mutex m_renderOpLock; // Lock over UpdateFrame/OnFrameUpdated
|
||||
Pal::IQueue* m_pQueue; // The queue being used to submit Begin/End GPU trace command buffers
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION >= 908
|
||||
Pal::ICmdBuffer* m_pCmdBufTracePrepare; // Command buffer for recording during the prep phase
|
||||
#endif
|
||||
Pal::ICmdBuffer* m_pCmdBufTraceBegin; // Command buffer to submit Trace Begin
|
||||
Pal::ICmdBuffer* m_pCmdBufTraceEnd; // Command buffer to submit Trace End
|
||||
Pal::ICmdBuffer* m_pCmdBufPostambleEnd; // Command buffer to submit Postamble End
|
||||
Pal::IFence* m_pFenceTraceEnd; // Fence to wait for Trace End command buffer completion
|
||||
Pal::IFence* m_pFencePostambleEnd; // Fence to wait for Postamble End command buffer completion
|
||||
};
|
||||
|
||||
} // namespace GpuUtil
|
||||
/*
|
||||
***********************************************************************************************************************
|
||||
*
|
||||
* Copyright (c) 2024-2025 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
**********************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "palTraceSession.h"
|
||||
|
||||
namespace Pal
|
||||
{
|
||||
class IPlatform;
|
||||
class IQueue;
|
||||
class ICmdBuffer;
|
||||
class Device;
|
||||
}
|
||||
|
||||
namespace GpuUtil
|
||||
{
|
||||
|
||||
/// Supported render operations used to advance the trace
|
||||
enum RenderOp : Pal::uint8
|
||||
{
|
||||
RenderOpDraw = (1u << 0),
|
||||
RenderOpDispatch = (1u << 1)
|
||||
};
|
||||
|
||||
/// Structure used to batch submit render operations on queue submission
|
||||
/// This struct should have a `*Count` field for each @ref RenderOp enumeration above
|
||||
struct RenderOpCounts
|
||||
{
|
||||
Pal::uint32 drawCount;
|
||||
Pal::uint32 dispatchCount;
|
||||
};
|
||||
|
||||
constexpr Pal::uint32 RenderOpTraceControllerVersion = 4;
|
||||
constexpr char RenderOpTraceControllerName[] = "renderop";
|
||||
|
||||
// =====================================================================================================================
|
||||
class RenderOpTraceController : public ITraceController
|
||||
{
|
||||
public:
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION < 896
|
||||
using RenderOp = GpuUtil::RenderOp;
|
||||
#endif
|
||||
RenderOpTraceController(Pal::IPlatform* pPlatform, Pal::IDevice* pDevice);
|
||||
virtual ~RenderOpTraceController();
|
||||
|
||||
virtual const char* GetName() const override { return RenderOpTraceControllerName; }
|
||||
virtual Pal::uint32 GetVersion() const override { return RenderOpTraceControllerVersion; }
|
||||
|
||||
virtual void OnConfigUpdated(DevDriver::StructuredValue* pJsonConfig) override;
|
||||
virtual Pal::Result OnTraceRequested() override;
|
||||
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION >= 908
|
||||
virtual Pal::Result OnPreparationGpuWork(Pal::uint32 gpuIndex, Pal::ICmdBuffer** ppCmdBuf) override;
|
||||
#endif
|
||||
virtual Pal::Result OnBeginGpuWork(Pal::uint32 gpuIndex, Pal::ICmdBuffer** ppCmdBuffer) override;
|
||||
virtual Pal::Result OnEndGpuWork(Pal::uint32 gpuIndex, Pal::ICmdBuffer** ppCmdBuffer) override;
|
||||
virtual Pal::Result OnEndPostambleGpuWork(
|
||||
Pal::uint32 gpuIndex,
|
||||
Pal::ICmdBuffer** ppCmdBuffer) override;
|
||||
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION < 896
|
||||
void RecordRenderOp(Pal::IQueue* pQueue, RenderOp renderOp);
|
||||
#endif
|
||||
|
||||
void FinishTrace();
|
||||
|
||||
// Cancel the trace currently in progress.
|
||||
virtual Pal::Result OnTraceCanceled() override;
|
||||
|
||||
/// This function must be called by client drivers implementing the RenderOp controller.
|
||||
/// On every queue submission, this function is called with the cumulative counts of render operations
|
||||
/// recorded into that queue's command buffers.
|
||||
/// Based on the controller's internal mask, set by the user during trace configuration,
|
||||
/// the trace controller may advance its state.
|
||||
void RecordRenderOps(Pal::IQueue* pQueue, const RenderOpCounts& renderOpCounts);
|
||||
|
||||
private:
|
||||
/// Controls whether the trace proceeds on absolute render op counts or relative
|
||||
enum class CaptureMode : Pal::uint8
|
||||
{
|
||||
Relative = 0, ///< Relative to when the trace request is received
|
||||
Absolute ///< Absolute render op index
|
||||
};
|
||||
|
||||
Pal::Result AcceptTrace();
|
||||
Pal::Result BeginTrace();
|
||||
|
||||
Pal::Result SubmitBeginTraceGpuWork() const;
|
||||
Pal::Result SubmitEndTraceGpuWork();
|
||||
Pal::Result SubmitEndPostambleGpuWork();
|
||||
|
||||
Pal::Result WaitForTraceEndGpuWorkCompletion() const;
|
||||
Pal::Result CreateFence(Pal::IFence** ppFence) const;
|
||||
Pal::Result CreateCommandBuffer(bool traceEnd, Pal::ICmdBuffer** ppCmdBuf) const;
|
||||
Pal::Result CreateCmdAllocator();
|
||||
|
||||
void OnRenderOpUpdated(Pal::uint64 countRecorded);
|
||||
void FreeResources();
|
||||
void AbortTrace();
|
||||
|
||||
Pal::IPlatform* const m_pPlatform; // Platform associated with this TraceController
|
||||
Pal::IDevice* m_pDevice; // Device associated with this TraceController
|
||||
Pal::ICmdAllocator* m_pCmdAllocator; // Command allocator for the TraceController
|
||||
|
||||
TraceSession* m_pTraceSession; // TraceSession owning this TraceController
|
||||
Pal::uint64 m_supportedGpuMask; // Bit mask of GPU indices that are capable of participating in the trace
|
||||
Pal::uint8 m_renderOpMask; // Bitmask of RenderOp modes, indicating which are accepted
|
||||
CaptureMode m_captureMode; // Modality for determining the starting renderop index of the trace
|
||||
Pal::uint64 m_renderOpCount; // The "global" count, incremented on every render op
|
||||
Pal::uint64 m_prepStartRenderOp; // Relative or absolute render op number indicating trace begin
|
||||
Pal::uint64 m_numPrepRenderOps; // Number of "warm-up" frames before the start frame
|
||||
Pal::uint64 m_captureRenderOpCount; // Number of frames to wait before ending the trace
|
||||
Pal::uint64 m_renderOpTraceAccepted; // The frame number when the trace was accepted
|
||||
|
||||
Util::Mutex m_renderOpLock; // Lock over UpdateFrame/OnFrameUpdated
|
||||
Pal::IQueue* m_pQueue; // The queue being used to submit Begin/End GPU trace command buffers
|
||||
#if PAL_CLIENT_INTERFACE_MAJOR_VERSION >= 908
|
||||
Pal::ICmdBuffer* m_pCmdBufTracePrepare; // Command buffer for recording during the prep phase
|
||||
#endif
|
||||
Pal::ICmdBuffer* m_pCmdBufTraceBegin; // Command buffer to submit Trace Begin
|
||||
Pal::ICmdBuffer* m_pCmdBufTraceEnd; // Command buffer to submit Trace End
|
||||
Pal::ICmdBuffer* m_pCmdBufPostambleEnd; // Command buffer to submit Postamble End
|
||||
Pal::IFence* m_pFenceTraceEnd; // Fence to wait for Trace End command buffer completion
|
||||
Pal::IFence* m_pFencePostambleEnd; // Fence to wait for Postamble End command buffer completion
|
||||
};
|
||||
|
||||
} // namespace GpuUtil
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user