summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/D3D/DXTexture.cpp
diff options
context:
space:
mode:
authorTilka <tilkax@gmail.com>2019-02-26 04:21:05 +0000
committerGitHub <noreply@github.com>2019-02-26 04:21:05 +0000
commit6ce7f44b8a0bb3b95d3f12ebffbef7a71a443fdd (patch)
tree98380ce3a3284c52597a6fba86589c847219ecd5 /Source/Core/VideoBackends/D3D/DXTexture.cpp
parent19673ce79af814ca3b77d7f8ea60458e564bfa51 (diff)
parentf039149198657c1891e1c6462ed30c31ed4b8486 (diff)
Merge pull request #7753 from stenzek/videocommon-all-the-things
Move a significant amount of video backend logic to VideoCommon
Diffstat (limited to 'Source/Core/VideoBackends/D3D/DXTexture.cpp')
-rw-r--r--Source/Core/VideoBackends/D3D/DXTexture.cpp346
1 files changed, 193 insertions, 153 deletions
diff --git a/Source/Core/VideoBackends/D3D/DXTexture.cpp b/Source/Core/VideoBackends/D3D/DXTexture.cpp
index 127a922146..dc1c04991a 100644
--- a/Source/Core/VideoBackends/D3D/DXTexture.cpp
+++ b/Source/Core/VideoBackends/D3D/DXTexture.cpp
@@ -9,25 +9,14 @@
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
-#include "VideoBackends/D3D/D3DBase.h"
#include "VideoBackends/D3D/D3DState.h"
-#include "VideoBackends/D3D/D3DTexture.h"
-#include "VideoBackends/D3D/D3DUtil.h"
#include "VideoBackends/D3D/DXTexture.h"
-#include "VideoBackends/D3D/FramebufferManager.h"
-#include "VideoBackends/D3D/GeometryShaderCache.h"
-#include "VideoBackends/D3D/PixelShaderCache.h"
-#include "VideoBackends/D3D/TextureCache.h"
-#include "VideoBackends/D3D/VertexShaderCache.h"
-
-#include "VideoCommon/ImageWrite.h"
-#include "VideoCommon/TextureConfig.h"
namespace DX11
{
namespace
{
-DXGI_FORMAT GetDXGIFormatForHostFormat(AbstractTextureFormat format)
+DXGI_FORMAT GetDXGIFormatForHostFormat(AbstractTextureFormat format, bool typeless)
{
switch (format)
{
@@ -40,13 +29,13 @@ DXGI_FORMAT GetDXGIFormatForHostFormat(AbstractTextureFormat format)
case AbstractTextureFormat::BPTC:
return DXGI_FORMAT_BC7_UNORM;
case AbstractTextureFormat::RGBA8:
- return DXGI_FORMAT_R8G8B8A8_UNORM;
+ return typeless ? DXGI_FORMAT_R8G8B8A8_TYPELESS : DXGI_FORMAT_R8G8B8A8_UNORM;
case AbstractTextureFormat::BGRA8:
- return DXGI_FORMAT_B8G8R8A8_UNORM;
+ return typeless ? DXGI_FORMAT_B8G8R8A8_TYPELESS : DXGI_FORMAT_B8G8R8A8_UNORM;
case AbstractTextureFormat::R16:
- return DXGI_FORMAT_R16_UNORM;
+ return typeless ? DXGI_FORMAT_R16_TYPELESS : DXGI_FORMAT_R16_UNORM;
case AbstractTextureFormat::R32F:
- return DXGI_FORMAT_R32_FLOAT;
+ return typeless ? DXGI_FORMAT_R32_TYPELESS : DXGI_FORMAT_R32_FLOAT;
case AbstractTextureFormat::D16:
return DXGI_FORMAT_R16_TYPELESS;
case AbstractTextureFormat::D24_S8:
@@ -64,6 +53,22 @@ DXGI_FORMAT GetSRVFormatForHostFormat(AbstractTextureFormat format)
{
switch (format)
{
+ case AbstractTextureFormat::DXT1:
+ return DXGI_FORMAT_BC1_UNORM;
+ case AbstractTextureFormat::DXT3:
+ return DXGI_FORMAT_BC2_UNORM;
+ case AbstractTextureFormat::DXT5:
+ return DXGI_FORMAT_BC3_UNORM;
+ case AbstractTextureFormat::BPTC:
+ return DXGI_FORMAT_BC7_UNORM;
+ case AbstractTextureFormat::RGBA8:
+ return DXGI_FORMAT_R8G8B8A8_UNORM;
+ case AbstractTextureFormat::BGRA8:
+ return DXGI_FORMAT_B8G8R8A8_UNORM;
+ case AbstractTextureFormat::R16:
+ return DXGI_FORMAT_R16_UNORM;
+ case AbstractTextureFormat::R32F:
+ return DXGI_FORMAT_R32_FLOAT;
case AbstractTextureFormat::D16:
return DXGI_FORMAT_R16_UNORM;
case AbstractTextureFormat::D24_S8:
@@ -73,7 +78,25 @@ DXGI_FORMAT GetSRVFormatForHostFormat(AbstractTextureFormat format)
case AbstractTextureFormat::D32F_S8:
return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
default:
- return GetDXGIFormatForHostFormat(format);
+ PanicAlert("Unhandled SRV format");
+ return DXGI_FORMAT_UNKNOWN;
+ }
+}
+DXGI_FORMAT GetRTVFormatForHostFormat(AbstractTextureFormat format, bool integer)
+{
+ switch (format)
+ {
+ case AbstractTextureFormat::RGBA8:
+ return integer ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM;
+ case AbstractTextureFormat::BGRA8:
+ return DXGI_FORMAT_B8G8R8A8_UNORM;
+ case AbstractTextureFormat::R16:
+ return integer ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R16_UNORM;
+ case AbstractTextureFormat::R32F:
+ return DXGI_FORMAT_R32_FLOAT;
+ default:
+ PanicAlert("Unhandled RTV format");
+ return DXGI_FORMAT_UNKNOWN;
}
}
DXGI_FORMAT GetDSVFormatForHostFormat(AbstractTextureFormat format)
@@ -89,55 +112,87 @@ DXGI_FORMAT GetDSVFormatForHostFormat(AbstractTextureFormat format)
case AbstractTextureFormat::D32F_S8:
return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
default:
- return GetDXGIFormatForHostFormat(format);
+ PanicAlert("Unhandled DSV format");
+ return DXGI_FORMAT_UNKNOWN;
}
}
} // Anonymous namespace
-DXTexture::DXTexture(const TextureConfig& tex_config) : AbstractTexture(tex_config)
+DXTexture::DXTexture(const TextureConfig& tex_config, ID3D11Texture2D* d3d_texture,
+ ID3D11ShaderResourceView* d3d_srv, ID3D11UnorderedAccessView* d3d_uav)
+ : AbstractTexture(tex_config), m_d3d_texture(d3d_texture), m_d3d_srv(d3d_srv),
+ m_d3d_uav(d3d_uav)
{
- DXGI_FORMAT tex_format = GetDXGIFormatForHostFormat(m_config.format);
- DXGI_FORMAT srv_format = GetSRVFormatForHostFormat(m_config.format);
- DXGI_FORMAT rtv_format = DXGI_FORMAT_UNKNOWN;
- DXGI_FORMAT dsv_format = DXGI_FORMAT_UNKNOWN;
- UINT bind_flags = D3D11_BIND_SHADER_RESOURCE;
- if (tex_config.rendertarget)
- {
- if (IsDepthFormat(tex_config.format))
- {
- bind_flags |= D3D11_BIND_DEPTH_STENCIL;
- dsv_format = GetDSVFormatForHostFormat(m_config.format);
- }
- else
- {
- bind_flags |= D3D11_BIND_RENDER_TARGET;
- rtv_format = tex_format;
- }
- }
-
- CD3D11_TEXTURE2D_DESC texdesc(tex_format, tex_config.width, tex_config.height, tex_config.layers,
- tex_config.levels, bind_flags, D3D11_USAGE_DEFAULT, 0,
- tex_config.samples, 0, 0);
-
- ID3D11Texture2D* pTexture;
- HRESULT hr = D3D::device->CreateTexture2D(&texdesc, nullptr, &pTexture);
- CHECK(SUCCEEDED(hr), "Create backing DXTexture");
-
- m_texture = new D3DTexture2D(pTexture, static_cast<D3D11_BIND_FLAG>(bind_flags), srv_format,
- dsv_format, rtv_format, tex_config.samples > 1);
-
- SAFE_RELEASE(pTexture);
}
DXTexture::~DXTexture()
{
- g_renderer->UnbindTexture(this);
- m_texture->Release();
+ if (m_d3d_uav)
+ m_d3d_uav->Release();
+
+ if (m_d3d_srv)
+ {
+ if (D3D::stateman->UnsetTexture(m_d3d_srv) != 0)
+ D3D::stateman->ApplyTextures();
+
+ m_d3d_srv->Release();
+ }
+ m_d3d_texture->Release();
}
-D3DTexture2D* DXTexture::GetRawTexIdentifier() const
+std::unique_ptr<DXTexture> DXTexture::Create(const TextureConfig& config)
{
- return m_texture;
+ // Use typeless to create the texture when it's a render target, so we can alias it with an
+ // integer format (for EFB).
+ const DXGI_FORMAT tex_format = GetDXGIFormatForHostFormat(config.format, config.IsRenderTarget());
+ const DXGI_FORMAT srv_format = GetSRVFormatForHostFormat(config.format);
+ UINT bindflags = D3D11_BIND_SHADER_RESOURCE;
+ if (config.IsRenderTarget())
+ bindflags |= IsDepthFormat(config.format) ? D3D11_BIND_DEPTH_STENCIL : D3D11_BIND_RENDER_TARGET;
+ if (config.IsComputeImage())
+ bindflags |= D3D11_BIND_UNORDERED_ACCESS;
+
+ CD3D11_TEXTURE2D_DESC desc(tex_format, config.width, config.height, config.layers, config.levels,
+ bindflags, D3D11_USAGE_DEFAULT, 0, config.samples, 0, 0);
+ ID3D11Texture2D* d3d_texture;
+ HRESULT hr = D3D::device->CreateTexture2D(&desc, nullptr, &d3d_texture);
+ if (FAILED(hr))
+ {
+ PanicAlert("Failed to create %ux%ux%u D3D backing texture", config.width, config.height,
+ config.layers);
+ return nullptr;
+ }
+
+ ID3D11ShaderResourceView* d3d_srv;
+ const CD3D11_SHADER_RESOURCE_VIEW_DESC srv_desc(d3d_texture,
+ config.IsMultisampled() ?
+ D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY :
+ D3D11_SRV_DIMENSION_TEXTURE2DARRAY,
+ srv_format, 0, config.levels, 0, config.layers);
+ hr = D3D::device->CreateShaderResourceView(d3d_texture, &srv_desc, &d3d_srv);
+ if (FAILED(hr))
+ {
+ PanicAlert("Failed to create %ux%ux%u D3D SRV", config.width, config.height, config.layers);
+ d3d_texture->Release();
+ return nullptr;
+ }
+
+ ID3D11UnorderedAccessView* d3d_uav = nullptr;
+ if (config.IsComputeImage())
+ {
+ const CD3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc(
+ d3d_texture, D3D11_UAV_DIMENSION_TEXTURE2DARRAY, srv_format, 0, 0, config.layers);
+ hr = D3D::device->CreateUnorderedAccessView(d3d_texture, &uav_desc, &d3d_uav);
+ if (FAILED(hr))
+ {
+ PanicAlert("Failed to create %ux%ux%u D3D UAV", config.width, config.height, config.layers);
+ d3d_uav->Release();
+ d3d_texture->Release();
+ return nullptr;
+ }
+ }
+
+ return std::make_unique<DXTexture>(config, d3d_texture, d3d_srv, d3d_uav);
}
void DXTexture::CopyRectangleFromTexture(const AbstractTexture* src,
@@ -158,42 +213,11 @@ void DXTexture::CopyRectangleFromTexture(const AbstractTexture* src,
src_box.back = 1;
D3D::context->CopySubresourceRegion(
- m_texture->GetTex(), D3D11CalcSubresource(dst_level, dst_layer, m_config.levels),
- dst_rect.left, dst_rect.top, 0, srcentry->m_texture->GetTex(),
+ m_d3d_texture, D3D11CalcSubresource(dst_level, dst_layer, m_config.levels), dst_rect.left,
+ dst_rect.top, 0, srcentry->m_d3d_texture,
D3D11CalcSubresource(src_level, src_layer, srcentry->m_config.levels), &src_box);
}
-void DXTexture::ScaleRectangleFromTexture(const AbstractTexture* source,
- const MathUtil::Rectangle<int>& srcrect,
- const MathUtil::Rectangle<int>& dstrect)
-{
- const DXTexture* srcentry = static_cast<const DXTexture*>(source);
- ASSERT(m_config.rendertarget);
-
- g_renderer->ResetAPIState(); // reset any game specific settings
-
- const D3D11_VIEWPORT vp = CD3D11_VIEWPORT(float(dstrect.left), float(dstrect.top),
- float(dstrect.GetWidth()), float(dstrect.GetHeight()));
-
- D3D::stateman->UnsetTexture(m_texture->GetSRV());
- D3D::stateman->Apply();
-
- D3D::context->OMSetRenderTargets(1, &m_texture->GetRTV(), nullptr);
- D3D::context->RSSetViewports(1, &vp);
- D3D::SetLinearCopySampler();
- D3D11_RECT srcRC;
- srcRC.left = srcrect.left;
- srcRC.right = srcrect.right;
- srcRC.top = srcrect.top;
- srcRC.bottom = srcrect.bottom;
- D3D::drawShadedTexQuad(
- srcentry->m_texture->GetSRV(), &srcRC, srcentry->m_config.width, srcentry->m_config.height,
- PixelShaderCache::GetColorCopyProgram(false), VertexShaderCache::GetSimpleVertexShader(),
- VertexShaderCache::GetSimpleInputLayout(), GeometryShaderCache::GetCopyGeometryShader(), 0);
-
- g_renderer->RestoreAPIState();
-}
-
void DXTexture::ResolveFromTexture(const AbstractTexture* src, const MathUtil::Rectangle<int>& rect,
u32 layer, u32 level)
{
@@ -204,16 +228,16 @@ void DXTexture::ResolveFromTexture(const AbstractTexture* src, const MathUtil::R
rect.top + rect.GetHeight() <= static_cast<int>(srcentry->m_config.height));
D3D::context->ResolveSubresource(
- m_texture->GetTex(), D3D11CalcSubresource(level, layer, m_config.levels),
- srcentry->m_texture->GetTex(), D3D11CalcSubresource(level, layer, srcentry->m_config.levels),
- GetDXGIFormatForHostFormat(m_config.format));
+ m_d3d_texture, D3D11CalcSubresource(level, layer, m_config.levels), srcentry->m_d3d_texture,
+ D3D11CalcSubresource(level, layer, srcentry->m_config.levels),
+ GetDXGIFormatForHostFormat(m_config.format, false));
}
void DXTexture::Load(u32 level, u32 width, u32 height, u32 row_length, const u8* buffer,
size_t buffer_size)
{
size_t src_pitch = CalculateStrideForFormat(m_config.format, row_length);
- D3D::context->UpdateSubresource(m_texture->GetTex(), level, nullptr, buffer,
+ D3D::context->UpdateSubresource(m_d3d_texture, level, nullptr, buffer,
static_cast<UINT>(src_pitch), 0);
}
@@ -251,8 +275,8 @@ std::unique_ptr<DXStagingTexture> DXStagingTexture::Create(StagingTextureType ty
cpu_flags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
}
- CD3D11_TEXTURE2D_DESC desc(GetDXGIFormatForHostFormat(config.format), config.width, config.height,
- 1, 1, 0, usage, cpu_flags);
+ CD3D11_TEXTURE2D_DESC desc(GetDXGIFormatForHostFormat(config.format, false), config.width,
+ config.height, 1, 1, 0, usage, cpu_flags);
ID3D11Texture2D* texture;
HRESULT hr = D3D::device->CreateTexture2D(&desc, nullptr, &texture);
@@ -267,22 +291,33 @@ void DXStagingTexture::CopyFromTexture(const AbstractTexture* src,
const MathUtil::Rectangle<int>& src_rect, u32 src_layer,
u32 src_level, const MathUtil::Rectangle<int>& dst_rect)
{
- ASSERT(m_type == StagingTextureType::Readback);
+ ASSERT(m_type == StagingTextureType::Readback || m_type == StagingTextureType::Mutable);
ASSERT(src_rect.GetWidth() == dst_rect.GetWidth() &&
src_rect.GetHeight() == dst_rect.GetHeight());
- ASSERT(src_rect.left >= 0 && static_cast<u32>(src_rect.right) <= src->GetConfig().width &&
- src_rect.top >= 0 && static_cast<u32>(src_rect.bottom) <= src->GetConfig().height);
+ ASSERT(src_rect.left >= 0 && static_cast<u32>(src_rect.right) <= src->GetWidth() &&
+ src_rect.top >= 0 && static_cast<u32>(src_rect.bottom) <= src->GetHeight());
ASSERT(dst_rect.left >= 0 && static_cast<u32>(dst_rect.right) <= m_config.width &&
dst_rect.top >= 0 && static_cast<u32>(dst_rect.bottom) <= m_config.height);
if (IsMapped())
DXStagingTexture::Unmap();
- CD3D11_BOX src_box(src_rect.left, src_rect.top, 0, src_rect.right, src_rect.bottom, 1);
- D3D::context->CopySubresourceRegion(
- m_tex, 0, static_cast<u32>(dst_rect.left), static_cast<u32>(dst_rect.top), 0,
- static_cast<const DXTexture*>(src)->GetRawTexIdentifier()->GetTex(),
- D3D11CalcSubresource(src_level, src_layer, src->GetConfig().levels), &src_box);
+ if (static_cast<u32>(src_rect.GetWidth()) == GetWidth() &&
+ static_cast<u32>(src_rect.GetHeight()) == GetHeight())
+ {
+ // Copy whole resource, needed for depth textures.
+ D3D::context->CopySubresourceRegion(
+ m_tex, 0, 0, 0, 0, static_cast<const DXTexture*>(src)->GetD3DTexture(),
+ D3D11CalcSubresource(src_level, src_layer, src->GetLevels()), nullptr);
+ }
+ else
+ {
+ CD3D11_BOX src_box(src_rect.left, src_rect.top, 0, src_rect.right, src_rect.bottom, 1);
+ D3D::context->CopySubresourceRegion(
+ m_tex, 0, static_cast<u32>(dst_rect.left), static_cast<u32>(dst_rect.top), 0,
+ static_cast<const DXTexture*>(src)->GetD3DTexture(),
+ D3D11CalcSubresource(src_level, src_layer, src->GetLevels()), &src_box);
+ }
m_needs_flush = true;
}
@@ -294,19 +329,29 @@ void DXStagingTexture::CopyToTexture(const MathUtil::Rectangle<int>& src_rect, A
ASSERT(m_type == StagingTextureType::Upload);
ASSERT(src_rect.GetWidth() == dst_rect.GetWidth() &&
src_rect.GetHeight() == dst_rect.GetHeight());
- ASSERT(src_rect.left >= 0 && static_cast<u32>(src_rect.right) <= m_config.width &&
- src_rect.top >= 0 && static_cast<u32>(src_rect.bottom) <= m_config.height);
- ASSERT(dst_rect.left >= 0 && static_cast<u32>(dst_rect.right) <= dst->GetConfig().width &&
- dst_rect.top >= 0 && static_cast<u32>(dst_rect.bottom) <= dst->GetConfig().height);
+ ASSERT(src_rect.left >= 0 && static_cast<u32>(src_rect.right) <= GetWidth() &&
+ src_rect.top >= 0 && static_cast<u32>(src_rect.bottom) <= GetHeight());
+ ASSERT(dst_rect.left >= 0 && static_cast<u32>(dst_rect.right) <= dst->GetWidth() &&
+ dst_rect.top >= 0 && static_cast<u32>(dst_rect.bottom) <= dst->GetHeight());
if (IsMapped())
DXStagingTexture::Unmap();
- CD3D11_BOX src_box(src_rect.left, src_rect.top, 0, src_rect.right, src_rect.bottom, 1);
- D3D::context->CopySubresourceRegion(
- static_cast<const DXTexture*>(dst)->GetRawTexIdentifier()->GetTex(),
- D3D11CalcSubresource(dst_level, dst_layer, dst->GetConfig().levels),
- static_cast<u32>(dst_rect.left), static_cast<u32>(dst_rect.top), 0, m_tex, 0, &src_box);
+ if (static_cast<u32>(src_rect.GetWidth()) == dst->GetWidth() &&
+ static_cast<u32>(src_rect.GetHeight()) == dst->GetHeight())
+ {
+ D3D::context->CopySubresourceRegion(
+ static_cast<const DXTexture*>(dst)->GetD3DTexture(),
+ D3D11CalcSubresource(dst_level, dst_layer, dst->GetLevels()), 0, 0, 0, m_tex, 0, nullptr);
+ }
+ else
+ {
+ CD3D11_BOX src_box(src_rect.left, src_rect.top, 0, src_rect.right, src_rect.bottom, 1);
+ D3D::context->CopySubresourceRegion(
+ static_cast<const DXTexture*>(dst)->GetD3DTexture(),
+ D3D11CalcSubresource(dst_level, dst_layer, dst->GetLevels()),
+ static_cast<u32>(dst_rect.left), static_cast<u32>(dst_rect.top), 0, m_tex, 0, &src_box);
+ }
}
bool DXStagingTexture::Map()
@@ -348,11 +393,14 @@ void DXStagingTexture::Flush()
m_needs_flush = false;
}
-DXFramebuffer::DXFramebuffer(AbstractTextureFormat color_format, AbstractTextureFormat depth_format,
+DXFramebuffer::DXFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment,
+ AbstractTextureFormat color_format, AbstractTextureFormat depth_format,
u32 width, u32 height, u32 layers, u32 samples,
- ID3D11RenderTargetView* rtv, ID3D11DepthStencilView* dsv)
- : AbstractFramebuffer(color_format, depth_format, width, height, layers, samples), m_rtv(rtv),
- m_dsv(dsv)
+ ID3D11RenderTargetView* rtv, ID3D11RenderTargetView* integer_rtv,
+ ID3D11DepthStencilView* dsv)
+ : AbstractFramebuffer(color_attachment, depth_attachment, color_format, depth_format, width,
+ height, layers, samples),
+ m_rtv(rtv), m_integer_rtv(integer_rtv), m_dsv(dsv)
{
}
@@ -360,12 +408,14 @@ DXFramebuffer::~DXFramebuffer()
{
if (m_rtv)
m_rtv->Release();
+ if (m_integer_rtv)
+ m_integer_rtv->Release();
if (m_dsv)
m_dsv->Release();
}
-std::unique_ptr<DXFramebuffer> DXFramebuffer::Create(const DXTexture* color_attachment,
- const DXTexture* depth_attachment)
+std::unique_ptr<DXFramebuffer> DXFramebuffer::Create(DXTexture* color_attachment,
+ DXTexture* depth_attachment)
{
if (!ValidateConfig(color_attachment, depth_attachment))
return nullptr;
@@ -381,55 +431,45 @@ std::unique_ptr<DXFramebuffer> DXFramebuffer::Create(const DXTexture* color_atta
const u32 samples = either_attachment->GetSamples();
ID3D11RenderTargetView* rtv = nullptr;
+ ID3D11RenderTargetView* integer_rtv = nullptr;
if (color_attachment)
{
- D3D11_RENDER_TARGET_VIEW_DESC desc;
- desc.Format = GetDXGIFormatForHostFormat(color_attachment->GetConfig().format);
- if (color_attachment->GetConfig().IsMultisampled())
- {
- desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY;
- desc.Texture2DMSArray.ArraySize = color_attachment->GetConfig().layers;
- desc.Texture2DMSArray.FirstArraySlice = 0;
- }
- else
+ CD3D11_RENDER_TARGET_VIEW_DESC desc(
+ color_attachment->IsMultisampled() ? D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY :
+ D3D11_RTV_DIMENSION_TEXTURE2DARRAY,
+ GetRTVFormatForHostFormat(color_attachment->GetFormat(), false), 0, 0,
+ color_attachment->GetLayers());
+ HRESULT hr =
+ D3D::device->CreateRenderTargetView(color_attachment->GetD3DTexture(), &desc, &rtv);
+ CHECK(SUCCEEDED(hr), "Create render target view for framebuffer");
+
+ // Only create the integer RTV on Win8+.
+ DXGI_FORMAT integer_format = GetRTVFormatForHostFormat(color_attachment->GetFormat(), true);
+ if (D3D::device1 && integer_format != desc.Format)
{
- desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
- desc.Texture2DArray.ArraySize = color_attachment->GetConfig().layers;
- desc.Texture2DArray.FirstArraySlice = 0;
- desc.Texture2DArray.MipSlice = 0;
+ desc.Format = integer_format;
+ hr = D3D::device->CreateRenderTargetView(color_attachment->GetD3DTexture(), &desc,
+ &integer_rtv);
+ CHECK(SUCCEEDED(hr), "Create integer render target view for framebuffer");
}
-
- HRESULT hr = D3D::device->CreateRenderTargetView(
- color_attachment->GetRawTexIdentifier()->GetTex(), &desc, &rtv);
- CHECK(SUCCEEDED(hr), "Create render target view for framebuffer");
}
ID3D11DepthStencilView* dsv = nullptr;
if (depth_attachment)
{
- D3D11_DEPTH_STENCIL_VIEW_DESC desc;
- desc.Format = GetDXGIFormatForHostFormat(depth_attachment->GetConfig().format);
- if (depth_attachment->GetConfig().IsMultisampled())
- {
- desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY;
- desc.Texture2DMSArray.ArraySize = depth_attachment->GetConfig().layers;
- desc.Texture2DMSArray.FirstArraySlice = 0;
- }
- else
- {
- desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
- desc.Texture2DArray.ArraySize = depth_attachment->GetConfig().layers;
- desc.Texture2DArray.FirstArraySlice = 0;
- desc.Texture2DArray.MipSlice = 0;
- }
-
- HRESULT hr = D3D::device->CreateDepthStencilView(
- depth_attachment->GetRawTexIdentifier()->GetTex(), &desc, &dsv);
+ const CD3D11_DEPTH_STENCIL_VIEW_DESC desc(
+ depth_attachment->GetConfig().IsMultisampled() ? D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY :
+ D3D11_DSV_DIMENSION_TEXTURE2DARRAY,
+ GetDSVFormatForHostFormat(depth_attachment->GetFormat()), 0, 0,
+ depth_attachment->GetLayers(), 0);
+ HRESULT hr =
+ D3D::device->CreateDepthStencilView(depth_attachment->GetD3DTexture(), &desc, &dsv);
CHECK(SUCCEEDED(hr), "Create depth stencil view for framebuffer");
}
- return std::make_unique<DXFramebuffer>(color_format, depth_format, width, height, layers, samples,
- rtv, dsv);
+ return std::make_unique<DXFramebuffer>(color_attachment, depth_attachment, color_format,
+ depth_format, width, height, layers, samples, rtv,
+ integer_rtv, dsv);
}
} // namespace DX11