mirror of https://github.com/AxioDL/boo.git
D3D11/12 mipmapping fixes
This commit is contained in:
parent
c8b72e8bef
commit
2f254dc955
|
@ -121,10 +121,10 @@ class D3D11TextureS : public ITextureS
|
||||||
friend class D3D11DataFactory;
|
friend class D3D11DataFactory;
|
||||||
size_t m_sz;
|
size_t m_sz;
|
||||||
D3D11TextureS(D3D11Context* ctx, size_t width, size_t height, size_t mips,
|
D3D11TextureS(D3D11Context* ctx, size_t width, size_t height, size_t mips,
|
||||||
TextureFormat fmt, const void* data, size_t sz)
|
TextureFormat fmt, const void* data, size_t sz)
|
||||||
: m_sz(sz)
|
: m_sz(sz)
|
||||||
{
|
{
|
||||||
CD3D11_TEXTURE2D_DESC desc(DXGI_FORMAT_R8G8B8A8_UNORM, width, height, 1, mips,
|
CD3D11_TEXTURE2D_DESC desc(DXGI_FORMAT_R8G8B8A8_UNORM, width, height, 1, mips,
|
||||||
D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_IMMUTABLE);
|
D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_IMMUTABLE);
|
||||||
|
|
||||||
const uint8_t* dataIt = static_cast<const uint8_t*>(data);
|
const uint8_t* dataIt = static_cast<const uint8_t*>(data);
|
||||||
|
@ -140,8 +140,8 @@ class D3D11TextureS : public ITextureS
|
||||||
}
|
}
|
||||||
|
|
||||||
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&desc, upData, &m_tex));
|
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&desc, upData, &m_tex));
|
||||||
ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_tex.Get(),
|
ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_tex.Get(),
|
||||||
&CD3D11_SHADER_RESOURCE_VIEW_DESC(m_tex.Get(), D3D_SRV_DIMENSION_TEXTURE2D, DXGI_FORMAT_R8G8B8A8_UNORM), &m_srv));
|
&CD3D11_SHADER_RESOURCE_VIEW_DESC(m_tex.Get(), D3D_SRV_DIMENSION_TEXTURE2D, DXGI_FORMAT_R8G8B8A8_UNORM, 0, mips), &m_srv));
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
ComPtr<ID3D11Texture2D> m_tex;
|
ComPtr<ID3D11Texture2D> m_tex;
|
||||||
|
@ -245,7 +245,7 @@ class D3D11TextureD : public ITextureD
|
||||||
for (int i=0 ; i<3 ; ++i)
|
for (int i=0 ; i<3 ; ++i)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&desc, nullptr, &m_texs[i]));
|
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&desc, nullptr, &m_texs[i]));
|
||||||
ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_texs[i].Get(),
|
ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_texs[i].Get(),
|
||||||
&CD3D11_SHADER_RESOURCE_VIEW_DESC(m_texs[i].Get(), D3D_SRV_DIMENSION_TEXTURE2D, pixelFmt), &m_srvs[i]));
|
&CD3D11_SHADER_RESOURCE_VIEW_DESC(m_texs[i].Get(), D3D_SRV_DIMENSION_TEXTURE2D, pixelFmt), &m_srvs[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,34 +270,34 @@ class D3D11TextureR : public ITextureR
|
||||||
|
|
||||||
void Setup(D3D11Context* ctx, size_t width, size_t height, size_t samples)
|
void Setup(D3D11Context* ctx, size_t width, size_t height, size_t samples)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R8G8B8A8_UNORM, width, height,
|
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R8G8B8A8_UNORM, width, height,
|
||||||
1, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, 0, 1), nullptr, &m_tex));
|
1, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, 0, 1), nullptr, &m_tex));
|
||||||
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_D24_UNORM_S8_UINT, width, height,
|
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_D24_UNORM_S8_UINT, width, height,
|
||||||
1, 1, D3D11_BIND_DEPTH_STENCIL, D3D11_USAGE_DEFAULT, 0, samples), nullptr, &m_depthTex));
|
1, 1, D3D11_BIND_DEPTH_STENCIL, D3D11_USAGE_DEFAULT, 0, samples), nullptr, &m_depthTex));
|
||||||
|
|
||||||
if (samples > 1)
|
if (samples > 1)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R8G8B8A8_UNORM, width, height,
|
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R8G8B8A8_UNORM, width, height,
|
||||||
1, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, 0, samples), nullptr, &m_msaaTex));
|
1, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, 0, samples), nullptr, &m_msaaTex));
|
||||||
ThrowIfFailed(ctx->m_dev->CreateRenderTargetView(m_msaaTex.Get(),
|
ThrowIfFailed(ctx->m_dev->CreateRenderTargetView(m_msaaTex.Get(),
|
||||||
&CD3D11_RENDER_TARGET_VIEW_DESC(m_msaaTex.Get(), D3D11_RTV_DIMENSION_TEXTURE2DMS), &m_rtv));
|
&CD3D11_RENDER_TARGET_VIEW_DESC(m_msaaTex.Get(), D3D11_RTV_DIMENSION_TEXTURE2DMS), &m_rtv));
|
||||||
ThrowIfFailed(ctx->m_dev->CreateDepthStencilView(m_depthTex.Get(),
|
ThrowIfFailed(ctx->m_dev->CreateDepthStencilView(m_depthTex.Get(),
|
||||||
&CD3D11_DEPTH_STENCIL_VIEW_DESC(m_depthTex.Get(), D3D11_DSV_DIMENSION_TEXTURE2DMS), &m_dsv));
|
&CD3D11_DEPTH_STENCIL_VIEW_DESC(m_depthTex.Get(), D3D11_DSV_DIMENSION_TEXTURE2DMS), &m_dsv));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ThrowIfFailed(ctx->m_dev->CreateRenderTargetView(m_tex.Get(),
|
ThrowIfFailed(ctx->m_dev->CreateRenderTargetView(m_tex.Get(),
|
||||||
&CD3D11_RENDER_TARGET_VIEW_DESC(m_tex.Get(), D3D11_RTV_DIMENSION_TEXTURE2D), &m_rtv));
|
&CD3D11_RENDER_TARGET_VIEW_DESC(m_tex.Get(), D3D11_RTV_DIMENSION_TEXTURE2D), &m_rtv));
|
||||||
ThrowIfFailed(ctx->m_dev->CreateDepthStencilView(m_depthTex.Get(),
|
ThrowIfFailed(ctx->m_dev->CreateDepthStencilView(m_depthTex.Get(),
|
||||||
&CD3D11_DEPTH_STENCIL_VIEW_DESC(m_depthTex.Get(), D3D11_DSV_DIMENSION_TEXTURE2D), &m_dsv));
|
&CD3D11_DEPTH_STENCIL_VIEW_DESC(m_depthTex.Get(), D3D11_DSV_DIMENSION_TEXTURE2D), &m_dsv));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_tex.Get(),
|
ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_tex.Get(),
|
||||||
&CD3D11_SHADER_RESOURCE_VIEW_DESC(m_tex.Get(), D3D11_SRV_DIMENSION_TEXTURE2D), &m_srv));
|
&CD3D11_SHADER_RESOURCE_VIEW_DESC(m_tex.Get(), D3D11_SRV_DIMENSION_TEXTURE2D), &m_srv));
|
||||||
}
|
}
|
||||||
|
|
||||||
D3D11TextureR(D3D11Context* ctx, size_t width, size_t height, size_t samples)
|
D3D11TextureR(D3D11Context* ctx, size_t width, size_t height, size_t samples)
|
||||||
: m_width(width), m_height(height), m_samples(samples)
|
: m_width(width), m_height(height), m_samples(samples)
|
||||||
{
|
{
|
||||||
if (samples == 0) m_samples = 1;
|
if (samples == 0) m_samples = 1;
|
||||||
Setup(ctx, width, height, samples);
|
Setup(ctx, width, height, samples);
|
||||||
|
@ -433,8 +433,8 @@ class D3D11ShaderPipeline : public IShaderPipeline
|
||||||
ThrowIfFailed(ctx->m_dev->CreateVertexShader(vert->GetBufferPointer(), vert->GetBufferSize(), nullptr, &m_vShader));
|
ThrowIfFailed(ctx->m_dev->CreateVertexShader(vert->GetBufferPointer(), vert->GetBufferSize(), nullptr, &m_vShader));
|
||||||
ThrowIfFailed(ctx->m_dev->CreatePixelShader(pixel->GetBufferPointer(), pixel->GetBufferSize(), nullptr, &m_pShader));
|
ThrowIfFailed(ctx->m_dev->CreatePixelShader(pixel->GetBufferPointer(), pixel->GetBufferSize(), nullptr, &m_pShader));
|
||||||
|
|
||||||
CD3D11_RASTERIZER_DESC rasDesc(D3D11_FILL_SOLID, backfaceCulling ? D3D11_CULL_BACK : D3D11_CULL_NONE, true,
|
CD3D11_RASTERIZER_DESC rasDesc(D3D11_FILL_SOLID, backfaceCulling ? D3D11_CULL_BACK : D3D11_CULL_NONE, true,
|
||||||
D3D11_DEFAULT_DEPTH_BIAS, D3D11_DEFAULT_DEPTH_BIAS_CLAMP, D3D11_DEFAULT_SLOPE_SCALED_DEPTH_BIAS,
|
D3D11_DEFAULT_DEPTH_BIAS, D3D11_DEFAULT_DEPTH_BIAS_CLAMP, D3D11_DEFAULT_SLOPE_SCALED_DEPTH_BIAS,
|
||||||
true, true, false, false);
|
true, true, false, false);
|
||||||
ThrowIfFailed(ctx->m_dev->CreateRasterizerState(&rasDesc, &m_rasState));
|
ThrowIfFailed(ctx->m_dev->CreateRasterizerState(&rasDesc, &m_rasState));
|
||||||
|
|
||||||
|
@ -450,7 +450,7 @@ class D3D11ShaderPipeline : public IShaderPipeline
|
||||||
blDesc.RenderTarget[0].DestBlend = BLEND_FACTOR_TABLE[int(dstFac)];
|
blDesc.RenderTarget[0].DestBlend = BLEND_FACTOR_TABLE[int(dstFac)];
|
||||||
ThrowIfFailed(ctx->m_dev->CreateBlendState(&blDesc, &m_blState));
|
ThrowIfFailed(ctx->m_dev->CreateBlendState(&blDesc, &m_blState));
|
||||||
|
|
||||||
ThrowIfFailed(ctx->m_dev->CreateInputLayout(vtxFmt->m_elements.get(), vtxFmt->m_elementCount,
|
ThrowIfFailed(ctx->m_dev->CreateInputLayout(vtxFmt->m_elements.get(), vtxFmt->m_elementCount,
|
||||||
vert->GetBufferPointer(), vert->GetBufferSize(), &m_inLayout));
|
vert->GetBufferPointer(), vert->GetBufferSize(), &m_inLayout));
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
|
@ -729,7 +729,7 @@ struct D3D11CommandQueue : IGraphicsCommandQueue
|
||||||
ID3D11Texture2D* src = csource->m_tex.Get();
|
ID3D11Texture2D* src = csource->m_tex.Get();
|
||||||
self->m_ctx->m_devCtx->CopyResource(dest.Get(), src);
|
self->m_ctx->m_devCtx->CopyResource(dest.Get(), src);
|
||||||
}
|
}
|
||||||
|
|
||||||
self->m_windowCtx->m_swapChain->Present(1, 0);
|
self->m_windowCtx->m_swapChain->Present(1, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1153,7 +1153,7 @@ public:
|
||||||
thread_local D3D11Data* D3D11DataFactory::m_deferredData;
|
thread_local D3D11Data* D3D11DataFactory::m_deferredData;
|
||||||
|
|
||||||
void D3D11CommandQueue::execute()
|
void D3D11CommandQueue::execute()
|
||||||
{
|
{
|
||||||
/* Stage dynamic uploads */
|
/* Stage dynamic uploads */
|
||||||
D3D11DataFactory* gfxF = static_cast<D3D11DataFactory*>(m_parent->getDataFactory());
|
D3D11DataFactory* gfxF = static_cast<D3D11DataFactory*>(m_parent->getDataFactory());
|
||||||
gfxF->procDeletes();
|
gfxF->procDeletes();
|
||||||
|
|
|
@ -77,8 +77,8 @@ class D3D12GraphicsBufferS : public IGraphicsBufferS
|
||||||
size_t reqSz = GetRequiredIntermediateSize(ctx->m_dev.Get(), &m_gpuDesc, 0, 1);
|
size_t reqSz = GetRequiredIntermediateSize(ctx->m_dev.Get(), &m_gpuDesc, 0, 1);
|
||||||
m_gpuDesc = CD3DX12_RESOURCE_DESC::Buffer(reqSz);
|
m_gpuDesc = CD3DX12_RESOURCE_DESC::Buffer(reqSz);
|
||||||
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(
|
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(
|
||||||
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
|
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
|
||||||
D3D12_HEAP_FLAG_NONE, &m_gpuDesc,
|
D3D12_HEAP_FLAG_NONE, &m_gpuDesc,
|
||||||
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, __uuidof(ID3D12Resource), &m_buf));
|
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, __uuidof(ID3D12Resource), &m_buf));
|
||||||
|
|
||||||
D3D12_SUBRESOURCE_DATA upData = {data, LONG_PTR(m_sz), LONG_PTR(m_sz)};
|
D3D12_SUBRESOURCE_DATA upData = {data, LONG_PTR(m_sz), LONG_PTR(m_sz)};
|
||||||
|
@ -94,12 +94,12 @@ public:
|
||||||
|
|
||||||
UINT64 placeForGPU(D3D12Context* ctx, ID3D12Heap* gpuHeap, UINT64 offset)
|
UINT64 placeForGPU(D3D12Context* ctx, ID3D12Heap* gpuHeap, UINT64 offset)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(ctx->m_dev->CreatePlacedResource(gpuHeap, offset, &m_gpuDesc, m_state,
|
ThrowIfFailed(ctx->m_dev->CreatePlacedResource(gpuHeap, offset, &m_gpuDesc, m_state,
|
||||||
nullptr, __uuidof(ID3D12Resource), &m_gpuBuf));
|
nullptr, __uuidof(ID3D12Resource), &m_gpuBuf));
|
||||||
|
|
||||||
/* Stage resource upload */
|
/* Stage resource upload */
|
||||||
CommandSubresourcesTransfer<1>(ctx->m_dev.Get(), ctx->m_loadlist.Get(), m_gpuBuf.Get(), m_buf.Get(), 0, 0, 1);
|
CommandSubresourcesTransfer<1>(ctx->m_dev.Get(), ctx->m_loadlist.Get(), m_gpuBuf.Get(), m_buf.Get(), 0, 0, 1);
|
||||||
ctx->m_loadlist->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_gpuBuf.Get(),
|
ctx->m_loadlist->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_gpuBuf.Get(),
|
||||||
D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER));
|
D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER));
|
||||||
|
|
||||||
return NextHeapOffset(offset, ctx->m_dev->GetResourceAllocationInfo(0, 1, &m_gpuDesc));
|
return NextHeapOffset(offset, ctx->m_dev->GetResourceAllocationInfo(0, 1, &m_gpuDesc));
|
||||||
|
@ -126,7 +126,7 @@ class D3D12GraphicsBufferD : public IGraphicsBufferD
|
||||||
for (int i=0 ; i<2 ; ++i)
|
for (int i=0 ; i<2 ; ++i)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(
|
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(
|
||||||
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
|
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
|
||||||
D3D12_HEAP_FLAG_NONE, &desc,
|
D3D12_HEAP_FLAG_NONE, &desc,
|
||||||
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, __uuidof(ID3D12Resource), &m_bufs[i]));
|
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, __uuidof(ID3D12Resource), &m_bufs[i]));
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ public:
|
||||||
for (int i=0 ; i<2 ; ++i)
|
for (int i=0 ; i<2 ; ++i)
|
||||||
{
|
{
|
||||||
D3D12_RESOURCE_DESC desc = m_bufs[i]->GetDesc();
|
D3D12_RESOURCE_DESC desc = m_bufs[i]->GetDesc();
|
||||||
ThrowIfFailed(ctx->m_dev->CreatePlacedResource(gpuHeap, offset, &desc, m_state,
|
ThrowIfFailed(ctx->m_dev->CreatePlacedResource(gpuHeap, offset, &desc, m_state,
|
||||||
nullptr, __uuidof(ID3D12Resource), &m_gpuBufs[i]));
|
nullptr, __uuidof(ID3D12Resource), &m_gpuBufs[i]));
|
||||||
offset = NextHeapOffset(offset, ctx->m_dev->GetResourceAllocationInfo(0, 1, &desc));
|
offset = NextHeapOffset(offset, ctx->m_dev->GetResourceAllocationInfo(0, 1, &desc));
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ class D3D12TextureS : public ITextureS
|
||||||
m_gpuDesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, width, height, 1, mips);
|
m_gpuDesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, width, height, 1, mips);
|
||||||
size_t reqSz = GetRequiredIntermediateSize(ctx->m_dev.Get(), &m_gpuDesc, 0, mips);
|
size_t reqSz = GetRequiredIntermediateSize(ctx->m_dev.Get(), &m_gpuDesc, 0, mips);
|
||||||
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(
|
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(
|
||||||
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
|
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
|
||||||
D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Buffer(reqSz),
|
D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Buffer(reqSz),
|
||||||
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, __uuidof(ID3D12Resource), &m_tex));
|
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, __uuidof(ID3D12Resource), &m_tex));
|
||||||
|
|
||||||
|
@ -195,12 +195,13 @@ public:
|
||||||
|
|
||||||
UINT64 placeForGPU(D3D12Context* ctx, ID3D12Heap* gpuHeap, UINT64 offset)
|
UINT64 placeForGPU(D3D12Context* ctx, ID3D12Heap* gpuHeap, UINT64 offset)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(ctx->m_dev->CreatePlacedResource(gpuHeap, offset, &m_gpuDesc,
|
ThrowIfFailed(ctx->m_dev->CreatePlacedResource(gpuHeap, offset, &m_gpuDesc,
|
||||||
D3D12_RESOURCE_STATE_COPY_DEST,
|
D3D12_RESOURCE_STATE_COPY_DEST,
|
||||||
nullptr, __uuidof(ID3D12Resource), &m_gpuTex));
|
nullptr, __uuidof(ID3D12Resource), &m_gpuTex));
|
||||||
|
|
||||||
CommandSubresourcesTransfer<16>(ctx->m_dev.Get(), ctx->m_loadlist.Get(), m_gpuTex.Get(), m_tex.Get(), 0, 0, m_gpuDesc.MipLevels);
|
CommandSubresourcesTransfer<16>(ctx->m_dev.Get(), ctx->m_loadlist.Get(), m_gpuTex.Get(),
|
||||||
ctx->m_loadlist->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_gpuTex.Get(),
|
m_tex.Get(), 0, 0, m_gpuDesc.MipLevels);
|
||||||
|
ctx->m_loadlist->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_gpuTex.Get(),
|
||||||
D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE));
|
D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE));
|
||||||
|
|
||||||
return NextHeapOffset(offset, ctx->m_dev->GetResourceAllocationInfo(0, 1, &m_gpuDesc));
|
return NextHeapOffset(offset, ctx->m_dev->GetResourceAllocationInfo(0, 1, &m_gpuDesc));
|
||||||
|
@ -336,8 +337,8 @@ class D3D12TextureD : public ITextureD
|
||||||
for (int i=0 ; i<2 ; ++i)
|
for (int i=0 ; i<2 ; ++i)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(
|
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(
|
||||||
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
|
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
|
||||||
D3D12_HEAP_FLAG_NONE,
|
D3D12_HEAP_FLAG_NONE,
|
||||||
&CD3DX12_RESOURCE_DESC::Buffer(reqSz),
|
&CD3DX12_RESOURCE_DESC::Buffer(reqSz),
|
||||||
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, __uuidof(ID3D12Resource), &m_texs[i]));
|
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, __uuidof(ID3D12Resource), &m_texs[i]));
|
||||||
}
|
}
|
||||||
|
@ -357,7 +358,7 @@ public:
|
||||||
for (int i=0 ; i<2 ; ++i)
|
for (int i=0 ; i<2 ; ++i)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(ctx->m_dev->CreatePlacedResource(gpuHeap, offset, &m_gpuDesc,
|
ThrowIfFailed(ctx->m_dev->CreatePlacedResource(gpuHeap, offset, &m_gpuDesc,
|
||||||
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
|
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
|
||||||
nullptr, __uuidof(ID3D12Resource), &m_gpuTexs[i]));
|
nullptr, __uuidof(ID3D12Resource), &m_gpuTexs[i]));
|
||||||
offset = NextHeapOffset(offset, ctx->m_dev->GetResourceAllocationInfo(0, 1, &m_gpuDesc));
|
offset = NextHeapOffset(offset, ctx->m_dev->GetResourceAllocationInfo(0, 1, &m_gpuDesc));
|
||||||
}
|
}
|
||||||
|
@ -379,10 +380,10 @@ class D3D12TextureR : public ITextureR
|
||||||
|
|
||||||
void Setup(D3D12Context* ctx, size_t width, size_t height, size_t samples)
|
void Setup(D3D12Context* ctx, size_t width, size_t height, size_t samples)
|
||||||
{
|
{
|
||||||
CD3DX12_RESOURCE_DESC rtvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, 1, 0, 1,
|
CD3DX12_RESOURCE_DESC rtvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, 1, 0, 1,
|
||||||
0, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET);
|
0, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET);
|
||||||
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE,
|
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE,
|
||||||
&rtvresdesc, D3D12_RESOURCE_STATE_RENDER_TARGET, &CD3DX12_CLEAR_VALUE(DXGI_FORMAT_R8G8B8A8_UNORM, BLACK_COLOR),
|
&rtvresdesc, D3D12_RESOURCE_STATE_RENDER_TARGET, &CD3DX12_CLEAR_VALUE(DXGI_FORMAT_R8G8B8A8_UNORM, BLACK_COLOR),
|
||||||
__uuidof(ID3D12Resource), &m_gpuTex));
|
__uuidof(ID3D12Resource), &m_gpuTex));
|
||||||
|
|
||||||
D3D12_DESCRIPTOR_HEAP_DESC rtvdesc = {D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1};
|
D3D12_DESCRIPTOR_HEAP_DESC rtvdesc = {D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1};
|
||||||
|
@ -393,16 +394,16 @@ class D3D12TextureR : public ITextureR
|
||||||
|
|
||||||
if (samples > 1)
|
if (samples > 1)
|
||||||
{
|
{
|
||||||
CD3DX12_RESOURCE_DESC rtvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, 1, 0, samples,
|
CD3DX12_RESOURCE_DESC rtvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, 1, 0, samples,
|
||||||
0, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, D3D12_TEXTURE_LAYOUT_UNKNOWN, D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT);
|
0, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, D3D12_TEXTURE_LAYOUT_UNKNOWN, D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT);
|
||||||
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE,
|
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE,
|
||||||
&rtvresdesc, D3D12_RESOURCE_STATE_RENDER_TARGET, &CD3DX12_CLEAR_VALUE(DXGI_FORMAT_R8G8B8A8_UNORM, BLACK_COLOR),
|
&rtvresdesc, D3D12_RESOURCE_STATE_RENDER_TARGET, &CD3DX12_CLEAR_VALUE(DXGI_FORMAT_R8G8B8A8_UNORM, BLACK_COLOR),
|
||||||
__uuidof(ID3D12Resource), &m_gpuMsaaTex));
|
__uuidof(ID3D12Resource), &m_gpuMsaaTex));
|
||||||
|
|
||||||
CD3DX12_RESOURCE_DESC dsvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_D24_UNORM_S8_UINT, m_width, m_height, 1, 0, samples,
|
CD3DX12_RESOURCE_DESC dsvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_D24_UNORM_S8_UINT, m_width, m_height, 1, 0, samples,
|
||||||
0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL, D3D12_TEXTURE_LAYOUT_UNKNOWN, D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT);
|
0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL, D3D12_TEXTURE_LAYOUT_UNKNOWN, D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT);
|
||||||
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE,
|
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE,
|
||||||
&dsvresdesc, D3D12_RESOURCE_STATE_DEPTH_WRITE, &CD3DX12_CLEAR_VALUE(DXGI_FORMAT_D24_UNORM_S8_UINT, 1.0, 0),
|
&dsvresdesc, D3D12_RESOURCE_STATE_DEPTH_WRITE, &CD3DX12_CLEAR_VALUE(DXGI_FORMAT_D24_UNORM_S8_UINT, 1.0, 0),
|
||||||
__uuidof(ID3D12Resource), &m_depthTex));
|
__uuidof(ID3D12Resource), &m_depthTex));
|
||||||
|
|
||||||
D3D12_RENDER_TARGET_VIEW_DESC rtvvdesc = {DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RTV_DIMENSION_TEXTURE2D};
|
D3D12_RENDER_TARGET_VIEW_DESC rtvvdesc = {DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RTV_DIMENSION_TEXTURE2D};
|
||||||
|
@ -413,12 +414,12 @@ class D3D12TextureR : public ITextureR
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CD3DX12_RESOURCE_DESC dsvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_D24_UNORM_S8_UINT, m_width, m_height, 1, 0, 1,
|
CD3DX12_RESOURCE_DESC dsvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_D24_UNORM_S8_UINT, m_width, m_height, 1, 0, 1,
|
||||||
0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL);
|
0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL);
|
||||||
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE,
|
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE,
|
||||||
&dsvresdesc, D3D12_RESOURCE_STATE_DEPTH_WRITE, &CD3DX12_CLEAR_VALUE(DXGI_FORMAT_D24_UNORM_S8_UINT, 1.0, 0),
|
&dsvresdesc, D3D12_RESOURCE_STATE_DEPTH_WRITE, &CD3DX12_CLEAR_VALUE(DXGI_FORMAT_D24_UNORM_S8_UINT, 1.0, 0),
|
||||||
__uuidof(ID3D12Resource), &m_depthTex));
|
__uuidof(ID3D12Resource), &m_depthTex));
|
||||||
|
|
||||||
D3D12_RENDER_TARGET_VIEW_DESC rtvvdesc = {DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RTV_DIMENSION_TEXTURE2D};
|
D3D12_RENDER_TARGET_VIEW_DESC rtvvdesc = {DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RTV_DIMENSION_TEXTURE2D};
|
||||||
ctx->m_dev->CreateRenderTargetView(m_gpuTex.Get(), &rtvvdesc, m_rtvHeap->GetCPUDescriptorHandleForHeapStart());
|
ctx->m_dev->CreateRenderTargetView(m_gpuTex.Get(), &rtvvdesc, m_rtvHeap->GetCPUDescriptorHandleForHeapStart());
|
||||||
|
|
||||||
|
@ -969,13 +970,13 @@ struct D3D12CommandQueue : IGraphicsCommandQueue
|
||||||
ID3D12CommandQueue** cmdQueueOut)
|
ID3D12CommandQueue** cmdQueueOut)
|
||||||
: m_ctx(ctx), m_windowCtx(windowCtx), m_parent(parent)
|
: m_ctx(ctx), m_windowCtx(windowCtx), m_parent(parent)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(ctx->m_dev->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
|
ThrowIfFailed(ctx->m_dev->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||||
__uuidof(ID3D12CommandAllocator),
|
__uuidof(ID3D12CommandAllocator),
|
||||||
&ctx->m_qalloc[0]));
|
&ctx->m_qalloc[0]));
|
||||||
ThrowIfFailed(ctx->m_dev->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
|
ThrowIfFailed(ctx->m_dev->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||||
__uuidof(ID3D12CommandAllocator),
|
__uuidof(ID3D12CommandAllocator),
|
||||||
&ctx->m_qalloc[1]));
|
&ctx->m_qalloc[1]));
|
||||||
D3D12_COMMAND_QUEUE_DESC desc =
|
D3D12_COMMAND_QUEUE_DESC desc =
|
||||||
{
|
{
|
||||||
D3D12_COMMAND_LIST_TYPE_DIRECT,
|
D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||||
D3D12_COMMAND_QUEUE_PRIORITY_HIGH,
|
D3D12_COMMAND_QUEUE_PRIORITY_HIGH,
|
||||||
|
@ -984,7 +985,7 @@ struct D3D12CommandQueue : IGraphicsCommandQueue
|
||||||
ThrowIfFailed(ctx->m_dev->CreateCommandQueue(&desc, __uuidof(ID3D12CommandQueue), &ctx->m_q));
|
ThrowIfFailed(ctx->m_dev->CreateCommandQueue(&desc, __uuidof(ID3D12CommandQueue), &ctx->m_q));
|
||||||
*cmdQueueOut = ctx->m_q.Get();
|
*cmdQueueOut = ctx->m_q.Get();
|
||||||
ThrowIfFailed(ctx->m_dev->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), &m_fence));
|
ThrowIfFailed(ctx->m_dev->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), &m_fence));
|
||||||
ThrowIfFailed(ctx->m_dev->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, ctx->m_qalloc[0].Get(),
|
ThrowIfFailed(ctx->m_dev->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, ctx->m_qalloc[0].Get(),
|
||||||
nullptr, __uuidof(ID3D12GraphicsCommandList), &m_cmdList));
|
nullptr, __uuidof(ID3D12GraphicsCommandList), &m_cmdList));
|
||||||
m_renderFenceHandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
m_renderFenceHandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||||
m_cmdList->SetGraphicsRootSignature(m_ctx->m_rs.Get());
|
m_cmdList->SetGraphicsRootSignature(m_ctx->m_rs.Get());
|
||||||
|
@ -1026,13 +1027,13 @@ struct D3D12CommandQueue : IGraphicsCommandQueue
|
||||||
D3D12TextureR* ctarget = static_cast<D3D12TextureR*>(target);
|
D3D12TextureR* ctarget = static_cast<D3D12TextureR*>(target);
|
||||||
|
|
||||||
if (m_boundTarget)
|
if (m_boundTarget)
|
||||||
m_cmdList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_boundTarget->getRenderColorRes(),
|
m_cmdList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_boundTarget->getRenderColorRes(),
|
||||||
D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE));
|
D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE));
|
||||||
|
|
||||||
m_cmdList->OMSetRenderTargets(1, &ctarget->m_rtvHeap->GetCPUDescriptorHandleForHeapStart(),
|
m_cmdList->OMSetRenderTargets(1, &ctarget->m_rtvHeap->GetCPUDescriptorHandleForHeapStart(),
|
||||||
false, &ctarget->m_dsvHeap->GetCPUDescriptorHandleForHeapStart());
|
false, &ctarget->m_dsvHeap->GetCPUDescriptorHandleForHeapStart());
|
||||||
|
|
||||||
m_cmdList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(ctarget->getRenderColorRes(),
|
m_cmdList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(ctarget->getRenderColorRes(),
|
||||||
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET));
|
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET));
|
||||||
|
|
||||||
m_boundTarget = ctarget;
|
m_boundTarget = ctarget;
|
||||||
|
@ -1129,7 +1130,7 @@ struct D3D12CommandQueue : IGraphicsCommandQueue
|
||||||
{
|
{
|
||||||
UINT nodeMasks[] = {0,0};
|
UINT nodeMasks[] = {0,0};
|
||||||
IUnknown* const queues[] = {m_ctx->m_q.Get(), m_ctx->m_q.Get()};
|
IUnknown* const queues[] = {m_ctx->m_q.Get(), m_ctx->m_q.Get()};
|
||||||
m_windowCtx->m_swapChain->ResizeBuffers1(2, m_windowCtx->width, m_windowCtx->height,
|
m_windowCtx->m_swapChain->ResizeBuffers1(2, m_windowCtx->width, m_windowCtx->height,
|
||||||
DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH, nodeMasks, queues);
|
DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH, nodeMasks, queues);
|
||||||
m_windowCtx->m_backBuf = m_windowCtx->m_swapChain->GetCurrentBackBufferIndex();
|
m_windowCtx->m_backBuf = m_windowCtx->m_swapChain->GetCurrentBackBufferIndex();
|
||||||
m_windowCtx->m_needsResize = false;
|
m_windowCtx->m_needsResize = false;
|
||||||
|
@ -1141,12 +1142,12 @@ struct D3D12CommandQueue : IGraphicsCommandQueue
|
||||||
if (csource->m_samples > 1)
|
if (csource->m_samples > 1)
|
||||||
{
|
{
|
||||||
ID3D12Resource* src = csource->m_gpuMsaaTex.Get();
|
ID3D12Resource* src = csource->m_gpuMsaaTex.Get();
|
||||||
|
|
||||||
D3D12_RESOURCE_BARRIER msaaSetup[] =
|
D3D12_RESOURCE_BARRIER msaaSetup[] =
|
||||||
{
|
{
|
||||||
CD3DX12_RESOURCE_BARRIER::Transition(src,
|
CD3DX12_RESOURCE_BARRIER::Transition(src,
|
||||||
D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_RESOLVE_SOURCE),
|
D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_RESOLVE_SOURCE),
|
||||||
CD3DX12_RESOURCE_BARRIER::Transition(dest.Get(),
|
CD3DX12_RESOURCE_BARRIER::Transition(dest.Get(),
|
||||||
D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RESOLVE_DEST)
|
D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RESOLVE_DEST)
|
||||||
};
|
};
|
||||||
m_cmdList->ResourceBarrier(2, msaaSetup);
|
m_cmdList->ResourceBarrier(2, msaaSetup);
|
||||||
|
@ -1155,9 +1156,9 @@ struct D3D12CommandQueue : IGraphicsCommandQueue
|
||||||
|
|
||||||
D3D12_RESOURCE_BARRIER msaaTeardown[] =
|
D3D12_RESOURCE_BARRIER msaaTeardown[] =
|
||||||
{
|
{
|
||||||
CD3DX12_RESOURCE_BARRIER::Transition(src,
|
CD3DX12_RESOURCE_BARRIER::Transition(src,
|
||||||
D3D12_RESOURCE_STATE_RESOLVE_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET),
|
D3D12_RESOURCE_STATE_RESOLVE_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET),
|
||||||
CD3DX12_RESOURCE_BARRIER::Transition(dest.Get(),
|
CD3DX12_RESOURCE_BARRIER::Transition(dest.Get(),
|
||||||
D3D12_RESOURCE_STATE_RESOLVE_DEST, D3D12_RESOURCE_STATE_PRESENT)
|
D3D12_RESOURCE_STATE_RESOLVE_DEST, D3D12_RESOURCE_STATE_PRESENT)
|
||||||
};
|
};
|
||||||
m_cmdList->ResourceBarrier(2, msaaTeardown);
|
m_cmdList->ResourceBarrier(2, msaaTeardown);
|
||||||
|
@ -1168,9 +1169,9 @@ struct D3D12CommandQueue : IGraphicsCommandQueue
|
||||||
|
|
||||||
D3D12_RESOURCE_BARRIER copySetup[] =
|
D3D12_RESOURCE_BARRIER copySetup[] =
|
||||||
{
|
{
|
||||||
CD3DX12_RESOURCE_BARRIER::Transition(src,
|
CD3DX12_RESOURCE_BARRIER::Transition(src,
|
||||||
D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE),
|
D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE),
|
||||||
CD3DX12_RESOURCE_BARRIER::Transition(dest.Get(),
|
CD3DX12_RESOURCE_BARRIER::Transition(dest.Get(),
|
||||||
D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_COPY_DEST)
|
D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_COPY_DEST)
|
||||||
};
|
};
|
||||||
m_cmdList->ResourceBarrier(2, copySetup);
|
m_cmdList->ResourceBarrier(2, copySetup);
|
||||||
|
@ -1179,9 +1180,9 @@ struct D3D12CommandQueue : IGraphicsCommandQueue
|
||||||
|
|
||||||
D3D12_RESOURCE_BARRIER copyTeardown[] =
|
D3D12_RESOURCE_BARRIER copyTeardown[] =
|
||||||
{
|
{
|
||||||
CD3DX12_RESOURCE_BARRIER::Transition(src,
|
CD3DX12_RESOURCE_BARRIER::Transition(src,
|
||||||
D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET),
|
D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET),
|
||||||
CD3DX12_RESOURCE_BARRIER::Transition(dest.Get(),
|
CD3DX12_RESOURCE_BARRIER::Transition(dest.Get(),
|
||||||
D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PRESENT)
|
D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PRESENT)
|
||||||
};
|
};
|
||||||
m_cmdList->ResourceBarrier(2, copyTeardown);
|
m_cmdList->ResourceBarrier(2, copyTeardown);
|
||||||
|
@ -1309,11 +1310,11 @@ public:
|
||||||
ComPtr<ID3DBlob> rsOutBlob;
|
ComPtr<ID3DBlob> rsOutBlob;
|
||||||
ComPtr<ID3DBlob> rsErrorBlob;
|
ComPtr<ID3DBlob> rsErrorBlob;
|
||||||
ThrowIfFailed(D3D12SerializeRootSignaturePROC(
|
ThrowIfFailed(D3D12SerializeRootSignaturePROC(
|
||||||
&CD3DX12_ROOT_SIGNATURE_DESC(1, rootParms, 1, &CD3DX12_STATIC_SAMPLER_DESC(0),
|
&CD3DX12_ROOT_SIGNATURE_DESC(1, rootParms, 1, &CD3DX12_STATIC_SAMPLER_DESC(0),
|
||||||
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT),
|
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT),
|
||||||
D3D_ROOT_SIGNATURE_VERSION_1, &rsOutBlob, &rsErrorBlob));
|
D3D_ROOT_SIGNATURE_VERSION_1, &rsOutBlob, &rsErrorBlob));
|
||||||
|
|
||||||
ThrowIfFailed(ctx->m_dev->CreateRootSignature(0, rsOutBlob->GetBufferPointer(),
|
ThrowIfFailed(ctx->m_dev->CreateRootSignature(0, rsOutBlob->GetBufferPointer(),
|
||||||
rsOutBlob->GetBufferSize(), __uuidof(ID3D12RootSignature), &ctx->m_rs));
|
rsOutBlob->GetBufferSize(), __uuidof(ID3D12RootSignature), &ctx->m_rs));
|
||||||
}
|
}
|
||||||
~D3D12DataFactory() {destroyAllData();}
|
~D3D12DataFactory() {destroyAllData();}
|
||||||
|
@ -1491,7 +1492,7 @@ public:
|
||||||
texDescs.reserve(retval->m_STexs.size() + retval->m_SATexs.size() + retval->m_DTexs.size() * 2);
|
texDescs.reserve(retval->m_STexs.size() + retval->m_SATexs.size() + retval->m_DTexs.size() * 2);
|
||||||
|
|
||||||
for (std::unique_ptr<D3D12GraphicsBufferS>& buf : retval->m_SBufs)
|
for (std::unique_ptr<D3D12GraphicsBufferS>& buf : retval->m_SBufs)
|
||||||
bufDescs.push_back(buf->m_buf->GetDesc());
|
bufDescs.push_back(buf->m_gpuDesc);
|
||||||
|
|
||||||
for (std::unique_ptr<D3D12GraphicsBufferD>& buf : retval->m_DBufs)
|
for (std::unique_ptr<D3D12GraphicsBufferD>& buf : retval->m_DBufs)
|
||||||
{
|
{
|
||||||
|
@ -1500,15 +1501,15 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::unique_ptr<D3D12TextureS>& tex : retval->m_STexs)
|
for (std::unique_ptr<D3D12TextureS>& tex : retval->m_STexs)
|
||||||
texDescs.push_back(tex->m_tex->GetDesc());
|
texDescs.push_back(tex->m_gpuDesc);
|
||||||
|
|
||||||
for (std::unique_ptr<D3D12TextureSA>& tex : retval->m_SATexs)
|
for (std::unique_ptr<D3D12TextureSA>& tex : retval->m_SATexs)
|
||||||
texDescs.push_back(tex->m_tex->GetDesc());
|
texDescs.push_back(tex->m_gpuDesc);
|
||||||
|
|
||||||
for (std::unique_ptr<D3D12TextureD>& tex : retval->m_DTexs)
|
for (std::unique_ptr<D3D12TextureD>& tex : retval->m_DTexs)
|
||||||
{
|
{
|
||||||
texDescs.push_back(tex->m_texs[0]->GetDesc());
|
texDescs.push_back(tex->m_gpuDesc);
|
||||||
texDescs.push_back(tex->m_texs[1]->GetDesc());
|
texDescs.push_back(tex->m_gpuDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create heap */
|
/* Create heap */
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace boo
|
||||||
{
|
{
|
||||||
static LogVisor::LogModule Log("boo::ApplicationWin32");
|
static LogVisor::LogModule Log("boo::ApplicationWin32");
|
||||||
Win32Cursors WIN32_CURSORS;
|
Win32Cursors WIN32_CURSORS;
|
||||||
|
|
||||||
IWindow* _WindowWin32New(const SystemString& title, Boo3DAppContext& d3dCtx);
|
IWindow* _WindowWin32New(const SystemString& title, Boo3DAppContext& d3dCtx);
|
||||||
|
|
||||||
class ApplicationWin32 final : public IApplication
|
class ApplicationWin32 final : public IApplication
|
||||||
|
@ -77,9 +77,9 @@ class ApplicationWin32 final : public IApplication
|
||||||
{
|
{
|
||||||
m_allWindows.erase(HWND(window->getPlatformHandle()));
|
m_allWindows.erase(HWND(window->getPlatformHandle()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ApplicationWin32(IApplicationCallback& callback,
|
ApplicationWin32(IApplicationCallback& callback,
|
||||||
const SystemString& uniqueName,
|
const SystemString& uniqueName,
|
||||||
const SystemString& friendlyName,
|
const SystemString& friendlyName,
|
||||||
|
@ -125,7 +125,7 @@ public:
|
||||||
{
|
{
|
||||||
#if _DEBUG
|
#if _DEBUG
|
||||||
{
|
{
|
||||||
PFN_D3D12_GET_DEBUG_INTERFACE MyD3D12GetDebugInterface =
|
PFN_D3D12_GET_DEBUG_INTERFACE MyD3D12GetDebugInterface =
|
||||||
(PFN_D3D12_GET_DEBUG_INTERFACE)GetProcAddress(d3d12lib, "D3D12GetDebugInterface");
|
(PFN_D3D12_GET_DEBUG_INTERFACE)GetProcAddress(d3d12lib, "D3D12GetDebugInterface");
|
||||||
ComPtr<ID3D12Debug> debugController;
|
ComPtr<ID3D12Debug> debugController;
|
||||||
if (SUCCEEDED(MyD3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
|
if (SUCCEEDED(MyD3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
|
||||||
|
@ -136,10 +136,10 @@ public:
|
||||||
#endif
|
#endif
|
||||||
if (!FindBestD3DCompile())
|
if (!FindBestD3DCompile())
|
||||||
Log.report(LogVisor::FatalError, "unable to find D3DCompile_[43-47].dll");
|
Log.report(LogVisor::FatalError, "unable to find D3DCompile_[43-47].dll");
|
||||||
|
|
||||||
D3D12SerializeRootSignaturePROC =
|
D3D12SerializeRootSignaturePROC =
|
||||||
(PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)GetProcAddress(d3d12lib, "D3D12SerializeRootSignature");
|
(PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)GetProcAddress(d3d12lib, "D3D12SerializeRootSignature");
|
||||||
|
|
||||||
/* Create device */
|
/* Create device */
|
||||||
PFN_D3D12_CREATE_DEVICE MyD3D12CreateDevice = (PFN_D3D12_CREATE_DEVICE)GetProcAddress(d3d12lib, "D3D12CreateDevice");
|
PFN_D3D12_CREATE_DEVICE MyD3D12CreateDevice = (PFN_D3D12_CREATE_DEVICE)GetProcAddress(d3d12lib, "D3D12CreateDevice");
|
||||||
if (!MyD3D12CreateDevice)
|
if (!MyD3D12CreateDevice)
|
||||||
|
@ -156,11 +156,11 @@ public:
|
||||||
Log.report(LogVisor::FatalError, "unable to create DXGI factory");
|
Log.report(LogVisor::FatalError, "unable to create DXGI factory");
|
||||||
|
|
||||||
/* Establish loader objects */
|
/* Establish loader objects */
|
||||||
if (FAILED(m_3dCtx.m_ctx12.m_dev->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
|
if (FAILED(m_3dCtx.m_ctx12.m_dev->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||||
__uuidof(ID3D12CommandAllocator), &m_3dCtx.m_ctx12.m_loadqalloc)))
|
__uuidof(ID3D12CommandAllocator), &m_3dCtx.m_ctx12.m_loadqalloc)))
|
||||||
Log.report(LogVisor::FatalError, "unable to create loader allocator");
|
Log.report(LogVisor::FatalError, "unable to create loader allocator");
|
||||||
|
|
||||||
D3D12_COMMAND_QUEUE_DESC desc =
|
D3D12_COMMAND_QUEUE_DESC desc =
|
||||||
{
|
{
|
||||||
D3D12_COMMAND_LIST_TYPE_DIRECT,
|
D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||||
D3D12_COMMAND_QUEUE_PRIORITY_NORMAL,
|
D3D12_COMMAND_QUEUE_PRIORITY_NORMAL,
|
||||||
|
@ -174,7 +174,7 @@ public:
|
||||||
|
|
||||||
m_3dCtx.m_ctx12.m_loadfencehandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
m_3dCtx.m_ctx12.m_loadfencehandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||||
|
|
||||||
if (FAILED(m_3dCtx.m_ctx12.m_dev->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_3dCtx.m_ctx12.m_loadqalloc.Get(),
|
if (FAILED(m_3dCtx.m_ctx12.m_dev->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_3dCtx.m_ctx12.m_loadqalloc.Get(),
|
||||||
nullptr, __uuidof(ID3D12GraphicsCommandList), &m_3dCtx.m_ctx12.m_loadlist)))
|
nullptr, __uuidof(ID3D12GraphicsCommandList), &m_3dCtx.m_ctx12.m_loadlist)))
|
||||||
Log.report(LogVisor::FatalError, "unable to create loader list");
|
Log.report(LogVisor::FatalError, "unable to create loader list");
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ public:
|
||||||
D3D_FEATURE_LEVEL level = D3D_FEATURE_LEVEL_11_0;
|
D3D_FEATURE_LEVEL level = D3D_FEATURE_LEVEL_11_0;
|
||||||
ComPtr<ID3D11Device> tempDev;
|
ComPtr<ID3D11Device> tempDev;
|
||||||
ComPtr<ID3D11DeviceContext> tempCtx;
|
ComPtr<ID3D11DeviceContext> tempCtx;
|
||||||
if (FAILED(MyD3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, D3D11_CREATE_DEVICE_FLAGS, &level,
|
if (FAILED(MyD3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, D3D11_CREATE_DEVICE_FLAGS, &level,
|
||||||
1, D3D11_SDK_VERSION, &tempDev, nullptr, &tempCtx)))
|
1, D3D11_SDK_VERSION, &tempDev, nullptr, &tempCtx)))
|
||||||
Log.report(LogVisor::FatalError, "unable to create D3D11 device");
|
Log.report(LogVisor::FatalError, "unable to create D3D11 device");
|
||||||
tempDev.As<ID3D11Device1>(&m_3dCtx.m_ctx11.m_dev);
|
tempDev.As<ID3D11Device1>(&m_3dCtx.m_ctx11.m_dev);
|
||||||
|
@ -211,7 +211,11 @@ public:
|
||||||
adapter->GetParent(__uuidof(IDXGIFactory2), &m_3dCtx.m_ctx11.m_dxFactory);
|
adapter->GetParent(__uuidof(IDXGIFactory2), &m_3dCtx.m_ctx11.m_dxFactory);
|
||||||
|
|
||||||
/* Build default sampler here */
|
/* Build default sampler here */
|
||||||
m_3dCtx.m_ctx11.m_dev->CreateSamplerState(&CD3D11_SAMPLER_DESC(D3D11_DEFAULT), &m_3dCtx.m_ctx11.m_ss);
|
CD3D11_SAMPLER_DESC sampDesc(D3D11_DEFAULT);
|
||||||
|
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||||
|
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||||
|
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||||
|
m_3dCtx.m_ctx11.m_dev->CreateSamplerState(&sampDesc, &m_3dCtx.m_ctx11.m_ss);
|
||||||
|
|
||||||
Log.report(LogVisor::Info, "initialized D3D11 renderer");
|
Log.report(LogVisor::Info, "initialized D3D11 renderer");
|
||||||
return;
|
return;
|
||||||
|
@ -230,12 +234,12 @@ public:
|
||||||
|
|
||||||
Log.report(LogVisor::FatalError, "system doesn't support OGL, D3D11 or D3D12");
|
Log.report(LogVisor::FatalError, "system doesn't support OGL, D3D11 or D3D12");
|
||||||
}
|
}
|
||||||
|
|
||||||
EPlatformType getPlatformType() const
|
EPlatformType getPlatformType() const
|
||||||
{
|
{
|
||||||
return EPlatformType::Win32;
|
return EPlatformType::Win32;
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT winHwndHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
LRESULT winHwndHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
/* Lookup boo window instance */
|
/* Lookup boo window instance */
|
||||||
|
@ -244,10 +248,10 @@ public:
|
||||||
{
|
{
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case WM_DEVICECHANGE:
|
case WM_DEVICECHANGE:
|
||||||
return DeviceFinder::winDevChangedHandler(wParam, lParam);
|
return DeviceFinder::winDevChangedHandler(wParam, lParam);
|
||||||
|
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
case WM_SIZE:
|
case WM_SIZE:
|
||||||
case WM_MOVING:
|
case WM_MOVING:
|
||||||
|
@ -278,7 +282,7 @@ public:
|
||||||
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int run()
|
int run()
|
||||||
{
|
{
|
||||||
g_mainThreadId = GetCurrentThreadId();
|
g_mainThreadId = GetCurrentThreadId();
|
||||||
|
@ -290,7 +294,7 @@ public:
|
||||||
clientReturn = m_callback.appMain(this);
|
clientReturn = m_callback.appMain(this);
|
||||||
PostThreadMessage(g_mainThreadId, WM_USER+1, 0, 0);
|
PostThreadMessage(g_mainThreadId, WM_USER+1, 0, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Pump messages */
|
/* Pump messages */
|
||||||
MSG msg = {0};
|
MSG msg = {0};
|
||||||
while (GetMessage(&msg, NULL, 0, 0))
|
while (GetMessage(&msg, NULL, 0, 0))
|
||||||
|
@ -337,7 +341,7 @@ public:
|
||||||
clientThread.join();
|
clientThread.join();
|
||||||
return clientReturn;
|
return clientReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SystemString& getUniqueName() const
|
const SystemString& getUniqueName() const
|
||||||
{
|
{
|
||||||
return m_uniqueName;
|
return m_uniqueName;
|
||||||
|
@ -352,12 +356,12 @@ public:
|
||||||
{
|
{
|
||||||
return m_pname;
|
return m_pname;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<SystemString>& getArgs() const
|
const std::vector<SystemString>& getArgs() const
|
||||||
{
|
{
|
||||||
return m_args;
|
return m_args;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::mutex m_nwmt;
|
std::mutex m_nwmt;
|
||||||
std::condition_variable m_nwcv;
|
std::condition_variable m_nwcv;
|
||||||
IWindow* m_mwret = nullptr;
|
IWindow* m_mwret = nullptr;
|
||||||
|
@ -371,14 +375,14 @@ public:
|
||||||
m_nwcv.wait(lk);
|
m_nwcv.wait(lk);
|
||||||
return m_mwret;
|
return m_mwret;
|
||||||
}
|
}
|
||||||
|
|
||||||
IWindow* window = _WindowWin32New(title, m_3dCtx);
|
IWindow* window = _WindowWin32New(title, m_3dCtx);
|
||||||
HWND hwnd = HWND(window->getPlatformHandle());
|
HWND hwnd = HWND(window->getPlatformHandle());
|
||||||
m_allWindows[hwnd] = window;
|
m_allWindows[hwnd] = window;
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
IApplication* APP = NULL;
|
IApplication* APP = NULL;
|
||||||
int ApplicationRun(IApplication::EPlatformType platform,
|
int ApplicationRun(IApplication::EPlatformType platform,
|
||||||
IApplicationCallback& cb,
|
IApplicationCallback& cb,
|
||||||
|
|
Loading…
Reference in New Issue