Skip to content

Commit

Permalink
State management fixes. DBZ toon shader effect now works.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Feb 17, 2017
1 parent b7f58a6 commit 0616856
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
8 changes: 0 additions & 8 deletions GPU/D3D11/DepalettizeShaderD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,13 @@ DepalShaderCacheD3D11::DepalShaderCacheD3D11(ID3D11Device *device, ID3D11DeviceC
std::vector<uint8_t> vsByteCode;
vertexShader_ = CreateVertexShaderD3D11(device, depalVShaderHLSL, strlen(depalVShaderHLSL), &vsByteCode);
device_->CreateInputLayout(g_DepalVertexElements, ARRAY_SIZE(g_DepalVertexElements), vsByteCode.data(), vsByteCode.size(), &inputLayout_);

D3D11_SAMPLER_DESC sampDesc{};
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
device_->CreateSamplerState(&sampDesc, &clutSampler);
}

DepalShaderCacheD3D11::~DepalShaderCacheD3D11() {
Clear();
if (vertexShader_) {
vertexShader_->Release();
}
clutSampler->Release();
}

u32 DepalShaderCacheD3D11::GenerateShaderID(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat) {
Expand Down
2 changes: 0 additions & 2 deletions GPU/D3D11/DepalettizeShaderD3D11.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class DepalShaderCacheD3D11 {
ID3D11VertexShader *GetDepalettizeVertexShader() { return vertexShader_; }
ID3D11InputLayout *GetInputLayout() { return inputLayout_; }
ID3D11ShaderResourceView *GetClutTexture(GEPaletteFormat clutFormat, const u32 clutHash, u32 *rawClut);
ID3D11SamplerState *GetClutSampler() { return clutSampler; }
void Clear();
void Decimate();

Expand All @@ -62,7 +61,6 @@ class DepalShaderCacheD3D11 {
ID3D11DeviceContext *context_;
ID3D11VertexShader *vertexShader_ = nullptr;
ID3D11InputLayout *inputLayout_ = nullptr;
ID3D11SamplerState *clutSampler = nullptr;

std::map<u32, DepalShaderD3D11 *> cache_;
std::map<u32, DepalTextureD3D11 *> texCache_;
Expand Down
2 changes: 2 additions & 0 deletions GPU/D3D11/DrawEngineD3D11.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ class DrawEngineD3D11 : public DrawEngineCommon {
std::map<uint32_t, ID3D11RasterizerState *> rasterCache_;

// Keep the depth state between ApplyDrawState and ApplyDrawStateLate
ID3D11RasterizerState *rasterState_;
ID3D11BlendState *blendState_;
ID3D11DepthStencilState *depthStencilState_;

// State keys
Expand Down
16 changes: 10 additions & 6 deletions GPU/D3D11/StateMappingD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ void DrawEngineD3D11::ApplyDrawState(int prim) {
if (vpAndScissor.dirtyProj) {
gstate_c.Dirty(DIRTY_PROJMATRIX);
}
context_->RSSetViewports(1, &vp);

D3D11_RECT &scissor = dynState_.scissor;
if (vpAndScissor.scissorEnable) {
Expand All @@ -344,7 +343,6 @@ void DrawEngineD3D11::ApplyDrawState(int prim) {
scissor.right = framebufferManager_->GetRenderWidth();
scissor.bottom = framebufferManager_->GetRenderHeight();
}
context_->RSSetScissorRects(1, &scissor);

if (gstate_c.IsDirty(DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS) && !gstate.isModeClear() && gstate.isTextureMapEnabled()) {
textureCache_->SetTexture();
Expand Down Expand Up @@ -378,9 +376,7 @@ void DrawEngineD3D11::ApplyDrawState(int prim) {
bs = blendIter->second;
}

float blendColor[4];
Uint8x4ToFloat4(blendColor, dynState_.blendColor);
context_->OMSetBlendState(bs, blendColor, 0xFFFFFFFF);
blendState_ = bs;

auto depthIter = depthStencilCache_.find(keys_.depthStencil.value);
if (depthIter == depthStencilCache_.end()) {
Expand Down Expand Up @@ -415,7 +411,7 @@ void DrawEngineD3D11::ApplyDrawState(int prim) {
} else {
rs = rasterIter->second;
}
context_->RSSetState(rs);
rasterState_ = rs;
}

void DrawEngineD3D11::ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRef) {
Expand All @@ -429,5 +425,13 @@ void DrawEngineD3D11::ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRe
}
textureCache_->ApplyTexture();
}

// Need to do this AFTER ApplyTexture because the process of depalettization can ruin the blend state.
float blendColor[4];
Uint8x4ToFloat4(blendColor, dynState_.blendColor);
context_->RSSetViewports(1, &dynState_.viewport);
context_->RSSetScissorRects(1, &dynState_.scissor);
context_->RSSetState(rasterState_);
context_->OMSetBlendState(blendState_, blendColor, 0xFFFFFFFF);
context_->OMSetDepthStencilState(depthStencilState_, applyStencilRef ? stencilRef : dynState_.stencilRef);
}
1 change: 0 additions & 1 deletion GPU/D3D11/TextureCacheD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ void TextureCacheD3D11::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFra
shaderApply.Use(depalShaderCache_->GetDepalettizeVertexShader(), depalShaderCache_->GetInputLayout());

context_->PSSetShaderResources(1, 1, &clutTexture);
context_->PSSetSamplers(1, 1, &stockD3D11.samplerPoint2DWrap);
framebufferManagerD3D11_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_SKIP_COPY);
context_->PSSetSamplers(0, 1, &stockD3D11.samplerPoint2DWrap);
draw_->BindFramebufferAsRenderTarget(depalFBO);
Expand Down

0 comments on commit 0616856

Please sign in to comment.