1e5c31af7Sopenharmony_ci#ifndef _VKTBITSTREAMBUFFERIMPL_HPP 2e5c31af7Sopenharmony_ci#define _VKTBITSTREAMBUFFERIMPL_HPP 3e5c31af7Sopenharmony_ci/*------------------------------------------------------------------------ 4e5c31af7Sopenharmony_ci * Vulkan Conformance Tests 5e5c31af7Sopenharmony_ci * ------------------------ 6e5c31af7Sopenharmony_ci * 7e5c31af7Sopenharmony_ci * Copyright (c) 2023 The Khronos Group Inc. 8e5c31af7Sopenharmony_ci * 9e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 10e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License. 11e5c31af7Sopenharmony_ci * You may obtain a copy of the License at 12e5c31af7Sopenharmony_ci * 13e5c31af7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 14e5c31af7Sopenharmony_ci * 15e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 16e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 17e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and 19e5c31af7Sopenharmony_ci * limitations under the License. 20e5c31af7Sopenharmony_ci * 21e5c31af7Sopenharmony_ci *//*! 22e5c31af7Sopenharmony_ci * \file 23e5c31af7Sopenharmony_ci * \brief Bitstream buffer implementation for the CTS. 24e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 25e5c31af7Sopenharmony_ci/* 26e5c31af7Sopenharmony_ci* Copyright 2023 NVIDIA Corporation. 27e5c31af7Sopenharmony_ci* 28e5c31af7Sopenharmony_ci* Licensed under the Apache License, Version 2.0 (the "License"); 29e5c31af7Sopenharmony_ci* you may not use this file except in compliance with the License. 30e5c31af7Sopenharmony_ci* You may obtain a copy of the License at 31e5c31af7Sopenharmony_ci* 32e5c31af7Sopenharmony_ci* http://www.apache.org/licenses/LICENSE-2.0 33e5c31af7Sopenharmony_ci* 34e5c31af7Sopenharmony_ci* Unless required by applicable law or agreed to in writing, software 35e5c31af7Sopenharmony_ci* distributed under the License is distributed on an "AS IS" BASIS, 36e5c31af7Sopenharmony_ci* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 37e5c31af7Sopenharmony_ci* See the License for the specific language governing permissions and 38e5c31af7Sopenharmony_ci* limitations under the License. 39e5c31af7Sopenharmony_ci*/ 40e5c31af7Sopenharmony_ci 41e5c31af7Sopenharmony_ci#include <atomic> 42e5c31af7Sopenharmony_ci#include <iostream> 43e5c31af7Sopenharmony_ci#include <vector> 44e5c31af7Sopenharmony_ci 45e5c31af7Sopenharmony_ci#include "vktVideoTestUtils.hpp" 46e5c31af7Sopenharmony_ci 47e5c31af7Sopenharmony_cinamespace vkt 48e5c31af7Sopenharmony_ci{ 49e5c31af7Sopenharmony_cinamespace video 50e5c31af7Sopenharmony_ci{ 51e5c31af7Sopenharmony_ci 52e5c31af7Sopenharmony_ciusing BufferPtr = de::MovePtr<BufferWithMemory>; 53e5c31af7Sopenharmony_ci 54e5c31af7Sopenharmony_ci// This class is required by the NVIDIA sample decoder interface. 55e5c31af7Sopenharmony_ci// The following is a CTS implementation of the VulkanBitstreamBuffer interface upstream. 56e5c31af7Sopenharmony_ciclass BitstreamBufferImpl : public VulkanBitstreamBuffer 57e5c31af7Sopenharmony_ci{ 58e5c31af7Sopenharmony_cipublic: 59e5c31af7Sopenharmony_ci static VkResult Create(DeviceContext* devctx, deUint32 queueFamilyIndex, 60e5c31af7Sopenharmony_ci VkDeviceSize bufferSize, VkDeviceSize bufferOffsetAlignment, VkDeviceSize bufferSizeAlignment, 61e5c31af7Sopenharmony_ci VkSharedBaseObj<BitstreamBufferImpl>& vulkanBitstreamBuffer, 62e5c31af7Sopenharmony_ci const VkVideoProfileListInfoKHR* profileList); 63e5c31af7Sopenharmony_ci 64e5c31af7Sopenharmony_ci int32_t AddRef() override 65e5c31af7Sopenharmony_ci { 66e5c31af7Sopenharmony_ci return ++m_refCount; 67e5c31af7Sopenharmony_ci } 68e5c31af7Sopenharmony_ci 69e5c31af7Sopenharmony_ci int32_t Release() override 70e5c31af7Sopenharmony_ci { 71e5c31af7Sopenharmony_ci DE_ASSERT(m_refCount > 0); 72e5c31af7Sopenharmony_ci deUint32 ret = --m_refCount; 73e5c31af7Sopenharmony_ci if (ret == 0) { 74e5c31af7Sopenharmony_ci delete this; 75e5c31af7Sopenharmony_ci } 76e5c31af7Sopenharmony_ci return ret; 77e5c31af7Sopenharmony_ci } 78e5c31af7Sopenharmony_ci 79e5c31af7Sopenharmony_ci int32_t GetRefCount() override 80e5c31af7Sopenharmony_ci { 81e5c31af7Sopenharmony_ci DE_ASSERT(m_refCount > 0); 82e5c31af7Sopenharmony_ci return m_refCount; 83e5c31af7Sopenharmony_ci } 84e5c31af7Sopenharmony_ci 85e5c31af7Sopenharmony_ci VkDeviceSize GetMaxSize() const override; 86e5c31af7Sopenharmony_ci VkDeviceSize GetOffsetAlignment() const override; 87e5c31af7Sopenharmony_ci VkDeviceSize GetSizeAlignment() const override; 88e5c31af7Sopenharmony_ci VkDeviceSize Resize(VkDeviceSize newSize, VkDeviceSize copySize = 0, VkDeviceSize copyOffset = 0) override; 89e5c31af7Sopenharmony_ci VkDeviceSize Clone(VkDeviceSize newSize, VkDeviceSize copySize, VkDeviceSize copyOffset, VkSharedBaseObj<VulkanBitstreamBuffer>& vulkanBitstreamBuffer) override; 90e5c31af7Sopenharmony_ci 91e5c31af7Sopenharmony_ci int64_t MemsetData(deUint32 value, VkDeviceSize offset, VkDeviceSize size) override; 92e5c31af7Sopenharmony_ci int64_t CopyDataToBuffer(deUint8 *dstBuffer, VkDeviceSize dstOffset, 93e5c31af7Sopenharmony_ci VkDeviceSize srcOffset, VkDeviceSize size) const override; 94e5c31af7Sopenharmony_ci int64_t CopyDataToBuffer(VkSharedBaseObj<VulkanBitstreamBuffer>& dstBuffer, VkDeviceSize dstOffset, 95e5c31af7Sopenharmony_ci VkDeviceSize srcOffset, VkDeviceSize size) const override; 96e5c31af7Sopenharmony_ci int64_t CopyDataFromBuffer(const deUint8 *sourceBuffer, VkDeviceSize srcOffset, 97e5c31af7Sopenharmony_ci VkDeviceSize dstOffset, VkDeviceSize size) override; 98e5c31af7Sopenharmony_ci int64_t CopyDataFromBuffer(const VkSharedBaseObj<VulkanBitstreamBuffer>& sourceBuffer, VkDeviceSize srcOffset, 99e5c31af7Sopenharmony_ci VkDeviceSize dstOffset, VkDeviceSize size) override; 100e5c31af7Sopenharmony_ci deUint8* GetDataPtr(VkDeviceSize offset, VkDeviceSize &maxSize) override; 101e5c31af7Sopenharmony_ci const deUint8* GetReadOnlyDataPtr(VkDeviceSize offset, VkDeviceSize &maxSize) const override; 102e5c31af7Sopenharmony_ci 103e5c31af7Sopenharmony_ci void FlushRange(VkDeviceSize offset, VkDeviceSize size) const override; 104e5c31af7Sopenharmony_ci void InvalidateRange(VkDeviceSize offset, VkDeviceSize size) const override; 105e5c31af7Sopenharmony_ci 106e5c31af7Sopenharmony_ci VkBuffer GetBuffer() const override { return m_bitstreamBuffer->get(); } 107e5c31af7Sopenharmony_ci VkDeviceMemory GetDeviceMemory() const override { return m_bitstreamBuffer->getAllocation().getMemory(); } 108e5c31af7Sopenharmony_ci 109e5c31af7Sopenharmony_ci deUint32 AddStreamMarker(deUint32 streamOffset) override; 110e5c31af7Sopenharmony_ci deUint32 SetStreamMarker(deUint32 streamOffset, deUint32 index) override; 111e5c31af7Sopenharmony_ci deUint32 GetStreamMarker(deUint32 index) const override; 112e5c31af7Sopenharmony_ci deUint32 GetStreamMarkersCount() const override; 113e5c31af7Sopenharmony_ci const deUint32* GetStreamMarkersPtr(deUint32 startIndex, deUint32& maxCount) const override; 114e5c31af7Sopenharmony_ci deUint32 ResetStreamMarkers() override; 115e5c31af7Sopenharmony_ci 116e5c31af7Sopenharmony_ci operator VkDeviceMemory() { return GetDeviceMemory(); } 117e5c31af7Sopenharmony_ci operator bool() { return !!m_bitstreamBuffer; } 118e5c31af7Sopenharmony_ci 119e5c31af7Sopenharmony_ci VkResult CopyDataToBuffer(const deUint8* pData, VkDeviceSize size, 120e5c31af7Sopenharmony_ci VkDeviceSize &dstBufferOffset) const; 121e5c31af7Sopenharmony_ci 122e5c31af7Sopenharmony_ciprivate: 123e5c31af7Sopenharmony_ci 124e5c31af7Sopenharmony_ci VkResult CreateBuffer(DeviceContext* ctx, deUint32 queueFamilyIndex, 125e5c31af7Sopenharmony_ci VkDeviceSize& bufferSize, 126e5c31af7Sopenharmony_ci VkDeviceSize bufferSizeAlignment, 127e5c31af7Sopenharmony_ci const VkVideoProfileListInfoKHR* profileList); 128e5c31af7Sopenharmony_ci 129e5c31af7Sopenharmony_ci deUint8* CheckAccess(VkDeviceSize offset, VkDeviceSize size) const; 130e5c31af7Sopenharmony_ci 131e5c31af7Sopenharmony_ci VkResult Initialize(VkDeviceSize bufferSize); 132e5c31af7Sopenharmony_ci 133e5c31af7Sopenharmony_ci BitstreamBufferImpl(DeviceContext* devctx, 134e5c31af7Sopenharmony_ci deUint32 queueFamilyIndex, 135e5c31af7Sopenharmony_ci VkDeviceSize bufferOffsetAlignment, 136e5c31af7Sopenharmony_ci VkDeviceSize bufferSizeAlignment, 137e5c31af7Sopenharmony_ci const VkVideoProfileListInfoKHR* profileList) 138e5c31af7Sopenharmony_ci : VulkanBitstreamBuffer() 139e5c31af7Sopenharmony_ci , m_refCount(0) 140e5c31af7Sopenharmony_ci , m_devctx(devctx) 141e5c31af7Sopenharmony_ci , m_profileList(profileList) 142e5c31af7Sopenharmony_ci , m_queueFamilyIndex(queueFamilyIndex) 143e5c31af7Sopenharmony_ci , m_bufferOffsetAlignment(bufferOffsetAlignment) 144e5c31af7Sopenharmony_ci , m_bufferSizeAlignment(bufferSizeAlignment) 145e5c31af7Sopenharmony_ci , m_bufferSize(0) 146e5c31af7Sopenharmony_ci , m_streamMarkers(256) { } 147e5c31af7Sopenharmony_ci 148e5c31af7Sopenharmony_ci 149e5c31af7Sopenharmony_ciprivate: 150e5c31af7Sopenharmony_ci std::atomic<int32_t> m_refCount; 151e5c31af7Sopenharmony_ci DeviceContext* m_devctx; 152e5c31af7Sopenharmony_ci const VkVideoProfileListInfoKHR* m_profileList; 153e5c31af7Sopenharmony_ci deUint32 m_queueFamilyIndex; 154e5c31af7Sopenharmony_ci VkDeviceSize m_bufferOffsetAlignment; 155e5c31af7Sopenharmony_ci VkDeviceSize m_bufferSizeAlignment; 156e5c31af7Sopenharmony_ci BufferPtr m_bitstreamBuffer; 157e5c31af7Sopenharmony_ci VkDeviceSize m_bufferSize; 158e5c31af7Sopenharmony_ci std::vector<deUint32> m_streamMarkers; 159e5c31af7Sopenharmony_ci}; 160e5c31af7Sopenharmony_ci 161e5c31af7Sopenharmony_ci} // video 162e5c31af7Sopenharmony_ci} // vkt 163e5c31af7Sopenharmony_ci 164e5c31af7Sopenharmony_ci#endif // _VKTBITSTREAMBUFFERIMPL_HPP 165