浏览代码

update

/siyaoH-1.17-vulkan2
siyao 3 年前
当前提交
bae103b4
共有 3 个文件被更改,包括 103 次插入99 次删除
  1. 40
      com.unity.uiwidgets/Runtime/engine/UIWidgetsPanelWrapper.cs
  2. 154
      engine/src/shell/platform/unity/android/unity_surface_manager.cc
  3. 8
      engine/src/shell/platform/unity/android/unity_surface_manager.h

40
com.unity.uiwidgets/Runtime/engine/UIWidgetsPanelWrapper.cs


#if (!UNITY_EDITOR && UNITY_ANDROID )
public partial class UIWidgetsPanelWrapper {
RenderTexture _renderTexture;
Texture _renderTexture;
public RenderTexture renderTexture {
public Texture renderTexture {
D.assert(_renderTexture == null);
var desc = new RenderTextureDescriptor(
width, height, RenderTextureFormat.ARGB32, 0) {
useMipMap = false,
autoGenerateMips = false,
};
_renderTexture = new RenderTexture(desc) {hideFlags = HideFlags.HideAndDontSave};
_renderTexture.Create();
// D.assert(_renderTexture == null);
//
// var desc = new RenderTextureDescriptor(
// width, height, RenderTextureFormat.ARGB32, 0) {
// useMipMap = false,
// autoGenerateMips = false,
// };
//
// _renderTexture = new RenderTexture(desc) {hideFlags = HideFlags.HideAndDontSave};
// _renderTexture.Create();
_width = width;
_height = height;

}
void _enableUIWidgetsPanel(string font_settings) {
UIWidgetsPanel_onEnable(_ptr, _renderTexture.GetNativeTexturePtr(),
IntPtr native_tex_ptr = UIWidgetsPanel_onEnableVK(_ptr,
D.assert(native_tex_ptr != IntPtr.Zero);
_renderTexture = Texture2D.CreateExternalTexture(_width, _height, TextureFormat.BGRA32, false, true, native_tex_ptr);
UIWidgetsPanel_onRenderTexture(_ptr,
_renderTexture.GetNativeTexturePtr(),
IntPtr native_tex_ptr = UIWidgetsPanel_onRenderTextureVK(_ptr,
D.assert(native_tex_ptr != IntPtr.Zero);
_renderTexture = Texture2D.CreateExternalTexture(_width, _height, TextureFormat.BGRA32, false, true, native_tex_ptr);
}
void _disableUIWidgetsPanel() {

string font_settings);
[DllImport(NativeBindings.dllName)]
static extern IntPtr UIWidgetsPanel_onEnableVK(IntPtr ptr, int width, int height, float dpi, string streamingAssetsPath,
string font_settings);
[DllImport(NativeBindings.dllName)]
[DllImport(NativeBindings.dllName)]
static extern IntPtr UIWidgetsPanel_onRenderTextureVK(
IntPtr ptr, int width, int height, float dpi);
}
#endif

154
engine/src/shell/platform/unity/android/unity_surface_manager.cc


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)
{

8
engine/src/shell/platform/unity/android/unity_surface_manager.h


void DestroyRenderSurface();
void* GetInnerTexture() const { return static_cast<void*>(vk_Image_); }
void* GetInnerTexture() {
// return (void*)vk_Image_;
return (void*)&vk_Image_;
}
bool ClearCurrent();

UnityVulkanInstance m_Instance;
sk_sp<GrContext> gr_context_;
sk_sp<SkSurface> m_SkSurface;
VkImage* vk_Image_;
VkImage vk_Image_;
VkDeviceMemory memory;
bool initialize_succeeded_;

正在加载...
取消
保存