Vulkan blend factor: Bugfix and minor optimization

This commit is contained in:
Henrik Rydgård 2019-10-13 21:15:01 +02:00
parent 29950c0ad5
commit 1e3711ee66
7 changed files with 36 additions and 10 deletions

View file

@ -126,7 +126,15 @@ static int SetupVertexAttribsPretransformed(VkVertexInputAttributeDescription at
}
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,

View file

@ -413,8 +413,6 @@ void DrawEngineVulkan::ApplyDrawStateLate(VulkanRenderManager *renderManager, bo
renderManager->SetStencilParams(dynState_.stencilWriteMask, dynState_.stencilCompareMask, applyStencilRef ? stencilRef : dynState_.stencilRef);
}
if (gstate_c.IsDirty(DIRTY_BLEND_STATE) && useBlendConstant) {
float bc[4];
Uint8x4ToFloat4(bc, dynState_.blendColor);
renderManager->SetBlendFactor(bc);
renderManager->SetBlendFactor(dynState_.blendColor);
}
}

View file

@ -46,6 +46,21 @@ inline void Uint8x4ToFloat4(float f[4], uint32_t u) {
#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) {
#if defined(_M_SSE) || PPSSPP_PLATFORM(ARM_NEON)
Uint8x4ToFloat4(f, (u & 0xFFFFFF) | (alpha << 24));

View file

@ -851,7 +851,7 @@ void VulkanQueueRunner::LogRenderPass(const VKRStep &pass) {
ILOG(" BindPipeline(%x)", (int)(intptr_t)cmd.pipeline.pipeline);
break;
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;
case VKRRenderCommand::CLEAR:
ILOG(" Clear");
@ -1015,8 +1015,12 @@ void VulkanQueueRunner::PerformRenderPass(const VKRStep &step, VkCommandBuffer c
break;
case VKRRenderCommand::BLEND:
vkCmdSetBlendConstants(cmd, c.blendColor.color);
{
float bc[4];
Uint8x4ToFloat4(bc, c.blendColor.color);
vkCmdSetBlendConstants(cmd, bc);
break;
}
case VKRRenderCommand::PUSH_CONSTANTS:
vkCmdPushConstants(cmd, c.push.pipelineLayout, c.push.stages, c.push.offset, c.push.size, c.push.data);

View file

@ -141,7 +141,7 @@ struct VkRenderData {
uint8_t stencilRef;
} stencil;
struct {
float color[4];
uint32_t color;
} blendColor;
struct {
VkPipelineLayout pipelineLayout;

View file

@ -164,10 +164,10 @@ public:
curRenderStep_->commands.push_back(data);
}
void SetBlendFactor(float color[4]) {
void SetBlendFactor(uint32_t color) {
_dbg_assert_(G3D, curRenderStep_ && curRenderStep_->stepType == VKRStepType::RENDER);
VkRenderData data{ VKRRenderCommand::BLEND };
CopyFloat4(data.blendColor.color, color);
data.blendColor.color = color;
curRenderStep_->commands.push_back(data);
}

View file

@ -1055,7 +1055,8 @@ void VKContext::SetViewports(int count, Viewport *viewports) {
}
void VKContext::SetBlendFactor(float color[4]) {
renderManager_.SetBlendFactor(color);
uint32_t col = Float4ToUint8x4(color);
renderManager_.SetBlendFactor(col);
}
void VKContext::SetStencilRef(uint8_t stencilRef) {