2009-02-09 21:15:56 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
* http://www.gabest.org
|
|
|
|
*
|
|
|
|
* This Program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This Program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2009-06-03 12:09:04 +00:00
|
|
|
#include "GSdx.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "GSDevice10.h"
|
|
|
|
#include "resource.h"
|
|
|
|
|
|
|
|
GSDevice10::GSDevice10()
|
2009-07-31 23:59:06 +00:00
|
|
|
{
|
|
|
|
memset(&m_state, 0, sizeof(m_state));
|
2009-09-18 00:16:52 +00:00
|
|
|
memset(&m_vs_cb_cache, 0, sizeof(m_vs_cb_cache));
|
|
|
|
memset(&m_ps_cb_cache, 0, sizeof(m_ps_cb_cache));
|
2009-07-31 23:59:06 +00:00
|
|
|
|
|
|
|
m_state.topology = D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED;
|
|
|
|
m_state.bf = -1;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSDevice10::~GSDevice10()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-10-31 01:06:23 +00:00
|
|
|
bool GSDevice10::Create(GSWnd* wnd)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-10-31 01:06:23 +00:00
|
|
|
if(!__super::Create(wnd))
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-02 23:07:30 +00:00
|
|
|
HRESULT hr = E_FAIL;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
DXGI_SWAP_CHAIN_DESC scd;
|
|
|
|
D3D10_BUFFER_DESC bd;
|
|
|
|
D3D10_SAMPLER_DESC sd;
|
|
|
|
D3D10_DEPTH_STENCIL_DESC dsd;
|
|
|
|
D3D10_RASTERIZER_DESC rd;
|
|
|
|
D3D10_BLEND_DESC bsd;
|
|
|
|
|
|
|
|
memset(&scd, 0, sizeof(scd));
|
|
|
|
|
2009-12-01 05:59:43 +00:00
|
|
|
// FIXME : Someone with a brain for DX10 and COM figure out how to make this IDXGIFactory
|
|
|
|
// call mess work. I fail at this stuff. Thanks! --air
|
|
|
|
|
|
|
|
// Also... should this be GS plugin territory, or should we incorporate it into PCSX2?
|
|
|
|
// (I'm thinking a dynamic loading of the DXGI dll, and general invocation that way).
|
|
|
|
|
|
|
|
//CComPtr<IDXGIFactory> pFactory;
|
|
|
|
//hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)(&pFactory) );
|
|
|
|
//pFactory->MakeWindowAssociation( (HWND)m_wnd->GetHandle(), DXGI_MWA_NO_WINDOW_CHANGES );
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
scd.BufferCount = 2;
|
|
|
|
scd.BufferDesc.Width = 1;
|
|
|
|
scd.BufferDesc.Height = 1;
|
|
|
|
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
|
|
//scd.BufferDesc.RefreshRate.Numerator = 60;
|
|
|
|
//scd.BufferDesc.RefreshRate.Denominator = 1;
|
|
|
|
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
2009-06-03 12:09:04 +00:00
|
|
|
scd.OutputWindow = (HWND)m_wnd->GetHandle();
|
2009-02-09 21:15:56 +00:00
|
|
|
scd.SampleDesc.Count = 1;
|
|
|
|
scd.SampleDesc.Quality = 0;
|
2009-12-01 05:59:43 +00:00
|
|
|
scd.Windowed = !!theApp.GetConfig("windowed", 1);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-10-20 11:44:43 +00:00
|
|
|
// Crashes when 2 threads work on the swapchain, as in pcsx2/wx when it provides us
|
|
|
|
// an external window handle (which could be attached to any thread other than the GS one).
|
|
|
|
// (but if we're managing our own window then it's safe to enable)
|
|
|
|
|
|
|
|
// FIXME : Figure out a way to have this flag anyway, since it's a measurable speedup (may
|
|
|
|
// not be possible though).
|
|
|
|
|
|
|
|
uint32 flags = m_wnd->IsManaged() ? D3D10_CREATE_DEVICE_SINGLETHREADED : 0;
|
2009-07-26 15:30:25 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
flags |= D3D10_CREATE_DEVICE_DEBUG;
|
|
|
|
#endif
|
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
D3D10_FEATURE_LEVEL1 levels[] =
|
|
|
|
{
|
|
|
|
D3D10_FEATURE_LEVEL_10_1,
|
|
|
|
D3D10_FEATURE_LEVEL_10_0
|
|
|
|
};
|
|
|
|
|
|
|
|
for(int i = 0; i < countof(levels); i++)
|
|
|
|
{
|
|
|
|
hr = D3D10CreateDeviceAndSwapChain1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, flags, levels[i], D3D10_1_SDK_VERSION, &scd, &m_swapchain, &m_dev);
|
|
|
|
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if(!SetFeatureLevel((D3D_FEATURE_LEVEL)levels[i], true))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
if(FAILED(hr)) return false;
|
|
|
|
|
2009-08-02 23:07:30 +00:00
|
|
|
// msaa
|
|
|
|
|
|
|
|
for(uint32 i = 2; i <= D3D10_MAX_MULTISAMPLE_SAMPLE_COUNT; i++)
|
|
|
|
{
|
|
|
|
uint32 quality[2] = {0, 0};
|
|
|
|
|
|
|
|
if(SUCCEEDED(m_dev->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM, i, &quality[0])) && quality[0] > 0
|
|
|
|
&& SUCCEEDED(m_dev->CheckMultisampleQualityLevels(DXGI_FORMAT_D32_FLOAT_S8X24_UINT, i, &quality[1])) && quality[1] > 0)
|
|
|
|
{
|
|
|
|
m_msaa_desc.Count = i;
|
|
|
|
m_msaa_desc.Quality = std::min<uint32>(quality[0] - 1, quality[1] - 1);
|
|
|
|
|
|
|
|
if(i >= m_msaa) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
// convert
|
|
|
|
|
|
|
|
D3D10_INPUT_ELEMENT_DESC il_convert[] =
|
|
|
|
{
|
|
|
|
{"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
|
|
|
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
|
|
|
};
|
|
|
|
|
2009-06-19 20:24:18 +00:00
|
|
|
hr = CompileShader(IDR_CONVERT_FX, "vs_main", NULL, &m_convert.vs, il_convert, countof(il_convert), &m_convert.il);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
for(int i = 0; i < countof(m_convert.ps); i++)
|
|
|
|
{
|
2009-06-19 20:24:18 +00:00
|
|
|
hr = CompileShader(IDR_CONVERT_FX, format("ps_main%d", i), NULL, &m_convert.ps[i]);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(&dsd, 0, sizeof(dsd));
|
|
|
|
|
|
|
|
dsd.DepthEnable = false;
|
|
|
|
dsd.StencilEnable = false;
|
|
|
|
|
|
|
|
hr = m_dev->CreateDepthStencilState(&dsd, &m_convert.dss);
|
|
|
|
|
|
|
|
memset(&bsd, 0, sizeof(bsd));
|
|
|
|
|
|
|
|
bsd.BlendEnable[0] = false;
|
|
|
|
bsd.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
|
|
|
|
|
|
|
|
hr = m_dev->CreateBlendState(&bsd, &m_convert.bs);
|
|
|
|
|
|
|
|
// merge
|
|
|
|
|
|
|
|
memset(&bd, 0, sizeof(bd));
|
|
|
|
|
|
|
|
bd.ByteWidth = sizeof(MergeConstantBuffer);
|
|
|
|
bd.Usage = D3D10_USAGE_DEFAULT;
|
|
|
|
bd.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
|
|
|
|
|
|
|
|
hr = m_dev->CreateBuffer(&bd, NULL, &m_merge.cb);
|
|
|
|
|
|
|
|
for(int i = 0; i < countof(m_merge.ps); i++)
|
|
|
|
{
|
2009-06-19 20:24:18 +00:00
|
|
|
hr = CompileShader(IDR_MERGE_FX, format("ps_main%d", i), NULL, &m_merge.ps[i]);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(&bsd, 0, sizeof(bsd));
|
|
|
|
|
|
|
|
bsd.BlendEnable[0] = true;
|
|
|
|
bsd.BlendOp = D3D10_BLEND_OP_ADD;
|
|
|
|
bsd.SrcBlend = D3D10_BLEND_SRC_ALPHA;
|
|
|
|
bsd.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
|
|
|
|
bsd.BlendOpAlpha = D3D10_BLEND_OP_ADD;
|
|
|
|
bsd.SrcBlendAlpha = D3D10_BLEND_ONE;
|
|
|
|
bsd.DestBlendAlpha = D3D10_BLEND_ZERO;
|
|
|
|
bsd.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
|
|
|
|
|
|
|
|
hr = m_dev->CreateBlendState(&bsd, &m_merge.bs);
|
|
|
|
|
|
|
|
// interlace
|
|
|
|
|
|
|
|
memset(&bd, 0, sizeof(bd));
|
|
|
|
|
|
|
|
bd.ByteWidth = sizeof(InterlaceConstantBuffer);
|
|
|
|
bd.Usage = D3D10_USAGE_DEFAULT;
|
|
|
|
bd.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
|
|
|
|
|
|
|
|
hr = m_dev->CreateBuffer(&bd, NULL, &m_interlace.cb);
|
|
|
|
|
|
|
|
for(int i = 0; i < countof(m_interlace.ps); i++)
|
|
|
|
{
|
2009-06-19 20:24:18 +00:00
|
|
|
hr = CompileShader(IDR_INTERLACE_FX, format("ps_main%d", i), NULL, &m_interlace.ps[i]);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
memset(&rd, 0, sizeof(rd));
|
|
|
|
|
|
|
|
rd.FillMode = D3D10_FILL_SOLID;
|
|
|
|
rd.CullMode = D3D10_CULL_NONE;
|
|
|
|
rd.FrontCounterClockwise = false;
|
|
|
|
rd.DepthBias = false;
|
|
|
|
rd.DepthBiasClamp = 0;
|
|
|
|
rd.SlopeScaledDepthBias = 0;
|
|
|
|
rd.DepthClipEnable = false; // ???
|
|
|
|
rd.ScissorEnable = true;
|
2009-08-02 23:07:30 +00:00
|
|
|
rd.MultisampleEnable = true;
|
2009-02-09 21:15:56 +00:00
|
|
|
rd.AntialiasedLineEnable = false;
|
|
|
|
|
|
|
|
hr = m_dev->CreateRasterizerState(&rd, &m_rs);
|
|
|
|
|
|
|
|
m_dev->RSSetState(m_rs);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
memset(&sd, 0, sizeof(sd));
|
|
|
|
|
|
|
|
sd.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
|
|
|
|
sd.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
|
|
|
|
sd.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
|
|
|
|
sd.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
|
|
|
|
sd.MaxLOD = FLT_MAX;
|
|
|
|
sd.MaxAnisotropy = 16;
|
|
|
|
sd.ComparisonFunc = D3D10_COMPARISON_NEVER;
|
|
|
|
|
|
|
|
hr = m_dev->CreateSamplerState(&sd, &m_convert.ln);
|
|
|
|
|
|
|
|
sd.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
|
|
|
|
|
|
|
|
hr = m_dev->CreateSamplerState(&sd, &m_convert.pt);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
2009-09-18 18:45:37 +00:00
|
|
|
Reset(1, 1);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
2009-09-18 00:16:52 +00:00
|
|
|
CreateTextureFX();
|
|
|
|
|
2009-11-07 17:50:48 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
memset(&dsd, 0, sizeof(dsd));
|
|
|
|
|
|
|
|
dsd.DepthEnable = false;
|
|
|
|
dsd.StencilEnable = true;
|
|
|
|
dsd.StencilReadMask = 1;
|
|
|
|
dsd.StencilWriteMask = 1;
|
|
|
|
dsd.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
|
|
|
|
dsd.FrontFace.StencilPassOp = D3D10_STENCIL_OP_REPLACE;
|
|
|
|
dsd.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
|
|
|
|
dsd.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
|
|
|
|
dsd.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
|
|
|
|
dsd.BackFace.StencilPassOp = D3D10_STENCIL_OP_REPLACE;
|
|
|
|
dsd.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
|
|
|
|
dsd.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
|
|
|
|
|
|
|
|
m_dev->CreateDepthStencilState(&dsd, &m_date.dss);
|
|
|
|
|
|
|
|
D3D10_BLEND_DESC blend;
|
|
|
|
|
|
|
|
memset(&blend, 0, sizeof(blend));
|
|
|
|
|
|
|
|
m_dev->CreateBlendState(&blend, &m_date.bs);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-18 18:45:37 +00:00
|
|
|
bool GSDevice10::Reset(int w, int h)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-09-18 18:45:37 +00:00
|
|
|
if(!__super::Reset(w, h))
|
2009-02-09 21:15:56 +00:00
|
|
|
return false;
|
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
if(m_swapchain)
|
|
|
|
{
|
|
|
|
DXGI_SWAP_CHAIN_DESC scd;
|
|
|
|
memset(&scd, 0, sizeof(scd));
|
|
|
|
m_swapchain->GetDesc(&scd);
|
|
|
|
m_swapchain->ResizeBuffers(scd.BufferCount, w, h, scd.BufferDesc.Format, 0);
|
|
|
|
|
|
|
|
CComPtr<ID3D10Texture2D> backbuffer;
|
|
|
|
m_swapchain->GetBuffer(0, __uuidof(ID3D10Texture2D), (void**)&backbuffer);
|
|
|
|
m_backbuffer = new GSTexture10(backbuffer);
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-31 01:06:23 +00:00
|
|
|
void GSDevice10::Flip()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-10-31 01:06:23 +00:00
|
|
|
m_swapchain->Present(m_vsync, 0);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-26 03:40:31 +00:00
|
|
|
void GSDevice10::DrawPrimitive()
|
|
|
|
{
|
|
|
|
m_dev->Draw(m_vertices.count, m_vertices.start);
|
|
|
|
}
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
void GSDevice10::ClearRenderTarget(GSTexture* t, const GSVector4& c)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-22 01:22:52 +00:00
|
|
|
m_dev->ClearRenderTargetView(*(GSTexture10*)t, c.v);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
void GSDevice10::ClearRenderTarget(GSTexture* t, uint32 c)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
GSVector4 color = GSVector4(c) * (1.0f / 255);
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
m_dev->ClearRenderTargetView(*(GSTexture10*)t, color.v);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
void GSDevice10::ClearDepth(GSTexture* t, float c)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-22 01:22:52 +00:00
|
|
|
m_dev->ClearDepthStencilView(*(GSTexture10*)t, D3D10_CLEAR_DEPTH, c, 0);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
void GSDevice10::ClearStencil(GSTexture* t, uint8 c)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-22 01:22:52 +00:00
|
|
|
m_dev->ClearDepthStencilView(*(GSTexture10*)t, D3D10_CLEAR_STENCIL, 0, c);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-08-02 23:07:30 +00:00
|
|
|
GSTexture* GSDevice10::Create(int type, int w, int h, bool msaa, int format)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
D3D10_TEXTURE2D_DESC desc;
|
|
|
|
|
|
|
|
memset(&desc, 0, sizeof(desc));
|
|
|
|
|
|
|
|
desc.Width = w;
|
|
|
|
desc.Height = h;
|
|
|
|
desc.Format = (DXGI_FORMAT)format;
|
|
|
|
desc.MipLevels = 1;
|
|
|
|
desc.ArraySize = 1;
|
|
|
|
desc.SampleDesc.Count = 1;
|
|
|
|
desc.SampleDesc.Quality = 0;
|
|
|
|
desc.Usage = D3D10_USAGE_DEFAULT;
|
|
|
|
|
2009-08-02 23:07:30 +00:00
|
|
|
if(msaa)
|
|
|
|
{
|
|
|
|
desc.SampleDesc = m_msaa_desc;
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case GSTexture::RenderTarget:
|
|
|
|
desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
|
|
|
|
break;
|
|
|
|
case GSTexture::DepthStencil:
|
2009-06-23 04:12:32 +00:00
|
|
|
desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;// | D3D10_BIND_SHADER_RESOURCE;
|
2009-02-09 21:15:56 +00:00
|
|
|
break;
|
|
|
|
case GSTexture::Texture:
|
|
|
|
desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
|
|
|
|
break;
|
|
|
|
case GSTexture::Offscreen:
|
|
|
|
desc.Usage = D3D10_USAGE_STAGING;
|
|
|
|
desc.CPUAccessFlags |= D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
GSTexture10* t = NULL;
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
CComPtr<ID3D10Texture2D> texture;
|
|
|
|
|
|
|
|
hr = m_dev->CreateTexture2D(&desc, NULL, &texture);
|
|
|
|
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
2009-05-22 01:22:52 +00:00
|
|
|
t = new GSTexture10(texture);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case GSTexture::RenderTarget:
|
|
|
|
ClearRenderTarget(t, 0);
|
|
|
|
break;
|
|
|
|
case GSTexture::DepthStencil:
|
|
|
|
ClearDepth(t, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
return t;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-08-02 23:07:30 +00:00
|
|
|
GSTexture* GSDevice10::CreateRenderTarget(int w, int h, bool msaa, int format)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-08-02 23:07:30 +00:00
|
|
|
return __super::CreateRenderTarget(w, h, msaa, format ? format : DXGI_FORMAT_R8G8B8A8_UNORM);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-08-02 23:07:30 +00:00
|
|
|
GSTexture* GSDevice10::CreateDepthStencil(int w, int h, bool msaa, int format)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-08-02 23:07:30 +00:00
|
|
|
return __super::CreateDepthStencil(w, h, msaa, format ? format : DXGI_FORMAT_D32_FLOAT_S8X24_UINT); // DXGI_FORMAT_R32G8X24_TYPELESS
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
GSTexture* GSDevice10::CreateTexture(int w, int h, int format)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-22 01:22:52 +00:00
|
|
|
return __super::CreateTexture(w, h, format ? format : DXGI_FORMAT_R8G8B8A8_UNORM);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
GSTexture* GSDevice10::CreateOffscreen(int w, int h, int format)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-22 01:22:52 +00:00
|
|
|
return __super::CreateOffscreen(w, h, format ? format : DXGI_FORMAT_R8G8B8A8_UNORM);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-08-02 23:07:30 +00:00
|
|
|
GSTexture* GSDevice10::Resolve(GSTexture* t)
|
|
|
|
{
|
|
|
|
ASSERT(t != NULL && t->IsMSAA());
|
|
|
|
|
|
|
|
if(GSTexture* dst = CreateRenderTarget(t->GetWidth(), t->GetHeight(), false, t->GetFormat()))
|
|
|
|
{
|
|
|
|
dst->SetScale(t->GetScale());
|
|
|
|
|
|
|
|
m_dev->ResolveSubresource(*(GSTexture10*)dst, 0, *(GSTexture10*)t, 0, (DXGI_FORMAT)t->GetFormat());
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
GSTexture* GSDevice10::CopyOffscreen(GSTexture* src, const GSVector4& sr, int w, int h, int format)
|
|
|
|
{
|
|
|
|
GSTexture* dst = NULL;
|
|
|
|
|
|
|
|
if(format == 0)
|
|
|
|
{
|
|
|
|
format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(format != DXGI_FORMAT_R8G8B8A8_UNORM && format != DXGI_FORMAT_R16_UINT)
|
|
|
|
{
|
|
|
|
ASSERT(0);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-02 23:07:30 +00:00
|
|
|
if(GSTexture* rt = CreateRenderTarget(w, h, false, format))
|
2009-05-22 01:22:52 +00:00
|
|
|
{
|
|
|
|
GSVector4 dr(0, 0, w, h);
|
|
|
|
|
2009-08-02 23:07:30 +00:00
|
|
|
if(GSTexture* src2 = src->IsMSAA() ? Resolve(src) : src)
|
|
|
|
{
|
|
|
|
StretchRect(src2, sr, rt, dr, m_convert.ps[format == DXGI_FORMAT_R16_UINT ? 1 : 0], NULL);
|
|
|
|
|
|
|
|
if(src2 != src) Recycle(src2);
|
|
|
|
}
|
2009-05-22 01:22:52 +00:00
|
|
|
|
|
|
|
dst = CreateOffscreen(w, h, format);
|
|
|
|
|
|
|
|
if(dst)
|
|
|
|
{
|
|
|
|
m_dev->CopyResource(*(GSTexture10*)dst, *(GSTexture10*)rt);
|
|
|
|
}
|
|
|
|
|
|
|
|
Recycle(rt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
void GSDevice10::CopyRect(GSTexture* st, GSTexture* dt, const GSVector4i& r)
|
|
|
|
{
|
|
|
|
D3D10_BOX box = {r.left, r.top, 0, r.right, r.bottom, 1};
|
|
|
|
|
2009-07-24 09:24:09 +00:00
|
|
|
m_dev->CopySubresourceRegion(*(GSTexture10*)dt, 0, r.left, r.top, 0, *(GSTexture10*)st, 0, &box);
|
2009-07-06 16:35:06 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 23:23:38 +00:00
|
|
|
void GSDevice10::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, int shader, bool linear)
|
2009-05-22 01:22:52 +00:00
|
|
|
{
|
2009-05-22 23:23:38 +00:00
|
|
|
StretchRect(st, sr, dt, dr, m_convert.ps[shader], NULL, linear);
|
2009-05-22 01:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDevice10::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, ID3D10PixelShader* ps, ID3D10Buffer* ps_cb, bool linear)
|
|
|
|
{
|
|
|
|
StretchRect(st, sr, dt, dr, ps, ps_cb, m_convert.bs, linear);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDevice10::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, ID3D10PixelShader* ps, ID3D10Buffer* ps_cb, ID3D10BlendState* bs, bool linear)
|
|
|
|
{
|
|
|
|
BeginScene();
|
|
|
|
|
|
|
|
GSVector2i ds = dt->GetSize();
|
|
|
|
|
|
|
|
// om
|
|
|
|
|
|
|
|
OMSetDepthStencilState(m_convert.dss, 0);
|
|
|
|
OMSetBlendState(bs, 0);
|
|
|
|
OMSetRenderTargets(dt, NULL);
|
|
|
|
|
|
|
|
// ia
|
|
|
|
|
|
|
|
float left = dr.x * 2 / ds.x - 1.0f;
|
|
|
|
float top = 1.0f - dr.y * 2 / ds.y;
|
|
|
|
float right = dr.z * 2 / ds.x - 1.0f;
|
|
|
|
float bottom = 1.0f - dr.w * 2 / ds.y;
|
|
|
|
|
|
|
|
GSVertexPT1 vertices[] =
|
|
|
|
{
|
|
|
|
{GSVector4(left, top, 0.5f, 1.0f), GSVector2(sr.x, sr.y)},
|
|
|
|
{GSVector4(right, top, 0.5f, 1.0f), GSVector2(sr.z, sr.y)},
|
|
|
|
{GSVector4(left, bottom, 0.5f, 1.0f), GSVector2(sr.x, sr.w)},
|
|
|
|
{GSVector4(right, bottom, 0.5f, 1.0f), GSVector2(sr.z, sr.w)},
|
|
|
|
};
|
|
|
|
|
2009-05-26 03:40:31 +00:00
|
|
|
IASetVertexBuffer(vertices, sizeof(vertices[0]), countof(vertices));
|
2009-05-22 01:22:52 +00:00
|
|
|
IASetInputLayout(m_convert.il);
|
|
|
|
IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
|
|
|
|
|
|
|
// vs
|
|
|
|
|
|
|
|
VSSetShader(m_convert.vs, NULL);
|
|
|
|
|
|
|
|
// gs
|
|
|
|
|
|
|
|
GSSetShader(NULL);
|
|
|
|
|
|
|
|
// ps
|
|
|
|
|
|
|
|
PSSetShader(ps, ps_cb);
|
|
|
|
PSSetSamplerState(linear ? m_convert.ln : m_convert.pt, NULL);
|
|
|
|
PSSetShaderResources(st, NULL);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
2009-05-26 03:40:31 +00:00
|
|
|
DrawPrimitive();
|
2009-05-22 01:22:52 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
EndScene();
|
2009-07-31 23:59:06 +00:00
|
|
|
|
|
|
|
PSSetShaderResources(NULL, NULL);
|
2009-05-22 01:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDevice10::DoMerge(GSTexture* st[2], GSVector4* sr, GSVector4* dr, GSTexture* dt, bool slbg, bool mmod, const GSVector4& c)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
ClearRenderTarget(dt, c);
|
|
|
|
|
|
|
|
if(st[1] && !slbg)
|
|
|
|
{
|
|
|
|
StretchRect(st[1], sr[1], dt, dr[1], m_merge.ps[0], NULL, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(st[0])
|
|
|
|
{
|
|
|
|
m_dev->UpdateSubresource(m_merge.cb, 0, NULL, &c, 0, 0);
|
|
|
|
|
|
|
|
StretchRect(st[0], sr[0], dt, dr[0], m_merge.ps[mmod ? 1 : 0], m_merge.cb, m_merge.bs, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
void GSDevice10::DoInterlace(GSTexture* st, GSTexture* dt, int shader, bool linear, float yoffset)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-22 01:22:52 +00:00
|
|
|
GSVector4 s = GSVector4(dt->GetSize());
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
GSVector4 sr(0, 0, 1, 1);
|
2009-05-22 01:22:52 +00:00
|
|
|
GSVector4 dr(0.0f, yoffset, s.x, s.y + yoffset);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
InterlaceConstantBuffer cb;
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
cb.ZrH = GSVector2(0, 1.0f / s.y);
|
|
|
|
cb.hH = s.y / 2;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
m_dev->UpdateSubresource(m_interlace.cb, 0, NULL, &cb, 0, 0);
|
|
|
|
|
|
|
|
StretchRect(st, sr, dt, dr, m_interlace.ps[shader], m_interlace.cb, linear);
|
|
|
|
}
|
|
|
|
|
2009-11-07 17:50:48 +00:00
|
|
|
void GSDevice10::SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1 (&iaVertices)[4], bool datm)
|
|
|
|
{
|
|
|
|
const GSVector2i& size = rt->GetSize();
|
|
|
|
|
|
|
|
if(GSTexture* t = CreateRenderTarget(size.x, size.y, rt->IsMSAA()))
|
|
|
|
{
|
|
|
|
// sfex3 (after the capcom logo), vf4 (first menu fading in), ffxii shadows, rumble roses shadows, persona4 shadows
|
|
|
|
|
|
|
|
BeginScene();
|
|
|
|
|
|
|
|
ClearStencil(ds, 0);
|
|
|
|
|
|
|
|
// om
|
|
|
|
|
|
|
|
OMSetDepthStencilState(m_date.dss, 1);
|
|
|
|
OMSetBlendState(m_date.bs, 0);
|
|
|
|
OMSetRenderTargets(t, ds);
|
|
|
|
|
|
|
|
// ia
|
|
|
|
|
|
|
|
IASetVertexBuffer(iaVertices, sizeof(iaVertices[0]), countof(iaVertices));
|
|
|
|
IASetInputLayout(m_convert.il);
|
|
|
|
IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
|
|
|
|
|
|
|
// vs
|
|
|
|
|
|
|
|
VSSetShader(m_convert.vs, NULL);
|
|
|
|
|
|
|
|
// gs
|
|
|
|
|
|
|
|
GSSetShader(NULL);
|
|
|
|
|
|
|
|
// ps
|
|
|
|
|
|
|
|
GSTexture* rt2 = rt->IsMSAA() ? Resolve(rt) : rt;
|
|
|
|
|
|
|
|
PSSetShaderResources(rt2, NULL);
|
|
|
|
PSSetShader(m_convert.ps[datm ? 2 : 3], NULL);
|
|
|
|
PSSetSamplerState(m_convert.pt, NULL);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
DrawPrimitive();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
EndScene();
|
|
|
|
|
|
|
|
Recycle(t);
|
|
|
|
|
|
|
|
if(rt2 != rt) Recycle(rt2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-26 03:40:31 +00:00
|
|
|
void GSDevice10::IASetVertexBuffer(const void* vertices, size_t stride, size_t count)
|
|
|
|
{
|
|
|
|
ASSERT(m_vertices.count == 0);
|
|
|
|
|
2009-05-27 05:55:32 +00:00
|
|
|
if(count * stride > m_vertices.limit * m_vertices.stride)
|
2009-05-26 03:40:31 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
m_vb_old = m_vb;
|
|
|
|
m_vb = NULL;
|
|
|
|
|
2009-05-26 03:40:31 +00:00
|
|
|
m_vertices.start = 0;
|
|
|
|
m_vertices.count = 0;
|
2009-07-04 15:14:04 +00:00
|
|
|
m_vertices.limit = std::max<int>(count * 3 / 2, 10000);
|
2009-05-26 03:40:31 +00:00
|
|
|
}
|
|
|
|
|
2009-07-31 23:59:06 +00:00
|
|
|
if(m_vb == NULL)
|
2009-05-26 03:40:31 +00:00
|
|
|
{
|
|
|
|
D3D10_BUFFER_DESC bd;
|
|
|
|
|
|
|
|
memset(&bd, 0, sizeof(bd));
|
|
|
|
|
|
|
|
bd.Usage = D3D10_USAGE_DYNAMIC;
|
|
|
|
bd.ByteWidth = m_vertices.limit * stride;
|
|
|
|
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
|
|
|
bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
2009-07-31 23:59:06 +00:00
|
|
|
hr = m_dev->CreateBuffer(&bd, NULL, &m_vb);
|
2009-05-26 03:40:31 +00:00
|
|
|
|
|
|
|
if(FAILED(hr)) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3D10_MAP type = D3D10_MAP_WRITE_NO_OVERWRITE;
|
|
|
|
|
|
|
|
if(m_vertices.start + count > m_vertices.limit || stride != m_vertices.stride)
|
|
|
|
{
|
|
|
|
m_vertices.start = 0;
|
|
|
|
|
|
|
|
type = D3D10_MAP_WRITE_DISCARD;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* v = NULL;
|
|
|
|
|
2009-07-31 23:59:06 +00:00
|
|
|
if(SUCCEEDED(m_vb->Map(type, 0, &v)))
|
2009-05-26 03:40:31 +00:00
|
|
|
{
|
|
|
|
GSVector4i::storent((uint8*)v + m_vertices.start * stride, vertices, count * stride);
|
|
|
|
|
2009-07-31 23:59:06 +00:00
|
|
|
m_vb->Unmap();
|
2009-05-26 03:40:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_vertices.count = count;
|
|
|
|
m_vertices.stride = stride;
|
|
|
|
|
2009-07-31 23:59:06 +00:00
|
|
|
IASetVertexBuffer(m_vb, stride);
|
2009-05-26 03:40:31 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
void GSDevice10::IASetVertexBuffer(ID3D10Buffer* vb, size_t stride)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
if(m_state.vb != vb || m_state.vb_stride != stride)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
m_state.vb = vb;
|
|
|
|
m_state.vb_stride = stride;
|
2009-07-22 03:55:28 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
uint32 offset = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
m_dev->IASetVertexBuffers(0, 1, &vb, &stride, &offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDevice10::IASetInputLayout(ID3D10InputLayout* layout)
|
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
if(m_state.layout != layout)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
m_state.layout = layout;
|
2009-07-22 03:55:28 +00:00
|
|
|
|
|
|
|
m_dev->IASetInputLayout(layout);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDevice10::IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY topology)
|
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
if(m_state.topology != topology)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
m_state.topology = topology;
|
2009-07-22 03:55:28 +00:00
|
|
|
|
|
|
|
m_dev->IASetPrimitiveTopology(topology);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDevice10::VSSetShader(ID3D10VertexShader* vs, ID3D10Buffer* vs_cb)
|
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
if(m_state.vs != vs)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
m_state.vs = vs;
|
2009-07-22 03:55:28 +00:00
|
|
|
|
|
|
|
m_dev->VSSetShader(vs);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-07-31 23:59:06 +00:00
|
|
|
if(m_state.vs_cb != vs_cb)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
m_state.vs_cb = vs_cb;
|
2009-07-22 03:55:28 +00:00
|
|
|
|
|
|
|
m_dev->VSSetConstantBuffers(0, 1, &vs_cb);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDevice10::GSSetShader(ID3D10GeometryShader* gs)
|
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
if(m_state.gs != gs)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
m_state.gs = gs;
|
2009-07-22 03:55:28 +00:00
|
|
|
|
|
|
|
m_dev->GSSetShader(gs);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
void GSDevice10::PSSetShaderResources(GSTexture* sr0, GSTexture* sr1)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-22 01:22:52 +00:00
|
|
|
ID3D10ShaderResourceView* srv0 = NULL;
|
|
|
|
ID3D10ShaderResourceView* srv1 = NULL;
|
2009-08-02 23:07:30 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
if(sr0) srv0 = *(GSTexture10*)sr0;
|
|
|
|
if(sr1) srv1 = *(GSTexture10*)sr1;
|
|
|
|
|
2009-07-31 23:59:06 +00:00
|
|
|
if(m_state.ps_srv[0] != srv0 || m_state.ps_srv[1] != srv1)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
m_state.ps_srv[0] = srv0;
|
|
|
|
m_state.ps_srv[1] = srv1;
|
2009-07-22 03:55:28 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
ID3D10ShaderResourceView* srvs[] = {srv0, srv1};
|
|
|
|
|
|
|
|
m_dev->PSSetShaderResources(0, 2, srvs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDevice10::PSSetShader(ID3D10PixelShader* ps, ID3D10Buffer* ps_cb)
|
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
if(m_state.ps != ps)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
m_state.ps = ps;
|
2009-07-22 03:55:28 +00:00
|
|
|
|
|
|
|
m_dev->PSSetShader(ps);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-07-31 23:59:06 +00:00
|
|
|
if(m_state.ps_cb != ps_cb)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
m_state.ps_cb = ps_cb;
|
2009-07-22 03:55:28 +00:00
|
|
|
|
|
|
|
m_dev->PSSetConstantBuffers(0, 1, &ps_cb);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDevice10::PSSetSamplerState(ID3D10SamplerState* ss0, ID3D10SamplerState* ss1)
|
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
if(m_state.ps_ss[0] != ss0 || m_state.ps_ss[1] != ss1)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
m_state.ps_ss[0] = ss0;
|
|
|
|
m_state.ps_ss[1] = ss1;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
ID3D10SamplerState* sss[] = {ss0, ss1};
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
m_dev->PSSetSamplers(0, 2, sss);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
void GSDevice10::OMSetDepthStencilState(ID3D10DepthStencilState* dss, uint8 sref)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
if(m_state.dss != dss || m_state.sref != sref)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
m_state.dss = dss;
|
|
|
|
m_state.sref = sref;
|
2009-07-22 03:55:28 +00:00
|
|
|
|
|
|
|
m_dev->OMSetDepthStencilState(dss, sref);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDevice10::OMSetBlendState(ID3D10BlendState* bs, float bf)
|
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
if(m_state.bs != bs || m_state.bf != bf)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
m_state.bs = bs;
|
|
|
|
m_state.bf = bf;
|
2009-07-22 03:55:28 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
float BlendFactor[] = {bf, bf, bf, 0};
|
|
|
|
|
|
|
|
m_dev->OMSetBlendState(bs, BlendFactor, 0xffffffff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
void GSDevice10::OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4i* scissor)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-22 01:22:52 +00:00
|
|
|
ID3D10RenderTargetView* rtv = NULL;
|
|
|
|
ID3D10DepthStencilView* dsv = NULL;
|
|
|
|
|
|
|
|
if(rt) rtv = *(GSTexture10*)rt;
|
|
|
|
if(ds) dsv = *(GSTexture10*)ds;
|
|
|
|
|
2009-07-31 23:59:06 +00:00
|
|
|
if(m_state.rtv != rtv || m_state.dsv != dsv)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
m_state.rtv = rtv;
|
|
|
|
m_state.dsv = dsv;
|
2009-07-22 03:55:28 +00:00
|
|
|
|
|
|
|
m_dev->OMSetRenderTargets(1, &rtv, dsv);
|
|
|
|
}
|
|
|
|
|
2009-08-02 23:07:30 +00:00
|
|
|
if(m_state.viewport != rt->GetSize())
|
2009-07-22 03:55:28 +00:00
|
|
|
{
|
2009-08-02 23:07:30 +00:00
|
|
|
m_state.viewport = rt->GetSize();
|
2009-07-22 03:55:28 +00:00
|
|
|
|
|
|
|
D3D10_VIEWPORT vp;
|
|
|
|
|
|
|
|
memset(&vp, 0, sizeof(vp));
|
|
|
|
|
|
|
|
vp.TopLeftX = 0;
|
|
|
|
vp.TopLeftY = 0;
|
2009-08-02 23:07:30 +00:00
|
|
|
vp.Width = rt->GetWidth();
|
|
|
|
vp.Height = rt->GetHeight();
|
2009-07-22 03:55:28 +00:00
|
|
|
vp.MinDepth = 0.0f;
|
|
|
|
vp.MaxDepth = 1.0f;
|
|
|
|
|
|
|
|
m_dev->RSSetViewports(1, &vp);
|
|
|
|
}
|
|
|
|
|
2009-08-02 23:07:30 +00:00
|
|
|
GSVector4i r = scissor ? *scissor : GSVector4i(rt->GetSize()).zwxy();
|
2009-07-22 03:55:28 +00:00
|
|
|
|
2009-07-31 23:59:06 +00:00
|
|
|
if(!m_state.scissor.eq(r))
|
2009-07-22 03:55:28 +00:00
|
|
|
{
|
2009-07-31 23:59:06 +00:00
|
|
|
m_state.scissor = r;
|
2009-07-22 03:55:28 +00:00
|
|
|
|
|
|
|
m_dev->RSSetScissorRects(1, r);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-19 20:24:18 +00:00
|
|
|
HRESULT GSDevice10::CompileShader(uint32 id, const string& entry, D3D10_SHADER_MACRO* macro, ID3D10VertexShader** vs, D3D10_INPUT_ELEMENT_DESC* layout, int count, ID3D10InputLayout** il)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2009-06-19 20:24:18 +00:00
|
|
|
vector<D3D10_SHADER_MACRO> m;
|
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
PrepareShaderMacro(m, macro);
|
2009-06-19 20:24:18 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
CComPtr<ID3D10Blob> shader, error;
|
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
hr = D3DX10CompileFromResource(theApp.GetModuleHandle(), MAKEINTRESOURCE(id), NULL, &m[0], NULL, entry.c_str(), m_shader.vs.c_str(), 0, 0, NULL, &shader, &error, NULL);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(error)
|
|
|
|
{
|
2009-05-26 03:40:31 +00:00
|
|
|
printf("%s\n", (const char*)error->GetBufferPointer());
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-06-19 20:24:18 +00:00
|
|
|
hr = m_dev->CreateVertexShader((void*)shader->GetBufferPointer(), shader->GetBufferSize(), vs);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = m_dev->CreateInputLayout(layout, count, shader->GetBufferPointer(), shader->GetBufferSize(), il);
|
|
|
|
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
HRESULT GSDevice10::CompileShader(uint32 id, const string& entry, D3D10_SHADER_MACRO* macro, ID3D10GeometryShader** gs)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2009-06-19 20:24:18 +00:00
|
|
|
vector<D3D10_SHADER_MACRO> m;
|
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
PrepareShaderMacro(m, macro);
|
2009-06-19 20:24:18 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
CComPtr<ID3D10Blob> shader, error;
|
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
hr = D3DX10CompileFromResource(theApp.GetModuleHandle(), MAKEINTRESOURCE(id), NULL, &m[0], NULL, entry.c_str(), m_shader.gs.c_str(), 0, 0, NULL, &shader, &error, NULL);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(error)
|
|
|
|
{
|
2009-05-26 03:40:31 +00:00
|
|
|
printf("%s\n", (const char*)error->GetBufferPointer());
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
hr = m_dev->CreateGeometryShader((void*)shader->GetBufferPointer(), shader->GetBufferSize(), gs);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
HRESULT GSDevice10::CompileShader(uint32 id, const string& entry, D3D10_SHADER_MACRO* macro, ID3D10PixelShader** ps)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2009-06-19 20:24:18 +00:00
|
|
|
vector<D3D10_SHADER_MACRO> m;
|
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
PrepareShaderMacro(m, macro);
|
2009-06-19 20:24:18 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
CComPtr<ID3D10Blob> shader, error;
|
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
hr = D3DX10CompileFromResource(theApp.GetModuleHandle(), MAKEINTRESOURCE(id), NULL, &m[0], NULL, entry.c_str(), m_shader.ps.c_str(), 0, 0, NULL, &shader, &error, NULL);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(error)
|
|
|
|
{
|
2009-05-26 03:40:31 +00:00
|
|
|
printf("%s\n", (const char*)error->GetBufferPointer());
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
hr = m_dev->CreatePixelShader((void*)shader->GetBufferPointer(), shader->GetBufferSize(), ps);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|