diff --git a/NativeRenderPlugin/RenderAPI.h b/NativeRenderPlugin/RenderAPI.h index 184d510..1d469a8 100644 --- a/NativeRenderPlugin/RenderAPI.h +++ b/NativeRenderPlugin/RenderAPI.h @@ -99,7 +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) {} + virtual void SetVKPSOHook(bool enable) {} protected: virtual void initSupportFeature() = 0; diff --git a/NativeRenderPlugin/RenderAPI_Vulkan.cpp b/NativeRenderPlugin/RenderAPI_Vulkan.cpp index 527b391..040354e 100644 --- a/NativeRenderPlugin/RenderAPI_Vulkan.cpp +++ b/NativeRenderPlugin/RenderAPI_Vulkan.cpp @@ -215,7 +215,7 @@ static VKAPI_ATTR void VKAPI_CALL Hook_vkCmdBindPipeline(VkCommandBuffer command // return ret; // } -static std::set mrt_renderpasses; +static std::set need_create_pso_renderpasses; static std::set created_pipeline_shader_module; static VKAPI_ATTR VkResult VKAPI_CALL Hook_vkCreateRenderPass2KHR( @@ -252,11 +252,12 @@ static VKAPI_ATTR VkResult VKAPI_CALL Hook_vkCreateRenderPass2KHR( auto ret = vkCreateRenderPass2KHR(device, pCreateInfo, pAllocator, pRenderPass); if(const_cast(pCreateInfo)->attachmentCount > 2) { - mrt_renderpasses.insert(*pRenderPass); + need_create_pso_renderpasses.insert(*pRenderPass); } return ret; } + static VKAPI_ATTR VkResult VKAPI_CALL Hook_vkCreateGraphicsPipelines( VkDevice device, VkPipelineCache pipelineCache, @@ -267,92 +268,13 @@ static VKAPI_ATTR VkResult VKAPI_CALL Hook_vkCreateGraphicsPipelines( { 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; + auto cur_pass = pCreateInfos->renderPass; if(!created_pipeline_shader_module.contains(shader_module)) { created_pipeline_shader_module.insert(shader_module); - - for (const auto i : mrt_renderpasses) + for (const auto i : need_create_pso_renderpasses) { const_cast(pCreateInfos)->renderPass = static_cast(i); char buf[80]; @@ -361,7 +283,9 @@ static VKAPI_ATTR VkResult VKAPI_CALL Hook_vkCreateGraphicsPipelines( ret = vkCreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines); } } - + + // const_cast(pCreateInfos)->renderPass = static_cast(cur_pass); + // ret = vkCreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines); return ret; } @@ -452,7 +376,7 @@ public: virtual void postFGExtrapolation() override; virtual void disableFGExtrapolation() override; - virtual void SetVKPSOHook(bool enable, int blen_state_index) override; + virtual void SetVKPSOHook(bool enable) override; private: typedef std::vector VulkanBuffers; typedef std::map DeleteQueue; @@ -727,7 +651,7 @@ void RenderAPI_Vulkan::disableFGExtrapolation() { } -void RenderAPI_Vulkan::SetVKPSOHook(bool enable, int blen_state_index) +void RenderAPI_Vulkan::SetVKPSOHook(bool enable) { blend_state_hook_enable = enable; } diff --git a/NativeRenderPlugin/RenderingPlugin.cpp b/NativeRenderPlugin/RenderingPlugin.cpp index b090b7f..80b606f 100644 --- a/NativeRenderPlugin/RenderingPlugin.cpp +++ b/NativeRenderPlugin/RenderingPlugin.cpp @@ -208,9 +208,9 @@ extern "C" UNITY_INTERFACE_EXPORT bool GetInputResolution(uint32_t outw, uint32_ } -extern "C" UNITY_INTERFACE_EXPORT void SetVKPSOHook(bool enable, int blend_state_index) +extern "C" UNITY_INTERFACE_EXPORT void SetVKPSOHook(bool enable) { - s_current_api->SetVKPSOHook(enable, blend_state_index); + s_current_api->SetVKPSOHook(enable); }