Move sampler state setting outside the drawQuad utility functions.

Use linear filtering for various buffer copies, improves visual quality a lot.

Some other tiny changes as well.


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5891 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
NeoBrainX 2010-07-17 15:18:52 +00:00
parent 5abed9d5a4
commit 15eb779c01
7 changed files with 46 additions and 43 deletions

View file

@ -197,7 +197,7 @@ int CD3DFont::Init()
context->Unmap(buftex, 0);
hr = D3D::device->CreateShaderResourceView(buftex, NULL, &m_pTexture);
if (FAILED(hr)) PanicAlert("Failed to create shader resource view at %s %d\n", __FILE__, __LINE__);
buftex->Release();
SAFE_RELEASE(buftex);
SelectObject(hDC, hOldbmBitmap);
DeleteObject(hbmBitmap);
@ -225,7 +225,7 @@ int CD3DFont::Init()
};
hr = D3D::device->CreateInputLayout(desc, 3, vsbytecode->Data(), vsbytecode->Size(), &m_InputLayout);
if (FAILED(hr)) PanicAlert("Failed to create input layout, %s %d\n", __FILE__, __LINE__);
vsbytecode->Release();
SAFE_RELEASE(vsbytecode);
D3D11_BLEND_DESC blenddesc;
blenddesc.AlphaToCoverageEnable = FALSE;
@ -408,8 +408,8 @@ ID3D11Buffer* CreateQuadVertexBuffer(unsigned int size, void* data)
return vb;
}
ID3D11SamplerState* stqsamplerstate = NULL;
ID3D11SamplerState* stsqsamplerstate = NULL;
ID3D11SamplerState* linear_copy_sampler = NULL;
ID3D11SamplerState* point_copy_sampler = NULL;
ID3D11Buffer* stqvb = NULL;
ID3D11Buffer* stsqvb = NULL;
ID3D11Buffer* clearvb = NULL;
@ -421,10 +421,15 @@ typedef struct { float x,y,z; u32 col; } ClearVertex;
void InitUtils()
{
float border[4] = { 0.f, 0.f, 0.f, 0.f };
D3D11_SAMPLER_DESC samDesc = CD3D11_SAMPLER_DESC(D3D11_FILTER_MIN_MAG_MIP_POINT, D3D11_TEXTURE_ADDRESS_CLAMP, D3D11_TEXTURE_ADDRESS_CLAMP, D3D11_TEXTURE_ADDRESS_CLAMP, 0.f, 16, D3D11_COMPARISON_ALWAYS, border, -D3D11_FLOAT32_MAX, D3D11_FLOAT32_MAX);
HRESULT hr = D3D::device->CreateSamplerState(&samDesc, &stqsamplerstate);
D3D11_SAMPLER_DESC samDesc = CD3D11_SAMPLER_DESC(D3D11_FILTER_MIN_MAG_MIP_POINT, D3D11_TEXTURE_ADDRESS_BORDER, D3D11_TEXTURE_ADDRESS_BORDER, D3D11_TEXTURE_ADDRESS_BORDER, 0.f, 1, D3D11_COMPARISON_ALWAYS, border, -D3D11_FLOAT32_MAX, D3D11_FLOAT32_MAX);
HRESULT hr = D3D::device->CreateSamplerState(&samDesc, &point_copy_sampler);
if (FAILED(hr)) PanicAlert("Failed to create sampler state at %s %d\n", __FILE__, __LINE__);
else SetDebugObjectName((ID3D11DeviceChild*)stqsamplerstate, "sampler state of drawShadedTexQuad");
else SetDebugObjectName((ID3D11DeviceChild*)point_copy_sampler, "point copy sampler state");
samDesc = CD3D11_SAMPLER_DESC(D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D11_TEXTURE_ADDRESS_BORDER, D3D11_TEXTURE_ADDRESS_BORDER, D3D11_TEXTURE_ADDRESS_BORDER, 0.f, 1, D3D11_COMPARISON_ALWAYS, border, -D3D11_FLOAT32_MAX, D3D11_FLOAT32_MAX);
hr = D3D::device->CreateSamplerState(&samDesc, &linear_copy_sampler);
if (FAILED(hr)) PanicAlert("Failed to create sampler state at %s %d\n", __FILE__, __LINE__);
else SetDebugObjectName((ID3D11DeviceChild*)linear_copy_sampler, "linear copy sampler state");
stqvb = CreateQuadVertexBuffer(4*sizeof(STQVertex), NULL);
CHECK(stqvb!=NULL, "Create vertex buffer of drawShadedTexQuad");
@ -437,22 +442,27 @@ void InitUtils()
clearvb = CreateQuadVertexBuffer(4*sizeof(ClearVertex), NULL);
CHECK(clearvb!=NULL, "Create vertex buffer of drawClearQuad");
SetDebugObjectName((ID3D11DeviceChild*)clearvb, "vertex buffer of drawClearQuad");
samDesc = CD3D11_SAMPLER_DESC(D3D11_FILTER_MIN_MAG_MIP_POINT, D3D11_TEXTURE_ADDRESS_CLAMP, D3D11_TEXTURE_ADDRESS_CLAMP, D3D11_TEXTURE_ADDRESS_CLAMP, 0.f, 16, D3D11_COMPARISON_ALWAYS, border, -D3D11_FLOAT32_MAX, D3D11_FLOAT32_MAX);
hr = D3D::device->CreateSamplerState(&samDesc, &stsqsamplerstate);
if (FAILED(hr)) PanicAlert("Failed to create sampler state at %s %d\n", __FILE__, __LINE__);
else SetDebugObjectName((ID3D11DeviceChild*)stsqsamplerstate, "sampler state of drawShadedTexSubQuad");
}
void ShutdownUtils()
{
SAFE_RELEASE(stqsamplerstate);
SAFE_RELEASE(stsqsamplerstate);
SAFE_RELEASE(point_copy_sampler);
SAFE_RELEASE(linear_copy_sampler);
SAFE_RELEASE(stqvb);
SAFE_RELEASE(stsqvb);
SAFE_RELEASE(clearvb);
}
void SetPointCopySampler()
{
D3D::context->PSSetSamplers(0, 1, &point_copy_sampler);
}
void SetLinearCopySampler()
{
D3D::context->PSSetSamplers(0, 1, &linear_copy_sampler);
}
void drawShadedTexQuad(ID3D11ShaderResourceView* texture,
const D3D11_RECT* rSource,
int SourceWidth,
@ -495,7 +505,6 @@ void drawShadedTexQuad(ID3D11ShaderResourceView* texture,
D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
D3D::context->IASetInputLayout(layout);
D3D::context->IASetVertexBuffers(0, 1, &stqvb, &stride, &offset);
D3D::context->PSSetSamplers(0, 1, &stqsamplerstate);
D3D::context->PSSetShader(PShader, NULL, 0);
D3D::context->PSSetShaderResources(0, 1, &texture);
D3D::context->VSSetShader(Vshader, NULL, 0);
@ -555,7 +564,6 @@ void drawShadedTexSubQuad(ID3D11ShaderResourceView* texture,
context->IASetVertexBuffers(0, 1, &stsqvb, &stride, &offset);
context->IASetInputLayout(layout);
context->PSSetShaderResources(0, 1, &texture);
context->PSSetSamplers(0, 1, &stsqsamplerstate);
context->PSSetShader(PShader, NULL, 0);
context->VSSetShader(Vshader, NULL, 0);
stateman->Apply();

View file

@ -61,6 +61,9 @@ namespace D3D
void InitUtils();
void ShutdownUtils();
void SetPointCopySampler();
void SetLinearCopySampler();
void drawShadedTexQuad(ID3D11ShaderResourceView* texture,
const D3D11_RECT* rSource,
int SourceWidth,

View file

@ -25,7 +25,6 @@
#include "VertexShaderCache.h"
FramebufferManager FBManager;
ID3D11SamplerState* copytoVirtualXFBsampler = NULL;
D3DTexture2D* &FramebufferManager::GetEFBColorTexture() { return m_efb.color_tex; }
ID3D11Texture2D* &FramebufferManager::GetEFBColorStagingBuffer() { return m_efb.color_staging_buf; }
@ -56,12 +55,11 @@ void FramebufferManager::Create()
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_efb.color_staging_buf, "EFB color staging texture (used for Renderer::AccessEFB)");
// EFB depth buffer
// TODO: Only bind as shader resource if EFB access enabled
texdesc = CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R24G8_TYPELESS, target_width, target_height, 1, 1, D3D11_BIND_DEPTH_STENCIL|D3D11_BIND_SHADER_RESOURCE);
hr = D3D::device->CreateTexture2D(&texdesc, NULL, &buf);
CHECK(hr==S_OK, "create EFB depth texture (size: %dx%d; hr=%#x)", target_width, target_height, hr);
m_efb.depth_tex = new D3DTexture2D(buf, (D3D11_BIND_FLAG)(D3D11_BIND_DEPTH_STENCIL|D3D11_BIND_SHADER_RESOURCE), DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT);
buf->Release();
SAFE_RELEASE(buf);
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_efb.depth_tex->GetTex(), "EFB depth texture");
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_efb.depth_tex->GetDSV(), "EFB depth texture depth stencil view");
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_efb.depth_tex->GetSRV(), "EFB depth texture shader resource view");
@ -71,7 +69,7 @@ void FramebufferManager::Create()
hr = D3D::device->CreateTexture2D(&texdesc, NULL, &buf);
CHECK(hr==S_OK, "create EFB depth read texture (hr=%#x)", hr);
m_efb.depth_read_texture = new D3DTexture2D(buf, D3D11_BIND_RENDER_TARGET);
buf->Release();
SAFE_RELEASE(buf);
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_efb.depth_read_texture->GetTex(), "EFB depth read texture (used in Renderer::AccessEFB)");
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_efb.depth_read_texture->GetRTV(), "EFB depth read texture render target view (used in Renderer::AccessEFB)");
@ -80,13 +78,6 @@ void FramebufferManager::Create()
hr = D3D::device->CreateTexture2D(&texdesc, NULL, &m_efb.depth_staging_buf);
CHECK(hr==S_OK, "create EFB depth staging buffer (hr=%#x)", hr);
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_efb.depth_staging_buf, "EFB depth staging texture (used for Renderer::AccessEFB)");
// sampler state for FramebufferManager::copyToVirtualXFB
float border[4] = {0.f, 0.f, 0.f, 0.f};
D3D11_SAMPLER_DESC samplerdesc = CD3D11_SAMPLER_DESC(D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D11_TEXTURE_ADDRESS_CLAMP, D3D11_TEXTURE_ADDRESS_CLAMP, D3D11_TEXTURE_ADDRESS_CLAMP, 0.f, 1, D3D11_COMPARISON_ALWAYS, border, -D3D11_FLOAT32_MAX, D3D11_FLOAT32_MAX);
hr = D3D::device->CreateSamplerState(&samplerdesc, &copytoVirtualXFBsampler);
CHECK(hr==S_OK, "Create sampler state for FramebufferManager::copyToVirtualXFB");
D3D::SetDebugObjectName((ID3D11DeviceChild*)copytoVirtualXFBsampler, "sampler state used for FramebufferManager::copyToVirtualXFB");
}
void FramebufferManager::Destroy()
@ -97,8 +88,6 @@ void FramebufferManager::Destroy()
SAFE_RELEASE(m_efb.depth_staging_buf);
SAFE_RELEASE(m_efb.depth_read_texture);
SAFE_RELEASE(copytoVirtualXFBsampler);
for (VirtualXFBListType::iterator it = m_virtualXFBList.begin(); it != m_virtualXFBList.end(); ++it)
SAFE_RELEASE(it->xfbSource.tex);
@ -252,7 +241,7 @@ void FramebufferManager::copyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight
if (m_virtualXFBList.size() >= MAX_VIRTUAL_XFB)
{
PanicAlert("Requested creating a new virtual XFB although the maximum number has already been reached! Report this to the devs");
newVirt.xfbSource.tex->Release();
SAFE_RELEASE(newVirt.xfbSource.tex);
return;
// TODO, possible alternative to failing: just delete the oldest virtual XFB:
// m_virtualXFBList.back().xfbSource.tex->Release();
@ -268,8 +257,8 @@ void FramebufferManager::copyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight
D3D11_RECT sourcerect = CD3D11_RECT(efbSource.left, efbSource.top, efbSource.right, efbSource.bottom);
D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)target_width, (float)target_height);
D3D::context->RSSetViewports(1, &vp);
D3D::context->PSSetSamplers(0, 1, &copytoVirtualXFBsampler);
D3D::context->OMSetRenderTargets(1, &xfbTex->GetRTV(), NULL);
D3D::SetLinearCopySampler();
D3D::drawShadedTexQuad(GetEFBColorTexture()->GetSRV(), &sourcerect,
Renderer::GetFullTargetWidth(), Renderer::GetFullTargetHeight(),
PixelShaderCache::GetColorCopyProgram(), VertexShaderCache::GetSimpleVertexShader(),

View file

@ -131,7 +131,7 @@ void EmuGfxState::ApplyState()
// input layout (only needs to be updated if the vertex shader signature changed)
if (vshaderchanged)
{
if (inp_layout) inp_layout->Release();
SAFE_RELEASE(inp_layout);
hr = D3D::device->CreateInputLayout(inp_elems, num_inp_elems, vsbytecode->Data(), vsbytecode->Size(), &inp_layout);
if (FAILED(hr)) PanicAlert("Failed to create input layout, %s %d\n", __FILE__, __LINE__);
SetDebugObjectName((ID3D11DeviceChild*)inp_layout, "an input layout of EmuGfxState");
@ -199,7 +199,7 @@ void EmuGfxState::ApplyState()
if (FAILED(hr)) PanicAlert("Failed to create blend state at %s %d\n", __FILE__, __LINE__);
stateman->PushBlendState(blstate);
SetDebugObjectName((ID3D11DeviceChild*)blstate, "a blend state of EmuGfxState");
blstate->Release();
SAFE_RELEASE(blstate);
rastdesc.FillMode = (g_ActiveConfig.bWireFrame) ? D3D11_FILL_WIREFRAME : D3D11_FILL_SOLID;
ID3D11RasterizerState* raststate;
@ -207,14 +207,14 @@ void EmuGfxState::ApplyState()
if (FAILED(hr)) PanicAlert("Failed to create rasterizer state at %s %d\n", __FILE__, __LINE__);
SetDebugObjectName((ID3D11DeviceChild*)raststate, "a rasterizer state of EmuGfxState");
stateman->PushRasterizerState(raststate);
raststate->Release();
SAFE_RELEASE(raststate);
ID3D11DepthStencilState* depth_state;
hr = device->CreateDepthStencilState(&depthdesc, &depth_state);
if (SUCCEEDED(hr)) SetDebugObjectName((ID3D11DeviceChild*)depth_state, "a depth-stencil state of EmuGfxState");
else PanicAlert("Failed to create depth state at %s %d\n", __FILE__, __LINE__);
D3D::stateman->PushDepthState(depth_state);
depth_state->Release();
SAFE_RELEASE(depth_state);
context->PSSetShader(pixelshader, NULL, 0);
context->VSSetShader(vertexshader, NULL, 0);
@ -316,7 +316,8 @@ template<typename T> AutoState<T>::AutoState(const AutoState<T> &source)
template<typename T> AutoState<T>::~AutoState()
{
((IUnknown*)state)->Release();
if(state) ((T*)state)->Release();
state = NULL;
}
StateManager::StateManager() : cur_blendstate(NULL), cur_depthstate(NULL), cur_raststate(NULL) {}

View file

@ -645,7 +645,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
D3D::context->RSSetViewports(1, &vp);
D3D::context->PSSetConstantBuffers(0, 1, &access_efb_cbuf);
D3D::context->OMSetRenderTargets(1, &FBManager.GetEFBDepthReadTexture()->GetRTV(), NULL);
// D3D::ChangeSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); // TODO!
D3D::SetPointCopySampler();
D3D::drawShadedTexQuad(FBManager.GetEFBDepthTexture()->GetSRV(),
&RectToLock,
Renderer::GetFullTargetWidth(),
@ -654,7 +654,6 @@ u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
VertexShaderCache::GetSimpleVertexShader(),
VertexShaderCache::GetSimpleInputLayout());
// D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
D3D::context->OMSetRenderTargets(1, &FBManager.GetEFBColorTexture()->GetRTV(), FBManager.GetEFBDepthTexture()->GetDSV());
RestoreAPIState();
RectToLock = CD3D11_RECT(0, 0, 4, 4);
@ -881,8 +880,9 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
D3D::context->RSSetViewports(1, &vp);
D3D::context->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV(), NULL);
// TODO: Enable linear filtering here
// activate linear filtering for the buffer copies
D3D::SetLinearCopySampler();
if(g_ActiveConfig.bUseXFB)
{
const XFBSource* xfbSource;

View file

@ -298,7 +298,7 @@ TextureCache::TCacheEntry* TextureCache::Load(unsigned int stage, u32 address, u
CHECK(entry.texture!=NULL, "Create texture of the TextureCache");
D3D::SetDebugObjectName((ID3D11DeviceChild*)entry.texture->GetTex(), "a texture of the TextureCache");
D3D::SetDebugObjectName((ID3D11DeviceChild*)entry.texture->GetSRV(), "shader resource view of a texture of the TextureCache");
pTexture->Release();
SAFE_RELEASE(pTexture);
if (TexLevels != 1) D3D::ReplaceRGBATexture2D(entry.texture->GetTex(), temp, width, height, expandedWidth, 0, usage);
}
@ -547,7 +547,9 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, boo
TargetRectangle targetSource = Renderer::ConvertEFBRectangle(source_rect);
D3D11_RECT sourcerect = CD3D11_RECT(targetSource.left, targetSource.top, targetSource.right, targetSource.bottom);
// TODO: Use linear filtering if (bScaleByHalf), else use point filtering
// Use linear filtering if (bScaleByHalf), use point filtering otherwise
if (bScaleByHalf) D3D::SetLinearCopySampler();
else D3D::SetPointCopySampler();
D3D::stateman->PushBlendState(efbcopyblendstate);
D3D::stateman->PushRasterizerState(efbcopyraststate);

View file

@ -256,8 +256,8 @@ void Shutdown()
Fifo_Shutdown();
VertexManager::Shutdown();
TextureCache::Shutdown();
Renderer::Shutdown();
D3D::ShutdownUtils();
Renderer::Shutdown();
EmuWindow::Close();
s_PluginInitialized = false;
}