This commit is contained in:
StarBeats 2025-04-02 17:11:10 +08:00
parent 432f558e78
commit 61b4f13b7d
3 changed files with 13 additions and 89 deletions

View File

@ -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;

View File

@ -215,7 +215,7 @@ static VKAPI_ATTR void VKAPI_CALL Hook_vkCmdBindPipeline(VkCommandBuffer command
// return ret;
// }
static std::set<void*> mrt_renderpasses;
static std::set<void*> need_create_pso_renderpasses;
static std::set<void*> 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<VkRenderPassCreateInfo2*>(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<VkPipelineColorBlendStateCreateInfo*>(pCreateInfos->pColorBlendState)->pAttachments[0],
// const_cast<VkPipelineColorBlendStateCreateInfo*>(pCreateInfos->pColorBlendState)->pAttachments[0],
// //colorblend_attachment_state
//};
//const_cast<VkPipelineColorBlendStateCreateInfo*>(pCreateInfos->pColorBlendState)->attachmentCount = 2;
//const_cast<VkPipelineColorBlendStateCreateInfo*>(pCreateInfos->pColorBlendState)->pAttachments = colorblend_attachment_states;
//// const_cast<VkPipelineDepthStencilStateCreateInfo*>(pCreateInfos->pDepthStencilState)->depthCompareOp = VK_COMPARE_OP_GREATER_OR_EQUAL;
//// const_cast<VkPipelineInputAssemblyStateCreateInfo*>(pCreateInfos->pInputAssemblyState)->topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
//// const_cast<VkPipelineRasterizationStateCreateInfo*>(pCreateInfos->pRasterizationState)->frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
//std::array<VkVertexInputAttributeDescription, 5> attribute_descriptions{};
//std::array<VkVertexInputBindingDescription, 2> 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<VkPipelineVertexInputStateCreateInfo*>(pCreateInfos->pVertexInputState)->vertexBindingDescriptionCount = bind_descs.size();
// const_cast<VkPipelineVertexInputStateCreateInfo*>(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<VkPipelineVertexInputStateCreateInfo*>(pCreateInfos->pVertexInputState)->vertexAttributeDescriptionCount = attribute_descriptions.size();
// const_cast<VkPipelineVertexInputStateCreateInfo*>(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<VkGraphicsPipelineCreateInfo*>(pCreateInfos)->renderPass = static_cast<VkRenderPass>(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<VkGraphicsPipelineCreateInfo*>(pCreateInfos)->renderPass = static_cast<VkRenderPass>(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<VulkanBuffer> VulkanBuffers;
typedef std::map<unsigned long long, VulkanBuffers> 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;
}

View File

@ -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);
}