Permalink
Browse files

Use dirty-flags more in Vulkan state setting

  • Loading branch information...
hrydgard committed Aug 14, 2017
1 parent 776c9e3 commit 5a653346463d590e6c56f9da4816b2def96b1bfd
@@ -457,10 +457,6 @@ void DrawEngineD3D11::ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRe
textureCache_->ApplyTexture();
}
// Need to do this AFTER ApplyTexture because the process of depallettization can ruin the blend state.
float blendColor[4];
Uint8x4ToFloat4(blendColor, dynState_.blendColor);
// we go through Draw here because it automatically handles screen rotation, as needed in UWP on mobiles.
if (gstate_c.IsDirty(DIRTY_VIEWPORTSCISSOR_STATE)) {
draw_->SetViewports(1, &dynState_.viewport);
@@ -470,13 +466,16 @@ void DrawEngineD3D11::ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRe
context_->RSSetState(rasterState_);
}
if (gstate_c.IsDirty(DIRTY_BLEND_STATE)) {
// Need to do this AFTER ApplyTexture because the process of depallettization can ruin the blend state.
float blendColor[4];
Uint8x4ToFloat4(blendColor, dynState_.blendColor);
if (device1_) {
context1_->OMSetBlendState(blendState1_, blendColor, 0xFFFFFFFF);
} else {
context_->OMSetBlendState(blendState_, blendColor, 0xFFFFFFFF);
}
}
if (gstate_c.IsDirty(DIRTY_DEPTHSTENCIL_STATE)) {
if (gstate_c.IsDirty(DIRTY_DEPTHSTENCIL_STATE) || applyStencilRef) {
context_->OMSetDepthStencilState(depthStencilState_, applyStencilRef ? stencilRef : dynState_.stencilRef);
}
gstate_c.Clean(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_BLEND_STATE);
@@ -650,19 +650,7 @@ void DrawEngineVulkan::DoFlush() {
}
ConvertStateToVulkanKey(*framebufferManager_, shaderManager_, prim, pipelineKey_, dynState_);
// TODO: Dirty-flag these.
vkCmdSetScissor(cmd, 0, 1, &dynState_.scissor);
vkCmdSetViewport(cmd, 0, 1, &dynState_.viewport);
if (dynState_.useStencil) {
vkCmdSetStencilWriteMask(cmd, VK_STENCIL_FRONT_AND_BACK, dynState_.stencilWriteMask);
vkCmdSetStencilCompareMask(cmd, VK_STENCIL_FRONT_AND_BACK, dynState_.stencilCompareMask);
vkCmdSetStencilReference(cmd, VK_STENCIL_FRONT_AND_BACK, dynState_.stencilRef);
}
if (dynState_.useBlendColor) {
float bc[4];
Uint8x4ToFloat4(bc, dynState_.blendColor);
vkCmdSetBlendConstants(cmd, bc);
}
ApplyDrawStateLate(cmd, false, 0);
dirtyUniforms_ |= shaderManager_->UpdateUniforms();
@@ -751,23 +739,8 @@ void DrawEngineVulkan::DoFlush() {
}
ConvertStateToVulkanKey(*framebufferManager_, shaderManager_, prim, pipelineKey_, dynState_);
// TODO: Dirty-flag these.
vkCmdSetScissor(cmd, 0, 1, &dynState_.scissor);
vkCmdSetViewport(cmd, 0, 1, &dynState_.viewport);
if (dynState_.useStencil) {
vkCmdSetStencilWriteMask(cmd, VK_STENCIL_FRONT_AND_BACK, dynState_.stencilWriteMask);
vkCmdSetStencilCompareMask(cmd, VK_STENCIL_FRONT_AND_BACK, dynState_.stencilCompareMask);
}
if (result.setStencil) {
vkCmdSetStencilReference(cmd, VK_STENCIL_FRONT_AND_BACK, result.stencilValue);
} else if (dynState_.useStencil) {
vkCmdSetStencilReference(cmd, VK_STENCIL_FRONT_AND_BACK, dynState_.stencilRef);
}
if (dynState_.useBlendColor) {
float bc[4];
Uint8x4ToFloat4(bc, dynState_.blendColor);
vkCmdSetBlendConstants(cmd, bc);
}
ApplyDrawStateLate(cmd, result.setStencil, result.stencilValue);
dirtyUniforms_ |= shaderManager_->UpdateUniforms();
shaderManager_->GetShaders(prim, lastVType_, &vshader, &fshader, useHWTransform);
@@ -127,7 +127,7 @@ class DrawEngineVulkan : public DrawEngineCommon {
private:
struct FrameData;
void ApplyDrawStateLate();
void ApplyDrawStateLate(VkCommandBuffer cmd, bool applyStencilRef, uint8_t stencilRef);
void ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManager, ShaderManagerVulkan *shaderManager, int prim, VulkanPipelineRasterStateKey &key, VulkanDynamicState &dynState);
void InitDeviceObjects();
@@ -17,6 +17,7 @@
#include "Common/Vulkan/VulkanLoader.h"
#include "math/dataconv.h"
#include "GPU/Math3D.h"
#include "GPU/GPUState.h"
#include "GPU/ge_constants.h"
@@ -235,7 +236,6 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag
}
if (gstate_c.IsDirty(DIRTY_RASTER_STATE)) {
gstate_c.Clean(DIRTY_RASTER_STATE);
if (gstate.isModeClear()) {
key.cullMode = VK_CULL_MODE_NONE;
} else {
@@ -246,7 +246,6 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag
}
if (gstate_c.IsDirty(DIRTY_DEPTHSTENCIL_STATE)) {
gstate_c.Clean(DIRTY_DEPTHSTENCIL_STATE);
if (gstate.isModeClear()) {
key.depthTestEnable = true;
key.depthCompareOp = VK_COMPARE_OP_ALWAYS;
@@ -328,7 +327,6 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag
}
if (gstate_c.IsDirty(DIRTY_VIEWPORTSCISSOR_STATE)) {
gstate_c.Clean(DIRTY_VIEWPORTSCISSOR_STATE);
ViewportAndScissor vpAndScissor;
ConvertViewportAndScissor(useBufferedRendering,
fbManager.GetRenderWidth(), fbManager.GetRenderHeight(),
@@ -373,7 +371,7 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag
}
void DrawEngineVulkan::ApplyDrawStateLate() {
void DrawEngineVulkan::ApplyDrawStateLate(VkCommandBuffer cmd, bool applyStencilRef, uint8_t stencilRef) {
// At this point, we know if the vertices are full alpha or not.
// TODO: Set the nearest/linear here (since we correctly know if alpha/color tests are needed)?
if (!gstate.isModeClear()) {
@@ -388,4 +386,27 @@ void DrawEngineVulkan::ApplyDrawStateLate() {
}
*/
}
if (gstate_c.IsDirty(DIRTY_VIEWPORTSCISSOR_STATE)) {
vkCmdSetScissor(cmd, 0, 1, &dynState_.scissor);
vkCmdSetViewport(cmd, 0, 1, &dynState_.viewport);
}
if (gstate_c.IsDirty(DIRTY_DEPTHSTENCIL_STATE)) {
if (dynState_.useStencil) {
vkCmdSetStencilWriteMask(cmd, VK_STENCIL_FRONT_AND_BACK, dynState_.stencilWriteMask);
vkCmdSetStencilCompareMask(cmd, VK_STENCIL_FRONT_AND_BACK, dynState_.stencilCompareMask);
if (!applyStencilRef) {
vkCmdSetStencilReference(cmd, VK_STENCIL_FRONT_AND_BACK, dynState_.stencilRef);
}
}
}
if (applyStencilRef) {
vkCmdSetStencilReference(cmd, VK_STENCIL_FRONT_AND_BACK, stencilRef);
}
if (dynState_.useBlendColor) {
float bc[4];
Uint8x4ToFloat4(bc, dynState_.blendColor);
vkCmdSetBlendConstants(cmd, bc);
}
gstate_c.Clean(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE);
}
View
@@ -78,11 +78,11 @@ enum GECommand {
GE_CMD_TGENMATRIXNUMBER = 0x40,
GE_CMD_TGENMATRIXDATA = 0x41,
GE_CMD_VIEWPORTXSCALE = 0x42,
GE_CMD_VIEWPORTYSCALE,
GE_CMD_VIEWPORTZSCALE,
GE_CMD_VIEWPORTXCENTER,
GE_CMD_VIEWPORTYCENTER,
GE_CMD_VIEWPORTZCENTER,
GE_CMD_VIEWPORTYSCALE = 0x43,
GE_CMD_VIEWPORTZSCALE = 0x44,
GE_CMD_VIEWPORTXCENTER = 0x45,
GE_CMD_VIEWPORTYCENTER = 0x46,
GE_CMD_VIEWPORTZCENTER = 0x47,
GE_CMD_TEXSCALEU = 0x48,
GE_CMD_TEXSCALEV = 0x49,
GE_CMD_TEXOFFSETU = 0x4A,
@@ -182,8 +182,8 @@ enum GECommand {
GE_CMD_TEXBUFWIDTH5,
GE_CMD_TEXBUFWIDTH6,
GE_CMD_TEXBUFWIDTH7,
GE_CMD_CLUTADDR=0xB0,
GE_CMD_CLUTADDRUPPER,
GE_CMD_CLUTADDR = 0xB0,
GE_CMD_CLUTADDRUPPER = 0xB1,
GE_CMD_TRANSFERSRC,
GE_CMD_TRANSFERSRCW,
GE_CMD_TRANSFERDST,
@@ -1,6 +1,6 @@
#pragma once
#include <inttypes.h>
#include <cstdint>
#include <cstring>
#ifdef _M_SSE

0 comments on commit 5a65334

Please sign in to comment.