diff --git a/NativeRenderPlugin/.vscode/compile_commands.json b/NativeRenderPlugin/.vscode/compile_commands.json index 32594b0..5851afc 100644 --- a/NativeRenderPlugin/.vscode/compile_commands.json +++ b/NativeRenderPlugin/.vscode/compile_commands.json @@ -1,31 +1,31 @@ [ { "directory": "g:\\TJURP\\NativeRenderPlugin", - "arguments": ["C:\\Users\\xinyt\\AppData\\Local\\OpenHarmony\\Sdk\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-fPIC", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI.cpp.o", "RenderAPI.cpp"], + "arguments": ["D:\\tj\\2022.3.48t2\\Editor\\Data\\PlaybackEngines\\OpenHarmonyPlayer\\SDK\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-fPIE", "-fPIC", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI.cpp.o", "RenderAPI.cpp"], "file": "RenderAPI.cpp" }, { "directory": "g:\\TJURP\\NativeRenderPlugin", - "arguments": ["C:\\Users\\xinyt\\AppData\\Local\\OpenHarmony\\Sdk\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-fPIC", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_D3D11.cpp.o", "RenderAPI_D3D11.cpp"], + "arguments": ["D:\\tj\\2022.3.48t2\\Editor\\Data\\PlaybackEngines\\OpenHarmonyPlayer\\SDK\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-fPIE", "-fPIC", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_D3D11.cpp.o", "RenderAPI_D3D11.cpp"], "file": "RenderAPI_D3D11.cpp" }, { "directory": "g:\\TJURP\\NativeRenderPlugin", - "arguments": ["C:\\Users\\xinyt\\AppData\\Local\\OpenHarmony\\Sdk\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-fPIC", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_D3D12.cpp.o", "RenderAPI_D3D12.cpp"], + "arguments": ["D:\\tj\\2022.3.48t2\\Editor\\Data\\PlaybackEngines\\OpenHarmonyPlayer\\SDK\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-fPIE", "-fPIC", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_D3D12.cpp.o", "RenderAPI_D3D12.cpp"], "file": "RenderAPI_D3D12.cpp" }, { "directory": "g:\\TJURP\\NativeRenderPlugin", - "arguments": ["C:\\Users\\xinyt\\AppData\\Local\\OpenHarmony\\Sdk\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-fPIC", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_OpenGLCoreES.cpp.o", "RenderAPI_OpenGLCoreES.cpp"], + "arguments": ["D:\\tj\\2022.3.48t2\\Editor\\Data\\PlaybackEngines\\OpenHarmonyPlayer\\SDK\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-fPIE", "-fPIC", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_OpenGLCoreES.cpp.o", "RenderAPI_OpenGLCoreES.cpp"], "file": "RenderAPI_OpenGLCoreES.cpp" }, { "directory": "g:\\TJURP\\NativeRenderPlugin", - "arguments": ["C:\\Users\\xinyt\\AppData\\Local\\OpenHarmony\\Sdk\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-fPIC", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_Vulkan.cpp.o", "RenderAPI_Vulkan.cpp"], + "arguments": ["D:\\tj\\2022.3.48t2\\Editor\\Data\\PlaybackEngines\\OpenHarmonyPlayer\\SDK\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-fPIE", "-fPIC", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_Vulkan.cpp.o", "RenderAPI_Vulkan.cpp"], "file": "RenderAPI_Vulkan.cpp" }, { "directory": "g:\\TJURP\\NativeRenderPlugin", - "arguments": ["C:\\Users\\xinyt\\AppData\\Local\\OpenHarmony\\Sdk\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-fPIC", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderingPlugin.cpp.o", "RenderingPlugin.cpp"], + "arguments": ["D:\\tj\\2022.3.48t2\\Editor\\Data\\PlaybackEngines\\OpenHarmonyPlayer\\SDK\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-fPIE", "-fPIC", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderingPlugin.cpp.o", "RenderingPlugin.cpp"], "file": "RenderingPlugin.cpp" }] diff --git a/NativeRenderPlugin/.vscode/settings.json b/NativeRenderPlugin/.vscode/settings.json index b33f0e9..a93a3d1 100644 --- a/NativeRenderPlugin/.vscode/settings.json +++ b/NativeRenderPlugin/.vscode/settings.json @@ -74,7 +74,8 @@ "xlocmon": "cpp", "xlocnum": "cpp", "xloctime": "cpp", - "xtr1common": "cpp" + "xtr1common": "cpp", + "string_view": "cpp" }, "workbench.colorCustomizations": { "editor.lineHighlightBackground": "#1073cf2d", diff --git a/NativeRenderPlugin/RenderAPI.h b/NativeRenderPlugin/RenderAPI.h index cbd2abf..184d510 100644 --- a/NativeRenderPlugin/RenderAPI.h +++ b/NativeRenderPlugin/RenderAPI.h @@ -99,6 +99,7 @@ public: virtual void disableXESS1() {} virtual bool getInputResolution(uint32_t outw, uint32_t outh, int quality, uint32_t& width, uint32_t& height) { return false; } + virtual void SetVKPSOHook(bool enable, int blen_state_index) {} protected: virtual void initSupportFeature() = 0; diff --git a/NativeRenderPlugin/RenderAPI_Vulkan.cpp b/NativeRenderPlugin/RenderAPI_Vulkan.cpp index 8d23789..527b391 100644 --- a/NativeRenderPlugin/RenderAPI_Vulkan.cpp +++ b/NativeRenderPlugin/RenderAPI_Vulkan.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -45,6 +46,8 @@ apply(vkGetPhysicalDeviceProperties2); \ apply(vkEnumerateDeviceExtensionProperties); \ apply(vkGetPhysicalDeviceProperties2KHR); \ + apply(vkCreateRenderPass); \ + apply(vkCreateRenderPass2KHR); \ apply(vkDestroyPipelineLayout); #define VULKAN_DEFINE_API_FUNCPTR(func) static PFN_##func func @@ -84,7 +87,8 @@ static VkExtent2D vrs_argment_size_table[] = { static VkExtent2D vrs_fragment_size = vrs_argment_size_table[0]; static bool vrs_enable; -static int curVrsIndex = 0; +static int cur_vrs_Index = 0; +static bool blend_state_hook_enable; static void LoadVulkanAPI(PFN_vkGetInstanceProcAddr getInstanceProcAddr, VkInstance instance) { @@ -164,7 +168,7 @@ static VKAPI_ATTR void VKAPI_CALL Hook_vkCmdBindDescriptorSets(VkCommandBuffer c { if (vrs_enable) { - VkExtent2D fragment_size = vrs_argment_size_table[curVrsIndex]; + VkExtent2D fragment_size = vrs_argment_size_table[cur_vrs_Index]; VkFragmentShadingRateCombinerOpKHR combiner_ops[2]; // If shading rate from attachment is enabled, we set the combiner, so that the values from the attachment are used @@ -182,7 +186,7 @@ static VKAPI_ATTR void VKAPI_CALL Hook_vkCmdBindPipeline(VkCommandBuffer command { // if (vrs_enable) //{ - // VkExtent2D fragment_size = vrs_argment_size_table[curVrsIndex]; + // VkExtent2D fragment_size = vrs_argment_size_table[cur_vrs_Index]; // VkFragmentShadingRateCombinerOpKHR combiner_ops[2]; // // If shading rate from attachment is enabled, we set the combiner, so that the values from the attachment are used @@ -197,11 +201,178 @@ static VKAPI_ATTR void VKAPI_CALL Hook_vkCmdBindPipeline(VkCommandBuffer command vkCmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline); } +// static VKAPI_ATTR VkResult VKAPI_CALL Hook_vkCreateRenderPass( +// VkDevice device, +// const VkRenderPassCreateInfo* pCreateInfo, +// const VkAllocationCallbacks* pAllocator, +// VkRenderPass* pRenderPass +// ) +// { +// auto ret = vkCreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass); +// char buf[80]; +// sprintf(buf, "vkCreateRenderPass---1: %p \n", *pRenderPass); +// unityLog(buf); +// return ret; +// } + +static std::set mrt_renderpasses; +static std::set created_pipeline_shader_module; + +static VKAPI_ATTR VkResult VKAPI_CALL Hook_vkCreateRenderPass2KHR( + VkDevice device, + const VkRenderPassCreateInfo2* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkRenderPass* pRenderPass +) +{ + //if (blend_state_hook_enable) + //{ + // unityLog("Hook_vkCreateRenderPass called."); + // if (pCreateInfo->attachmentCount == 2) + // { + // const_cast(pCreateInfo)->attachmentCount = 3; + // VkAttachmentDescription2 color_attachments[] = { + // pCreateInfo->pAttachments[0], + // pCreateInfo->pAttachments[0], + // pCreateInfo->pAttachments[1], + // }; + // const_cast(pCreateInfo)->pAttachments = color_attachments; + + // const_cast(pCreateInfo->pSubpasses)->colorAttachmentCount = 2; + // VkAttachmentReference2 color_attachment_refs[] = { + // pCreateInfo->pSubpasses->pColorAttachments[0], + // pCreateInfo->pSubpasses->pColorAttachments[0], + // }; + // color_attachment_refs[1].attachment = 1; + // const_cast(pCreateInfo->pSubpasses)->pColorAttachments = color_attachment_refs; + // } + + //} + + auto ret = vkCreateRenderPass2KHR(device, pCreateInfo, pAllocator, pRenderPass); + if(const_cast(pCreateInfo)->attachmentCount > 2) + { + mrt_renderpasses.insert(*pRenderPass); + } + return ret; +} + +static VKAPI_ATTR VkResult VKAPI_CALL Hook_vkCreateGraphicsPipelines( + VkDevice device, + VkPipelineCache pipelineCache, + uint32_t createInfoCount, + const VkGraphicsPipelineCreateInfo* pCreateInfos, + const VkAllocationCallbacks* pAllocator, + VkPipeline* pPipelines) +{ + if (blend_state_hook_enable) + { + //unityLog("Hook_vkCreateGraphicsPipelines called."); + ////VkPipelineColorBlendAttachmentState colorblend_attachment_state{}; + ////colorblend_attachment_state.colorWriteMask = VK_COLOR_COMPONENT_A_BIT | VK_COLOR_COMPONENT_R_BIT | + //// VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT; + ////colorblend_attachment_state.blendEnable = VK_TRUE; + ////colorblend_attachment_state.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; + ////colorblend_attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + ////colorblend_attachment_state.colorBlendOp = VK_BLEND_OP_ADD; + ////colorblend_attachment_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; + ////colorblend_attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + ////colorblend_attachment_state.alphaBlendOp = VK_BLEND_OP_ADD; + + //VkPipelineColorBlendAttachmentState colorblend_attachment_states[] = + //{ + // const_cast(pCreateInfos->pColorBlendState)->pAttachments[0], + // const_cast(pCreateInfos->pColorBlendState)->pAttachments[0], + // //colorblend_attachment_state + //}; + //const_cast(pCreateInfos->pColorBlendState)->attachmentCount = 2; + //const_cast(pCreateInfos->pColorBlendState)->pAttachments = colorblend_attachment_states; + + //// const_cast(pCreateInfos->pDepthStencilState)->depthCompareOp = VK_COMPARE_OP_GREATER_OR_EQUAL; + //// const_cast(pCreateInfos->pInputAssemblyState)->topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + + //// const_cast(pCreateInfos->pRasterizationState)->frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; + + //std::array attribute_descriptions{}; + + //std::array bind_descs{}; + //bind_descs[0].binding = 0; + //bind_descs[0].stride = 56; + //bind_descs[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX; + + //bind_descs[1].binding = 1; + //bind_descs[1].stride = 0; + //bind_descs[1].inputRate = VK_VERTEX_INPUT_RATE_VERTEX; + + //if (pCreateInfos->pVertexInputState->vertexBindingDescriptionCount == 2 && pCreateInfos->pVertexInputState->pVertexBindingDescriptions[0].stride == 64) + //{ + + // const_cast(pCreateInfos->pVertexInputState)->vertexBindingDescriptionCount = bind_descs.size(); + // const_cast(pCreateInfos->pVertexInputState)->pVertexBindingDescriptions = bind_descs.data(); + + // attribute_descriptions[0].binding = 0; + // attribute_descriptions[0].location = 0; + // attribute_descriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT; + // attribute_descriptions[0].offset = 0; + + // attribute_descriptions[1].binding = 0; + // attribute_descriptions[1].location = 1; + // attribute_descriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT; + // attribute_descriptions[1].offset = 12; + + // attribute_descriptions[2].binding = 1; + // attribute_descriptions[2].location = 2; + // attribute_descriptions[2].format = VK_FORMAT_R8G8B8A8_UNORM; + // attribute_descriptions[2].offset = 4; + + // attribute_descriptions[3].binding = 0; + // attribute_descriptions[3].location = 3; + // attribute_descriptions[3].format = VK_FORMAT_R32G32_SFLOAT; + // attribute_descriptions[3].offset = 40; + + // attribute_descriptions[4].binding = 0; + // attribute_descriptions[4].location = 4; + // attribute_descriptions[4].format = VK_FORMAT_R32G32_SFLOAT; + // attribute_descriptions[4].offset = 48; + + // const_cast(pCreateInfos->pVertexInputState)->vertexAttributeDescriptionCount = attribute_descriptions.size(); + // const_cast(pCreateInfos->pVertexInputState)->pVertexAttributeDescriptions = attribute_descriptions.data();; + //} + + //if (pCreateInfos->pVertexInputState->vertexBindingDescriptionCount == 2 && pCreateInfos->pVertexInputState->pVertexBindingDescriptions[0].stride == 56) + //{ + // char buf[80]; + // sprintf(buf, "vkCreateGraphicsPipelines---: %p : %p\n", pCreateInfos->pStages[1].module, pCreateInfos->renderPass); + // unityLog(buf); + // unityLog("vkCreateGraphicsPipelines Attr."); + //} + VkResult ret; + auto shader_module = pCreateInfos->pStages[1].module; + if(!created_pipeline_shader_module.contains(shader_module)) + { + created_pipeline_shader_module.insert(shader_module); + + for (const auto i : mrt_renderpasses) + { + const_cast(pCreateInfos)->renderPass = static_cast(i); + char buf[80]; + sprintf(buf, "vkCreateGraphicsPipelines---: %p : %p\n", pCreateInfos->pStages[1].module, pCreateInfos->renderPass); + unityLog(buf); + ret = vkCreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines); + } + } + + return ret; + } + + return vkCreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines); +} + static int FindMemoryTypeIndex(VkPhysicalDeviceMemoryProperties const &physicalDeviceMemoryProperties, VkMemoryRequirements const &memoryRequirements, VkMemoryPropertyFlags memoryPropertyFlags) { uint32_t memoryTypeBits = memoryRequirements.memoryTypeBits; - // Search memtypes to find first curVrsIndex with those properties + // Search memtypes to find first cur_vrs_Index with those properties for (uint32_t memoryTypeIndex = 0; memoryTypeIndex < VK_MAX_MEMORY_TYPES; ++memoryTypeIndex) { if ((memoryTypeBits & 1) == 1) @@ -228,6 +399,8 @@ static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL Hook_vkGetInstanceProcAddr(VkIns INTERCEPT(vkCreateDevice); INTERCEPT(vkCmdBindPipeline); INTERCEPT(vkCmdBindDescriptorSets); + INTERCEPT(vkCreateGraphicsPipelines); + INTERCEPT(vkCreateRenderPass2KHR); #undef INTERCEPT return (PFN_vkVoidFunction)vkGetInstanceProcAddr(device, funcName); @@ -279,6 +452,7 @@ public: virtual void postFGExtrapolation() override; virtual void disableFGExtrapolation() override; + virtual void SetVKPSOHook(bool enable, int blen_state_index) override; private: typedef std::vector VulkanBuffers; typedef std::map DeleteQueue; @@ -513,7 +687,7 @@ void RenderAPI_Vulkan::initSupportFeature() void RenderAPI_Vulkan::enableVRS(void* data) { int vrs_enum = *(int*) data; - curVrsIndex = vrs_enum; + cur_vrs_Index = vrs_enum; vrs_fragment_size = vrs_argment_size_table[vrs_enum]; vrs_enable = true; } @@ -552,4 +726,9 @@ void RenderAPI_Vulkan::postFGExtrapolation() void RenderAPI_Vulkan::disableFGExtrapolation() { } + +void RenderAPI_Vulkan::SetVKPSOHook(bool enable, int blen_state_index) +{ + blend_state_hook_enable = enable; +} #endif // #if SUPPORT_VULKAN diff --git a/NativeRenderPlugin/RenderingPlugin.cpp b/NativeRenderPlugin/RenderingPlugin.cpp index 82138c5..b090b7f 100644 --- a/NativeRenderPlugin/RenderingPlugin.cpp +++ b/NativeRenderPlugin/RenderingPlugin.cpp @@ -207,6 +207,13 @@ extern "C" UNITY_INTERFACE_EXPORT bool GetInputResolution(uint32_t outw, uint32_ return s_current_api->getInputResolution(outw, outh, quality, width, height); } + +extern "C" UNITY_INTERFACE_EXPORT void SetVKPSOHook(bool enable, int blend_state_index) +{ + s_current_api->SetVKPSOHook(enable, blend_state_index); +} + + // -------------------------------------------------------------------------- // DX12 plugin specific // --------------------------------------------------------------------------