Commit 9aa00bbc by Geoff Lang

Simplify formatutils11 by exposing the internal structures.

BUG=angle:658 Change-Id: I8a4ce5f45054a1fa829a9647a94cf2bd0ba93bc0 Reviewed-on: https://chromium-review.googlesource.com/206836Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarNicolas Capens <capn@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 1c28e1f0
...@@ -252,7 +252,6 @@ class Renderer ...@@ -252,7 +252,6 @@ class Renderer
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea) = 0; GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea) = 0;
virtual bool getLUID(LUID *adapterLuid) const = 0; virtual bool getLUID(LUID *adapterLuid) const = 0;
virtual GLenum getNativeTextureFormat(GLenum internalFormat) const = 0;
virtual rx::VertexConversionType getVertexConversionType(const gl::VertexFormat &vertexFormat) const = 0; virtual rx::VertexConversionType getVertexConversionType(const gl::VertexFormat &vertexFormat) const = 0;
virtual GLenum getVertexComponentType(const gl::VertexFormat &vertexFormat) const = 0; virtual GLenum getVertexComponentType(const gl::VertexFormat &vertexFormat) const = 0;
......
...@@ -377,7 +377,9 @@ bool Blit11::swizzleTexture(ID3D11ShaderResourceView *source, ID3D11RenderTarget ...@@ -377,7 +377,9 @@ bool Blit11::swizzleTexture(ID3D11ShaderResourceView *source, ID3D11RenderTarget
D3D11_SHADER_RESOURCE_VIEW_DESC sourceSRVDesc; D3D11_SHADER_RESOURCE_VIEW_DESC sourceSRVDesc;
source->GetDesc(&sourceSRVDesc); source->GetDesc(&sourceSRVDesc);
const gl::InternalFormat &sourceFormatInfo = gl::GetInternalFormatInfo(d3d11_gl::GetInternalFormat(sourceSRVDesc.Format));
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(sourceSRVDesc.Format);
const gl::InternalFormat &sourceFormatInfo = gl::GetInternalFormatInfo(dxgiFormatInfo.internalFormat);
GLenum shaderType = GL_NONE; GLenum shaderType = GL_NONE;
switch (sourceFormatInfo.componentType) switch (sourceFormatInfo.componentType)
...@@ -516,11 +518,13 @@ bool Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &source ...@@ -516,11 +518,13 @@ bool Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &source
// be GL_XXXX_INTEGER but it does not tell us if it is signed or unsigned. // be GL_XXXX_INTEGER but it does not tell us if it is signed or unsigned.
D3D11_SHADER_RESOURCE_VIEW_DESC sourceSRVDesc; D3D11_SHADER_RESOURCE_VIEW_DESC sourceSRVDesc;
source->GetDesc(&sourceSRVDesc); source->GetDesc(&sourceSRVDesc);
GLenum sourceInternalFormat = d3d11_gl::GetInternalFormat(sourceSRVDesc.Format);
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(sourceSRVDesc.Format);
const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(dxgiFormatInfo.internalFormat);
BlitParameters parameters = { 0 }; BlitParameters parameters = { 0 };
parameters.mDestinationFormat = destFormat; parameters.mDestinationFormat = destFormat;
parameters.mSignedInteger = gl::GetInternalFormatInfo(sourceInternalFormat).componentType == GL_INT; parameters.mSignedInteger = (internalFormatInfo.componentType == GL_INT);
parameters.m3DBlit = sourceArea.depth > 1; parameters.m3DBlit = sourceArea.depth > 1;
BlitShaderMap::const_iterator i = mBlitShaderMap.find(parameters); BlitShaderMap::const_iterator i = mBlitShaderMap.find(parameters);
...@@ -766,18 +770,19 @@ bool Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubreso ...@@ -766,18 +770,19 @@ bool Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubreso
DXGI_FORMAT format = GetTextureFormat(source); DXGI_FORMAT format = GetTextureFormat(source);
ASSERT(format == GetTextureFormat(dest)); ASSERT(format == GetTextureFormat(dest));
unsigned int pixelSize = d3d11::GetFormatPixelBytes(format); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(format);
unsigned int pixelSize = dxgiFormatInfo.pixelBytes;
unsigned int copyOffset = 0; unsigned int copyOffset = 0;
unsigned int copySize = pixelSize; unsigned int copySize = pixelSize;
if (stencilOnly) if (stencilOnly)
{ {
copyOffset = d3d11::GetStencilOffset(format) / 8; copyOffset = dxgiFormatInfo.depthBits / 8;
copySize = d3d11::GetStencilBits(format) / 8; copySize = dxgiFormatInfo.stencilBits / 8;
// It would be expensive to have non-byte sized stencil sizes since it would // It would be expensive to have non-byte sized stencil sizes since it would
// require reading from the destination, currently there aren't any though. // require reading from the destination, currently there aren't any though.
ASSERT(d3d11::GetStencilBits(format) % 8 == 0 && ASSERT(dxgiFormatInfo.stencilBits % 8 == 0 &&
d3d11::GetStencilOffset(format) % 8 == 0); dxgiFormatInfo.depthBits % 8 == 0);
} }
D3D11_MAPPED_SUBRESOURCE sourceMapping, destMapping; D3D11_MAPPED_SUBRESOURCE sourceMapping, destMapping;
......
...@@ -437,9 +437,11 @@ ID3D11ShaderResourceView *Buffer11::getSRV(DXGI_FORMAT srvFormat) ...@@ -437,9 +437,11 @@ ID3D11ShaderResourceView *Buffer11::getSRV(DXGI_FORMAT srvFormat)
ID3D11Device *device = mRenderer->getDevice(); ID3D11Device *device = mRenderer->getDevice();
ID3D11ShaderResourceView *bufferSRV = NULL; ID3D11ShaderResourceView *bufferSRV = NULL;
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(srvFormat);
D3D11_SHADER_RESOURCE_VIEW_DESC bufferSRVDesc; D3D11_SHADER_RESOURCE_VIEW_DESC bufferSRVDesc;
bufferSRVDesc.Buffer.ElementOffset = 0; bufferSRVDesc.Buffer.ElementOffset = 0;
bufferSRVDesc.Buffer.ElementWidth = mSize / d3d11::GetFormatPixelBytes(srvFormat); bufferSRVDesc.Buffer.ElementWidth = mSize / dxgiFormatInfo.pixelBytes;
bufferSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; bufferSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
bufferSRVDesc.Format = srvFormat; bufferSRVDesc.Format = srvFormat;
......
...@@ -46,8 +46,8 @@ void Image11::generateMipmap(Image11 *dest, Image11 *src) ...@@ -46,8 +46,8 @@ void Image11::generateMipmap(Image11 *dest, Image11 *src)
ASSERT(src->getWidth() == 1 || src->getWidth() / 2 == dest->getWidth()); ASSERT(src->getWidth() == 1 || src->getWidth() / 2 == dest->getWidth());
ASSERT(src->getHeight() == 1 || src->getHeight() / 2 == dest->getHeight()); ASSERT(src->getHeight() == 1 || src->getHeight() / 2 == dest->getHeight());
MipGenerationFunction mipFunction = d3d11::GetMipGenerationFunction(src->getDXGIFormat()); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(src->getDXGIFormat());
ASSERT(mipFunction != NULL); ASSERT(dxgiFormatInfo.mipGenerationFunction != NULL);
D3D11_MAPPED_SUBRESOURCE destMapped; D3D11_MAPPED_SUBRESOURCE destMapped;
HRESULT destMapResult = dest->map(D3D11_MAP_WRITE, &destMapped); HRESULT destMapResult = dest->map(D3D11_MAP_WRITE, &destMapped);
...@@ -70,8 +70,9 @@ void Image11::generateMipmap(Image11 *dest, Image11 *src) ...@@ -70,8 +70,9 @@ void Image11::generateMipmap(Image11 *dest, Image11 *src)
const uint8_t *sourceData = reinterpret_cast<const uint8_t*>(srcMapped.pData); const uint8_t *sourceData = reinterpret_cast<const uint8_t*>(srcMapped.pData);
uint8_t *destData = reinterpret_cast<uint8_t*>(destMapped.pData); uint8_t *destData = reinterpret_cast<uint8_t*>(destMapped.pData);
mipFunction(src->getWidth(), src->getHeight(), src->getDepth(), sourceData, srcMapped.RowPitch, srcMapped.DepthPitch, dxgiFormatInfo.mipGenerationFunction(src->getWidth(), src->getHeight(), src->getDepth(),
destData, destMapped.RowPitch, destMapped.DepthPitch); sourceData, srcMapped.RowPitch, srcMapped.DepthPitch,
destData, destMapped.RowPitch, destMapped.DepthPitch);
dest->unmap(); dest->unmap();
src->unmap(); src->unmap();
...@@ -83,7 +84,7 @@ bool Image11::isDirty() const ...@@ -83,7 +84,7 @@ bool Image11::isDirty() const
{ {
// Make sure that this image is marked as dirty even if the staging texture hasn't been created yet // Make sure that this image is marked as dirty even if the staging texture hasn't been created yet
// if initialization is required before use. // if initialization is required before use.
return (mDirty && (mStagingTexture || gl_d3d11::RequiresTextureDataInitialization(mInternalFormat))); return (mDirty && (mStagingTexture || d3d11::GetTextureFormatInfo(mInternalFormat).dataInitializerFunction != NULL));
} }
bool Image11::copyToStorage(TextureStorageInterface2D *storage, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height) bool Image11::copyToStorage(TextureStorageInterface2D *storage, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height)
...@@ -126,12 +127,14 @@ bool Image11::redefine(Renderer *renderer, GLenum target, GLenum internalformat, ...@@ -126,12 +127,14 @@ bool Image11::redefine(Renderer *renderer, GLenum target, GLenum internalformat,
mTarget = target; mTarget = target;
// compute the d3d format that will be used // compute the d3d format that will be used
mDXGIFormat = gl_d3d11::GetTexFormat(internalformat); const d3d11::TextureFormat &formatInfo = d3d11::GetTextureFormatInfo(internalformat);
mActualFormat = d3d11_gl::GetInternalFormat(mDXGIFormat); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(formatInfo.texFormat);
mRenderable = gl_d3d11::GetRTVFormat(internalformat) != DXGI_FORMAT_UNKNOWN; mDXGIFormat = formatInfo.texFormat;
mActualFormat = dxgiFormatInfo.internalFormat;
mRenderable = (formatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN);
SafeRelease(mStagingTexture); SafeRelease(mStagingTexture);
mDirty = gl_d3d11::RequiresTextureDataInitialization(mInternalFormat); mDirty = (formatInfo.dataInitializerFunction != NULL);
return true; return true;
} }
...@@ -156,10 +159,12 @@ void Image11::loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei widt ...@@ -156,10 +159,12 @@ void Image11::loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei widt
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(mInternalFormat); const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(mInternalFormat);
GLsizei inputRowPitch = formatInfo.computeRowPitch(type, width, unpackAlignment); GLsizei inputRowPitch = formatInfo.computeRowPitch(type, width, unpackAlignment);
GLsizei inputDepthPitch = formatInfo.computeDepthPitch(type, width, height, unpackAlignment); GLsizei inputDepthPitch = formatInfo.computeDepthPitch(type, width, height, unpackAlignment);
GLuint outputPixelSize = d3d11::GetFormatPixelBytes(mDXGIFormat);
LoadImageFunction loadFunction = d3d11::GetImageLoadFunction(mInternalFormat, type); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(mDXGIFormat);
ASSERT(loadFunction != NULL); GLuint outputPixelSize = dxgiFormatInfo.pixelBytes;
const d3d11::TextureFormat &d3dFormatInfo = d3d11::GetTextureFormatInfo(mInternalFormat);
LoadImageFunction loadFunction = d3dFormatInfo.loadFunctions.at(type);
D3D11_MAPPED_SUBRESOURCE mappedImage; D3D11_MAPPED_SUBRESOURCE mappedImage;
HRESULT result = map(D3D11_MAP_WRITE, &mappedImage); HRESULT result = map(D3D11_MAP_WRITE, &mappedImage);
...@@ -184,15 +189,16 @@ void Image11::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GL ...@@ -184,15 +189,16 @@ void Image11::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GL
GLsizei inputRowPitch = formatInfo.computeRowPitch(GL_UNSIGNED_BYTE, width, 1); GLsizei inputRowPitch = formatInfo.computeRowPitch(GL_UNSIGNED_BYTE, width, 1);
GLsizei inputDepthPitch = formatInfo.computeDepthPitch(GL_UNSIGNED_BYTE, width, height, 1); GLsizei inputDepthPitch = formatInfo.computeDepthPitch(GL_UNSIGNED_BYTE, width, height, 1);
GLuint outputPixelSize = d3d11::GetFormatPixelBytes(mDXGIFormat); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(mDXGIFormat);
GLuint outputBlockWidth = d3d11::GetBlockWidth(mDXGIFormat); GLuint outputPixelSize = dxgiFormatInfo.pixelBytes;
GLuint outputBlockHeight = d3d11::GetBlockHeight(mDXGIFormat); GLuint outputBlockWidth = dxgiFormatInfo.blockWidth;
GLuint outputBlockHeight = dxgiFormatInfo.blockHeight;
ASSERT(xoffset % outputBlockWidth == 0); ASSERT(xoffset % outputBlockWidth == 0);
ASSERT(yoffset % outputBlockHeight == 0); ASSERT(yoffset % outputBlockHeight == 0);
LoadImageFunction loadFunction = d3d11::GetImageLoadFunction(mInternalFormat, GL_UNSIGNED_BYTE); const d3d11::TextureFormat &d3dFormatInfo = d3d11::GetTextureFormatInfo(mInternalFormat);
ASSERT(loadFunction != NULL); LoadImageFunction loadFunction = d3dFormatInfo.loadFunctions.at(GL_UNSIGNED_BYTE);
D3D11_MAPPED_SUBRESOURCE mappedImage; D3D11_MAPPED_SUBRESOURCE mappedImage;
HRESULT result = map(D3D11_MAP_WRITE, &mappedImage); HRESULT result = map(D3D11_MAP_WRITE, &mappedImage);
...@@ -350,7 +356,7 @@ void Image11::createStagingTexture() ...@@ -350,7 +356,7 @@ void Image11::createStagingTexture()
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
desc.MiscFlags = 0; desc.MiscFlags = 0;
if (gl_d3d11::RequiresTextureDataInitialization(mInternalFormat)) if (d3d11::GetTextureFormatInfo(mInternalFormat).dataInitializerFunction != NULL)
{ {
std::vector<D3D11_SUBRESOURCE_DATA> initialData; std::vector<D3D11_SUBRESOURCE_DATA> initialData;
std::vector< std::vector<BYTE> > textureData; std::vector< std::vector<BYTE> > textureData;
...@@ -391,7 +397,7 @@ void Image11::createStagingTexture() ...@@ -391,7 +397,7 @@ void Image11::createStagingTexture()
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
desc.MiscFlags = 0; desc.MiscFlags = 0;
if (gl_d3d11::RequiresTextureDataInitialization(mInternalFormat)) if (d3d11::GetTextureFormatInfo(mInternalFormat).dataInitializerFunction != NULL)
{ {
std::vector<D3D11_SUBRESOURCE_DATA> initialData; std::vector<D3D11_SUBRESOURCE_DATA> initialData;
std::vector< std::vector<BYTE> > textureData; std::vector< std::vector<BYTE> > textureData;
......
...@@ -109,7 +109,7 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M ...@@ -109,7 +109,7 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M
D3D11_INPUT_CLASSIFICATION inputClass = attributes[i].divisor > 0 ? D3D11_INPUT_PER_INSTANCE_DATA : D3D11_INPUT_PER_VERTEX_DATA; D3D11_INPUT_CLASSIFICATION inputClass = attributes[i].divisor > 0 ? D3D11_INPUT_PER_INSTANCE_DATA : D3D11_INPUT_PER_VERTEX_DATA;
gl::VertexFormat vertexFormat(*attributes[i].attribute, attributes[i].currentValueType); gl::VertexFormat vertexFormat(*attributes[i].attribute, attributes[i].currentValueType);
DXGI_FORMAT dxgiFormat = gl_d3d11::GetNativeVertexFormat(vertexFormat); const d3d11::VertexFormat &vertexFormatInfo = d3d11::GetVertexFormatInfo(vertexFormat);
// Record the type of the associated vertex shader vector in our key // Record the type of the associated vertex shader vector in our key
// This will prevent mismatched vertex shaders from using the same input layout // This will prevent mismatched vertex shaders from using the same input layout
...@@ -118,7 +118,7 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M ...@@ -118,7 +118,7 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M
ilKey.elements[ilKey.elementCount].desc.SemanticName = semanticName; ilKey.elements[ilKey.elementCount].desc.SemanticName = semanticName;
ilKey.elements[ilKey.elementCount].desc.SemanticIndex = sortedSemanticIndices[i]; ilKey.elements[ilKey.elementCount].desc.SemanticIndex = sortedSemanticIndices[i];
ilKey.elements[ilKey.elementCount].desc.Format = dxgiFormat; ilKey.elements[ilKey.elementCount].desc.Format = vertexFormatInfo.nativeFormat;
ilKey.elements[ilKey.elementCount].desc.InputSlot = i; ilKey.elements[ilKey.elementCount].desc.InputSlot = i;
ilKey.elements[ilKey.elementCount].desc.AlignedByteOffset = 0; ilKey.elements[ilKey.elementCount].desc.AlignedByteOffset = 0;
ilKey.elements[ilKey.elementCount].desc.InputSlotClass = inputClass; ilKey.elements[ilKey.elementCount].desc.InputSlotClass = inputClass;
......
...@@ -160,7 +160,8 @@ bool PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpack, un ...@@ -160,7 +160,8 @@ bool PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpack, un
GLenum unsizedFormat = gl::GetInternalFormatInfo(destinationFormat).format; GLenum unsizedFormat = gl::GetInternalFormatInfo(destinationFormat).format;
GLenum sourceFormat = gl::GetFormatTypeInfo(unsizedFormat, sourcePixelsType).internalFormat; GLenum sourceFormat = gl::GetFormatTypeInfo(unsizedFormat, sourcePixelsType).internalFormat;
DXGI_FORMAT srvFormat = gl_d3d11::GetSRVFormat(sourceFormat); const d3d11::TextureFormat &sourceFormatInfo = d3d11::GetTextureFormatInfo(sourceFormat);
DXGI_FORMAT srvFormat = sourceFormatInfo.srvFormat;
ASSERT(srvFormat != DXGI_FORMAT_UNKNOWN); ASSERT(srvFormat != DXGI_FORMAT_UNKNOWN);
Buffer11 *bufferStorage11 = Buffer11::makeBuffer11(sourceBuffer.getImplementation()); Buffer11 *bufferStorage11 = Buffer11::makeBuffer11(sourceBuffer.getImplementation());
ID3D11ShaderResourceView *bufferSRV = bufferStorage11->getSRV(srvFormat); ID3D11ShaderResourceView *bufferSRV = bufferStorage11->getSRV(srvFormat);
......
...@@ -219,8 +219,9 @@ RenderTarget11::RenderTarget11(Renderer *renderer, ID3D11RenderTargetView *rtv, ...@@ -219,8 +219,9 @@ RenderTarget11::RenderTarget11(Renderer *renderer, ID3D11RenderTargetView *rtv,
mDepth = depth; mDepth = depth;
mSamples = samples; mSamples = samples;
mInternalFormat = d3d11_gl::GetInternalFormat(desc.Format); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(desc.Format);
mActualFormat = d3d11_gl::GetInternalFormat(desc.Format); mInternalFormat = dxgiFormatInfo.internalFormat;
mActualFormat = dxgiFormatInfo.internalFormat;
} }
} }
...@@ -265,8 +266,9 @@ RenderTarget11::RenderTarget11(Renderer *renderer, ID3D11DepthStencilView *dsv, ...@@ -265,8 +266,9 @@ RenderTarget11::RenderTarget11(Renderer *renderer, ID3D11DepthStencilView *dsv,
mDepth = depth; mDepth = depth;
mSamples = samples; mSamples = samples;
mInternalFormat = d3d11_gl::GetInternalFormat(desc.Format); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(desc.Format);
mActualFormat = d3d11_gl::GetInternalFormat(desc.Format); mInternalFormat = dxgiFormatInfo.internalFormat;
mActualFormat = dxgiFormatInfo.internalFormat;
} }
} }
...@@ -278,10 +280,8 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height ...@@ -278,10 +280,8 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height
mDepthStencil = NULL; mDepthStencil = NULL;
mShaderResource = NULL; mShaderResource = NULL;
DXGI_FORMAT texFormat = gl_d3d11::GetTexFormat(internalFormat); const d3d11::TextureFormat &formatInfo = d3d11::GetTextureFormatInfo(internalFormat);
DXGI_FORMAT srvFormat = gl_d3d11::GetSRVFormat(internalFormat); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(formatInfo.texFormat);
DXGI_FORMAT rtvFormat = gl_d3d11::GetRTVFormat(internalFormat);
DXGI_FORMAT dsvFormat = gl_d3d11::GetDSVFormat(internalFormat);
const gl::TextureCaps &textureCaps = mRenderer->getRendererTextureCaps().get(internalFormat); const gl::TextureCaps &textureCaps = mRenderer->getRendererTextureCaps().get(internalFormat);
GLuint supportedSamples = textureCaps.getNearestSamples(samples); GLuint supportedSamples = textureCaps.getNearestSamples(samples);
...@@ -294,7 +294,7 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height ...@@ -294,7 +294,7 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height
desc.Height = height; desc.Height = height;
desc.MipLevels = 1; desc.MipLevels = 1;
desc.ArraySize = 1; desc.ArraySize = 1;
desc.Format = texFormat; desc.Format = formatInfo.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;
...@@ -305,14 +305,14 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height ...@@ -305,14 +305,14 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height
// 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 = (rtvFormat != DXGI_FORMAT_UNKNOWN); bindRTV = (formatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN);
bindDSV = (dsvFormat != DXGI_FORMAT_UNKNOWN); bindDSV = (formatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN);
if (srvFormat != DXGI_FORMAT_UNKNOWN) if (formatInfo.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 = !(dsvFormat != DXGI_FORMAT_UNKNOWN && desc.SampleDesc.Count > 1); bindSRV = !(formatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN && desc.SampleDesc.Count > 1);
} }
desc.BindFlags = (bindRTV ? D3D11_BIND_RENDER_TARGET : 0) | desc.BindFlags = (bindRTV ? D3D11_BIND_RENDER_TARGET : 0) |
...@@ -334,7 +334,7 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height ...@@ -334,7 +334,7 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height
if (bindSRV) if (bindSRV)
{ {
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = srvFormat; srvDesc.Format = formatInfo.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;
...@@ -352,7 +352,7 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height ...@@ -352,7 +352,7 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height
if (bindDSV) if (bindDSV)
{ {
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
dsvDesc.Format = dsvFormat; dsvDesc.Format = formatInfo.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;
...@@ -371,7 +371,7 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height ...@@ -371,7 +371,7 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height
if (bindRTV) if (bindRTV)
{ {
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
rtvDesc.Format = rtvFormat; rtvDesc.Format = formatInfo.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;
result = device->CreateRenderTargetView(mTexture, &rtvDesc, &mRenderTarget); result = device->CreateRenderTargetView(mTexture, &rtvDesc, &mRenderTarget);
...@@ -386,7 +386,7 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height ...@@ -386,7 +386,7 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height
} }
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
if (gl_d3d11::RequiresTextureDataInitialization(internalFormat)) if (formatInfo.dataInitializerFunction != NULL)
{ {
ID3D11DeviceContext *context = mRenderer->getDeviceContext(); ID3D11DeviceContext *context = mRenderer->getDeviceContext();
...@@ -396,12 +396,13 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height ...@@ -396,12 +396,13 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height
} }
} }
mWidth = width; mWidth = width;
mHeight = height; mHeight = height;
mDepth = 1; mDepth = 1;
mInternalFormat = internalFormat; mInternalFormat = internalFormat;
mSamples = supportedSamples; mSamples = supportedSamples;
mActualFormat = d3d11_gl::GetInternalFormat(texFormat); mActualFormat = dxgiFormatInfo.internalFormat;
mSubresourceIndex = D3D11CalcSubresource(0, 0, 1); mSubresourceIndex = D3D11CalcSubresource(0, 0, 1);
} }
......
...@@ -319,31 +319,19 @@ int Renderer11::generateConfigs(ConfigDesc **configDescList) ...@@ -319,31 +319,19 @@ int Renderer11::generateConfigs(ConfigDesc **configDescList)
for (unsigned int formatIndex = 0; formatIndex < numRenderFormats; formatIndex++) for (unsigned int formatIndex = 0; formatIndex < numRenderFormats; formatIndex++)
{ {
for (unsigned int depthStencilIndex = 0; depthStencilIndex < numDepthFormats; depthStencilIndex++) const d3d11::DXGIFormat &renderTargetFormatInfo = d3d11::GetDXGIFormatInfo(RenderTargetFormats[formatIndex]);
const gl::TextureCaps &renderTargetFormatCaps = getRendererTextureCaps().get(renderTargetFormatInfo.internalFormat);
if (renderTargetFormatCaps.renderable)
{ {
DXGI_FORMAT renderTargetFormat = RenderTargetFormats[formatIndex]; for (unsigned int depthStencilIndex = 0; depthStencilIndex < numDepthFormats; depthStencilIndex++)
UINT formatSupport = 0;
HRESULT result = mDevice->CheckFormatSupport(renderTargetFormat, &formatSupport);
if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET))
{ {
DXGI_FORMAT depthStencilFormat = DepthStencilFormats[depthStencilIndex]; const d3d11::DXGIFormat &depthStencilFormatInfo = d3d11::GetDXGIFormatInfo(DepthStencilFormats[depthStencilIndex]);
const gl::TextureCaps &depthStencilFormatCaps = getRendererTextureCaps().get(depthStencilFormatInfo.internalFormat);
bool depthStencilFormatOK = true; if (depthStencilFormatCaps.renderable || DepthStencilFormats[depthStencilIndex] == DXGI_FORMAT_UNKNOWN)
if (depthStencilFormat != DXGI_FORMAT_UNKNOWN)
{
UINT depthStencilSupport = 0;
result = mDevice->CheckFormatSupport(depthStencilFormat, &depthStencilSupport);
depthStencilFormatOK = SUCCEEDED(result) && (depthStencilSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL);
}
if (depthStencilFormatOK)
{ {
ConfigDesc newConfig; ConfigDesc newConfig;
newConfig.renderTargetFormat = d3d11_gl::GetInternalFormat(renderTargetFormat); newConfig.renderTargetFormat = renderTargetFormatInfo.internalFormat;
newConfig.depthStencilFormat = d3d11_gl::GetInternalFormat(depthStencilFormat); newConfig.depthStencilFormat = depthStencilFormatInfo.internalFormat;
newConfig.multiSample = 0; // FIXME: enumerate multi-sampling newConfig.multiSample = 0; // FIXME: enumerate multi-sampling
newConfig.fastConfig = true; // Assume all DX11 format conversions to be fast newConfig.fastConfig = true; // Assume all DX11 format conversions to be fast
newConfig.es3Capable = true; newConfig.es3Capable = true;
...@@ -2602,28 +2590,30 @@ bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const ...@@ -2602,28 +2590,30 @@ bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const
{ {
ASSERT(getRendererExtensions().pixelBufferObject); ASSERT(getRendererExtensions().pixelBufferObject);
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat); const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(internalFormat);
const d3d11::TextureFormat &d3d11FormatInfo = d3d11::GetTextureFormatInfo(internalFormat);
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(d3d11FormatInfo.texFormat);
// sRGB formats do not work with D3D11 buffer SRVs // sRGB formats do not work with D3D11 buffer SRVs
if (formatInfo.colorEncoding == GL_SRGB) if (internalFormatInfo.colorEncoding == GL_SRGB)
{ {
return false; return false;
} }
// We cannot support direct copies to non-color-renderable formats // We cannot support direct copies to non-color-renderable formats
if (gl_d3d11::GetRTVFormat(internalFormat) != DXGI_FORMAT_UNKNOWN) if (d3d11FormatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN)
{ {
return false; return false;
} }
// We skip all 3-channel formats since sometimes format support is missing // We skip all 3-channel formats since sometimes format support is missing
if (formatInfo.componentCount == 3) if (internalFormatInfo.componentCount == 3)
{ {
return false; return false;
} }
// We don't support formats which we can't represent without conversion // We don't support formats which we can't represent without conversion
if (getNativeTextureFormat(internalFormat) != internalFormat) if (dxgiFormatInfo.internalFormat != internalFormat)
{ {
return false; return false;
} }
...@@ -2957,7 +2947,8 @@ void Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams ...@@ -2957,7 +2947,8 @@ void Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams
inputPitch = static_cast<int>(mapping.RowPitch); inputPitch = static_cast<int>(mapping.RowPitch);
} }
const gl::InternalFormat &sourceFormatInfo = gl::GetInternalFormatInfo(d3d11_gl::GetInternalFormat(textureDesc.Format)); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(textureDesc.Format);
const gl::InternalFormat &sourceFormatInfo = gl::GetInternalFormatInfo(dxgiFormatInfo.internalFormat);
if (sourceFormatInfo.format == params.format && sourceFormatInfo.type == params.type) if (sourceFormatInfo.format == params.format && sourceFormatInfo.type == params.type)
{ {
unsigned char *dest = static_cast<unsigned char*>(pixelsOut) + params.offset; unsigned char *dest = static_cast<unsigned char*>(pixelsOut) + params.offset;
...@@ -2968,9 +2959,12 @@ void Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams ...@@ -2968,9 +2959,12 @@ void Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams
} }
else else
{ {
const d3d11::DXGIFormat &sourceDXGIFormatInfo = d3d11::GetDXGIFormatInfo(textureDesc.Format);
ColorCopyFunction fastCopyFunc = sourceDXGIFormatInfo.getFastCopyFunction(params.format, params.type);
const gl::FormatType &destFormatTypeInfo = gl::GetFormatTypeInfo(params.format, params.type); const gl::FormatType &destFormatTypeInfo = gl::GetFormatTypeInfo(params.format, params.type);
const gl::InternalFormat &destFormatInfo = gl::GetInternalFormatInfo(destFormatTypeInfo.internalFormat); const gl::InternalFormat &destFormatInfo = gl::GetInternalFormatInfo(destFormatTypeInfo.internalFormat);
ColorCopyFunction fastCopyFunc = d3d11::GetFastCopyFunction(textureDesc.Format, params.format, params.type);
if (fastCopyFunc) if (fastCopyFunc)
{ {
// Fast copy is possible through some special function // Fast copy is possible through some special function
...@@ -2987,8 +2981,6 @@ void Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams ...@@ -2987,8 +2981,6 @@ void Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams
} }
else else
{ {
ColorReadFunction readFunc = d3d11::GetColorReadFunction(textureDesc.Format);
unsigned char temp[16]; // Maximum size of any Color<T> type used. unsigned char temp[16]; // Maximum size of any Color<T> type used.
META_ASSERT(sizeof(temp) >= sizeof(gl::ColorF) && META_ASSERT(sizeof(temp) >= sizeof(gl::ColorF) &&
sizeof(temp) >= sizeof(gl::ColorUI) && sizeof(temp) >= sizeof(gl::ColorUI) &&
...@@ -3003,7 +2995,7 @@ void Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams ...@@ -3003,7 +2995,7 @@ void Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams
// readFunc and writeFunc will be using the same type of color, CopyTexImage // readFunc and writeFunc will be using the same type of color, CopyTexImage
// will not allow the copy otherwise. // will not allow the copy otherwise.
readFunc(src, temp); sourceDXGIFormatInfo.colorReadFunction(src, temp);
destFormatTypeInfo.colorWriteFunction(temp, dest); destFormatTypeInfo.colorWriteFunction(temp, dest);
} }
} }
...@@ -3289,19 +3281,14 @@ bool Renderer11::getLUID(LUID *adapterLuid) const ...@@ -3289,19 +3281,14 @@ bool Renderer11::getLUID(LUID *adapterLuid) const
return true; return true;
} }
GLenum Renderer11::getNativeTextureFormat(GLenum internalFormat) const
{
return d3d11_gl::GetInternalFormat(gl_d3d11::GetTexFormat(internalFormat));
}
rx::VertexConversionType Renderer11::getVertexConversionType(const gl::VertexFormat &vertexFormat) const rx::VertexConversionType Renderer11::getVertexConversionType(const gl::VertexFormat &vertexFormat) const
{ {
return gl_d3d11::GetVertexConversionType(vertexFormat); return d3d11::GetVertexFormatInfo(vertexFormat).conversionType;
} }
GLenum Renderer11::getVertexComponentType(const gl::VertexFormat &vertexFormat) const GLenum Renderer11::getVertexComponentType(const gl::VertexFormat &vertexFormat) const
{ {
return d3d11::GetComponentType(gl_d3d11::GetNativeVertexFormat(vertexFormat)); return d3d11::GetDXGIFormatInfo(d3d11::GetVertexFormatInfo(vertexFormat).nativeFormat).componentType;
} }
void Renderer11::generateCaps(gl::Caps *outCaps, gl::TextureCapsMap *outTextureCaps, gl::Extensions *outExtensions) const void Renderer11::generateCaps(gl::Caps *outCaps, gl::TextureCapsMap *outTextureCaps, gl::Extensions *outExtensions) const
......
...@@ -207,7 +207,6 @@ class Renderer11 : public Renderer ...@@ -207,7 +207,6 @@ class Renderer11 : public Renderer
void packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams &params, void *pixelsOut); void packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams &params, void *pixelsOut);
virtual bool getLUID(LUID *adapterLuid) const; virtual bool getLUID(LUID *adapterLuid) const;
virtual GLenum getNativeTextureFormat(GLenum internalFormat) const;
virtual rx::VertexConversionType getVertexConversionType(const gl::VertexFormat &vertexFormat) const; virtual rx::VertexConversionType getVertexConversionType(const gl::VertexFormat &vertexFormat) const;
virtual GLenum getVertexComponentType(const gl::VertexFormat &vertexFormat) const; virtual GLenum getVertexComponentType(const gl::VertexFormat &vertexFormat) const;
......
...@@ -102,6 +102,8 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei ...@@ -102,6 +102,8 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei
releaseOffscreenTexture(); releaseOffscreenTexture();
const d3d11::TextureFormat &backbufferFormatInfo = d3d11::GetTextureFormatInfo(mBackBufferFormat);
// If the app passed in a share handle, open the resource // If the app passed in a share handle, open the resource
// See EGL_ANGLE_d3d_share_handle_client_buffer // See EGL_ANGLE_d3d_share_handle_client_buffer
if (mAppCreatedShareHandle) if (mAppCreatedShareHandle)
...@@ -130,11 +132,11 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei ...@@ -130,11 +132,11 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei
D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0}; D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0};
mOffscreenTexture->GetDesc(&offscreenTextureDesc); mOffscreenTexture->GetDesc(&offscreenTextureDesc);
if (offscreenTextureDesc.Width != (UINT)backbufferWidth if (offscreenTextureDesc.Width != (UINT)backbufferWidth ||
|| offscreenTextureDesc.Height != (UINT)backbufferHeight offscreenTextureDesc.Height != (UINT)backbufferHeight ||
|| offscreenTextureDesc.Format != gl_d3d11::GetTexFormat(mBackBufferFormat) offscreenTextureDesc.Format != backbufferFormatInfo.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();
...@@ -148,7 +150,7 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei ...@@ -148,7 +150,7 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei
D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0}; D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0};
offscreenTextureDesc.Width = backbufferWidth; offscreenTextureDesc.Width = backbufferWidth;
offscreenTextureDesc.Height = backbufferHeight; offscreenTextureDesc.Height = backbufferHeight;
offscreenTextureDesc.Format = gl_d3d11::GetTexFormat(mBackBufferFormat); offscreenTextureDesc.Format = backbufferFormatInfo.texFormat;
offscreenTextureDesc.MipLevels = 1; offscreenTextureDesc.MipLevels = 1;
offscreenTextureDesc.ArraySize = 1; offscreenTextureDesc.ArraySize = 1;
offscreenTextureDesc.SampleDesc.Count = 1; offscreenTextureDesc.SampleDesc.Count = 1;
...@@ -204,7 +206,7 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei ...@@ -204,7 +206,7 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei
D3D11_RENDER_TARGET_VIEW_DESC offscreenRTVDesc; D3D11_RENDER_TARGET_VIEW_DESC offscreenRTVDesc;
offscreenRTVDesc.Format = gl_d3d11::GetRTVFormat(mBackBufferFormat); offscreenRTVDesc.Format = backbufferFormatInfo.rtvFormat;
offscreenRTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; offscreenRTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
offscreenRTVDesc.Texture2D.MipSlice = 0; offscreenRTVDesc.Texture2D.MipSlice = 0;
...@@ -213,7 +215,7 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei ...@@ -213,7 +215,7 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei
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 = gl_d3d11::GetSRVFormat(mBackBufferFormat); offscreenSRVDesc.Format = backbufferFormatInfo.srvFormat;
offscreenSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; offscreenSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
offscreenSRVDesc.Texture2D.MostDetailedMip = 0; offscreenSRVDesc.Texture2D.MostDetailedMip = 0;
offscreenSRVDesc.Texture2D.MipLevels = -1; offscreenSRVDesc.Texture2D.MipLevels = -1;
...@@ -222,12 +224,14 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei ...@@ -222,12 +224,14 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mOffscreenSRView, "Offscreen back buffer shader resource"); d3d11::SetDebugName(mOffscreenSRView, "Offscreen back buffer shader resource");
const d3d11::TextureFormat &depthBufferFormatInfo = d3d11::GetTextureFormatInfo(mDepthBufferFormat);
if (mDepthBufferFormat != GL_NONE) if (mDepthBufferFormat != GL_NONE)
{ {
D3D11_TEXTURE2D_DESC depthStencilTextureDesc; D3D11_TEXTURE2D_DESC depthStencilTextureDesc;
depthStencilTextureDesc.Width = backbufferWidth; depthStencilTextureDesc.Width = backbufferWidth;
depthStencilTextureDesc.Height = backbufferHeight; depthStencilTextureDesc.Height = backbufferHeight;
depthStencilTextureDesc.Format = gl_d3d11::GetTexFormat(mDepthBufferFormat); depthStencilTextureDesc.Format = depthBufferFormatInfo.texFormat;
depthStencilTextureDesc.MipLevels = 1; depthStencilTextureDesc.MipLevels = 1;
depthStencilTextureDesc.ArraySize = 1; depthStencilTextureDesc.ArraySize = 1;
depthStencilTextureDesc.SampleDesc.Count = 1; depthStencilTextureDesc.SampleDesc.Count = 1;
...@@ -255,7 +259,7 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei ...@@ -255,7 +259,7 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei
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 = gl_d3d11::GetDSVFormat(mDepthBufferFormat); depthStencilDesc.Format = depthBufferFormatInfo.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;
...@@ -265,7 +269,7 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei ...@@ -265,7 +269,7 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei
d3d11::SetDebugName(mDepthStencilDSView, "Offscreen depth stencil view"); d3d11::SetDebugName(mDepthStencilDSView, "Offscreen depth stencil view");
D3D11_SHADER_RESOURCE_VIEW_DESC depthStencilSRVDesc; D3D11_SHADER_RESOURCE_VIEW_DESC depthStencilSRVDesc;
depthStencilSRVDesc.Format = gl_d3d11::GetSRVFormat(mDepthBufferFormat); depthStencilSRVDesc.Format = depthBufferFormatInfo.srvFormat;
depthStencilSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; depthStencilSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
depthStencilSRVDesc.Texture2D.MostDetailedMip = 0; depthStencilSRVDesc.Texture2D.MostDetailedMip = 0;
depthStencilSRVDesc.Texture2D.MipLevels = -1; depthStencilSRVDesc.Texture2D.MipLevels = -1;
...@@ -325,8 +329,8 @@ EGLint SwapChain11::resize(EGLint backbufferWidth, EGLint backbufferHeight) ...@@ -325,8 +329,8 @@ EGLint SwapChain11::resize(EGLint backbufferWidth, EGLint backbufferHeight)
SafeRelease(mBackBufferRTView); SafeRelease(mBackBufferRTView);
// Resize swap chain // Resize swap chain
DXGI_FORMAT backbufferDXGIFormat = gl_d3d11::GetTexFormat(mBackBufferFormat); const d3d11::TextureFormat &backbufferFormatInfo = d3d11::GetTextureFormatInfo(mBackBufferFormat);
HRESULT result = mSwapChain->ResizeBuffers(1, backbufferWidth, backbufferHeight, backbufferDXGIFormat, 0); HRESULT result = mSwapChain->ResizeBuffers(1, backbufferWidth, backbufferHeight, backbufferFormatInfo.texFormat, 0);
if (FAILED(result)) if (FAILED(result))
{ {
...@@ -391,6 +395,8 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap ...@@ -391,6 +395,8 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap
if (mWindow) if (mWindow)
{ {
const d3d11::TextureFormat &backbufferFormatInfo = d3d11::GetTextureFormatInfo(mBackBufferFormat);
IDXGIFactory *factory = mRenderer->getDxgiFactory(); IDXGIFactory *factory = mRenderer->getDxgiFactory();
DXGI_SWAP_CHAIN_DESC swapChainDesc = {0}; DXGI_SWAP_CHAIN_DESC swapChainDesc = {0};
...@@ -398,7 +404,7 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap ...@@ -398,7 +404,7 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap
swapChainDesc.BufferDesc.Height = backbufferHeight; swapChainDesc.BufferDesc.Height = backbufferHeight;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0; swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1; swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferDesc.Format = gl_d3d11::GetTexFormat(mBackBufferFormat); swapChainDesc.BufferDesc.Format = backbufferFormatInfo.texFormat;
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Count = 1;
......
...@@ -126,15 +126,16 @@ DWORD TextureStorage11::GetTextureBindFlags(GLenum internalFormat, bool renderTa ...@@ -126,15 +126,16 @@ DWORD TextureStorage11::GetTextureBindFlags(GLenum internalFormat, bool renderTa
{ {
UINT bindFlags = 0; UINT bindFlags = 0;
if (gl_d3d11::GetSRVFormat(internalFormat) != DXGI_FORMAT_UNKNOWN) const d3d11::TextureFormat &formatInfo = d3d11::GetTextureFormatInfo(internalFormat);
if (formatInfo.srvFormat != DXGI_FORMAT_UNKNOWN)
{ {
bindFlags |= D3D11_BIND_SHADER_RESOURCE; bindFlags |= D3D11_BIND_SHADER_RESOURCE;
} }
if (gl_d3d11::GetDSVFormat(internalFormat) != DXGI_FORMAT_UNKNOWN) if (formatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN)
{ {
bindFlags |= D3D11_BIND_DEPTH_STENCIL; bindFlags |= D3D11_BIND_DEPTH_STENCIL;
} }
if (gl_d3d11::GetRTVFormat(internalFormat) != DXGI_FORMAT_UNKNOWN && renderTarget) if (formatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN && renderTarget)
{ {
bindFlags |= D3D11_BIND_RENDER_TARGET; bindFlags |= D3D11_BIND_RENDER_TARGET;
} }
...@@ -308,7 +309,8 @@ bool TextureStorage11::updateSubresourceLevel(ID3D11Resource *srcTexture, unsign ...@@ -308,7 +309,8 @@ bool TextureStorage11::updateSubresourceLevel(ID3D11Resource *srcTexture, unsign
ASSERT(dstTexture); ASSERT(dstTexture);
if (!fullCopy && (d3d11::GetDepthBits(mTextureFormat) > 0 || d3d11::GetStencilBits(mTextureFormat) > 0)) const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(mTextureFormat);
if (!fullCopy && (dxgiFormatInfo.depthBits > 0 || dxgiFormatInfo.stencilBits > 0))
{ {
// CopySubresourceRegion cannot copy partial depth stencils, use the blitter instead // CopySubresourceRegion cannot copy partial depth stencils, use the blitter instead
Blit11 *blitter = mRenderer->getBlitter(); Blit11 *blitter = mRenderer->getBlitter();
...@@ -319,11 +321,13 @@ bool TextureStorage11::updateSubresourceLevel(ID3D11Resource *srcTexture, unsign ...@@ -319,11 +321,13 @@ bool TextureStorage11::updateSubresourceLevel(ID3D11Resource *srcTexture, unsign
} }
else else
{ {
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(mTextureFormat);
D3D11_BOX srcBox; D3D11_BOX srcBox;
srcBox.left = copyArea.x; srcBox.left = copyArea.x;
srcBox.top = copyArea.y; srcBox.top = copyArea.y;
srcBox.right = copyArea.x + roundUp((unsigned int)width, d3d11::GetBlockWidth(mTextureFormat)); srcBox.right = copyArea.x + roundUp((unsigned int)width, dxgiFormatInfo.blockWidth);
srcBox.bottom = copyArea.y + roundUp((unsigned int)height, d3d11::GetBlockHeight(mTextureFormat)); srcBox.bottom = copyArea.y + roundUp((unsigned int)height, dxgiFormatInfo.blockHeight);
srcBox.front = copyArea.z; srcBox.front = copyArea.z;
srcBox.back = copyArea.z + copyArea.depth; srcBox.back = copyArea.z + copyArea.depth;
...@@ -401,10 +405,11 @@ TextureStorage11_2D::TextureStorage11_2D(Renderer *renderer, SwapChain11 *swapch ...@@ -401,10 +405,11 @@ TextureStorage11_2D::TextureStorage11_2D(Renderer *renderer, SwapChain11 *swapch
offscreenRTV->GetDesc(&rtvDesc); offscreenRTV->GetDesc(&rtvDesc);
mRenderTargetFormat = rtvDesc.Format; mRenderTargetFormat = rtvDesc.Format;
GLenum internalFormat = d3d11_gl::GetInternalFormat(mTextureFormat); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(mTextureFormat);
mSwizzleTextureFormat = gl_d3d11::GetSwizzleTexFormat(internalFormat); const d3d11::TextureFormat &formatInfo = d3d11::GetTextureFormatInfo(dxgiFormatInfo.internalFormat);
mSwizzleShaderResourceFormat = gl_d3d11::GetSwizzleSRVFormat(internalFormat); mSwizzleTextureFormat = formatInfo.swizzleTexFormat;
mSwizzleRenderTargetFormat = gl_d3d11::GetSwizzleRTVFormat(internalFormat); mSwizzleShaderResourceFormat = formatInfo.swizzleSRVFormat;
mSwizzleRenderTargetFormat = formatInfo.swizzleRTVFormat;
mDepthStencilFormat = DXGI_FORMAT_UNKNOWN; mDepthStencilFormat = DXGI_FORMAT_UNKNOWN;
} }
...@@ -421,13 +426,14 @@ TextureStorage11_2D::TextureStorage11_2D(Renderer *renderer, GLenum internalform ...@@ -421,13 +426,14 @@ TextureStorage11_2D::TextureStorage11_2D(Renderer *renderer, GLenum internalform
mSwizzleRenderTargets[i] = NULL; mSwizzleRenderTargets[i] = NULL;
} }
mTextureFormat = gl_d3d11::GetTexFormat(internalformat); const d3d11::TextureFormat &formatInfo = d3d11::GetTextureFormatInfo(internalformat);
mShaderResourceFormat = gl_d3d11::GetSRVFormat(internalformat); mTextureFormat = formatInfo.texFormat;
mDepthStencilFormat = gl_d3d11::GetDSVFormat(internalformat); mShaderResourceFormat = formatInfo.srvFormat;
mRenderTargetFormat = gl_d3d11::GetRTVFormat(internalformat); mDepthStencilFormat = formatInfo.dsvFormat;
mSwizzleTextureFormat = gl_d3d11::GetSwizzleTexFormat(internalformat); mRenderTargetFormat = formatInfo.rtvFormat;
mSwizzleShaderResourceFormat = gl_d3d11::GetSwizzleSRVFormat(internalformat); mSwizzleTextureFormat = formatInfo.swizzleTexFormat;
mSwizzleRenderTargetFormat = gl_d3d11::GetSwizzleRTVFormat(internalformat); mSwizzleShaderResourceFormat = formatInfo.swizzleSRVFormat;
mSwizzleRenderTargetFormat = formatInfo.swizzleRTVFormat;
// if the width or height is not positive this should be treated as an incomplete texture // if the width or height is not positive this should be treated as an incomplete texture
// we handle that here by skipping the d3d texture creation // we handle that here by skipping the d3d texture creation
...@@ -691,13 +697,14 @@ TextureStorage11_Cube::TextureStorage11_Cube(Renderer *renderer, GLenum internal ...@@ -691,13 +697,14 @@ TextureStorage11_Cube::TextureStorage11_Cube(Renderer *renderer, GLenum internal
} }
} }
mTextureFormat = gl_d3d11::GetTexFormat(internalformat); const d3d11::TextureFormat &formatInfo = d3d11::GetTextureFormatInfo(internalformat);
mShaderResourceFormat = gl_d3d11::GetSRVFormat(internalformat); mTextureFormat = formatInfo.texFormat;
mDepthStencilFormat = gl_d3d11::GetDSVFormat(internalformat); mShaderResourceFormat = formatInfo.srvFormat;
mRenderTargetFormat = gl_d3d11::GetRTVFormat(internalformat); mDepthStencilFormat = formatInfo.dsvFormat;
mSwizzleTextureFormat = gl_d3d11::GetSwizzleTexFormat(internalformat); mRenderTargetFormat = formatInfo.rtvFormat;
mSwizzleShaderResourceFormat = gl_d3d11::GetSwizzleSRVFormat(internalformat); mSwizzleTextureFormat = formatInfo.swizzleTexFormat;
mSwizzleRenderTargetFormat = gl_d3d11::GetSwizzleRTVFormat(internalformat); mSwizzleShaderResourceFormat = formatInfo.swizzleSRVFormat;
mSwizzleRenderTargetFormat = formatInfo.swizzleRTVFormat;
// if the size is not positive this should be treated as an incomplete texture // if the size is not positive this should be treated as an incomplete texture
// we handle that here by skipping the d3d texture creation // we handle that here by skipping the d3d texture creation
...@@ -865,10 +872,8 @@ ID3D11ShaderResourceView *TextureStorage11_Cube::createSRV(int baseLevel, int mi ...@@ -865,10 +872,8 @@ ID3D11ShaderResourceView *TextureStorage11_Cube::createSRV(int baseLevel, int mi
srvDesc.Format = format; srvDesc.Format = format;
// Unnormalized integer cube maps are not supported by DX11; we emulate them as an array of six 2D textures // Unnormalized integer cube maps are not supported by DX11; we emulate them as an array of six 2D textures
bool unnormalizedInteger = (d3d11::GetComponentType(mTextureFormat) == GL_INT || const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(format);
d3d11::GetComponentType(mTextureFormat) == GL_UNSIGNED_INT); if (dxgiFormatInfo.componentType == GL_INT || dxgiFormatInfo.componentType == GL_UNSIGNED_INT)
if(unnormalizedInteger)
{ {
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
srvDesc.Texture2DArray.MostDetailedMip = mTopLevel + baseLevel; srvDesc.Texture2DArray.MostDetailedMip = mTopLevel + baseLevel;
...@@ -994,13 +999,14 @@ TextureStorage11_3D::TextureStorage11_3D(Renderer *renderer, GLenum internalform ...@@ -994,13 +999,14 @@ TextureStorage11_3D::TextureStorage11_3D(Renderer *renderer, GLenum internalform
mSwizzleRenderTargets[i] = NULL; mSwizzleRenderTargets[i] = NULL;
} }
mTextureFormat = gl_d3d11::GetTexFormat(internalformat); const d3d11::TextureFormat &formatInfo = d3d11::GetTextureFormatInfo(internalformat);
mShaderResourceFormat = gl_d3d11::GetSRVFormat(internalformat); mTextureFormat = formatInfo.texFormat;
mDepthStencilFormat = gl_d3d11::GetDSVFormat(internalformat); mShaderResourceFormat = formatInfo.srvFormat;
mRenderTargetFormat = gl_d3d11::GetRTVFormat(internalformat); mDepthStencilFormat = formatInfo.dsvFormat;
mSwizzleTextureFormat = gl_d3d11::GetSwizzleTexFormat(internalformat); mRenderTargetFormat = formatInfo.rtvFormat;
mSwizzleShaderResourceFormat = gl_d3d11::GetSwizzleSRVFormat(internalformat); mSwizzleTextureFormat = formatInfo.swizzleTexFormat;
mSwizzleRenderTargetFormat = gl_d3d11::GetSwizzleRTVFormat(internalformat); mSwizzleShaderResourceFormat = formatInfo.swizzleSRVFormat;
mSwizzleRenderTargetFormat = formatInfo.swizzleRTVFormat;
// If the width, height or depth are not positive this should be treated as an incomplete texture // If the width, height or depth are not positive this should be treated as an incomplete texture
// we handle that here by skipping the d3d texture creation // we handle that here by skipping the d3d texture creation
...@@ -1297,13 +1303,14 @@ TextureStorage11_2DArray::TextureStorage11_2DArray(Renderer *renderer, GLenum in ...@@ -1297,13 +1303,14 @@ TextureStorage11_2DArray::TextureStorage11_2DArray(Renderer *renderer, GLenum in
mSwizzleRenderTargets[level] = NULL; mSwizzleRenderTargets[level] = NULL;
} }
mTextureFormat = gl_d3d11::GetTexFormat(internalformat); const d3d11::TextureFormat &formatInfo = d3d11::GetTextureFormatInfo(internalformat);
mShaderResourceFormat = gl_d3d11::GetSRVFormat(internalformat); mTextureFormat = formatInfo.texFormat;
mDepthStencilFormat = gl_d3d11::GetDSVFormat(internalformat); mShaderResourceFormat = formatInfo.srvFormat;
mRenderTargetFormat = gl_d3d11::GetRTVFormat(internalformat); mDepthStencilFormat = formatInfo.dsvFormat;
mSwizzleTextureFormat = gl_d3d11::GetSwizzleTexFormat(internalformat); mRenderTargetFormat = formatInfo.rtvFormat;
mSwizzleShaderResourceFormat = gl_d3d11::GetSwizzleSRVFormat(internalformat); mSwizzleTextureFormat = formatInfo.swizzleTexFormat;
mSwizzleRenderTargetFormat = gl_d3d11::GetSwizzleRTVFormat(internalformat); mSwizzleShaderResourceFormat = formatInfo.swizzleSRVFormat;
mSwizzleRenderTargetFormat = formatInfo.swizzleRTVFormat;
// if the width, height or depth is not positive this should be treated as an incomplete texture // if the width, height or depth is not positive this should be treated as an incomplete texture
// we handle that here by skipping the d3d texture creation // we handle that here by skipping the d3d texture creation
......
...@@ -109,9 +109,9 @@ bool VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, co ...@@ -109,9 +109,9 @@ bool VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, co
} }
gl::VertexFormat vertexFormat(attrib, currentValue.Type); gl::VertexFormat vertexFormat(attrib, currentValue.Type);
VertexCopyFunction conversionFunc = gl_d3d11::GetVertexCopyFunction(vertexFormat); const d3d11::VertexFormat &vertexFormatInfo = d3d11::GetVertexFormatInfo(vertexFormat);
ASSERT(conversionFunc != NULL); ASSERT(vertexFormatInfo.copyFunction != NULL);
conversionFunc(input, inputStride, count, output); vertexFormatInfo.copyFunction(input, inputStride, count, output);
dxContext->Unmap(mBuffer, 0); dxContext->Unmap(mBuffer, 0);
...@@ -141,7 +141,9 @@ bool VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei ...@@ -141,7 +141,9 @@ bool VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei
} }
gl::VertexFormat vertexFormat(attrib); gl::VertexFormat vertexFormat(attrib);
unsigned int elementSize = static_cast<unsigned int>(gl_d3d11::GetVertexElementSize(vertexFormat)); const d3d11::VertexFormat &vertexFormatInfo = d3d11::GetVertexFormatInfo(vertexFormat);
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(vertexFormatInfo.nativeFormat);
unsigned int elementSize = dxgiFormatInfo.pixelBytes;
if (elementSize <= std::numeric_limits<unsigned int>::max() / elementCount) if (elementSize <= std::numeric_limits<unsigned int>::max() / elementCount)
{ {
if (outSpaceRequired) if (outSpaceRequired)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -15,62 +15,65 @@ ...@@ -15,62 +15,65 @@
namespace rx namespace rx
{ {
class Renderer;
namespace d3d11 namespace d3d11
{ {
typedef std::set<DXGI_FORMAT> DXGIFormatSet; typedef std::map<std::pair<GLenum, GLenum>, ColorCopyFunction> FastCopyFunctionMap;
MipGenerationFunction GetMipGenerationFunction(DXGI_FORMAT format);
LoadImageFunction GetImageLoadFunction(GLenum internalFormat, GLenum type);
GLuint GetFormatPixelBytes(DXGI_FORMAT format); struct DXGIFormat
GLuint GetBlockWidth(DXGI_FORMAT format); {
GLuint GetBlockHeight(DXGI_FORMAT format); DXGIFormat();
GLenum GetComponentType(DXGI_FORMAT format);
GLuint GetDepthBits(DXGI_FORMAT format); GLuint pixelBytes;
GLuint GetDepthOffset(DXGI_FORMAT format); GLuint blockWidth;
GLuint GetStencilBits(DXGI_FORMAT format); GLuint blockHeight;
GLuint GetStencilOffset(DXGI_FORMAT format);
void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset); GLuint depthBits;
GLuint depthOffset;
GLuint stencilBits;
GLuint stencilOffset;
const DXGIFormatSet &GetAllUsedDXGIFormats(); GLenum internalFormat;
GLenum componentType;
ColorReadFunction GetColorReadFunction(DXGI_FORMAT format); MipGenerationFunction mipGenerationFunction;
ColorCopyFunction GetFastCopyFunction(DXGI_FORMAT sourceFormat, GLenum destFormat, GLenum destType); ColorReadFunction colorReadFunction;
} FastCopyFunctionMap fastCopyFunctions;
ColorCopyFunction getFastCopyFunction(GLenum format, GLenum type) const;
};
const DXGIFormat &GetDXGIFormatInfo(DXGI_FORMAT format);
namespace gl_d3d11 struct TextureFormat
{ {
TextureFormat();
DXGI_FORMAT GetTexFormat(GLenum internalFormat); DXGI_FORMAT texFormat;
DXGI_FORMAT GetSRVFormat(GLenum internalFormat); DXGI_FORMAT srvFormat;
DXGI_FORMAT GetRTVFormat(GLenum internalFormat); DXGI_FORMAT rtvFormat;
DXGI_FORMAT GetDSVFormat(GLenum internalFormat); DXGI_FORMAT dsvFormat;
DXGI_FORMAT GetRenderableFormat(GLenum internalFormat); DXGI_FORMAT renderFormat;
DXGI_FORMAT GetSwizzleTexFormat(GLint internalFormat);
DXGI_FORMAT GetSwizzleSRVFormat(GLint internalFormat);
DXGI_FORMAT GetSwizzleRTVFormat(GLint internalFormat);
bool RequiresTextureDataInitialization(GLint internalFormat); DXGI_FORMAT swizzleTexFormat;
InitializeTextureDataFunction GetTextureDataInitializationFunction(GLint internalFormat); DXGI_FORMAT swizzleSRVFormat;
DXGI_FORMAT swizzleRTVFormat;
VertexCopyFunction GetVertexCopyFunction(const gl::VertexFormat &vertexFormat); InitializeTextureDataFunction dataInitializerFunction;
size_t GetVertexElementSize(const gl::VertexFormat &vertexFormat);
VertexConversionType GetVertexConversionType(const gl::VertexFormat &vertexFormat);
DXGI_FORMAT GetNativeVertexFormat(const gl::VertexFormat &vertexFormat);
} typedef std::map<GLenum, LoadImageFunction> LoadFunctionMap;
LoadFunctionMap loadFunctions;
};
const TextureFormat &GetTextureFormatInfo(GLenum internalFormat);
namespace d3d11_gl struct VertexFormat
{ {
VertexFormat();
GLenum GetInternalFormat(DXGI_FORMAT format); VertexConversionType conversionType;
DXGI_FORMAT nativeFormat;
VertexCopyFunction copyFunction;
};
const VertexFormat &GetVertexFormatInfo(const gl::VertexFormat &vertexFormat);
} }
......
...@@ -224,14 +224,10 @@ static gl::TextureCaps GenerateTextureFormatCaps(GLenum internalFormat, ID3D11De ...@@ -224,14 +224,10 @@ static gl::TextureCaps GenerateTextureFormatCaps(GLenum internalFormat, ID3D11De
{ {
gl::TextureCaps textureCaps; gl::TextureCaps textureCaps;
DXGI_FORMAT textureFormat = gl_d3d11::GetTexFormat(internalFormat); const d3d11::TextureFormat &formatInfo = d3d11::GetTextureFormatInfo(internalFormat);
DXGI_FORMAT srvFormat = gl_d3d11::GetSRVFormat(internalFormat);
DXGI_FORMAT rtvFormat = gl_d3d11::GetRTVFormat(internalFormat);
DXGI_FORMAT dsvFormat = gl_d3d11::GetDSVFormat(internalFormat);
DXGI_FORMAT renderFormat = gl_d3d11::GetRenderableFormat(internalFormat);
UINT formatSupport; UINT formatSupport;
if (SUCCEEDED(device->CheckFormatSupport(textureFormat, &formatSupport))) if (SUCCEEDED(device->CheckFormatSupport(formatInfo.texFormat, &formatSupport)))
{ {
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat); const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0) if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0)
...@@ -246,13 +242,13 @@ static gl::TextureCaps GenerateTextureFormatCaps(GLenum internalFormat, ID3D11De ...@@ -246,13 +242,13 @@ static gl::TextureCaps GenerateTextureFormatCaps(GLenum internalFormat, ID3D11De
} }
} }
if (SUCCEEDED(device->CheckFormatSupport(renderFormat, &formatSupport)) && if (SUCCEEDED(device->CheckFormatSupport(formatInfo.renderFormat, &formatSupport)) &&
((formatSupport & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET) != 0)) ((formatSupport & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET) != 0))
{ {
for (size_t sampleCount = 1; sampleCount <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; sampleCount++) for (size_t sampleCount = 1; sampleCount <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; sampleCount++)
{ {
UINT qualityCount = 0; UINT qualityCount = 0;
if (SUCCEEDED(device->CheckMultisampleQualityLevels(renderFormat, sampleCount, &qualityCount)) && if (SUCCEEDED(device->CheckMultisampleQualityLevels(formatInfo.renderFormat, sampleCount, &qualityCount)) &&
qualityCount > 0) qualityCount > 0)
{ {
textureCaps.sampleCounts.insert(sampleCount); textureCaps.sampleCounts.insert(sampleCount);
...@@ -260,11 +256,11 @@ static gl::TextureCaps GenerateTextureFormatCaps(GLenum internalFormat, ID3D11De ...@@ -260,11 +256,11 @@ static gl::TextureCaps GenerateTextureFormatCaps(GLenum internalFormat, ID3D11De
} }
} }
textureCaps.filterable = SUCCEEDED(device->CheckFormatSupport(srvFormat, &formatSupport)) && textureCaps.filterable = SUCCEEDED(device->CheckFormatSupport(formatInfo.srvFormat, &formatSupport)) &&
((formatSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE)) != 0; ((formatSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE)) != 0;
textureCaps.renderable = (SUCCEEDED(device->CheckFormatSupport(rtvFormat, &formatSupport)) && textureCaps.renderable = (SUCCEEDED(device->CheckFormatSupport(formatInfo.rtvFormat, &formatSupport)) &&
((formatSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET)) != 0) || ((formatSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET)) != 0) ||
(SUCCEEDED(device->CheckFormatSupport(dsvFormat, &formatSupport)) && (SUCCEEDED(device->CheckFormatSupport(formatInfo.dsvFormat, &formatSupport)) &&
((formatSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL) != 0)); ((formatSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL) != 0));
return textureCaps; return textureCaps;
...@@ -578,12 +574,33 @@ void GenerateCaps(ID3D11Device *device, gl::Caps *caps, gl::TextureCapsMap *text ...@@ -578,12 +574,33 @@ void GenerateCaps(ID3D11Device *device, gl::Caps *caps, gl::TextureCapsMap *text
namespace d3d11 namespace d3d11
{ {
void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset)
{
const DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(format);
int upsampleCount = 0;
// Don't expand the size of full textures that are at least (blockWidth x blockHeight) already.
if (isImage || *requestWidth < static_cast<GLsizei>(dxgiFormatInfo.blockWidth) ||
*requestHeight < static_cast<GLsizei>(dxgiFormatInfo.blockHeight))
{
while (*requestWidth % dxgiFormatInfo.blockWidth != 0 || *requestHeight % dxgiFormatInfo.blockHeight != 0)
{
*requestWidth <<= 1;
*requestHeight <<= 1;
upsampleCount++;
}
}
*levelOffset = upsampleCount;
}
void GenerateInitialTextureData(GLint internalFormat, GLuint width, GLuint height, GLuint depth, void GenerateInitialTextureData(GLint internalFormat, GLuint width, GLuint height, GLuint depth,
GLuint mipLevels, std::vector<D3D11_SUBRESOURCE_DATA> *outSubresourceData, GLuint mipLevels, std::vector<D3D11_SUBRESOURCE_DATA> *outSubresourceData,
std::vector< std::vector<BYTE> > *outData) std::vector< std::vector<BYTE> > *outData)
{ {
InitializeTextureDataFunction initializeFunc = gl_d3d11::GetTextureDataInitializationFunction(internalFormat); const d3d11::TextureFormat &d3dFormatInfo = d3d11::GetTextureFormatInfo(internalFormat);
DXGI_FORMAT dxgiFormat = gl_d3d11::GetTexFormat(internalFormat); ASSERT(d3dFormatInfo.dataInitializerFunction != NULL);
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(d3dFormatInfo.texFormat);
outSubresourceData->resize(mipLevels); outSubresourceData->resize(mipLevels);
outData->resize(mipLevels); outData->resize(mipLevels);
...@@ -594,11 +611,11 @@ void GenerateInitialTextureData(GLint internalFormat, GLuint width, GLuint heigh ...@@ -594,11 +611,11 @@ void GenerateInitialTextureData(GLint internalFormat, GLuint width, GLuint heigh
unsigned int mipHeight = std::max(height >> i, 1U); unsigned int mipHeight = std::max(height >> i, 1U);
unsigned int mipDepth = std::max(depth >> i, 1U); unsigned int mipDepth = std::max(depth >> i, 1U);
unsigned int rowWidth = d3d11::GetFormatPixelBytes(dxgiFormat) * mipWidth; unsigned int rowWidth = dxgiFormatInfo.pixelBytes * mipWidth;
unsigned int imageSize = rowWidth * height; unsigned int imageSize = rowWidth * height;
outData->at(i).resize(rowWidth * mipHeight * mipDepth); outData->at(i).resize(rowWidth * mipHeight * mipDepth);
initializeFunc(mipWidth, mipHeight, mipDepth, outData->at(i).data(), rowWidth, imageSize); d3dFormatInfo.dataInitializerFunction(mipWidth, mipHeight, mipDepth, outData->at(i).data(), rowWidth, imageSize);
outSubresourceData->at(i).pSysMem = outData->at(i).data(); outSubresourceData->at(i).pSysMem = outData->at(i).data();
outSubresourceData->at(i).SysMemPitch = rowWidth; outSubresourceData->at(i).SysMemPitch = rowWidth;
......
...@@ -47,6 +47,8 @@ void GenerateCaps(ID3D11Device *device, gl::Caps *caps, gl::TextureCapsMap *text ...@@ -47,6 +47,8 @@ void GenerateCaps(ID3D11Device *device, gl::Caps *caps, gl::TextureCapsMap *text
namespace d3d11 namespace d3d11
{ {
void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset);
void GenerateInitialTextureData(GLint internalFormat, GLuint width, GLuint height, GLuint depth, void GenerateInitialTextureData(GLint internalFormat, GLuint width, GLuint height, GLuint depth,
GLuint mipLevels, std::vector<D3D11_SUBRESOURCE_DATA> *outSubresourceData, GLuint mipLevels, std::vector<D3D11_SUBRESOURCE_DATA> *outSubresourceData,
std::vector< std::vector<BYTE> > *outData); std::vector< std::vector<BYTE> > *outData);
......
...@@ -3098,11 +3098,6 @@ bool Renderer9::getLUID(LUID *adapterLuid) const ...@@ -3098,11 +3098,6 @@ bool Renderer9::getLUID(LUID *adapterLuid) const
return false; return false;
} }
GLenum Renderer9::getNativeTextureFormat(GLenum internalFormat) const
{
return d3d9_gl::GetInternalFormat(gl_d3d9::GetTextureFormat(internalFormat));
}
rx::VertexConversionType Renderer9::getVertexConversionType(const gl::VertexFormat &vertexFormat) const rx::VertexConversionType Renderer9::getVertexConversionType(const gl::VertexFormat &vertexFormat) const
{ {
return d3d9::GetVertexConversionType(vertexFormat); return d3d9::GetVertexConversionType(vertexFormat);
......
...@@ -202,7 +202,6 @@ class Renderer9 : public Renderer ...@@ -202,7 +202,6 @@ class Renderer9 : public Renderer
D3DPOOL getTexturePool(DWORD usage) const; D3DPOOL getTexturePool(DWORD usage) const;
virtual bool getLUID(LUID *adapterLuid) const; virtual bool getLUID(LUID *adapterLuid) const;
virtual GLenum getNativeTextureFormat(GLenum internalFormat) const;
virtual rx::VertexConversionType getVertexConversionType(const gl::VertexFormat &vertexFormat) const; virtual rx::VertexConversionType getVertexConversionType(const gl::VertexFormat &vertexFormat) const;
virtual GLenum getVertexComponentType(const gl::VertexFormat &vertexFormat) const; virtual GLenum getVertexComponentType(const gl::VertexFormat &vertexFormat) const;
......
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