1 // Copyright (C) 2024 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 #ifndef EXTENDED_RENDERCONTROL_H
15 #define EXTENDED_RENDERCONTROL_H
16 
17 #include <cstring>
18 #include <string>
19 
20 #include "EmulatorFeatureInfo.h"
21 #include "gfxstream/guest/ChecksumCalculator.h"
22 #include "gfxstream/guest/IOStream.h"
23 #include "renderControl_enc.h"
24 
25 using gfxstream::guest::ChecksumCalculator;
26 
27 // ExtendedRCEncoderContext is an extended version of renderControl_encoder_context_t
28 // that will be used to track available emulator features.
29 class ExtendedRCEncoderContext : public renderControl_encoder_context_t {
30    public:
ExtendedRCEncoderContext(gfxstream::guest::IOStream * stream,gfxstream::guest::ChecksumCalculator * checksumCalculator)31     ExtendedRCEncoderContext(gfxstream::guest::IOStream* stream,
32                              gfxstream::guest::ChecksumCalculator* checksumCalculator)
33         : renderControl_encoder_context_t(stream, checksumCalculator) {}
setSyncImpl(SyncImpl syncImpl)34     void setSyncImpl(SyncImpl syncImpl) { m_featureInfo.syncImpl = syncImpl; }
setDmaImpl(DmaImpl dmaImpl)35     void setDmaImpl(DmaImpl dmaImpl) { m_featureInfo.dmaImpl = dmaImpl; }
setHostComposition(HostComposition hostComposition)36     void setHostComposition(HostComposition hostComposition) {
37         m_featureInfo.hostComposition = hostComposition;
38     }
hasNativeSync()39     bool hasNativeSync() const { return m_featureInfo.syncImpl >= SYNC_IMPL_NATIVE_SYNC_V2; }
hasNativeSyncV3()40     bool hasNativeSyncV3() const { return m_featureInfo.syncImpl >= SYNC_IMPL_NATIVE_SYNC_V3; }
hasNativeSyncV4()41     bool hasNativeSyncV4() const { return m_featureInfo.syncImpl >= SYNC_IMPL_NATIVE_SYNC_V4; }
hasVirtioGpuNativeSync()42     bool hasVirtioGpuNativeSync() const { return m_featureInfo.hasVirtioGpuNativeSync; }
hasHostCompositionV1()43     bool hasHostCompositionV1() const {
44         return m_featureInfo.hostComposition == HOST_COMPOSITION_V1;
45     }
hasHostCompositionV2()46     bool hasHostCompositionV2() const {
47         return m_featureInfo.hostComposition == HOST_COMPOSITION_V2;
48     }
hasYUVCache()49     bool hasYUVCache() const { return m_featureInfo.hasYUVCache; }
hasAsyncUnmapBuffer()50     bool hasAsyncUnmapBuffer() const { return m_featureInfo.hasAsyncUnmapBuffer; }
hasHostSideTracing()51     bool hasHostSideTracing() const { return m_featureInfo.hasHostSideTracing; }
hasAsyncFrameCommands()52     bool hasAsyncFrameCommands() const { return m_featureInfo.hasAsyncFrameCommands; }
hasSyncBufferData()53     bool hasSyncBufferData() const { return m_featureInfo.hasSyncBufferData; }
hasHWCMultiConfigs()54     bool hasHWCMultiConfigs() const { return m_featureInfo.hasHWCMultiConfigs; }
bindDmaDirectly(void * dmaPtr,uint64_t dmaPhysAddr)55     void bindDmaDirectly(void* dmaPtr, uint64_t dmaPhysAddr) {
56         m_dmaPtr = dmaPtr;
57         m_dmaPhysAddr = dmaPhysAddr;
58     }
lockAndWriteDma(void * data,uint32_t size)59     virtual uint64_t lockAndWriteDma(void* data, uint32_t size) {
60         if (m_dmaPtr && m_dmaPhysAddr) {
61             if (data != m_dmaPtr) {
62                 memcpy(m_dmaPtr, data, size);
63             }
64             return m_dmaPhysAddr;
65         } else {
66             ALOGE("%s: ALOGEOR: No DMA context bound!", __func__);
67             return 0;
68         }
69     }
setGLESMaxVersion(GLESMaxVersion ver)70     void setGLESMaxVersion(GLESMaxVersion ver) { m_featureInfo.glesMaxVersion = ver; }
getGLESMaxVersion()71     GLESMaxVersion getGLESMaxVersion() const { return m_featureInfo.glesMaxVersion; }
hasDirectMem()72     bool hasDirectMem() const { return m_featureInfo.hasDirectMem; }
73 
featureInfo_const()74     const EmulatorFeatureInfo* featureInfo_const() const { return &m_featureInfo; }
featureInfo()75     EmulatorFeatureInfo* featureInfo() { return &m_featureInfo; }
76 
77     const std::string& queryHostExtensions();
78     // setProtocol initializes GL communication protocol for checksums
79     // should be called when m_rcEnc is created
80     void setChecksumHelper(ChecksumCalculator* calculator);
81     void queryAndSetSyncImpl();
82     void queryAndSetDmaImpl();
83     void queryAndSetGLESMaxVersion();
84     void queryAndSetNoErrorState(bool& hostError);
85     void queryAndSetHostCompositionImpl();
86     void queryAndSetDirectMemSupport();
87     void queryAndSetVulkanSupport();
88     void queryAndSetDeferredVulkanCommandsSupport();
89     void queryAndSetVulkanNullOptionalStringsSupport();
90     void queryAndSetVulkanCreateResourcesWithRequirementsSupport();
91     void queryAndSetVulkanIgnoredHandles();
92     void queryAndSetYUVCache();
93     void queryAndSetAsyncUnmapBuffer();
94     void queryAndSetVirtioGpuNext();
95     void queryHasSharedSlotsHostMemoryAllocator();
96     void queryAndSetVulkanFreeMemorySync();
97     void queryAndSetVirtioGpuNativeSync();
98     void queryAndSetVulkanShaderFloat16Int8Support();
99     void queryAndSetVulkanAsyncQueueSubmitSupport();
100     void queryAndSetHostSideTracingSupport();
101     void queryAndSetAsyncFrameCommands();
102     void queryAndSetVulkanQueueSubmitWithCommandsSupport();
103     void queryAndSetVulkanBatchedDescriptorSetUpdateSupport();
104     void queryAndSetSyncBufferData();
105     void queryAndSetVulkanAsyncQsri();
106     void queryAndSetReadColorBufferDma();
107     void queryAndSetHWCMultiConfigs();
108     void queryAndSetVulkanAuxCommandBufferMemory();
109     GLint queryVersion();
110     void setVulkanFeatureInfo(void* info);
111 
112    private:
113     EmulatorFeatureInfo m_featureInfo;
114     std::string m_hostExtensions;
115     void* m_dmaPtr = nullptr;
116     uint64_t m_dmaPhysAddr = 0;
117 };
118 
119 #endif
120