mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Vulkan blend factor: Bugfix and minor optimization
This commit is contained in:
parent
29950c0ad5
commit
1e3711ee66
7 changed files with 36 additions and 10 deletions
|
@ -126,7 +126,15 @@ static int SetupVertexAttribsPretransformed(VkVertexInputAttributeDescription at
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool UsesBlendConstant(int factor) {
|
static bool UsesBlendConstant(int factor) {
|
||||||
return factor == VK_BLEND_FACTOR_CONSTANT_ALPHA || factor == VK_BLEND_FACTOR_CONSTANT_COLOR;
|
switch (factor) {
|
||||||
|
case VK_BLEND_FACTOR_CONSTANT_ALPHA:
|
||||||
|
case VK_BLEND_FACTOR_CONSTANT_COLOR:
|
||||||
|
case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA:
|
||||||
|
case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static VulkanPipeline *CreateVulkanPipeline(VkDevice device, VkPipelineCache pipelineCache,
|
static VulkanPipeline *CreateVulkanPipeline(VkDevice device, VkPipelineCache pipelineCache,
|
||||||
|
|
|
@ -413,8 +413,6 @@ void DrawEngineVulkan::ApplyDrawStateLate(VulkanRenderManager *renderManager, bo
|
||||||
renderManager->SetStencilParams(dynState_.stencilWriteMask, dynState_.stencilCompareMask, applyStencilRef ? stencilRef : dynState_.stencilRef);
|
renderManager->SetStencilParams(dynState_.stencilWriteMask, dynState_.stencilCompareMask, applyStencilRef ? stencilRef : dynState_.stencilRef);
|
||||||
}
|
}
|
||||||
if (gstate_c.IsDirty(DIRTY_BLEND_STATE) && useBlendConstant) {
|
if (gstate_c.IsDirty(DIRTY_BLEND_STATE) && useBlendConstant) {
|
||||||
float bc[4];
|
renderManager->SetBlendFactor(dynState_.blendColor);
|
||||||
Uint8x4ToFloat4(bc, dynState_.blendColor);
|
|
||||||
renderManager->SetBlendFactor(bc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,21 @@ inline void Uint8x4ToFloat4(float f[4], uint32_t u) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Could be SSE optimized.
|
||||||
|
inline uint32_t Float4ToUint8x4(const float f[4]) {
|
||||||
|
int i4[4];
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
if (f[i] > 1.0f) {
|
||||||
|
i4[i] = 255;
|
||||||
|
} else if (f[i] < 0.0f) {
|
||||||
|
i4[i] = 0;
|
||||||
|
} else {
|
||||||
|
i4[i] = (int)(f[i] * 255.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i4[0] | (i4[1] << 8) | (i4[2] << 16) | (i4[3] << 24);
|
||||||
|
}
|
||||||
|
|
||||||
inline void Uint8x3ToFloat4_AlphaUint8(float f[4], uint32_t u, uint8_t alpha) {
|
inline void Uint8x3ToFloat4_AlphaUint8(float f[4], uint32_t u, uint8_t alpha) {
|
||||||
#if defined(_M_SSE) || PPSSPP_PLATFORM(ARM_NEON)
|
#if defined(_M_SSE) || PPSSPP_PLATFORM(ARM_NEON)
|
||||||
Uint8x4ToFloat4(f, (u & 0xFFFFFF) | (alpha << 24));
|
Uint8x4ToFloat4(f, (u & 0xFFFFFF) | (alpha << 24));
|
||||||
|
|
|
@ -851,7 +851,7 @@ void VulkanQueueRunner::LogRenderPass(const VKRStep &pass) {
|
||||||
ILOG(" BindPipeline(%x)", (int)(intptr_t)cmd.pipeline.pipeline);
|
ILOG(" BindPipeline(%x)", (int)(intptr_t)cmd.pipeline.pipeline);
|
||||||
break;
|
break;
|
||||||
case VKRRenderCommand::BLEND:
|
case VKRRenderCommand::BLEND:
|
||||||
ILOG(" Blend(%f, %f, %f, %f)", cmd.blendColor.color[0], cmd.blendColor.color[1], cmd.blendColor.color[2], cmd.blendColor.color[3]);
|
ILOG(" BlendColor(%08x)", cmd.blendColor.color);
|
||||||
break;
|
break;
|
||||||
case VKRRenderCommand::CLEAR:
|
case VKRRenderCommand::CLEAR:
|
||||||
ILOG(" Clear");
|
ILOG(" Clear");
|
||||||
|
@ -1015,8 +1015,12 @@ void VulkanQueueRunner::PerformRenderPass(const VKRStep &step, VkCommandBuffer c
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VKRRenderCommand::BLEND:
|
case VKRRenderCommand::BLEND:
|
||||||
vkCmdSetBlendConstants(cmd, c.blendColor.color);
|
{
|
||||||
|
float bc[4];
|
||||||
|
Uint8x4ToFloat4(bc, c.blendColor.color);
|
||||||
|
vkCmdSetBlendConstants(cmd, bc);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case VKRRenderCommand::PUSH_CONSTANTS:
|
case VKRRenderCommand::PUSH_CONSTANTS:
|
||||||
vkCmdPushConstants(cmd, c.push.pipelineLayout, c.push.stages, c.push.offset, c.push.size, c.push.data);
|
vkCmdPushConstants(cmd, c.push.pipelineLayout, c.push.stages, c.push.offset, c.push.size, c.push.data);
|
||||||
|
|
|
@ -141,7 +141,7 @@ struct VkRenderData {
|
||||||
uint8_t stencilRef;
|
uint8_t stencilRef;
|
||||||
} stencil;
|
} stencil;
|
||||||
struct {
|
struct {
|
||||||
float color[4];
|
uint32_t color;
|
||||||
} blendColor;
|
} blendColor;
|
||||||
struct {
|
struct {
|
||||||
VkPipelineLayout pipelineLayout;
|
VkPipelineLayout pipelineLayout;
|
||||||
|
|
|
@ -164,10 +164,10 @@ public:
|
||||||
curRenderStep_->commands.push_back(data);
|
curRenderStep_->commands.push_back(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetBlendFactor(float color[4]) {
|
void SetBlendFactor(uint32_t color) {
|
||||||
_dbg_assert_(G3D, curRenderStep_ && curRenderStep_->stepType == VKRStepType::RENDER);
|
_dbg_assert_(G3D, curRenderStep_ && curRenderStep_->stepType == VKRStepType::RENDER);
|
||||||
VkRenderData data{ VKRRenderCommand::BLEND };
|
VkRenderData data{ VKRRenderCommand::BLEND };
|
||||||
CopyFloat4(data.blendColor.color, color);
|
data.blendColor.color = color;
|
||||||
curRenderStep_->commands.push_back(data);
|
curRenderStep_->commands.push_back(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1055,7 +1055,8 @@ void VKContext::SetViewports(int count, Viewport *viewports) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VKContext::SetBlendFactor(float color[4]) {
|
void VKContext::SetBlendFactor(float color[4]) {
|
||||||
renderManager_.SetBlendFactor(color);
|
uint32_t col = Float4ToUint8x4(color);
|
||||||
|
renderManager_.SetBlendFactor(col);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VKContext::SetStencilRef(uint8_t stencilRef) {
|
void VKContext::SetStencilRef(uint8_t stencilRef) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue