Commit 114d129d by Olli Etuaho

D3D11: Get color read function from ANGLE format

This is done to make it possible to change some of the DXGI formats of integer textures without affecting their color read function associations. The packPixels function gets the ANGLE format from the texture helper, which now requires the ANGLE format to be passed in at the time of creation. BUG=angleproject:1244 TEST=angle_end2end_tests, dEQP-GLES3.functional.fbo.* (no regressions), dEQP-GLES3.functional.pbo.* (all pass) Change-Id: I368337cfe5f8c86ff3292009ccf29e9d01409a07 Reviewed-on: https://chromium-review.googlesource.com/329213Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 3b3657be
......@@ -1322,7 +1322,8 @@ gl::Error Buffer11::PackStorage::packPixels(const gl::FramebufferAttachment &rea
ASSERT(renderTargetResource);
unsigned int srcSubresource = renderTarget->getSubresourceIndex();
TextureHelper11 srcTexture = TextureHelper11::MakeAndReference(renderTargetResource);
TextureHelper11 srcTexture =
TextureHelper11::MakeAndReference(renderTargetResource, renderTarget->getANGLEFormat());
mQueuedPackCommand.reset(new PackPixelsParams(params));
......@@ -1330,9 +1331,9 @@ gl::Error Buffer11::PackStorage::packPixels(const gl::FramebufferAttachment &rea
if (!mStagingTexture.getResource() || mStagingTexture.getFormat() != srcTexture.getFormat() ||
mStagingTexture.getExtents() != srcTextureSize)
{
auto textureOrError =
CreateStagingTexture(srcTexture.getTextureType(), srcTexture.getFormat(),
srcTextureSize, mRenderer->getDevice());
auto textureOrError = CreateStagingTexture(
srcTexture.getTextureType(), srcTexture.getFormat(), srcTexture.getANGLEFormat(),
srcTextureSize, mRenderer->getDevice());
if (textureOrError.isError())
{
return textureOrError.getError();
......
......@@ -327,7 +327,8 @@ gl::Error Image11::copyFromTexStorage(const gl::ImageIndex &imageIndex, TextureS
}
UINT subresourceIndex = storage11->getSubresourceIndex(imageIndex);
TextureHelper11 textureHelper = TextureHelper11::MakeAndReference(resource);
TextureHelper11 textureHelper =
TextureHelper11::MakeAndReference(resource, storage11->getANGLEFormat());
gl::Box sourceBox(0, 0, 0, mWidth, mHeight, mDepth);
return copyWithoutConversion(gl::Offset(), sourceBox, textureHelper, subresourceIndex);
......@@ -355,7 +356,8 @@ gl::Error Image11::copyFromFramebuffer(const gl::Offset &destOffset,
RenderTarget11 *rt11 = GetAs<RenderTarget11>(renderTarget);
ASSERT(rt11->getTexture());
TextureHelper11 textureHelper = TextureHelper11::MakeAndReference(rt11->getTexture());
TextureHelper11 textureHelper =
TextureHelper11::MakeAndReference(rt11->getTexture(), rt11->getANGLEFormat());
unsigned int sourceSubResource = rt11->getSubresourceIndex();
gl::Box sourceBox(sourceArea.x, sourceArea.y, 0, sourceArea.width, sourceArea.height, 1);
......
......@@ -3575,7 +3575,8 @@ gl::Error Renderer11::readFromAttachment(const gl::FramebufferAttachment &srcAtt
RenderTarget11 *rt11 = GetAs<RenderTarget11>(renderTarget);
ASSERT(rt11->getTexture());
TextureHelper11 textureHelper = TextureHelper11::MakeAndReference(rt11->getTexture());
TextureHelper11 textureHelper =
TextureHelper11::MakeAndReference(rt11->getTexture(), rt11->getANGLEFormat());
unsigned int sourceSubResource = rt11->getSubresourceIndex();
const gl::Extents &texSize = textureHelper.getExtents();
......@@ -3607,8 +3608,9 @@ gl::Error Renderer11::readFromAttachment(const gl::FramebufferAttachment &srcAtt
}
gl::Extents safeSize(safeArea.width, safeArea.height, 1);
auto errorOrResult = CreateStagingTexture(textureHelper.getTextureType(),
textureHelper.getFormat(), safeSize, mDevice);
auto errorOrResult =
CreateStagingTexture(textureHelper.getTextureType(), textureHelper.getFormat(),
textureHelper.getANGLEFormat(), safeSize, mDevice);
if (errorOrResult.isError())
{
return errorOrResult.getError();
......@@ -3648,7 +3650,8 @@ gl::Error Renderer11::readFromAttachment(const gl::FramebufferAttachment &srcAtt
mDeviceContext->ResolveSubresource(resolveTex2D, 0, textureHelper.getTexture2D(),
sourceSubResource, textureHelper.getFormat());
resolvedTextureHelper = TextureHelper11::MakeAndReference(resolveTex2D);
resolvedTextureHelper =
TextureHelper11::MakeAndReference(resolveTex2D, textureHelper.getANGLEFormat());
sourceSubResource = 0;
srcTexture = &resolvedTextureHelper;
......@@ -3757,7 +3760,8 @@ gl::Error Renderer11::packPixels(const TextureHelper11 &textureHelper,
}
else
{
ColorReadFunction colorReadFunction = dxgiFormatInfo.colorReadFunction;
const auto &angleFormatInfo = d3d11::GetANGLEFormatSet(textureHelper.getANGLEFormat());
ColorReadFunction colorReadFunction = angleFormatInfo.colorReadFunction;
ColorWriteFunction colorWriteFunction = GetColorWriteFunction(params.format, params.type);
uint8_t temp[16]; // Maximum size of any Color<T> type used.
......
......@@ -358,6 +358,11 @@ gl::Error TextureStorage11::getSRVLevels(GLint baseLevel,
return gl::Error(GL_NO_ERROR);
}
d3d11::ANGLEFormat TextureStorage11::getANGLEFormat() const
{
return mTextureFormatSet.format;
}
gl::Error TextureStorage11::generateSwizzles(GLenum swizzleRed,
GLenum swizzleGreen,
GLenum swizzleBlue,
......
......@@ -78,6 +78,8 @@ class TextureStorage11 : public TextureStorage
gl::Error getSRVLevels(GLint baseLevel, GLint maxLevel, ID3D11ShaderResourceView **outSRV);
d3d11::ANGLEFormat getANGLEFormat() const;
protected:
TextureStorage11(Renderer11 *renderer, UINT bindFlags, UINT miscFlags);
int getLevelWidth(int mipLevel) const;
......
......@@ -43,8 +43,6 @@ struct DXGIFormat
GLenum internalFormat;
GLenum componentType;
ColorReadFunction colorReadFunction;
FastCopyFunctionMap fastCopyFunctions;
NativeMipmapGenerationSupportFunction nativeMipmapSupport;
......
......@@ -52,6 +52,7 @@ template_texture_format_table_autogen_cpp = """// GENERATED FILE - DO NOT EDIT.
#include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
#include "libANGLE/renderer/d3d/d3d11/load_functions_table.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include "libANGLE/renderer/d3d/copyimage.h"
#include "libANGLE/renderer/d3d/generatemip.h"
#include "libANGLE/renderer/d3d/loadimage.h"
......@@ -144,7 +145,8 @@ ANGLEFormatSet::ANGLEFormatSet()
rtvFormat(DXGI_FORMAT_UNKNOWN),
dsvFormat(DXGI_FORMAT_UNKNOWN),
swizzleFormat(ANGLE_FORMAT_NONE),
mipGenerationFunction(nullptr)
mipGenerationFunction(nullptr),
colorReadFunction(nullptr)
{{
}}
......@@ -173,7 +175,8 @@ ANGLEFormatSet::ANGLEFormatSet(ANGLEFormat format,
DXGI_FORMAT rtvFormat,
DXGI_FORMAT dsvFormat,
ANGLEFormat swizzleFormat,
MipGenerationFunction mipGenerationFunction)
MipGenerationFunction mipGenerationFunction,
ColorReadFunction colorReadFunction)
: format(format),
glInternalFormat(glInternalFormat),
texFormat(texFormat),
......@@ -181,7 +184,8 @@ ANGLEFormatSet::ANGLEFormatSet(ANGLEFormat format,
rtvFormat(rtvFormat),
dsvFormat(dsvFormat),
swizzleFormat(swizzleFormat),
mipGenerationFunction(mipGenerationFunction)
mipGenerationFunction(mipGenerationFunction),
colorReadFunction(colorReadFunction)
{{
}}
......@@ -424,6 +428,19 @@ def get_mip_generation_function(angle_format):
return 'nullptr'
return 'GenerateMip<' + channel_struct + '>'
def get_color_read_function(angle_format):
channel_struct = get_channel_struct(angle_format)
if channel_struct == None:
return 'nullptr'
component_type_map = {
'uint': 'GLuint',
'int': 'GLint',
'unorm': 'GLfloat',
'snorm': 'GLfloat',
'float': 'GLfloat'
}
return 'ReadColor<' + channel_struct + ', '+ component_type_map[angle_format['componentType']] + '>'
def parse_json_into_switch_angle_format_string(json_data):
table_data = ''
for angle_format_item in sorted(json_data.iteritems()):
......@@ -436,6 +453,7 @@ def parse_json_into_switch_angle_format_string(json_data):
dsv_format = angle_format["dsvFormat"] if "dsvFormat" in angle_format else "DXGI_FORMAT_UNKNOWN"
swizzle_format = get_swizzle_format_id(angle_format_item[0], angle_format)
mip_generation_function = get_mip_generation_function(angle_format)
color_read_function = get_color_read_function(angle_format)
table_data += ' {\n'
table_data += ' static const ANGLEFormatSet formatInfo(' + angle_format_item[0] + ',\n'
table_data += ' ' + gl_internal_format + ',\n'
......@@ -444,7 +462,8 @@ def parse_json_into_switch_angle_format_string(json_data):
table_data += ' ' + rtv_format + ',\n'
table_data += ' ' + dsv_format + ',\n'
table_data += ' ' + swizzle_format + ',\n'
table_data += ' ' + mip_generation_function + ');\n'
table_data += ' ' + mip_generation_function + ',\n'
table_data += ' ' + color_read_function + ');\n'
table_data += ' return formatInfo;\n'
table_data += ' }\n'
return table_data
......
......@@ -1526,6 +1526,7 @@ void InitConstantBufferDesc(D3D11_BUFFER_DESC *constantBufferDescription, size_t
TextureHelper11::TextureHelper11()
: mTextureType(GL_NONE),
mFormat(DXGI_FORMAT_UNKNOWN),
mANGLEFormat(d3d11::ANGLE_FORMAT_NONE),
mSampleCount(0),
mTexture2D(nullptr),
mTexture3D(nullptr)
......@@ -1536,6 +1537,7 @@ TextureHelper11::TextureHelper11(TextureHelper11 &&toCopy)
: mTextureType(toCopy.mTextureType),
mExtents(toCopy.mExtents),
mFormat(toCopy.mFormat),
mANGLEFormat(toCopy.mANGLEFormat),
mSampleCount(toCopy.mSampleCount),
mTexture2D(toCopy.mTexture2D),
mTexture3D(toCopy.mTexture3D)
......@@ -1544,9 +1546,11 @@ TextureHelper11::TextureHelper11(TextureHelper11 &&toCopy)
}
// static
TextureHelper11 TextureHelper11::MakeAndReference(ID3D11Resource *genericResource)
TextureHelper11 TextureHelper11::MakeAndReference(ID3D11Resource *genericResource,
d3d11::ANGLEFormat angleFormat)
{
TextureHelper11 newHelper;
newHelper.mANGLEFormat = angleFormat;
newHelper.mTexture2D = d3d11::DynamicCastComObject<ID3D11Texture2D>(genericResource);
newHelper.mTexture3D = d3d11::DynamicCastComObject<ID3D11Texture3D>(genericResource);
newHelper.mTextureType = newHelper.mTexture2D ? GL_TEXTURE_2D : GL_TEXTURE_3D;
......@@ -1555,9 +1559,11 @@ TextureHelper11 TextureHelper11::MakeAndReference(ID3D11Resource *genericResourc
}
// static
TextureHelper11 TextureHelper11::MakeAndPossess2D(ID3D11Texture2D *texToOwn)
TextureHelper11 TextureHelper11::MakeAndPossess2D(ID3D11Texture2D *texToOwn,
d3d11::ANGLEFormat angleFormat)
{
TextureHelper11 newHelper;
newHelper.mANGLEFormat = angleFormat;
newHelper.mTexture2D = texToOwn;
newHelper.mTextureType = GL_TEXTURE_2D;
newHelper.initDesc();
......@@ -1565,9 +1571,11 @@ TextureHelper11 TextureHelper11::MakeAndPossess2D(ID3D11Texture2D *texToOwn)
}
// static
TextureHelper11 TextureHelper11::MakeAndPossess3D(ID3D11Texture3D *texToOwn)
TextureHelper11 TextureHelper11::MakeAndPossess3D(ID3D11Texture3D *texToOwn,
d3d11::ANGLEFormat angleFormat)
{
TextureHelper11 newHelper;
newHelper.mANGLEFormat = angleFormat;
newHelper.mTexture3D = texToOwn;
newHelper.mTextureType = GL_TEXTURE_3D;
newHelper.initDesc();
......@@ -1600,6 +1608,7 @@ void TextureHelper11::initDesc()
mFormat = desc3D.Format;
mSampleCount = 1;
}
ASSERT(mFormat == d3d11::GetANGLEFormatSet(mANGLEFormat).texFormat);
}
TextureHelper11::~TextureHelper11()
......@@ -1622,6 +1631,7 @@ TextureHelper11 &TextureHelper11::operator=(TextureHelper11 &&texture)
mTextureType = texture.mTextureType;
mExtents = texture.mExtents;
mFormat = texture.mFormat;
mANGLEFormat = texture.mANGLEFormat;
mSampleCount = texture.mSampleCount;
mTexture2D = texture.mTexture2D;
mTexture3D = texture.mTexture3D;
......@@ -1641,6 +1651,7 @@ void TextureHelper11::reset()
gl::ErrorOrResult<TextureHelper11> CreateStagingTexture(GLenum textureType,
DXGI_FORMAT dxgiFormat,
d3d11::ANGLEFormat angleFormat,
const gl::Extents &size,
ID3D11Device *device)
{
......@@ -1667,7 +1678,7 @@ gl::ErrorOrResult<TextureHelper11> CreateStagingTexture(GLenum textureType,
result);
}
return TextureHelper11::MakeAndPossess2D(stagingTex);
return TextureHelper11::MakeAndPossess2D(stagingTex, angleFormat);
}
ASSERT(textureType == GL_TEXTURE_3D);
......@@ -1690,7 +1701,7 @@ gl::ErrorOrResult<TextureHelper11> CreateStagingTexture(GLenum textureType,
result);
}
return TextureHelper11::MakeAndPossess3D(stagingTex);
return TextureHelper11::MakeAndPossess3D(stagingTex, angleFormat);
}
bool UsePresentPathFast(const Renderer11 *renderer,
......
......@@ -17,6 +17,7 @@
#include "libANGLE/angletypes.h"
#include "libANGLE/Caps.h"
#include "libANGLE/Error.h"
#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h"
#include "libANGLE/renderer/d3d/RendererD3D.h"
namespace gl
......@@ -366,13 +367,17 @@ class TextureHelper11 : angle::NonCopyable
~TextureHelper11();
TextureHelper11 &operator=(TextureHelper11 &&texture);
static TextureHelper11 MakeAndReference(ID3D11Resource *genericResource);
static TextureHelper11 MakeAndPossess2D(ID3D11Texture2D *texToOwn);
static TextureHelper11 MakeAndPossess3D(ID3D11Texture3D *texToOwn);
static TextureHelper11 MakeAndReference(ID3D11Resource *genericResource,
d3d11::ANGLEFormat angleFormat);
static TextureHelper11 MakeAndPossess2D(ID3D11Texture2D *texToOwn,
d3d11::ANGLEFormat angleFormat);
static TextureHelper11 MakeAndPossess3D(ID3D11Texture3D *texToOwn,
d3d11::ANGLEFormat angleFormat);
GLenum getTextureType() const { return mTextureType; }
gl::Extents getExtents() const { return mExtents; }
DXGI_FORMAT getFormat() const { return mFormat; }
d3d11::ANGLEFormat getANGLEFormat() const { return mANGLEFormat; }
int getSampleCount() const { return mSampleCount; }
ID3D11Texture2D *getTexture2D() const { return mTexture2D; }
ID3D11Texture3D *getTexture3D() const { return mTexture3D; }
......@@ -385,6 +390,7 @@ class TextureHelper11 : angle::NonCopyable
GLenum mTextureType;
gl::Extents mExtents;
DXGI_FORMAT mFormat;
d3d11::ANGLEFormat mANGLEFormat;
int mSampleCount;
ID3D11Texture2D *mTexture2D;
ID3D11Texture3D *mTexture3D;
......@@ -392,6 +398,7 @@ class TextureHelper11 : angle::NonCopyable
gl::ErrorOrResult<TextureHelper11> CreateStagingTexture(GLenum textureType,
DXGI_FORMAT dxgiFormat,
d3d11::ANGLEFormat angleFormat,
const gl::Extents &size,
ID3D11Device *device);
......
......@@ -12,14 +12,16 @@
#include <map>
#include "common/angleutils.h"
#include "common/platform.h"
#include "libANGLE/renderer/d3d/formatutilsD3D.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
#include "libANGLE/renderer/d3d/d3d11/texture_format_table_autogen.h"
namespace rx
{
struct Renderer11DeviceCaps;
namespace d3d11
{
......@@ -45,7 +47,8 @@ struct ANGLEFormatSet
DXGI_FORMAT rtvFormat,
DXGI_FORMAT dsvFormat,
ANGLEFormat swizzleFormat,
MipGenerationFunction mipGenerationFunction);
MipGenerationFunction mipGenerationFunction,
ColorReadFunction colorReadFunction);
ANGLEFormatSet(const ANGLEFormatSet &) = default;
ANGLEFormatSet &operator=(const ANGLEFormatSet &) = default;
......@@ -63,6 +66,7 @@ struct ANGLEFormatSet
ANGLEFormat swizzleFormat;
MipGenerationFunction mipGenerationFunction;
ColorReadFunction colorReadFunction;
};
struct TextureFormat : public angle::NonCopyable
......
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