1 // Copyright 2023 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expresso or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "BufferVk.h"
16 
17 #include "VkCommonOperations.h"
18 
19 namespace gfxstream {
20 namespace vk {
21 
22 /*static*/
create(uint32_t handle,uint64_t size,bool vulkanOnly)23 std::unique_ptr<BufferVk> BufferVk::create(uint32_t handle, uint64_t size, bool vulkanOnly) {
24     if (!setupVkBuffer(size, handle, vulkanOnly, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) {
25         ERR("Failed to create BufferVk:%d", handle);
26         return nullptr;
27     }
28 
29     return std::unique_ptr<BufferVk>(new BufferVk(handle));
30 }
31 
BufferVk(uint32_t handle)32 BufferVk::BufferVk(uint32_t handle) : mHandle(handle) {}
33 
~BufferVk()34 BufferVk::~BufferVk() {
35     if (!teardownVkBuffer(mHandle)) {
36         ERR("Failed to destroy BufferVk:%d", mHandle);
37     }
38 }
39 
readToBytes(uint64_t offset,uint64_t size,void * outBytes)40 void BufferVk::readToBytes(uint64_t offset, uint64_t size, void* outBytes) {
41     readBufferToBytes(mHandle, offset, size, outBytes);
42 }
43 
updateFromBytes(uint64_t offset,uint64_t size,const void * bytes)44 bool BufferVk::updateFromBytes(uint64_t offset, uint64_t size, const void* bytes) {
45     return updateBufferFromBytes(mHandle, offset, size, bytes);
46 }
47 
48 }  // namespace vk
49 }  // namespace gfxstream