Get timestamp period from device

- Get timestamp period on each backend
  D3D12: Get GPU frequency(HZ) from queue and calculate the period in ns
  Vulkan: Get timestampPeriod from device properties
  Metal and others: don't need the period

Bug: dawn:434
Change-Id: Ia5588a3dccadfe92d7384b9fdf1e6848c6e5c6e2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/36220
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Hao Li <hao.x.li@intel.com>
This commit is contained in:
Hao Li 2021-01-05 02:39:18 +00:00 committed by Commit Bot service account
parent 4110684aa0
commit cdbd295cc6
11 changed files with 44 additions and 0 deletions

View File

@ -249,6 +249,8 @@ namespace dawn_native {
virtual uint32_t GetOptimalBytesPerRowAlignment() const = 0;
virtual uint64_t GetOptimalBufferToTextureCopyOffsetAlignment() const = 0;
virtual float GetTimestampPeriodInNS() const = 0;
protected:
void SetToggle(Toggle toggle, bool isEnabled);
void ForceSetToggle(Toggle toggle, bool isEnabled);

View File

@ -77,6 +77,15 @@ namespace dawn_native { namespace d3d12 {
CheckHRESULT(mD3d12Device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&mCommandQueue)),
"D3D12 create command queue"));
// Get GPU timestamp counter frequency (in ticks/second). This fails if the specified
// command queue doesn't support timestamps, D3D12_COMMAND_LIST_TYPE_DIRECT always support
// timestamps.
uint64_t frequency;
DAWN_TRY(CheckHRESULT(mCommandQueue->GetTimestampFrequency(&frequency),
"D3D12 get timestamp frequency"));
// Calculate the period in nanoseconds by the frequency.
mTimestampPeriod = static_cast<float>(1e9) / frequency;
// If PIX is not attached, the QueryInterface fails. Hence, no need to check the return
// value.
mCommandQueue.As(&mD3d12SharingContract);
@ -655,4 +664,8 @@ namespace dawn_native { namespace d3d12 {
return 1;
}
float Device::GetTimestampPeriodInNS() const {
return mTimestampPeriod;
}
}} // namespace dawn_native::d3d12

View File

@ -141,6 +141,8 @@ namespace dawn_native { namespace d3d12 {
uint32_t GetOptimalBytesPerRowAlignment() const override;
uint64_t GetOptimalBufferToTextureCopyOffsetAlignment() const override;
float GetTimestampPeriodInNS() const override;
private:
using DeviceBase::DeviceBase;
@ -236,6 +238,9 @@ namespace dawn_native { namespace d3d12 {
// Sampler cache needs to be destroyed before the CPU sampler allocator to ensure the final
// release is called.
std::unique_ptr<SamplerHeapCache> mSamplerHeapCache;
// The number of nanoseconds required for a timestamp query to be incremented by 1
float mTimestampPeriod = 1.0f;
};
}} // namespace dawn_native::d3d12

View File

@ -71,6 +71,8 @@ namespace dawn_native { namespace metal {
uint32_t GetOptimalBytesPerRowAlignment() const override;
uint64_t GetOptimalBufferToTextureCopyOffsetAlignment() const override;
float GetTimestampPeriodInNS() const override;
private:
Device(AdapterBase* adapter,
NSPRef<id<MTLDevice>> mtlDevice,

View File

@ -402,4 +402,8 @@ namespace dawn_native { namespace metal {
return 1;
}
float Device::GetTimestampPeriodInNS() const {
return 1.0f;
}
}} // namespace dawn_native::metal

View File

@ -470,4 +470,8 @@ namespace dawn_native { namespace null {
return 1;
}
float Device::GetTimestampPeriodInNS() const {
return 1.0f;
}
}} // namespace dawn_native::null

View File

@ -116,6 +116,8 @@ namespace dawn_native { namespace null {
uint32_t GetOptimalBytesPerRowAlignment() const override;
uint64_t GetOptimalBufferToTextureCopyOffsetAlignment() const override;
float GetTimestampPeriodInNS() const override;
private:
using DeviceBase::DeviceBase;

View File

@ -228,4 +228,8 @@ namespace dawn_native { namespace opengl {
return 1;
}
float Device::GetTimestampPeriodInNS() const {
return 1.0f;
}
}} // namespace dawn_native::opengl

View File

@ -70,6 +70,8 @@ namespace dawn_native { namespace opengl {
uint32_t GetOptimalBytesPerRowAlignment() const override;
uint64_t GetOptimalBufferToTextureCopyOffsetAlignment() const override;
float GetTimestampPeriodInNS() const override;
private:
Device(AdapterBase* adapter,
const DeviceDescriptor* descriptor,

View File

@ -945,4 +945,8 @@ namespace dawn_native { namespace vulkan {
return mDeviceInfo.properties.limits.optimalBufferCopyOffsetAlignment;
}
float Device::GetTimestampPeriodInNS() const {
return mDeviceInfo.properties.limits.timestampPeriod;
}
}} // namespace dawn_native::vulkan

View File

@ -108,6 +108,8 @@ namespace dawn_native { namespace vulkan {
uint32_t GetOptimalBytesPerRowAlignment() const override;
uint64_t GetOptimalBufferToTextureCopyOffsetAlignment() const override;
float GetTimestampPeriodInNS() const override;
private:
Device(Adapter* adapter, const DeviceDescriptor* descriptor);