Last active
October 28, 2021 10:46
-
-
Save tonykwok/c2bb95b9eefe1573082b537f97833a3d to your computer and use it in GitHub Desktop.
gralloc_handle_t
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 + // copied from the link bebow: | |
128 + // https://es.osdn.net/projects/android-x86/scm/git/external-mesa/commits/5a595cd3af15b99d266d3fd5cba41da33f1888ac | |
129 + | |
130 + bool ubwc = false; | |
131 + | |
132 + const uint32_t *handle_fds = (uint32_t *)gralloc_info->handle->data; | |
133 + const uint32_t *handle_data = &handle_fds[gralloc_info->handle->numFds]; | |
134 + int dma_buf; | |
135 + | |
136 + if (gralloc_info->handle->numFds == 1) { | |
137 + /* gbm_gralloc. TODO: modifiers support */ | |
138 + dma_buf = handle_fds[0]; | |
139 + } else if (gralloc_info->handle->numFds == 2) { | |
140 + /* Qualcomm gralloc, find it at: | |
141 + * | |
142 + * https://android.googlesource.com/platform/hardware/qcom/display/. | |
143 + * | |
144 + * The gralloc_info->handle is a pointer to a struct private_handle_t | |
145 + * from your platform's gralloc. On msm8996 (a5xx) and newer grallocs | |
146 + * that's libgralloc1/gr_priv_handle.h, while previously it was | |
147 + * libgralloc/gralloc_priv.h. | |
148 + */ | |
149 + | |
150 + if (gralloc_info->handle->numInts < 2) { | |
151 + return vk_errorf(device->instance, VK_ERROR_INVALID_EXTERNAL_HANDLE, | |
152 + "VkNativeBufferANDROID::handle::numInts is %d, " | |
153 + "expected at least 2 for qcom gralloc", | |
154 + gralloc_info->handle->numFds); | |
155 + } | |
156 + | |
157 + uint32_t gmsm = ('g' << 24) | ('m' << 16) | ('s' << 8) | 'm'; | |
158 + if (handle_data[0] != gmsm) { | |
159 + return vk_errorf(device->instance, VK_ERROR_INVALID_EXTERNAL_HANDLE, | |
160 + "private_handle_t::magic is %x, expected %x", | |
161 + handle_data[0], gmsm); | |
162 + } | |
163 + | |
164 + /* This UBWC flag was introduced in a5xx. */ | |
165 + ubwc = handle_data[1] & 0x08000000; | |
166 + | |
167 + /* QCOM gralloc has two fds passed in: the actual GPU buffer, and a buffer | |
168 + * of CPU-side metadata. I haven't found any need for the metadata buffer | |
169 + * yet. See qdMetaData.h for what's in the metadata fd. | |
170 + */ | |
171 + dma_buf = handle_fds[0]; | |
172 + } else { | |
173 + return vk_errorf(device->instance, VK_ERROR_INVALID_EXTERNAL_HANDLE, | |
174 + "VkNativeBufferANDROID::handle::numFds is %d, " | |
175 + "expected 1 (gbm_gralloc) or 2 (qcom gralloc)", | |
176 + gralloc_info->handle->numFds); | |
177 + } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment