Commit f434906c by Olli Etuaho Committed by Commit Bot

Group D3D11 DXGI format info under a struct

This patch refactors how DXGI format info is stored. The goal is to make it easier to make changes that affect both swizzle formats and regular texture formats, and make it easier to pass the format sets around. BUG=angleproject:1244 TEST=angle_end2end_tests Change-Id: I1cc220bccbbdde9200a41829fdc37c8ec123c6a1 Reviewed-on: https://chromium-review.googlesource.com/329072Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 6151af8c
...@@ -89,7 +89,7 @@ bool Image11::isDirty() const ...@@ -89,7 +89,7 @@ bool Image11::isDirty() const
if (mDirty && !mStagingTexture && !mRecoverFromStorage) if (mDirty && !mStagingTexture && !mRecoverFromStorage)
{ {
const Renderer11DeviceCaps &deviceCaps = mRenderer->getRenderer11DeviceCaps(); const Renderer11DeviceCaps &deviceCaps = mRenderer->getRenderer11DeviceCaps();
const d3d11::TextureFormat formatInfo = d3d11::GetTextureFormatInfo(mInternalFormat, deviceCaps); const auto &formatInfo = d3d11::GetTextureFormatInfo(mInternalFormat, deviceCaps);
if (formatInfo.dataInitializerFunction == nullptr) if (formatInfo.dataInitializerFunction == nullptr)
{ {
return false; return false;
...@@ -219,9 +219,10 @@ bool Image11::redefine(GLenum target, GLenum internalformat, const gl::Extents & ...@@ -219,9 +219,10 @@ bool Image11::redefine(GLenum target, GLenum internalformat, const gl::Extents &
mTarget = target; mTarget = target;
// compute the d3d format that will be used // compute the d3d format that will be used
const d3d11::TextureFormat &formatInfo = d3d11::GetTextureFormatInfo(internalformat, mRenderer->getRenderer11DeviceCaps()); const d3d11::TextureFormat &formatInfo =
mDXGIFormat = formatInfo.texFormat; d3d11::GetTextureFormatInfo(internalformat, mRenderer->getRenderer11DeviceCaps());
mRenderable = (formatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN); mDXGIFormat = formatInfo.formatSet.texFormat;
mRenderable = (formatInfo.formatSet.rtvFormat != DXGI_FORMAT_UNKNOWN);
releaseStagingTexture(); releaseStagingTexture();
mDirty = (formatInfo.dataInitializerFunction != NULL); mDirty = (formatInfo.dataInitializerFunction != NULL);
...@@ -341,7 +342,7 @@ gl::Error Image11::copyFromFramebuffer(const gl::Offset &destOffset, ...@@ -341,7 +342,7 @@ gl::Error Image11::copyFromFramebuffer(const gl::Offset &destOffset,
const auto &d3d11Format = d3d11::GetTextureFormatInfo(srcAttachment->getInternalFormat(), const auto &d3d11Format = d3d11::GetTextureFormatInfo(srcAttachment->getInternalFormat(),
mRenderer->getRenderer11DeviceCaps()); mRenderer->getRenderer11DeviceCaps());
if (d3d11Format.texFormat == mDXGIFormat) if (d3d11Format.formatSet.texFormat == mDXGIFormat)
{ {
RenderTargetD3D *renderTarget = nullptr; RenderTargetD3D *renderTarget = nullptr;
gl::Error error = srcAttachment->getRenderTarget(&renderTarget); gl::Error error = srcAttachment->getRenderTarget(&renderTarget);
......
...@@ -205,7 +205,7 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpac ...@@ -205,7 +205,7 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpac
GLenum sourceFormat = gl::GetSizedInternalFormat(unsizedFormat, sourcePixelsType); GLenum sourceFormat = gl::GetSizedInternalFormat(unsizedFormat, sourcePixelsType);
const d3d11::TextureFormat &sourceFormatInfo = d3d11::GetTextureFormatInfo(sourceFormat, mRenderer->getRenderer11DeviceCaps()); const d3d11::TextureFormat &sourceFormatInfo = d3d11::GetTextureFormatInfo(sourceFormat, mRenderer->getRenderer11DeviceCaps());
DXGI_FORMAT srvFormat = sourceFormatInfo.srvFormat; DXGI_FORMAT srvFormat = sourceFormatInfo.formatSet.srvFormat;
ASSERT(srvFormat != DXGI_FORMAT_UNKNOWN); ASSERT(srvFormat != DXGI_FORMAT_UNKNOWN);
Buffer11 *bufferStorage11 = GetAs<Buffer11>(sourceBuffer.getImplementation()); Buffer11 *bufferStorage11 = GetAs<Buffer11>(sourceBuffer.getImplementation());
ID3D11ShaderResourceView *bufferSRV = bufferStorage11->getSRV(srvFormat); ID3D11ShaderResourceView *bufferSRV = bufferStorage11->getSRV(srvFormat);
......
...@@ -384,7 +384,8 @@ unsigned int SurfaceRenderTarget11::getSubresourceIndex() const ...@@ -384,7 +384,8 @@ unsigned int SurfaceRenderTarget11::getSubresourceIndex() const
DXGI_FORMAT SurfaceRenderTarget11::getDXGIFormat() const DXGI_FORMAT SurfaceRenderTarget11::getDXGIFormat() const
{ {
return d3d11::GetTextureFormatInfo(getInternalFormat(), mRenderer->getRenderer11DeviceCaps()).texFormat; return d3d11::GetTextureFormatInfo(getInternalFormat(), mRenderer->getRenderer11DeviceCaps())
.formatSet.texFormat;
} }
} }
...@@ -3058,7 +3058,7 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G ...@@ -3058,7 +3058,7 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
desc.Height = height; desc.Height = height;
desc.MipLevels = 1; desc.MipLevels = 1;
desc.ArraySize = 1; desc.ArraySize = 1;
desc.Format = formatInfo.texFormat; desc.Format = formatInfo.formatSet.texFormat;
desc.SampleDesc.Count = (supportedSamples == 0) ? 1 : supportedSamples; desc.SampleDesc.Count = (supportedSamples == 0) ? 1 : supportedSamples;
desc.SampleDesc.Quality = 0; desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT; desc.Usage = D3D11_USAGE_DEFAULT;
...@@ -3069,14 +3069,15 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G ...@@ -3069,14 +3069,15 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
// we'll flag it to allow binding that way. Shader resource views are a little // we'll flag it to allow binding that way. Shader resource views are a little
// more complicated. // more complicated.
bool bindRTV = false, bindDSV = false, bindSRV = false; bool bindRTV = false, bindDSV = false, bindSRV = false;
bindRTV = (formatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN); bindRTV = (formatInfo.formatSet.rtvFormat != DXGI_FORMAT_UNKNOWN);
bindDSV = (formatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN); bindDSV = (formatInfo.formatSet.dsvFormat != DXGI_FORMAT_UNKNOWN);
if (formatInfo.srvFormat != DXGI_FORMAT_UNKNOWN) if (formatInfo.formatSet.srvFormat != DXGI_FORMAT_UNKNOWN)
{ {
// Multisample targets flagged for binding as depth stencil cannot also be // Multisample targets flagged for binding as depth stencil cannot also be
// flagged for binding as SRV, so make certain not to add the SRV flag for // flagged for binding as SRV, so make certain not to add the SRV flag for
// these targets. // these targets.
bindSRV = !(formatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN && desc.SampleDesc.Count > 1); bindSRV = !(formatInfo.formatSet.dsvFormat != DXGI_FORMAT_UNKNOWN &&
desc.SampleDesc.Count > 1);
} }
desc.BindFlags = (bindRTV ? D3D11_BIND_RENDER_TARGET : 0) | desc.BindFlags = (bindRTV ? D3D11_BIND_RENDER_TARGET : 0) |
...@@ -3098,7 +3099,7 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G ...@@ -3098,7 +3099,7 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
if (bindSRV) if (bindSRV)
{ {
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = formatInfo.srvFormat; srvDesc.Format = formatInfo.formatSet.srvFormat;
srvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_SRV_DIMENSION_TEXTURE2D : D3D11_SRV_DIMENSION_TEXTURE2DMS; srvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_SRV_DIMENSION_TEXTURE2D : D3D11_SRV_DIMENSION_TEXTURE2DMS;
srvDesc.Texture2D.MostDetailedMip = 0; srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = 1; srvDesc.Texture2D.MipLevels = 1;
...@@ -3115,7 +3116,7 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G ...@@ -3115,7 +3116,7 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
if (bindDSV) if (bindDSV)
{ {
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
dsvDesc.Format = formatInfo.dsvFormat; dsvDesc.Format = formatInfo.formatSet.dsvFormat;
dsvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_DSV_DIMENSION_TEXTURE2D : D3D11_DSV_DIMENSION_TEXTURE2DMS; dsvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_DSV_DIMENSION_TEXTURE2D : D3D11_DSV_DIMENSION_TEXTURE2DMS;
dsvDesc.Texture2D.MipSlice = 0; dsvDesc.Texture2D.MipSlice = 0;
dsvDesc.Flags = 0; dsvDesc.Flags = 0;
...@@ -3137,7 +3138,7 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G ...@@ -3137,7 +3138,7 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
else if (bindRTV) else if (bindRTV)
{ {
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
rtvDesc.Format = formatInfo.rtvFormat; rtvDesc.Format = formatInfo.formatSet.rtvFormat;
rtvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_RTV_DIMENSION_TEXTURE2D : D3D11_RTV_DIMENSION_TEXTURE2DMS; rtvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_RTV_DIMENSION_TEXTURE2D : D3D11_RTV_DIMENSION_TEXTURE2DMS;
rtvDesc.Texture2D.MipSlice = 0; rtvDesc.Texture2D.MipSlice = 0;
...@@ -3448,7 +3449,8 @@ bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const ...@@ -3448,7 +3449,8 @@ bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const
const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(internalFormat); const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(internalFormat);
const d3d11::TextureFormat &d3d11FormatInfo = d3d11::GetTextureFormatInfo(internalFormat, mRenderer11DeviceCaps); const d3d11::TextureFormat &d3d11FormatInfo = d3d11::GetTextureFormatInfo(internalFormat, mRenderer11DeviceCaps);
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(d3d11FormatInfo.texFormat); const d3d11::DXGIFormat &dxgiFormatInfo =
d3d11::GetDXGIFormatInfo(d3d11FormatInfo.formatSet.texFormat);
// sRGB formats do not work with D3D11 buffer SRVs // sRGB formats do not work with D3D11 buffer SRVs
if (internalFormatInfo.colorEncoding == GL_SRGB) if (internalFormatInfo.colorEncoding == GL_SRGB)
...@@ -3457,7 +3459,7 @@ bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const ...@@ -3457,7 +3459,7 @@ bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const
} }
// We cannot support direct copies to non-color-renderable formats // We cannot support direct copies to non-color-renderable formats
if (d3d11FormatInfo.rtvFormat == DXGI_FORMAT_UNKNOWN) if (d3d11FormatInfo.formatSet.rtvFormat == DXGI_FORMAT_UNKNOWN)
{ {
return false; return false;
} }
......
...@@ -208,9 +208,8 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe ...@@ -208,9 +208,8 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe
if (offscreenTextureDesc.Width != (UINT)backbufferWidth || if (offscreenTextureDesc.Width != (UINT)backbufferWidth ||
offscreenTextureDesc.Height != (UINT)backbufferHeight || offscreenTextureDesc.Height != (UINT)backbufferHeight ||
offscreenTextureDesc.Format != backbufferFormatInfo.texFormat || offscreenTextureDesc.Format != backbufferFormatInfo.formatSet.texFormat ||
offscreenTextureDesc.MipLevels != 1 || offscreenTextureDesc.MipLevels != 1 || offscreenTextureDesc.ArraySize != 1)
offscreenTextureDesc.ArraySize != 1)
{ {
ERR("Invalid texture parameters in the shared offscreen texture pbuffer"); ERR("Invalid texture parameters in the shared offscreen texture pbuffer");
release(); release();
...@@ -224,7 +223,7 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe ...@@ -224,7 +223,7 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe
D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0}; D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0};
offscreenTextureDesc.Width = backbufferWidth; offscreenTextureDesc.Width = backbufferWidth;
offscreenTextureDesc.Height = backbufferHeight; offscreenTextureDesc.Height = backbufferHeight;
offscreenTextureDesc.Format = backbufferFormatInfo.texFormat; offscreenTextureDesc.Format = backbufferFormatInfo.formatSet.texFormat;
offscreenTextureDesc.MipLevels = 1; offscreenTextureDesc.MipLevels = 1;
offscreenTextureDesc.ArraySize = 1; offscreenTextureDesc.ArraySize = 1;
offscreenTextureDesc.SampleDesc.Count = 1; offscreenTextureDesc.SampleDesc.Count = 1;
...@@ -282,7 +281,7 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe ...@@ -282,7 +281,7 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe
mKeyedMutex = d3d11::DynamicCastComObject<IDXGIKeyedMutex>(mOffscreenTexture); mKeyedMutex = d3d11::DynamicCastComObject<IDXGIKeyedMutex>(mOffscreenTexture);
D3D11_RENDER_TARGET_VIEW_DESC offscreenRTVDesc; D3D11_RENDER_TARGET_VIEW_DESC offscreenRTVDesc;
offscreenRTVDesc.Format = backbufferFormatInfo.rtvFormat; offscreenRTVDesc.Format = backbufferFormatInfo.formatSet.rtvFormat;
offscreenRTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; offscreenRTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
offscreenRTVDesc.Texture2D.MipSlice = 0; offscreenRTVDesc.Texture2D.MipSlice = 0;
...@@ -291,7 +290,7 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe ...@@ -291,7 +290,7 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe
d3d11::SetDebugName(mOffscreenRTView, "Offscreen back buffer render target"); d3d11::SetDebugName(mOffscreenRTView, "Offscreen back buffer render target");
D3D11_SHADER_RESOURCE_VIEW_DESC offscreenSRVDesc; D3D11_SHADER_RESOURCE_VIEW_DESC offscreenSRVDesc;
offscreenSRVDesc.Format = backbufferFormatInfo.srvFormat; offscreenSRVDesc.Format = backbufferFormatInfo.formatSet.srvFormat;
offscreenSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; offscreenSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
offscreenSRVDesc.Texture2D.MostDetailedMip = 0; offscreenSRVDesc.Texture2D.MostDetailedMip = 0;
offscreenSRVDesc.Texture2D.MipLevels = static_cast<UINT>(-1); offscreenSRVDesc.Texture2D.MipLevels = static_cast<UINT>(-1);
...@@ -338,7 +337,7 @@ EGLint SwapChain11::resetOffscreenDepthBuffer(int backbufferWidth, int backbuffe ...@@ -338,7 +337,7 @@ EGLint SwapChain11::resetOffscreenDepthBuffer(int backbufferWidth, int backbuffe
D3D11_TEXTURE2D_DESC depthStencilTextureDesc; D3D11_TEXTURE2D_DESC depthStencilTextureDesc;
depthStencilTextureDesc.Width = backbufferWidth; depthStencilTextureDesc.Width = backbufferWidth;
depthStencilTextureDesc.Height = backbufferHeight; depthStencilTextureDesc.Height = backbufferHeight;
depthStencilTextureDesc.Format = depthBufferFormatInfo.texFormat; depthStencilTextureDesc.Format = depthBufferFormatInfo.formatSet.texFormat;
depthStencilTextureDesc.MipLevels = 1; depthStencilTextureDesc.MipLevels = 1;
depthStencilTextureDesc.ArraySize = 1; depthStencilTextureDesc.ArraySize = 1;
depthStencilTextureDesc.SampleDesc.Count = 1; depthStencilTextureDesc.SampleDesc.Count = 1;
...@@ -346,7 +345,7 @@ EGLint SwapChain11::resetOffscreenDepthBuffer(int backbufferWidth, int backbuffe ...@@ -346,7 +345,7 @@ EGLint SwapChain11::resetOffscreenDepthBuffer(int backbufferWidth, int backbuffe
depthStencilTextureDesc.Usage = D3D11_USAGE_DEFAULT; depthStencilTextureDesc.Usage = D3D11_USAGE_DEFAULT;
depthStencilTextureDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; depthStencilTextureDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
if (depthBufferFormatInfo.srvFormat != DXGI_FORMAT_UNKNOWN) if (depthBufferFormatInfo.formatSet.srvFormat != DXGI_FORMAT_UNKNOWN)
{ {
depthStencilTextureDesc.BindFlags |= D3D11_BIND_SHADER_RESOURCE; depthStencilTextureDesc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
} }
...@@ -374,7 +373,7 @@ EGLint SwapChain11::resetOffscreenDepthBuffer(int backbufferWidth, int backbuffe ...@@ -374,7 +373,7 @@ EGLint SwapChain11::resetOffscreenDepthBuffer(int backbufferWidth, int backbuffe
d3d11::SetDebugName(mDepthStencilTexture, "Offscreen depth stencil texture"); d3d11::SetDebugName(mDepthStencilTexture, "Offscreen depth stencil texture");
D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilDesc; D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilDesc;
depthStencilDesc.Format = depthBufferFormatInfo.dsvFormat; depthStencilDesc.Format = depthBufferFormatInfo.formatSet.dsvFormat;
depthStencilDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; depthStencilDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
depthStencilDesc.Flags = 0; depthStencilDesc.Flags = 0;
depthStencilDesc.Texture2D.MipSlice = 0; depthStencilDesc.Texture2D.MipSlice = 0;
...@@ -383,10 +382,10 @@ EGLint SwapChain11::resetOffscreenDepthBuffer(int backbufferWidth, int backbuffe ...@@ -383,10 +382,10 @@ EGLint SwapChain11::resetOffscreenDepthBuffer(int backbufferWidth, int backbuffe
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mDepthStencilDSView, "Offscreen depth stencil view"); d3d11::SetDebugName(mDepthStencilDSView, "Offscreen depth stencil view");
if (depthBufferFormatInfo.srvFormat != DXGI_FORMAT_UNKNOWN) if (depthBufferFormatInfo.formatSet.srvFormat != DXGI_FORMAT_UNKNOWN)
{ {
D3D11_SHADER_RESOURCE_VIEW_DESC depthStencilSRVDesc; D3D11_SHADER_RESOURCE_VIEW_DESC depthStencilSRVDesc;
depthStencilSRVDesc.Format = depthBufferFormatInfo.srvFormat; depthStencilSRVDesc.Format = depthBufferFormatInfo.formatSet.srvFormat;
depthStencilSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; depthStencilSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
depthStencilSRVDesc.Texture2D.MostDetailedMip = 0; depthStencilSRVDesc.Texture2D.MostDetailedMip = 0;
depthStencilSRVDesc.Texture2D.MipLevels = static_cast<UINT>(-1); depthStencilSRVDesc.Texture2D.MipLevels = static_cast<UINT>(-1);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "libANGLE/Texture.h" #include "libANGLE/Texture.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/renderer/d3d/TextureStorage.h" #include "libANGLE/renderer/d3d/TextureStorage.h"
#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h"
#include <map> #include <map>
...@@ -103,13 +104,8 @@ class TextureStorage11 : public TextureStorage ...@@ -103,13 +104,8 @@ class TextureStorage11 : public TextureStorage
unsigned int mMipLevels; unsigned int mMipLevels;
GLenum mInternalFormat; GLenum mInternalFormat;
DXGI_FORMAT mTextureFormat; d3d11::DXGIFormatSet mTextureFormatSet;
DXGI_FORMAT mShaderResourceFormat; d3d11::DXGIFormatSet mSwizzleFormatSet;
DXGI_FORMAT mRenderTargetFormat;
DXGI_FORMAT mDepthStencilFormat;
DXGI_FORMAT mSwizzleTextureFormat;
DXGI_FORMAT mSwizzleShaderResourceFormat;
DXGI_FORMAT mSwizzleRenderTargetFormat;
unsigned int mTextureWidth; unsigned int mTextureWidth;
unsigned int mTextureHeight; unsigned int mTextureHeight;
unsigned int mTextureDepth; unsigned int mTextureDepth;
......
...@@ -109,24 +109,32 @@ bool SupportsFormat(const Renderer11DeviceCaps &deviceCaps) ...@@ -109,24 +109,32 @@ bool SupportsFormat(const Renderer11DeviceCaps &deviceCaps)
}} }}
// End Format Support Functions // End Format Support Functions
}} // namespace
DXGIFormatSet::DXGIFormatSet()
: texFormat(DXGI_FORMAT_UNKNOWN),
srvFormat(DXGI_FORMAT_UNKNOWN),
rtvFormat(DXGI_FORMAT_UNKNOWN),
dsvFormat(DXGI_FORMAT_UNKNOWN)
{{
}}
// For sized GL internal formats, there are several possible corresponding D3D11 formats depending // For sized GL internal formats, there are several possible corresponding D3D11 formats depending
// on device capabilities. // on device capabilities.
// This function allows querying for the DXGI texture formats to use for textures, SRVs, RTVs and // This function allows querying for the DXGI texture formats to use for textures, SRVs, RTVs and
// DSVs given a GL internal format. // DSVs given a GL internal format.
const TextureFormat GetD3D11FormatInfo(GLenum internalFormat, TextureFormat::TextureFormat(GLenum internalFormat,
DXGI_FORMAT texFormat, DXGI_FORMAT texFormat,
DXGI_FORMAT srvFormat, DXGI_FORMAT srvFormat,
DXGI_FORMAT rtvFormat, DXGI_FORMAT rtvFormat,
DXGI_FORMAT dsvFormat, DXGI_FORMAT dsvFormat,
InitializeTextureDataFunction internalFormatInitializer) InitializeTextureDataFunction internalFormatInitializer)
: dataInitializerFunction(internalFormatInitializer)
{{ {{
TextureFormat info; formatSet.texFormat = texFormat;
info.texFormat = texFormat; formatSet.srvFormat = srvFormat;
info.srvFormat = srvFormat; formatSet.rtvFormat = rtvFormat;
info.rtvFormat = rtvFormat; formatSet.dsvFormat = dsvFormat;
info.dsvFormat = dsvFormat;
info.dataInitializerFunction = internalFormatInitializer;
// Compute the swizzle formats // Compute the swizzle formats
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat); const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
...@@ -158,47 +166,28 @@ const TextureFormat GetD3D11FormatInfo(GLenum internalFormat, ...@@ -158,47 +166,28 @@ const TextureFormat GetD3D11FormatInfo(GLenum internalFormat,
const SwizzleFormatInfo &swizzleInfo = const SwizzleFormatInfo &swizzleInfo =
GetSwizzleFormatInfo(maxBits, formatInfo.componentType); GetSwizzleFormatInfo(maxBits, formatInfo.componentType);
info.swizzleTexFormat = swizzleInfo.mTexFormat; swizzleFormatSet.texFormat = swizzleInfo.mTexFormat;
info.swizzleSRVFormat = swizzleInfo.mSRVFormat; swizzleFormatSet.srvFormat = swizzleInfo.mSRVFormat;
info.swizzleRTVFormat = swizzleInfo.mRTVFormat; swizzleFormatSet.rtvFormat = swizzleInfo.mRTVFormat;
}} }}
else else
{{ {{
// The original texture format is suitable for swizzle operations // The original texture format is suitable for swizzle operations
info.swizzleTexFormat = texFormat; swizzleFormatSet = formatSet;
info.swizzleSRVFormat = srvFormat;
info.swizzleRTVFormat = rtvFormat;
}} }}
}} }}
else else
{{ {{
// Not possible to swizzle with this texture format since it is either unsized or GL_NONE // Not possible to swizzle with this texture format since it is either unsized or GL_NONE
info.swizzleTexFormat = DXGI_FORMAT_UNKNOWN; ASSERT(swizzleFormatSet.texFormat == DXGI_FORMAT_UNKNOWN);
info.swizzleSRVFormat = DXGI_FORMAT_UNKNOWN; ASSERT(swizzleFormatSet.srvFormat == DXGI_FORMAT_UNKNOWN);
info.swizzleRTVFormat = DXGI_FORMAT_UNKNOWN; ASSERT(swizzleFormatSet.rtvFormat == DXGI_FORMAT_UNKNOWN);
}} }}
// Gather all the load functions for this internal format // Gather all the load functions for this internal format
info.loadFunctions = GetLoadFunctionsMap(internalFormat, texFormat); loadFunctions = GetLoadFunctionsMap(internalFormat, texFormat);
ASSERT(info.loadFunctions.size() != 0 || internalFormat == GL_NONE);
return info; ASSERT(loadFunctions.size() != 0 || internalFormat == GL_NONE);
}}
}} // namespace
TextureFormat::TextureFormat()
: texFormat(DXGI_FORMAT_UNKNOWN),
srvFormat(DXGI_FORMAT_UNKNOWN),
rtvFormat(DXGI_FORMAT_UNKNOWN),
dsvFormat(DXGI_FORMAT_UNKNOWN),
swizzleTexFormat(DXGI_FORMAT_UNKNOWN),
swizzleSRVFormat(DXGI_FORMAT_UNKNOWN),
swizzleRTVFormat(DXGI_FORMAT_UNKNOWN),
dataInitializerFunction(NULL),
loadFunctions()
{{
}} }}
const TextureFormat &GetTextureFormatInfo(GLenum internalFormat, const TextureFormat &GetTextureFormatInfo(GLenum internalFormat,
...@@ -213,7 +202,8 @@ const TextureFormat &GetTextureFormatInfo(GLenum internalFormat, ...@@ -213,7 +202,8 @@ const TextureFormat &GetTextureFormatInfo(GLenum internalFormat,
}} }}
// clang-format on // clang-format on
static const TextureFormat defaultInfo; static const TextureFormat defaultInfo(GL_NONE, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN,
DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, nullptr);
return defaultInfo; return defaultInfo;
}} // GetTextureFormatInfo }} // GetTextureFormatInfo
...@@ -312,12 +302,12 @@ def get_texture_format_item(idx, internal_format, requirements_fn, angle_format) ...@@ -312,12 +302,12 @@ def get_texture_format_item(idx, internal_format, requirements_fn, angle_format)
table_data += ' {\n' table_data += ' {\n'
indent += ' ' indent += ' '
table_data += indent + 'static const TextureFormat textureFormat = GetD3D11FormatInfo(internalFormat,\n' table_data += indent + 'static const TextureFormat textureFormat(internalFormat,\n'
table_data += indent + ' ' + tex_format + ',\n' table_data += indent + ' ' + tex_format + ',\n'
table_data += indent + ' ' + srv_format + ',\n' table_data += indent + ' ' + srv_format + ',\n'
table_data += indent + ' ' + rtv_format + ',\n' table_data += indent + ' ' + rtv_format + ',\n'
table_data += indent + ' ' + dsv_format + ',\n' table_data += indent + ' ' + dsv_format + ',\n'
table_data += indent + ' ' + internal_format_initializer + ');\n' table_data += indent + ' ' + internal_format_initializer + ');\n'
table_data += indent + 'return textureFormat;\n' table_data += indent + 'return textureFormat;\n'
if requirements_fn != None: if requirements_fn != None:
......
...@@ -358,19 +358,21 @@ static gl::TextureCaps GenerateTextureFormatCaps(GLint maxClientVersion, GLenum ...@@ -358,19 +358,21 @@ static gl::TextureCaps GenerateTextureFormatCaps(GLint maxClientVersion, GLenum
} }
} }
textureCaps.texturable = support.query(formatInfo.texFormat, texSupportMask); textureCaps.texturable = support.query(formatInfo.formatSet.texFormat, texSupportMask);
textureCaps.filterable = support.query(formatInfo.srvFormat, D3D11_FORMAT_SUPPORT_SHADER_SAMPLE); textureCaps.filterable =
textureCaps.renderable = (support.query(formatInfo.rtvFormat, D3D11_FORMAT_SUPPORT_RENDER_TARGET)) || support.query(formatInfo.formatSet.srvFormat, D3D11_FORMAT_SUPPORT_SHADER_SAMPLE);
(support.query(formatInfo.dsvFormat, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)); textureCaps.renderable =
(support.query(formatInfo.formatSet.rtvFormat, D3D11_FORMAT_SUPPORT_RENDER_TARGET)) ||
(support.query(formatInfo.formatSet.dsvFormat, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL));
DXGI_FORMAT renderFormat = DXGI_FORMAT_UNKNOWN; DXGI_FORMAT renderFormat = DXGI_FORMAT_UNKNOWN;
if (formatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN) if (formatInfo.formatSet.dsvFormat != DXGI_FORMAT_UNKNOWN)
{ {
renderFormat = formatInfo.dsvFormat; renderFormat = formatInfo.formatSet.dsvFormat;
} }
else if (formatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN) else if (formatInfo.formatSet.rtvFormat != DXGI_FORMAT_UNKNOWN)
{ {
renderFormat = formatInfo.rtvFormat; renderFormat = formatInfo.formatSet.rtvFormat;
} }
if (renderFormat != DXGI_FORMAT_UNKNOWN && if (renderFormat != DXGI_FORMAT_UNKNOWN &&
support.query(renderFormat, D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET)) support.query(renderFormat, D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET))
...@@ -1364,7 +1366,7 @@ void GenerateInitialTextureData(GLint internalFormat, ...@@ -1364,7 +1366,7 @@ void GenerateInitialTextureData(GLint internalFormat,
ASSERT(d3dFormatInfo.dataInitializerFunction != NULL); ASSERT(d3dFormatInfo.dataInitializerFunction != NULL);
const d3d11::DXGIFormatSize &dxgiFormatInfo = const d3d11::DXGIFormatSize &dxgiFormatInfo =
d3d11::GetDXGIFormatSizeInfo(d3dFormatInfo.texFormat); d3d11::GetDXGIFormatSizeInfo(d3dFormatInfo.formatSet.texFormat);
outSubresourceData->resize(mipLevels); outSubresourceData->resize(mipLevels);
outData->resize(mipLevels); outData->resize(mipLevels);
......
...@@ -34,18 +34,29 @@ struct LoadImageFunctionInfo ...@@ -34,18 +34,29 @@ struct LoadImageFunctionInfo
bool requiresConversion; bool requiresConversion;
}; };
struct TextureFormat struct DXGIFormatSet
{ {
TextureFormat(); DXGIFormatSet();
DXGIFormatSet(const DXGIFormatSet &) = default;
DXGIFormatSet &operator=(const DXGIFormatSet &) = default;
DXGI_FORMAT texFormat; DXGI_FORMAT texFormat;
DXGI_FORMAT srvFormat; DXGI_FORMAT srvFormat;
DXGI_FORMAT rtvFormat; DXGI_FORMAT rtvFormat;
DXGI_FORMAT dsvFormat; DXGI_FORMAT dsvFormat;
};
DXGI_FORMAT swizzleTexFormat; struct TextureFormat : public angle::NonCopyable
DXGI_FORMAT swizzleSRVFormat; {
DXGI_FORMAT swizzleRTVFormat; TextureFormat(GLenum internalFormat,
DXGI_FORMAT texFormat,
DXGI_FORMAT srvFormat,
DXGI_FORMAT rtvFormat,
DXGI_FORMAT dsvFormat,
InitializeTextureDataFunction internalFormatInitializer);
DXGIFormatSet formatSet;
DXGIFormatSet swizzleFormatSet;
InitializeTextureDataFunction dataInitializerFunction; InitializeTextureDataFunction dataInitializerFunction;
typedef std::map<GLenum, LoadImageFunctionInfo> LoadFunctionMap; typedef std::map<GLenum, LoadImageFunctionInfo> LoadFunctionMap;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -64,13 +64,15 @@ TEST_P(D3D11FormatTablesTest, TestFormatSupport) ...@@ -64,13 +64,15 @@ TEST_P(D3D11FormatTablesTest, TestFormatSupport)
} }
UINT texSupport; UINT texSupport;
bool texSuccess = SUCCEEDED(device->CheckFormatSupport(formatInfo.texFormat, &texSupport)); bool texSuccess =
SUCCEEDED(device->CheckFormatSupport(formatInfo.formatSet.texFormat, &texSupport));
bool textureable = texSuccess && ((texSupport & texSupportMask) == texSupportMask); bool textureable = texSuccess && ((texSupport & texSupportMask) == texSupportMask);
EXPECT_EQ(textureable, textureInfo.texturable); EXPECT_EQ(textureable, textureInfo.texturable);
// Bits for filtering // Bits for filtering
UINT filterSupport; UINT filterSupport;
bool filterSuccess = SUCCEEDED(device->CheckFormatSupport(formatInfo.srvFormat, &filterSupport)); bool filterSuccess =
SUCCEEDED(device->CheckFormatSupport(formatInfo.formatSet.srvFormat, &filterSupport));
bool filterable = filterSuccess && ((filterSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE) != 0); bool filterable = filterSuccess && ((filterSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE) != 0);
EXPECT_EQ(filterable, textureInfo.filterable); EXPECT_EQ(filterable, textureInfo.filterable);
...@@ -80,25 +82,25 @@ TEST_P(D3D11FormatTablesTest, TestFormatSupport) ...@@ -80,25 +82,25 @@ TEST_P(D3D11FormatTablesTest, TestFormatSupport)
DXGI_FORMAT renderFormat = DXGI_FORMAT_UNKNOWN; DXGI_FORMAT renderFormat = DXGI_FORMAT_UNKNOWN;
if (internalFormatInfo.depthBits > 0 || internalFormatInfo.stencilBits > 0) if (internalFormatInfo.depthBits > 0 || internalFormatInfo.stencilBits > 0)
{ {
renderFormat = formatInfo.dsvFormat; renderFormat = formatInfo.formatSet.dsvFormat;
bool depthSuccess = bool depthSuccess = SUCCEEDED(
SUCCEEDED(device->CheckFormatSupport(formatInfo.dsvFormat, &renderSupport)); device->CheckFormatSupport(formatInfo.formatSet.dsvFormat, &renderSupport));
renderable = renderable =
depthSuccess && ((renderSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL) != 0); depthSuccess && ((renderSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL) != 0);
if (renderable) if (renderable)
{ {
EXPECT_NE(DXGI_FORMAT_UNKNOWN, formatInfo.dsvFormat); EXPECT_NE(DXGI_FORMAT_UNKNOWN, formatInfo.formatSet.dsvFormat);
} }
} }
else else
{ {
renderFormat = formatInfo.rtvFormat; renderFormat = formatInfo.formatSet.rtvFormat;
bool rtSuccess = bool rtSuccess = SUCCEEDED(
SUCCEEDED(device->CheckFormatSupport(formatInfo.rtvFormat, &renderSupport)); device->CheckFormatSupport(formatInfo.formatSet.rtvFormat, &renderSupport));
renderable = rtSuccess && ((renderSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET) != 0); renderable = rtSuccess && ((renderSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET) != 0);
if (renderable) if (renderable)
{ {
EXPECT_NE(DXGI_FORMAT_UNKNOWN, formatInfo.rtvFormat); EXPECT_NE(DXGI_FORMAT_UNKNOWN, formatInfo.formatSet.rtvFormat);
} }
} }
EXPECT_EQ(renderable, textureInfo.renderable); EXPECT_EQ(renderable, textureInfo.renderable);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment