Commit c1069a08 by Jamie Madill

D3D11: Add a TextureHelper class to wrap 2D+3D reads.

In some cases in our code we had hard-coded ID3D11Texture2D, where the code should handle 2D and 3D textures. This happens in ReadPixels, where we have to handle 3D textures when the user binds a layer of a 3D textures with FramebufferTextureLayer. This is a refactoring patch only, which makes the error cleaner. Tests and the bug fix to come in a follow-up patch. BUG=angleproject:1290 Change-Id: Ie1c293dead4d5b6b4dd6ce24ba2a9146619b141d Reviewed-on: https://chromium-review.googlesource.com/322680Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tryjob-Request: Jamie Madill <jmadill@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 5103f4c0
...@@ -199,7 +199,7 @@ class Buffer11::PackStorage : public Buffer11::BufferStorage ...@@ -199,7 +199,7 @@ class Buffer11::PackStorage : public Buffer11::BufferStorage
uint8_t *map(size_t offset, size_t length, GLbitfield access) override; uint8_t *map(size_t offset, size_t length, GLbitfield access) override;
void unmap() override; void unmap() override;
gl::Error packPixels(ID3D11Texture2D *srcTexure, gl::Error packPixels(const TextureHelper11 &srcTexture,
UINT srcSubresource, UINT srcSubresource,
const PackPixelsParams &params); const PackPixelsParams &params);
...@@ -624,7 +624,7 @@ ID3D11ShaderResourceView *Buffer11::getSRV(DXGI_FORMAT srvFormat) ...@@ -624,7 +624,7 @@ ID3D11ShaderResourceView *Buffer11::getSRV(DXGI_FORMAT srvFormat)
return bufferSRV; return bufferSRV;
} }
gl::Error Buffer11::packPixels(ID3D11Texture2D *srcTexture, gl::Error Buffer11::packPixels(const TextureHelper11 &srcTexture,
UINT srcSubresource, UINT srcSubresource,
const PackPixelsParams &params) const PackPixelsParams &params)
{ {
...@@ -1308,10 +1308,18 @@ void Buffer11::PackStorage::unmap() ...@@ -1308,10 +1308,18 @@ void Buffer11::PackStorage::unmap()
// No-op // No-op
} }
gl::Error Buffer11::PackStorage::packPixels(ID3D11Texture2D *srcTexure, gl::Error Buffer11::PackStorage::packPixels(const TextureHelper11 &srcTexture,
UINT srcSubresource, UINT srcSubresource,
const PackPixelsParams &params) const PackPixelsParams &params)
{ {
ID3D11Texture2D *tex2D = srcTexture.getTexture2D();
if (tex2D == nullptr)
{
// TODO(jmadill): Implement for 3D textures.
return gl::Error(GL_OUT_OF_MEMORY,
"Buffer11::PackStorage::packPixels called with 3D texture.");
}
gl::Error error = flushQueuedPackCommand(); gl::Error error = flushQueuedPackCommand();
if (error.isError()) if (error.isError())
{ {
...@@ -1320,11 +1328,8 @@ gl::Error Buffer11::PackStorage::packPixels(ID3D11Texture2D *srcTexure, ...@@ -1320,11 +1328,8 @@ gl::Error Buffer11::PackStorage::packPixels(ID3D11Texture2D *srcTexure,
mQueuedPackCommand = new PackPixelsParams(params); mQueuedPackCommand = new PackPixelsParams(params);
D3D11_TEXTURE2D_DESC textureDesc;
srcTexure->GetDesc(&textureDesc);
if (mStagingTexture != nullptr && if (mStagingTexture != nullptr &&
(mTextureFormat != textureDesc.Format || mTextureSize.width != params.area.width || (mTextureFormat != srcTexture.getFormat() || mTextureSize.width != params.area.width ||
mTextureSize.height != params.area.height)) mTextureSize.height != params.area.height))
{ {
SafeRelease(mStagingTexture); SafeRelease(mStagingTexture);
...@@ -1340,7 +1345,7 @@ gl::Error Buffer11::PackStorage::packPixels(ID3D11Texture2D *srcTexure, ...@@ -1340,7 +1345,7 @@ gl::Error Buffer11::PackStorage::packPixels(ID3D11Texture2D *srcTexure,
mTextureSize.width = params.area.width; mTextureSize.width = params.area.width;
mTextureSize.height = params.area.height; mTextureSize.height = params.area.height;
mTextureFormat = textureDesc.Format; mTextureFormat = srcTexture.getFormat();
D3D11_TEXTURE2D_DESC stagingDesc; D3D11_TEXTURE2D_DESC stagingDesc;
stagingDesc.Width = params.area.width; stagingDesc.Width = params.area.width;
...@@ -1364,7 +1369,7 @@ gl::Error Buffer11::PackStorage::packPixels(ID3D11Texture2D *srcTexure, ...@@ -1364,7 +1369,7 @@ gl::Error Buffer11::PackStorage::packPixels(ID3D11Texture2D *srcTexure,
} }
// ReadPixels from multisampled FBOs isn't supported in current GL // ReadPixels from multisampled FBOs isn't supported in current GL
ASSERT(textureDesc.SampleDesc.Count <= 1); ASSERT(srcTexture.getSampleCount() <= 1);
ID3D11DeviceContext *immediateContext = mRenderer->getDeviceContext(); ID3D11DeviceContext *immediateContext = mRenderer->getDeviceContext();
D3D11_BOX srcBox; D3D11_BOX srcBox;
...@@ -1376,7 +1381,7 @@ gl::Error Buffer11::PackStorage::packPixels(ID3D11Texture2D *srcTexure, ...@@ -1376,7 +1381,7 @@ gl::Error Buffer11::PackStorage::packPixels(ID3D11Texture2D *srcTexure,
srcBox.back = 1; srcBox.back = 1;
// Asynchronous copy // Asynchronous copy
immediateContext->CopySubresourceRegion(mStagingTexture, 0, 0, 0, 0, srcTexure, srcSubresource, immediateContext->CopySubresourceRegion(mStagingTexture, 0, 0, 0, 0, tex2D, srcSubresource,
&srcBox); &srcBox);
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
...@@ -1388,8 +1393,10 @@ gl::Error Buffer11::PackStorage::flushQueuedPackCommand() ...@@ -1388,8 +1393,10 @@ gl::Error Buffer11::PackStorage::flushQueuedPackCommand()
if (mQueuedPackCommand) if (mQueuedPackCommand)
{ {
TextureHelper11 stagingHelper(mStagingTexture);
gl::Error error = gl::Error error =
mRenderer->packPixels(mStagingTexture, *mQueuedPackCommand, mMemoryBuffer.data()); mRenderer->packPixels(stagingHelper, *mQueuedPackCommand, mMemoryBuffer.data());
SafeDelete(mQueuedPackCommand); SafeDelete(mQueuedPackCommand);
if (error.isError()) if (error.isError())
{ {
......
...@@ -18,6 +18,7 @@ namespace rx ...@@ -18,6 +18,7 @@ namespace rx
{ {
class Renderer11; class Renderer11;
struct SourceIndexData; struct SourceIndexData;
class TextureHelper11;
struct TranslatedAttribute; struct TranslatedAttribute;
enum BufferUsage enum BufferUsage
...@@ -62,7 +63,9 @@ class Buffer11 : public BufferD3D ...@@ -62,7 +63,9 @@ class Buffer11 : public BufferD3D
ID3D11Buffer *getConstantBufferRange(GLintptr offset, GLsizeiptr size); ID3D11Buffer *getConstantBufferRange(GLintptr offset, GLsizeiptr size);
ID3D11ShaderResourceView *getSRV(DXGI_FORMAT srvFormat); ID3D11ShaderResourceView *getSRV(DXGI_FORMAT srvFormat);
bool isMapped() const { return mMappedStorage != NULL; } bool isMapped() const { return mMappedStorage != NULL; }
gl::Error packPixels(ID3D11Texture2D *srcTexure, UINT srcSubresource, const PackPixelsParams &params); gl::Error packPixels(const TextureHelper11 &srcTexture,
UINT srcSubresource,
const PackPixelsParams &params);
size_t getTotalCPUBufferMemoryBytes() const; size_t getTotalCPUBufferMemoryBytes() const;
// BufferD3D implementation // BufferD3D implementation
......
...@@ -108,32 +108,6 @@ gl::Error Framebuffer11::clear(const gl::Data &data, const ClearParameters &clea ...@@ -108,32 +108,6 @@ gl::Error Framebuffer11::clear(const gl::Data &data, const ClearParameters &clea
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
static gl::Error getRenderTargetResource(const gl::FramebufferAttachment *colorbuffer, unsigned int *subresourceIndexOut,
ID3D11Texture2D **texture2DOut)
{
ASSERT(colorbuffer);
RenderTarget11 *renderTarget = nullptr;
gl::Error error = colorbuffer->getRenderTarget(&renderTarget);
if (error.isError())
{
return error;
}
ID3D11Resource *renderTargetResource = renderTarget->getTexture();
ASSERT(renderTargetResource);
*subresourceIndexOut = renderTarget->getSubresourceIndex();
*texture2DOut = d3d11::DynamicCastComObject<ID3D11Texture2D>(renderTargetResource);
if (!(*texture2DOut))
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to query the ID3D11Texture2D from a RenderTarget");
}
return gl::Error(GL_NO_ERROR);
}
gl::Error Framebuffer11::invalidate(size_t count, const GLenum *attachments) gl::Error Framebuffer11::invalidate(size_t count, const GLenum *attachments)
{ {
return invalidateBase(count, attachments, false); return invalidateBase(count, attachments, false);
...@@ -295,18 +269,22 @@ gl::Error Framebuffer11::readPixelsImpl(const gl::Rectangle &area, ...@@ -295,18 +269,22 @@ gl::Error Framebuffer11::readPixelsImpl(const gl::Rectangle &area,
const gl::PixelPackState &pack, const gl::PixelPackState &pack,
uint8_t *pixels) const uint8_t *pixels) const
{ {
ID3D11Texture2D *colorBufferTexture = nullptr;
unsigned int subresourceIndex = 0;
const gl::FramebufferAttachment *colorbuffer = mData.getReadAttachment(); const gl::FramebufferAttachment *colorbuffer = mData.getReadAttachment();
ASSERT(colorbuffer); ASSERT(colorbuffer);
gl::Error error = getRenderTargetResource(colorbuffer, &subresourceIndex, &colorBufferTexture); RenderTarget11 *renderTarget = nullptr;
gl::Error error = colorbuffer->getRenderTarget(&renderTarget);
if (error.isError()) if (error.isError())
{ {
return error; return error;
} }
ID3D11Resource *renderTargetResource = renderTarget->getTexture();
ASSERT(renderTargetResource);
unsigned int subresourceIndex = renderTarget->getSubresourceIndex();
TextureHelper11 textureHelper(renderTargetResource);
gl::Buffer *packBuffer = pack.pixelBuffer.get(); gl::Buffer *packBuffer = pack.pixelBuffer.get();
if (packBuffer != nullptr) if (packBuffer != nullptr)
{ {
...@@ -321,26 +299,22 @@ gl::Error Framebuffer11::readPixelsImpl(const gl::Rectangle &area, ...@@ -321,26 +299,22 @@ gl::Error Framebuffer11::readPixelsImpl(const gl::Rectangle &area,
PackPixelsParams packParams(area, format, type, static_cast<GLuint>(outputPitch), pack, PackPixelsParams packParams(area, format, type, static_cast<GLuint>(outputPitch), pack,
reinterpret_cast<ptrdiff_t>(pixels)); reinterpret_cast<ptrdiff_t>(pixels));
error = packBufferStorage->packPixels(colorBufferTexture, subresourceIndex, packParams); error = packBufferStorage->packPixels(textureHelper, subresourceIndex, packParams);
if (error.isError()) if (error.isError())
{ {
SafeRelease(colorBufferTexture);
return error; return error;
} }
} }
else else
{ {
error = mRenderer->readTextureData(colorBufferTexture, subresourceIndex, area, format, type, error = mRenderer->readTextureData(textureHelper, subresourceIndex, area, format, type,
static_cast<GLuint>(outputPitch), pack, pixels); static_cast<GLuint>(outputPitch), pack, pixels);
if (error.isError()) if (error.isError())
{ {
SafeRelease(colorBufferTexture);
return error; return error;
} }
} }
SafeRelease(colorBufferTexture);
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
......
...@@ -475,7 +475,10 @@ gl::Error Image11::copy(const gl::Offset &destOffset, const gl::Box &sourceArea, ...@@ -475,7 +475,10 @@ gl::Error Image11::copy(const gl::Offset &destOffset, const gl::Box &sourceArea,
ASSERT(dim == D3D11_RESOURCE_DIMENSION_TEXTURE2D); ASSERT(dim == D3D11_RESOURCE_DIMENSION_TEXTURE2D);
ASSERT(sourceArea.z == 0 && sourceArea.depth == 1); ASSERT(sourceArea.z == 0 && sourceArea.depth == 1);
gl::Rectangle sourceRect(sourceArea.x, sourceArea.y, sourceArea.width, sourceArea.height); gl::Rectangle sourceRect(sourceArea.x, sourceArea.y, sourceArea.width, sourceArea.height);
error = mRenderer->readTextureData(source2D, sourceSubResource, sourceRect, formatInfo.format, formatInfo.type, mappedImage.RowPitch, gl::PixelPackState(), dataOffset); TextureHelper11 sourceHelper(source2D);
error = mRenderer->readTextureData(sourceHelper, sourceSubResource, sourceRect,
formatInfo.format, formatInfo.type, mappedImage.RowPitch,
gl::PixelPackState(), dataOffset);
unmap(); unmap();
......
...@@ -3587,28 +3587,31 @@ RenderbufferImpl *Renderer11::createRenderbuffer() ...@@ -3587,28 +3587,31 @@ RenderbufferImpl *Renderer11::createRenderbuffer()
return renderbuffer; return renderbuffer;
} }
gl::Error Renderer11::readTextureData(ID3D11Texture2D *texture, unsigned int subResource, const gl::Rectangle &area, GLenum format, gl::Error Renderer11::readTextureData(const TextureHelper11 &textureHelper,
GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, uint8_t *pixels) unsigned int subResource,
const gl::Rectangle &area,
GLenum format,
GLenum type,
GLuint outputPitch,
const gl::PixelPackState &pack,
uint8_t *pixels)
{ {
ASSERT(area.width >= 0); ASSERT(area.width >= 0);
ASSERT(area.height >= 0); ASSERT(area.height >= 0);
D3D11_TEXTURE2D_DESC textureDesc; const gl::Extents &texSize = textureHelper.getExtents();
texture->GetDesc(&textureDesc);
// Clamp read region to the defined texture boundaries, preventing out of bounds reads // Clamp read region to the defined texture boundaries, preventing out of bounds reads
// and reads of uninitialized data. // and reads of uninitialized data.
gl::Rectangle safeArea; gl::Rectangle safeArea;
safeArea.x = gl::clamp(area.x, 0, static_cast<int>(textureDesc.Width)); safeArea.x = gl::clamp(area.x, 0, texSize.width);
safeArea.y = gl::clamp(area.y, 0, static_cast<int>(textureDesc.Height)); safeArea.y = gl::clamp(area.y, 0, texSize.height);
safeArea.width = gl::clamp(area.width + std::min(area.x, 0), 0, safeArea.width = gl::clamp(area.width + std::min(area.x, 0), 0, texSize.width - safeArea.x);
static_cast<int>(textureDesc.Width) - safeArea.x); safeArea.height = gl::clamp(area.height + std::min(area.y, 0), 0, texSize.height - safeArea.y);
safeArea.height = gl::clamp(area.height + std::min(area.y, 0), 0,
static_cast<int>(textureDesc.Height) - safeArea.y);
ASSERT(safeArea.x >= 0 && safeArea.y >= 0); ASSERT(safeArea.x >= 0 && safeArea.y >= 0);
ASSERT(safeArea.x + safeArea.width <= static_cast<int>(textureDesc.Width)); ASSERT(safeArea.x + safeArea.width <= texSize.width);
ASSERT(safeArea.y + safeArea.height <= static_cast<int>(textureDesc.Height)); ASSERT(safeArea.y + safeArea.height <= texSize.height);
if (safeArea.width == 0 || safeArea.height == 0) if (safeArea.width == 0 || safeArea.height == 0)
{ {
...@@ -3621,7 +3624,7 @@ gl::Error Renderer11::readTextureData(ID3D11Texture2D *texture, unsigned int sub ...@@ -3621,7 +3624,7 @@ gl::Error Renderer11::readTextureData(ID3D11Texture2D *texture, unsigned int sub
stagingDesc.Height = safeArea.height; stagingDesc.Height = safeArea.height;
stagingDesc.MipLevels = 1; stagingDesc.MipLevels = 1;
stagingDesc.ArraySize = 1; stagingDesc.ArraySize = 1;
stagingDesc.Format = textureDesc.Format; stagingDesc.Format = textureHelper.getFormat();
stagingDesc.SampleDesc.Count = 1; stagingDesc.SampleDesc.Count = 1;
stagingDesc.SampleDesc.Quality = 0; stagingDesc.SampleDesc.Quality = 0;
stagingDesc.Usage = D3D11_USAGE_STAGING; stagingDesc.Usage = D3D11_USAGE_STAGING;
...@@ -3629,22 +3632,29 @@ gl::Error Renderer11::readTextureData(ID3D11Texture2D *texture, unsigned int sub ...@@ -3629,22 +3632,29 @@ gl::Error Renderer11::readTextureData(ID3D11Texture2D *texture, unsigned int sub
stagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; stagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
stagingDesc.MiscFlags = 0; stagingDesc.MiscFlags = 0;
ID3D11Texture2D* stagingTex = NULL; ID3D11Texture2D *stagingTex = nullptr;
HRESULT result = mDevice->CreateTexture2D(&stagingDesc, NULL, &stagingTex); HRESULT result = mDevice->CreateTexture2D(&stagingDesc, nullptr, &stagingTex);
if (FAILED(result)) if (FAILED(result))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal staging texture for ReadPixels, HRESULT: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal staging texture for ReadPixels, HRESULT: 0x%X.", result);
} }
ID3D11Texture2D* srcTex = NULL; ID3D11Texture2D *texture = textureHelper.getTexture2D();
if (textureDesc.SampleDesc.Count > 1) if (!texture)
{
// TODO(jmadill): Implement for 3D Textures.
return gl::Error(GL_OUT_OF_MEMORY, "Renderer11::readTextureData called with 3D Texture.");
}
ID3D11Texture2D *srcTex = nullptr;
if (textureHelper.getSampleCount() > 1)
{ {
D3D11_TEXTURE2D_DESC resolveDesc; D3D11_TEXTURE2D_DESC resolveDesc;
resolveDesc.Width = textureDesc.Width; resolveDesc.Width = static_cast<UINT>(texSize.width);
resolveDesc.Height = textureDesc.Height; resolveDesc.Height = static_cast<UINT>(texSize.height);
resolveDesc.MipLevels = 1; resolveDesc.MipLevels = 1;
resolveDesc.ArraySize = 1; resolveDesc.ArraySize = 1;
resolveDesc.Format = textureDesc.Format; resolveDesc.Format = textureHelper.getFormat();
resolveDesc.SampleDesc.Count = 1; resolveDesc.SampleDesc.Count = 1;
resolveDesc.SampleDesc.Quality = 0; resolveDesc.SampleDesc.Quality = 0;
resolveDesc.Usage = D3D11_USAGE_DEFAULT; resolveDesc.Usage = D3D11_USAGE_DEFAULT;
...@@ -3652,14 +3662,15 @@ gl::Error Renderer11::readTextureData(ID3D11Texture2D *texture, unsigned int sub ...@@ -3652,14 +3662,15 @@ gl::Error Renderer11::readTextureData(ID3D11Texture2D *texture, unsigned int sub
resolveDesc.CPUAccessFlags = 0; resolveDesc.CPUAccessFlags = 0;
resolveDesc.MiscFlags = 0; resolveDesc.MiscFlags = 0;
result = mDevice->CreateTexture2D(&resolveDesc, NULL, &srcTex); result = mDevice->CreateTexture2D(&resolveDesc, nullptr, &srcTex);
if (FAILED(result)) if (FAILED(result))
{ {
SafeRelease(stagingTex); SafeRelease(stagingTex);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal resolve texture for ReadPixels, HRESULT: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal resolve texture for ReadPixels, HRESULT: 0x%X.", result);
} }
mDeviceContext->ResolveSubresource(srcTex, 0, texture, subResource, textureDesc.Format); mDeviceContext->ResolveSubresource(srcTex, 0, texture, subResource,
textureHelper.getFormat());
subResource = 0; subResource = 0;
} }
else else
...@@ -3681,17 +3692,25 @@ gl::Error Renderer11::readTextureData(ID3D11Texture2D *texture, unsigned int sub ...@@ -3681,17 +3692,25 @@ gl::Error Renderer11::readTextureData(ID3D11Texture2D *texture, unsigned int sub
SafeRelease(srcTex); SafeRelease(srcTex);
PackPixelsParams packParams(safeArea, format, type, outputPitch, pack, 0); PackPixelsParams packParams(safeArea, format, type, outputPitch, pack, 0);
gl::Error error = packPixels(stagingTex, packParams, pixels); TextureHelper11 stagingHelper(stagingTex);
gl::Error error = packPixels(stagingHelper, packParams, pixels);
SafeRelease(stagingTex); SafeRelease(stagingTex);
return error; return error;
} }
gl::Error Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams &params, uint8_t *pixelsOut) gl::Error Renderer11::packPixels(const TextureHelper11 &textureHelper,
const PackPixelsParams &params,
uint8_t *pixelsOut)
{ {
D3D11_TEXTURE2D_DESC textureDesc; ID3D11Texture2D *readTexture = textureHelper.getTexture2D();
readTexture->GetDesc(&textureDesc);
if (readTexture == nullptr)
{
// TODO(jmadill): Implement packPixels for 3D textures.
return gl::Error(GL_OUT_OF_MEMORY, "Renderer11::packPixels called with 3D Texture.");
}
D3D11_MAPPED_SUBRESOURCE mapping; D3D11_MAPPED_SUBRESOURCE mapping;
HRESULT hr = mDeviceContext->Map(readTexture, 0, D3D11_MAP_READ, 0, &mapping); HRESULT hr = mDeviceContext->Map(readTexture, 0, D3D11_MAP_READ, 0, &mapping);
...@@ -3714,7 +3733,7 @@ gl::Error Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsP ...@@ -3714,7 +3733,7 @@ gl::Error Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsP
inputPitch = static_cast<int>(mapping.RowPitch); inputPitch = static_cast<int>(mapping.RowPitch);
} }
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(textureDesc.Format); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(textureHelper.getFormat());
const gl::InternalFormat &sourceFormatInfo = gl::GetInternalFormatInfo(dxgiFormatInfo.internalFormat); 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)
{ {
...@@ -3726,9 +3745,8 @@ gl::Error Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsP ...@@ -3726,9 +3745,8 @@ gl::Error Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsP
} }
else else
{ {
const d3d11::DXGIFormat &sourceDXGIFormatInfo = d3d11::GetDXGIFormatInfo(textureDesc.Format); ColorCopyFunction fastCopyFunc =
ColorCopyFunction fastCopyFunc = sourceDXGIFormatInfo.getFastCopyFunction(params.format, params.type); dxgiFormatInfo.getFastCopyFunction(params.format, params.type);
GLenum sizedDestInternalFormat = gl::GetSizedInternalFormat(params.format, params.type); GLenum sizedDestInternalFormat = gl::GetSizedInternalFormat(params.format, params.type);
const gl::InternalFormat &destFormatInfo = gl::GetInternalFormatInfo(sizedDestInternalFormat); const gl::InternalFormat &destFormatInfo = gl::GetInternalFormatInfo(sizedDestInternalFormat);
...@@ -3748,7 +3766,7 @@ gl::Error Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsP ...@@ -3748,7 +3766,7 @@ gl::Error Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsP
} }
else else
{ {
ColorReadFunction colorReadFunction = sourceDXGIFormatInfo.colorReadFunction; ColorReadFunction colorReadFunction = dxgiFormatInfo.colorReadFunction;
ColorWriteFunction colorWriteFunction = GetColorWriteFunction(params.format, params.type); ColorWriteFunction colorWriteFunction = GetColorWriteFunction(params.format, params.type);
uint8_t temp[16]; // Maximum size of any Color<T> type used. uint8_t temp[16]; // Maximum size of any Color<T> type used.
......
...@@ -254,14 +254,22 @@ class Renderer11 : public RendererD3D ...@@ -254,14 +254,22 @@ class Renderer11 : public RendererD3D
void unapplyRenderTargets(); void unapplyRenderTargets();
void setOneTimeRenderTarget(ID3D11RenderTargetView *renderTargetView); void setOneTimeRenderTarget(ID3D11RenderTargetView *renderTargetView);
gl::Error packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams &params, uint8_t *pixelsOut); gl::Error packPixels(const TextureHelper11 &textureHelper,
const PackPixelsParams &params,
uint8_t *pixelsOut);
bool getLUID(LUID *adapterLuid) const override; bool getLUID(LUID *adapterLuid) const override;
VertexConversionType getVertexConversionType(gl::VertexFormatType vertexFormatType) const override; VertexConversionType getVertexConversionType(gl::VertexFormatType vertexFormatType) const override;
GLenum getVertexComponentType(gl::VertexFormatType vertexFormatType) const override; GLenum getVertexComponentType(gl::VertexFormatType vertexFormatType) const override;
gl::Error readTextureData(ID3D11Texture2D *texture, unsigned int subResource, const gl::Rectangle &area, GLenum format, gl::Error readTextureData(const TextureHelper11 &textureHelper,
GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, uint8_t *pixels); unsigned int subResource,
const gl::Rectangle &area,
GLenum format,
GLenum type,
GLuint outputPitch,
const gl::PixelPackState &pack,
uint8_t *pixels);
void setShaderResource(gl::SamplerType shaderType, UINT resourceSlot, ID3D11ShaderResourceView *srv); void setShaderResource(gl::SamplerType shaderType, UINT resourceSlot, ID3D11ShaderResourceView *srv);
......
...@@ -225,8 +225,7 @@ D3D11_QUERY ConvertQueryType(GLenum queryType) ...@@ -225,8 +225,7 @@ D3D11_QUERY ConvertQueryType(GLenum queryType)
} }
} }
} } // namespace gl_d3d11
namespace d3d11_gl namespace d3d11_gl
{ {
...@@ -1247,7 +1246,7 @@ void GenerateCaps(ID3D11Device *device, ID3D11DeviceContext *deviceContext, cons ...@@ -1247,7 +1246,7 @@ void GenerateCaps(ID3D11Device *device, ID3D11DeviceContext *deviceContext, cons
#endif #endif
} }
} } // namespace d3d11_gl
namespace d3d11 namespace d3d11
{ {
...@@ -1489,6 +1488,103 @@ WorkaroundsD3D GenerateWorkarounds(D3D_FEATURE_LEVEL featureLevel) ...@@ -1489,6 +1488,103 @@ WorkaroundsD3D GenerateWorkarounds(D3D_FEATURE_LEVEL featureLevel)
return workarounds; return workarounds;
} }
} // namespace d3d11
TextureHelper11::TextureHelper11()
: mTextureType(GL_NONE),
mFormat(DXGI_FORMAT_UNKNOWN),
mSampleCount(0),
mTexture2D(nullptr),
mTexture3D(nullptr)
{
} }
TextureHelper11::TextureHelper11(ID3D11Resource *resource)
: mTextureType(GL_NONE),
mFormat(DXGI_FORMAT_UNKNOWN),
mSampleCount(0),
mTexture2D(nullptr),
mTexture3D(nullptr)
{
mTexture2D = d3d11::DynamicCastComObject<ID3D11Texture2D>(resource);
mTexture3D = d3d11::DynamicCastComObject<ID3D11Texture3D>(resource);
if (mTexture2D)
{
ASSERT(!mTexture3D);
mTextureType = GL_TEXTURE_2D;
D3D11_TEXTURE2D_DESC desc2D;
mTexture2D->GetDesc(&desc2D);
mExtents.width = static_cast<int>(desc2D.Width);
mExtents.height = static_cast<int>(desc2D.Height);
mExtents.depth = 1;
mFormat = desc2D.Format;
mSampleCount = desc2D.SampleDesc.Count;
}
else
{
ASSERT(mTexture3D);
mTextureType = GL_TEXTURE_3D;
D3D11_TEXTURE3D_DESC desc3D;
mTexture3D->GetDesc(&desc3D);
mExtents.width = static_cast<int>(desc3D.Width);
mExtents.height = static_cast<int>(desc3D.Height);
mExtents.depth = static_cast<int>(desc3D.Depth);
mFormat = desc3D.Format;
mSampleCount = 1;
}
} }
TextureHelper11::TextureHelper11(TextureHelper11 &&toCopy)
: mTextureType(toCopy.mTextureType),
mExtents(toCopy.mExtents),
mFormat(toCopy.mFormat),
mSampleCount(toCopy.mSampleCount),
mTexture2D(toCopy.mTexture2D),
mTexture3D(toCopy.mTexture3D)
{
toCopy.reset();
}
TextureHelper11::~TextureHelper11()
{
SafeRelease(mTexture2D);
SafeRelease(mTexture3D);
}
ID3D11Resource *TextureHelper11::getResource() const
{
return mTexture2D ? static_cast<ID3D11Resource *>(mTexture2D)
: static_cast<ID3D11Resource *>(mTexture3D);
}
TextureHelper11 &TextureHelper11::operator=(TextureHelper11 &&texture)
{
SafeRelease(mTexture2D);
SafeRelease(mTexture3D);
mTextureType = texture.mTextureType;
mExtents = texture.mExtents;
mFormat = texture.mFormat;
mSampleCount = texture.mSampleCount;
mTexture2D = texture.mTexture2D;
mTexture3D = texture.mTexture3D;
texture.reset();
return *this;
}
void TextureHelper11::reset()
{
mTextureType = GL_NONE;
mExtents = gl::Extents();
mFormat = DXGI_FORMAT_UNKNOWN;
mSampleCount = 0;
mTexture2D = nullptr;
mTexture3D = nullptr;
}
} // namespace rx
...@@ -47,7 +47,7 @@ D3D11_TEXTURE_ADDRESS_MODE ConvertTextureWrap(GLenum wrap); ...@@ -47,7 +47,7 @@ D3D11_TEXTURE_ADDRESS_MODE ConvertTextureWrap(GLenum wrap);
D3D11_QUERY ConvertQueryType(GLenum queryType); D3D11_QUERY ConvertQueryType(GLenum queryType);
} } // namespace gl_d3d11
namespace d3d11_gl namespace d3d11_gl
{ {
...@@ -60,7 +60,7 @@ GLint GetMaximumClientVersion(D3D_FEATURE_LEVEL featureLevel); ...@@ -60,7 +60,7 @@ GLint GetMaximumClientVersion(D3D_FEATURE_LEVEL featureLevel);
void GenerateCaps(ID3D11Device *device, ID3D11DeviceContext *deviceContext, const Renderer11DeviceCaps &renderer11DeviceCaps, gl::Caps *caps, void GenerateCaps(ID3D11Device *device, ID3D11DeviceContext *deviceContext, const Renderer11DeviceCaps &renderer11DeviceCaps, gl::Caps *caps,
gl::TextureCapsMap *textureCapsMap, gl::Extensions *extensions, gl::Limitations *limitations); gl::TextureCapsMap *textureCapsMap, gl::Extensions *extensions, gl::Limitations *limitations);
} } // namespace d3d11_gl
namespace d3d11 namespace d3d11
{ {
...@@ -334,8 +334,37 @@ void SetBufferData(ID3D11DeviceContext *context, ID3D11Buffer *constantBuffer, c ...@@ -334,8 +334,37 @@ void SetBufferData(ID3D11DeviceContext *context, ID3D11Buffer *constantBuffer, c
} }
WorkaroundsD3D GenerateWorkarounds(D3D_FEATURE_LEVEL featureLevel); WorkaroundsD3D GenerateWorkarounds(D3D_FEATURE_LEVEL featureLevel);
} } // namespace d3d11
} // A helper class which wraps a 2D or 3D texture.
class TextureHelper11 : angle::NonCopyable
{
public:
TextureHelper11();
explicit TextureHelper11(ID3D11Resource *resource);
TextureHelper11(TextureHelper11 &&toCopy);
~TextureHelper11();
TextureHelper11 &operator=(TextureHelper11 &&texture);
GLenum getTextureType() const { return mTextureType; }
gl::Extents getExtents() const { return mExtents; }
DXGI_FORMAT getFormat() const { return mFormat; }
int getSampleCount() const { return mSampleCount; }
ID3D11Texture2D *getTexture2D() const { return mTexture2D; }
ID3D11Texture3D *getTexture3D() const { return mTexture3D; }
ID3D11Resource *getResource() const;
private:
void reset();
GLenum mTextureType;
gl::Extents mExtents;
DXGI_FORMAT mFormat;
int mSampleCount;
ID3D11Texture2D *mTexture2D;
ID3D11Texture3D *mTexture3D;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_D3D_D3D11_RENDERER11_UTILS_H_ #endif // LIBANGLE_RENDERER_D3D_D3D11_RENDERER11_UTILS_H_
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