|
|
|
|
|
|
return fbo_; |
|
|
|
} |
|
|
|
|
|
|
|
bool getMemoryTypeIndex(uint32_t typeBits, VkPhysicalDevice device, VkFlags quirementsMaks, |
|
|
|
uint32_t &index) |
|
|
|
{ |
|
|
|
// const auto& memoryPropertys =
|
|
|
|
// VulkanManager::Get().physical->mempryProperties;
|
|
|
|
VkPhysicalDeviceMemoryProperties memoryPropertys; |
|
|
|
vkGetPhysicalDeviceMemoryProperties(device, &memoryPropertys); |
|
|
|
for (uint32_t i = 0; i < memoryPropertys.memoryTypeCount; i++) |
|
|
|
{ |
|
|
|
if ((typeBits & 1) == 1) |
|
|
|
{ |
|
|
|
// Type is available, does it match user properties?
|
|
|
|
if ((memoryPropertys.memoryTypes[i].propertyFlags & |
|
|
|
quirementsMaks) == quirementsMaks) |
|
|
|
{ |
|
|
|
index = i; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
typeBits >>= 1; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
GLuint UnitySurfaceManager::CreateRenderSurfaceVK(int width, int height) |
|
|
|
{ |
|
|
|
if (m_UnityVulkan != nullptr) |
|
|
|
|
|
|
VkImage vkImage; |
|
|
|
// VkImage vkImage;
|
|
|
|
bool useExternalFormat = true; |
|
|
|
|
|
|
|
AHardwareBuffer *buffer = nullptr; |
|
|
|
|
|
|
usage.rfu0 = 0; |
|
|
|
usage.rfu1 = 0; |
|
|
|
usage.stride = 0; |
|
|
|
usage.usage = AHARDWAREBUFFER_USAGE_CPU_READ_NEVER | |
|
|
|
AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER | |
|
|
|
AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | |
|
|
|
AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT; |
|
|
|
usage.usage = AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN | |
|
|
|
AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER | |
|
|
|
AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT; |
|
|
|
FML_CHECK(AHardwareBuffer_allocate(&usage, &buffer) == 0); |
|
|
|
VkResult err; |
|
|
|
|
|
|
|
|
|
|
.pNext = &formatInfo, |
|
|
|
}; |
|
|
|
err = vkGetAndroidHardwareBufferPropertiesANDROID(vkDevice, buffer, &properties); |
|
|
|
bool check = false; |
|
|
|
check = VK_FORMAT_R8G8B8A8_UNORM == formatInfo.format; |
|
|
|
check = VK_FORMAT_UNDEFINED == formatInfo.format; |
|
|
|
|
|
|
|
VkExternalFormatANDROID externalFormat{ |
|
|
|
.sType = VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID, |
|
|
|
|
|
|
VkExternalMemoryImageCreateInfo externalCreateInfo{ |
|
|
|
.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO, |
|
|
|
.pNext = useExternalFormat ? &externalFormat : nullptr, |
|
|
|
.pNext = &externalFormat, |
|
|
|
VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT | |
|
|
|
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | |
|
|
|
VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
|
|
|
if (true) |
|
|
|
{ //forWrite) {
|
|
|
|
usageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
VkImageCreateInfo imageInfo = {}; |
|
|
|
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
|
|
|
|
|
|
imageInfo.format = |
|
|
|
formatInfo.format; |
|
|
|
VK_FORMAT_UNDEFINED; |
|
|
|
imageInfo.extent = { |
|
|
|
bufferDesc.width, |
|
|
|
bufferDesc.height, |
|
|
|
|
|
|
imageInfo.samples = VK_SAMPLE_COUNT_1_BIT; |
|
|
|
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; |
|
|
|
imageInfo.usage = usageFlags; |
|
|
|
imageInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
|
|
|
imageInfo.pQueueFamilyIndices = 0; |
|
|
|
imageInfo.pQueueFamilyIndices = nullptr; |
|
|
|
auto result = vkCreateImage(vkDevice, &imageInfo, nullptr, &vkImage); |
|
|
|
auto result = vkCreateImage(vkDevice, &imageInfo, nullptr, &vk_Image_); |
|
|
|
|
|
|
|
VkImportAndroidHardwareBufferInfoANDROID androidHardwareBufferInfo{ |
|
|
|
.sType = VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID, |
|
|
|
|
|
|
VkMemoryDedicatedAllocateInfo memoryAllocateInfo{ |
|
|
|
.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO, |
|
|
|
.pNext = &androidHardwareBufferInfo, |
|
|
|
.image = vkImage, |
|
|
|
.image = vk_Image_, |
|
|
|
vkGetImageMemoryRequirements(vkDevice, vkImage, &requires); |
|
|
|
vkGetImageMemoryRequirements(vkDevice, vk_Image_, &requires); |
|
|
|
uint32_t typeIndex = 0; |
|
|
|
// uint32_t heapIndex = 0;
|
|
|
|
bool foundHeap = false; |
|
|
|
vkGetPhysicalDeviceMemoryProperties2(m_Instance.physicalDevice, &phyDevMemProps); |
|
|
|
uint32_t memTypeCnt = phyDevMemProps.memoryProperties.memoryTypeCount; |
|
|
|
for (uint32_t i = 0; i < memTypeCnt && !foundHeap; ++i) |
|
|
|
{ |
|
|
|
if (properties.memoryTypeBits & (1 << i)) |
|
|
|
{ |
|
|
|
const VkPhysicalDeviceMemoryProperties &pdmp = phyDevMemProps.memoryProperties; |
|
|
|
uint32_t supportedFlags = pdmp.memoryTypes[i].propertyFlags & |
|
|
|
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
|
|
|
if (supportedFlags == VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) |
|
|
|
{ |
|
|
|
typeIndex = i; |
|
|
|
// heapIndex = pdmp.memoryTypes[i].heapIndex;
|
|
|
|
foundHeap = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// uint32_t memoryTypeIndex = 0;
|
|
|
|
// // VkPhysicalDeviceMemoryProperties memoryPropertys; //???
|
|
|
|
uint32_t memoryTypeIndex = 0; |
|
|
|
bool getIndex = |
|
|
|
getMemoryTypeIndex(properties.memoryTypeBits, m_Instance.physicalDevice, 0, memoryTypeIndex); |
|
|
|
// bool getIndex =
|
|
|
|
// getMemoryTypeIndex(properties.memoryTypeBits, m_Instance.physicalDevice, 0, memoryTypeIndex); //??
|
|
|
|
// assert(getIndex);
|
|
|
|
memoryInfo.memoryTypeIndex = typeIndex; |
|
|
|
memoryInfo.memoryTypeIndex = memoryTypeIndex; |
|
|
|
|
|
|
|
VkDeviceMemory memory; //???
|
|
|
|
|
|
|
|
vkAllocateMemory(vkDevice, &memoryInfo, nullptr, &memory); |
|
|
|
|
|
|
|
|
|
|
bindImageInfo.image = vkImage; |
|
|
|
bindImageInfo.image = vk_Image_; |
|
|
|
|
|
|
|
eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE, egl_context_); |
|
|
|
EGLint attrs[] = {EGL_NONE}; |
|
|
|
eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE, egl_context_); |
|
|
|
EGLImageKHR image = eglCreateImageKHR(egl_display_, EGL_NO_CONTEXT, |
|
|
|
EGL_NATIVE_BUFFER_ANDROID, native_buffer, attrs); |
|
|
|
FML_DCHECK(image != EGL_NO_IMAGE_KHR); |
|
|
|
|
|
|
|
GLuint mTexture = 0; |
|
|
|
glGenTextures(1, &mTexture); |
|
|
|
glGenFramebuffers(1, &fbo_); |
|
|
|
|
|
|
|
|
|
|
EGLint attrs[] = {EGL_NONE}; |
|
|
|
EGLImageKHR image = eglCreateImageKHR(egl_display_, EGL_NO_CONTEXT, |
|
|
|
EGL_NATIVE_BUFFER_ANDROID, native_buffer, attrs); |
|
|
|
FML_DCHECK(image != EGL_NO_IMAGE_KHR); |
|
|
|
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
|
|
|
vk_Image_ = &vkImage; |
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0); |
|
|
|
auto x = glGetError(); |
|
|
|
glEnable(GL_TEXTURE_2D); |
|
|
|
x = glGetError(); |
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo_); |
|
|
|
x = glGetError(); |
|
|
|
glViewport(0,0,200, 200); |
|
|
|
x = glGetError(); |
|
|
|
|
|
|
|
glClearColor(0,0,1,0); |
|
|
|
x = glGetError(); |
|
|
|
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
|
|
|
x = glGetError(); |
|
|
|
|
|
|
|
// return fbo_;
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
static const int DEV_W = 16, DEV_H = 16; |
|
|
|
|
|
|
|
bool getMemoryTypeIndex(uint32_t typeBits, VkPhysicalDevice device, VkFlags quirementsMaks, |
|
|
|
uint32_t &index) |
|
|
|
{ |
|
|
|
// const auto& memoryPropertys =
|
|
|
|
// VulkanManager::Get().physical->mempryProperties;
|
|
|
|
VkPhysicalDeviceMemoryProperties memoryPropertys; |
|
|
|
vkGetPhysicalDeviceMemoryProperties(device, &memoryPropertys); |
|
|
|
for (uint32_t i = 0; i < memoryPropertys.memoryTypeCount; i++) |
|
|
|
{ |
|
|
|
if ((typeBits & 1) == 1) |
|
|
|
{ |
|
|
|
// Type is available, does it match user properties?
|
|
|
|
if ((memoryPropertys.memoryTypes[i].propertyFlags & |
|
|
|
quirementsMaks) == quirementsMaks) |
|
|
|
{ |
|
|
|
index = i; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
typeBits >>= 1; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool UnitySurfaceManager::Initialize(IUnityInterfaces *unity_interfaces) |
|
|
|
{ |
|
|
|