• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 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 express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #pragma once
15 
16 #include "compressedTextureFormats/AstcCpuDecompressor.h"
17 #include "stream-servers/vulkan/VkDecoderContext.h"
18 #include "vulkan/cereal/common/goldfish_vk_dispatch.h"
19 #include "vulkan/vulkan.h"
20 
21 namespace gfxstream {
22 namespace vk {
23 
24 // Holds the resources necessary to perform CPU ASTC decompression of a single texture.
25 class AstcTexture {
26    public:
27     AstcTexture(VulkanDispatch* vk, VkDevice device, VkPhysicalDevice physicalDevice,
28                 VkExtent3D imgSize, uint32_t blockWidth, uint32_t blockHeight,
29                 AstcCpuDecompressor* decompressor);
30 
31     ~AstcTexture();
32 
33     // Whether we're able to decompress ASTC textures on the CPU
34     bool canDecompressOnCpu() const;
35 
36     // Whether this texture was successfully decompressed on the CPU
successfullyDecompressed()37     bool successfullyDecompressed() const { return mSuccess; }
38 
39     void on_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, uint8_t* srcAstcData,
40                                    size_t astcDataSize, VkImage dstImage,
41                                    VkImageLayout dstImageLayout, uint32_t regionCount,
42                                    const VkBufferImageCopy* pRegions,
43                                    const VkDecoderContext& context);
44 
45    private:
46     uint8_t* createVkBufferAndMapMemory(size_t bufferSize);
47     void destroyVkBuffer();
48 
49     bool mSuccess = false;  // true if the image was successfully decompressed
50     VulkanDispatch* mVk;
51     VkDevice mDevice;
52     VkPhysicalDevice mPhysicalDevice;
53     VkExtent3D mImgSize;
54     uint32_t mBlockWidth;
55     uint32_t mBlockHeight;
56     VkBuffer mDecompBuffer = VK_NULL_HANDLE;              // VkBuffer of the decompressed image
57     VkDeviceMemory mDecompBufferMemory = VK_NULL_HANDLE;  // Memory of the decompressed image
58     uint64_t mBufferSize = 0;                             // Size of the decompressed image
59     AstcCpuDecompressor* mDecompressor;
60 };
61 
62 }  // namespace vk
63 }  // namespace gfxstream
64