mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-29 13:20:54 +00:00
Refactor and optimise D3D11 refcounting implementation
* In heavy D3D11 workloads the refcounting overhead especially during fast binding changes was significant. Refactoring the refcounting to work on a different model and deferring destruction of objects removes most of the overhead.
This commit is contained in:
@@ -144,7 +144,7 @@ static const UINT formatStrides[] = {
|
||||
0, // DXGI_FORMAT_B4G4R4A4_UNORM
|
||||
};
|
||||
|
||||
D3D11BufferCreator::D3D11BufferCreator(D3D11GraphicsTest *test) : m_Test(test)
|
||||
D3D11BufferCreator::D3D11BufferCreator(ID3D11DevicePtr dev) : m_Dev(dev)
|
||||
{
|
||||
m_BufDesc.ByteWidth = 0;
|
||||
m_BufDesc.MiscFlags = 0;
|
||||
@@ -262,13 +262,13 @@ D3D11BufferCreator &D3D11BufferCreator::Size(UINT size)
|
||||
D3D11BufferCreator::operator ID3D11BufferPtr() const
|
||||
{
|
||||
ID3D11BufferPtr buf;
|
||||
CHECK_HR(m_Test->dev->CreateBuffer(&m_BufDesc, m_Initdata.pSysMem ? &m_Initdata : NULL, &buf));
|
||||
CHECK_HR(m_Dev->CreateBuffer(&m_BufDesc, m_Initdata.pSysMem ? &m_Initdata : NULL, &buf));
|
||||
return buf;
|
||||
}
|
||||
|
||||
D3D11TextureCreator::D3D11TextureCreator(D3D11GraphicsTest *test, DXGI_FORMAT format, UINT width,
|
||||
D3D11TextureCreator::D3D11TextureCreator(ID3D11DevicePtr dev, DXGI_FORMAT format, UINT width,
|
||||
UINT height, UINT depth)
|
||||
: m_Test(test)
|
||||
: m_Dev(dev)
|
||||
{
|
||||
Format = format;
|
||||
Width = width;
|
||||
@@ -353,7 +353,7 @@ D3D11TextureCreator::operator ID3D11Texture1DPtr() const
|
||||
texdesc.Format = Format;
|
||||
|
||||
ID3D11Texture1DPtr tex;
|
||||
CHECK_HR(m_Test->dev->CreateTexture1D(&texdesc, NULL, &tex));
|
||||
CHECK_HR(m_Dev->CreateTexture1D(&texdesc, NULL, &tex));
|
||||
return tex;
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ D3D11TextureCreator::operator ID3D11Texture2DPtr() const
|
||||
texdesc.SampleDesc.Quality = SampleDesc.Quality;
|
||||
|
||||
ID3D11Texture2DPtr tex;
|
||||
CHECK_HR(m_Test->dev->CreateTexture2D(&texdesc, NULL, &tex));
|
||||
CHECK_HR(m_Dev->CreateTexture2D(&texdesc, NULL, &tex));
|
||||
return tex;
|
||||
}
|
||||
|
||||
@@ -393,18 +393,18 @@ D3D11TextureCreator::operator ID3D11Texture3DPtr() const
|
||||
texdesc.Format = Format;
|
||||
|
||||
ID3D11Texture3DPtr tex;
|
||||
CHECK_HR(m_Test->dev->CreateTexture3D(&texdesc, NULL, &tex));
|
||||
CHECK_HR(m_Dev->CreateTexture3D(&texdesc, NULL, &tex));
|
||||
return tex;
|
||||
}
|
||||
|
||||
D3D11ViewCreator::D3D11ViewCreator(D3D11GraphicsTest *test, ViewType viewType, ID3D11Buffer *buf)
|
||||
: m_Test(test), m_ViewType(viewType), m_ResType(ResourceType::Buffer), m_Res(buf)
|
||||
D3D11ViewCreator::D3D11ViewCreator(ID3D11DevicePtr dev, ViewType viewType, ID3D11Buffer *buf)
|
||||
: m_Dev(dev), m_ViewType(viewType), m_ResType(ResourceType::Buffer), m_Res(buf)
|
||||
{
|
||||
SetupDescriptors();
|
||||
}
|
||||
|
||||
D3D11ViewCreator::D3D11ViewCreator(D3D11GraphicsTest *test, ViewType viewType, ID3D11Texture1D *tex)
|
||||
: m_Test(test), m_ViewType(viewType), m_Res(tex)
|
||||
D3D11ViewCreator::D3D11ViewCreator(ID3D11DevicePtr dev, ViewType viewType, ID3D11Texture1D *tex)
|
||||
: m_Dev(dev), m_ViewType(viewType), m_Res(tex)
|
||||
{
|
||||
D3D11_TEXTURE1D_DESC texdesc;
|
||||
tex->GetDesc(&texdesc);
|
||||
@@ -419,8 +419,8 @@ D3D11ViewCreator::D3D11ViewCreator(D3D11GraphicsTest *test, ViewType viewType, I
|
||||
Format(texdesc.Format);
|
||||
}
|
||||
|
||||
D3D11ViewCreator::D3D11ViewCreator(D3D11GraphicsTest *test, ViewType viewType, ID3D11Texture2D *tex)
|
||||
: m_Test(test), m_ViewType(viewType), m_Res(tex)
|
||||
D3D11ViewCreator::D3D11ViewCreator(ID3D11DevicePtr dev, ViewType viewType, ID3D11Texture2D *tex)
|
||||
: m_Dev(dev), m_ViewType(viewType), m_Res(tex)
|
||||
{
|
||||
D3D11_TEXTURE2D_DESC texdesc;
|
||||
tex->GetDesc(&texdesc);
|
||||
@@ -443,8 +443,8 @@ D3D11ViewCreator::D3D11ViewCreator(D3D11GraphicsTest *test, ViewType viewType, I
|
||||
Format(texdesc.Format);
|
||||
}
|
||||
|
||||
D3D11ViewCreator::D3D11ViewCreator(D3D11GraphicsTest *test, ViewType viewType, ID3D11Texture3D *tex)
|
||||
: m_Test(test), m_ViewType(viewType), m_ResType(ResourceType::Texture3D), m_Res(tex)
|
||||
D3D11ViewCreator::D3D11ViewCreator(ID3D11DevicePtr dev, ViewType viewType, ID3D11Texture3D *tex)
|
||||
: m_Dev(dev), m_ViewType(viewType), m_ResType(ResourceType::Texture3D), m_Res(tex)
|
||||
{
|
||||
D3D11_TEXTURE3D_DESC texdesc;
|
||||
tex->GetDesc(&texdesc);
|
||||
@@ -776,7 +776,7 @@ D3D11ViewCreator::operator ID3D11ShaderResourceViewPtr()
|
||||
TEST_ASSERT(m_ViewType == ViewType::SRV, "Casting non-SRV ViewCreator to SRV");
|
||||
|
||||
ID3D11ShaderResourceViewPtr srv;
|
||||
CHECK_HR(m_Test->dev->CreateShaderResourceView(m_Res, &desc.srv, &srv));
|
||||
CHECK_HR(m_Dev->CreateShaderResourceView(m_Res, &desc.srv, &srv));
|
||||
return srv;
|
||||
}
|
||||
|
||||
@@ -806,7 +806,7 @@ D3D11ViewCreator::operator ID3D11UnorderedAccessViewPtr()
|
||||
TEST_ASSERT(m_ViewType == ViewType::UAV, "Casting non-UAV ViewCreator to UAV");
|
||||
|
||||
ID3D11UnorderedAccessViewPtr uav;
|
||||
CHECK_HR(m_Test->dev->CreateUnorderedAccessView(m_Res, &desc.uav, &uav));
|
||||
CHECK_HR(m_Dev->CreateUnorderedAccessView(m_Res, &desc.uav, &uav));
|
||||
return uav;
|
||||
}
|
||||
|
||||
@@ -816,7 +816,7 @@ D3D11ViewCreator::operator ID3D11RenderTargetViewPtr()
|
||||
TEST_ASSERT(m_ViewType == ViewType::RTV, "Casting non-RTV ViewCreator to RTV");
|
||||
|
||||
ID3D11RenderTargetViewPtr rtv;
|
||||
CHECK_HR(m_Test->dev->CreateRenderTargetView(m_Res, &desc.rtv, &rtv));
|
||||
CHECK_HR(m_Dev->CreateRenderTargetView(m_Res, &desc.rtv, &rtv));
|
||||
return rtv;
|
||||
}
|
||||
|
||||
@@ -826,14 +826,12 @@ D3D11ViewCreator::operator ID3D11DepthStencilViewPtr()
|
||||
TEST_ASSERT(m_ViewType == ViewType::DSV, "Casting non-DSV ViewCreator to DSV");
|
||||
|
||||
ID3D11DepthStencilViewPtr dsv;
|
||||
CHECK_HR(m_Test->dev->CreateDepthStencilView(m_Res, &desc.dsv, &dsv));
|
||||
CHECK_HR(m_Dev->CreateDepthStencilView(m_Res, &desc.dsv, &dsv));
|
||||
return dsv;
|
||||
}
|
||||
|
||||
D3D11SamplerCreator::D3D11SamplerCreator(D3D11GraphicsTest *test)
|
||||
D3D11SamplerCreator::D3D11SamplerCreator(ID3D11DevicePtr dev) : m_Dev(dev)
|
||||
{
|
||||
m_Test = test;
|
||||
|
||||
m_Desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
m_Desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
m_Desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
@@ -852,6 +850,6 @@ D3D11SamplerCreator::D3D11SamplerCreator(D3D11GraphicsTest *test)
|
||||
D3D11SamplerCreator::operator ID3D11SamplerStatePtr() const
|
||||
{
|
||||
ID3D11SamplerStatePtr samp;
|
||||
CHECK_HR(m_Test->dev->CreateSamplerState(&m_Desc, &samp));
|
||||
CHECK_HR(m_Dev->CreateSamplerState(&m_Desc, &samp));
|
||||
return samp;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ struct D3D11GraphicsTest;
|
||||
class D3D11BufferCreator
|
||||
{
|
||||
public:
|
||||
D3D11BufferCreator(D3D11GraphicsTest *test);
|
||||
D3D11BufferCreator(ID3D11DevicePtr dev);
|
||||
|
||||
D3D11BufferCreator &Vertex();
|
||||
D3D11BufferCreator &Index();
|
||||
@@ -134,7 +134,7 @@ public:
|
||||
operator ID3D11BufferPtr() const;
|
||||
|
||||
private:
|
||||
D3D11GraphicsTest *m_Test;
|
||||
ID3D11DevicePtr m_Dev;
|
||||
|
||||
D3D11_BUFFER_DESC m_BufDesc;
|
||||
D3D11_SUBRESOURCE_DATA m_Initdata = {};
|
||||
@@ -143,8 +143,7 @@ private:
|
||||
class D3D11TextureCreator
|
||||
{
|
||||
public:
|
||||
D3D11TextureCreator(D3D11GraphicsTest *test, DXGI_FORMAT format, UINT width, UINT height,
|
||||
UINT depth);
|
||||
D3D11TextureCreator(ID3D11DevicePtr dev, DXGI_FORMAT format, UINT width, UINT height, UINT depth);
|
||||
|
||||
D3D11TextureCreator &Mips(UINT mips);
|
||||
D3D11TextureCreator &Array(UINT size);
|
||||
@@ -167,7 +166,7 @@ public:
|
||||
ID3D11Texture2DPtr Tex2D() const { return (ID3D11Texture2DPtr) * this; };
|
||||
ID3D11Texture3DPtr Tex3D() const { return (ID3D11Texture3DPtr) * this; };
|
||||
protected:
|
||||
D3D11GraphicsTest *m_Test;
|
||||
ID3D11DevicePtr m_Dev;
|
||||
|
||||
UINT Width = 1;
|
||||
UINT Height = 1;
|
||||
@@ -185,7 +184,7 @@ protected:
|
||||
class D3D11SamplerCreator
|
||||
{
|
||||
public:
|
||||
D3D11SamplerCreator(D3D11GraphicsTest *test);
|
||||
D3D11SamplerCreator(ID3D11DevicePtr dev);
|
||||
|
||||
D3D11SamplerCreator &AddressU(D3D11_TEXTURE_ADDRESS_MODE addr)
|
||||
{
|
||||
@@ -237,7 +236,7 @@ public:
|
||||
operator ID3D11SamplerStatePtr() const;
|
||||
|
||||
protected:
|
||||
D3D11GraphicsTest *m_Test;
|
||||
ID3D11DevicePtr m_Dev;
|
||||
|
||||
D3D11_SAMPLER_DESC m_Desc;
|
||||
};
|
||||
@@ -245,10 +244,10 @@ protected:
|
||||
class D3D11ViewCreator
|
||||
{
|
||||
public:
|
||||
D3D11ViewCreator(D3D11GraphicsTest *test, ViewType viewType, ID3D11Buffer *buf);
|
||||
D3D11ViewCreator(D3D11GraphicsTest *test, ViewType viewType, ID3D11Texture1D *tex);
|
||||
D3D11ViewCreator(D3D11GraphicsTest *test, ViewType viewType, ID3D11Texture2D *tex);
|
||||
D3D11ViewCreator(D3D11GraphicsTest *test, ViewType viewType, ID3D11Texture3D *tex);
|
||||
D3D11ViewCreator(ID3D11DevicePtr dev, ViewType viewType, ID3D11Buffer *buf);
|
||||
D3D11ViewCreator(ID3D11DevicePtr dev, ViewType viewType, ID3D11Texture1D *tex);
|
||||
D3D11ViewCreator(ID3D11DevicePtr dev, ViewType viewType, ID3D11Texture2D *tex);
|
||||
D3D11ViewCreator(ID3D11DevicePtr dev, ViewType viewType, ID3D11Texture3D *tex);
|
||||
|
||||
// common params
|
||||
D3D11ViewCreator &Format(DXGI_FORMAT format);
|
||||
@@ -275,7 +274,7 @@ public:
|
||||
private:
|
||||
void SetupDescriptors();
|
||||
|
||||
D3D11GraphicsTest *m_Test;
|
||||
ID3D11DevicePtr m_Dev;
|
||||
ID3D11ResourcePtr m_Res;
|
||||
ViewType m_ViewType;
|
||||
ResourceType m_ResType;
|
||||
@@ -298,13 +297,6 @@ private:
|
||||
UINT *firstSlice = NULL, *numSlices = NULL;
|
||||
};
|
||||
|
||||
#define GET_REFCOUNT(val, obj) \
|
||||
do \
|
||||
{ \
|
||||
obj->AddRef(); \
|
||||
val = obj->Release(); \
|
||||
} while(0)
|
||||
|
||||
#define CHECK_HR(expr) \
|
||||
{ \
|
||||
HRESULT hr = (expr); \
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -112,7 +112,7 @@ void D3D11GraphicsTest::Prepare(int argc, char **argv)
|
||||
if(dyn_D3D11CreateDevice)
|
||||
{
|
||||
D3D_FEATURE_LEVEL features[] = {D3D_FEATURE_LEVEL_11_0};
|
||||
hr = CreateDevice(adapters, NULL, features, 0);
|
||||
hr = CreateDevice(NULL, NULL, features, 0);
|
||||
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
@@ -148,10 +148,7 @@ bool D3D11GraphicsTest::Init(IDXGIAdapterPtr pAdapter)
|
||||
|
||||
if(headless)
|
||||
{
|
||||
if(pAdapter != NULL)
|
||||
hr = CreateDevice({pAdapter}, NULL, features, flags);
|
||||
else
|
||||
hr = CreateDevice(adapters, NULL, features, flags);
|
||||
hr = CreateDevice(pAdapter, NULL, features, flags);
|
||||
|
||||
if(FAILED(hr))
|
||||
{
|
||||
@@ -182,10 +179,7 @@ bool D3D11GraphicsTest::Init(IDXGIAdapterPtr pAdapter)
|
||||
swapDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
||||
swapDesc.Flags = 0;
|
||||
|
||||
if(pAdapter != NULL)
|
||||
hr = CreateDevice({pAdapter}, &swapDesc, features, flags);
|
||||
else
|
||||
hr = CreateDevice(adapters, &swapDesc, features, flags);
|
||||
hr = CreateDevice(pAdapter, &swapDesc, features, flags);
|
||||
|
||||
if(FAILED(hr))
|
||||
{
|
||||
@@ -222,23 +216,39 @@ GraphicsWindow *D3D11GraphicsTest::MakeWindow(int width, int height, const char
|
||||
return new Win32Window(width, height, title);
|
||||
}
|
||||
|
||||
HRESULT D3D11GraphicsTest::CreateDevice(const std::vector<IDXGIAdapterPtr> &adaptersToTry,
|
||||
DXGI_SWAP_CHAIN_DESC *swapDesc, D3D_FEATURE_LEVEL *features,
|
||||
UINT flags)
|
||||
HRESULT D3D11GraphicsTest::CreateDevice(IDXGIAdapterPtr adapterToTry, DXGI_SWAP_CHAIN_DESC *swapDesc,
|
||||
D3D_FEATURE_LEVEL *features, UINT flags)
|
||||
{
|
||||
HRESULT hr = E_FAIL;
|
||||
for(size_t i = 0; i < adaptersToTry.size(); ++i)
|
||||
|
||||
if(adapterToTry)
|
||||
{
|
||||
if(swapDesc)
|
||||
hr = dyn_D3D11CreateDeviceAndSwapChain(adaptersToTry[i], D3D_DRIVER_TYPE_UNKNOWN, NULL, flags,
|
||||
hr = dyn_D3D11CreateDeviceAndSwapChain(adapterToTry, D3D_DRIVER_TYPE_UNKNOWN, NULL, flags,
|
||||
features, 1, D3D11_SDK_VERSION, swapDesc, &swap, &dev,
|
||||
NULL, &ctx);
|
||||
else
|
||||
hr = dyn_D3D11CreateDevice(adaptersToTry[i], D3D_DRIVER_TYPE_UNKNOWN, NULL, flags, features,
|
||||
1, D3D11_SDK_VERSION, &dev, NULL, &ctx);
|
||||
hr = dyn_D3D11CreateDevice(adapterToTry, D3D_DRIVER_TYPE_UNKNOWN, NULL, flags, features, 1,
|
||||
D3D11_SDK_VERSION, &dev, NULL, &ctx);
|
||||
|
||||
if(SUCCEEDED(hr))
|
||||
break;
|
||||
return hr;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(size_t i = 0; i < adapters.size(); ++i)
|
||||
{
|
||||
if(swapDesc)
|
||||
hr = dyn_D3D11CreateDeviceAndSwapChain(adapters[i], D3D_DRIVER_TYPE_UNKNOWN, NULL, flags,
|
||||
features, 1, D3D11_SDK_VERSION, swapDesc, &swap,
|
||||
&dev, NULL, &ctx);
|
||||
else
|
||||
hr = dyn_D3D11CreateDevice(adapters[i], D3D_DRIVER_TYPE_UNKNOWN, NULL, flags, features, 1,
|
||||
D3D11_SDK_VERSION, &dev, NULL, &ctx);
|
||||
|
||||
if(SUCCEEDED(hr))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If it failed, try again on warp
|
||||
@@ -339,6 +349,9 @@ void D3D11GraphicsTest::Shutdown()
|
||||
dev1 = NULL;
|
||||
dev2 = NULL;
|
||||
dev = NULL;
|
||||
|
||||
swapBlitVS = NULL;
|
||||
swapBlitPS = NULL;
|
||||
}
|
||||
|
||||
bool D3D11GraphicsTest::Running()
|
||||
|
||||
@@ -50,8 +50,8 @@ struct D3D11GraphicsTest : public GraphicsTest
|
||||
void Shutdown();
|
||||
GraphicsWindow *MakeWindow(int width, int height, const char *title);
|
||||
|
||||
HRESULT CreateDevice(const std::vector<IDXGIAdapterPtr> &adaptersToTry,
|
||||
DXGI_SWAP_CHAIN_DESC *swapDesc, D3D_FEATURE_LEVEL *features, UINT flags);
|
||||
HRESULT CreateDevice(IDXGIAdapterPtr adapterToTry, DXGI_SWAP_CHAIN_DESC *swapDesc,
|
||||
D3D_FEATURE_LEVEL *features, UINT flags);
|
||||
void PostDeviceCreate();
|
||||
|
||||
enum BufType
|
||||
@@ -87,40 +87,40 @@ struct D3D11GraphicsTest : public GraphicsTest
|
||||
|
||||
void CreateDefaultInputLayout(ID3DBlobPtr vsblob);
|
||||
|
||||
D3D11BufferCreator MakeBuffer() { return D3D11BufferCreator(this); }
|
||||
D3D11BufferCreator MakeBuffer() { return D3D11BufferCreator(dev); }
|
||||
D3D11TextureCreator MakeTexture(DXGI_FORMAT format, UINT width)
|
||||
{
|
||||
return D3D11TextureCreator(this, format, width, 1, 1);
|
||||
return D3D11TextureCreator(dev, format, width, 1, 1);
|
||||
}
|
||||
D3D11TextureCreator MakeTexture(DXGI_FORMAT format, UINT width, UINT height)
|
||||
{
|
||||
return D3D11TextureCreator(this, format, width, height, 1);
|
||||
return D3D11TextureCreator(dev, format, width, height, 1);
|
||||
}
|
||||
D3D11TextureCreator MakeTexture(DXGI_FORMAT format, UINT width, UINT height, UINT depth)
|
||||
{
|
||||
return D3D11TextureCreator(this, format, width, height, depth);
|
||||
return D3D11TextureCreator(dev, format, width, height, depth);
|
||||
}
|
||||
|
||||
D3D11SamplerCreator MakeSampler() { return D3D11SamplerCreator(this); }
|
||||
D3D11SamplerCreator MakeSampler() { return D3D11SamplerCreator(dev); }
|
||||
template <typename T>
|
||||
D3D11ViewCreator MakeSRV(T res)
|
||||
{
|
||||
return D3D11ViewCreator(this, ViewType::SRV, res);
|
||||
return D3D11ViewCreator(dev, ViewType::SRV, res);
|
||||
}
|
||||
template <typename T>
|
||||
D3D11ViewCreator MakeRTV(T res)
|
||||
{
|
||||
return D3D11ViewCreator(this, ViewType::RTV, res);
|
||||
return D3D11ViewCreator(dev, ViewType::RTV, res);
|
||||
}
|
||||
template <typename T>
|
||||
D3D11ViewCreator MakeDSV(T res)
|
||||
{
|
||||
return D3D11ViewCreator(this, ViewType::DSV, res);
|
||||
return D3D11ViewCreator(dev, ViewType::DSV, res);
|
||||
}
|
||||
template <typename T>
|
||||
D3D11ViewCreator MakeUAV(T res)
|
||||
{
|
||||
return D3D11ViewCreator(this, ViewType::UAV, res);
|
||||
return D3D11ViewCreator(dev, ViewType::UAV, res);
|
||||
}
|
||||
|
||||
std::vector<byte> GetBufferData(ID3D11Buffer *buf, uint32_t offset = 0, uint32_t len = 0);
|
||||
|
||||
@@ -199,7 +199,8 @@ D3D12_ROOT_PARAMETER1 tableParam(D3D12_SHADER_VISIBILITY vis, D3D12_DESCRIPTOR_R
|
||||
return ret;
|
||||
}
|
||||
|
||||
D3D12BufferCreator::D3D12BufferCreator(D3D12GraphicsTest *test) : m_Test(test)
|
||||
D3D12BufferCreator::D3D12BufferCreator(ID3D12DevicePtr dev, D3D12GraphicsTest *test)
|
||||
: m_Dev(dev), m_Test(test)
|
||||
{
|
||||
m_BufDesc.Alignment = 0;
|
||||
m_BufDesc.DepthOrArraySize = 1;
|
||||
@@ -260,20 +261,19 @@ D3D12BufferCreator::operator ID3D12ResourcePtr() const
|
||||
initialState = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
|
||||
ID3D12ResourcePtr buf;
|
||||
CHECK_HR(m_Test->dev->CreateCommittedResource(&m_HeapDesc, D3D12_HEAP_FLAG_NONE, &m_BufDesc,
|
||||
initialState, NULL, __uuidof(ID3D12Resource),
|
||||
(void **)&buf));
|
||||
CHECK_HR(m_Dev->CreateCommittedResource(&m_HeapDesc, D3D12_HEAP_FLAG_NONE, &m_BufDesc, initialState,
|
||||
NULL, __uuidof(ID3D12Resource), (void **)&buf));
|
||||
|
||||
if(m_Initdata)
|
||||
if(m_Initdata && m_Test)
|
||||
m_Test->SetBufferData(buf, D3D12_RESOURCE_STATE_COMMON, (const byte *)m_Initdata,
|
||||
m_BufDesc.Width);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
D3D12TextureCreator::D3D12TextureCreator(D3D12GraphicsTest *test, DXGI_FORMAT format, UINT width,
|
||||
D3D12TextureCreator::D3D12TextureCreator(ID3D12DevicePtr dev, DXGI_FORMAT format, UINT width,
|
||||
UINT height, UINT depth)
|
||||
: m_Test(test)
|
||||
: m_Dev(dev)
|
||||
{
|
||||
m_InitialState = D3D12_RESOURCE_STATE_COMMON;
|
||||
|
||||
@@ -371,15 +371,15 @@ D3D12TextureCreator &D3D12TextureCreator::InitialState(D3D12_RESOURCE_STATES sta
|
||||
D3D12TextureCreator::operator ID3D12ResourcePtr() const
|
||||
{
|
||||
ID3D12ResourcePtr tex;
|
||||
CHECK_HR(m_Test->dev->CreateCommittedResource(&m_HeapDesc, m_HeapFlags, &m_TexDesc, m_InitialState,
|
||||
NULL, __uuidof(ID3D12Resource), (void **)&tex));
|
||||
CHECK_HR(m_Dev->CreateCommittedResource(&m_HeapDesc, m_HeapFlags, &m_TexDesc, m_InitialState,
|
||||
NULL, __uuidof(ID3D12Resource), (void **)&tex));
|
||||
return tex;
|
||||
}
|
||||
|
||||
D3D12ViewCreator::D3D12ViewCreator(D3D12GraphicsTest *test, ID3D12DescriptorHeap *heap,
|
||||
D3D12ViewCreator::D3D12ViewCreator(ID3D12DevicePtr dev, ID3D12DescriptorHeap *heap,
|
||||
ID3D12DescriptorHeap *clearHeap, ViewType viewType,
|
||||
ID3D12Resource *res)
|
||||
: m_Test(test), m_Type(viewType), m_Heap(heap), m_ClearHeap(clearHeap), m_Res(res)
|
||||
: m_Dev(dev), m_Type(viewType), m_Heap(heap), m_ClearHeap(clearHeap), m_Res(res)
|
||||
{
|
||||
D3D12_RESOURCE_DESC resdesc = res->GetDesc();
|
||||
D3D12_RESOURCE_DIMENSION dim = resdesc.Dimension;
|
||||
@@ -784,10 +784,10 @@ D3D12_CPU_DESCRIPTOR_HANDLE D3D12ViewCreator::CreateCPU(ID3D12DescriptorHeap *he
|
||||
uint32_t descriptor)
|
||||
{
|
||||
static UINT increment[] = {
|
||||
m_Test->dev->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV),
|
||||
m_Dev->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV),
|
||||
0, // D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER
|
||||
m_Test->dev->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV),
|
||||
m_Test->dev->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV),
|
||||
m_Dev->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV),
|
||||
m_Dev->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV),
|
||||
};
|
||||
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE cpu = heap->GetCPUDescriptorHandleForHeapStart();
|
||||
@@ -797,17 +797,17 @@ D3D12_CPU_DESCRIPTOR_HANDLE D3D12ViewCreator::CreateCPU(ID3D12DescriptorHeap *he
|
||||
if(m_Type == ViewType::DSV)
|
||||
{
|
||||
cpu.ptr += increment[D3D12_DESCRIPTOR_HEAP_TYPE_DSV] * descriptor;
|
||||
m_Test->dev->CreateDepthStencilView(m_Res, &desc.dsv, cpu);
|
||||
m_Dev->CreateDepthStencilView(m_Res, &desc.dsv, cpu);
|
||||
}
|
||||
else if(m_Type == ViewType::RTV)
|
||||
{
|
||||
cpu.ptr += increment[D3D12_DESCRIPTOR_HEAP_TYPE_RTV] * descriptor;
|
||||
m_Test->dev->CreateRenderTargetView(m_Res, &desc.rtv, cpu);
|
||||
m_Dev->CreateRenderTargetView(m_Res, &desc.rtv, cpu);
|
||||
}
|
||||
else if(m_Type == ViewType::CBV)
|
||||
{
|
||||
cpu.ptr += increment[D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV] * descriptor;
|
||||
m_Test->dev->CreateConstantBufferView(&desc.cbv, cpu);
|
||||
m_Dev->CreateConstantBufferView(&desc.cbv, cpu);
|
||||
}
|
||||
else if(m_Type == ViewType::SRV)
|
||||
{
|
||||
@@ -830,7 +830,7 @@ D3D12_CPU_DESCRIPTOR_HANDLE D3D12ViewCreator::CreateCPU(ID3D12DescriptorHeap *he
|
||||
desc.srv.Shader4ComponentMapping = Shader4ComponentMapping;
|
||||
|
||||
cpu.ptr += increment[D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV] * descriptor;
|
||||
m_Test->dev->CreateShaderResourceView(m_Res, &desc.srv, cpu);
|
||||
m_Dev->CreateShaderResourceView(m_Res, &desc.srv, cpu);
|
||||
}
|
||||
else if(m_Type == ViewType::UAV)
|
||||
{
|
||||
@@ -851,7 +851,7 @@ D3D12_CPU_DESCRIPTOR_HANDLE D3D12ViewCreator::CreateCPU(ID3D12DescriptorHeap *he
|
||||
}
|
||||
|
||||
cpu.ptr += increment[D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV] * descriptor;
|
||||
m_Test->dev->CreateUnorderedAccessView(m_Res, NULL, &desc.uav, cpu);
|
||||
m_Dev->CreateUnorderedAccessView(m_Res, NULL, &desc.uav, cpu);
|
||||
}
|
||||
|
||||
return cpu;
|
||||
@@ -863,10 +863,10 @@ D3D12_GPU_DESCRIPTOR_HANDLE D3D12ViewCreator::CreateGPU(ID3D12DescriptorHeap *he
|
||||
CreateCPU(heap, descriptor);
|
||||
|
||||
static UINT increment[] = {
|
||||
m_Test->dev->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV),
|
||||
m_Dev->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV),
|
||||
0, // D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER
|
||||
m_Test->dev->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV),
|
||||
m_Test->dev->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV),
|
||||
m_Dev->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV),
|
||||
m_Dev->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV),
|
||||
};
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE gpu = heap->GetGPUDescriptorHandleForHeapStart();
|
||||
@@ -881,7 +881,7 @@ D3D12_GPU_DESCRIPTOR_HANDLE D3D12ViewCreator::CreateGPU(ID3D12DescriptorHeap *he
|
||||
return gpu;
|
||||
}
|
||||
|
||||
D3D12PSOCreator::D3D12PSOCreator(D3D12GraphicsTest *test) : m_Test(test)
|
||||
D3D12PSOCreator::D3D12PSOCreator(ID3D12DevicePtr dev) : m_Dev(dev)
|
||||
{
|
||||
GraphicsDesc.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID;
|
||||
GraphicsDesc.RasterizerState.CullMode = D3D12_CULL_MODE_NONE;
|
||||
@@ -963,7 +963,13 @@ D3D12PSOCreator &D3D12PSOCreator::InputLayout(const std::vector<D3D12_INPUT_ELEM
|
||||
|
||||
D3D12PSOCreator &D3D12PSOCreator::InputLayout()
|
||||
{
|
||||
return InputLayout(m_Test->DefaultInputLayout());
|
||||
const D3D12_INPUT_CLASSIFICATION vertex = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
|
||||
static const std::vector<D3D12_INPUT_ELEMENT_DESC> defaultLayout = {
|
||||
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, vertex, 0},
|
||||
{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, vertex, 0},
|
||||
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 28, vertex, 0},
|
||||
};
|
||||
return InputLayout(defaultLayout);
|
||||
}
|
||||
|
||||
D3D12PSOCreator &D3D12PSOCreator::StripRestart(D3D12_INDEX_BUFFER_STRIP_CUT_VALUE stripCut)
|
||||
@@ -1011,13 +1017,13 @@ D3D12PSOCreator::operator ID3D12PipelineStatePtr() const
|
||||
ID3D12PipelineStatePtr pso;
|
||||
if(ComputeDesc.CS.BytecodeLength > 0)
|
||||
{
|
||||
CHECK_HR(m_Test->dev->CreateComputePipelineState(&ComputeDesc, __uuidof(ID3D12PipelineState),
|
||||
(void **)&pso));
|
||||
CHECK_HR(m_Dev->CreateComputePipelineState(&ComputeDesc, __uuidof(ID3D12PipelineState),
|
||||
(void **)&pso));
|
||||
}
|
||||
else
|
||||
{
|
||||
CHECK_HR(m_Test->dev->CreateGraphicsPipelineState(&GraphicsDesc, __uuidof(ID3D12PipelineState),
|
||||
(void **)&pso));
|
||||
CHECK_HR(m_Dev->CreateGraphicsPipelineState(&GraphicsDesc, __uuidof(ID3D12PipelineState),
|
||||
(void **)&pso));
|
||||
}
|
||||
return pso;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ struct D3D12GraphicsTest;
|
||||
class D3D12PSOCreator
|
||||
{
|
||||
public:
|
||||
D3D12PSOCreator(D3D12GraphicsTest *test);
|
||||
D3D12PSOCreator(ID3D12DevicePtr dev);
|
||||
|
||||
D3D12PSOCreator &VS(ID3DBlobPtr blob);
|
||||
D3D12PSOCreator &HS(ID3DBlobPtr blob);
|
||||
@@ -104,13 +104,13 @@ public:
|
||||
D3D12_COMPUTE_PIPELINE_STATE_DESC ComputeDesc = {};
|
||||
|
||||
private:
|
||||
D3D12GraphicsTest *m_Test;
|
||||
ID3D12DevicePtr m_Dev;
|
||||
};
|
||||
|
||||
class D3D12BufferCreator
|
||||
{
|
||||
public:
|
||||
D3D12BufferCreator(D3D12GraphicsTest *test);
|
||||
D3D12BufferCreator(ID3D12DevicePtr dev, D3D12GraphicsTest *test);
|
||||
|
||||
D3D12BufferCreator &UAV();
|
||||
|
||||
@@ -135,6 +135,7 @@ public:
|
||||
operator ID3D12ResourcePtr() const;
|
||||
|
||||
private:
|
||||
ID3D12DevicePtr m_Dev;
|
||||
D3D12GraphicsTest *m_Test;
|
||||
|
||||
D3D12_RESOURCE_DESC m_BufDesc;
|
||||
@@ -145,8 +146,7 @@ private:
|
||||
class D3D12TextureCreator
|
||||
{
|
||||
public:
|
||||
D3D12TextureCreator(D3D12GraphicsTest *test, DXGI_FORMAT format, UINT width, UINT height,
|
||||
UINT depth);
|
||||
D3D12TextureCreator(ID3D12DevicePtr dev, DXGI_FORMAT format, UINT width, UINT height, UINT depth);
|
||||
|
||||
D3D12TextureCreator &Mips(UINT mips);
|
||||
D3D12TextureCreator &Array(UINT size);
|
||||
@@ -167,7 +167,7 @@ public:
|
||||
operator ID3D12ResourcePtr() const;
|
||||
|
||||
protected:
|
||||
D3D12GraphicsTest *m_Test;
|
||||
ID3D12DevicePtr m_Dev;
|
||||
|
||||
D3D12_RESOURCE_STATES m_InitialState;
|
||||
D3D12_RESOURCE_DESC m_TexDesc;
|
||||
@@ -178,8 +178,8 @@ protected:
|
||||
class D3D12ViewCreator
|
||||
{
|
||||
public:
|
||||
D3D12ViewCreator(D3D12GraphicsTest *test, ID3D12DescriptorHeap *heap,
|
||||
ID3D12DescriptorHeap *clearHeap, ViewType viewType, ID3D12Resource *res);
|
||||
D3D12ViewCreator(ID3D12DevicePtr dev, ID3D12DescriptorHeap *heap, ID3D12DescriptorHeap *clearHeap,
|
||||
ViewType viewType, ID3D12Resource *res);
|
||||
|
||||
// common params
|
||||
D3D12ViewCreator &Format(DXGI_FORMAT format);
|
||||
@@ -229,7 +229,7 @@ public:
|
||||
private:
|
||||
void SetupDescriptors(ViewType viewType, ResourceType resType);
|
||||
|
||||
D3D12GraphicsTest *m_Test;
|
||||
ID3D12DevicePtr m_Dev;
|
||||
ID3D12Resource *m_Res;
|
||||
ID3D12DescriptorHeap *m_Heap;
|
||||
ID3D12DescriptorHeap *m_ClearHeap;
|
||||
@@ -276,13 +276,6 @@ D3D12_INDIRECT_ARGUMENT_DESC drawArg();
|
||||
D3D12_INDIRECT_ARGUMENT_DESC drawIndexedArg();
|
||||
D3D12_INDIRECT_ARGUMENT_DESC dispatchArg();
|
||||
|
||||
#define GET_REFCOUNT(val, obj) \
|
||||
do \
|
||||
{ \
|
||||
obj->AddRef(); \
|
||||
val = obj->Release(); \
|
||||
} while(0)
|
||||
|
||||
#define CHECK_HR(expr) \
|
||||
{ \
|
||||
HRESULT hr = (expr); \
|
||||
|
||||
@@ -55,7 +55,7 @@ RD_TEST(D3D12_Large_Buffer, D3D12GraphicsTest)
|
||||
verts[indices[1]] = DefaultTri[1];
|
||||
verts[indices[2]] = DefaultTri[2];
|
||||
|
||||
range.End = vb->GetDesc().Width;
|
||||
range.End = (SIZE_T)vb->GetDesc().Width;
|
||||
|
||||
vb->Unmap(0, &range);
|
||||
|
||||
|
||||
@@ -301,14 +301,6 @@ bool D3D12GraphicsTest::Init()
|
||||
|
||||
m_GPUSyncFence->SetName(L"GPUSync fence");
|
||||
|
||||
const D3D12_INPUT_CLASSIFICATION vertex = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
|
||||
|
||||
m_DefaultInputLayout = {
|
||||
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, vertex, 0},
|
||||
{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, vertex, 0},
|
||||
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 28, vertex, 0},
|
||||
};
|
||||
|
||||
CHECK_HR(dev->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
__uuidof(ID3D12CommandAllocator), (void **)&m_Alloc));
|
||||
|
||||
|
||||
@@ -75,7 +75,6 @@ struct D3D12GraphicsTest : public GraphicsTest
|
||||
ID3DBlobPtr Compile(std::string src, std::string entry, std::string profile);
|
||||
void WriteBlob(std::string name, ID3DBlobPtr blob, bool compress);
|
||||
|
||||
const std::vector<D3D12_INPUT_ELEMENT_DESC> &DefaultInputLayout() { return m_DefaultInputLayout; }
|
||||
void SetBlobPath(std::string name, ID3DBlobPtr &blob);
|
||||
void SetBlobPath(std::string name, ID3D12DeviceChild *shader);
|
||||
|
||||
@@ -89,45 +88,45 @@ struct D3D12GraphicsTest : public GraphicsTest
|
||||
UINT NumStaticSamplers = 0, const D3D12_STATIC_SAMPLER_DESC *StaticSamplers = NULL);
|
||||
ID3D12CommandSignaturePtr MakeCommandSig(ID3D12RootSignaturePtr rootSig,
|
||||
const std::vector<D3D12_INDIRECT_ARGUMENT_DESC> ¶ms);
|
||||
D3D12PSOCreator MakePSO() { return D3D12PSOCreator(this); }
|
||||
D3D12BufferCreator MakeBuffer() { return D3D12BufferCreator(this); }
|
||||
D3D12PSOCreator MakePSO() { return D3D12PSOCreator(dev); }
|
||||
D3D12BufferCreator MakeBuffer() { return D3D12BufferCreator(dev, this); }
|
||||
D3D12TextureCreator MakeTexture(DXGI_FORMAT format, UINT width)
|
||||
{
|
||||
return D3D12TextureCreator(this, format, width, 1, 1);
|
||||
return D3D12TextureCreator(dev, format, width, 1, 1);
|
||||
}
|
||||
D3D12TextureCreator MakeTexture(DXGI_FORMAT format, UINT width, UINT height)
|
||||
{
|
||||
return D3D12TextureCreator(this, format, width, height, 1);
|
||||
return D3D12TextureCreator(dev, format, width, height, 1);
|
||||
}
|
||||
D3D12TextureCreator MakeTexture(DXGI_FORMAT format, UINT width, UINT height, UINT depth)
|
||||
{
|
||||
return D3D12TextureCreator(this, format, width, height, depth);
|
||||
return D3D12TextureCreator(dev, format, width, height, depth);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
D3D12ViewCreator MakeCBV(T res)
|
||||
{
|
||||
return D3D12ViewCreator(this, m_CBVUAVSRV, NULL, ViewType::CBV, res);
|
||||
return D3D12ViewCreator(dev, m_CBVUAVSRV, NULL, ViewType::CBV, res);
|
||||
}
|
||||
template <typename T>
|
||||
D3D12ViewCreator MakeSRV(T res)
|
||||
{
|
||||
return D3D12ViewCreator(this, m_CBVUAVSRV, NULL, ViewType::SRV, res);
|
||||
return D3D12ViewCreator(dev, m_CBVUAVSRV, NULL, ViewType::SRV, res);
|
||||
}
|
||||
template <typename T>
|
||||
D3D12ViewCreator MakeRTV(T res)
|
||||
{
|
||||
return D3D12ViewCreator(this, m_RTV, NULL, ViewType::RTV, res);
|
||||
return D3D12ViewCreator(dev, m_RTV, NULL, ViewType::RTV, res);
|
||||
}
|
||||
template <typename T>
|
||||
D3D12ViewCreator MakeDSV(T res)
|
||||
{
|
||||
return D3D12ViewCreator(this, m_DSV, NULL, ViewType::DSV, res);
|
||||
return D3D12ViewCreator(dev, m_DSV, NULL, ViewType::DSV, res);
|
||||
}
|
||||
template <typename T>
|
||||
D3D12ViewCreator MakeUAV(T res)
|
||||
{
|
||||
return D3D12ViewCreator(this, m_CBVUAVSRV, m_Clear, ViewType::UAV, res);
|
||||
return D3D12ViewCreator(dev, m_CBVUAVSRV, m_Clear, ViewType::UAV, res);
|
||||
}
|
||||
|
||||
std::vector<byte> GetBufferData(ID3D12ResourcePtr buffer, D3D12_RESOURCE_STATES state,
|
||||
@@ -227,8 +226,6 @@ struct D3D12GraphicsTest : public GraphicsTest
|
||||
|
||||
ID3D12CommandQueuePtr queue;
|
||||
|
||||
std::vector<D3D12_INPUT_ELEMENT_DESC> m_DefaultInputLayout;
|
||||
|
||||
ID3D12FencePtr m_GPUSyncFence;
|
||||
HANDLE m_GPUSyncHandle = NULL;
|
||||
UINT64 m_GPUSyncCounter = 1;
|
||||
|
||||
@@ -44,6 +44,13 @@ COM_SMARTPTR(IDXGIAdapter);
|
||||
COM_SMARTPTR(IDXGISurface);
|
||||
COM_SMARTPTR(IDXGIResource);
|
||||
|
||||
template <typename T>
|
||||
ULONG GetRefcount(T *ptr)
|
||||
{
|
||||
ptr->AddRef();
|
||||
return ptr->Release();
|
||||
}
|
||||
|
||||
std::vector<IDXGIAdapterPtr> FindD3DAdapters(IDXGIFactoryPtr factory, int argc, char **argv,
|
||||
bool &warp);
|
||||
|
||||
|
||||
@@ -453,7 +453,7 @@ void main()
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> scoped(doneLock);
|
||||
while(threadsDone < threadCount)
|
||||
while(threadsDone < (int)threadCount)
|
||||
doneCV.wait(scoped);
|
||||
threadsDone = 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import struct
|
||||
import math
|
||||
import renderdoc as rd
|
||||
import rdtest
|
||||
|
||||
|
||||
class D3D11_Refcount_Check(rdtest.TestCase):
|
||||
demos_test_name = 'D3D11_Refcount_Check'
|
||||
|
||||
def get_capture_options(self):
|
||||
# Ensure we enable API validation since the test relies on being able to query it
|
||||
ret = rd.CaptureOptions()
|
||||
|
||||
ret.apiValidation = True
|
||||
ret.debugOutputMute = False
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def check_capture(self):
|
||||
draw = self.find_draw("Color Draw")
|
||||
|
||||
self.check(draw is not None)
|
||||
|
||||
draw = draw.next
|
||||
|
||||
self.controller.SetFrameEvent(draw.eventId, False)
|
||||
|
||||
pipe: rd.PipeState = self.controller.GetPipelineState()
|
||||
|
||||
self.check_pixel_value(pipe.GetOutputTargets()[0].resourceId, 0.5, 0.5, [0.0, 1.0, 0.0, 1.0])
|
||||
|
||||
rdtest.log.success("Captured loaded with color as expected")
|
||||
Reference in New Issue
Block a user