diff options
Diffstat (limited to 'src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11')
88 files changed, 0 insertions, 41020 deletions
diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp deleted file mode 100644 index f032e888f1..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp +++ /dev/null @@ -1,2153 +0,0 @@ -// -// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Blit11.cpp: Texture copy utility class. - -#include "libANGLE/renderer/d3d/d3d11/Blit11.h" - -#include <float.h> - -#include "common/utilities.h" -#include "libANGLE/formatutils.h" -#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h" -#include "third_party/trace_event/trace_event.h" - -namespace rx -{ - -namespace -{ - -// Include inline shaders in the anonymous namespace to make sure no symbols are exported -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthrough2d11vs.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthrougha2d11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughdepth2d11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughlum2d11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughlumalpha2d11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughr2d11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughr2di11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughr2dui11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrg2d11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrg2di11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrg2dui11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgb2d11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgb2di11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgb2dui11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgba2d11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgba2di11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgba2dui11ps.h" - -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/multiplyalpha_ftof_pm_luma_ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/multiplyalpha_ftof_pm_lumaalpha_ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/multiplyalpha_ftof_pm_rgb_ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/multiplyalpha_ftof_pm_rgba_ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/multiplyalpha_ftof_um_luma_ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/multiplyalpha_ftof_um_lumaalpha_ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/multiplyalpha_ftof_um_rgb_ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/multiplyalpha_ftof_um_rgba_ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/multiplyalpha_ftou_pm_rgb_ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/multiplyalpha_ftou_pm_rgba_ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/multiplyalpha_ftou_pt_rgb_ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/multiplyalpha_ftou_pt_rgba_ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/multiplyalpha_ftou_um_rgb_ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/multiplyalpha_ftou_um_rgba_ps.h" - -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthrough3d11gs.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthrough3d11vs.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughlum3d11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughlumalpha3d11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughr3d11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughr3di11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughr3dui11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrg3d11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrg3di11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrg3dui11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgb3d11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgb3di11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgb3dui11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgba3d11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgba3di11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgba3dui11ps.h" - -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/resolvedepth11_ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/resolvedepthstencil11_ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/resolvedepthstencil11_vs.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/resolvestencil11_ps.h" - -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/swizzlef2darrayps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/swizzlef2dps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/swizzlef3dps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/swizzlei2darrayps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/swizzlei2dps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/swizzlei3dps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/swizzleui2darrayps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/swizzleui2dps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/swizzleui3dps.h" - -void StretchedBlitNearest_RowByRow(const gl::Box &sourceArea, - const gl::Box &destArea, - const gl::Rectangle &clippedDestArea, - const gl::Extents &sourceSize, - unsigned int sourceRowPitch, - unsigned int destRowPitch, - size_t pixelSize, - const uint8_t *sourceData, - uint8_t *destData) -{ - int srcHeightSubOne = (sourceArea.height - 1); - size_t copySize = pixelSize * destArea.width; - size_t srcOffset = sourceArea.x * pixelSize; - size_t destOffset = destArea.x * pixelSize; - - for (int y = clippedDestArea.y; y < clippedDestArea.y + clippedDestArea.height; y++) - { - float yPerc = static_cast<float>(y - destArea.y) / (destArea.height - 1); - - // Interpolate using the original source rectangle to determine which row to sample from - // while clamping to the edges - unsigned int readRow = static_cast<unsigned int>( - gl::clamp(sourceArea.y + floor(yPerc * srcHeightSubOne + 0.5f), 0, srcHeightSubOne)); - unsigned int writeRow = y; - - const uint8_t *sourceRow = sourceData + readRow * sourceRowPitch + srcOffset; - uint8_t *destRow = destData + writeRow * destRowPitch + destOffset; - memcpy(destRow, sourceRow, copySize); - } -} - -void StretchedBlitNearest_PixelByPixel(const gl::Box &sourceArea, - const gl::Box &destArea, - const gl::Rectangle &clippedDestArea, - const gl::Extents &sourceSize, - unsigned int sourceRowPitch, - unsigned int destRowPitch, - ptrdiff_t readOffset, - ptrdiff_t writeOffset, - size_t copySize, - size_t srcPixelStride, - size_t destPixelStride, - const uint8_t *sourceData, - uint8_t *destData) -{ - auto xMax = clippedDestArea.x + clippedDestArea.width; - auto yMax = clippedDestArea.y + clippedDestArea.height; - - for (int writeRow = clippedDestArea.y; writeRow < yMax; writeRow++) - { - // Interpolate using the original source rectangle to determine which row to sample from - // while clamping to the edges - float yPerc = static_cast<float>(writeRow - destArea.y) / (destArea.height - 1); - float yRounded = floor(yPerc * (sourceArea.height - 1) + 0.5f); - unsigned int readRow = - static_cast<unsigned int>(gl::clamp(sourceArea.y + yRounded, 0, sourceSize.height - 1)); - - for (int writeColumn = clippedDestArea.x; writeColumn < xMax; writeColumn++) - { - // Interpolate the original source rectangle to determine which column to sample - // from while clamping to the edges - float xPerc = static_cast<float>(writeColumn - destArea.x) / (destArea.width - 1); - float xRounded = floor(xPerc * (sourceArea.width - 1) + 0.5f); - unsigned int readColumn = static_cast<unsigned int>( - gl::clamp(sourceArea.x + xRounded, 0, sourceSize.height - 1)); - - const uint8_t *sourcePixel = - sourceData + readRow * sourceRowPitch + readColumn * srcPixelStride + readOffset; - - uint8_t *destPixel = - destData + writeRow * destRowPitch + writeColumn * destPixelStride + writeOffset; - - memcpy(destPixel, sourcePixel, copySize); - } - } -} - -void StretchedBlitNearest(const gl::Box &sourceArea, - const gl::Box &destArea, - const gl::Rectangle &clipRect, - const gl::Extents &sourceSize, - unsigned int sourceRowPitch, - unsigned int destRowPitch, - ptrdiff_t readOffset, - ptrdiff_t writeOffset, - size_t copySize, - size_t srcPixelStride, - size_t destPixelStride, - const uint8_t *sourceData, - uint8_t *destData) -{ - gl::Rectangle clippedDestArea(destArea.x, destArea.y, destArea.width, destArea.height); - gl::ClipRectangle(clippedDestArea, clipRect, &clippedDestArea); - - // Determine if entire rows can be copied at once instead of each individual pixel. There - // must be no out of bounds lookups, whole rows copies, and no scale. - if (sourceArea.width == clippedDestArea.width && sourceArea.x >= 0 && - sourceArea.x + sourceArea.width <= sourceSize.width && copySize == srcPixelStride && - copySize == destPixelStride) - { - StretchedBlitNearest_RowByRow(sourceArea, destArea, clippedDestArea, sourceSize, - sourceRowPitch, destRowPitch, srcPixelStride, sourceData, - destData); - } - else - { - StretchedBlitNearest_PixelByPixel(sourceArea, destArea, clippedDestArea, sourceSize, - sourceRowPitch, destRowPitch, readOffset, writeOffset, - copySize, srcPixelStride, destPixelStride, sourceData, - destData); - } -} - -using DepthStencilLoader = void(const float *, uint8_t *); - -void LoadDepth16(const float *source, uint8_t *dest) -{ - uint32_t convertedDepth = gl::floatToNormalized<16, uint32_t>(source[0]); - memcpy(dest, &convertedDepth, 2u); -} - -void LoadDepth24(const float *source, uint8_t *dest) -{ - uint32_t convertedDepth = gl::floatToNormalized<24, uint32_t>(source[0]); - memcpy(dest, &convertedDepth, 3u); -} - -void LoadStencilHelper(const float *source, uint8_t *dest) -{ - uint32_t convertedStencil = gl::getShiftedData<8, 0>(static_cast<uint32_t>(source[1])); - memcpy(dest, &convertedStencil, 1u); -} - -void LoadStencil8(const float *source, uint8_t *dest) -{ - // STENCIL_INDEX8 is implemented with D24S8, with the depth bits unused. Writes zero for safety. - float zero = 0.0f; - LoadDepth24(&zero, &dest[0]); - LoadStencilHelper(source, &dest[3]); -} - -void LoadDepth24Stencil8(const float *source, uint8_t *dest) -{ - LoadDepth24(source, &dest[0]); - LoadStencilHelper(source, &dest[3]); -} - -void LoadDepth32F(const float *source, uint8_t *dest) -{ - memcpy(dest, source, sizeof(float)); -} - -void LoadDepth32FStencil8(const float *source, uint8_t *dest) -{ - LoadDepth32F(source, &dest[0]); - LoadStencilHelper(source, &dest[4]); -} - -template <DepthStencilLoader loader> -void CopyDepthStencil(const gl::Box &sourceArea, - const gl::Box &destArea, - const gl::Rectangle &clippedDestArea, - const gl::Extents &sourceSize, - unsigned int sourceRowPitch, - unsigned int destRowPitch, - ptrdiff_t readOffset, - ptrdiff_t writeOffset, - size_t copySize, - size_t srcPixelStride, - size_t destPixelStride, - const uint8_t *sourceData, - uint8_t *destData) -{ - // No stretching or subregions are supported, only full blits. - ASSERT(sourceArea == destArea); - ASSERT(sourceSize.width == sourceArea.width && sourceSize.height == sourceArea.height && - sourceSize.depth == 1); - ASSERT(clippedDestArea.width == sourceSize.width && - clippedDestArea.height == sourceSize.height); - ASSERT(readOffset == 0 && writeOffset == 0); - ASSERT(destArea.x == 0 && destArea.y == 0); - - for (int row = 0; row < destArea.height; ++row) - { - for (int column = 0; column < destArea.width; ++column) - { - ptrdiff_t offset = row * sourceRowPitch + column * srcPixelStride; - const float *sourcePixel = reinterpret_cast<const float *>(sourceData + offset); - - uint8_t *destPixel = destData + row * destRowPitch + column * destPixelStride; - - loader(sourcePixel, destPixel); - } - } -} - -void Depth32FStencil8ToDepth32F(const float *source, float *dest) -{ - *dest = *source; -} - -void Depth24Stencil8ToDepth32F(const uint32_t *source, float *dest) -{ - uint32_t normDepth = source[0] & 0x00FFFFFF; - float floatDepth = gl::normalizedToFloat<24>(normDepth); - *dest = floatDepth; -} - -void BlitD24S8ToD32F(const gl::Box &sourceArea, - const gl::Box &destArea, - const gl::Rectangle &clippedDestArea, - const gl::Extents &sourceSize, - unsigned int sourceRowPitch, - unsigned int destRowPitch, - ptrdiff_t readOffset, - ptrdiff_t writeOffset, - size_t copySize, - size_t srcPixelStride, - size_t destPixelStride, - const uint8_t *sourceData, - uint8_t *destData) -{ - // No stretching or subregions are supported, only full blits. - ASSERT(sourceArea == destArea); - ASSERT(sourceSize.width == sourceArea.width && sourceSize.height == sourceArea.height && - sourceSize.depth == 1); - ASSERT(clippedDestArea.width == sourceSize.width && - clippedDestArea.height == sourceSize.height); - ASSERT(readOffset == 0 && writeOffset == 0); - ASSERT(destArea.x == 0 && destArea.y == 0); - - for (int row = 0; row < destArea.height; ++row) - { - for (int column = 0; column < destArea.width; ++column) - { - ptrdiff_t offset = row * sourceRowPitch + column * srcPixelStride; - const uint32_t *sourcePixel = reinterpret_cast<const uint32_t *>(sourceData + offset); - - float *destPixel = - reinterpret_cast<float *>(destData + row * destRowPitch + column * destPixelStride); - - Depth24Stencil8ToDepth32F(sourcePixel, destPixel); - } - } -} - -void BlitD32FS8ToD32F(const gl::Box &sourceArea, - const gl::Box &destArea, - const gl::Rectangle &clippedDestArea, - const gl::Extents &sourceSize, - unsigned int sourceRowPitch, - unsigned int destRowPitch, - ptrdiff_t readOffset, - ptrdiff_t writeOffset, - size_t copySize, - size_t srcPixelStride, - size_t destPixelStride, - const uint8_t *sourceData, - uint8_t *destData) -{ - // No stretching or subregions are supported, only full blits. - ASSERT(sourceArea == destArea); - ASSERT(sourceSize.width == sourceArea.width && sourceSize.height == sourceArea.height && - sourceSize.depth == 1); - ASSERT(clippedDestArea.width == sourceSize.width && - clippedDestArea.height == sourceSize.height); - ASSERT(readOffset == 0 && writeOffset == 0); - ASSERT(destArea.x == 0 && destArea.y == 0); - - for (int row = 0; row < destArea.height; ++row) - { - for (int column = 0; column < destArea.width; ++column) - { - ptrdiff_t offset = row * sourceRowPitch + column * srcPixelStride; - const float *sourcePixel = reinterpret_cast<const float *>(sourceData + offset); - float *destPixel = - reinterpret_cast<float *>(destData + row * destRowPitch + column * destPixelStride); - - Depth32FStencil8ToDepth32F(sourcePixel, destPixel); - } - } -} - -Blit11::BlitConvertFunction *GetCopyDepthStencilFunction(GLenum internalFormat) -{ - switch (internalFormat) - { - case GL_DEPTH_COMPONENT16: - return &CopyDepthStencil<LoadDepth16>; - case GL_DEPTH_COMPONENT24: - return &CopyDepthStencil<LoadDepth24>; - case GL_DEPTH_COMPONENT32F: - return &CopyDepthStencil<LoadDepth32F>; - case GL_STENCIL_INDEX8: - return &CopyDepthStencil<LoadStencil8>; - case GL_DEPTH24_STENCIL8: - return &CopyDepthStencil<LoadDepth24Stencil8>; - case GL_DEPTH32F_STENCIL8: - return &CopyDepthStencil<LoadDepth32FStencil8>; - default: - UNREACHABLE(); - return nullptr; - } -} - -inline void GenerateVertexCoords(const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const gl::Box &destArea, - const gl::Extents &destSize, - float *x1, - float *y1, - float *x2, - float *y2, - float *u1, - float *v1, - float *u2, - float *v2) -{ - *x1 = (destArea.x / float(destSize.width)) * 2.0f - 1.0f; - *y1 = ((destSize.height - destArea.y - destArea.height) / float(destSize.height)) * 2.0f - 1.0f; - *x2 = ((destArea.x + destArea.width) / float(destSize.width)) * 2.0f - 1.0f; - *y2 = ((destSize.height - destArea.y) / float(destSize.height)) * 2.0f - 1.0f; - - *u1 = sourceArea.x / float(sourceSize.width); - *v1 = sourceArea.y / float(sourceSize.height); - *u2 = (sourceArea.x + sourceArea.width) / float(sourceSize.width); - *v2 = (sourceArea.y + sourceArea.height) / float(sourceSize.height); -} - -void Write2DVertices(const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const gl::Box &destArea, - const gl::Extents &destSize, - void *outVertices, - unsigned int *outStride, - unsigned int *outVertexCount, - D3D11_PRIMITIVE_TOPOLOGY *outTopology) -{ - float x1, y1, x2, y2, u1, v1, u2, v2; - GenerateVertexCoords(sourceArea, sourceSize, destArea, destSize, &x1, &y1, &x2, &y2, &u1, &v1, - &u2, &v2); - - d3d11::PositionTexCoordVertex *vertices = - static_cast<d3d11::PositionTexCoordVertex *>(outVertices); - - d3d11::SetPositionTexCoordVertex(&vertices[0], x1, y1, u1, v2); - d3d11::SetPositionTexCoordVertex(&vertices[1], x1, y2, u1, v1); - d3d11::SetPositionTexCoordVertex(&vertices[2], x2, y1, u2, v2); - d3d11::SetPositionTexCoordVertex(&vertices[3], x2, y2, u2, v1); - - *outStride = sizeof(d3d11::PositionTexCoordVertex); - *outVertexCount = 4; - *outTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; -} - -void Write3DVertices(const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const gl::Box &destArea, - const gl::Extents &destSize, - void *outVertices, - unsigned int *outStride, - unsigned int *outVertexCount, - D3D11_PRIMITIVE_TOPOLOGY *outTopology) -{ - ASSERT(sourceSize.depth > 0 && destSize.depth > 0); - - float x1, y1, x2, y2, u1, v1, u2, v2; - GenerateVertexCoords(sourceArea, sourceSize, destArea, destSize, &x1, &y1, &x2, &y2, &u1, &v1, - &u2, &v2); - - d3d11::PositionLayerTexCoord3DVertex *vertices = - static_cast<d3d11::PositionLayerTexCoord3DVertex *>(outVertices); - - for (int i = 0; i < destSize.depth; i++) - { - float readDepth = (float)i / std::max(destSize.depth - 1, 1); - - d3d11::SetPositionLayerTexCoord3DVertex(&vertices[i * 6 + 0], x1, y1, i, u1, v2, readDepth); - d3d11::SetPositionLayerTexCoord3DVertex(&vertices[i * 6 + 1], x1, y2, i, u1, v1, readDepth); - d3d11::SetPositionLayerTexCoord3DVertex(&vertices[i * 6 + 2], x2, y1, i, u2, v2, readDepth); - - d3d11::SetPositionLayerTexCoord3DVertex(&vertices[i * 6 + 3], x1, y2, i, u1, v1, readDepth); - d3d11::SetPositionLayerTexCoord3DVertex(&vertices[i * 6 + 4], x2, y2, i, u2, v1, readDepth); - d3d11::SetPositionLayerTexCoord3DVertex(&vertices[i * 6 + 5], x2, y1, i, u2, v2, readDepth); - } - - *outStride = sizeof(d3d11::PositionLayerTexCoord3DVertex); - *outVertexCount = destSize.depth * 6; - *outTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; -} - -unsigned int GetSwizzleIndex(GLenum swizzle) -{ - unsigned int colorIndex = 0; - - switch (swizzle) - { - case GL_RED: - colorIndex = 0; - break; - case GL_GREEN: - colorIndex = 1; - break; - case GL_BLUE: - colorIndex = 2; - break; - case GL_ALPHA: - colorIndex = 3; - break; - case GL_ZERO: - colorIndex = 4; - break; - case GL_ONE: - colorIndex = 5; - break; - default: - UNREACHABLE(); - break; - } - - return colorIndex; -} - -D3D11_BLEND_DESC GetAlphaMaskBlendStateDesc() -{ - D3D11_BLEND_DESC desc; - memset(&desc, 0, sizeof(desc)); - desc.RenderTarget[0].BlendEnable = TRUE; - desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; - desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO; - desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO; - desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; - desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; - desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED | - D3D11_COLOR_WRITE_ENABLE_GREEN | - D3D11_COLOR_WRITE_ENABLE_BLUE; - return desc; -} - -D3D11_INPUT_ELEMENT_DESC quad2DLayout[] = { - {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, - {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0}, -}; - -D3D11_INPUT_ELEMENT_DESC quad3DLayout[] = { - {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, - {"LAYER", 0, DXGI_FORMAT_R32_UINT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0}, - {"TEXCOORD", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}, -}; - -DXGI_FORMAT GetStencilSRVFormat(const d3d11::Format &formatSet) -{ - switch (formatSet.texFormat) - { - case DXGI_FORMAT_R32G8X24_TYPELESS: - return DXGI_FORMAT_X32_TYPELESS_G8X24_UINT; - case DXGI_FORMAT_R24G8_TYPELESS: - return DXGI_FORMAT_X24_TYPELESS_G8_UINT; - default: - UNREACHABLE(); - return DXGI_FORMAT_UNKNOWN; - } -} - -} // namespace - -Blit11::Shader::Shader() = default; - -Blit11::Shader::Shader(Shader &&other) = default; - -Blit11::Shader::~Shader() = default; - -Blit11::Shader &Blit11::Shader::operator=(Blit11::Shader &&other) = default; - -Blit11::Blit11(Renderer11 *renderer) - : mRenderer(renderer), - mResourcesInitialized(false), - mVertexBuffer(), - mPointSampler(), - mLinearSampler(), - mScissorEnabledRasterizerState(), - mScissorDisabledRasterizerState(), - mDepthStencilState(), - mQuad2DIL(quad2DLayout, - ArraySize(quad2DLayout), - g_VS_Passthrough2D, - ArraySize(g_VS_Passthrough2D), - "Blit11 2D input layout"), - mQuad2DVS(g_VS_Passthrough2D, ArraySize(g_VS_Passthrough2D), "Blit11 2D vertex shader"), - mDepthPS(g_PS_PassthroughDepth2D, - ArraySize(g_PS_PassthroughDepth2D), - "Blit11 2D depth pixel shader"), - mQuad3DIL(quad3DLayout, - ArraySize(quad3DLayout), - g_VS_Passthrough3D, - ArraySize(g_VS_Passthrough3D), - "Blit11 3D input layout"), - mQuad3DVS(g_VS_Passthrough3D, ArraySize(g_VS_Passthrough3D), "Blit11 3D vertex shader"), - mQuad3DGS(g_GS_Passthrough3D, ArraySize(g_GS_Passthrough3D), "Blit11 3D geometry shader"), - mAlphaMaskBlendState(GetAlphaMaskBlendStateDesc(), "Blit11 Alpha Mask Blend"), - mSwizzleCB(), - mResolveDepthStencilVS(g_VS_ResolveDepthStencil, - ArraySize(g_VS_ResolveDepthStencil), - "Blit11::mResolveDepthStencilVS"), - mResolveDepthPS(g_PS_ResolveDepth, ArraySize(g_PS_ResolveDepth), "Blit11::mResolveDepthPS"), - mResolveDepthStencilPS(g_PS_ResolveDepthStencil, - ArraySize(g_PS_ResolveDepthStencil), - "Blit11::mResolveDepthStencilPS"), - mResolveStencilPS(g_PS_ResolveStencil, - ArraySize(g_PS_ResolveStencil), - "Blit11::mResolveStencilPS"), - mStencilSRV(), - mResolvedDepthStencilRTView() -{ -} - -Blit11::~Blit11() -{ -} - -gl::Error Blit11::initResources() -{ - if (mResourcesInitialized) - { - return gl::NoError(); - } - - TRACE_EVENT0("gpu.angle", "Blit11::initResources"); - - D3D11_BUFFER_DESC vbDesc; - vbDesc.ByteWidth = - static_cast<unsigned int>(std::max(sizeof(d3d11::PositionLayerTexCoord3DVertex), - sizeof(d3d11::PositionTexCoordVertex)) * - 6 * mRenderer->getNativeCaps().max3DTextureSize); - vbDesc.Usage = D3D11_USAGE_DYNAMIC; - vbDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - vbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - vbDesc.MiscFlags = 0; - vbDesc.StructureByteStride = 0; - - ANGLE_TRY(mRenderer->allocateResource(vbDesc, &mVertexBuffer)); - mVertexBuffer.setDebugName("Blit11 vertex buffer"); - - D3D11_SAMPLER_DESC pointSamplerDesc; - pointSamplerDesc.Filter = D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR; - pointSamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - pointSamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - pointSamplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; - pointSamplerDesc.MipLODBias = 0.0f; - pointSamplerDesc.MaxAnisotropy = 0; - pointSamplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; - pointSamplerDesc.BorderColor[0] = 0.0f; - pointSamplerDesc.BorderColor[1] = 0.0f; - pointSamplerDesc.BorderColor[2] = 0.0f; - pointSamplerDesc.BorderColor[3] = 0.0f; - pointSamplerDesc.MinLOD = 0.0f; - pointSamplerDesc.MaxLOD = FLT_MAX; - - ANGLE_TRY(mRenderer->allocateResource(pointSamplerDesc, &mPointSampler)); - mPointSampler.setDebugName("Blit11 point sampler"); - - D3D11_SAMPLER_DESC linearSamplerDesc; - linearSamplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; - linearSamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - linearSamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - linearSamplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; - linearSamplerDesc.MipLODBias = 0.0f; - linearSamplerDesc.MaxAnisotropy = 0; - linearSamplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; - linearSamplerDesc.BorderColor[0] = 0.0f; - linearSamplerDesc.BorderColor[1] = 0.0f; - linearSamplerDesc.BorderColor[2] = 0.0f; - linearSamplerDesc.BorderColor[3] = 0.0f; - linearSamplerDesc.MinLOD = 0.0f; - linearSamplerDesc.MaxLOD = FLT_MAX; - - ANGLE_TRY(mRenderer->allocateResource(linearSamplerDesc, &mLinearSampler)); - mLinearSampler.setDebugName("Blit11 linear sampler"); - - // Use a rasterizer state that will not cull so that inverted quads will not be culled - D3D11_RASTERIZER_DESC rasterDesc; - rasterDesc.FillMode = D3D11_FILL_SOLID; - rasterDesc.CullMode = D3D11_CULL_NONE; - rasterDesc.FrontCounterClockwise = FALSE; - rasterDesc.DepthBias = 0; - rasterDesc.SlopeScaledDepthBias = 0.0f; - rasterDesc.DepthBiasClamp = 0.0f; - rasterDesc.DepthClipEnable = TRUE; - rasterDesc.MultisampleEnable = FALSE; - rasterDesc.AntialiasedLineEnable = FALSE; - - rasterDesc.ScissorEnable = TRUE; - ANGLE_TRY(mRenderer->allocateResource(rasterDesc, &mScissorEnabledRasterizerState)); - mScissorEnabledRasterizerState.setDebugName("Blit11 scissoring rasterizer state"); - - rasterDesc.ScissorEnable = FALSE; - ANGLE_TRY(mRenderer->allocateResource(rasterDesc, &mScissorDisabledRasterizerState)); - mScissorDisabledRasterizerState.setDebugName("Blit11 no scissoring rasterizer state"); - - D3D11_DEPTH_STENCIL_DESC depthStencilDesc; - depthStencilDesc.DepthEnable = TRUE; - depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; - depthStencilDesc.DepthFunc = D3D11_COMPARISON_ALWAYS; - depthStencilDesc.StencilEnable = FALSE; - depthStencilDesc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK; - depthStencilDesc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK; - depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; - depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; - depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; - depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; - - ANGLE_TRY(mRenderer->allocateResource(depthStencilDesc, &mDepthStencilState)); - mDepthStencilState.setDebugName("Blit11 depth stencil state"); - - D3D11_BUFFER_DESC swizzleBufferDesc; - swizzleBufferDesc.ByteWidth = sizeof(unsigned int) * 4; - swizzleBufferDesc.Usage = D3D11_USAGE_DYNAMIC; - swizzleBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - swizzleBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - swizzleBufferDesc.MiscFlags = 0; - swizzleBufferDesc.StructureByteStride = 0; - - ANGLE_TRY(mRenderer->allocateResource(swizzleBufferDesc, &mSwizzleCB)); - mSwizzleCB.setDebugName("Blit11 swizzle constant buffer"); - - mResourcesInitialized = true; - - return gl::NoError(); -} - -// static -Blit11::BlitShaderType Blit11::GetBlitShaderType(GLenum destinationFormat, - GLenum sourceFormat, - bool isSigned, - bool unpackPremultiplyAlpha, - bool unpackUnmultiplyAlpha, - ShaderDimension dimension) -{ - if (dimension == SHADER_3D) - { - ASSERT(!unpackPremultiplyAlpha && !unpackUnmultiplyAlpha); - - if (isSigned) - { - switch (destinationFormat) - { - case GL_RGBA_INTEGER: - return BLITSHADER_3D_RGBAI; - case GL_RGB_INTEGER: - return BLITSHADER_3D_RGBI; - case GL_RG_INTEGER: - return BLITSHADER_3D_RGI; - case GL_RED_INTEGER: - return BLITSHADER_3D_RI; - default: - UNREACHABLE(); - return BLITSHADER_INVALID; - } - } - else - { - switch (destinationFormat) - { - case GL_RGBA: - return BLITSHADER_3D_RGBAF; - case GL_RGBA_INTEGER: - return BLITSHADER_3D_RGBAUI; - case GL_BGRA_EXT: - return BLITSHADER_3D_BGRAF; - case GL_RGB: - return BLITSHADER_3D_RGBF; - case GL_RGB_INTEGER: - return BLITSHADER_3D_RGBUI; - case GL_RG: - return BLITSHADER_3D_RGF; - case GL_RG_INTEGER: - return BLITSHADER_3D_RGUI; - case GL_RED: - return BLITSHADER_3D_RF; - case GL_RED_INTEGER: - return BLITSHADER_3D_RUI; - case GL_ALPHA: - return BLITSHADER_3D_ALPHA; - case GL_LUMINANCE: - return BLITSHADER_3D_LUMA; - case GL_LUMINANCE_ALPHA: - return BLITSHADER_3D_LUMAALPHA; - default: - UNREACHABLE(); - return BLITSHADER_INVALID; - } - } - } - else if (isSigned) - { - ASSERT(!unpackPremultiplyAlpha && !unpackUnmultiplyAlpha); - - switch (destinationFormat) - { - case GL_RGBA_INTEGER: - return BLITSHADER_2D_RGBAI; - case GL_RGB_INTEGER: - return BLITSHADER_2D_RGBI; - case GL_RG_INTEGER: - return BLITSHADER_2D_RGI; - case GL_RED_INTEGER: - return BLITSHADER_2D_RI; - default: - UNREACHABLE(); - return BLITSHADER_INVALID; - } - } - else - { - bool floatToIntBlit = - !gl::IsIntegerFormat(sourceFormat) && gl::IsIntegerFormat(destinationFormat); - if (unpackPremultiplyAlpha != unpackUnmultiplyAlpha || floatToIntBlit) - { - switch (destinationFormat) - { - case GL_RGBA: - case GL_BGRA_EXT: - ASSERT(!floatToIntBlit); - return unpackPremultiplyAlpha ? BLITSHADER_2D_RGBAF_PREMULTIPLY - : BLITSHADER_2D_RGBAF_UNMULTIPLY; - - case GL_RGB: - case GL_RG: - case GL_RED: - ASSERT(!floatToIntBlit); - return unpackPremultiplyAlpha ? BLITSHADER_2D_RGBF_PREMULTIPLY - : BLITSHADER_2D_RGBF_UNMULTIPLY; - - case GL_RGBA_INTEGER: - if (unpackPremultiplyAlpha == unpackUnmultiplyAlpha) - { - return BLITSHADER_2D_RGBAF_TOUI; - } - else - { - return unpackPremultiplyAlpha ? BLITSHADER_2D_RGBAF_TOUI_PREMULTIPLY - : BLITSHADER_2D_RGBAF_TOUI_UNMULTIPLY; - } - - case GL_RGB_INTEGER: - case GL_RG_INTEGER: - case GL_RED_INTEGER: - if (unpackPremultiplyAlpha == unpackUnmultiplyAlpha) - { - return BLITSHADER_2D_RGBF_TOUI; - } - else - { - return unpackPremultiplyAlpha ? BLITSHADER_2D_RGBF_TOUI_PREMULTIPLY - : BLITSHADER_2D_RGBF_TOUI_UNMULTIPLY; - } - case GL_LUMINANCE: - ASSERT(!floatToIntBlit); - return unpackPremultiplyAlpha ? BLITSHADER_2D_LUMAF_PREMULTIPLY - : BLITSHADER_2D_LUMAF_UNMULTIPLY; - case GL_LUMINANCE_ALPHA: - ASSERT(!floatToIntBlit); - return unpackPremultiplyAlpha ? BLITSHADER_2D_LUMAALPHAF_PREMULTIPLY - : BLITSHADER_2D_LUMAALPHAF_UNMULTIPLY; - case GL_ALPHA: - ASSERT(!floatToIntBlit); - return BLITSHADER_2D_ALPHA; - default: - UNREACHABLE(); - return BLITSHADER_INVALID; - } - } - else - { - switch (destinationFormat) - { - case GL_RGBA: - return BLITSHADER_2D_RGBAF; - case GL_RGBA_INTEGER: - return BLITSHADER_2D_RGBAUI; - case GL_BGRA_EXT: - return BLITSHADER_2D_BGRAF; - case GL_RGB: - return BLITSHADER_2D_RGBF; - case GL_RGB_INTEGER: - return BLITSHADER_2D_RGBUI; - case GL_RG: - return BLITSHADER_2D_RGF; - case GL_RG_INTEGER: - return BLITSHADER_2D_RGUI; - case GL_RED: - return BLITSHADER_2D_RF; - case GL_RED_INTEGER: - return BLITSHADER_2D_RUI; - case GL_ALPHA: - return BLITSHADER_2D_ALPHA; - case GL_LUMINANCE: - return BLITSHADER_2D_LUMA; - case GL_LUMINANCE_ALPHA: - return BLITSHADER_2D_LUMAALPHA; - default: - UNREACHABLE(); - return BLITSHADER_INVALID; - } - } - } -} - -// static -Blit11::SwizzleShaderType Blit11::GetSwizzleShaderType(GLenum type, - D3D11_SRV_DIMENSION dimensionality) -{ - switch (dimensionality) - { - case D3D11_SRV_DIMENSION_TEXTURE2D: - switch (type) - { - case GL_FLOAT: - return SWIZZLESHADER_2D_FLOAT; - case GL_UNSIGNED_INT: - return SWIZZLESHADER_2D_UINT; - case GL_INT: - return SWIZZLESHADER_2D_INT; - default: - UNREACHABLE(); - return SWIZZLESHADER_INVALID; - } - case D3D11_SRV_DIMENSION_TEXTURECUBE: - switch (type) - { - case GL_FLOAT: - return SWIZZLESHADER_CUBE_FLOAT; - case GL_UNSIGNED_INT: - return SWIZZLESHADER_CUBE_UINT; - case GL_INT: - return SWIZZLESHADER_CUBE_INT; - default: - UNREACHABLE(); - return SWIZZLESHADER_INVALID; - } - case D3D11_SRV_DIMENSION_TEXTURE3D: - switch (type) - { - case GL_FLOAT: - return SWIZZLESHADER_3D_FLOAT; - case GL_UNSIGNED_INT: - return SWIZZLESHADER_3D_UINT; - case GL_INT: - return SWIZZLESHADER_3D_INT; - default: - UNREACHABLE(); - return SWIZZLESHADER_INVALID; - } - case D3D11_SRV_DIMENSION_TEXTURE2DARRAY: - switch (type) - { - case GL_FLOAT: - return SWIZZLESHADER_ARRAY_FLOAT; - case GL_UNSIGNED_INT: - return SWIZZLESHADER_ARRAY_UINT; - case GL_INT: - return SWIZZLESHADER_ARRAY_INT; - default: - UNREACHABLE(); - return SWIZZLESHADER_INVALID; - } - default: - UNREACHABLE(); - return SWIZZLESHADER_INVALID; - } -} - -gl::Error Blit11::getShaderSupport(const Shader &shader, Blit11::ShaderSupport *supportOut) -{ - if (shader.dimension == SHADER_2D) - { - ANGLE_TRY(mQuad2DIL.resolve(mRenderer)); - ANGLE_TRY(mQuad2DVS.resolve(mRenderer)); - supportOut->inputLayout = &mQuad2DIL.getObj(); - supportOut->vertexShader = &mQuad2DVS.getObj(); - supportOut->geometryShader = nullptr; - supportOut->vertexWriteFunction = Write2DVertices; - } - else - { - ASSERT(shader.dimension == SHADER_3D); - ANGLE_TRY(mQuad3DIL.resolve(mRenderer)); - ANGLE_TRY(mQuad3DVS.resolve(mRenderer)); - ANGLE_TRY(mQuad3DGS.resolve(mRenderer)); - supportOut->inputLayout = &mQuad2DIL.getObj(); - supportOut->vertexShader = &mQuad3DVS.getObj(); - supportOut->geometryShader = &mQuad3DGS.getObj(); - supportOut->vertexWriteFunction = Write3DVertices; - } - - return gl::NoError(); -} - -gl::Error Blit11::swizzleTexture(const gl::Context *context, - const d3d11::SharedSRV &source, - const d3d11::RenderTargetView &dest, - const gl::Extents &size, - const gl::SwizzleState &swizzleTarget) -{ - ANGLE_TRY(initResources()); - - HRESULT result; - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - D3D11_SHADER_RESOURCE_VIEW_DESC sourceSRVDesc; - source.get()->GetDesc(&sourceSRVDesc); - - GLenum componentType = d3d11::GetComponentType(sourceSRVDesc.Format); - if (componentType == GL_NONE) - { - // We're swizzling the depth component of a depth-stencil texture. - switch (sourceSRVDesc.Format) - { - case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: - componentType = GL_UNSIGNED_NORMALIZED; - break; - case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: - componentType = GL_FLOAT; - break; - default: - UNREACHABLE(); - break; - } - } - - GLenum shaderType = GL_NONE; - switch (componentType) - { - case GL_UNSIGNED_NORMALIZED: - case GL_SIGNED_NORMALIZED: - case GL_FLOAT: - shaderType = GL_FLOAT; - break; - case GL_INT: - shaderType = GL_INT; - break; - case GL_UNSIGNED_INT: - shaderType = GL_UNSIGNED_INT; - break; - default: - UNREACHABLE(); - break; - } - - const Shader *shader = nullptr; - ANGLE_TRY(getSwizzleShader(shaderType, sourceSRVDesc.ViewDimension, &shader)); - - // Set vertices - D3D11_MAPPED_SUBRESOURCE mappedResource; - result = - deviceContext->Map(mVertexBuffer.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - if (FAILED(result)) - { - return gl::OutOfMemory() << "Failed to map internal vertex buffer for swizzle, " - << gl::FmtHR(result); - } - - ShaderSupport support; - ANGLE_TRY(getShaderSupport(*shader, &support)); - - UINT stride = 0; - UINT drawCount = 0; - D3D11_PRIMITIVE_TOPOLOGY topology; - - gl::Box area(0, 0, 0, size.width, size.height, size.depth); - support.vertexWriteFunction(area, size, area, size, mappedResource.pData, &stride, &drawCount, - &topology); - - deviceContext->Unmap(mVertexBuffer.get(), 0); - - // Set constant buffer - result = deviceContext->Map(mSwizzleCB.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - if (FAILED(result)) - { - return gl::OutOfMemory() << "Failed to map internal constant buffer for swizzle, " - << gl::FmtHR(result); - } - - unsigned int *swizzleIndices = reinterpret_cast<unsigned int *>(mappedResource.pData); - swizzleIndices[0] = GetSwizzleIndex(swizzleTarget.swizzleRed); - swizzleIndices[1] = GetSwizzleIndex(swizzleTarget.swizzleGreen); - swizzleIndices[2] = GetSwizzleIndex(swizzleTarget.swizzleBlue); - swizzleIndices[3] = GetSwizzleIndex(swizzleTarget.swizzleAlpha); - - deviceContext->Unmap(mSwizzleCB.get(), 0); - - StateManager11 *stateManager = mRenderer->getStateManager(); - - // Apply vertex buffer - stateManager->setSingleVertexBuffer(&mVertexBuffer, stride, 0); - - // Apply constant buffer - stateManager->setPixelConstantBuffer(0, &mSwizzleCB); - - // Apply state - stateManager->setSimpleBlendState(nullptr); - stateManager->setDepthStencilState(nullptr, 0xFFFFFFFF); - stateManager->setRasterizerState(&mScissorDisabledRasterizerState); - - // Apply shaders - stateManager->setInputLayout(support.inputLayout); - stateManager->setPrimitiveTopology(topology); - - stateManager->setDrawShaders(support.vertexShader, support.geometryShader, - &shader->pixelShader); - - // Apply render target - stateManager->setRenderTarget(dest.get(), nullptr); - - // Set the viewport - stateManager->setSimpleViewport(size); - - // Apply textures and sampler - stateManager->setSimplePixelTextureAndSampler(source, mPointSampler); - - // Draw the quad - deviceContext->Draw(drawCount, 0); - - return gl::NoError(); -} - -gl::Error Blit11::copyTexture(const gl::Context *context, - const d3d11::SharedSRV &source, - const gl::Box &sourceArea, - const gl::Extents &sourceSize, - GLenum sourceFormat, - const d3d11::RenderTargetView &dest, - const gl::Box &destArea, - const gl::Extents &destSize, - const gl::Rectangle *scissor, - GLenum destFormat, - GLenum filter, - bool maskOffAlpha, - bool unpackPremultiplyAlpha, - bool unpackUnmultiplyAlpha) -{ - ANGLE_TRY(initResources()); - - HRESULT result; - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - // Determine if the source format is a signed integer format, the destFormat will already - // be GL_XXXX_INTEGER but it does not tell us if it is signed or unsigned. - D3D11_SHADER_RESOURCE_VIEW_DESC sourceSRVDesc; - source.get()->GetDesc(&sourceSRVDesc); - - GLenum componentType = d3d11::GetComponentType(sourceSRVDesc.Format); - - ASSERT(componentType != GL_NONE); - ASSERT(componentType != GL_SIGNED_NORMALIZED); - bool isSigned = (componentType == GL_INT); - - ShaderDimension dimension = - (sourceSRVDesc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE3D) ? SHADER_3D : SHADER_2D; - - const Shader *shader = nullptr; - ANGLE_TRY(getBlitShader(destFormat, sourceFormat, isSigned, unpackPremultiplyAlpha, - unpackUnmultiplyAlpha, dimension, &shader)); - - ShaderSupport support; - ANGLE_TRY(getShaderSupport(*shader, &support)); - - // Set vertices - D3D11_MAPPED_SUBRESOURCE mappedResource; - result = - deviceContext->Map(mVertexBuffer.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - if (FAILED(result)) - { - return gl::OutOfMemory() << "Failed to map internal vertex buffer for texture copy, " - << gl::FmtHR(result); - } - - UINT stride = 0; - UINT drawCount = 0; - D3D11_PRIMITIVE_TOPOLOGY topology; - - support.vertexWriteFunction(sourceArea, sourceSize, destArea, destSize, mappedResource.pData, - &stride, &drawCount, &topology); - - deviceContext->Unmap(mVertexBuffer.get(), 0); - - StateManager11 *stateManager = mRenderer->getStateManager(); - - // Apply vertex buffer - stateManager->setSingleVertexBuffer(&mVertexBuffer, stride, 0); - - // Apply state - if (maskOffAlpha) - { - ANGLE_TRY(mAlphaMaskBlendState.resolve(mRenderer)); - stateManager->setSimpleBlendState(&mAlphaMaskBlendState.getObj()); - } - else - { - stateManager->setSimpleBlendState(nullptr); - } - stateManager->setDepthStencilState(nullptr, 0xFFFFFFFF); - - if (scissor) - { - stateManager->setSimpleScissorRect(*scissor); - stateManager->setRasterizerState(&mScissorEnabledRasterizerState); - } - else - { - stateManager->setRasterizerState(&mScissorDisabledRasterizerState); - } - - // Apply shaders - stateManager->setInputLayout(support.inputLayout); - stateManager->setPrimitiveTopology(topology); - - stateManager->setDrawShaders(support.vertexShader, support.geometryShader, - &shader->pixelShader); - - // Apply render target - stateManager->setRenderTarget(dest.get(), nullptr); - - // Set the viewport - stateManager->setSimpleViewport(destSize); - - // Apply texture and sampler - switch (filter) - { - case GL_NEAREST: - stateManager->setSimplePixelTextureAndSampler(source, mPointSampler); - break; - case GL_LINEAR: - stateManager->setSimplePixelTextureAndSampler(source, mLinearSampler); - break; - - default: - UNREACHABLE(); - return gl::InternalError() << "Internal error, unknown blit filter mode."; - } - - // Draw the quad - deviceContext->Draw(drawCount, 0); - - return gl::NoError(); -} - -gl::Error Blit11::copyStencil(const gl::Context *context, - const TextureHelper11 &source, - unsigned int sourceSubresource, - const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const TextureHelper11 &dest, - unsigned int destSubresource, - const gl::Box &destArea, - const gl::Extents &destSize, - const gl::Rectangle *scissor) -{ - return copyDepthStencilImpl(source, sourceSubresource, sourceArea, sourceSize, dest, - destSubresource, destArea, destSize, scissor, true); -} - -gl::Error Blit11::copyDepth(const gl::Context *context, - const d3d11::SharedSRV &source, - const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const d3d11::DepthStencilView &dest, - const gl::Box &destArea, - const gl::Extents &destSize, - const gl::Rectangle *scissor) -{ - ANGLE_TRY(initResources()); - - HRESULT result; - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - // Set vertices - D3D11_MAPPED_SUBRESOURCE mappedResource; - result = - deviceContext->Map(mVertexBuffer.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - if (FAILED(result)) - { - return gl::OutOfMemory() << "Failed to map internal vertex buffer for texture copy, " - << gl::FmtHR(result); - } - - UINT stride = 0; - UINT drawCount = 0; - D3D11_PRIMITIVE_TOPOLOGY topology; - - Write2DVertices(sourceArea, sourceSize, destArea, destSize, mappedResource.pData, &stride, - &drawCount, &topology); - - deviceContext->Unmap(mVertexBuffer.get(), 0); - - StateManager11 *stateManager = mRenderer->getStateManager(); - - // Apply vertex buffer - stateManager->setSingleVertexBuffer(&mVertexBuffer, stride, 0); - - // Apply state - stateManager->setSimpleBlendState(nullptr); - stateManager->setDepthStencilState(&mDepthStencilState, 0xFFFFFFFF); - - if (scissor) - { - stateManager->setSimpleScissorRect(*scissor); - stateManager->setRasterizerState(&mScissorEnabledRasterizerState); - } - else - { - stateManager->setRasterizerState(&mScissorDisabledRasterizerState); - } - - ANGLE_TRY(mQuad2DIL.resolve(mRenderer)); - ANGLE_TRY(mQuad2DVS.resolve(mRenderer)); - ANGLE_TRY(mDepthPS.resolve(mRenderer)); - - // Apply shaders - stateManager->setInputLayout(&mQuad2DIL.getObj()); - stateManager->setPrimitiveTopology(topology); - - stateManager->setDrawShaders(&mQuad2DVS.getObj(), nullptr, &mDepthPS.getObj()); - - // Apply render target - stateManager->setRenderTarget(nullptr, dest.get()); - - // Set the viewport - stateManager->setSimpleViewport(destSize); - - // Apply texture and sampler - stateManager->setSimplePixelTextureAndSampler(source, mPointSampler); - - // Draw the quad - deviceContext->Draw(drawCount, 0); - - return gl::NoError(); -} - -gl::Error Blit11::copyDepthStencil(const TextureHelper11 &source, - unsigned int sourceSubresource, - const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const TextureHelper11 &dest, - unsigned int destSubresource, - const gl::Box &destArea, - const gl::Extents &destSize, - const gl::Rectangle *scissor) -{ - return copyDepthStencilImpl(source, sourceSubresource, sourceArea, sourceSize, dest, - destSubresource, destArea, destSize, scissor, false); -} - -gl::Error Blit11::copyDepthStencilImpl(const TextureHelper11 &source, - unsigned int sourceSubresource, - const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const TextureHelper11 &dest, - unsigned int destSubresource, - const gl::Box &destArea, - const gl::Extents &destSize, - const gl::Rectangle *scissor, - bool stencilOnly) -{ - auto srcDXGIFormat = source.getFormat(); - const auto &srcSizeInfo = d3d11::GetDXGIFormatSizeInfo(srcDXGIFormat); - unsigned int srcPixelSize = srcSizeInfo.pixelBytes; - unsigned int copyOffset = 0; - unsigned int copySize = srcPixelSize; - auto destDXGIFormat = dest.getFormat(); - const auto &destSizeInfo = d3d11::GetDXGIFormatSizeInfo(destDXGIFormat); - unsigned int destPixelSize = destSizeInfo.pixelBytes; - - ASSERT(srcDXGIFormat == destDXGIFormat || destDXGIFormat == DXGI_FORMAT_R32_TYPELESS); - - if (stencilOnly) - { - const auto &srcFormat = source.getFormatSet().format(); - - // Stencil channel should be right after the depth channel. Some views to depth/stencil - // resources have red channel for depth, in which case the depth channel bit width is in - // redBits. - ASSERT((srcFormat.redBits != 0) != (srcFormat.depthBits != 0)); - GLuint depthBits = srcFormat.redBits + srcFormat.depthBits; - // Known formats have either 24 or 32 bits of depth. - ASSERT(depthBits == 24 || depthBits == 32); - copyOffset = depthBits / 8; - - // Stencil is assumed to be 8-bit - currently this is true for all possible formats. - copySize = 1; - } - - if (srcDXGIFormat != destDXGIFormat) - { - if (srcDXGIFormat == DXGI_FORMAT_R24G8_TYPELESS) - { - ASSERT(sourceArea == destArea && sourceSize == destSize && scissor == nullptr); - return copyAndConvert(source, sourceSubresource, sourceArea, sourceSize, dest, - destSubresource, destArea, destSize, scissor, copyOffset, - copyOffset, copySize, srcPixelSize, destPixelSize, - BlitD24S8ToD32F); - } - ASSERT(srcDXGIFormat == DXGI_FORMAT_R32G8X24_TYPELESS); - return copyAndConvert(source, sourceSubresource, sourceArea, sourceSize, dest, - destSubresource, destArea, destSize, scissor, copyOffset, copyOffset, - copySize, srcPixelSize, destPixelSize, BlitD32FS8ToD32F); - } - - return copyAndConvert(source, sourceSubresource, sourceArea, sourceSize, dest, destSubresource, - destArea, destSize, scissor, copyOffset, copyOffset, copySize, - srcPixelSize, destPixelSize, StretchedBlitNearest); -} - -gl::Error Blit11::copyAndConvertImpl(const TextureHelper11 &source, - unsigned int sourceSubresource, - const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const TextureHelper11 &destStaging, - const gl::Box &destArea, - const gl::Extents &destSize, - const gl::Rectangle *scissor, - size_t readOffset, - size_t writeOffset, - size_t copySize, - size_t srcPixelStride, - size_t destPixelStride, - BlitConvertFunction *convertFunction) -{ - ANGLE_TRY(initResources()); - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - TextureHelper11 sourceStaging; - ANGLE_TRY_RESULT(mRenderer->createStagingTexture(ResourceType::Texture2D, source.getFormatSet(), - sourceSize, StagingAccess::READ), - sourceStaging); - - deviceContext->CopySubresourceRegion(sourceStaging.get(), 0, 0, 0, 0, source.get(), - sourceSubresource, nullptr); - - D3D11_MAPPED_SUBRESOURCE sourceMapping; - HRESULT result = deviceContext->Map(sourceStaging.get(), 0, D3D11_MAP_READ, 0, &sourceMapping); - if (FAILED(result)) - { - return gl::OutOfMemory() - << "Failed to map internal source staging texture for depth stencil blit, " - << gl::FmtHR(result); - } - - D3D11_MAPPED_SUBRESOURCE destMapping; - result = deviceContext->Map(destStaging.get(), 0, D3D11_MAP_WRITE, 0, &destMapping); - if (FAILED(result)) - { - deviceContext->Unmap(sourceStaging.get(), 0); - return gl::OutOfMemory() - << "Failed to map internal destination staging texture for depth stencil blit, " - << gl::FmtHR(result); - } - - // Clip dest area to the destination size - gl::Rectangle clipRect = gl::Rectangle(0, 0, destSize.width, destSize.height); - - // Clip dest area to the scissor - if (scissor) - { - gl::ClipRectangle(clipRect, *scissor, &clipRect); - } - - convertFunction(sourceArea, destArea, clipRect, sourceSize, sourceMapping.RowPitch, - destMapping.RowPitch, readOffset, writeOffset, copySize, srcPixelStride, - destPixelStride, static_cast<const uint8_t *>(sourceMapping.pData), - static_cast<uint8_t *>(destMapping.pData)); - - deviceContext->Unmap(sourceStaging.get(), 0); - deviceContext->Unmap(destStaging.get(), 0); - - return gl::NoError(); -} - -gl::Error Blit11::copyAndConvert(const TextureHelper11 &source, - unsigned int sourceSubresource, - const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const TextureHelper11 &dest, - unsigned int destSubresource, - const gl::Box &destArea, - const gl::Extents &destSize, - const gl::Rectangle *scissor, - size_t readOffset, - size_t writeOffset, - size_t copySize, - size_t srcPixelStride, - size_t destPixelStride, - BlitConvertFunction *convertFunction) -{ - ANGLE_TRY(initResources()); - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - // HACK: Create the destination staging buffer as a read/write texture so - // ID3D11DevicContext::UpdateSubresource can be called - // using it's mapped data as a source - TextureHelper11 destStaging; - ANGLE_TRY_RESULT(mRenderer->createStagingTexture(ResourceType::Texture2D, dest.getFormatSet(), - destSize, StagingAccess::READ_WRITE), - destStaging); - - deviceContext->CopySubresourceRegion(destStaging.get(), 0, 0, 0, 0, dest.get(), destSubresource, - nullptr); - - ANGLE_TRY(copyAndConvertImpl(source, sourceSubresource, sourceArea, sourceSize, destStaging, - destArea, destSize, scissor, readOffset, writeOffset, copySize, - srcPixelStride, destPixelStride, convertFunction)); - - // Work around timeouts/TDRs in older NVIDIA drivers. - if (mRenderer->getWorkarounds().depthStencilBlitExtraCopy) - { - D3D11_MAPPED_SUBRESOURCE mapped; - deviceContext->Map(destStaging.get(), 0, D3D11_MAP_READ, 0, &mapped); - deviceContext->UpdateSubresource(dest.get(), destSubresource, nullptr, mapped.pData, - mapped.RowPitch, mapped.DepthPitch); - deviceContext->Unmap(destStaging.get(), 0); - } - else - { - deviceContext->CopySubresourceRegion(dest.get(), destSubresource, 0, 0, 0, - destStaging.get(), 0, nullptr); - } - - return gl::NoError(); -} - -gl::Error Blit11::addBlitShaderToMap(BlitShaderType blitShaderType, - ShaderDimension dimension, - const ShaderData &shaderData, - const char *name) -{ - ASSERT(mBlitShaderMap.find(blitShaderType) == mBlitShaderMap.end()); - - d3d11::PixelShader ps; - ANGLE_TRY(mRenderer->allocateResource(shaderData, &ps)); - ps.setDebugName(name); - - Shader shader; - shader.dimension = dimension; - shader.pixelShader = std::move(ps); - - mBlitShaderMap[blitShaderType] = std::move(shader); - return gl::NoError(); -} - -gl::Error Blit11::addSwizzleShaderToMap(SwizzleShaderType swizzleShaderType, - ShaderDimension dimension, - const ShaderData &shaderData, - const char *name) -{ - ASSERT(mSwizzleShaderMap.find(swizzleShaderType) == mSwizzleShaderMap.end()); - - d3d11::PixelShader ps; - ANGLE_TRY(mRenderer->allocateResource(shaderData, &ps)); - ps.setDebugName(name); - - Shader shader; - shader.dimension = dimension; - shader.pixelShader = std::move(ps); - - mSwizzleShaderMap[swizzleShaderType] = std::move(shader); - return gl::NoError(); -} - -void Blit11::clearShaderMap() -{ - mBlitShaderMap.clear(); - mSwizzleShaderMap.clear(); -} - -gl::Error Blit11::getBlitShader(GLenum destFormat, - GLenum sourceFormat, - bool isSigned, - bool unpackPremultiplyAlpha, - bool unpackUnmultiplyAlpha, - ShaderDimension dimension, - const Shader **shader) -{ - BlitShaderType blitShaderType = - GetBlitShaderType(destFormat, sourceFormat, isSigned, unpackPremultiplyAlpha, - unpackUnmultiplyAlpha, dimension); - - if (blitShaderType == BLITSHADER_INVALID) - { - return gl::InternalError() << "Internal blit shader type mismatch"; - } - - auto blitShaderIt = mBlitShaderMap.find(blitShaderType); - if (blitShaderIt != mBlitShaderMap.end()) - { - *shader = &blitShaderIt->second; - return gl::NoError(); - } - - ASSERT(dimension == SHADER_2D || mRenderer->isES3Capable()); - - switch (blitShaderType) - { - case BLITSHADER_2D_RGBAF: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_PassthroughRGBA2D), - "Blit11 2D RGBA pixel shader")); - break; - case BLITSHADER_2D_BGRAF: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_PassthroughRGBA2D), - "Blit11 2D BGRA pixel shader")); - break; - case BLITSHADER_2D_RGBF: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_PassthroughRGB2D), - "Blit11 2D RGB pixel shader")); - break; - case BLITSHADER_2D_RGF: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_PassthroughRG2D), - "Blit11 2D RG pixel shader")); - break; - case BLITSHADER_2D_RF: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, ShaderData(g_PS_PassthroughR2D), - "Blit11 2D R pixel shader")); - break; - case BLITSHADER_2D_ALPHA: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, ShaderData(g_PS_PassthroughA2D), - "Blit11 2D alpha pixel shader")); - break; - case BLITSHADER_2D_LUMA: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_PassthroughLum2D), - "Blit11 2D lum pixel shader")); - break; - case BLITSHADER_2D_LUMAALPHA: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_PassthroughLumAlpha2D), - "Blit11 2D luminance alpha pixel shader")); - break; - case BLITSHADER_2D_RGBAUI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_PassthroughRGBA2DUI), - "Blit11 2D RGBA UI pixel shader")); - break; - case BLITSHADER_2D_RGBAI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_PassthroughRGBA2DI), - "Blit11 2D RGBA I pixel shader")); - break; - case BLITSHADER_2D_RGBUI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_PassthroughRGB2DUI), - "Blit11 2D RGB UI pixel shader")); - break; - case BLITSHADER_2D_RGBI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_PassthroughRGB2DI), - "Blit11 2D RGB I pixel shader")); - break; - case BLITSHADER_2D_RGUI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_PassthroughRG2DUI), - "Blit11 2D RG UI pixel shader")); - break; - case BLITSHADER_2D_RGI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_PassthroughRG2DI), - "Blit11 2D RG I pixel shader")); - break; - case BLITSHADER_2D_RUI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_PassthroughR2DUI), - "Blit11 2D R UI pixel shader")); - break; - case BLITSHADER_2D_RI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_PassthroughR2DI), - "Blit11 2D R I pixel shader")); - break; - case BLITSHADER_3D_RGBAF: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, - ShaderData(g_PS_PassthroughRGBA3D), - "Blit11 3D RGBA pixel shader")); - break; - case BLITSHADER_3D_RGBAUI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, - ShaderData(g_PS_PassthroughRGBA3DUI), - "Blit11 3D UI RGBA pixel shader")); - break; - case BLITSHADER_3D_RGBAI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, - ShaderData(g_PS_PassthroughRGBA3DI), - "Blit11 3D I RGBA pixel shader")); - break; - case BLITSHADER_3D_BGRAF: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, - ShaderData(g_PS_PassthroughRGBA3D), - "Blit11 3D BGRA pixel shader")); - break; - case BLITSHADER_3D_RGBF: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, - ShaderData(g_PS_PassthroughRGB3D), - "Blit11 3D RGB pixel shader")); - break; - case BLITSHADER_3D_RGBUI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, - ShaderData(g_PS_PassthroughRGB3DUI), - "Blit11 3D RGB UI pixel shader")); - break; - case BLITSHADER_3D_RGBI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, - ShaderData(g_PS_PassthroughRGB3DI), - "Blit11 3D RGB I pixel shader")); - break; - case BLITSHADER_3D_RGF: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, - ShaderData(g_PS_PassthroughRG3D), - "Blit11 3D RG pixel shader")); - break; - case BLITSHADER_3D_RGUI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, - ShaderData(g_PS_PassthroughRG3DUI), - "Blit11 3D RG UI pixel shader")); - break; - case BLITSHADER_3D_RGI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, - ShaderData(g_PS_PassthroughRG3DI), - "Blit11 3D RG I pixel shader")); - break; - case BLITSHADER_3D_RF: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, ShaderData(g_PS_PassthroughR3D), - "Blit11 3D R pixel shader")); - break; - case BLITSHADER_3D_RUI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, - ShaderData(g_PS_PassthroughR3DUI), - "Blit11 3D R UI pixel shader")); - break; - case BLITSHADER_3D_RI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, - ShaderData(g_PS_PassthroughR3DI), - "Blit11 3D R I pixel shader")); - break; - case BLITSHADER_3D_ALPHA: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, - ShaderData(g_PS_PassthroughRGBA3D), - "Blit11 3D alpha pixel shader")); - break; - case BLITSHADER_3D_LUMA: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, - ShaderData(g_PS_PassthroughLum3D), - "Blit11 3D luminance pixel shader")); - break; - case BLITSHADER_3D_LUMAALPHA: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_3D, - ShaderData(g_PS_PassthroughLumAlpha3D), - "Blit11 3D luminance alpha pixel shader")); - break; - - case BLITSHADER_2D_RGBAF_PREMULTIPLY: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, ShaderData(g_PS_FtoF_PM_RGBA), - "Blit11 2D RGBA premultiply pixel shader")); - break; - - case BLITSHADER_2D_RGBAF_UNMULTIPLY: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, ShaderData(g_PS_FtoF_UM_RGBA), - "Blit11 2D RGBA unmultiply pixel shader")); - break; - - case BLITSHADER_2D_RGBF_PREMULTIPLY: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, ShaderData(g_PS_FtoF_PM_RGB), - "Blit11 2D RGB premultiply pixel shader")); - break; - - case BLITSHADER_2D_RGBF_UNMULTIPLY: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, ShaderData(g_PS_FtoF_UM_RGB), - "Blit11 2D RGB unmultiply pixel shader")); - break; - - case BLITSHADER_2D_RGBAF_TOUI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, ShaderData(g_PS_FtoU_PT_RGBA), - "Blit11 2D RGBA to uint pixel shader")); - break; - - case BLITSHADER_2D_RGBAF_TOUI_PREMULTIPLY: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, ShaderData(g_PS_FtoU_PM_RGBA), - "Blit11 2D RGBA to uint premultiply pixel shader")); - break; - - case BLITSHADER_2D_RGBAF_TOUI_UNMULTIPLY: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, ShaderData(g_PS_FtoU_UM_RGBA), - "Blit11 2D RGBA to uint unmultiply pixel shader")); - break; - - case BLITSHADER_2D_RGBF_TOUI: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, ShaderData(g_PS_FtoU_PT_RGB), - "Blit11 2D RGB to uint pixel shader")); - break; - - case BLITSHADER_2D_RGBF_TOUI_PREMULTIPLY: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, ShaderData(g_PS_FtoU_PM_RGB), - "Blit11 2D RGB to uint premultiply pixel shader")); - break; - - case BLITSHADER_2D_RGBF_TOUI_UNMULTIPLY: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, ShaderData(g_PS_FtoU_UM_RGB), - "Blit11 2D RGB to uint unmultiply pixel shader")); - break; - case BLITSHADER_2D_LUMAF_PREMULTIPLY: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, ShaderData(g_PS_FtoF_PM_LUMA), - "Blit11 2D LUMA premultiply pixel shader")); - break; - case BLITSHADER_2D_LUMAF_UNMULTIPLY: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, ShaderData(g_PS_FtoF_UM_LUMA), - "Blit11 2D LUMA unmultiply pixel shader")); - break; - case BLITSHADER_2D_LUMAALPHAF_PREMULTIPLY: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_FtoF_PM_LUMAALPHA), - "Blit11 2D LUMAALPHA premultiply pixel shader")); - break; - case BLITSHADER_2D_LUMAALPHAF_UNMULTIPLY: - ANGLE_TRY(addBlitShaderToMap(blitShaderType, SHADER_2D, - ShaderData(g_PS_FtoF_UM_LUMAALPHA), - "Blit11 2D LUMAALPHA unmultiply pixel shader")); - break; - - default: - UNREACHABLE(); - return gl::InternalError() << "Internal error"; - } - - blitShaderIt = mBlitShaderMap.find(blitShaderType); - ASSERT(blitShaderIt != mBlitShaderMap.end()); - *shader = &blitShaderIt->second; - return gl::NoError(); -} - -gl::Error Blit11::getSwizzleShader(GLenum type, - D3D11_SRV_DIMENSION viewDimension, - const Shader **shader) -{ - SwizzleShaderType swizzleShaderType = GetSwizzleShaderType(type, viewDimension); - - if (swizzleShaderType == SWIZZLESHADER_INVALID) - { - return gl::InternalError() << "Swizzle shader type not found"; - } - - auto swizzleShaderIt = mSwizzleShaderMap.find(swizzleShaderType); - if (swizzleShaderIt != mSwizzleShaderMap.end()) - { - *shader = &swizzleShaderIt->second; - return gl::NoError(); - } - - // Swizzling shaders (OpenGL ES 3+) - ASSERT(mRenderer->isES3Capable()); - - switch (swizzleShaderType) - { - case SWIZZLESHADER_2D_FLOAT: - ANGLE_TRY(addSwizzleShaderToMap(swizzleShaderType, SHADER_2D, - ShaderData(g_PS_SwizzleF2D), - "Blit11 2D F swizzle pixel shader")); - break; - case SWIZZLESHADER_2D_UINT: - ANGLE_TRY(addSwizzleShaderToMap(swizzleShaderType, SHADER_2D, - ShaderData(g_PS_SwizzleUI2D), - "Blit11 2D UI swizzle pixel shader")); - break; - case SWIZZLESHADER_2D_INT: - ANGLE_TRY(addSwizzleShaderToMap(swizzleShaderType, SHADER_2D, - ShaderData(g_PS_SwizzleI2D), - "Blit11 2D I swizzle pixel shader")); - break; - case SWIZZLESHADER_CUBE_FLOAT: - ANGLE_TRY(addSwizzleShaderToMap(swizzleShaderType, SHADER_3D, - ShaderData(g_PS_SwizzleF2DArray), - "Blit11 2D Cube F swizzle pixel shader")); - break; - case SWIZZLESHADER_CUBE_UINT: - ANGLE_TRY(addSwizzleShaderToMap(swizzleShaderType, SHADER_3D, - ShaderData(g_PS_SwizzleUI2DArray), - "Blit11 2D Cube UI swizzle pixel shader")); - break; - case SWIZZLESHADER_CUBE_INT: - ANGLE_TRY(addSwizzleShaderToMap(swizzleShaderType, SHADER_3D, - ShaderData(g_PS_SwizzleI2DArray), - "Blit11 2D Cube I swizzle pixel shader")); - break; - case SWIZZLESHADER_3D_FLOAT: - ANGLE_TRY(addSwizzleShaderToMap(swizzleShaderType, SHADER_3D, - ShaderData(g_PS_SwizzleF3D), - "Blit11 3D F swizzle pixel shader")); - break; - case SWIZZLESHADER_3D_UINT: - ANGLE_TRY(addSwizzleShaderToMap(swizzleShaderType, SHADER_3D, - ShaderData(g_PS_SwizzleUI3D), - "Blit11 3D UI swizzle pixel shader")); - break; - case SWIZZLESHADER_3D_INT: - ANGLE_TRY(addSwizzleShaderToMap(swizzleShaderType, SHADER_3D, - ShaderData(g_PS_SwizzleI3D), - "Blit11 3D I swizzle pixel shader")); - break; - case SWIZZLESHADER_ARRAY_FLOAT: - ANGLE_TRY(addSwizzleShaderToMap(swizzleShaderType, SHADER_3D, - ShaderData(g_PS_SwizzleF2DArray), - "Blit11 2D Array F swizzle pixel shader")); - break; - case SWIZZLESHADER_ARRAY_UINT: - ANGLE_TRY(addSwizzleShaderToMap(swizzleShaderType, SHADER_3D, - ShaderData(g_PS_SwizzleUI2DArray), - "Blit11 2D Array UI swizzle pixel shader")); - break; - case SWIZZLESHADER_ARRAY_INT: - ANGLE_TRY(addSwizzleShaderToMap(swizzleShaderType, SHADER_3D, - ShaderData(g_PS_SwizzleI2DArray), - "Blit11 2D Array I swizzle pixel shader")); - break; - default: - UNREACHABLE(); - return gl::InternalError() << "Internal error"; - } - - swizzleShaderIt = mSwizzleShaderMap.find(swizzleShaderType); - ASSERT(swizzleShaderIt != mSwizzleShaderMap.end()); - *shader = &swizzleShaderIt->second; - return gl::NoError(); -} - -gl::ErrorOrResult<TextureHelper11> Blit11::resolveDepth(const gl::Context *context, - RenderTarget11 *depth) -{ - ANGLE_TRY(initResources()); - - // Multisampled depth stencil SRVs are not available in feature level 10.0 - ASSERT(mRenderer->getRenderer11DeviceCaps().featureLevel > D3D_FEATURE_LEVEL_10_0); - - const auto &extents = depth->getExtents(); - auto *deviceContext = mRenderer->getDeviceContext(); - auto *stateManager = mRenderer->getStateManager(); - - ANGLE_TRY(initResolveDepthOnly(depth->getFormatSet(), extents)); - - ANGLE_TRY(mResolveDepthStencilVS.resolve(mRenderer)); - ANGLE_TRY(mResolveDepthPS.resolve(mRenderer)); - - // Apply the necessary state changes to the D3D11 immediate device context. - stateManager->setInputLayout(nullptr); - stateManager->setPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - stateManager->setDrawShaders(&mResolveDepthStencilVS.getObj(), nullptr, - &mResolveDepthPS.getObj()); - stateManager->setRasterizerState(nullptr); - stateManager->setDepthStencilState(&mDepthStencilState, 0xFFFFFFFF); - stateManager->setRenderTargets(nullptr, 0, mResolvedDepthDSView.get()); - stateManager->setSimpleBlendState(nullptr); - stateManager->setSimpleViewport(extents); - - // Set the viewport - stateManager->setShaderResourceShared(gl::SAMPLER_PIXEL, 0, &depth->getShaderResourceView()); - - // Trigger the blit on the GPU. - deviceContext->Draw(6, 0); - - return mResolvedDepth; -} - -gl::Error Blit11::initResolveDepthOnly(const d3d11::Format &format, const gl::Extents &extents) -{ - if (mResolvedDepth.valid() && extents == mResolvedDepth.getExtents() && - format.texFormat == mResolvedDepth.getFormat()) - { - return gl::NoError(); - } - - D3D11_TEXTURE2D_DESC textureDesc; - textureDesc.Width = extents.width; - textureDesc.Height = extents.height; - textureDesc.MipLevels = 1; - textureDesc.ArraySize = 1; - textureDesc.Format = format.texFormat; - textureDesc.SampleDesc.Count = 1; - textureDesc.SampleDesc.Quality = 0; - textureDesc.Usage = D3D11_USAGE_DEFAULT; - textureDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE; - textureDesc.CPUAccessFlags = 0; - textureDesc.MiscFlags = 0; - - ANGLE_TRY(mRenderer->allocateTexture(textureDesc, format, &mResolvedDepth)); - mResolvedDepth.setDebugName("Blit11::mResolvedDepth"); - - D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; - dsvDesc.Flags = 0; - dsvDesc.Format = format.dsvFormat; - dsvDesc.Texture2D.MipSlice = 0; - dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; - - ANGLE_TRY(mRenderer->allocateResource(dsvDesc, mResolvedDepth.get(), &mResolvedDepthDSView)); - mResolvedDepthDSView.setDebugName("Blit11::mResolvedDepthDSView"); - - // Possibly D3D11 bug or undefined behaviour: Clear the DSV so that our first render - // works as expected. Otherwise the results of the first use seem to be incorrect. - ID3D11DeviceContext *context = mRenderer->getDeviceContext(); - context->ClearDepthStencilView(mResolvedDepthDSView.get(), D3D11_CLEAR_DEPTH, 1.0f, 0); - - return gl::NoError(); -} - -gl::Error Blit11::initResolveDepthStencil(const gl::Extents &extents) -{ - // Check if we need to recreate depth stencil view - if (mResolvedDepthStencil.valid() && extents == mResolvedDepthStencil.getExtents()) - { - ASSERT(mResolvedDepthStencil.getFormat() == DXGI_FORMAT_R32G32_FLOAT); - return gl::NoError(); - } - - if (mResolvedDepthStencil.valid()) - { - releaseResolveDepthStencilResources(); - } - - const auto &formatSet = d3d11::Format::Get(GL_RG32F, mRenderer->getRenderer11DeviceCaps()); - - D3D11_TEXTURE2D_DESC textureDesc; - textureDesc.Width = extents.width; - textureDesc.Height = extents.height; - textureDesc.MipLevels = 1; - textureDesc.ArraySize = 1; - textureDesc.Format = formatSet.texFormat; - textureDesc.SampleDesc.Count = 1; - textureDesc.SampleDesc.Quality = 0; - textureDesc.Usage = D3D11_USAGE_DEFAULT; - textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET; - textureDesc.CPUAccessFlags = 0; - textureDesc.MiscFlags = 0; - - ANGLE_TRY(mRenderer->allocateTexture(textureDesc, formatSet, &mResolvedDepthStencil)); - mResolvedDepthStencil.setDebugName("Blit11::mResolvedDepthStencil"); - - ANGLE_TRY(mRenderer->allocateResourceNoDesc(mResolvedDepthStencil.get(), - &mResolvedDepthStencilRTView)); - mResolvedDepthStencilRTView.setDebugName("Blit11::mResolvedDepthStencilRTView"); - - return gl::NoError(); -} - -gl::ErrorOrResult<TextureHelper11> Blit11::resolveStencil(const gl::Context *context, - RenderTarget11 *depthStencil, - bool alsoDepth) -{ - ANGLE_TRY(initResources()); - - // Multisampled depth stencil SRVs are not available in feature level 10.0 - ASSERT(mRenderer->getRenderer11DeviceCaps().featureLevel > D3D_FEATURE_LEVEL_10_0); - - const auto &extents = depthStencil->getExtents(); - - ANGLE_TRY(initResolveDepthStencil(extents)); - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - auto *stateManager = mRenderer->getStateManager(); - ID3D11Resource *stencilResource = depthStencil->getTexture().get(); - - // Check if we need to re-create the stencil SRV. - if (mStencilSRV.valid()) - { - ID3D11Resource *priorResource = nullptr; - mStencilSRV.get()->GetResource(&priorResource); - - if (stencilResource != priorResource) - { - mStencilSRV.reset(); - } - - SafeRelease(priorResource); - } - - if (!mStencilSRV.valid()) - { - D3D11_SHADER_RESOURCE_VIEW_DESC srViewDesc; - srViewDesc.Format = GetStencilSRVFormat(depthStencil->getFormatSet()); - srViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS; - - ANGLE_TRY(mRenderer->allocateResource(srViewDesc, stencilResource, &mStencilSRV)); - mStencilSRV.setDebugName("Blit11::mStencilSRV"); - } - - // Notify the Renderer that all state should be invalidated. - ANGLE_TRY(mResolveDepthStencilVS.resolve(mRenderer)); - - // Resolving the depth buffer works by sampling the depth in the shader using a SRV, then - // writing to the resolved depth buffer using SV_Depth. We can't use this method for stencil - // because SV_StencilRef isn't supported until HLSL 5.1/D3D11.3. - const d3d11::PixelShader *pixelShader = nullptr; - if (alsoDepth) - { - ANGLE_TRY(mResolveDepthStencilPS.resolve(mRenderer)); - pixelShader = &mResolveDepthStencilPS.getObj(); - } - else - { - ANGLE_TRY(mResolveStencilPS.resolve(mRenderer)); - pixelShader = &mResolveStencilPS.getObj(); - } - - // Apply the necessary state changes to the D3D11 immediate device context. - stateManager->setInputLayout(nullptr); - stateManager->setPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - stateManager->setDrawShaders(&mResolveDepthStencilVS.getObj(), nullptr, pixelShader); - stateManager->setRasterizerState(nullptr); - stateManager->setDepthStencilState(nullptr, 0xFFFFFFFF); - stateManager->setRenderTarget(mResolvedDepthStencilRTView.get(), nullptr); - stateManager->setSimpleBlendState(nullptr); - - // Set the viewport - stateManager->setSimpleViewport(extents); - stateManager->setShaderResourceShared(gl::SAMPLER_PIXEL, 0, - &depthStencil->getShaderResourceView()); - stateManager->setShaderResource(gl::SAMPLER_PIXEL, 1, &mStencilSRV); - - // Trigger the blit on the GPU. - deviceContext->Draw(6, 0); - - gl::Box copyBox(0, 0, 0, extents.width, extents.height, 1); - - TextureHelper11 dest; - ANGLE_TRY_RESULT( - mRenderer->createStagingTexture(ResourceType::Texture2D, depthStencil->getFormatSet(), - extents, StagingAccess::READ_WRITE), - dest); - - const auto ©Function = GetCopyDepthStencilFunction(depthStencil->getInternalFormat()); - const auto &dsFormatSet = depthStencil->getFormatSet(); - const auto &dsDxgiInfo = d3d11::GetDXGIFormatSizeInfo(dsFormatSet.texFormat); - - ANGLE_TRY(copyAndConvertImpl(mResolvedDepthStencil, 0, copyBox, extents, dest, copyBox, extents, - nullptr, 0, 0, 0, 8u, dsDxgiInfo.pixelBytes, copyFunction)); - - // Return the resolved depth texture, which the caller must Release. - return dest; -} - -void Blit11::releaseResolveDepthStencilResources() -{ - mStencilSRV.reset(); - mResolvedDepthStencilRTView.reset(); -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Blit11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Blit11.h deleted file mode 100644 index 14078f9db8..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Blit11.h +++ /dev/null @@ -1,332 +0,0 @@ -// -// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Blit11.cpp: Texture copy utility class. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_BLIT11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_BLIT11_H_ - -#include "common/angleutils.h" -#include "libANGLE/Error.h" -#include "libANGLE/angletypes.h" -#include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -#include <map> - -namespace rx -{ -class Renderer11; - -class Blit11 : angle::NonCopyable -{ - public: - explicit Blit11(Renderer11 *renderer); - ~Blit11(); - - gl::Error swizzleTexture(const gl::Context *context, - const d3d11::SharedSRV &source, - const d3d11::RenderTargetView &dest, - const gl::Extents &size, - const gl::SwizzleState &swizzleTarget); - - gl::Error copyTexture(const gl::Context *context, - const d3d11::SharedSRV &source, - const gl::Box &sourceArea, - const gl::Extents &sourceSize, - GLenum sourceFormat, - const d3d11::RenderTargetView &dest, - const gl::Box &destArea, - const gl::Extents &destSize, - const gl::Rectangle *scissor, - GLenum destFormat, - GLenum filter, - bool maskOffAlpha, - bool unpackPremultiplyAlpha, - bool unpackUnmultiplyAlpha); - - gl::Error copyStencil(const gl::Context *context, - const TextureHelper11 &source, - unsigned int sourceSubresource, - const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const TextureHelper11 &dest, - unsigned int destSubresource, - const gl::Box &destArea, - const gl::Extents &destSize, - const gl::Rectangle *scissor); - - gl::Error copyDepth(const gl::Context *context, - const d3d11::SharedSRV &source, - const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const d3d11::DepthStencilView &dest, - const gl::Box &destArea, - const gl::Extents &destSize, - const gl::Rectangle *scissor); - - gl::Error copyDepthStencil(const TextureHelper11 &source, - unsigned int sourceSubresource, - const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const TextureHelper11 &dest, - unsigned int destSubresource, - const gl::Box &destArea, - const gl::Extents &destSize, - const gl::Rectangle *scissor); - - gl::ErrorOrResult<TextureHelper11> resolveDepth(const gl::Context *context, - RenderTarget11 *depth); - - gl::ErrorOrResult<TextureHelper11> resolveStencil(const gl::Context *context, - RenderTarget11 *depthStencil, - bool alsoDepth); - - using BlitConvertFunction = void(const gl::Box &sourceArea, - const gl::Box &destArea, - const gl::Rectangle &clipRect, - const gl::Extents &sourceSize, - unsigned int sourceRowPitch, - unsigned int destRowPitch, - ptrdiff_t readOffset, - ptrdiff_t writeOffset, - size_t copySize, - size_t srcPixelStride, - size_t destPixelStride, - const uint8_t *sourceData, - uint8_t *destData); - - private: - enum BlitShaderType - { - BLITSHADER_INVALID, - - // Passthrough shaders - BLITSHADER_2D_RGBAF, - BLITSHADER_2D_BGRAF, - BLITSHADER_2D_RGBF, - BLITSHADER_2D_RGF, - BLITSHADER_2D_RF, - BLITSHADER_2D_ALPHA, - BLITSHADER_2D_LUMA, - BLITSHADER_2D_LUMAALPHA, - BLITSHADER_2D_RGBAUI, - BLITSHADER_2D_RGBAI, - BLITSHADER_2D_RGBUI, - BLITSHADER_2D_RGBI, - BLITSHADER_2D_RGUI, - BLITSHADER_2D_RGI, - BLITSHADER_2D_RUI, - BLITSHADER_2D_RI, - BLITSHADER_3D_RGBAF, - BLITSHADER_3D_RGBAUI, - BLITSHADER_3D_RGBAI, - BLITSHADER_3D_BGRAF, - BLITSHADER_3D_RGBF, - BLITSHADER_3D_RGBUI, - BLITSHADER_3D_RGBI, - BLITSHADER_3D_RGF, - BLITSHADER_3D_RGUI, - BLITSHADER_3D_RGI, - BLITSHADER_3D_RF, - BLITSHADER_3D_RUI, - BLITSHADER_3D_RI, - BLITSHADER_3D_ALPHA, - BLITSHADER_3D_LUMA, - BLITSHADER_3D_LUMAALPHA, - - // Multiply alpha shaders - BLITSHADER_2D_RGBAF_PREMULTIPLY, - BLITSHADER_2D_RGBAF_UNMULTIPLY, - - BLITSHADER_2D_RGBF_PREMULTIPLY, - BLITSHADER_2D_RGBF_UNMULTIPLY, - - BLITSHADER_2D_RGBAF_TOUI, - BLITSHADER_2D_RGBAF_TOUI_PREMULTIPLY, - BLITSHADER_2D_RGBAF_TOUI_UNMULTIPLY, - - BLITSHADER_2D_RGBF_TOUI, - BLITSHADER_2D_RGBF_TOUI_PREMULTIPLY, - BLITSHADER_2D_RGBF_TOUI_UNMULTIPLY, - - BLITSHADER_2D_LUMAF_PREMULTIPLY, - BLITSHADER_2D_LUMAF_UNMULTIPLY, - - BLITSHADER_2D_LUMAALPHAF_PREMULTIPLY, - BLITSHADER_2D_LUMAALPHAF_UNMULTIPLY - }; - - enum SwizzleShaderType - { - SWIZZLESHADER_INVALID, - SWIZZLESHADER_2D_FLOAT, - SWIZZLESHADER_2D_UINT, - SWIZZLESHADER_2D_INT, - SWIZZLESHADER_CUBE_FLOAT, - SWIZZLESHADER_CUBE_UINT, - SWIZZLESHADER_CUBE_INT, - SWIZZLESHADER_3D_FLOAT, - SWIZZLESHADER_3D_UINT, - SWIZZLESHADER_3D_INT, - SWIZZLESHADER_ARRAY_FLOAT, - SWIZZLESHADER_ARRAY_UINT, - SWIZZLESHADER_ARRAY_INT, - }; - - typedef void (*WriteVertexFunction)(const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const gl::Box &destArea, - const gl::Extents &destSize, - void *outVertices, - unsigned int *outStride, - unsigned int *outVertexCount, - D3D11_PRIMITIVE_TOPOLOGY *outTopology); - - enum ShaderDimension - { - SHADER_2D, - SHADER_3D, - }; - - struct Shader - { - Shader(); - Shader(Shader &&other); - ~Shader(); - Shader &operator=(Shader &&other); - - ShaderDimension dimension; - d3d11::PixelShader pixelShader; - }; - - struct ShaderSupport - { - const d3d11::InputLayout *inputLayout; - const d3d11::VertexShader *vertexShader; - const d3d11::GeometryShader *geometryShader; - WriteVertexFunction vertexWriteFunction; - }; - - gl::Error initResources(); - - gl::Error getShaderSupport(const Shader &shader, ShaderSupport *supportOut); - - static BlitShaderType GetBlitShaderType(GLenum destinationFormat, - GLenum sourceFormat, - bool isSigned, - bool unpackPremultiplyAlpha, - bool unpackUnmultiplyAlpha, - ShaderDimension dimension); - static SwizzleShaderType GetSwizzleShaderType(GLenum type, D3D11_SRV_DIMENSION dimensionality); - - gl::Error copyDepthStencilImpl(const TextureHelper11 &source, - unsigned int sourceSubresource, - const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const TextureHelper11 &dest, - unsigned int destSubresource, - const gl::Box &destArea, - const gl::Extents &destSize, - const gl::Rectangle *scissor, - bool stencilOnly); - - gl::Error copyAndConvertImpl(const TextureHelper11 &source, - unsigned int sourceSubresource, - const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const TextureHelper11 &destStaging, - const gl::Box &destArea, - const gl::Extents &destSize, - const gl::Rectangle *scissor, - size_t readOffset, - size_t writeOffset, - size_t copySize, - size_t srcPixelStride, - size_t destPixelStride, - BlitConvertFunction *convertFunction); - - gl::Error copyAndConvert(const TextureHelper11 &source, - unsigned int sourceSubresource, - const gl::Box &sourceArea, - const gl::Extents &sourceSize, - const TextureHelper11 &dest, - unsigned int destSubresource, - const gl::Box &destArea, - const gl::Extents &destSize, - const gl::Rectangle *scissor, - size_t readOffset, - size_t writeOffset, - size_t copySize, - size_t srcPixelStride, - size_t destPixelStride, - BlitConvertFunction *convertFunction); - - gl::Error addBlitShaderToMap(BlitShaderType blitShaderType, - ShaderDimension dimension, - const ShaderData &shaderData, - const char *name); - - gl::Error getBlitShader(GLenum destFormat, - GLenum sourceFormat, - bool isSigned, - bool unpackPremultiplyAlpha, - bool unpackUnmultiplyAlpha, - ShaderDimension dimension, - const Shader **shaderOut); - gl::Error getSwizzleShader(GLenum type, - D3D11_SRV_DIMENSION viewDimension, - const Shader **shaderOut); - - gl::Error addSwizzleShaderToMap(SwizzleShaderType swizzleShaderType, - ShaderDimension dimension, - const ShaderData &shaderData, - const char *name); - - void clearShaderMap(); - void releaseResolveDepthStencilResources(); - gl::Error initResolveDepthOnly(const d3d11::Format &format, const gl::Extents &extents); - gl::Error initResolveDepthStencil(const gl::Extents &extents); - - Renderer11 *mRenderer; - - std::map<BlitShaderType, Shader> mBlitShaderMap; - std::map<SwizzleShaderType, Shader> mSwizzleShaderMap; - - bool mResourcesInitialized; - d3d11::Buffer mVertexBuffer; - d3d11::SamplerState mPointSampler; - d3d11::SamplerState mLinearSampler; - d3d11::RasterizerState mScissorEnabledRasterizerState; - d3d11::RasterizerState mScissorDisabledRasterizerState; - d3d11::DepthStencilState mDepthStencilState; - - d3d11::LazyInputLayout mQuad2DIL; - d3d11::LazyShader<ID3D11VertexShader> mQuad2DVS; - d3d11::LazyShader<ID3D11PixelShader> mDepthPS; - - d3d11::LazyInputLayout mQuad3DIL; - d3d11::LazyShader<ID3D11VertexShader> mQuad3DVS; - d3d11::LazyShader<ID3D11GeometryShader> mQuad3DGS; - - d3d11::LazyBlendState mAlphaMaskBlendState; - - d3d11::Buffer mSwizzleCB; - - d3d11::LazyShader<ID3D11VertexShader> mResolveDepthStencilVS; - d3d11::LazyShader<ID3D11PixelShader> mResolveDepthPS; - d3d11::LazyShader<ID3D11PixelShader> mResolveDepthStencilPS; - d3d11::LazyShader<ID3D11PixelShader> mResolveStencilPS; - d3d11::ShaderResourceView mStencilSRV; - TextureHelper11 mResolvedDepthStencil; - d3d11::RenderTargetView mResolvedDepthStencilRTView; - TextureHelper11 mResolvedDepth; - d3d11::DepthStencilView mResolvedDepthDSView; -}; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_BLIT11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Buffer11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Buffer11.cpp deleted file mode 100644 index 2317c9abdb..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Buffer11.cpp +++ /dev/null @@ -1,1600 +0,0 @@ -// -// Copyright 2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Buffer11.cpp Defines the Buffer11 class. - -#include "libANGLE/renderer/d3d/d3d11/Buffer11.h" - -#include <memory> - -#include "common/MemoryBuffer.h" -#include "libANGLE/renderer/d3d/IndexDataManager.h" -#include "libANGLE/renderer/d3d/VertexDataManager.h" -#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/renderer/renderer_utils.h" - -namespace rx -{ - -namespace -{ - -template <typename T> -GLuint ReadIndexValueFromIndices(const uint8_t *data, size_t index) -{ - return reinterpret_cast<const T *>(data)[index]; -} -typedef GLuint (*ReadIndexValueFunction)(const uint8_t *data, size_t index); - -enum class CopyResult -{ - RECREATED, - NOT_RECREATED, -}; - -void CalculateConstantBufferParams(GLintptr offset, - GLsizeiptr size, - UINT *outFirstConstant, - UINT *outNumConstants) -{ - // The offset must be aligned to 256 bytes (should have been enforced by glBindBufferRange). - ASSERT(offset % 256 == 0); - - // firstConstant and numConstants are expressed in constants of 16-bytes. Furthermore they must - // be a multiple of 16 constants. - *outFirstConstant = static_cast<UINT>(offset / 16); - - // The GL size is not required to be aligned to a 256 bytes boundary. - // Round the size up to a 256 bytes boundary then express the results in constants of 16-bytes. - *outNumConstants = static_cast<UINT>(rx::roundUp(size, static_cast<GLsizeiptr>(256)) / 16); - - // Since the size is rounded up, firstConstant + numConstants may be bigger than the actual size - // of the buffer. This behaviour is explictly allowed according to the documentation on - // ID3D11DeviceContext1::PSSetConstantBuffers1 - // https://msdn.microsoft.com/en-us/library/windows/desktop/hh404649%28v=vs.85%29.aspx -} - -} // anonymous namespace - -namespace gl_d3d11 -{ - -D3D11_MAP GetD3DMapTypeFromBits(BufferUsage usage, GLbitfield access) -{ - bool readBit = ((access & GL_MAP_READ_BIT) != 0); - bool writeBit = ((access & GL_MAP_WRITE_BIT) != 0); - - ASSERT(readBit || writeBit); - - // Note : we ignore the discard bit, because in D3D11, staging buffers - // don't accept the map-discard flag (discard only works for DYNAMIC usage) - - if (readBit && !writeBit) - { - return D3D11_MAP_READ; - } - else if (writeBit && !readBit) - { - // Special case for uniform storage - we only allow full buffer updates. - return usage == BUFFER_USAGE_UNIFORM ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE; - } - else if (writeBit && readBit) - { - return D3D11_MAP_READ_WRITE; - } - else - { - UNREACHABLE(); - return D3D11_MAP_READ; - } -} -} // namespace gl_d3d11 - -// Each instance of Buffer11::BufferStorage is specialized for a class of D3D binding points -// - vertex/transform feedback buffers -// - index buffers -// - pixel unpack buffers -// - uniform buffers -class Buffer11::BufferStorage : angle::NonCopyable -{ - public: - virtual ~BufferStorage() {} - - DataRevision getDataRevision() const { return mRevision; } - BufferUsage getUsage() const { return mUsage; } - size_t getSize() const { return mBufferSize; } - void setDataRevision(DataRevision rev) { mRevision = rev; } - - virtual bool isCPUAccessible(GLbitfield access) const = 0; - - virtual bool isGPUAccessible() const = 0; - - virtual gl::ErrorOrResult<CopyResult> copyFromStorage(const gl::Context *context, - BufferStorage *source, - size_t sourceOffset, - size_t size, - size_t destOffset) = 0; - virtual gl::Error resize(const gl::Context *context, size_t size, bool preserveData) = 0; - - virtual gl::Error map(size_t offset, - size_t length, - GLbitfield access, - uint8_t **mapPointerOut) = 0; - virtual void unmap() = 0; - - gl::Error setData(const uint8_t *data, size_t offset, size_t size); - - protected: - BufferStorage(Renderer11 *renderer, BufferUsage usage); - - Renderer11 *mRenderer; - DataRevision mRevision; - const BufferUsage mUsage; - size_t mBufferSize; -}; - -// A native buffer storage represents an underlying D3D11 buffer for a particular -// type of storage. -class Buffer11::NativeStorage : public Buffer11::BufferStorage -{ - public: - NativeStorage(Renderer11 *renderer, - BufferUsage usage, - const OnBufferDataDirtyChannel *onStorageChanged); - ~NativeStorage() override; - - bool isCPUAccessible(GLbitfield access) const override; - - bool isGPUAccessible() const override { return true; } - - const d3d11::Buffer &getBuffer() const { return mBuffer; } - gl::ErrorOrResult<CopyResult> copyFromStorage(const gl::Context *context, - BufferStorage *source, - size_t sourceOffset, - size_t size, - size_t destOffset) override; - gl::Error resize(const gl::Context *context, size_t size, bool preserveData) override; - - gl::Error map(size_t offset, - size_t length, - GLbitfield access, - uint8_t **mapPointerOut) override; - void unmap() override; - - gl::ErrorOrResult<const d3d11::ShaderResourceView *> getSRVForFormat(DXGI_FORMAT srvFormat); - - private: - static void FillBufferDesc(D3D11_BUFFER_DESC *bufferDesc, - Renderer11 *renderer, - BufferUsage usage, - unsigned int bufferSize); - void clearSRVs(); - - d3d11::Buffer mBuffer; - const OnBufferDataDirtyChannel *mOnStorageChanged; - std::map<DXGI_FORMAT, d3d11::ShaderResourceView> mBufferResourceViews; -}; - -// A emulated indexed buffer storage represents an underlying D3D11 buffer for data -// that has been expanded to match the indices list used. This storage is only -// used for FL9_3 pointsprite rendering emulation. -class Buffer11::EmulatedIndexedStorage : public Buffer11::BufferStorage -{ - public: - EmulatedIndexedStorage(Renderer11 *renderer); - ~EmulatedIndexedStorage() override; - - bool isCPUAccessible(GLbitfield access) const override { return true; } - - bool isGPUAccessible() const override { return false; } - - gl::ErrorOrResult<const d3d11::Buffer *> getBuffer(SourceIndexData *indexInfo, - const TranslatedAttribute &attribute, - GLint startVertex); - - gl::ErrorOrResult<CopyResult> copyFromStorage(const gl::Context *context, - BufferStorage *source, - size_t sourceOffset, - size_t size, - size_t destOffset) override; - - gl::Error resize(const gl::Context *context, size_t size, bool preserveData) override; - - gl::Error map(size_t offset, - size_t length, - GLbitfield access, - uint8_t **mapPointerOut) override; - void unmap() override; - - private: - d3d11::Buffer mBuffer; // contains expanded data for use by D3D - angle::MemoryBuffer mMemoryBuffer; // original data (not expanded) - angle::MemoryBuffer mIndicesMemoryBuffer; // indices data -}; - -// Pack storage represents internal storage for pack buffers. We implement pack buffers -// as CPU memory, tied to a staging texture, for asynchronous texture readback. -class Buffer11::PackStorage : public Buffer11::BufferStorage -{ - public: - explicit PackStorage(Renderer11 *renderer); - ~PackStorage() override; - - bool isCPUAccessible(GLbitfield access) const override { return true; } - - bool isGPUAccessible() const override { return false; } - - gl::ErrorOrResult<CopyResult> copyFromStorage(const gl::Context *context, - BufferStorage *source, - size_t sourceOffset, - size_t size, - size_t destOffset) override; - gl::Error resize(const gl::Context *context, size_t size, bool preserveData) override; - - gl::Error map(size_t offset, - size_t length, - GLbitfield access, - uint8_t **mapPointerOut) override; - void unmap() override; - - gl::Error packPixels(const gl::Context *context, - const gl::FramebufferAttachment &readAttachment, - const PackPixelsParams ¶ms); - - private: - gl::Error flushQueuedPackCommand(); - - TextureHelper11 mStagingTexture; - angle::MemoryBuffer mMemoryBuffer; - std::unique_ptr<PackPixelsParams> mQueuedPackCommand; - PackPixelsParams mPackParams; - bool mDataModified; -}; - -// System memory storage stores a CPU memory buffer with our buffer data. -// For dynamic data, it's much faster to update the CPU memory buffer than -// it is to update a D3D staging buffer and read it back later. -class Buffer11::SystemMemoryStorage : public Buffer11::BufferStorage -{ - public: - explicit SystemMemoryStorage(Renderer11 *renderer); - ~SystemMemoryStorage() override {} - - bool isCPUAccessible(GLbitfield access) const override { return true; } - - bool isGPUAccessible() const override { return false; } - - gl::ErrorOrResult<CopyResult> copyFromStorage(const gl::Context *context, - BufferStorage *source, - size_t sourceOffset, - size_t size, - size_t destOffset) override; - gl::Error resize(const gl::Context *context, size_t size, bool preserveData) override; - - gl::Error map(size_t offset, - size_t length, - GLbitfield access, - uint8_t **mapPointerOut) override; - void unmap() override; - - angle::MemoryBuffer *getSystemCopy() { return &mSystemCopy; } - - protected: - angle::MemoryBuffer mSystemCopy; -}; - -Buffer11::Buffer11(const gl::BufferState &state, Renderer11 *renderer) - : BufferD3D(state, renderer), - mRenderer(renderer), - mSize(0), - mMappedStorage(nullptr), - mBufferStorages({}), - mLatestBufferStorage(nullptr), - mDeallocThresholds({}), - mIdleness({}), - mConstantBufferStorageAdditionalSize(0), - mMaxConstantBufferLruCount(0) -{ -} - -Buffer11::~Buffer11() -{ - for (BufferStorage *&storage : mBufferStorages) - { - SafeDelete(storage); - } - - for (auto &p : mConstantBufferRangeStoragesCache) - { - SafeDelete(p.second.storage); - } - - mRenderer->onBufferDelete(this); -} - -gl::Error Buffer11::setData(const gl::Context *context, - gl::BufferBinding target, - const void *data, - size_t size, - gl::BufferUsage usage) -{ - updateD3DBufferUsage(context, usage); - ANGLE_TRY(setSubData(context, target, data, size, 0)); - return gl::NoError(); -} - -gl::Error Buffer11::getData(const gl::Context *context, const uint8_t **outData) -{ - SystemMemoryStorage *systemMemoryStorage = nullptr; - ANGLE_TRY_RESULT(getSystemMemoryStorage(context), systemMemoryStorage); - - ASSERT(systemMemoryStorage->getSize() >= mSize); - - *outData = systemMemoryStorage->getSystemCopy()->data(); - return gl::NoError(); -} - -gl::ErrorOrResult<Buffer11::SystemMemoryStorage *> Buffer11::getSystemMemoryStorage( - const gl::Context *context) -{ - BufferStorage *storage = nullptr; - ANGLE_TRY_RESULT(getBufferStorage(context, BUFFER_USAGE_SYSTEM_MEMORY), storage); - return GetAs<SystemMemoryStorage>(storage); -} - -gl::Error Buffer11::setSubData(const gl::Context *context, - gl::BufferBinding target, - const void *data, - size_t size, - size_t offset) -{ - size_t requiredSize = size + offset; - - if (data && size > 0) - { - // Use system memory storage for dynamic buffers. - // Try using a constant storage for constant buffers - BufferStorage *writeBuffer = nullptr; - if (target == gl::BufferBinding::Uniform) - { - // If we are a very large uniform buffer, keep system memory storage around so that we - // aren't forced to read back from a constant buffer. We also check the workaround for - // Intel - this requires us to use system memory so we don't end up having to copy from - // a constant buffer to a staging buffer. - // TODO(jmadill): Use Context caps. - if (offset == 0 && size >= mSize && - size <= static_cast<UINT>(mRenderer->getNativeCaps().maxUniformBlockSize) && - !mRenderer->getWorkarounds().useSystemMemoryForConstantBuffers) - { - ANGLE_TRY_RESULT(getBufferStorage(context, BUFFER_USAGE_UNIFORM), writeBuffer); - } - else - { - ANGLE_TRY_RESULT(getSystemMemoryStorage(context), writeBuffer); - } - } - else if (supportsDirectBinding()) - { - ANGLE_TRY_RESULT(getStagingStorage(context), writeBuffer); - } - else - { - ANGLE_TRY_RESULT(getSystemMemoryStorage(context), writeBuffer); - } - - ASSERT(writeBuffer); - - // Explicitly resize the staging buffer, preserving data if the new data will not - // completely fill the buffer - if (writeBuffer->getSize() < requiredSize) - { - bool preserveData = (offset > 0); - ANGLE_TRY(writeBuffer->resize(context, requiredSize, preserveData)); - } - - ANGLE_TRY(writeBuffer->setData(static_cast<const uint8_t *>(data), offset, size)); - onStorageUpdate(writeBuffer); - - // Notify any vertex arrays that we have dirty data. - // TODO(jmadill): Use a more fine grained notification for data updates. - mDirectBroadcastChannel.signal(context); - } - - mSize = std::max(mSize, requiredSize); - invalidateStaticData(context); - - return gl::NoError(); -} - -gl::Error Buffer11::copySubData(const gl::Context *context, - BufferImpl *source, - GLintptr sourceOffset, - GLintptr destOffset, - GLsizeiptr size) -{ - Buffer11 *sourceBuffer = GetAs<Buffer11>(source); - ASSERT(sourceBuffer != nullptr); - - BufferStorage *copyDest = nullptr; - ANGLE_TRY_RESULT(getLatestBufferStorage(context), copyDest); - - if (!copyDest) - { - ANGLE_TRY_RESULT(getStagingStorage(context), copyDest); - } - - BufferStorage *copySource = nullptr; - ANGLE_TRY_RESULT(sourceBuffer->getLatestBufferStorage(context), copySource); - - if (!copySource) - { - ANGLE_TRY_RESULT(sourceBuffer->getStagingStorage(context), copySource); - } - - ASSERT(copySource && copyDest); - - // A staging buffer is needed if there is no cpu-cpu or gpu-gpu copy path avaiable. - if (!copyDest->isGPUAccessible() && !copySource->isCPUAccessible(GL_MAP_READ_BIT)) - { - ANGLE_TRY_RESULT(sourceBuffer->getStagingStorage(context), copySource); - } - else if (!copySource->isGPUAccessible() && !copyDest->isCPUAccessible(GL_MAP_WRITE_BIT)) - { - ANGLE_TRY_RESULT(getStagingStorage(context), copyDest); - } - - // D3D11 does not allow overlapped copies until 11.1, and only if the - // device supports D3D11_FEATURE_DATA_D3D11_OPTIONS::CopyWithOverlap - // Get around this via a different source buffer - if (copySource == copyDest) - { - if (copySource->getUsage() == BUFFER_USAGE_STAGING) - { - ANGLE_TRY_RESULT(getBufferStorage(context, BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK), - copySource); - } - else - { - ANGLE_TRY_RESULT(getStagingStorage(context), copySource); - } - } - - CopyResult copyResult = CopyResult::NOT_RECREATED; - ANGLE_TRY_RESULT(copyDest->copyFromStorage(context, copySource, sourceOffset, size, destOffset), - copyResult); - onStorageUpdate(copyDest); - - mSize = std::max<size_t>(mSize, destOffset + size); - invalidateStaticData(context); - - // Also notify that direct buffers are dirty. - mDirectBroadcastChannel.signal(context); - - return gl::NoError(); -} - -gl::Error Buffer11::map(const gl::Context *context, GLenum access, void **mapPtr) -{ - // GL_OES_mapbuffer uses an enum instead of a bitfield for it's access, convert to a bitfield - // and call mapRange. - ASSERT(access == GL_WRITE_ONLY_OES); - return mapRange(context, 0, mSize, GL_MAP_WRITE_BIT, mapPtr); -} - -gl::Error Buffer11::mapRange(const gl::Context *context, - size_t offset, - size_t length, - GLbitfield access, - void **mapPtr) -{ - ASSERT(!mMappedStorage); - - BufferStorage *latestStorage = nullptr; - ANGLE_TRY_RESULT(getLatestBufferStorage(context), latestStorage); - - if (latestStorage && (latestStorage->getUsage() == BUFFER_USAGE_PIXEL_PACK || - latestStorage->getUsage() == BUFFER_USAGE_STAGING)) - { - // Latest storage is mappable. - mMappedStorage = latestStorage; - } - else - { - // Fall back to using the staging buffer if the latest storage does not exist or is not - // CPU-accessible. - ANGLE_TRY_RESULT(getStagingStorage(context), mMappedStorage); - } - - if (!mMappedStorage) - { - return gl::OutOfMemory() << "Failed to allocate mappable internal buffer."; - } - - if ((access & GL_MAP_WRITE_BIT) > 0) - { - // Update the data revision immediately, since the data might be changed at any time - onStorageUpdate(mMappedStorage); - invalidateStaticData(context); - } - - uint8_t *mappedBuffer = nullptr; - ANGLE_TRY(mMappedStorage->map(offset, length, access, &mappedBuffer)); - ASSERT(mappedBuffer); - - *mapPtr = static_cast<void *>(mappedBuffer); - return gl::NoError(); -} - -gl::Error Buffer11::unmap(const gl::Context *context, GLboolean *result) -{ - ASSERT(mMappedStorage); - mMappedStorage->unmap(); - mMappedStorage = nullptr; - - // TODO: detect if we had corruption. if so, return false. - *result = GL_TRUE; - - return gl::NoError(); -} - -gl::Error Buffer11::markTransformFeedbackUsage(const gl::Context *context) -{ - BufferStorage *transformFeedbackStorage = nullptr; - ANGLE_TRY_RESULT(getBufferStorage(context, BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK), - transformFeedbackStorage); - - if (transformFeedbackStorage) - { - onStorageUpdate(transformFeedbackStorage); - } - - invalidateStaticData(context); - return gl::NoError(); -} - -void Buffer11::updateDeallocThreshold(BufferUsage usage) -{ - // The following strategy was tuned on the Oort online benchmark (http://oortonline.gl/) - // as well as a custom microbenchmark (IndexConversionPerfTest.Run/index_range_d3d11) - - // First readback: 8 unmodified uses before we free buffer memory. - // After that, double the threshold each time until we reach the max. - if (mDeallocThresholds[usage] == 0) - { - mDeallocThresholds[usage] = 8; - } - else if (mDeallocThresholds[usage] < std::numeric_limits<unsigned int>::max() / 2u) - { - mDeallocThresholds[usage] *= 2u; - } - else - { - mDeallocThresholds[usage] = std::numeric_limits<unsigned int>::max(); - } -} - -// Free the storage if we decide it isn't being used very often. -gl::Error Buffer11::checkForDeallocation(const gl::Context *context, BufferUsage usage) -{ - mIdleness[usage]++; - - BufferStorage *&storage = mBufferStorages[usage]; - if (storage != nullptr && mIdleness[usage] > mDeallocThresholds[usage]) - { - BufferStorage *latestStorage = nullptr; - ANGLE_TRY_RESULT(getLatestBufferStorage(context), latestStorage); - if (latestStorage != storage) - { - SafeDelete(storage); - } - } - - return gl::NoError(); -} - -// Keep system memory when we are using it for the canonical version of data. -bool Buffer11::canDeallocateSystemMemory() const -{ - // Must keep system memory on Intel. - if (mRenderer->getWorkarounds().useSystemMemoryForConstantBuffers) - { - return false; - } - - return (!mBufferStorages[BUFFER_USAGE_UNIFORM] || - mSize <= mRenderer->getNativeCaps().maxUniformBlockSize); -} - -void Buffer11::markBufferUsage(BufferUsage usage) -{ - mIdleness[usage] = 0; -} - -gl::Error Buffer11::garbageCollection(const gl::Context *context, BufferUsage currentUsage) -{ - if (currentUsage != BUFFER_USAGE_SYSTEM_MEMORY && canDeallocateSystemMemory()) - { - ANGLE_TRY(checkForDeallocation(context, BUFFER_USAGE_SYSTEM_MEMORY)); - } - - if (currentUsage != BUFFER_USAGE_STAGING) - { - ANGLE_TRY(checkForDeallocation(context, BUFFER_USAGE_STAGING)); - } - - return gl::NoError(); -} - -gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getBuffer(const gl::Context *context, BufferUsage usage) -{ - BufferStorage *storage = nullptr; - ANGLE_TRY_RESULT(getBufferStorage(context, usage), storage); - return GetAs<NativeStorage>(storage)->getBuffer().get(); -} - -gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getEmulatedIndexedBuffer( - const gl::Context *context, - SourceIndexData *indexInfo, - const TranslatedAttribute &attribute, - GLint startVertex) -{ - ASSERT(indexInfo); - - BufferStorage *untypedStorage = nullptr; - ANGLE_TRY_RESULT(getBufferStorage(context, BUFFER_USAGE_EMULATED_INDEXED_VERTEX), - untypedStorage); - - EmulatedIndexedStorage *emulatedStorage = GetAs<EmulatedIndexedStorage>(untypedStorage); - - const d3d11::Buffer *nativeStorage = nullptr; - ANGLE_TRY_RESULT(emulatedStorage->getBuffer(indexInfo, attribute, startVertex), nativeStorage); - - return nativeStorage->get(); -} - -gl::Error Buffer11::getConstantBufferRange(const gl::Context *context, - GLintptr offset, - GLsizeiptr size, - const d3d11::Buffer **bufferOut, - UINT *firstConstantOut, - UINT *numConstantsOut) -{ - BufferStorage *bufferStorage = nullptr; - - if (offset == 0 || mRenderer->getRenderer11DeviceCaps().supportsConstantBufferOffsets) - { - ANGLE_TRY_RESULT(getBufferStorage(context, BUFFER_USAGE_UNIFORM), bufferStorage); - CalculateConstantBufferParams(offset, size, firstConstantOut, numConstantsOut); - } - else - { - ANGLE_TRY_RESULT(getConstantBufferRangeStorage(context, offset, size), bufferStorage); - *firstConstantOut = 0; - *numConstantsOut = 0; - } - - *bufferOut = &GetAs<NativeStorage>(bufferStorage)->getBuffer(); - - return gl::NoError(); -} - -gl::ErrorOrResult<const d3d11::ShaderResourceView *> Buffer11::getSRV(const gl::Context *context, - DXGI_FORMAT srvFormat) -{ - BufferStorage *storage = nullptr; - ANGLE_TRY_RESULT(getBufferStorage(context, BUFFER_USAGE_PIXEL_UNPACK), storage); - NativeStorage *nativeStorage = GetAs<NativeStorage>(storage); - return nativeStorage->getSRVForFormat(srvFormat); -} - -gl::Error Buffer11::packPixels(const gl::Context *context, - const gl::FramebufferAttachment &readAttachment, - const PackPixelsParams ¶ms) -{ - PackStorage *packStorage = nullptr; - ANGLE_TRY_RESULT(getPackStorage(context), packStorage); - - ASSERT(packStorage); - ANGLE_TRY(packStorage->packPixels(context, readAttachment, params)); - onStorageUpdate(packStorage); - - return gl::NoError(); -} - -size_t Buffer11::getTotalCPUBufferMemoryBytes() const -{ - size_t allocationSize = 0; - - BufferStorage *staging = mBufferStorages[BUFFER_USAGE_STAGING]; - allocationSize += staging ? staging->getSize() : 0; - - BufferStorage *sysMem = mBufferStorages[BUFFER_USAGE_SYSTEM_MEMORY]; - allocationSize += sysMem ? sysMem->getSize() : 0; - - return allocationSize; -} - -gl::ErrorOrResult<Buffer11::BufferStorage *> Buffer11::getBufferStorage(const gl::Context *context, - BufferUsage usage) -{ - ASSERT(0 <= usage && usage < BUFFER_USAGE_COUNT); - BufferStorage *&newStorage = mBufferStorages[usage]; - - if (!newStorage) - { - newStorage = allocateStorage(usage); - } - - markBufferUsage(usage); - - // resize buffer - if (newStorage->getSize() < mSize) - { - ANGLE_TRY(newStorage->resize(context, mSize, true)); - } - - ASSERT(newStorage); - - ANGLE_TRY(updateBufferStorage(context, newStorage, 0, mSize)); - ANGLE_TRY(garbageCollection(context, usage)); - - return newStorage; -} - -Buffer11::BufferStorage *Buffer11::allocateStorage(BufferUsage usage) -{ - updateDeallocThreshold(usage); - switch (usage) - { - case BUFFER_USAGE_PIXEL_PACK: - return new PackStorage(mRenderer); - case BUFFER_USAGE_SYSTEM_MEMORY: - return new SystemMemoryStorage(mRenderer); - case BUFFER_USAGE_EMULATED_INDEXED_VERTEX: - return new EmulatedIndexedStorage(mRenderer); - case BUFFER_USAGE_INDEX: - case BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK: - return new NativeStorage(mRenderer, usage, &mDirectBroadcastChannel); - default: - return new NativeStorage(mRenderer, usage, nullptr); - } -} - -gl::ErrorOrResult<Buffer11::BufferStorage *> Buffer11::getConstantBufferRangeStorage( - const gl::Context *context, - GLintptr offset, - GLsizeiptr size) -{ - BufferStorage *newStorage; - - { - // Keep the cacheEntry in a limited scope because it may be invalidated later in the code if - // we need to reclaim some space. - ConstantBufferCacheEntry *cacheEntry = &mConstantBufferRangeStoragesCache[offset]; - - if (!cacheEntry->storage) - { - cacheEntry->storage = allocateStorage(BUFFER_USAGE_UNIFORM); - cacheEntry->lruCount = ++mMaxConstantBufferLruCount; - } - - cacheEntry->lruCount = ++mMaxConstantBufferLruCount; - newStorage = cacheEntry->storage; - } - - markBufferUsage(BUFFER_USAGE_UNIFORM); - - if (newStorage->getSize() < static_cast<size_t>(size)) - { - size_t maximumAllowedAdditionalSize = 2 * getSize(); - - size_t sizeDelta = size - newStorage->getSize(); - - while (mConstantBufferStorageAdditionalSize + sizeDelta > maximumAllowedAdditionalSize) - { - auto iter = std::min_element(std::begin(mConstantBufferRangeStoragesCache), - std::end(mConstantBufferRangeStoragesCache), - [](const ConstantBufferCache::value_type &a, - const ConstantBufferCache::value_type &b) { - return a.second.lruCount < b.second.lruCount; - }); - - ASSERT(iter->second.storage != newStorage); - ASSERT(mConstantBufferStorageAdditionalSize >= iter->second.storage->getSize()); - - mConstantBufferStorageAdditionalSize -= iter->second.storage->getSize(); - SafeDelete(iter->second.storage); - mConstantBufferRangeStoragesCache.erase(iter); - } - - ANGLE_TRY(newStorage->resize(context, size, false)); - mConstantBufferStorageAdditionalSize += sizeDelta; - - // We don't copy the old data when resizing the constant buffer because the data may be - // out-of-date therefore we reset the data revision and let updateBufferStorage() handle the - // copy. - newStorage->setDataRevision(0); - } - - ANGLE_TRY(updateBufferStorage(context, newStorage, offset, size)); - ANGLE_TRY(garbageCollection(context, BUFFER_USAGE_UNIFORM)); - return newStorage; -} - -gl::Error Buffer11::updateBufferStorage(const gl::Context *context, - BufferStorage *storage, - size_t sourceOffset, - size_t storageSize) -{ - BufferStorage *latestBuffer = nullptr; - ANGLE_TRY_RESULT(getLatestBufferStorage(context), latestBuffer); - - ASSERT(storage); - - if (!latestBuffer) - { - onStorageUpdate(storage); - return gl::NoError(); - } - - if (latestBuffer->getDataRevision() <= storage->getDataRevision()) - { - return gl::NoError(); - } - - // Copy through a staging buffer if we're copying from or to a non-staging, mappable - // buffer storage. This is because we can't map a GPU buffer, and copy CPU - // data directly. If we're already using a staging buffer we're fine. - if (latestBuffer->getUsage() != BUFFER_USAGE_STAGING && - storage->getUsage() != BUFFER_USAGE_STAGING && - (!latestBuffer->isCPUAccessible(GL_MAP_READ_BIT) || - !storage->isCPUAccessible(GL_MAP_WRITE_BIT))) - { - NativeStorage *stagingBuffer = nullptr; - ANGLE_TRY_RESULT(getStagingStorage(context), stagingBuffer); - - CopyResult copyResult = CopyResult::NOT_RECREATED; - ANGLE_TRY_RESULT( - stagingBuffer->copyFromStorage(context, latestBuffer, 0, latestBuffer->getSize(), 0), - copyResult); - onCopyStorage(stagingBuffer, latestBuffer); - - latestBuffer = stagingBuffer; - } - - CopyResult copyResult = CopyResult::NOT_RECREATED; - ANGLE_TRY_RESULT(storage->copyFromStorage(context, latestBuffer, sourceOffset, storageSize, 0), - copyResult); - // If the D3D buffer has been recreated, we should update our serial. - if (copyResult == CopyResult::RECREATED) - { - updateSerial(); - } - onCopyStorage(storage, latestBuffer); - return gl::NoError(); -} - -gl::ErrorOrResult<Buffer11::BufferStorage *> Buffer11::getLatestBufferStorage( - const gl::Context *context) const -{ - // resize buffer - if (mLatestBufferStorage && mLatestBufferStorage->getSize() < mSize) - { - ANGLE_TRY(mLatestBufferStorage->resize(context, mSize, true)); - } - - return mLatestBufferStorage; -} - -gl::ErrorOrResult<Buffer11::NativeStorage *> Buffer11::getStagingStorage(const gl::Context *context) -{ - BufferStorage *stagingStorage = nullptr; - ANGLE_TRY_RESULT(getBufferStorage(context, BUFFER_USAGE_STAGING), stagingStorage); - return GetAs<NativeStorage>(stagingStorage); -} - -gl::ErrorOrResult<Buffer11::PackStorage *> Buffer11::getPackStorage(const gl::Context *context) -{ - BufferStorage *packStorage = nullptr; - ANGLE_TRY_RESULT(getBufferStorage(context, BUFFER_USAGE_PIXEL_PACK), packStorage); - return GetAs<PackStorage>(packStorage); -} - -size_t Buffer11::getSize() const -{ - return mSize; -} - -bool Buffer11::supportsDirectBinding() const -{ - // Do not support direct buffers for dynamic data. The streaming buffer - // offers better performance for data which changes every frame. - return (mUsage == D3DBufferUsage::STATIC); -} - -void Buffer11::initializeStaticData(const gl::Context *context) -{ - BufferD3D::initializeStaticData(context); - - // Notify when static data changes. - mStaticBroadcastChannel.signal(context); -} - -void Buffer11::invalidateStaticData(const gl::Context *context) -{ - BufferD3D::invalidateStaticData(context); - - // Notify when static data changes. - mStaticBroadcastChannel.signal(context); -} - -OnBufferDataDirtyChannel *Buffer11::getStaticBroadcastChannel() -{ - return &mStaticBroadcastChannel; -} - -OnBufferDataDirtyChannel *Buffer11::getDirectBroadcastChannel() -{ - return &mDirectBroadcastChannel; -} - -void Buffer11::onCopyStorage(BufferStorage *dest, BufferStorage *source) -{ - ASSERT(source && mLatestBufferStorage); - dest->setDataRevision(source->getDataRevision()); - - // Only update the latest buffer storage if our usage index is lower. See comment in header. - if (dest->getUsage() < mLatestBufferStorage->getUsage()) - { - mLatestBufferStorage = dest; - } -} - -void Buffer11::onStorageUpdate(BufferStorage *updatedStorage) -{ - updatedStorage->setDataRevision(updatedStorage->getDataRevision() + 1); - mLatestBufferStorage = updatedStorage; -} - -// Buffer11::BufferStorage implementation - -Buffer11::BufferStorage::BufferStorage(Renderer11 *renderer, BufferUsage usage) - : mRenderer(renderer), mRevision(0), mUsage(usage), mBufferSize(0) -{ -} - -gl::Error Buffer11::BufferStorage::setData(const uint8_t *data, size_t offset, size_t size) -{ - ASSERT(isCPUAccessible(GL_MAP_WRITE_BIT)); - - // Uniform storage can have a different internal size than the buffer size. Ensure we don't - // overflow. - size_t mapSize = std::min(size, mBufferSize - offset); - - uint8_t *writePointer = nullptr; - ANGLE_TRY(map(offset, mapSize, GL_MAP_WRITE_BIT, &writePointer)); - - memcpy(writePointer, data, mapSize); - - unmap(); - - return gl::NoError(); -} - -// Buffer11::NativeStorage implementation - -Buffer11::NativeStorage::NativeStorage(Renderer11 *renderer, - BufferUsage usage, - const OnBufferDataDirtyChannel *onStorageChanged) - : BufferStorage(renderer, usage), mBuffer(), mOnStorageChanged(onStorageChanged) -{ -} - -Buffer11::NativeStorage::~NativeStorage() -{ - clearSRVs(); -} - -bool Buffer11::NativeStorage::isCPUAccessible(GLbitfield access) const -{ - if ((access & GL_MAP_READ_BIT) != 0) - { - // Read is more exclusive than write mappability. - return (mUsage == BUFFER_USAGE_STAGING); - } - ASSERT((access & GL_MAP_WRITE_BIT) != 0); - return (mUsage == BUFFER_USAGE_STAGING || mUsage == BUFFER_USAGE_UNIFORM); -} - -// Returns true if it recreates the direct buffer -gl::ErrorOrResult<CopyResult> Buffer11::NativeStorage::copyFromStorage(const gl::Context *context, - BufferStorage *source, - size_t sourceOffset, - size_t size, - size_t destOffset) -{ - size_t requiredSize = destOffset + size; - bool createBuffer = !mBuffer.valid() || mBufferSize < requiredSize; - - // (Re)initialize D3D buffer if needed - bool preserveData = (destOffset > 0); - if (createBuffer) - { - ANGLE_TRY(resize(context, requiredSize, preserveData)); - } - - size_t clampedSize = size; - if (mUsage == BUFFER_USAGE_UNIFORM) - { - clampedSize = std::min(clampedSize, mBufferSize - destOffset); - } - - if (source->getUsage() == BUFFER_USAGE_PIXEL_PACK || - source->getUsage() == BUFFER_USAGE_SYSTEM_MEMORY) - { - ASSERT(source->isCPUAccessible(GL_MAP_READ_BIT) && isCPUAccessible(GL_MAP_WRITE_BIT)); - - // Uniform buffers must be mapped with write/discard. - ASSERT(!(preserveData && mUsage == BUFFER_USAGE_UNIFORM)); - - uint8_t *sourcePointer = nullptr; - ANGLE_TRY(source->map(sourceOffset, clampedSize, GL_MAP_READ_BIT, &sourcePointer)); - - auto err = setData(sourcePointer, destOffset, clampedSize); - source->unmap(); - ANGLE_TRY(err); - } - else - { - D3D11_BOX srcBox; - srcBox.left = static_cast<unsigned int>(sourceOffset); - srcBox.right = static_cast<unsigned int>(sourceOffset + clampedSize); - srcBox.top = 0; - srcBox.bottom = 1; - srcBox.front = 0; - srcBox.back = 1; - - const d3d11::Buffer *sourceBuffer = &GetAs<NativeStorage>(source)->getBuffer(); - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - deviceContext->CopySubresourceRegion(mBuffer.get(), 0, - static_cast<unsigned int>(destOffset), 0, 0, - sourceBuffer->get(), 0, &srcBox); - } - - return createBuffer ? CopyResult::RECREATED : CopyResult::NOT_RECREATED; -} - -gl::Error Buffer11::NativeStorage::resize(const gl::Context *context, - size_t size, - bool preserveData) -{ - D3D11_BUFFER_DESC bufferDesc; - FillBufferDesc(&bufferDesc, mRenderer, mUsage, static_cast<unsigned int>(size)); - - d3d11::Buffer newBuffer; - ANGLE_TRY(mRenderer->allocateResource(bufferDesc, &newBuffer)); - newBuffer.setDebugName("Buffer11::NativeStorage"); - - if (mBuffer.valid() && preserveData) - { - // We don't call resize if the buffer is big enough already. - ASSERT(mBufferSize <= size); - - D3D11_BOX srcBox; - srcBox.left = 0; - srcBox.right = static_cast<unsigned int>(mBufferSize); - srcBox.top = 0; - srcBox.bottom = 1; - srcBox.front = 0; - srcBox.back = 1; - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - deviceContext->CopySubresourceRegion(newBuffer.get(), 0, 0, 0, 0, mBuffer.get(), 0, - &srcBox); - } - - // No longer need the old buffer - mBuffer = std::move(newBuffer); - - mBufferSize = bufferDesc.ByteWidth; - - // Free the SRVs. - clearSRVs(); - - // Notify that the storage has changed. - if (mOnStorageChanged) - { - mOnStorageChanged->signal(context); - } - - return gl::NoError(); -} - -// static -void Buffer11::NativeStorage::FillBufferDesc(D3D11_BUFFER_DESC *bufferDesc, - Renderer11 *renderer, - BufferUsage usage, - unsigned int bufferSize) -{ - bufferDesc->ByteWidth = bufferSize; - bufferDesc->MiscFlags = 0; - bufferDesc->StructureByteStride = 0; - - switch (usage) - { - case BUFFER_USAGE_STAGING: - bufferDesc->Usage = D3D11_USAGE_STAGING; - bufferDesc->BindFlags = 0; - bufferDesc->CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; - break; - - case BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK: - bufferDesc->Usage = D3D11_USAGE_DEFAULT; - bufferDesc->BindFlags = D3D11_BIND_VERTEX_BUFFER; - - if (renderer->isES3Capable()) - { - bufferDesc->BindFlags |= D3D11_BIND_STREAM_OUTPUT; - } - - bufferDesc->CPUAccessFlags = 0; - break; - - case BUFFER_USAGE_INDEX: - bufferDesc->Usage = D3D11_USAGE_DEFAULT; - bufferDesc->BindFlags = D3D11_BIND_INDEX_BUFFER; - bufferDesc->CPUAccessFlags = 0; - break; - - case BUFFER_USAGE_INDIRECT: - bufferDesc->MiscFlags = D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS; - bufferDesc->Usage = D3D11_USAGE_DEFAULT; - bufferDesc->BindFlags = 0; - bufferDesc->CPUAccessFlags = 0; - break; - - case BUFFER_USAGE_PIXEL_UNPACK: - bufferDesc->Usage = D3D11_USAGE_DEFAULT; - bufferDesc->BindFlags = D3D11_BIND_SHADER_RESOURCE; - bufferDesc->CPUAccessFlags = 0; - break; - - case BUFFER_USAGE_UNIFORM: - bufferDesc->Usage = D3D11_USAGE_DYNAMIC; - bufferDesc->BindFlags = D3D11_BIND_CONSTANT_BUFFER; - bufferDesc->CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - - // Constant buffers must be of a limited size, and aligned to 16 byte boundaries - // For our purposes we ignore any buffer data past the maximum constant buffer size - bufferDesc->ByteWidth = roundUp(bufferDesc->ByteWidth, 16u); - - // Note: it seems that D3D11 allows larger buffers on some platforms, but not all. - // (Windows 10 seems to allow larger constant buffers, but not Windows 7) - bufferDesc->ByteWidth = - std::min<UINT>(bufferDesc->ByteWidth, - static_cast<UINT>(renderer->getNativeCaps().maxUniformBlockSize)); - break; - - default: - UNREACHABLE(); - } -} - -gl::Error Buffer11::NativeStorage::map(size_t offset, - size_t length, - GLbitfield access, - uint8_t **mapPointerOut) -{ - ASSERT(isCPUAccessible(access)); - - D3D11_MAPPED_SUBRESOURCE mappedResource; - ID3D11DeviceContext *context = mRenderer->getDeviceContext(); - D3D11_MAP d3dMapType = gl_d3d11::GetD3DMapTypeFromBits(mUsage, access); - UINT d3dMapFlag = ((access & GL_MAP_UNSYNCHRONIZED_BIT) != 0 ? D3D11_MAP_FLAG_DO_NOT_WAIT : 0); - - HRESULT result = context->Map(mBuffer.get(), 0, d3dMapType, d3dMapFlag, &mappedResource); - ASSERT(SUCCEEDED(result)); - if (FAILED(result)) - { - return gl::OutOfMemory() << "Failed to map native storage in Buffer11::NativeStorage::map"; - } - ASSERT(mappedResource.pData); - *mapPointerOut = static_cast<uint8_t *>(mappedResource.pData) + offset; - return gl::NoError(); -} - -void Buffer11::NativeStorage::unmap() -{ - ASSERT(isCPUAccessible(GL_MAP_WRITE_BIT) || isCPUAccessible(GL_MAP_READ_BIT)); - ID3D11DeviceContext *context = mRenderer->getDeviceContext(); - context->Unmap(mBuffer.get(), 0); -} - -gl::ErrorOrResult<const d3d11::ShaderResourceView *> Buffer11::NativeStorage::getSRVForFormat( - DXGI_FORMAT srvFormat) -{ - auto bufferSRVIt = mBufferResourceViews.find(srvFormat); - - if (bufferSRVIt != mBufferResourceViews.end()) - { - return &bufferSRVIt->second; - } - - const d3d11::DXGIFormatSize &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(srvFormat); - - D3D11_SHADER_RESOURCE_VIEW_DESC bufferSRVDesc; - bufferSRVDesc.Buffer.ElementOffset = 0; - bufferSRVDesc.Buffer.ElementWidth = static_cast<UINT>(mBufferSize) / dxgiFormatInfo.pixelBytes; - bufferSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; - bufferSRVDesc.Format = srvFormat; - - ANGLE_TRY(mRenderer->allocateResource(bufferSRVDesc, mBuffer.get(), - &mBufferResourceViews[srvFormat])); - - return &mBufferResourceViews[srvFormat]; -} - -void Buffer11::NativeStorage::clearSRVs() -{ - mBufferResourceViews.clear(); -} - -// Buffer11::EmulatedIndexStorage implementation - -Buffer11::EmulatedIndexedStorage::EmulatedIndexedStorage(Renderer11 *renderer) - : BufferStorage(renderer, BUFFER_USAGE_EMULATED_INDEXED_VERTEX), mBuffer() -{ -} - -Buffer11::EmulatedIndexedStorage::~EmulatedIndexedStorage() -{ -} - -gl::ErrorOrResult<const d3d11::Buffer *> Buffer11::EmulatedIndexedStorage::getBuffer( - SourceIndexData *indexInfo, - const TranslatedAttribute &attribute, - GLint startVertex) -{ - // If a change in the indices applied from the last draw call is detected, then the emulated - // indexed buffer needs to be invalidated. After invalidation, the change detected flag should - // be cleared to avoid unnecessary recreation of the buffer. - if (!mBuffer.valid() || indexInfo->srcIndicesChanged) - { - mBuffer.reset(); - - // Copy the source index data. This ensures that the lifetime of the indices pointer - // stays with this storage until the next time we invalidate. - size_t indicesDataSize = 0; - switch (indexInfo->srcIndexType) - { - case GL_UNSIGNED_INT: - indicesDataSize = sizeof(GLuint) * indexInfo->srcCount; - break; - case GL_UNSIGNED_SHORT: - indicesDataSize = sizeof(GLushort) * indexInfo->srcCount; - break; - case GL_UNSIGNED_BYTE: - indicesDataSize = sizeof(GLubyte) * indexInfo->srcCount; - break; - default: - indicesDataSize = sizeof(GLushort) * indexInfo->srcCount; - break; - } - - if (!mIndicesMemoryBuffer.resize(indicesDataSize)) - { - return gl::OutOfMemory() << "Error resizing index memory buffer in " - "Buffer11::EmulatedIndexedStorage::getBuffer"; - } - - memcpy(mIndicesMemoryBuffer.data(), indexInfo->srcIndices, indicesDataSize); - - indexInfo->srcIndicesChanged = false; - } - - if (!mBuffer.valid()) - { - unsigned int offset = 0; - ANGLE_TRY_RESULT(attribute.computeOffset(startVertex), offset); - - // Expand the memory storage upon request and cache the results. - unsigned int expandedDataSize = - static_cast<unsigned int>((indexInfo->srcCount * attribute.stride) + offset); - angle::MemoryBuffer expandedData; - if (!expandedData.resize(expandedDataSize)) - { - return gl::OutOfMemory() - << "Error resizing buffer in Buffer11::EmulatedIndexedStorage::getBuffer"; - } - - // Clear the contents of the allocated buffer - ZeroMemory(expandedData.data(), expandedDataSize); - - uint8_t *curr = expandedData.data(); - const uint8_t *ptr = static_cast<const uint8_t *>(indexInfo->srcIndices); - - // Ensure that we start in the correct place for the emulated data copy operation to - // maintain offset behaviors. - curr += offset; - - ReadIndexValueFunction readIndexValue = ReadIndexValueFromIndices<GLushort>; - - switch (indexInfo->srcIndexType) - { - case GL_UNSIGNED_INT: - readIndexValue = ReadIndexValueFromIndices<GLuint>; - break; - case GL_UNSIGNED_SHORT: - readIndexValue = ReadIndexValueFromIndices<GLushort>; - break; - case GL_UNSIGNED_BYTE: - readIndexValue = ReadIndexValueFromIndices<GLubyte>; - break; - } - - // Iterate over the cached index data and copy entries indicated into the emulated buffer. - for (GLuint i = 0; i < indexInfo->srcCount; i++) - { - GLuint idx = readIndexValue(ptr, i); - memcpy(curr, mMemoryBuffer.data() + (attribute.stride * idx), attribute.stride); - curr += attribute.stride; - } - - // Finally, initialize the emulated indexed native storage object with the newly copied data - // and free the temporary buffers used. - D3D11_BUFFER_DESC bufferDesc; - bufferDesc.ByteWidth = expandedDataSize; - bufferDesc.MiscFlags = 0; - bufferDesc.StructureByteStride = 0; - bufferDesc.Usage = D3D11_USAGE_DEFAULT; - bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bufferDesc.CPUAccessFlags = 0; - - D3D11_SUBRESOURCE_DATA subResourceData = {expandedData.data(), 0, 0}; - - ANGLE_TRY(mRenderer->allocateResource(bufferDesc, &subResourceData, &mBuffer)); - mBuffer.setDebugName("Buffer11::EmulatedIndexedStorage"); - } - - return &mBuffer; -} - -gl::ErrorOrResult<CopyResult> Buffer11::EmulatedIndexedStorage::copyFromStorage( - const gl::Context *context, - BufferStorage *source, - size_t sourceOffset, - size_t size, - size_t destOffset) -{ - ASSERT(source->isCPUAccessible(GL_MAP_READ_BIT)); - uint8_t *sourceData = nullptr; - ANGLE_TRY(source->map(sourceOffset, size, GL_MAP_READ_BIT, &sourceData)); - ASSERT(destOffset + size <= mMemoryBuffer.size()); - memcpy(mMemoryBuffer.data() + destOffset, sourceData, size); - source->unmap(); - return CopyResult::RECREATED; -} - -gl::Error Buffer11::EmulatedIndexedStorage::resize(const gl::Context *context, - size_t size, - bool preserveData) -{ - if (mMemoryBuffer.size() < size) - { - if (!mMemoryBuffer.resize(size)) - { - return gl::OutOfMemory() << "Failed to resize EmulatedIndexedStorage"; - } - mBufferSize = size; - } - - return gl::NoError(); -} - -gl::Error Buffer11::EmulatedIndexedStorage::map(size_t offset, - size_t length, - GLbitfield access, - uint8_t **mapPointerOut) -{ - ASSERT(!mMemoryBuffer.empty() && offset + length <= mMemoryBuffer.size()); - *mapPointerOut = mMemoryBuffer.data() + offset; - return gl::NoError(); -} - -void Buffer11::EmulatedIndexedStorage::unmap() -{ - // No-op -} - -// Buffer11::PackStorage implementation - -Buffer11::PackStorage::PackStorage(Renderer11 *renderer) - : BufferStorage(renderer, BUFFER_USAGE_PIXEL_PACK), mStagingTexture(), mDataModified(false) -{ -} - -Buffer11::PackStorage::~PackStorage() -{ -} - -gl::ErrorOrResult<CopyResult> Buffer11::PackStorage::copyFromStorage(const gl::Context *context, - BufferStorage *source, - size_t sourceOffset, - size_t size, - size_t destOffset) -{ - ANGLE_TRY(flushQueuedPackCommand()); - - // For all use cases of pack buffers, we must copy through a readable buffer. - ASSERT(source->isCPUAccessible(GL_MAP_READ_BIT)); - uint8_t *sourceData = nullptr; - ANGLE_TRY(source->map(sourceOffset, size, GL_MAP_READ_BIT, &sourceData)); - ASSERT(destOffset + size <= mMemoryBuffer.size()); - memcpy(mMemoryBuffer.data() + destOffset, sourceData, size); - source->unmap(); - return CopyResult::NOT_RECREATED; -} - -gl::Error Buffer11::PackStorage::resize(const gl::Context *context, size_t size, bool preserveData) -{ - if (size != mBufferSize) - { - if (!mMemoryBuffer.resize(size)) - { - return gl::OutOfMemory() << "Failed to resize internal buffer storage."; - } - mBufferSize = size; - } - - return gl::NoError(); -} - -gl::Error Buffer11::PackStorage::map(size_t offset, - size_t length, - GLbitfield access, - uint8_t **mapPointerOut) -{ - ASSERT(offset + length <= getSize()); - // TODO: fast path - // We might be able to optimize out one or more memcpy calls by detecting when - // and if D3D packs the staging texture memory identically to how we would fill - // the pack buffer according to the current pack state. - - ANGLE_TRY(flushQueuedPackCommand()); - - mDataModified = (mDataModified || (access & GL_MAP_WRITE_BIT) != 0); - - *mapPointerOut = mMemoryBuffer.data() + offset; - return gl::NoError(); -} - -void Buffer11::PackStorage::unmap() -{ - // No-op -} - -gl::Error Buffer11::PackStorage::packPixels(const gl::Context *context, - const gl::FramebufferAttachment &readAttachment, - const PackPixelsParams ¶ms) -{ - ANGLE_TRY(flushQueuedPackCommand()); - - RenderTarget11 *renderTarget = nullptr; - ANGLE_TRY(readAttachment.getRenderTarget(context, &renderTarget)); - - const TextureHelper11 &srcTexture = renderTarget->getTexture(); - ASSERT(srcTexture.valid()); - unsigned int srcSubresource = renderTarget->getSubresourceIndex(); - - mQueuedPackCommand.reset(new PackPixelsParams(params)); - - gl::Extents srcTextureSize(params.area.width, params.area.height, 1); - if (!mStagingTexture.get() || mStagingTexture.getFormat() != srcTexture.getFormat() || - mStagingTexture.getExtents() != srcTextureSize) - { - ANGLE_TRY_RESULT( - mRenderer->createStagingTexture(srcTexture.getTextureType(), srcTexture.getFormatSet(), - srcTextureSize, StagingAccess::READ), - mStagingTexture); - } - - // ReadPixels from multisampled FBOs isn't supported in current GL - ASSERT(srcTexture.getSampleCount() <= 1); - - ID3D11DeviceContext *immediateContext = mRenderer->getDeviceContext(); - D3D11_BOX srcBox; - srcBox.left = params.area.x; - srcBox.right = params.area.x + params.area.width; - srcBox.top = params.area.y; - srcBox.bottom = params.area.y + params.area.height; - - // Select the correct layer from a 3D attachment - srcBox.front = 0; - if (mStagingTexture.is3D()) - { - srcBox.front = static_cast<UINT>(readAttachment.layer()); - } - srcBox.back = srcBox.front + 1; - - // Asynchronous copy - immediateContext->CopySubresourceRegion(mStagingTexture.get(), 0, 0, 0, 0, srcTexture.get(), - srcSubresource, &srcBox); - - return gl::NoError(); -} - -gl::Error Buffer11::PackStorage::flushQueuedPackCommand() -{ - ASSERT(mMemoryBuffer.size() > 0); - - if (mQueuedPackCommand) - { - ANGLE_TRY( - mRenderer->packPixels(mStagingTexture, *mQueuedPackCommand, mMemoryBuffer.data())); - mQueuedPackCommand.reset(nullptr); - } - - return gl::NoError(); -} - -// Buffer11::SystemMemoryStorage implementation - -Buffer11::SystemMemoryStorage::SystemMemoryStorage(Renderer11 *renderer) - : Buffer11::BufferStorage(renderer, BUFFER_USAGE_SYSTEM_MEMORY) -{ -} - -gl::ErrorOrResult<CopyResult> Buffer11::SystemMemoryStorage::copyFromStorage( - const gl::Context *context, - BufferStorage *source, - size_t sourceOffset, - size_t size, - size_t destOffset) -{ - ASSERT(source->isCPUAccessible(GL_MAP_READ_BIT)); - uint8_t *sourceData = nullptr; - ANGLE_TRY(source->map(sourceOffset, size, GL_MAP_READ_BIT, &sourceData)); - ASSERT(destOffset + size <= mSystemCopy.size()); - memcpy(mSystemCopy.data() + destOffset, sourceData, size); - source->unmap(); - return CopyResult::RECREATED; -} - -gl::Error Buffer11::SystemMemoryStorage::resize(const gl::Context *context, - size_t size, - bool preserveData) -{ - if (mSystemCopy.size() < size) - { - if (!mSystemCopy.resize(size)) - { - return gl::OutOfMemory() << "Failed to resize SystemMemoryStorage"; - } - mBufferSize = size; - } - - return gl::NoError(); -} - -gl::Error Buffer11::SystemMemoryStorage::map(size_t offset, - size_t length, - GLbitfield access, - uint8_t **mapPointerOut) -{ - ASSERT(!mSystemCopy.empty() && offset + length <= mSystemCopy.size()); - *mapPointerOut = mSystemCopy.data() + offset; - return gl::NoError(); -} - -void Buffer11::SystemMemoryStorage::unmap() -{ - // No-op -} -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Buffer11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Buffer11.h deleted file mode 100644 index f92a68454b..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Buffer11.h +++ /dev/null @@ -1,189 +0,0 @@ -// -// Copyright 2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Buffer11.h: Defines the rx::Buffer11 class which implements rx::BufferImpl via rx::BufferD3D. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_BUFFER11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_BUFFER11_H_ - -#include <array> -#include <map> - -#include "libANGLE/angletypes.h" -#include "libANGLE/renderer/d3d/BufferD3D.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -namespace gl -{ -class FramebufferAttachment; -} - -namespace rx -{ -struct PackPixelsParams; -class Renderer11; -struct SourceIndexData; -struct TranslatedAttribute; - -// The order of this enum governs priority of 'getLatestBufferStorage'. -enum BufferUsage -{ - BUFFER_USAGE_STAGING, - BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK, - BUFFER_USAGE_INDEX, - // TODO: possibly share this buffer type with shader storage buffers. - BUFFER_USAGE_INDIRECT, - BUFFER_USAGE_PIXEL_UNPACK, - BUFFER_USAGE_PIXEL_PACK, - BUFFER_USAGE_UNIFORM, - BUFFER_USAGE_SYSTEM_MEMORY, - BUFFER_USAGE_EMULATED_INDEXED_VERTEX, - - BUFFER_USAGE_COUNT, -}; - -typedef size_t DataRevision; - -class Buffer11 : public BufferD3D -{ - public: - Buffer11(const gl::BufferState &state, Renderer11 *renderer); - ~Buffer11() override; - - gl::ErrorOrResult<ID3D11Buffer *> getBuffer(const gl::Context *context, BufferUsage usage); - gl::ErrorOrResult<ID3D11Buffer *> getEmulatedIndexedBuffer(const gl::Context *context, - SourceIndexData *indexInfo, - const TranslatedAttribute &attribute, - GLint startVertex); - gl::Error getConstantBufferRange(const gl::Context *context, - GLintptr offset, - GLsizeiptr size, - const d3d11::Buffer **bufferOut, - UINT *firstConstantOut, - UINT *numConstantsOut); - gl::ErrorOrResult<const d3d11::ShaderResourceView *> getSRV(const gl::Context *context, - DXGI_FORMAT srvFormat); - bool isMapped() const { return mMappedStorage != nullptr; } - gl::Error packPixels(const gl::Context *context, - const gl::FramebufferAttachment &readAttachment, - const PackPixelsParams ¶ms); - size_t getTotalCPUBufferMemoryBytes() const; - - // BufferD3D implementation - size_t getSize() const override; - bool supportsDirectBinding() const override; - gl::Error getData(const gl::Context *context, const uint8_t **outData) override; - void initializeStaticData(const gl::Context *context) override; - void invalidateStaticData(const gl::Context *context) override; - - // BufferImpl implementation - gl::Error setData(const gl::Context *context, - gl::BufferBinding target, - const void *data, - size_t size, - gl::BufferUsage usage) override; - gl::Error setSubData(const gl::Context *context, - gl::BufferBinding target, - const void *data, - size_t size, - size_t offset) override; - gl::Error copySubData(const gl::Context *context, - BufferImpl *source, - GLintptr sourceOffset, - GLintptr destOffset, - GLsizeiptr size) override; - gl::Error map(const gl::Context *context, GLenum access, void **mapPtr) override; - gl::Error mapRange(const gl::Context *context, - size_t offset, - size_t length, - GLbitfield access, - void **mapPtr) override; - gl::Error unmap(const gl::Context *context, GLboolean *result) override; - gl::Error markTransformFeedbackUsage(const gl::Context *context) override; - - // We use two set of dirty events. Static buffers are marked dirty whenever - // data changes, because they must be re-translated. Direct buffers only need to be - // updated when the underlying ID3D11Buffer pointer changes - hopefully far less often. - OnBufferDataDirtyChannel *getStaticBroadcastChannel(); - OnBufferDataDirtyChannel *getDirectBroadcastChannel(); - - private: - class BufferStorage; - class EmulatedIndexedStorage; - class NativeStorage; - class PackStorage; - class SystemMemoryStorage; - - struct ConstantBufferCacheEntry - { - ConstantBufferCacheEntry() : storage(nullptr), lruCount(0) {} - - BufferStorage *storage; - unsigned int lruCount; - }; - - void markBufferUsage(BufferUsage usage); - gl::Error garbageCollection(const gl::Context *context, BufferUsage currentUsage); - gl::ErrorOrResult<NativeStorage *> getStagingStorage(const gl::Context *context); - gl::ErrorOrResult<PackStorage *> getPackStorage(const gl::Context *context); - gl::ErrorOrResult<SystemMemoryStorage *> getSystemMemoryStorage(const gl::Context *context); - - gl::Error updateBufferStorage(const gl::Context *context, - BufferStorage *storage, - size_t sourceOffset, - size_t storageSize); - gl::ErrorOrResult<BufferStorage *> getBufferStorage(const gl::Context *context, - BufferUsage usage); - gl::ErrorOrResult<BufferStorage *> getLatestBufferStorage(const gl::Context *context) const; - - gl::ErrorOrResult<BufferStorage *> getConstantBufferRangeStorage(const gl::Context *context, - GLintptr offset, - GLsizeiptr size); - - BufferStorage *allocateStorage(BufferUsage usage); - void updateDeallocThreshold(BufferUsage usage); - - // Free the storage if we decide it isn't being used very often. - gl::Error checkForDeallocation(const gl::Context *context, BufferUsage usage); - - // For some cases of uniform buffer storage, we can't deallocate system memory storage. - bool canDeallocateSystemMemory() const; - - // Updates data revisions and latest storage. - void onCopyStorage(BufferStorage *dest, BufferStorage *source); - void onStorageUpdate(BufferStorage *updatedStorage); - - Renderer11 *mRenderer; - size_t mSize; - - BufferStorage *mMappedStorage; - - // Buffer storages are sorted by usage. It's important that the latest buffer storage picks - // the lowest usage in the case where two storages are tied on data revision - this ensures - // we never do anything dangerous like map a uniform buffer over a staging or system memory - // copy. - std::array<BufferStorage *, BUFFER_USAGE_COUNT> mBufferStorages; - BufferStorage *mLatestBufferStorage; - - // These two arrays are used to track when to free unused storage. - std::array<unsigned int, BUFFER_USAGE_COUNT> mDeallocThresholds; - std::array<unsigned int, BUFFER_USAGE_COUNT> mIdleness; - - // Cache of D3D11 constant buffer for specific ranges of buffer data. - // This is used to emulate UBO ranges on 11.0 devices. - // Constant buffers are indexed by there start offset. - typedef std::map<GLintptr /*offset*/, ConstantBufferCacheEntry> ConstantBufferCache; - ConstantBufferCache mConstantBufferRangeStoragesCache; - size_t mConstantBufferStorageAdditionalSize; - unsigned int mMaxConstantBufferLruCount; - - OnBufferDataDirtyChannel mStaticBroadcastChannel; - OnBufferDataDirtyChannel mDirectBroadcastChannel; -}; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_BUFFER11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Clear11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Clear11.cpp deleted file mode 100644 index f9dda0aeb4..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Clear11.cpp +++ /dev/null @@ -1,833 +0,0 @@ - -// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Clear11.cpp: Framebuffer clear utility class. - -#include "libANGLE/renderer/d3d/d3d11/Clear11.h" - -#include <algorithm> - -#include "libANGLE/FramebufferAttachment.h" -#include "libANGLE/formatutils.h" -#include "libANGLE/renderer/d3d/FramebufferD3D.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h" -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" -#include "third_party/trace_event/trace_event.h" - -// Precompiled shaders -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clear11_fl9vs.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clear11multiviewgs.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clear11multiviewvs.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clear11vs.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/cleardepth11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearfloat11_fl9ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearfloat11ps1.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearfloat11ps2.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearfloat11ps3.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearfloat11ps4.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearfloat11ps5.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearfloat11ps6.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearfloat11ps7.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearfloat11ps8.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearsint11ps1.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearsint11ps2.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearsint11ps3.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearsint11ps4.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearsint11ps5.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearsint11ps6.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearsint11ps7.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearsint11ps8.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearuint11ps1.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearuint11ps2.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearuint11ps3.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearuint11ps4.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearuint11ps5.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearuint11ps6.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearuint11ps7.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clearuint11ps8.h" - -namespace rx -{ - -namespace -{ -constexpr uint32_t g_ConstantBufferSize = sizeof(RtvDsvClearInfo<float>); -constexpr uint32_t g_VertexSize = sizeof(d3d11::PositionVertex); - -// Updates color, depth and alpha components of cached CB if necessary. -// Returns true if any constants are updated, false otherwise. -template <typename T> -bool UpdateDataCache(RtvDsvClearInfo<T> *dataCache, - const gl::Color<T> &color, - const float *zValue, - const uint32_t numRtvs, - const uint8_t writeMask) -{ - bool cacheDirty = false; - - if (numRtvs > 0) - { - const bool writeRGB = (writeMask & ~D3D11_COLOR_WRITE_ENABLE_ALPHA) != 0; - if (writeRGB && memcmp(&dataCache->r, &color.red, sizeof(T) * 3) != 0) - { - dataCache->r = color.red; - dataCache->g = color.green; - dataCache->b = color.blue; - cacheDirty = true; - } - - const bool writeAlpha = (writeMask & D3D11_COLOR_WRITE_ENABLE_ALPHA) != 0; - if (writeAlpha && (dataCache->a != color.alpha)) - { - dataCache->a = color.alpha; - cacheDirty = true; - } - } - - if (zValue) - { - const float clampedZValue = gl::clamp01(*zValue); - - if (clampedZValue != dataCache->z) - { - dataCache->z = clampedZValue; - cacheDirty = true; - } - } - - return cacheDirty; -} - -bool AllOffsetsAreNonNegative(const std::vector<gl::Offset> &viewportOffsets) -{ - for (size_t i = 0u; i < viewportOffsets.size(); ++i) - { - const auto &offset = viewportOffsets[i]; - if (offset.x < 0 || offset.y < 0) - { - return false; - } - } - return true; -} -} // anonymous namespace - -#define CLEARPS(Index) \ - d3d11::LazyShader<ID3D11PixelShader>(g_PS_Clear##Index, ArraySize(g_PS_Clear##Index), \ - "Clear11 PS " ANGLE_STRINGIFY(Index)) - -Clear11::ShaderManager::ShaderManager() - : mIl9(), - mVs9(g_VS_Clear_FL9, ArraySize(g_VS_Clear_FL9), "Clear11 VS FL9"), - mPsFloat9(g_PS_ClearFloat_FL9, ArraySize(g_PS_ClearFloat_FL9), "Clear11 PS FloatFL9"), - mVs(g_VS_Clear, ArraySize(g_VS_Clear), "Clear11 VS"), - mVsMultiview(g_VS_Multiview_Clear, ArraySize(g_VS_Multiview_Clear), "Clear11 VS Multiview"), - mGsMultiview(g_GS_Multiview_Clear, ArraySize(g_GS_Multiview_Clear), "Clear11 GS Multiview"), - mPsDepth(g_PS_ClearDepth, ArraySize(g_PS_ClearDepth), "Clear11 PS Depth"), - mPsFloat{{CLEARPS(Float1), CLEARPS(Float2), CLEARPS(Float3), CLEARPS(Float4), CLEARPS(Float5), - CLEARPS(Float6), CLEARPS(Float7), CLEARPS(Float8)}}, - mPsUInt{{CLEARPS(Uint1), CLEARPS(Uint2), CLEARPS(Uint3), CLEARPS(Uint4), CLEARPS(Uint5), - CLEARPS(Uint6), CLEARPS(Uint7), CLEARPS(Uint8)}}, - mPsSInt{{CLEARPS(Sint1), CLEARPS(Sint2), CLEARPS(Sint3), CLEARPS(Sint4), CLEARPS(Sint5), - CLEARPS(Sint6), CLEARPS(Sint7), CLEARPS(Sint8)}} -{ -} - -#undef CLEARPS - -Clear11::ShaderManager::~ShaderManager() -{ -} - -gl::Error Clear11::ShaderManager::getShadersAndLayout(Renderer11 *renderer, - const INT clearType, - const uint32_t numRTs, - const bool hasLayeredLayout, - const d3d11::InputLayout **il, - const d3d11::VertexShader **vs, - const d3d11::GeometryShader **gs, - const d3d11::PixelShader **ps) -{ - if (renderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_9_3) - { - ASSERT(clearType == GL_FLOAT); - - ANGLE_TRY(mVs9.resolve(renderer)); - ANGLE_TRY(mPsFloat9.resolve(renderer)); - - if (!mIl9.valid()) - { - const D3D11_INPUT_ELEMENT_DESC ilDesc[] = { - {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}}; - - InputElementArray ilDescArray(ilDesc); - ShaderData vertexShader(g_VS_Clear_FL9); - - ANGLE_TRY(renderer->allocateResource(ilDescArray, &vertexShader, &mIl9)); - } - - *vs = &mVs9.getObj(); - *gs = nullptr; - *il = &mIl9; - *ps = &mPsFloat9.getObj(); - return gl::NoError(); - } - if (!hasLayeredLayout) - { - ANGLE_TRY(mVs.resolve(renderer)); - *vs = &mVs.getObj(); - *gs = nullptr; - } - else - { - // For layered framebuffers we have to use the multi-view versions of the VS and GS. - ANGLE_TRY(mVsMultiview.resolve(renderer)); - ANGLE_TRY(mGsMultiview.resolve(renderer)); - *vs = &mVsMultiview.getObj(); - *gs = &mGsMultiview.getObj(); - } - - *il = nullptr; - - if (numRTs == 0) - { - ANGLE_TRY(mPsDepth.resolve(renderer)); - *ps = &mPsDepth.getObj(); - return gl::NoError(); - } - - switch (clearType) - { - case GL_FLOAT: - ANGLE_TRY(mPsFloat[numRTs - 1].resolve(renderer)); - *ps = &mPsFloat[numRTs - 1].getObj(); - break; - case GL_UNSIGNED_INT: - ANGLE_TRY(mPsUInt[numRTs - 1].resolve(renderer)); - *ps = &mPsUInt[numRTs - 1].getObj(); - break; - case GL_INT: - ANGLE_TRY(mPsSInt[numRTs - 1].resolve(renderer)); - *ps = &mPsSInt[numRTs - 1].getObj(); - break; - default: - UNREACHABLE(); - break; - } - - return gl::NoError(); -} - -Clear11::Clear11(Renderer11 *renderer) - : mRenderer(renderer), - mResourcesInitialized(false), - mScissorEnabledRasterizerState(), - mScissorDisabledRasterizerState(), - mShaderManager(), - mConstantBuffer(), - mVertexBuffer(), - mShaderData({}) -{ -} - -Clear11::~Clear11() -{ -} - -gl::Error Clear11::ensureResourcesInitialized() -{ - if (mResourcesInitialized) - { - return gl::NoError(); - } - - TRACE_EVENT0("gpu.angle", "Clear11::ensureResourcesInitialized"); - - static_assert((sizeof(RtvDsvClearInfo<float>) == sizeof(RtvDsvClearInfo<int>)), - "Size of rx::RtvDsvClearInfo<float> is not equal to rx::RtvDsvClearInfo<int>"); - - static_assert( - (sizeof(RtvDsvClearInfo<float>) == sizeof(RtvDsvClearInfo<uint32_t>)), - "Size of rx::RtvDsvClearInfo<float> is not equal to rx::RtvDsvClearInfo<uint32_t>"); - - static_assert((sizeof(RtvDsvClearInfo<float>) % 16 == 0), - "The size of RtvDsvClearInfo<float> should be a multiple of 16bytes."); - - // Create Rasterizer States - D3D11_RASTERIZER_DESC rsDesc; - rsDesc.FillMode = D3D11_FILL_SOLID; - rsDesc.CullMode = D3D11_CULL_NONE; - rsDesc.FrontCounterClockwise = FALSE; - rsDesc.DepthBias = 0; - rsDesc.DepthBiasClamp = 0.0f; - rsDesc.SlopeScaledDepthBias = 0.0f; - rsDesc.DepthClipEnable = TRUE; - rsDesc.ScissorEnable = FALSE; - rsDesc.MultisampleEnable = FALSE; - rsDesc.AntialiasedLineEnable = FALSE; - - ANGLE_TRY(mRenderer->allocateResource(rsDesc, &mScissorDisabledRasterizerState)); - mScissorDisabledRasterizerState.setDebugName("Clear11 Rasterizer State with scissor disabled"); - - rsDesc.ScissorEnable = TRUE; - ANGLE_TRY(mRenderer->allocateResource(rsDesc, &mScissorEnabledRasterizerState)); - mScissorEnabledRasterizerState.setDebugName("Clear11 Rasterizer State with scissor enabled"); - - // Initialize Depthstencil state with defaults - mDepthStencilStateKey.depthTest = false; - mDepthStencilStateKey.depthMask = false; - mDepthStencilStateKey.depthFunc = GL_ALWAYS; - mDepthStencilStateKey.stencilWritemask = static_cast<GLuint>(-1); - mDepthStencilStateKey.stencilBackWritemask = static_cast<GLuint>(-1); - mDepthStencilStateKey.stencilBackMask = 0; - mDepthStencilStateKey.stencilTest = false; - mDepthStencilStateKey.stencilMask = 0; - mDepthStencilStateKey.stencilFail = GL_REPLACE; - mDepthStencilStateKey.stencilPassDepthFail = GL_REPLACE; - mDepthStencilStateKey.stencilPassDepthPass = GL_REPLACE; - mDepthStencilStateKey.stencilFunc = GL_ALWAYS; - mDepthStencilStateKey.stencilBackFail = GL_REPLACE; - mDepthStencilStateKey.stencilBackPassDepthFail = GL_REPLACE; - mDepthStencilStateKey.stencilBackPassDepthPass = GL_REPLACE; - mDepthStencilStateKey.stencilBackFunc = GL_ALWAYS; - - // Initialize BlendStateKey with defaults - mBlendStateKey.blendState.blend = false; - mBlendStateKey.blendState.sourceBlendRGB = GL_ONE; - mBlendStateKey.blendState.sourceBlendAlpha = GL_ONE; - mBlendStateKey.blendState.destBlendRGB = GL_ZERO; - mBlendStateKey.blendState.destBlendAlpha = GL_ZERO; - mBlendStateKey.blendState.blendEquationRGB = GL_FUNC_ADD; - mBlendStateKey.blendState.blendEquationAlpha = GL_FUNC_ADD; - mBlendStateKey.blendState.sampleAlphaToCoverage = false; - mBlendStateKey.blendState.dither = true; - - mResourcesInitialized = true; - return gl::NoError(); -} - -bool Clear11::useVertexBuffer() const -{ - return (mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_9_3); -} - -gl::Error Clear11::ensureConstantBufferCreated() -{ - if (mConstantBuffer.valid()) - { - return gl::NoError(); - } - - // Create constant buffer for color & depth data - - D3D11_BUFFER_DESC bufferDesc; - bufferDesc.ByteWidth = g_ConstantBufferSize; - bufferDesc.Usage = D3D11_USAGE_DYNAMIC; - bufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - bufferDesc.MiscFlags = 0; - bufferDesc.StructureByteStride = 0; - - D3D11_SUBRESOURCE_DATA initialData; - initialData.pSysMem = &mShaderData; - initialData.SysMemPitch = g_ConstantBufferSize; - initialData.SysMemSlicePitch = g_ConstantBufferSize; - - ANGLE_TRY(mRenderer->allocateResource(bufferDesc, &initialData, &mConstantBuffer)); - mConstantBuffer.setDebugName("Clear11 Constant Buffer"); - return gl::NoError(); -} - -gl::Error Clear11::ensureVertexBufferCreated() -{ - ASSERT(useVertexBuffer()); - - if (mVertexBuffer.valid()) - { - return gl::NoError(); - } - - // Create vertex buffer with vertices for a quad covering the entire surface - - static_assert((sizeof(d3d11::PositionVertex) % 16) == 0, - "d3d11::PositionVertex should be a multiple of 16 bytes"); - const d3d11::PositionVertex vbData[6] = {{-1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, -1.0f, 0.0f, 1.0f}, - {-1.0f, -1.0f, 0.0f, 1.0f}, {-1.0f, 1.0f, 0.0f, 1.0f}, - {1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, -1.0f, 0.0f, 1.0f}}; - - const UINT vbSize = sizeof(vbData); - - D3D11_BUFFER_DESC bufferDesc; - bufferDesc.ByteWidth = vbSize; - bufferDesc.Usage = D3D11_USAGE_IMMUTABLE; - bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bufferDesc.CPUAccessFlags = 0; - bufferDesc.MiscFlags = 0; - bufferDesc.StructureByteStride = 0; - - D3D11_SUBRESOURCE_DATA initialData; - initialData.pSysMem = vbData; - initialData.SysMemPitch = vbSize; - initialData.SysMemSlicePitch = initialData.SysMemPitch; - - ANGLE_TRY(mRenderer->allocateResource(bufferDesc, &initialData, &mVertexBuffer)); - mVertexBuffer.setDebugName("Clear11 Vertex Buffer"); - return gl::NoError(); -} - -gl::Error Clear11::clearFramebuffer(const gl::Context *context, - const ClearParameters &clearParams, - const gl::FramebufferState &fboData) -{ - ANGLE_TRY(ensureResourcesInitialized()); - - // Iterate over the color buffers which require clearing and determine if they can be - // cleared with ID3D11DeviceContext::ClearRenderTargetView or ID3D11DeviceContext1::ClearView. - // This requires: - // 1) The render target is being cleared to a float value (will be cast to integer when clearing - // integer render targets as expected but does not work the other way around) - // 2) The format of the render target has no color channels that are currently masked out. - // Clear the easy-to-clear buffers on the spot and accumulate the ones that require special - // work. - // - // If these conditions are met, and: - // - No scissored clear is needed, then clear using ID3D11DeviceContext::ClearRenderTargetView. - // - A scissored clear is needed then clear using ID3D11DeviceContext1::ClearView if available. - // Otherwise perform a shader based clear. - // - // Also determine if the DSV can be cleared withID3D11DeviceContext::ClearDepthStencilView by - // checking if the stencil write mask covers the entire stencil. - // - // To clear the remaining buffers, a shader based clear is performed: - // - The appropriate ShaderManagers (VS & PS) for the clearType is set - // - A CB containing the clear color and Z values is bound - // - An IL and VB are bound (for FL93 and below) - // - ScissorRect/Raststate/Viewport set as required - // - Blendstate set containing appropriate colorMasks - // - DepthStencilState set with appropriate parameters for a z or stencil clear if required - // - Color and/or Z buffers to be cleared are bound - // - Primitive covering entire clear area is drawn - - gl::Extents framebufferSize; - - const auto *depthStencilAttachment = fboData.getDepthOrStencilAttachment(); - if (depthStencilAttachment != nullptr) - { - framebufferSize = depthStencilAttachment->getSize(); - } - else - { - const gl::FramebufferAttachment *colorAttachment = fboData.getFirstColorAttachment(); - - if (!colorAttachment) - { - UNREACHABLE(); - return gl::InternalError(); - } - - framebufferSize = colorAttachment->getSize(); - } - - const bool isSideBySideFBO = - (fboData.getMultiviewLayout() == GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE); - bool needScissoredClear = false; - std::vector<D3D11_RECT> scissorRects; - if (clearParams.scissorEnabled) - { - const std::vector<gl::Offset> *viewportOffsets = fboData.getViewportOffsets(); - ASSERT(viewportOffsets != nullptr); - ASSERT(AllOffsetsAreNonNegative(*fboData.getViewportOffsets())); - - if (clearParams.scissor.x >= framebufferSize.width || - clearParams.scissor.y >= framebufferSize.height || clearParams.scissor.width == 0 || - clearParams.scissor.height == 0) - { - // The check assumes that the viewport offsets are not negative as according to the - // ANGLE_multiview spec. - // Scissor rect is outside the renderbuffer or is an empty rect. - return gl::NoError(); - } - - if (isSideBySideFBO) - { - // We always have to do a scissor clear for side-by-side framebuffers. - needScissoredClear = true; - } - else - { - // Because the viewport offsets can generate scissor rectangles within the framebuffer's - // bounds, we can do this check only for non-side-by-side framebuffers. - if (clearParams.scissor.x + clearParams.scissor.width <= 0 || - clearParams.scissor.y + clearParams.scissor.height <= 0) - { - // Scissor rect is outside the renderbuffer. - return gl::NoError(); - } - needScissoredClear = - clearParams.scissor.x > 0 || clearParams.scissor.y > 0 || - clearParams.scissor.x + clearParams.scissor.width < framebufferSize.width || - clearParams.scissor.y + clearParams.scissor.height < framebufferSize.height; - } - - if (needScissoredClear) - { - // Apply viewport offsets to compute the final scissor rectangles. This is valid also - // for non-side-by-side framebuffers, because the default viewport offset is {0,0}. - const size_t numViews = viewportOffsets->size(); - scissorRects.reserve(numViews); - for (size_t i = 0u; i < numViews; ++i) - { - const gl::Offset &offset = (*viewportOffsets)[i]; - D3D11_RECT rect; - int x = clearParams.scissor.x + offset.x; - int y = clearParams.scissor.y + offset.y; - rect.left = x; - rect.right = x + clearParams.scissor.width; - rect.top = y; - rect.bottom = y + clearParams.scissor.height; - scissorRects.emplace_back(rect); - } - } - } - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - ID3D11DeviceContext1 *deviceContext1 = mRenderer->getDeviceContext1IfSupported(); - - std::array<ID3D11RenderTargetView *, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT> rtvs; - std::array<uint8_t, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT> rtvMasks = {}; - - uint32_t numRtvs = 0; - const uint8_t colorMask = - gl_d3d11::ConvertColorMask(clearParams.colorMaskRed, clearParams.colorMaskGreen, - clearParams.colorMaskBlue, clearParams.colorMaskAlpha); - - const auto &colorAttachments = fboData.getColorAttachments(); - for (auto colorAttachmentIndex : fboData.getEnabledDrawBuffers()) - { - const gl::FramebufferAttachment &attachment = colorAttachments[colorAttachmentIndex]; - - if (!clearParams.clearColor[colorAttachmentIndex]) - { - continue; - } - - RenderTarget11 *renderTarget = nullptr; - ANGLE_TRY(attachment.getRenderTarget(context, &renderTarget)); - - const gl::InternalFormat &formatInfo = *attachment.getFormat().info; - - if (clearParams.colorType == GL_FLOAT && - !(formatInfo.componentType == GL_FLOAT || - formatInfo.componentType == GL_UNSIGNED_NORMALIZED || - formatInfo.componentType == GL_SIGNED_NORMALIZED)) - { - ERR() << "It is undefined behaviour to clear a render buffer which is not " - "normalized fixed point or floating-point to floating point values (color " - "attachment " - << colorAttachmentIndex << " has internal format " << attachment.getFormat() - << ")."; - } - - if ((formatInfo.redBits == 0 || !clearParams.colorMaskRed) && - (formatInfo.greenBits == 0 || !clearParams.colorMaskGreen) && - (formatInfo.blueBits == 0 || !clearParams.colorMaskBlue) && - (formatInfo.alphaBits == 0 || !clearParams.colorMaskAlpha)) - { - // Every channel either does not exist in the render target or is masked out - continue; - } - - const auto &framebufferRTV = renderTarget->getRenderTargetView(); - ASSERT(framebufferRTV.valid()); - - if ((!(mRenderer->getRenderer11DeviceCaps().supportsClearView) && needScissoredClear) || - clearParams.colorType != GL_FLOAT || - (formatInfo.redBits > 0 && !clearParams.colorMaskRed) || - (formatInfo.greenBits > 0 && !clearParams.colorMaskGreen) || - (formatInfo.blueBits > 0 && !clearParams.colorMaskBlue) || - (formatInfo.alphaBits > 0 && !clearParams.colorMaskAlpha)) - { - rtvs[numRtvs] = framebufferRTV.get(); - rtvMasks[numRtvs] = gl_d3d11::GetColorMask(formatInfo) & colorMask; - numRtvs++; - } - else - { - // ID3D11DeviceContext::ClearRenderTargetView or ID3D11DeviceContext1::ClearView is - // possible - - const auto &nativeFormat = renderTarget->getFormatSet().format(); - - // Check if the actual format has a channel that the internal format does not and - // set them to the default values - float clearValues[4] = { - ((formatInfo.redBits == 0 && nativeFormat.redBits > 0) ? 0.0f - : clearParams.colorF.red), - ((formatInfo.greenBits == 0 && nativeFormat.greenBits > 0) - ? 0.0f - : clearParams.colorF.green), - ((formatInfo.blueBits == 0 && nativeFormat.blueBits > 0) ? 0.0f - : clearParams.colorF.blue), - ((formatInfo.alphaBits == 0 && nativeFormat.alphaBits > 0) - ? 1.0f - : clearParams.colorF.alpha), - }; - - if (formatInfo.alphaBits == 1) - { - // Some drivers do not correctly handle calling Clear() on a format with 1-bit - // alpha. They can incorrectly round all non-zero values up to 1.0f. Note that - // WARP does not do this. We should handle the rounding for them instead. - clearValues[3] = (clearParams.colorF.alpha >= 0.5f) ? 1.0f : 0.0f; - } - - if (needScissoredClear) - { - // We shouldn't reach here if deviceContext1 is unavailable. - ASSERT(deviceContext1); - // There must be at least one scissor rectangle. - ASSERT(!scissorRects.empty()); - deviceContext1->ClearView(framebufferRTV.get(), clearValues, scissorRects.data(), - static_cast<UINT>(scissorRects.size())); - if (mRenderer->getWorkarounds().callClearTwice) - { - deviceContext1->ClearView(framebufferRTV.get(), clearValues, - scissorRects.data(), - static_cast<UINT>(scissorRects.size())); - } - } - else - { - deviceContext->ClearRenderTargetView(framebufferRTV.get(), clearValues); - if (mRenderer->getWorkarounds().callClearTwice) - { - deviceContext->ClearRenderTargetView(framebufferRTV.get(), clearValues); - } - } - } - } - - ID3D11DepthStencilView *dsv = nullptr; - - if (clearParams.clearDepth || clearParams.clearStencil) - { - RenderTarget11 *depthStencilRenderTarget = nullptr; - - ASSERT(depthStencilAttachment != nullptr); - ANGLE_TRY(depthStencilAttachment->getRenderTarget(context, &depthStencilRenderTarget)); - - dsv = depthStencilRenderTarget->getDepthStencilView().get(); - ASSERT(dsv != nullptr); - - const auto &nativeFormat = depthStencilRenderTarget->getFormatSet().format(); - const auto *stencilAttachment = fboData.getStencilAttachment(); - - uint32_t stencilUnmasked = - (stencilAttachment != nullptr) ? (1 << nativeFormat.stencilBits) - 1 : 0; - bool needMaskedStencilClear = - clearParams.clearStencil && - (clearParams.stencilWriteMask & stencilUnmasked) != stencilUnmasked; - - if (!needScissoredClear && !needMaskedStencilClear) - { - const UINT clearFlags = (clearParams.clearDepth ? D3D11_CLEAR_DEPTH : 0) | - (clearParams.clearStencil ? D3D11_CLEAR_STENCIL : 0); - const FLOAT depthClear = gl::clamp01(clearParams.depthValue); - const UINT8 stencilClear = clearParams.stencilValue & 0xFF; - - deviceContext->ClearDepthStencilView(dsv, clearFlags, depthClear, stencilClear); - - dsv = nullptr; - } - } - - if (numRtvs == 0 && dsv == nullptr) - { - return gl::NoError(); - } - - // Clear the remaining render targets and depth stencil in one pass by rendering a quad: - // - // IA/VS: Vertices containing position and color members are passed through to the next stage. - // The vertex position has XY coordinates equal to clip extents and a Z component equal to the - // Z clear value. The vertex color contains the clear color. - // - // Rasterizer: Viewport scales the VS output over the entire surface and depending on whether - // or not scissoring is enabled the appropriate scissor rect and rasterizerState with or without - // the scissor test enabled is set as well. - // - // DepthStencilTest: DepthTesting, DepthWrites, StencilMask and StencilWrites will be enabled or - // disabled or set depending on what the input depthStencil clear parameters are. Since the PS - // is not writing out depth or rejecting pixels, this should happen prior to the PS stage. - // - // PS: Will write out the color values passed through from the previous stage to all outputs. - // - // OM: BlendState will perform the required color masking and output to RTV(s). - - // - // ====================================================================================== - // - // Luckily, the gl spec (ES 3.0.2 pg 183) states that the results of clearing a render- - // buffer that is not normalized fixed point or floating point with floating point values - // are undefined so we can just write floats to them and D3D11 will bit cast them to - // integers. - // - // Also, we don't have to worry about attempting to clear a normalized fixed/floating point - // buffer with integer values because there is no gl API call which would allow it, - // glClearBuffer* calls only clear a single renderbuffer at a time which is verified to - // be a compatible clear type. - - ASSERT(numRtvs <= mRenderer->getNativeCaps().maxDrawBuffers); - - // Setup BlendStateKey parameters - mBlendStateKey.blendState.colorMaskRed = clearParams.colorMaskRed; - mBlendStateKey.blendState.colorMaskGreen = clearParams.colorMaskGreen; - mBlendStateKey.blendState.colorMaskBlue = clearParams.colorMaskBlue; - mBlendStateKey.blendState.colorMaskAlpha = clearParams.colorMaskAlpha; - mBlendStateKey.rtvMax = numRtvs; - memcpy(mBlendStateKey.rtvMasks, &rtvMasks[0], sizeof(mBlendStateKey.rtvMasks)); - - // Get BlendState - const d3d11::BlendState *blendState = nullptr; - ANGLE_TRY(mRenderer->getBlendState(mBlendStateKey, &blendState)); - - const d3d11::DepthStencilState *dsState = nullptr; - const float *zValue = nullptr; - - if (dsv) - { - // Setup DepthStencilStateKey - mDepthStencilStateKey.depthTest = clearParams.clearDepth; - mDepthStencilStateKey.depthMask = clearParams.clearDepth; - mDepthStencilStateKey.stencilWritemask = clearParams.stencilWriteMask; - mDepthStencilStateKey.stencilTest = clearParams.clearStencil; - - // Get DepthStencilState - ANGLE_TRY(mRenderer->getDepthStencilState(mDepthStencilStateKey, &dsState)); - zValue = clearParams.clearDepth ? &clearParams.depthValue : nullptr; - } - - bool dirtyCb = false; - - // Compare the input color/z values against the CB cache and update it if necessary - switch (clearParams.colorType) - { - case GL_FLOAT: - dirtyCb = UpdateDataCache(reinterpret_cast<RtvDsvClearInfo<float> *>(&mShaderData), - clearParams.colorF, zValue, numRtvs, colorMask); - break; - case GL_UNSIGNED_INT: - dirtyCb = UpdateDataCache(reinterpret_cast<RtvDsvClearInfo<uint32_t> *>(&mShaderData), - clearParams.colorUI, zValue, numRtvs, colorMask); - break; - case GL_INT: - dirtyCb = UpdateDataCache(reinterpret_cast<RtvDsvClearInfo<int> *>(&mShaderData), - clearParams.colorI, zValue, numRtvs, colorMask); - break; - default: - UNREACHABLE(); - break; - } - - ANGLE_TRY(ensureConstantBufferCreated()); - - if (dirtyCb) - { - // Update the constant buffer with the updated cache contents - // TODO(Shahmeer): Consider using UpdateSubresource1 D3D11_COPY_DISCARD where possible. - D3D11_MAPPED_SUBRESOURCE mappedResource; - HRESULT result = deviceContext->Map(mConstantBuffer.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, - &mappedResource); - if (FAILED(result)) - { - return gl::OutOfMemory() << "Clear11: Failed to map CB, " << gl::FmtHR(result); - } - - memcpy(mappedResource.pData, &mShaderData, g_ConstantBufferSize); - deviceContext->Unmap(mConstantBuffer.get(), 0); - } - - auto *stateManager = mRenderer->getStateManager(); - - // Set the viewport to be the same size as the framebuffer. - stateManager->setSimpleViewport(framebufferSize); - - // Apply state - stateManager->setSimpleBlendState(blendState); - - const UINT stencilValue = clearParams.stencilValue & 0xFF; - stateManager->setDepthStencilState(dsState, stencilValue); - - if (needScissoredClear) - { - stateManager->setRasterizerState(&mScissorEnabledRasterizerState); - } - else - { - stateManager->setRasterizerState(&mScissorDisabledRasterizerState); - } - - // Get Shaders - const d3d11::VertexShader *vs = nullptr; - const d3d11::GeometryShader *gs = nullptr; - const d3d11::InputLayout *il = nullptr; - const d3d11::PixelShader *ps = nullptr; - const bool hasLayeredLayout = - (fboData.getMultiviewLayout() == GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE); - ANGLE_TRY(mShaderManager.getShadersAndLayout(mRenderer, clearParams.colorType, numRtvs, - hasLayeredLayout, &il, &vs, &gs, &ps)); - - // Apply Shaders - stateManager->setDrawShaders(vs, gs, ps); - stateManager->setPixelConstantBuffer(0, &mConstantBuffer); - - // Bind IL & VB if needed - stateManager->setIndexBuffer(nullptr, DXGI_FORMAT_UNKNOWN, 0); - stateManager->setInputLayout(il); - - if (useVertexBuffer()) - { - ANGLE_TRY(ensureVertexBufferCreated()); - stateManager->setSingleVertexBuffer(&mVertexBuffer, g_VertexSize, 0); - } - else - { - stateManager->setSingleVertexBuffer(nullptr, 0, 0); - } - - stateManager->setPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - - // Apply render targets - stateManager->setRenderTargets(&rtvs[0], numRtvs, dsv); - - // If scissors are necessary to be applied, then the number of clears is the number of scissor - // rects. If no scissors are necessary, then a single full-size clear is enough. - size_t necessaryNumClears = needScissoredClear ? scissorRects.size() : 1u; - for (size_t i = 0u; i < necessaryNumClears; ++i) - { - if (needScissoredClear) - { - ASSERT(i < scissorRects.size()); - stateManager->setScissorRectD3D(scissorRects[i]); - } - // Draw the fullscreen quad. - if (!hasLayeredLayout || isSideBySideFBO) - { - deviceContext->Draw(6, 0); - } - else - { - ASSERT(hasLayeredLayout); - deviceContext->DrawInstanced(6, static_cast<UINT>(fboData.getNumViews()), 0, 0); - } - } - - return gl::NoError(); -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Clear11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Clear11.h deleted file mode 100644 index a09812c42b..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Clear11.h +++ /dev/null @@ -1,100 +0,0 @@ -// -// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Clear11.h: Framebuffer clear utility class. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_CLEAR11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_CLEAR11_H_ - -#include <map> -#include <vector> - -#include "libANGLE/angletypes.h" -#include "libANGLE/Error.h" -#include "libANGLE/Framebuffer.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -namespace rx -{ -class Renderer11; -class RenderTarget11; -struct ClearParameters; - -template <typename T> -struct RtvDsvClearInfo -{ - T r, g, b, a; - float z; - float c1padding[3]; -}; - -class Clear11 : angle::NonCopyable -{ - public: - explicit Clear11(Renderer11 *renderer); - ~Clear11(); - - // Clears the framebuffer with the supplied clear parameters, assumes that the framebuffer is currently applied. - gl::Error clearFramebuffer(const gl::Context *context, - const ClearParameters &clearParams, - const gl::FramebufferState &fboData); - - private: - class ShaderManager final : angle::NonCopyable - { - public: - ShaderManager(); - ~ShaderManager(); - gl::Error getShadersAndLayout(Renderer11 *renderer, - const INT clearType, - const uint32_t numRTs, - const bool hasLayeredLayout, - const d3d11::InputLayout **il, - const d3d11::VertexShader **vs, - const d3d11::GeometryShader **gs, - const d3d11::PixelShader **ps); - - private: - constexpr static size_t kNumShaders = D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; - - d3d11::InputLayout mIl9; - d3d11::LazyShader<ID3D11VertexShader> mVs9; - d3d11::LazyShader<ID3D11PixelShader> mPsFloat9; - d3d11::LazyShader<ID3D11VertexShader> mVs; - d3d11::LazyShader<ID3D11VertexShader> mVsMultiview; - d3d11::LazyShader<ID3D11GeometryShader> mGsMultiview; - d3d11::LazyShader<ID3D11PixelShader> mPsDepth; - std::array<d3d11::LazyShader<ID3D11PixelShader>, kNumShaders> mPsFloat; - std::array<d3d11::LazyShader<ID3D11PixelShader>, kNumShaders> mPsUInt; - std::array<d3d11::LazyShader<ID3D11PixelShader>, kNumShaders> mPsSInt; - }; - - bool useVertexBuffer() const; - gl::Error ensureConstantBufferCreated(); - gl::Error ensureVertexBufferCreated(); - gl::Error ensureResourcesInitialized(); - - Renderer11 *mRenderer; - bool mResourcesInitialized; - - // States - d3d11::RasterizerState mScissorEnabledRasterizerState; - d3d11::RasterizerState mScissorDisabledRasterizerState; - gl::DepthStencilState mDepthStencilStateKey; - d3d11::BlendStateKey mBlendStateKey; - - // Shaders and shader resources - ShaderManager mShaderManager; - d3d11::Buffer mConstantBuffer; - d3d11::Buffer mVertexBuffer; - - // Buffer data and draw parameters - RtvDsvClearInfo<float> mShaderData; -}; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_CLEAR11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Context11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Context11.cpp deleted file mode 100644 index b79dd3603a..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Context11.cpp +++ /dev/null @@ -1,405 +0,0 @@ -// -// Copyright 2016 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// Context11: -// D3D11-specific functionality associated with a GL Context. -// - -#include "libANGLE/renderer/d3d/d3d11/Context11.h" - -#include "common/string_utils.h" -#include "libANGLE/Context.h" -#include "libANGLE/MemoryProgramCache.h" -#include "libANGLE/renderer/d3d/CompilerD3D.h" -#include "libANGLE/renderer/d3d/ProgramD3D.h" -#include "libANGLE/renderer/d3d/RenderbufferD3D.h" -#include "libANGLE/renderer/d3d/SamplerD3D.h" -#include "libANGLE/renderer/d3d/ShaderD3D.h" -#include "libANGLE/renderer/d3d/TextureD3D.h" -#include "libANGLE/renderer/d3d/d3d11/Buffer11.h" -#include "libANGLE/renderer/d3d/d3d11/Fence11.h" -#include "libANGLE/renderer/d3d/d3d11/Framebuffer11.h" -#include "libANGLE/renderer/d3d/d3d11/ProgramPipeline11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/StateManager11.h" -#include "libANGLE/renderer/d3d/d3d11/TransformFeedback11.h" -#include "libANGLE/renderer/d3d/d3d11/VertexArray11.h" - -namespace rx -{ - -Context11::Context11(const gl::ContextState &state, Renderer11 *renderer) - : ContextImpl(state), mRenderer(renderer) -{ -} - -Context11::~Context11() -{ -} - -gl::Error Context11::initialize() -{ - return gl::NoError(); -} - -CompilerImpl *Context11::createCompiler() -{ - if (mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_9_3) - { - return new CompilerD3D(SH_HLSL_4_0_FL9_3_OUTPUT); - } - else - { - return new CompilerD3D(SH_HLSL_4_1_OUTPUT); - } -} - -ShaderImpl *Context11::createShader(const gl::ShaderState &data) -{ - return new ShaderD3D(data, mRenderer->getWorkarounds(), mRenderer->getNativeExtensions()); -} - -ProgramImpl *Context11::createProgram(const gl::ProgramState &data) -{ - return new ProgramD3D(data, mRenderer); -} - -FramebufferImpl *Context11::createFramebuffer(const gl::FramebufferState &data) -{ - return new Framebuffer11(data, mRenderer); -} - -TextureImpl *Context11::createTexture(const gl::TextureState &state) -{ - switch (state.getTarget()) - { - case GL_TEXTURE_2D: - return new TextureD3D_2D(state, mRenderer); - case GL_TEXTURE_CUBE_MAP: - return new TextureD3D_Cube(state, mRenderer); - case GL_TEXTURE_3D: - return new TextureD3D_3D(state, mRenderer); - case GL_TEXTURE_2D_ARRAY: - return new TextureD3D_2DArray(state, mRenderer); - case GL_TEXTURE_EXTERNAL_OES: - return new TextureD3D_External(state, mRenderer); - case GL_TEXTURE_2D_MULTISAMPLE: - return new TextureD3D_2DMultisample(state, mRenderer); - break; - default: - UNREACHABLE(); - } - - return nullptr; -} - -RenderbufferImpl *Context11::createRenderbuffer() -{ - return new RenderbufferD3D(mRenderer); -} - -BufferImpl *Context11::createBuffer(const gl::BufferState &state) -{ - Buffer11 *buffer = new Buffer11(state, mRenderer); - mRenderer->onBufferCreate(buffer); - return buffer; -} - -VertexArrayImpl *Context11::createVertexArray(const gl::VertexArrayState &data) -{ - return new VertexArray11(data); -} - -QueryImpl *Context11::createQuery(GLenum type) -{ - return new Query11(mRenderer, type); -} - -FenceNVImpl *Context11::createFenceNV() -{ - return new FenceNV11(mRenderer); -} - -SyncImpl *Context11::createSync() -{ - return new Sync11(mRenderer); -} - -TransformFeedbackImpl *Context11::createTransformFeedback(const gl::TransformFeedbackState &state) -{ - return new TransformFeedback11(state, mRenderer); -} - -SamplerImpl *Context11::createSampler(const gl::SamplerState &state) -{ - return new SamplerD3D(state); -} - -ProgramPipelineImpl *Context11::createProgramPipeline(const gl::ProgramPipelineState &data) -{ - return new ProgramPipeline11(data); -} - -std::vector<PathImpl *> Context11::createPaths(GLsizei) -{ - return std::vector<PathImpl *>(); -} - -gl::Error Context11::flush(const gl::Context *context) -{ - return mRenderer->flush(); -} - -gl::Error Context11::finish(const gl::Context *context) -{ - return mRenderer->finish(); -} - -gl::Error Context11::drawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count) -{ - ANGLE_TRY(prepareForDrawCall(context, mode)); - return mRenderer->drawArrays(context, mode, first, count, 0); -} - -gl::Error Context11::drawArraysInstanced(const gl::Context *context, - GLenum mode, - GLint first, - GLsizei count, - GLsizei instanceCount) -{ - ANGLE_TRY(prepareForDrawCall(context, mode)); - return mRenderer->drawArrays(context, mode, first, count, instanceCount); -} - -gl::Error Context11::drawElements(const gl::Context *context, - GLenum mode, - GLsizei count, - GLenum type, - const void *indices) -{ - ANGLE_TRY(prepareForDrawCall(context, mode)); - return mRenderer->drawElements(context, mode, count, type, indices, 0); -} - -gl::Error Context11::drawElementsInstanced(const gl::Context *context, - GLenum mode, - GLsizei count, - GLenum type, - const void *indices, - GLsizei instances) -{ - ANGLE_TRY(prepareForDrawCall(context, mode)); - return mRenderer->drawElements(context, mode, count, type, indices, instances); -} - -gl::Error Context11::drawRangeElements(const gl::Context *context, - GLenum mode, - GLuint start, - GLuint end, - GLsizei count, - GLenum type, - const void *indices) -{ - ANGLE_TRY(prepareForDrawCall(context, mode)); - return mRenderer->drawElements(context, mode, count, type, indices, 0); -} - -gl::Error Context11::drawArraysIndirect(const gl::Context *context, - GLenum mode, - const void *indirect) -{ - ANGLE_TRY(prepareForDrawCall(context, mode)); - return mRenderer->drawArraysIndirect(context, mode, indirect); -} - -gl::Error Context11::drawElementsIndirect(const gl::Context *context, - GLenum mode, - GLenum type, - const void *indirect) -{ - ANGLE_TRY(prepareForDrawCall(context, mode)); - return mRenderer->drawElementsIndirect(context, mode, type, indirect); -} - -GLenum Context11::getResetStatus() -{ - return mRenderer->getResetStatus(); -} - -std::string Context11::getVendorString() const -{ - return mRenderer->getVendorString(); -} - -std::string Context11::getRendererDescription() const -{ - return mRenderer->getRendererDescription(); -} - -void Context11::insertEventMarker(GLsizei length, const char *marker) -{ - auto optionalString = angle::WidenString(static_cast<size_t>(length), marker); - if (optionalString.valid()) - { - mRenderer->getAnnotator()->setMarker(optionalString.value().data()); - } -} - -void Context11::pushGroupMarker(GLsizei length, const char *marker) -{ - auto optionalString = angle::WidenString(static_cast<size_t>(length), marker); - if (optionalString.valid()) - { - mRenderer->getAnnotator()->beginEvent(optionalString.value().data()); - } -} - -void Context11::popGroupMarker() -{ - mRenderer->getAnnotator()->endEvent(); -} - -void Context11::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message) -{ - // Fall through to the EXT_debug_marker functions - pushGroupMarker(length, message); -} - -void Context11::popDebugGroup() -{ - // Fall through to the EXT_debug_marker functions - popGroupMarker(); -} - -void Context11::syncState(const gl::Context *context, const gl::State::DirtyBits &dirtyBits) -{ - mRenderer->getStateManager()->syncState(context, dirtyBits); -} - -GLint Context11::getGPUDisjoint() -{ - return mRenderer->getGPUDisjoint(); -} - -GLint64 Context11::getTimestamp() -{ - return mRenderer->getTimestamp(); -} - -void Context11::onMakeCurrent(const gl::Context *context) -{ - ANGLE_SWALLOW_ERR(mRenderer->getStateManager()->onMakeCurrent(context)); -} - -const gl::Caps &Context11::getNativeCaps() const -{ - return mRenderer->getNativeCaps(); -} - -const gl::TextureCapsMap &Context11::getNativeTextureCaps() const -{ - return mRenderer->getNativeTextureCaps(); -} - -const gl::Extensions &Context11::getNativeExtensions() const -{ - return mRenderer->getNativeExtensions(); -} - -const gl::Limitations &Context11::getNativeLimitations() const -{ - return mRenderer->getNativeLimitations(); -} - -gl::Error Context11::dispatchCompute(const gl::Context *context, - GLuint numGroupsX, - GLuint numGroupsY, - GLuint numGroupsZ) -{ - return mRenderer->dispatchCompute(context, numGroupsX, numGroupsY, numGroupsZ); -} - -gl::Error Context11::triggerDrawCallProgramRecompilation(const gl::Context *context, - GLenum drawMode) -{ - const auto &glState = context->getGLState(); - const auto *va11 = GetImplAs<VertexArray11>(glState.getVertexArray()); - const auto *drawFBO = glState.getDrawFramebuffer(); - gl::Program *program = glState.getProgram(); - ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program); - - programD3D->updateCachedInputLayout(va11->getCurrentStateSerial(), glState); - programD3D->updateCachedOutputLayout(context, drawFBO); - - bool recompileVS = !programD3D->hasVertexExecutableForCachedInputLayout(); - bool recompileGS = !programD3D->hasGeometryExecutableForPrimitiveType(drawMode); - bool recompilePS = !programD3D->hasPixelExecutableForCachedOutputLayout(); - - if (!recompileVS && !recompileGS && !recompilePS) - { - return gl::NoError(); - } - - // Load the compiler if necessary and recompile the programs. - ANGLE_TRY(mRenderer->ensureHLSLCompilerInitialized()); - - gl::InfoLog infoLog; - - if (recompileVS) - { - ShaderExecutableD3D *vertexExe = nullptr; - ANGLE_TRY(programD3D->getVertexExecutableForCachedInputLayout(&vertexExe, &infoLog)); - if (!programD3D->hasVertexExecutableForCachedInputLayout()) - { - ASSERT(infoLog.getLength() > 0); - ERR() << "Dynamic recompilation error log: " << infoLog.str(); - return gl::InternalError() - << "Error compiling dynamic vertex executable:" << infoLog.str(); - } - } - - if (recompileGS) - { - ShaderExecutableD3D *geometryExe = nullptr; - ANGLE_TRY(programD3D->getGeometryExecutableForPrimitiveType(context, drawMode, &geometryExe, - &infoLog)); - if (!programD3D->hasGeometryExecutableForPrimitiveType(drawMode)) - { - ASSERT(infoLog.getLength() > 0); - ERR() << "Dynamic recompilation error log: " << infoLog.str(); - return gl::InternalError() - << "Error compiling dynamic geometry executable:" << infoLog.str(); - } - } - - if (recompilePS) - { - ShaderExecutableD3D *pixelExe = nullptr; - ANGLE_TRY(programD3D->getPixelExecutableForCachedOutputLayout(&pixelExe, &infoLog)); - if (!programD3D->hasPixelExecutableForCachedOutputLayout()) - { - ASSERT(infoLog.getLength() > 0); - ERR() << "Dynamic recompilation error log: " << infoLog.str(); - return gl::InternalError() - << "Error compiling dynamic pixel executable:" << infoLog.str(); - } - } - - // Refresh the program cache entry. - if (mMemoryProgramCache) - { - mMemoryProgramCache->updateProgram(context, program); - } - - return gl::NoError(); -} - -gl::Error Context11::prepareForDrawCall(const gl::Context *context, GLenum drawMode) -{ - ANGLE_TRY(mRenderer->getStateManager()->updateState(context, drawMode)); - return gl::NoError(); -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Context11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Context11.h deleted file mode 100644 index dd99111b19..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Context11.h +++ /dev/null @@ -1,155 +0,0 @@ -// -// Copyright 2016 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// Context11: -// D3D11-specific functionality associated with a GL Context. -// - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_CONTEXT11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_CONTEXT11_H_ - -#include "libANGLE/renderer/ContextImpl.h" - -namespace rx -{ -class Renderer11; - -class Context11 : public ContextImpl -{ - public: - Context11(const gl::ContextState &state, Renderer11 *renderer); - ~Context11() override; - - gl::Error initialize() override; - - // Shader creation - CompilerImpl *createCompiler() override; - ShaderImpl *createShader(const gl::ShaderState &data) override; - ProgramImpl *createProgram(const gl::ProgramState &data) override; - - // Framebuffer creation - FramebufferImpl *createFramebuffer(const gl::FramebufferState &data) override; - - // Texture creation - TextureImpl *createTexture(const gl::TextureState &state) override; - - // Renderbuffer creation - RenderbufferImpl *createRenderbuffer() override; - - // Buffer creation - BufferImpl *createBuffer(const gl::BufferState &state) override; - - // Vertex Array creation - VertexArrayImpl *createVertexArray(const gl::VertexArrayState &data) override; - - // Query and Fence creation - QueryImpl *createQuery(GLenum type) override; - FenceNVImpl *createFenceNV() override; - SyncImpl *createSync() override; - - // Transform Feedback creation - TransformFeedbackImpl *createTransformFeedback( - const gl::TransformFeedbackState &state) override; - - // Sampler object creation - SamplerImpl *createSampler(const gl::SamplerState &state) override; - - // Program Pipeline object creation - ProgramPipelineImpl *createProgramPipeline(const gl::ProgramPipelineState &data) override; - - // Path object creation. - std::vector<PathImpl *> createPaths(GLsizei) override; - - // Flush and finish. - gl::Error flush(const gl::Context *context) override; - gl::Error finish(const gl::Context *context) override; - - // Drawing methods. - gl::Error drawArrays(const gl::Context *context, - GLenum mode, - GLint first, - GLsizei count) override; - gl::Error drawArraysInstanced(const gl::Context *context, - GLenum mode, - GLint first, - GLsizei count, - GLsizei instanceCount) override; - - gl::Error drawElements(const gl::Context *context, - GLenum mode, - GLsizei count, - GLenum type, - const void *indices) override; - gl::Error drawElementsInstanced(const gl::Context *context, - GLenum mode, - GLsizei count, - GLenum type, - const void *indices, - GLsizei instances) override; - gl::Error drawRangeElements(const gl::Context *context, - GLenum mode, - GLuint start, - GLuint end, - GLsizei count, - GLenum type, - const void *indices) override; - gl::Error drawArraysIndirect(const gl::Context *context, - GLenum mode, - const void *indirect) override; - gl::Error drawElementsIndirect(const gl::Context *context, - GLenum mode, - GLenum type, - const void *indirect) override; - - // Device loss - GLenum getResetStatus() override; - - // Vendor and description strings. - std::string getVendorString() const override; - std::string getRendererDescription() const override; - - // EXT_debug_marker - void insertEventMarker(GLsizei length, const char *marker) override; - void pushGroupMarker(GLsizei length, const char *marker) override; - void popGroupMarker() override; - - // KHR_debug - void pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message) override; - void popDebugGroup() override; - - // State sync with dirty bits. - void syncState(const gl::Context *context, const gl::State::DirtyBits &dirtyBits) override; - - // Disjoint timer queries - GLint getGPUDisjoint() override; - GLint64 getTimestamp() override; - - // Context switching - void onMakeCurrent(const gl::Context *context) override; - - // Caps queries - const gl::Caps &getNativeCaps() const override; - const gl::TextureCapsMap &getNativeTextureCaps() const override; - const gl::Extensions &getNativeExtensions() const override; - const gl::Limitations &getNativeLimitations() const override; - - Renderer11 *getRenderer() const { return mRenderer; } - - gl::Error dispatchCompute(const gl::Context *context, - GLuint numGroupsX, - GLuint numGroupsY, - GLuint numGroupsZ) override; - - gl::Error triggerDrawCallProgramRecompilation(const gl::Context *context, GLenum drawMode); - - private: - gl::Error prepareForDrawCall(const gl::Context *context, GLenum drawMode); - - Renderer11 *mRenderer; -}; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_CONTEXT11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/DebugAnnotator11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/DebugAnnotator11.cpp deleted file mode 100644 index 1e70363e11..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/DebugAnnotator11.cpp +++ /dev/null @@ -1,119 +0,0 @@ -// -// Copyright 2015 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// DebugAnnotator11.cpp: D3D11 helpers for adding trace annotations. -// - -#include "libANGLE/renderer/d3d/d3d11/DebugAnnotator11.h" - -#include "common/debug.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -namespace rx -{ - -DebugAnnotator11::DebugAnnotator11() - : mInitialized(false), - mD3d11Module(nullptr), - mUserDefinedAnnotation(nullptr) -{ - // D3D11 devices can't be created during DllMain. - // We defer device creation until the object is actually used. -} - -DebugAnnotator11::~DebugAnnotator11() -{ - if (mInitialized) - { - SafeRelease(mUserDefinedAnnotation); - -#if !defined(ANGLE_ENABLE_WINDOWS_STORE) - FreeLibrary(mD3d11Module); -#endif // !ANGLE_ENABLE_WINDOWS_STORE - } -} - -void DebugAnnotator11::beginEvent(const wchar_t *eventName) -{ - initializeDevice(); - - if (mUserDefinedAnnotation != nullptr) - { - mUserDefinedAnnotation->BeginEvent(eventName); - } -} - -void DebugAnnotator11::endEvent() -{ - initializeDevice(); - - if (mUserDefinedAnnotation != nullptr) - { - mUserDefinedAnnotation->EndEvent(); - } -} - -void DebugAnnotator11::setMarker(const wchar_t *markerName) -{ - initializeDevice(); - - if (mUserDefinedAnnotation != nullptr) - { - mUserDefinedAnnotation->SetMarker(markerName); - } -} - -bool DebugAnnotator11::getStatus() -{ -#if defined(ANGLE_ENABLE_WINDOWS_STORE) - static_assert(NTDDI_VERSION >= NTDDI_WIN10, "GetStatus only works on Win10 and above"); - initializeDevice(); - - if (mUserDefinedAnnotation != nullptr) - { - return !!(mUserDefinedAnnotation->GetStatus()); - } - - return true; // Default if initializeDevice() failed -#else - // We can't detect GetStatus() on desktop ANGLE builds so always return true. - return true; -#endif // ANGLE_ENABLE_WINDOWS_STORE -} - -void DebugAnnotator11::initializeDevice() -{ - if (!mInitialized) - { -#if !defined(ANGLE_ENABLE_WINDOWS_STORE) - mD3d11Module = LoadLibrary(TEXT("d3d11.dll")); - ASSERT(mD3d11Module); - - PFN_D3D11_CREATE_DEVICE D3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(mD3d11Module, "D3D11CreateDevice"); - ASSERT(D3D11CreateDevice != nullptr); -#endif // !ANGLE_ENABLE_WINDOWS_STORE - - ID3D11Device *device = nullptr; - ID3D11DeviceContext *context = nullptr; - - HRESULT hr = E_FAIL; - - // Create a D3D_DRIVER_TYPE_NULL device, which is much cheaper than other types of device. - hr = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_NULL, nullptr, 0, nullptr, 0, - D3D11_SDK_VERSION, &device, nullptr, &context); - ASSERT(SUCCEEDED(hr)); - if (SUCCEEDED(hr)) - { - mUserDefinedAnnotation = d3d11::DynamicCastComObject<ID3DUserDefinedAnnotation>(context); - ASSERT(mUserDefinedAnnotation != nullptr); - mInitialized = true; - } - - SafeRelease(device); - SafeRelease(context); - } -} - -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/DebugAnnotator11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/DebugAnnotator11.h deleted file mode 100644 index 62662c49ae..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/DebugAnnotator11.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// Copyright 2015 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// DebugAnnotator11.h: D3D11 helpers for adding trace annotations. -// - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_DEBUGANNOTATOR11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_DEBUGANNOTATOR11_H_ - -#include "libANGLE/LoggingAnnotator.h" - -namespace rx -{ - -class DebugAnnotator11 : public angle::LoggingAnnotator -{ - public: - DebugAnnotator11(); - ~DebugAnnotator11() override; - void beginEvent(const wchar_t *eventName) override; - void endEvent() override; - void setMarker(const wchar_t *markerName) override; - bool getStatus() override; - - private: - void initializeDevice(); - - bool mInitialized; - HMODULE mD3d11Module; - ID3DUserDefinedAnnotation *mUserDefinedAnnotation; -}; - -} - -#endif // LIBANGLE_RENDERER_D3D_D3D11_DEBUGANNOTATOR11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Fence11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Fence11.cpp deleted file mode 100644 index 082f28d794..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Fence11.cpp +++ /dev/null @@ -1,240 +0,0 @@ -// -// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Fence11.cpp: Defines the rx::FenceNV11 and rx::Sync11 classes which implement -// rx::FenceNVImpl and rx::SyncImpl. - -#include "libANGLE/renderer/d3d/d3d11/Fence11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" - -#include "common/utilities.h" - -namespace rx -{ - -static const int kDeviceLostCheckPeriod = 64; - -// -// Template helpers for set and test operations. -// - -template <class FenceClass> -gl::Error FenceSetHelper(FenceClass *fence) -{ - if (!fence->mQuery) - { - D3D11_QUERY_DESC queryDesc; - queryDesc.Query = D3D11_QUERY_EVENT; - queryDesc.MiscFlags = 0; - - HRESULT result = fence->mRenderer->getDevice()->CreateQuery(&queryDesc, &fence->mQuery); - if (FAILED(result)) - { - return gl::OutOfMemory() << "Failed to create event query, " << gl::FmtHR(result); - } - } - - fence->mRenderer->getDeviceContext()->End(fence->mQuery); - return gl::NoError(); -} - -template <class FenceClass> -gl::Error FenceTestHelper(FenceClass *fence, bool flushCommandBuffer, GLboolean *outFinished) -{ - ASSERT(fence->mQuery); - - UINT getDataFlags = (flushCommandBuffer ? 0 : D3D11_ASYNC_GETDATA_DONOTFLUSH); - HRESULT result = - fence->mRenderer->getDeviceContext()->GetData(fence->mQuery, nullptr, 0, getDataFlags); - - if (FAILED(result)) - { - return gl::OutOfMemory() << "Failed to get query data, " << gl::FmtHR(result); - } - - ASSERT(result == S_OK || result == S_FALSE); - *outFinished = ((result == S_OK) ? GL_TRUE : GL_FALSE); - return gl::NoError(); -} - -// -// FenceNV11 -// - -FenceNV11::FenceNV11(Renderer11 *renderer) : FenceNVImpl(), mRenderer(renderer), mQuery(nullptr) -{ -} - -FenceNV11::~FenceNV11() -{ - SafeRelease(mQuery); -} - -gl::Error FenceNV11::set(GLenum condition) -{ - return FenceSetHelper(this); -} - -gl::Error FenceNV11::test(GLboolean *outFinished) -{ - return FenceTestHelper(this, true, outFinished); -} - -gl::Error FenceNV11::finish() -{ - GLboolean finished = GL_FALSE; - - int loopCount = 0; - while (finished != GL_TRUE) - { - loopCount++; - ANGLE_TRY(FenceTestHelper(this, true, &finished)); - - if (loopCount % kDeviceLostCheckPeriod == 0 && mRenderer->testDeviceLost()) - { - return gl::OutOfMemory() << "Device was lost while querying result of an event query."; - } - - ScheduleYield(); - } - - return gl::NoError(); -} - -// -// Sync11 -// - -// Important note on accurate timers in Windows: -// -// QueryPerformanceCounter has a few major issues, including being 10x as expensive to call -// as timeGetTime on laptops and "jumping" during certain hardware events. -// -// See the comments at the top of the Chromium source file "chromium/src/base/time/time_win.cc" -// https://code.google.com/p/chromium/codesearch#chromium/src/base/time/time_win.cc -// -// We still opt to use QPC. In the present and moving forward, most newer systems will not suffer -// from buggy implementations. - -Sync11::Sync11(Renderer11 *renderer) : SyncImpl(), mRenderer(renderer), mQuery(nullptr) -{ - LARGE_INTEGER counterFreqency = {}; - BOOL success = QueryPerformanceFrequency(&counterFreqency); - ASSERT(success); - - mCounterFrequency = counterFreqency.QuadPart; -} - -Sync11::~Sync11() -{ - SafeRelease(mQuery); -} - -gl::Error Sync11::set(GLenum condition, GLbitfield flags) -{ - ASSERT(condition == GL_SYNC_GPU_COMMANDS_COMPLETE && flags == 0); - return FenceSetHelper(this); -} - -gl::Error Sync11::clientWait(GLbitfield flags, GLuint64 timeout, GLenum *outResult) -{ - ASSERT(outResult); - - bool flushCommandBuffer = ((flags & GL_SYNC_FLUSH_COMMANDS_BIT) != 0); - - GLboolean result = GL_FALSE; - gl::Error error = FenceTestHelper(this, flushCommandBuffer, &result); - if (error.isError()) - { - *outResult = GL_WAIT_FAILED; - return error; - } - - if (result == GL_TRUE) - { - *outResult = GL_ALREADY_SIGNALED; - return gl::NoError(); - } - - if (timeout == 0) - { - *outResult = GL_TIMEOUT_EXPIRED; - return gl::NoError(); - } - - LARGE_INTEGER currentCounter = {}; - BOOL success = QueryPerformanceCounter(¤tCounter); - ASSERT(success); - - LONGLONG timeoutInSeconds = static_cast<LONGLONG>(timeout / 1000000000ull); - LONGLONG endCounter = currentCounter.QuadPart + mCounterFrequency * timeoutInSeconds; - - // Extremely unlikely, but if mCounterFrequency is large enough, endCounter can wrap - if (endCounter < currentCounter.QuadPart) - { - endCounter = MAXLONGLONG; - } - - int loopCount = 0; - while (currentCounter.QuadPart < endCounter && !result) - { - loopCount++; - ScheduleYield(); - success = QueryPerformanceCounter(¤tCounter); - ASSERT(success); - - error = FenceTestHelper(this, flushCommandBuffer, &result); - if (error.isError()) - { - *outResult = GL_WAIT_FAILED; - return error; - } - - if ((loopCount % kDeviceLostCheckPeriod) == 0 && mRenderer->testDeviceLost()) - { - *outResult = GL_WAIT_FAILED; - return gl::OutOfMemory() << "Device was lost while querying result of an event query."; - } - } - - if (currentCounter.QuadPart >= endCounter) - { - *outResult = GL_TIMEOUT_EXPIRED; - } - else - { - *outResult = GL_CONDITION_SATISFIED; - } - - return gl::NoError(); -} - -gl::Error Sync11::serverWait(GLbitfield flags, GLuint64 timeout) -{ - // Because our API is currently designed to be called from a single thread, we don't need to do - // extra work for a server-side fence. GPU commands issued after the fence is created will - // always be processed after the fence is signaled. - return gl::NoError(); -} - -gl::Error Sync11::getStatus(GLint *outResult) -{ - GLboolean result = GL_FALSE; - gl::Error error = FenceTestHelper(this, false, &result); - if (error.isError()) - { - // The spec does not specify any way to report errors during the status test (e.g. device - // lost) so we report the fence is unblocked in case of error or signaled. - *outResult = GL_SIGNALED; - - return error; - } - - *outResult = (result ? GL_SIGNALED : GL_UNSIGNALED); - return gl::NoError(); -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Fence11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Fence11.h deleted file mode 100644 index 4168df5365..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Fence11.h +++ /dev/null @@ -1,60 +0,0 @@ -// -// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Fence11.h: Defines the rx::FenceNV11 and rx::Sync11 classes which implement rx::FenceNVImpl -// and rx::SyncImpl. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_FENCE11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_FENCE11_H_ - -#include "libANGLE/renderer/FenceNVImpl.h" -#include "libANGLE/renderer/SyncImpl.h" - -namespace rx -{ -class Renderer11; - -class FenceNV11 : public FenceNVImpl -{ - public: - explicit FenceNV11(Renderer11 *renderer); - ~FenceNV11() override; - - gl::Error set(GLenum condition) override; - gl::Error test(GLboolean *outFinished) override; - gl::Error finish() override; - - private: - template<class T> friend gl::Error FenceSetHelper(T *fence); - template<class T> friend gl::Error FenceTestHelper(T *fence, bool flushCommandBuffer, GLboolean *outFinished); - - Renderer11 *mRenderer; - ID3D11Query *mQuery; -}; - -class Sync11 : public SyncImpl -{ - public: - explicit Sync11(Renderer11 *renderer); - ~Sync11() override; - - gl::Error set(GLenum condition, GLbitfield flags) override; - gl::Error clientWait(GLbitfield flags, GLuint64 timeout, GLenum *outResult) override; - gl::Error serverWait(GLbitfield flags, GLuint64 timeout) override; - gl::Error getStatus(GLint *outResult) override; - - private: - template<class T> friend gl::Error FenceSetHelper(T *fence); - template<class T> friend gl::Error FenceTestHelper(T *fence, bool flushCommandBuffer, GLboolean *outFinished); - - Renderer11 *mRenderer; - ID3D11Query *mQuery; - LONGLONG mCounterFrequency; -}; - -} - -#endif // LIBANGLE_RENDERER_D3D_D3D11_FENCE11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Framebuffer11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Framebuffer11.cpp deleted file mode 100644 index 02326d7b50..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Framebuffer11.cpp +++ /dev/null @@ -1,507 +0,0 @@ -// -// Copyright 2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Framebuffer11.cpp: Implements the Framebuffer11 class. - -#include "libANGLE/renderer/d3d/d3d11/Framebuffer11.h" - -#include "common/bitset_utils.h" -#include "common/debug.h" -#include "libANGLE/Context.h" -#include "libANGLE/Framebuffer.h" -#include "libANGLE/FramebufferAttachment.h" -#include "libANGLE/Texture.h" -#include "libANGLE/renderer/d3d/TextureD3D.h" -#include "libANGLE/renderer/d3d/d3d11/Buffer11.h" -#include "libANGLE/renderer/d3d/d3d11/Clear11.h" -#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/TextureStorage11.h" -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -using namespace angle; - -namespace rx -{ - -namespace -{ -gl::Error MarkAttachmentsDirty(const gl::Context *context, - const gl::FramebufferAttachment *attachment) -{ - if (attachment->type() == GL_TEXTURE) - { - gl::Texture *texture = attachment->getTexture(); - - TextureD3D *textureD3D = GetImplAs<TextureD3D>(texture); - - TextureStorage *texStorage = nullptr; - ANGLE_TRY(textureD3D->getNativeTexture(context, &texStorage)); - - if (texStorage) - { - TextureStorage11 *texStorage11 = GetAs<TextureStorage11>(texStorage); - ASSERT(texStorage11); - - texStorage11->markLevelDirty(attachment->mipLevel()); - } - } - - return gl::NoError(); -} - -void UpdateCachedRenderTarget(const gl::Context *context, - const gl::FramebufferAttachment *attachment, - RenderTarget11 *&cachedRenderTarget, - OnRenderTargetDirtyBinding *channelBinding) -{ - RenderTarget11 *newRenderTarget = nullptr; - if (attachment) - { - // TODO(jmadill): Don't swallow this error. - gl::Error error = attachment->getRenderTarget(context, &newRenderTarget); - if (error.isError()) - { - ERR() << "Internal rendertarget error: " << error; - } - } - if (newRenderTarget != cachedRenderTarget) - { - OnRenderTargetDirtyChannel *channel = - (newRenderTarget ? newRenderTarget->getBroadcastChannel() : nullptr); - channelBinding->bind(channel); - cachedRenderTarget = newRenderTarget; - } -} -} // anonymous namespace - -Framebuffer11::Framebuffer11(const gl::FramebufferState &data, Renderer11 *renderer) - : FramebufferD3D(data, renderer), - mRenderer(renderer), - mCachedDepthStencilRenderTarget(nullptr), - mDepthStencilRenderTargetDirty(this, gl::IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS) -{ - ASSERT(mRenderer != nullptr); - mCachedColorRenderTargets.fill(nullptr); - for (size_t colorIndex = 0; colorIndex < data.getColorAttachments().size(); ++colorIndex) - { - mColorRenderTargetsDirty.emplace_back(this, colorIndex); - } -} - -Framebuffer11::~Framebuffer11() -{ -} - -gl::Error Framebuffer11::markAttachmentsDirty(const gl::Context *context) const -{ - const auto &colorAttachments = mState.getColorAttachments(); - for (size_t drawBuffer : mState.getEnabledDrawBuffers()) - { - const gl::FramebufferAttachment &colorAttachment = colorAttachments[drawBuffer]; - ASSERT(colorAttachment.isAttached()); - ANGLE_TRY(MarkAttachmentsDirty(context, &colorAttachment)); - } - - const gl::FramebufferAttachment *dsAttachment = mState.getDepthOrStencilAttachment(); - if (dsAttachment) - { - ANGLE_TRY(MarkAttachmentsDirty(context, dsAttachment)); - } - - return gl::NoError(); -} - -gl::Error Framebuffer11::clearImpl(const gl::Context *context, const ClearParameters &clearParams) -{ - Clear11 *clearer = mRenderer->getClearer(); - - const gl::FramebufferAttachment *colorAttachment = mState.getFirstColorAttachment(); - if (clearParams.scissorEnabled == true && colorAttachment != nullptr && - UsePresentPathFast(mRenderer, colorAttachment)) - { - // If the current framebuffer is using the default colorbuffer, and present path fast is - // active, and the scissor rect is enabled, then we should invert the scissor rect - // vertically - ClearParameters presentPathFastClearParams = clearParams; - gl::Extents framebufferSize = colorAttachment->getSize(); - presentPathFastClearParams.scissor.y = framebufferSize.height - - presentPathFastClearParams.scissor.y - - presentPathFastClearParams.scissor.height; - ANGLE_TRY(clearer->clearFramebuffer(context, presentPathFastClearParams, mState)); - } - else - { - ANGLE_TRY(clearer->clearFramebuffer(context, clearParams, mState)); - } - - ANGLE_TRY(markAttachmentsDirty(context)); - - return gl::NoError(); -} - -gl::Error Framebuffer11::invalidate(const gl::Context *context, - size_t count, - const GLenum *attachments) -{ - return invalidateBase(context, count, attachments, false); -} - -gl::Error Framebuffer11::discard(const gl::Context *context, - size_t count, - const GLenum *attachments) -{ - return invalidateBase(context, count, attachments, true); -} - -gl::Error Framebuffer11::invalidateBase(const gl::Context *context, - size_t count, - const GLenum *attachments, - bool useEXTBehavior) const -{ - ID3D11DeviceContext1 *deviceContext1 = mRenderer->getDeviceContext1IfSupported(); - - if (!deviceContext1) - { - // DiscardView() is only supported on ID3D11DeviceContext1 - return gl::NoError(); - } - - bool foundDepth = false; - bool foundStencil = false; - - for (size_t i = 0; i < count; ++i) - { - switch (attachments[i]) - { - // Handle depth and stencil attachments. Defer discarding until later. - case GL_DEPTH_STENCIL_ATTACHMENT: - foundDepth = true; - foundStencil = true; - break; - case GL_DEPTH_EXT: - case GL_DEPTH_ATTACHMENT: - foundDepth = true; - break; - case GL_STENCIL_EXT: - case GL_STENCIL_ATTACHMENT: - foundStencil = true; - break; - default: - { - // Handle color attachments - ASSERT((attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15) || - (attachments[i] == GL_COLOR)); - - size_t colorIndex = - (attachments[i] == GL_COLOR ? 0u : (attachments[i] - GL_COLOR_ATTACHMENT0)); - const gl::FramebufferAttachment *colorAttachment = - mState.getColorAttachment(colorIndex); - if (colorAttachment) - { - ANGLE_TRY(invalidateAttachment(context, colorAttachment)); - } - break; - } - } - } - - bool discardDepth = false; - bool discardStencil = false; - - // The D3D11 renderer uses the same view for depth and stencil buffers, so we must be careful. - if (useEXTBehavior) - { - // In the extension, if the app discards only one of the depth and stencil attachments, but - // those are backed by the same packed_depth_stencil buffer, then both images become undefined. - discardDepth = foundDepth; - - // Don't bother discarding the stencil buffer if the depth buffer will already do it - discardStencil = foundStencil && (!discardDepth || mState.getDepthAttachment() == nullptr); - } - else - { - // In ES 3.0.4, if a specified attachment has base internal format DEPTH_STENCIL but the - // attachments list does not include DEPTH_STENCIL_ATTACHMENT or both DEPTH_ATTACHMENT and - // STENCIL_ATTACHMENT, then only the specified portion of every pixel in the subregion of pixels - // of the DEPTH_STENCIL buffer may be invalidated, and the other portion must be preserved. - discardDepth = (foundDepth && foundStencil) || - (foundDepth && (mState.getStencilAttachment() == nullptr)); - discardStencil = (foundStencil && (mState.getDepthAttachment() == nullptr)); - } - - if (discardDepth && mState.getDepthAttachment()) - { - ANGLE_TRY(invalidateAttachment(context, mState.getDepthAttachment())); - } - - if (discardStencil && mState.getStencilAttachment()) - { - ANGLE_TRY(invalidateAttachment(context, mState.getStencilAttachment())); - } - - return gl::NoError(); -} - -gl::Error Framebuffer11::invalidateSub(const gl::Context *context, - size_t, - const GLenum *, - const gl::Rectangle &) -{ - // A no-op implementation conforms to the spec, so don't call UNIMPLEMENTED() - return gl::NoError(); -} - -gl::Error Framebuffer11::invalidateAttachment(const gl::Context *context, - const gl::FramebufferAttachment *attachment) const -{ - ID3D11DeviceContext1 *deviceContext1 = mRenderer->getDeviceContext1IfSupported(); - ASSERT(deviceContext1); - ASSERT(attachment && attachment->isAttached()); - - RenderTarget11 *renderTarget = nullptr; - ANGLE_TRY(attachment->getRenderTarget(context, &renderTarget)); - const auto &rtv = renderTarget->getRenderTargetView(); - - if (rtv.valid()) - { - deviceContext1->DiscardView(rtv.get()); - } - - return gl::NoError(); -} - -gl::Error Framebuffer11::readPixelsImpl(const gl::Context *context, - const gl::Rectangle &area, - GLenum format, - GLenum type, - size_t outputPitch, - const gl::PixelPackState &pack, - uint8_t *pixels) -{ - const gl::FramebufferAttachment *readAttachment = mState.getReadAttachment(); - ASSERT(readAttachment); - - gl::Buffer *packBuffer = context->getGLState().getTargetBuffer(gl::BufferBinding::PixelPack); - if (packBuffer != nullptr) - { - Buffer11 *packBufferStorage = GetImplAs<Buffer11>(packBuffer); - PackPixelsParams packParams(area, format, type, static_cast<GLuint>(outputPitch), pack, - packBuffer, reinterpret_cast<ptrdiff_t>(pixels)); - - return packBufferStorage->packPixels(context, *readAttachment, packParams); - } - - return mRenderer->readFromAttachment(context, *readAttachment, area, format, type, - static_cast<GLuint>(outputPitch), pack, pixels); -} - -gl::Error Framebuffer11::blitImpl(const gl::Context *context, - const gl::Rectangle &sourceArea, - const gl::Rectangle &destArea, - const gl::Rectangle *scissor, - bool blitRenderTarget, - bool blitDepth, - bool blitStencil, - GLenum filter, - const gl::Framebuffer *sourceFramebuffer) -{ - if (blitRenderTarget) - { - const gl::FramebufferAttachment *readBuffer = sourceFramebuffer->getReadColorbuffer(); - ASSERT(readBuffer); - - RenderTargetD3D *readRenderTarget = nullptr; - ANGLE_TRY(readBuffer->getRenderTarget(context, &readRenderTarget)); - ASSERT(readRenderTarget); - - const auto &colorAttachments = mState.getColorAttachments(); - const auto &drawBufferStates = mState.getDrawBufferStates(); - - for (size_t colorAttachment = 0; colorAttachment < colorAttachments.size(); colorAttachment++) - { - const gl::FramebufferAttachment &drawBuffer = colorAttachments[colorAttachment]; - - if (drawBuffer.isAttached() && - drawBufferStates[colorAttachment] != GL_NONE) - { - RenderTargetD3D *drawRenderTarget = nullptr; - ANGLE_TRY(drawBuffer.getRenderTarget(context, &drawRenderTarget)); - ASSERT(drawRenderTarget); - - const bool invertColorSource = UsePresentPathFast(mRenderer, readBuffer); - gl::Rectangle actualSourceArea = sourceArea; - if (invertColorSource) - { - RenderTarget11 *readRenderTarget11 = GetAs<RenderTarget11>(readRenderTarget); - actualSourceArea.y = readRenderTarget11->getHeight() - sourceArea.y; - actualSourceArea.height = -sourceArea.height; - } - - const bool invertColorDest = UsePresentPathFast(mRenderer, &drawBuffer); - gl::Rectangle actualDestArea = destArea; - if (invertColorDest) - { - RenderTarget11 *drawRenderTarget11 = GetAs<RenderTarget11>(drawRenderTarget); - actualDestArea.y = drawRenderTarget11->getHeight() - destArea.y; - actualDestArea.height = -destArea.height; - } - - ANGLE_TRY(mRenderer->blitRenderbufferRect( - context, actualSourceArea, actualDestArea, readRenderTarget, drawRenderTarget, - filter, scissor, blitRenderTarget, false, false)); - } - } - } - - if (blitDepth || blitStencil) - { - const gl::FramebufferAttachment *readBuffer = sourceFramebuffer->getDepthOrStencilbuffer(); - ASSERT(readBuffer); - - RenderTargetD3D *readRenderTarget = nullptr; - ANGLE_TRY(readBuffer->getRenderTarget(context, &readRenderTarget)); - ASSERT(readRenderTarget); - - const gl::FramebufferAttachment *drawBuffer = mState.getDepthOrStencilAttachment(); - ASSERT(drawBuffer); - - RenderTargetD3D *drawRenderTarget = nullptr; - ANGLE_TRY(drawBuffer->getRenderTarget(context, &drawRenderTarget)); - ASSERT(drawRenderTarget); - - ANGLE_TRY(mRenderer->blitRenderbufferRect(context, sourceArea, destArea, readRenderTarget, - drawRenderTarget, filter, scissor, false, - blitDepth, blitStencil)); - } - - ANGLE_TRY(markAttachmentsDirty(context)); - return gl::NoError(); -} - -GLenum Framebuffer11::getRenderTargetImplementationFormat(RenderTargetD3D *renderTarget) const -{ - RenderTarget11 *renderTarget11 = GetAs<RenderTarget11>(renderTarget); - return renderTarget11->getFormatSet().format().fboImplementationInternalFormat; -} - -void Framebuffer11::updateColorRenderTarget(const gl::Context *context, size_t colorIndex) -{ - UpdateCachedRenderTarget(context, mState.getColorAttachment(colorIndex), - mCachedColorRenderTargets[colorIndex], - &mColorRenderTargetsDirty[colorIndex]); -} - -void Framebuffer11::updateDepthStencilRenderTarget(const gl::Context *context) -{ - UpdateCachedRenderTarget(context, mState.getDepthOrStencilAttachment(), - mCachedDepthStencilRenderTarget, &mDepthStencilRenderTargetDirty); -} - -void Framebuffer11::syncState(const gl::Context *context, - const gl::Framebuffer::DirtyBits &dirtyBits) -{ - const auto &mergedDirtyBits = dirtyBits | mInternalDirtyBits; - mInternalDirtyBits.reset(); - - for (auto dirtyBit : mergedDirtyBits) - { - switch (dirtyBit) - { - case gl::Framebuffer::DIRTY_BIT_DEPTH_ATTACHMENT: - case gl::Framebuffer::DIRTY_BIT_STENCIL_ATTACHMENT: - updateDepthStencilRenderTarget(context); - break; - case gl::Framebuffer::DIRTY_BIT_DRAW_BUFFERS: - case gl::Framebuffer::DIRTY_BIT_READ_BUFFER: - break; - case gl::Framebuffer::DIRTY_BIT_DEFAULT_WIDTH: - case gl::Framebuffer::DIRTY_BIT_DEFAULT_HEIGHT: - case gl::Framebuffer::DIRTY_BIT_DEFAULT_SAMPLES: - case gl::Framebuffer::DIRTY_BIT_DEFAULT_FIXED_SAMPLE_LOCATIONS: - break; - default: - { - ASSERT(gl::Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0 == 0 && - dirtyBit < gl::Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_MAX); - size_t colorIndex = - static_cast<size_t>(dirtyBit - gl::Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0); - updateColorRenderTarget(context, colorIndex); - break; - } - } - } - - // We should not have dirtied any additional state during our sync. - ASSERT(!mInternalDirtyBits.any()); - - FramebufferD3D::syncState(context, dirtyBits); - - // Call this last to allow the state manager to take advantage of the cached render targets. - mRenderer->getStateManager()->invalidateRenderTarget(); - - // Call this to syncViewport for framebuffer default parameters. - if (mState.getDefaultWidth() != 0 || mState.getDefaultHeight() != 0) - { - mRenderer->getStateManager()->invalidateViewport(context); - } -} - -void Framebuffer11::signal(size_t channelID, const gl::Context *context) -{ - if (channelID == gl::IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS) - { - // Stencil is redundant in this case. - mInternalDirtyBits.set(gl::Framebuffer::DIRTY_BIT_DEPTH_ATTACHMENT); - mCachedDepthStencilRenderTarget = nullptr; - } - else - { - mInternalDirtyBits.set(gl::Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0 + channelID); - mCachedColorRenderTargets[channelID] = nullptr; - } - - // Notify the context we need to re-validate the RenderTarget. - // TODO(jmadill): Check that we're the active draw framebuffer. - mRenderer->getStateManager()->invalidateRenderTarget(); -} - -gl::Error Framebuffer11::getSamplePosition(size_t index, GLfloat *xy) const -{ - const gl::FramebufferAttachment *attachment = mState.getFirstNonNullAttachment(); - ASSERT(attachment); - GLsizei sampleCount = attachment->getSamples(); - - d3d11_gl::GetSamplePosition(sampleCount, index, xy); - return gl::NoError(); -} - -bool Framebuffer11::hasAnyInternalDirtyBit() const -{ - return mInternalDirtyBits.any(); -} - -void Framebuffer11::syncInternalState(const gl::Context *context) -{ - syncState(context, gl::Framebuffer::DirtyBits()); -} - -RenderTarget11 *Framebuffer11::getFirstRenderTarget() const -{ - ASSERT(mInternalDirtyBits.none()); - for (auto *renderTarget : mCachedColorRenderTargets) - { - if (renderTarget) - { - return renderTarget; - } - } - - return mCachedDepthStencilRenderTarget; -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Framebuffer11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Framebuffer11.h deleted file mode 100644 index afdda299b9..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Framebuffer11.h +++ /dev/null @@ -1,104 +0,0 @@ -// -// Copyright 2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Framebuffer11.h: Defines the Framebuffer11 class. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_FRAMBUFFER11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_FRAMBUFFER11_H_ - -#include "libANGLE/renderer/d3d/FramebufferD3D.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/signal_utils.h" - -namespace rx -{ -class Renderer11; - -class Framebuffer11 : public FramebufferD3D, public OnRenderTargetDirtyReceiver -{ - public: - Framebuffer11(const gl::FramebufferState &data, Renderer11 *renderer); - ~Framebuffer11() override; - - gl::Error discard(const gl::Context *context, size_t count, const GLenum *attachments) override; - gl::Error invalidate(const gl::Context *context, - size_t count, - const GLenum *attachments) override; - gl::Error invalidateSub(const gl::Context *context, - size_t count, - const GLenum *attachments, - const gl::Rectangle &area) override; - - // Invalidate the cached swizzles of all bound texture attachments. - gl::Error markAttachmentsDirty(const gl::Context *context) const; - - void syncState(const gl::Context *context, - const gl::Framebuffer::DirtyBits &dirtyBits) override; - - const RenderTargetArray &getCachedColorRenderTargets() const - { - return mCachedColorRenderTargets; - } - const RenderTarget11 *getCachedDepthStencilRenderTarget() const - { - return mCachedDepthStencilRenderTarget; - } - - RenderTarget11 *getFirstRenderTarget() const; - - bool hasAnyInternalDirtyBit() const; - void syncInternalState(const gl::Context *context); - - void signal(size_t channelID, const gl::Context *context) override; - - gl::Error getSamplePosition(size_t index, GLfloat *xy) const override; - - private: - gl::Error clearImpl(const gl::Context *context, const ClearParameters &clearParams) override; - - gl::Error readPixelsImpl(const gl::Context *context, - const gl::Rectangle &area, - GLenum format, - GLenum type, - size_t outputPitch, - const gl::PixelPackState &pack, - uint8_t *pixels) override; - - gl::Error blitImpl(const gl::Context *context, - const gl::Rectangle &sourceArea, - const gl::Rectangle &destArea, - const gl::Rectangle *scissor, - bool blitRenderTarget, - bool blitDepth, - bool blitStencil, - GLenum filter, - const gl::Framebuffer *sourceFramebuffer) override; - - gl::Error invalidateBase(const gl::Context *context, - size_t count, - const GLenum *attachments, - bool useEXTBehavior) const; - gl::Error invalidateAttachment(const gl::Context *context, - const gl::FramebufferAttachment *attachment) const; - - GLenum getRenderTargetImplementationFormat(RenderTargetD3D *renderTarget) const override; - - void updateColorRenderTarget(const gl::Context *context, size_t colorIndex); - void updateDepthStencilRenderTarget(const gl::Context *context); - - Renderer11 *const mRenderer; - RenderTargetArray mCachedColorRenderTargets; - RenderTarget11 *mCachedDepthStencilRenderTarget; - - std::vector<OnRenderTargetDirtyBinding> mColorRenderTargetsDirty; - OnRenderTargetDirtyBinding mDepthStencilRenderTargetDirty; - - gl::Framebuffer::DirtyBits mInternalDirtyBits; -}; - -} - -#endif // LIBANGLE_RENDERER_D3D_D3D11_FRAMBUFFER11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Image11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Image11.cpp deleted file mode 100644 index bd921f1935..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Image11.cpp +++ /dev/null @@ -1,657 +0,0 @@ -// -// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Image11.h: Implements the rx::Image11 class, which acts as the interface to -// the actual underlying resources of a Texture - -#include "libANGLE/renderer/d3d/d3d11/Image11.h" - -#include "common/utilities.h" -#include "libANGLE/formatutils.h" -#include "libANGLE/Framebuffer.h" -#include "libANGLE/FramebufferAttachment.h" -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h" -#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h" -#include "libANGLE/renderer/d3d/d3d11/TextureStorage11.h" - -namespace rx -{ - -Image11::Image11(Renderer11 *renderer) - : mRenderer(renderer), - mDXGIFormat(DXGI_FORMAT_UNKNOWN), - mStagingTexture(), - mStagingSubresource(0), - mRecoverFromStorage(false), - mAssociatedStorage(nullptr), - mAssociatedImageIndex(gl::ImageIndex::MakeInvalid()), - mRecoveredFromStorageCount(0) -{ -} - -Image11::~Image11() -{ - disassociateStorage(); - releaseStagingTexture(); -} - -// static -gl::Error Image11::GenerateMipmap(const gl::Context *context, - Image11 *dest, - Image11 *src, - const Renderer11DeviceCaps &rendererCaps) -{ - ASSERT(src->getDXGIFormat() == dest->getDXGIFormat()); - ASSERT(src->getWidth() == 1 || src->getWidth() / 2 == dest->getWidth()); - ASSERT(src->getHeight() == 1 || src->getHeight() / 2 == dest->getHeight()); - - D3D11_MAPPED_SUBRESOURCE destMapped; - ANGLE_TRY(dest->map(context, D3D11_MAP_WRITE, &destMapped)); - - D3D11_MAPPED_SUBRESOURCE srcMapped; - gl::Error error = src->map(context, D3D11_MAP_READ, &srcMapped); - if (error.isError()) - { - dest->unmap(); - return error; - } - - const uint8_t *sourceData = reinterpret_cast<const uint8_t *>(srcMapped.pData); - uint8_t *destData = reinterpret_cast<uint8_t *>(destMapped.pData); - - auto mipGenerationFunction = - d3d11::Format::Get(src->getInternalFormat(), rendererCaps).format().mipGenerationFunction; - mipGenerationFunction(src->getWidth(), src->getHeight(), src->getDepth(), sourceData, - srcMapped.RowPitch, srcMapped.DepthPitch, destData, destMapped.RowPitch, - destMapped.DepthPitch); - - dest->unmap(); - src->unmap(); - - dest->markDirty(); - - return gl::NoError(); -} - -// static -gl::Error Image11::CopyImage(const gl::Context *context, - Image11 *dest, - Image11 *source, - const gl::Rectangle &sourceRect, - const gl::Offset &destOffset, - bool unpackFlipY, - bool unpackPremultiplyAlpha, - bool unpackUnmultiplyAlpha, - const Renderer11DeviceCaps &rendererCaps) -{ - D3D11_MAPPED_SUBRESOURCE destMapped; - ANGLE_TRY(dest->map(context, D3D11_MAP_WRITE, &destMapped)); - - D3D11_MAPPED_SUBRESOURCE srcMapped; - gl::Error error = source->map(context, D3D11_MAP_READ, &srcMapped); - if (error.isError()) - { - dest->unmap(); - return error; - } - - const auto &sourceFormat = - d3d11::Format::Get(source->getInternalFormat(), rendererCaps).format(); - GLuint sourcePixelBytes = - gl::GetSizedInternalFormatInfo(sourceFormat.fboImplementationInternalFormat).pixelBytes; - - GLenum destUnsizedFormat = gl::GetUnsizedFormat(dest->getInternalFormat()); - const auto &destFormat = d3d11::Format::Get(dest->getInternalFormat(), rendererCaps).format(); - const auto &destFormatInfo = - gl::GetSizedInternalFormatInfo(destFormat.fboImplementationInternalFormat); - GLuint destPixelBytes = destFormatInfo.pixelBytes; - - const uint8_t *sourceData = reinterpret_cast<const uint8_t *>(srcMapped.pData) + - sourceRect.x * sourcePixelBytes + sourceRect.y * srcMapped.RowPitch; - uint8_t *destData = reinterpret_cast<uint8_t *>(destMapped.pData) + - destOffset.x * destPixelBytes + destOffset.y * destMapped.RowPitch; - - CopyImageCHROMIUM(sourceData, srcMapped.RowPitch, sourcePixelBytes, - sourceFormat.colorReadFunction, destData, destMapped.RowPitch, destPixelBytes, - destFormat.colorWriteFunction, destUnsizedFormat, - destFormatInfo.componentType, sourceRect.width, sourceRect.height, - unpackFlipY, unpackPremultiplyAlpha, unpackUnmultiplyAlpha); - - dest->unmap(); - source->unmap(); - - dest->markDirty(); - - return gl::NoError(); -} - -bool Image11::isDirty() const -{ - // If mDirty is true AND mStagingTexture doesn't exist AND mStagingTexture doesn't need to be - // recovered from TextureStorage AND the texture doesn't require init data (i.e. a blank new - // texture will suffice) AND robust resource initialization is not enabled then isDirty should - // still return false. - if (mDirty && !mStagingTexture.valid() && !mRecoverFromStorage) - { - const Renderer11DeviceCaps &deviceCaps = mRenderer->getRenderer11DeviceCaps(); - const auto &formatInfo = d3d11::Format::Get(mInternalFormat, deviceCaps); - if (formatInfo.dataInitializerFunction == nullptr) - { - return false; - } - } - - return mDirty; -} - -gl::Error Image11::copyToStorage(const gl::Context *context, - TextureStorage *storage, - const gl::ImageIndex &index, - const gl::Box ®ion) -{ - TextureStorage11 *storage11 = GetAs<TextureStorage11>(storage); - - // If an app's behavior results in an Image11 copying its data to/from to a TextureStorage - // multiple times, then we should just keep the staging texture around to prevent the copying - // from impacting perf. We allow the Image11 to copy its data to/from TextureStorage once. This - // accounts for an app making a late call to glGenerateMipmap. - bool attemptToReleaseStagingTexture = (mRecoveredFromStorageCount < 2); - - if (attemptToReleaseStagingTexture) - { - // If another image is relying on this Storage for its data, then we must let it recover its - // data before we overwrite it. - ANGLE_TRY(storage11->releaseAssociatedImage(context, index, this)); - } - - const TextureHelper11 *stagingTexture = nullptr; - unsigned int stagingSubresourceIndex = 0; - ANGLE_TRY(getStagingTexture(&stagingTexture, &stagingSubresourceIndex)); - ANGLE_TRY(storage11->updateSubresourceLevel(context, *stagingTexture, stagingSubresourceIndex, - index, region)); - - // Once the image data has been copied into the Storage, we can release it locally. - if (attemptToReleaseStagingTexture) - { - storage11->associateImage(this, index); - releaseStagingTexture(); - mRecoverFromStorage = true; - mAssociatedStorage = storage11; - mAssociatedImageIndex = index; - } - - return gl::NoError(); -} - -void Image11::verifyAssociatedStorageValid(TextureStorage11 *textureStorage) const -{ - ASSERT(mAssociatedStorage == textureStorage); -} - -gl::Error Image11::recoverFromAssociatedStorage(const gl::Context *context) -{ - if (mRecoverFromStorage) - { - ANGLE_TRY(createStagingTexture()); - - mAssociatedStorage->verifyAssociatedImageValid(mAssociatedImageIndex, this); - - // CopySubResource from the Storage to the Staging texture - gl::Box region(0, 0, 0, mWidth, mHeight, mDepth); - ANGLE_TRY(mAssociatedStorage->copySubresourceLevel( - context, mStagingTexture, mStagingSubresource, mAssociatedImageIndex, region)); - mRecoveredFromStorageCount += 1; - - // Reset all the recovery parameters, even if the texture storage association is broken. - disassociateStorage(); - } - - return gl::NoError(); -} - -void Image11::disassociateStorage() -{ - if (mRecoverFromStorage) - { - // Make the texturestorage release the Image11 too - mAssociatedStorage->disassociateImage(mAssociatedImageIndex, this); - - mRecoverFromStorage = false; - mAssociatedStorage = nullptr; - mAssociatedImageIndex = gl::ImageIndex::MakeInvalid(); - } -} - -bool Image11::redefine(GLenum target, - GLenum internalformat, - const gl::Extents &size, - bool forceRelease) -{ - if (mWidth != size.width || mHeight != size.height || mInternalFormat != internalformat || - forceRelease) - { - // End the association with the TextureStorage, since that data will be out of date. - // Also reset mRecoveredFromStorageCount since this Image is getting completely redefined. - disassociateStorage(); - mRecoveredFromStorageCount = 0; - - mWidth = size.width; - mHeight = size.height; - mDepth = size.depth; - mInternalFormat = internalformat; - mTarget = target; - - // compute the d3d format that will be used - const d3d11::Format &formatInfo = - d3d11::Format::Get(internalformat, mRenderer->getRenderer11DeviceCaps()); - mDXGIFormat = formatInfo.texFormat; - mRenderable = (formatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN); - - releaseStagingTexture(); - mDirty = (formatInfo.dataInitializerFunction != nullptr); - - return true; - } - - return false; -} - -DXGI_FORMAT Image11::getDXGIFormat() const -{ - // this should only happen if the image hasn't been redefined first - // which would be a bug by the caller - ASSERT(mDXGIFormat != DXGI_FORMAT_UNKNOWN); - - return mDXGIFormat; -} - -// Store the pixel rectangle designated by xoffset,yoffset,width,height with pixels stored as -// format/type at input -// into the target pixel rectangle. -gl::Error Image11::loadData(const gl::Context *context, - const gl::Box &area, - const gl::PixelUnpackState &unpack, - GLenum type, - const void *input, - bool applySkipImages) -{ - const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(mInternalFormat); - GLuint inputRowPitch = 0; - ANGLE_TRY_RESULT( - formatInfo.computeRowPitch(type, area.width, unpack.alignment, unpack.rowLength), - inputRowPitch); - GLuint inputDepthPitch = 0; - ANGLE_TRY_RESULT(formatInfo.computeDepthPitch(area.height, unpack.imageHeight, inputRowPitch), - inputDepthPitch); - GLuint inputSkipBytes = 0; - ANGLE_TRY_RESULT( - formatInfo.computeSkipBytes(inputRowPitch, inputDepthPitch, unpack, applySkipImages), - inputSkipBytes); - - const d3d11::DXGIFormatSize &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(mDXGIFormat); - GLuint outputPixelSize = dxgiFormatInfo.pixelBytes; - - const d3d11::Format &d3dFormatInfo = - d3d11::Format::Get(mInternalFormat, mRenderer->getRenderer11DeviceCaps()); - LoadImageFunction loadFunction = d3dFormatInfo.getLoadFunctions()(type).loadFunction; - - D3D11_MAPPED_SUBRESOURCE mappedImage; - ANGLE_TRY(map(context, D3D11_MAP_WRITE, &mappedImage)); - - uint8_t *offsetMappedData = (reinterpret_cast<uint8_t *>(mappedImage.pData) + - (area.y * mappedImage.RowPitch + area.x * outputPixelSize + - area.z * mappedImage.DepthPitch)); - loadFunction(area.width, area.height, area.depth, - reinterpret_cast<const uint8_t *>(input) + inputSkipBytes, inputRowPitch, - inputDepthPitch, offsetMappedData, mappedImage.RowPitch, mappedImage.DepthPitch); - - unmap(); - - return gl::NoError(); -} - -gl::Error Image11::loadCompressedData(const gl::Context *context, - const gl::Box &area, - const void *input) -{ - const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(mInternalFormat); - GLsizei inputRowPitch = 0; - ANGLE_TRY_RESULT(formatInfo.computeRowPitch(GL_UNSIGNED_BYTE, area.width, 1, 0), inputRowPitch); - GLsizei inputDepthPitch = 0; - ANGLE_TRY_RESULT(formatInfo.computeDepthPitch(area.height, 0, inputRowPitch), inputDepthPitch); - - const d3d11::DXGIFormatSize &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(mDXGIFormat); - GLuint outputPixelSize = dxgiFormatInfo.pixelBytes; - GLuint outputBlockWidth = dxgiFormatInfo.blockWidth; - GLuint outputBlockHeight = dxgiFormatInfo.blockHeight; - - ASSERT(area.x % outputBlockWidth == 0); - ASSERT(area.y % outputBlockHeight == 0); - - const d3d11::Format &d3dFormatInfo = - d3d11::Format::Get(mInternalFormat, mRenderer->getRenderer11DeviceCaps()); - LoadImageFunction loadFunction = - d3dFormatInfo.getLoadFunctions()(GL_UNSIGNED_BYTE).loadFunction; - - D3D11_MAPPED_SUBRESOURCE mappedImage; - ANGLE_TRY(map(context, D3D11_MAP_WRITE, &mappedImage)); - - uint8_t *offsetMappedData = - reinterpret_cast<uint8_t *>(mappedImage.pData) + - ((area.y / outputBlockHeight) * mappedImage.RowPitch + - (area.x / outputBlockWidth) * outputPixelSize + area.z * mappedImage.DepthPitch); - - loadFunction(area.width, area.height, area.depth, reinterpret_cast<const uint8_t *>(input), - inputRowPitch, inputDepthPitch, offsetMappedData, mappedImage.RowPitch, - mappedImage.DepthPitch); - - unmap(); - - return gl::NoError(); -} - -gl::Error Image11::copyFromTexStorage(const gl::Context *context, - const gl::ImageIndex &imageIndex, - TextureStorage *source) -{ - TextureStorage11 *storage11 = GetAs<TextureStorage11>(source); - - const TextureHelper11 *textureHelper = nullptr; - ANGLE_TRY(storage11->getResource(context, &textureHelper)); - - UINT subresourceIndex = storage11->getSubresourceIndex(imageIndex); - - gl::Box sourceBox(0, 0, 0, mWidth, mHeight, mDepth); - return copyWithoutConversion(gl::Offset(), sourceBox, *textureHelper, subresourceIndex); -} - -gl::Error Image11::copyFromFramebuffer(const gl::Context *context, - const gl::Offset &destOffset, - const gl::Rectangle &sourceArea, - const gl::Framebuffer *sourceFBO) -{ - const gl::FramebufferAttachment *srcAttachment = sourceFBO->getReadColorbuffer(); - ASSERT(srcAttachment); - - GLenum sourceInternalFormat = srcAttachment->getFormat().info->sizedInternalFormat; - const auto &d3d11Format = - d3d11::Format::Get(sourceInternalFormat, mRenderer->getRenderer11DeviceCaps()); - - if (d3d11Format.texFormat == mDXGIFormat && sourceInternalFormat == mInternalFormat) - { - RenderTarget11 *rt11 = nullptr; - ANGLE_TRY(srcAttachment->getRenderTarget(context, &rt11)); - ASSERT(rt11->getTexture().get()); - - TextureHelper11 textureHelper = rt11->getTexture(); - unsigned int sourceSubResource = rt11->getSubresourceIndex(); - - gl::Box sourceBox(sourceArea.x, sourceArea.y, 0, sourceArea.width, sourceArea.height, 1); - return copyWithoutConversion(destOffset, sourceBox, textureHelper, sourceSubResource); - } - - // This format requires conversion, so we must copy the texture to staging and manually convert - // via readPixels - D3D11_MAPPED_SUBRESOURCE mappedImage; - ANGLE_TRY(map(context, D3D11_MAP_WRITE, &mappedImage)); - - // determine the offset coordinate into the destination buffer - const auto &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(mDXGIFormat); - GLsizei rowOffset = dxgiFormatInfo.pixelBytes * destOffset.x; - - uint8_t *dataOffset = static_cast<uint8_t *>(mappedImage.pData) + - mappedImage.RowPitch * destOffset.y + rowOffset + - destOffset.z * mappedImage.DepthPitch; - - const gl::InternalFormat &destFormatInfo = gl::GetSizedInternalFormatInfo(mInternalFormat); - const auto &destD3D11Format = - d3d11::Format::Get(mInternalFormat, mRenderer->getRenderer11DeviceCaps()); - - auto loadFunction = destD3D11Format.getLoadFunctions()(destFormatInfo.type); - gl::Error error = gl::NoError(); - if (loadFunction.requiresConversion) - { - size_t bufferSize = destFormatInfo.pixelBytes * sourceArea.width * sourceArea.height; - angle::MemoryBuffer *memoryBuffer = nullptr; - error = mRenderer->getScratchMemoryBuffer(bufferSize, &memoryBuffer); - - if (!error.isError()) - { - GLuint memoryBufferRowPitch = destFormatInfo.pixelBytes * sourceArea.width; - - error = mRenderer->readFromAttachment( - context, *srcAttachment, sourceArea, destFormatInfo.format, destFormatInfo.type, - memoryBufferRowPitch, gl::PixelPackState(), memoryBuffer->data()); - - loadFunction.loadFunction(sourceArea.width, sourceArea.height, 1, memoryBuffer->data(), - memoryBufferRowPitch, 0, dataOffset, mappedImage.RowPitch, - mappedImage.DepthPitch); - } - } - else - { - error = mRenderer->readFromAttachment( - context, *srcAttachment, sourceArea, destFormatInfo.format, destFormatInfo.type, - mappedImage.RowPitch, gl::PixelPackState(), dataOffset); - } - - unmap(); - mDirty = true; - - return error; -} - -gl::Error Image11::copyWithoutConversion(const gl::Offset &destOffset, - const gl::Box &sourceArea, - const TextureHelper11 &textureHelper, - UINT sourceSubResource) -{ - // No conversion needed-- use copyback fastpath - const TextureHelper11 *stagingTexture = nullptr; - unsigned int stagingSubresourceIndex = 0; - ANGLE_TRY(getStagingTexture(&stagingTexture, &stagingSubresourceIndex)); - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - const gl::Extents &extents = textureHelper.getExtents(); - - D3D11_BOX srcBox; - srcBox.left = sourceArea.x; - srcBox.right = sourceArea.x + sourceArea.width; - srcBox.top = sourceArea.y; - srcBox.bottom = sourceArea.y + sourceArea.height; - srcBox.front = sourceArea.z; - srcBox.back = sourceArea.z + sourceArea.depth; - - if (textureHelper.is2D() && textureHelper.getSampleCount() > 1) - { - D3D11_TEXTURE2D_DESC resolveDesc; - resolveDesc.Width = extents.width; - resolveDesc.Height = extents.height; - resolveDesc.MipLevels = 1; - resolveDesc.ArraySize = 1; - resolveDesc.Format = textureHelper.getFormat(); - resolveDesc.SampleDesc.Count = 1; - resolveDesc.SampleDesc.Quality = 0; - resolveDesc.Usage = D3D11_USAGE_DEFAULT; - resolveDesc.BindFlags = 0; - resolveDesc.CPUAccessFlags = 0; - resolveDesc.MiscFlags = 0; - - d3d11::Texture2D resolveTex; - ANGLE_TRY(mRenderer->allocateResource(resolveDesc, &resolveTex)); - - deviceContext->ResolveSubresource(resolveTex.get(), 0, textureHelper.get(), - sourceSubResource, textureHelper.getFormat()); - - deviceContext->CopySubresourceRegion(stagingTexture->get(), stagingSubresourceIndex, - destOffset.x, destOffset.y, destOffset.z, - resolveTex.get(), 0, &srcBox); - } - else - { - deviceContext->CopySubresourceRegion(stagingTexture->get(), stagingSubresourceIndex, - destOffset.x, destOffset.y, destOffset.z, - textureHelper.get(), sourceSubResource, &srcBox); - } - - mDirty = true; - return gl::NoError(); -} - -gl::Error Image11::getStagingTexture(const TextureHelper11 **outStagingTexture, - unsigned int *outSubresourceIndex) -{ - ANGLE_TRY(createStagingTexture()); - - *outStagingTexture = &mStagingTexture; - *outSubresourceIndex = mStagingSubresource; - return gl::NoError(); -} - -void Image11::releaseStagingTexture() -{ - mStagingTexture.reset(); -} - -gl::Error Image11::createStagingTexture() -{ - if (mStagingTexture.valid()) - { - return gl::NoError(); - } - - ASSERT(mWidth > 0 && mHeight > 0 && mDepth > 0); - - const DXGI_FORMAT dxgiFormat = getDXGIFormat(); - const auto &formatInfo = - d3d11::Format::Get(mInternalFormat, mRenderer->getRenderer11DeviceCaps()); - - int lodOffset = 1; - GLsizei width = mWidth; - GLsizei height = mHeight; - - // adjust size if needed for compressed textures - d3d11::MakeValidSize(false, dxgiFormat, &width, &height, &lodOffset); - - if (mTarget == GL_TEXTURE_3D) - { - D3D11_TEXTURE3D_DESC desc; - desc.Width = width; - desc.Height = height; - desc.Depth = mDepth; - desc.MipLevels = lodOffset + 1; - desc.Format = dxgiFormat; - desc.Usage = D3D11_USAGE_STAGING; - desc.BindFlags = 0; - desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; - desc.MiscFlags = 0; - - if (formatInfo.dataInitializerFunction != nullptr) - { - std::vector<D3D11_SUBRESOURCE_DATA> initialData; - std::vector<std::vector<BYTE>> textureData; - d3d11::GenerateInitialTextureData(mInternalFormat, mRenderer->getRenderer11DeviceCaps(), - width, height, mDepth, lodOffset + 1, &initialData, - &textureData); - - ANGLE_TRY( - mRenderer->allocateTexture(desc, formatInfo, initialData.data(), &mStagingTexture)); - } - else - { - ANGLE_TRY(mRenderer->allocateTexture(desc, formatInfo, &mStagingTexture)); - } - - mStagingTexture.setDebugName("Image11::StagingTexture3D"); - mStagingSubresource = D3D11CalcSubresource(lodOffset, 0, lodOffset + 1); - } - else if (mTarget == GL_TEXTURE_2D || mTarget == GL_TEXTURE_2D_ARRAY || - mTarget == GL_TEXTURE_CUBE_MAP) - { - D3D11_TEXTURE2D_DESC desc; - desc.Width = width; - desc.Height = height; - desc.MipLevels = lodOffset + 1; - desc.ArraySize = 1; - desc.Format = dxgiFormat; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.Usage = D3D11_USAGE_STAGING; - desc.BindFlags = 0; - desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; - desc.MiscFlags = 0; - - if (formatInfo.dataInitializerFunction != nullptr) - { - std::vector<D3D11_SUBRESOURCE_DATA> initialData; - std::vector<std::vector<BYTE>> textureData; - d3d11::GenerateInitialTextureData(mInternalFormat, mRenderer->getRenderer11DeviceCaps(), - width, height, 1, lodOffset + 1, &initialData, - &textureData); - - ANGLE_TRY( - mRenderer->allocateTexture(desc, formatInfo, initialData.data(), &mStagingTexture)); - } - else - { - ANGLE_TRY(mRenderer->allocateTexture(desc, formatInfo, &mStagingTexture)); - } - - mStagingTexture.setDebugName("Image11::StagingTexture2D"); - mStagingSubresource = D3D11CalcSubresource(lodOffset, 0, lodOffset + 1); - } - else - { - UNREACHABLE(); - } - - mDirty = false; - return gl::NoError(); -} - -gl::Error Image11::map(const gl::Context *context, D3D11_MAP mapType, D3D11_MAPPED_SUBRESOURCE *map) -{ - // We must recover from the TextureStorage if necessary, even for D3D11_MAP_WRITE. - ANGLE_TRY(recoverFromAssociatedStorage(context)); - - const TextureHelper11 *stagingTexture = nullptr; - unsigned int subresourceIndex = 0; - ANGLE_TRY(getStagingTexture(&stagingTexture, &subresourceIndex)); - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - ASSERT(stagingTexture && stagingTexture->valid()); - HRESULT result = deviceContext->Map(stagingTexture->get(), subresourceIndex, mapType, 0, map); - - if (FAILED(result)) - { - // this can fail if the device is removed (from TDR) - if (d3d11::isDeviceLostError(result)) - { - mRenderer->notifyDeviceLost(); - } - return gl::OutOfMemory() << "Failed to map staging texture, " << gl::FmtHR(result); - } - - mDirty = true; - - return gl::NoError(); -} - -void Image11::unmap() -{ - if (mStagingTexture.valid()) - { - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - deviceContext->Unmap(mStagingTexture.get(), mStagingSubresource); - } -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Image11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Image11.h deleted file mode 100644 index 584d231b37..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Image11.h +++ /dev/null @@ -1,112 +0,0 @@ -// -// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Image11.h: Defines the rx::Image11 class, which acts as the interface to -// the actual underlying resources of a Texture - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_IMAGE11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_IMAGE11_H_ - -#include "common/debug.h" -#include "libANGLE/ImageIndex.h" -#include "libANGLE/renderer/d3d/ImageD3D.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -namespace gl -{ -class Framebuffer; -} - -namespace rx -{ -class Renderer11; -class TextureHelper11; -class TextureStorage11; -struct Renderer11DeviceCaps; - -class Image11 : public ImageD3D -{ - public: - Image11(Renderer11 *renderer); - ~Image11() override; - - static gl::Error GenerateMipmap(const gl::Context *context, - Image11 *dest, - Image11 *src, - const Renderer11DeviceCaps &rendererCaps); - static gl::Error CopyImage(const gl::Context *context, - Image11 *dest, - Image11 *source, - const gl::Rectangle &sourceRect, - const gl::Offset &destOffset, - bool unpackFlipY, - bool unpackPremultiplyAlpha, - bool unpackUnmultiplyAlpha, - const Renderer11DeviceCaps &rendererCaps); - - bool isDirty() const override; - - gl::Error copyToStorage(const gl::Context *context, - TextureStorage *storage, - const gl::ImageIndex &index, - const gl::Box ®ion) override; - - bool redefine(GLenum target, GLenum internalformat, const gl::Extents &size, bool forceRelease) override; - - DXGI_FORMAT getDXGIFormat() const; - - gl::Error loadData(const gl::Context *context, - const gl::Box &area, - const gl::PixelUnpackState &unpack, - GLenum type, - const void *input, - bool applySkipImages) override; - gl::Error loadCompressedData(const gl::Context *context, - const gl::Box &area, - const void *input) override; - - gl::Error copyFromTexStorage(const gl::Context *context, - const gl::ImageIndex &imageIndex, - TextureStorage *source) override; - gl::Error copyFromFramebuffer(const gl::Context *context, - const gl::Offset &destOffset, - const gl::Rectangle &sourceArea, - const gl::Framebuffer *source) override; - - gl::Error recoverFromAssociatedStorage(const gl::Context *context); - void verifyAssociatedStorageValid(TextureStorage11 *textureStorage) const; - void disassociateStorage(); - - protected: - gl::Error map(const gl::Context *context, D3D11_MAP mapType, D3D11_MAPPED_SUBRESOURCE *map); - void unmap(); - - private: - gl::Error copyWithoutConversion(const gl::Offset &destOffset, - const gl::Box &sourceArea, - const TextureHelper11 &textureHelper, - UINT sourceSubResource); - - gl::Error getStagingTexture(const TextureHelper11 **outStagingTexture, - unsigned int *outSubresourceIndex); - gl::Error createStagingTexture(); - void releaseStagingTexture(); - - Renderer11 *mRenderer; - - DXGI_FORMAT mDXGIFormat; - TextureHelper11 mStagingTexture; - unsigned int mStagingSubresource; - - bool mRecoverFromStorage; - TextureStorage11 *mAssociatedStorage; - gl::ImageIndex mAssociatedImageIndex; - unsigned int mRecoveredFromStorageCount; -}; - -} - -#endif // LIBANGLE_RENDERER_D3D_D3D11_IMAGE11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/IndexBuffer11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/IndexBuffer11.cpp deleted file mode 100644 index a79fb71f71..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/IndexBuffer11.cpp +++ /dev/null @@ -1,159 +0,0 @@ -// -// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// IndexBuffer11.cpp: Defines the D3D11 IndexBuffer implementation. - -#include "libANGLE/renderer/d3d/d3d11/IndexBuffer11.h" - -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -namespace rx -{ - -IndexBuffer11::IndexBuffer11(Renderer11 *const renderer) - : mRenderer(renderer), mBuffer(), mBufferSize(0), mIndexType(GL_NONE), mDynamicUsage(false) -{ -} - -IndexBuffer11::~IndexBuffer11() -{ -} - -gl::Error IndexBuffer11::initialize(unsigned int bufferSize, GLenum indexType, bool dynamic) -{ - mBuffer.reset(); - - updateSerial(); - - if (bufferSize > 0) - { - D3D11_BUFFER_DESC bufferDesc; - bufferDesc.ByteWidth = bufferSize; - bufferDesc.Usage = D3D11_USAGE_DYNAMIC; - bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; - bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - bufferDesc.MiscFlags = 0; - bufferDesc.StructureByteStride = 0; - - ANGLE_TRY(mRenderer->allocateResource(bufferDesc, &mBuffer)); - - if (dynamic) - { - mBuffer.setDebugName("IndexBuffer11 (dynamic)"); - } - else - { - mBuffer.setDebugName("IndexBuffer11 (static)"); - } - } - - mBufferSize = bufferSize; - mIndexType = indexType; - mDynamicUsage = dynamic; - - return gl::NoError(); -} - -gl::Error IndexBuffer11::mapBuffer(unsigned int offset, unsigned int size, void** outMappedMemory) -{ - if (!mBuffer.valid()) - { - return gl::OutOfMemory() << "Internal index buffer is not initialized."; - } - - // Check for integer overflows and out-out-bounds map requests - if (offset + size < offset || offset + size > mBufferSize) - { - return gl::OutOfMemory() << "Index buffer map range is not inside the buffer."; - } - - ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext(); - - D3D11_MAPPED_SUBRESOURCE mappedResource; - HRESULT result = - dxContext->Map(mBuffer.get(), 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mappedResource); - if (FAILED(result)) - { - return gl::OutOfMemory() << "Failed to map internal index buffer, " << gl::FmtHR(result); - } - - *outMappedMemory = reinterpret_cast<char*>(mappedResource.pData) + offset; - return gl::NoError(); -} - -gl::Error IndexBuffer11::unmapBuffer() -{ - if (!mBuffer.valid()) - { - return gl::OutOfMemory() << "Internal index buffer is not initialized."; - } - - ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext(); - dxContext->Unmap(mBuffer.get(), 0); - return gl::NoError(); -} - -GLenum IndexBuffer11::getIndexType() const -{ - return mIndexType; -} - -unsigned int IndexBuffer11::getBufferSize() const -{ - return mBufferSize; -} - -gl::Error IndexBuffer11::setSize(unsigned int bufferSize, GLenum indexType) -{ - if (bufferSize > mBufferSize || indexType != mIndexType) - { - return initialize(bufferSize, indexType, mDynamicUsage); - } - else - { - return gl::NoError(); - } -} - -gl::Error IndexBuffer11::discard() -{ - if (!mBuffer.valid()) - { - return gl::OutOfMemory() << "Internal index buffer is not initialized."; - } - - ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext(); - - D3D11_MAPPED_SUBRESOURCE mappedResource; - HRESULT result = dxContext->Map(mBuffer.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - if (FAILED(result)) - { - return gl::OutOfMemory() << "Failed to map internal index buffer, " << gl::FmtHR(result); - } - - dxContext->Unmap(mBuffer.get(), 0); - - return gl::NoError(); -} - -DXGI_FORMAT IndexBuffer11::getIndexFormat() const -{ - switch (mIndexType) - { - case GL_UNSIGNED_BYTE: return DXGI_FORMAT_R16_UINT; - case GL_UNSIGNED_SHORT: return DXGI_FORMAT_R16_UINT; - case GL_UNSIGNED_INT: return DXGI_FORMAT_R32_UINT; - default: UNREACHABLE(); return DXGI_FORMAT_UNKNOWN; - } -} - -const d3d11::Buffer &IndexBuffer11::getBuffer() const -{ - return mBuffer; -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/IndexBuffer11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/IndexBuffer11.h deleted file mode 100644 index 7b5d744c02..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/IndexBuffer11.h +++ /dev/null @@ -1,50 +0,0 @@ -// -// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// IndexBuffer11.h: Defines the D3D11 IndexBuffer implementation. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_INDEXBUFFER11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_INDEXBUFFER11_H_ - -#include "libANGLE/renderer/d3d/IndexBuffer.h" -#include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h" - -namespace rx -{ -class Renderer11; - -class IndexBuffer11 : public IndexBuffer -{ - public: - explicit IndexBuffer11(Renderer11 *const renderer); - ~IndexBuffer11() override; - - gl::Error initialize(unsigned int bufferSize, GLenum indexType, bool dynamic) override; - - gl::Error mapBuffer(unsigned int offset, unsigned int size, void **outMappedMemory) override; - gl::Error unmapBuffer() override; - - GLenum getIndexType() const override; - unsigned int getBufferSize() const override; - gl::Error setSize(unsigned int bufferSize, GLenum indexType) override; - - gl::Error discard() override; - - DXGI_FORMAT getIndexFormat() const; - const d3d11::Buffer &getBuffer() const; - - private: - Renderer11 *const mRenderer; - - d3d11::Buffer mBuffer; - unsigned int mBufferSize; - GLenum mIndexType; - bool mDynamicUsage; -}; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_INDEXBUFFER11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/InputLayoutCache.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/InputLayoutCache.cpp deleted file mode 100644 index a238f97b08..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/InputLayoutCache.cpp +++ /dev/null @@ -1,503 +0,0 @@ -// -// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// InputLayoutCache.cpp: Defines InputLayoutCache, a class that builds and caches -// D3D11 input layouts. - -#include "libANGLE/renderer/d3d/d3d11/InputLayoutCache.h" - -#include "common/bitset_utils.h" -#include "common/utilities.h" -#include "libANGLE/Context.h" -#include "libANGLE/Program.h" -#include "libANGLE/VertexArray.h" -#include "libANGLE/VertexAttribute.h" -#include "libANGLE/renderer/d3d/IndexDataManager.h" -#include "libANGLE/renderer/d3d/ProgramD3D.h" -#include "libANGLE/renderer/d3d/VertexDataManager.h" -#include "libANGLE/renderer/d3d/d3d11/Buffer11.h" -#include "libANGLE/renderer/d3d/d3d11/Context11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/ShaderExecutable11.h" -#include "libANGLE/renderer/d3d/d3d11/VertexArray11.h" -#include "libANGLE/renderer/d3d/d3d11/VertexBuffer11.h" -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" - -namespace rx -{ - -namespace -{ - -size_t GetReservedBufferCount(bool usesPointSpriteEmulation) -{ - return usesPointSpriteEmulation ? 1 : 0; -} - -GLenum GetGLSLAttributeType(const std::vector<sh::Attribute> &shaderAttributes, size_t index) -{ - // Count matrices differently - for (const sh::Attribute &attrib : shaderAttributes) - { - if (attrib.location == -1) - { - continue; - } - - GLenum transposedType = gl::TransposeMatrixType(attrib.type); - int rows = gl::VariableRowCount(transposedType); - int intIndex = static_cast<int>(index); - - if (intIndex >= attrib.location && intIndex < attrib.location + rows) - { - return transposedType; - } - } - - UNREACHABLE(); - return GL_NONE; -} - -struct PackedAttribute -{ - uint8_t attribType; - uint8_t semanticIndex; - uint8_t vertexFormatType; - uint8_t divisor; -}; - -} // anonymous namespace - -PackedAttributeLayout::PackedAttributeLayout() : numAttributes(0), flags(0), attributeData({}) -{ -} - -PackedAttributeLayout::PackedAttributeLayout(const PackedAttributeLayout &other) = default; - -void PackedAttributeLayout::addAttributeData(GLenum glType, - UINT semanticIndex, - gl::VertexFormatType vertexFormatType, - unsigned int divisor) -{ - gl::AttributeType attribType = gl::GetAttributeType(glType); - - PackedAttribute packedAttrib; - packedAttrib.attribType = static_cast<uint8_t>(attribType); - packedAttrib.semanticIndex = static_cast<uint8_t>(semanticIndex); - packedAttrib.vertexFormatType = static_cast<uint8_t>(vertexFormatType); - packedAttrib.divisor = static_cast<uint8_t>(divisor); - - ASSERT(static_cast<gl::AttributeType>(packedAttrib.attribType) == attribType); - ASSERT(static_cast<UINT>(packedAttrib.semanticIndex) == semanticIndex); - ASSERT(static_cast<gl::VertexFormatType>(packedAttrib.vertexFormatType) == vertexFormatType); - ASSERT(static_cast<unsigned int>(packedAttrib.divisor) == divisor); - - static_assert(sizeof(uint32_t) == sizeof(PackedAttribute), "PackedAttributes must be 32-bits exactly."); - - attributeData[numAttributes++] = gl::bitCast<uint32_t>(packedAttrib); -} - -bool PackedAttributeLayout::operator==(const PackedAttributeLayout &other) const -{ - return (numAttributes == other.numAttributes) && (flags == other.flags) && - (attributeData == other.attributeData); -} - -InputLayoutCache::InputLayoutCache() - : mLayoutCache(kDefaultCacheSize * 2), mPointSpriteVertexBuffer(), mPointSpriteIndexBuffer() -{ -} - -InputLayoutCache::~InputLayoutCache() -{ -} - -void InputLayoutCache::clear() -{ - mLayoutCache.Clear(); - mPointSpriteVertexBuffer.reset(); - mPointSpriteIndexBuffer.reset(); -} - -gl::Error InputLayoutCache::applyVertexBuffers( - const gl::Context *context, - const std::vector<const TranslatedAttribute *> ¤tAttributes, - GLenum mode, - GLint start, - bool isIndexedRendering) -{ - Renderer11 *renderer = GetImplAs<Context11>(context)->getRenderer(); - const gl::State &state = context->getGLState(); - auto *stateManager = renderer->getStateManager(); - gl::Program *program = state.getProgram(); - ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program); - - bool programUsesInstancedPointSprites = programD3D->usesPointSize() && programD3D->usesInstancedPointSpriteEmulation(); - bool instancedPointSpritesActive = programUsesInstancedPointSprites && (mode == GL_POINTS); - - // Note that if we use instance emulation, we reserve the first buffer slot. - size_t reservedBuffers = GetReservedBufferCount(programUsesInstancedPointSprites); - - for (size_t attribIndex = 0; attribIndex < (gl::MAX_VERTEX_ATTRIBS - reservedBuffers); - ++attribIndex) - { - ID3D11Buffer *buffer = nullptr; - UINT vertexStride = 0; - UINT vertexOffset = 0; - - if (attribIndex < currentAttributes.size()) - { - const auto &attrib = *currentAttributes[attribIndex]; - Buffer11 *bufferStorage = attrib.storage ? GetAs<Buffer11>(attrib.storage) : nullptr; - - // If indexed pointsprite emulation is active, then we need to take a less efficent code path. - // Emulated indexed pointsprite rendering requires that the vertex buffers match exactly to - // the indices passed by the caller. This could expand or shrink the vertex buffer depending - // on the number of points indicated by the index list or how many duplicates are found on the index list. - if (bufferStorage == nullptr) - { - ASSERT(attrib.vertexBuffer.get()); - buffer = GetAs<VertexBuffer11>(attrib.vertexBuffer.get())->getBuffer().get(); - } - else if (instancedPointSpritesActive && isIndexedRendering) - { - VertexArray11 *vao11 = GetImplAs<VertexArray11>(state.getVertexArray()); - ASSERT(vao11->isCachedIndexInfoValid()); - TranslatedIndexData *indexInfo = vao11->getCachedIndexInfo(); - if (indexInfo->srcIndexData.srcBuffer != nullptr) - { - const uint8_t *bufferData = nullptr; - ANGLE_TRY(indexInfo->srcIndexData.srcBuffer->getData(context, &bufferData)); - ASSERT(bufferData != nullptr); - - ptrdiff_t offset = - reinterpret_cast<ptrdiff_t>(indexInfo->srcIndexData.srcIndices); - indexInfo->srcIndexData.srcBuffer = nullptr; - indexInfo->srcIndexData.srcIndices = bufferData + offset; - } - - ANGLE_TRY_RESULT(bufferStorage->getEmulatedIndexedBuffer( - context, &indexInfo->srcIndexData, attrib, start), - buffer); - } - else - { - ANGLE_TRY_RESULT( - bufferStorage->getBuffer(context, BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK), - buffer); - } - - vertexStride = attrib.stride; - ANGLE_TRY_RESULT(attrib.computeOffset(start), vertexOffset); - } - - size_t bufferIndex = reservedBuffers + attribIndex; - - stateManager->queueVertexBufferChange(bufferIndex, buffer, vertexStride, vertexOffset); - } - - // Instanced PointSprite emulation requires two additional ID3D11Buffers. A vertex buffer needs - // to be created and added to the list of current buffers, strides and offsets collections. - // This buffer contains the vertices for a single PointSprite quad. - // An index buffer also needs to be created and applied because rendering instanced data on - // D3D11 FL9_3 requires DrawIndexedInstanced() to be used. Shaders that contain gl_PointSize and - // used without the GL_POINTS rendering mode require a vertex buffer because some drivers cannot - // handle missing vertex data and will TDR the system. - if (programUsesInstancedPointSprites) - { - const UINT pointSpriteVertexStride = sizeof(float) * 5; - - if (!mPointSpriteVertexBuffer.valid()) - { - static const float pointSpriteVertices[] = - { - // Position // TexCoord - -1.0f, -1.0f, 0.0f, 0.0f, 1.0f, - -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, - 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, - 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, - -1.0f, -1.0f, 0.0f, 0.0f, 1.0f, - 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, - }; - - D3D11_SUBRESOURCE_DATA vertexBufferData = { pointSpriteVertices, 0, 0 }; - D3D11_BUFFER_DESC vertexBufferDesc; - vertexBufferDesc.ByteWidth = sizeof(pointSpriteVertices); - vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - vertexBufferDesc.Usage = D3D11_USAGE_IMMUTABLE; - vertexBufferDesc.CPUAccessFlags = 0; - vertexBufferDesc.MiscFlags = 0; - vertexBufferDesc.StructureByteStride = 0; - - ANGLE_TRY(renderer->allocateResource(vertexBufferDesc, &vertexBufferData, - &mPointSpriteVertexBuffer)); - } - - // Set the stride to 0 if GL_POINTS mode is not being used to instruct the driver to avoid - // indexing into the vertex buffer. - UINT stride = instancedPointSpritesActive ? pointSpriteVertexStride : 0; - stateManager->queueVertexBufferChange(0, mPointSpriteVertexBuffer.get(), stride, 0); - - if (!mPointSpriteIndexBuffer.valid()) - { - // Create an index buffer and set it for pointsprite rendering - static const unsigned short pointSpriteIndices[] = - { - 0, 1, 2, 3, 4, 5, - }; - - D3D11_SUBRESOURCE_DATA indexBufferData = { pointSpriteIndices, 0, 0 }; - D3D11_BUFFER_DESC indexBufferDesc; - indexBufferDesc.ByteWidth = sizeof(pointSpriteIndices); - indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; - indexBufferDesc.Usage = D3D11_USAGE_IMMUTABLE; - indexBufferDesc.CPUAccessFlags = 0; - indexBufferDesc.MiscFlags = 0; - indexBufferDesc.StructureByteStride = 0; - - ANGLE_TRY(renderer->allocateResource(indexBufferDesc, &indexBufferData, - &mPointSpriteIndexBuffer)); - } - - if (instancedPointSpritesActive) - { - // The index buffer is applied here because Instanced PointSprite emulation uses the a - // non-indexed rendering path in ANGLE (DrawArrays). This means that applyIndexBuffer() - // on the renderer will not be called and setting this buffer here ensures that the - // rendering path will contain the correct index buffers. - stateManager->setIndexBuffer(mPointSpriteIndexBuffer.get(), DXGI_FORMAT_R16_UINT, 0); - } - } - - stateManager->applyVertexBufferChanges(); - return gl::NoError(); -} - -gl::Error InputLayoutCache::updateVertexOffsetsForPointSpritesEmulation( - Renderer11 *renderer, - const std::vector<const TranslatedAttribute *> ¤tAttributes, - GLint startVertex, - GLsizei emulatedInstanceId) -{ - auto *stateManager = renderer->getStateManager(); - - size_t reservedBuffers = GetReservedBufferCount(true); - for (size_t attribIndex = 0; attribIndex < currentAttributes.size(); ++attribIndex) - { - const auto &attrib = *currentAttributes[attribIndex]; - size_t bufferIndex = reservedBuffers + attribIndex; - - if (attrib.divisor > 0) - { - unsigned int offset = 0; - ANGLE_TRY_RESULT(attrib.computeOffset(startVertex), offset); - offset += (attrib.stride * (emulatedInstanceId / attrib.divisor)); - stateManager->queueVertexOffsetChange(bufferIndex, offset); - } - } - - stateManager->applyVertexBufferChanges(); - return gl::NoError(); -} - -gl::Error InputLayoutCache::updateInputLayout( - Renderer11 *renderer, - const gl::State &state, - const std::vector<const TranslatedAttribute *> ¤tAttributes, - GLenum mode, - const AttribIndexArray &sortedSemanticIndices, - const DrawCallVertexParams &vertexParams) -{ - gl::Program *program = state.getProgram(); - const auto &shaderAttributes = program->getAttributes(); - PackedAttributeLayout layout; - - ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program); - bool programUsesInstancedPointSprites = - programD3D->usesPointSize() && programD3D->usesInstancedPointSpriteEmulation(); - bool instancedPointSpritesActive = programUsesInstancedPointSprites && (mode == GL_POINTS); - - if (programUsesInstancedPointSprites) - { - layout.flags |= PackedAttributeLayout::FLAG_USES_INSTANCED_SPRITES; - } - - if (instancedPointSpritesActive) - { - layout.flags |= PackedAttributeLayout::FLAG_INSTANCED_SPRITES_ACTIVE; - } - - if (vertexParams.instances() > 0) - { - layout.flags |= PackedAttributeLayout::FLAG_INSTANCED_RENDERING_ACTIVE; - } - - const auto &attribs = state.getVertexArray()->getVertexAttributes(); - const auto &bindings = state.getVertexArray()->getVertexBindings(); - const auto &locationToSemantic = programD3D->getAttribLocationToD3DSemantics(); - int divisorMultiplier = program->usesMultiview() ? program->getNumViews() : 1; - - for (size_t attribIndex : program->getActiveAttribLocationsMask()) - { - // Record the type of the associated vertex shader vector in our key - // This will prevent mismatched vertex shaders from using the same input layout - GLenum glslElementType = GetGLSLAttributeType(shaderAttributes, attribIndex); - - const auto &attrib = attribs[attribIndex]; - const auto &binding = bindings[attrib.bindingIndex]; - int d3dSemantic = locationToSemantic[attribIndex]; - - const auto ¤tValue = - state.getVertexAttribCurrentValue(static_cast<unsigned int>(attribIndex)); - gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib, currentValue.Type); - - layout.addAttributeData(glslElementType, d3dSemantic, vertexFormatType, - binding.getDivisor() * divisorMultiplier); - } - - const d3d11::InputLayout *inputLayout = nullptr; - if (layout.numAttributes > 0 || layout.flags != 0) - { - auto it = mLayoutCache.Get(layout); - if (it != mLayoutCache.end()) - { - inputLayout = &it->second; - } - else - { - angle::TrimCache(mLayoutCache.max_size() / 2, kGCLimit, "input layout", &mLayoutCache); - - d3d11::InputLayout newInputLayout; - ANGLE_TRY(createInputLayout(renderer, sortedSemanticIndices, currentAttributes, mode, - program, vertexParams, &newInputLayout)); - - auto insertIt = mLayoutCache.Put(layout, std::move(newInputLayout)); - inputLayout = &insertIt->second; - } - } - - renderer->getStateManager()->setInputLayout(inputLayout); - return gl::NoError(); -} - -gl::Error InputLayoutCache::createInputLayout( - Renderer11 *renderer, - const AttribIndexArray &sortedSemanticIndices, - const std::vector<const TranslatedAttribute *> ¤tAttributes, - GLenum mode, - gl::Program *program, - const DrawCallVertexParams &vertexParams, - d3d11::InputLayout *inputLayoutOut) -{ - ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program); - auto featureLevel = renderer->getRenderer11DeviceCaps().featureLevel; - - bool programUsesInstancedPointSprites = - programD3D->usesPointSize() && programD3D->usesInstancedPointSpriteEmulation(); - - unsigned int inputElementCount = 0; - std::array<D3D11_INPUT_ELEMENT_DESC, gl::MAX_VERTEX_ATTRIBS> inputElements; - - for (size_t attribIndex = 0; attribIndex < currentAttributes.size(); ++attribIndex) - { - const auto &attrib = *currentAttributes[attribIndex]; - const int sortedIndex = sortedSemanticIndices[attribIndex]; - - D3D11_INPUT_CLASSIFICATION inputClass = - attrib.divisor > 0 ? D3D11_INPUT_PER_INSTANCE_DATA : D3D11_INPUT_PER_VERTEX_DATA; - - const auto &vertexFormatType = - gl::GetVertexFormatType(*attrib.attribute, attrib.currentValueType); - const auto &vertexFormatInfo = d3d11::GetVertexFormatInfo(vertexFormatType, featureLevel); - - auto *inputElement = &inputElements[inputElementCount]; - - inputElement->SemanticName = "TEXCOORD"; - inputElement->SemanticIndex = sortedIndex; - inputElement->Format = vertexFormatInfo.nativeFormat; - inputElement->InputSlot = static_cast<UINT>(attribIndex); - inputElement->AlignedByteOffset = 0; - inputElement->InputSlotClass = inputClass; - inputElement->InstanceDataStepRate = attrib.divisor; - - inputElementCount++; - } - - // Instanced PointSprite emulation requires additional entries in the - // inputlayout to support the vertices that make up the pointsprite quad. - // We do this even if mode != GL_POINTS, since the shader signature has these inputs, and the - // input layout must match the shader - if (programUsesInstancedPointSprites) - { - // On 9_3, we must ensure that slot 0 contains non-instanced data. - // If slot 0 currently contains instanced data then we swap it with a non-instanced element. - // Note that instancing is only available on 9_3 via ANGLE_instanced_arrays, since 9_3 - // doesn't support OpenGL ES 3.0. - // As per the spec for ANGLE_instanced_arrays, not all attributes can be instanced - // simultaneously, so a non-instanced element must exist. - - GLsizei numIndicesPerInstance = 0; - if (vertexParams.instances() > 0) - { - // This may trigger an evaluation of the index range. - numIndicesPerInstance = vertexParams.vertexCount(); - } - - for (size_t elementIndex = 0; elementIndex < inputElementCount; ++elementIndex) - { - // If rendering points and instanced pointsprite emulation is being used, the - // inputClass is required to be configured as per instance data - if (mode == GL_POINTS) - { - inputElements[elementIndex].InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA; - inputElements[elementIndex].InstanceDataStepRate = 1; - if (numIndicesPerInstance > 0 && currentAttributes[elementIndex]->divisor > 0) - { - inputElements[elementIndex].InstanceDataStepRate = numIndicesPerInstance; - } - } - inputElements[elementIndex].InputSlot++; - } - - inputElements[inputElementCount].SemanticName = "SPRITEPOSITION"; - inputElements[inputElementCount].SemanticIndex = 0; - inputElements[inputElementCount].Format = DXGI_FORMAT_R32G32B32_FLOAT; - inputElements[inputElementCount].InputSlot = 0; - inputElements[inputElementCount].AlignedByteOffset = 0; - inputElements[inputElementCount].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; - inputElements[inputElementCount].InstanceDataStepRate = 0; - inputElementCount++; - - inputElements[inputElementCount].SemanticName = "SPRITETEXCOORD"; - inputElements[inputElementCount].SemanticIndex = 0; - inputElements[inputElementCount].Format = DXGI_FORMAT_R32G32_FLOAT; - inputElements[inputElementCount].InputSlot = 0; - inputElements[inputElementCount].AlignedByteOffset = sizeof(float) * 3; - inputElements[inputElementCount].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; - inputElements[inputElementCount].InstanceDataStepRate = 0; - inputElementCount++; - } - - ShaderExecutableD3D *shader = nullptr; - ANGLE_TRY(programD3D->getVertexExecutableForCachedInputLayout(&shader, nullptr)); - - ShaderExecutableD3D *shader11 = GetAs<ShaderExecutable11>(shader); - - InputElementArray inputElementArray(inputElements.data(), inputElementCount); - ShaderData vertexShaderData(shader11->getFunction(), shader11->getLength()); - - ANGLE_TRY(renderer->allocateResource(inputElementArray, &vertexShaderData, inputLayoutOut)); - return gl::NoError(); -} - -void InputLayoutCache::setCacheSize(size_t newCacheSize) -{ - // Forces a reset of the cache. - LayoutCache newCache(newCacheSize); - mLayoutCache.Swap(newCache); -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/InputLayoutCache.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/InputLayoutCache.h deleted file mode 100644 index 8d7c7dd0f0..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/InputLayoutCache.h +++ /dev/null @@ -1,135 +0,0 @@ -// -// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// InputLayoutCache.h: Defines InputLayoutCache, a class that builds and caches -// D3D11 input layouts. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_INPUTLAYOUTCACHE_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_INPUTLAYOUTCACHE_H_ - -#include <GLES2/gl2.h> - -#include <cstddef> - -#include <array> -#include <map> - -#include "common/angleutils.h" -#include "libANGLE/Constants.h" -#include "libANGLE/Error.h" -#include "libANGLE/SizedMRUCache.h" -#include "libANGLE/formatutils.h" -#include "libANGLE/renderer/d3d/RendererD3D.h" -#include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h" - -namespace rx -{ -class DrawCallVertexParams; -struct PackedAttributeLayout -{ - PackedAttributeLayout(); - PackedAttributeLayout(const PackedAttributeLayout &other); - - void addAttributeData(GLenum glType, - UINT semanticIndex, - gl::VertexFormatType vertexFormatType, - unsigned int divisor); - - bool operator==(const PackedAttributeLayout &other) const; - - enum Flags - { - FLAG_USES_INSTANCED_SPRITES = 0x1, - FLAG_INSTANCED_SPRITES_ACTIVE = 0x2, - FLAG_INSTANCED_RENDERING_ACTIVE = 0x4, - }; - - uint32_t numAttributes; - uint32_t flags; - std::array<uint32_t, gl::MAX_VERTEX_ATTRIBS> attributeData; -}; -} // namespace rx - -namespace std -{ -template <> -struct hash<rx::PackedAttributeLayout> -{ - size_t operator()(const rx::PackedAttributeLayout &value) const - { - return angle::ComputeGenericHash(value); - } -}; -} // namespace std - -namespace gl -{ -class Program; -} // namespace gl - -namespace rx -{ -struct TranslatedAttribute; -struct TranslatedIndexData; -struct SourceIndexData; -class ProgramD3D; -class Renderer11; - -class InputLayoutCache : angle::NonCopyable -{ - public: - InputLayoutCache(); - ~InputLayoutCache(); - - void clear(); - - gl::Error applyVertexBuffers(const gl::Context *context, - const std::vector<const TranslatedAttribute *> ¤tAttributes, - GLenum mode, - GLint start, - bool isIndexedRendering); - - gl::Error updateVertexOffsetsForPointSpritesEmulation( - Renderer11 *renderer, - const std::vector<const TranslatedAttribute *> ¤tAttributes, - GLint startVertex, - GLsizei emulatedInstanceId); - - // Useful for testing - void setCacheSize(size_t newCacheSize); - - gl::Error updateInputLayout(Renderer11 *renderer, - const gl::State &state, - const std::vector<const TranslatedAttribute *> ¤tAttributes, - GLenum mode, - const AttribIndexArray &sortedSemanticIndices, - const DrawCallVertexParams &vertexParams); - - private: - gl::Error createInputLayout(Renderer11 *renderer, - const AttribIndexArray &sortedSemanticIndices, - const std::vector<const TranslatedAttribute *> ¤tAttributes, - GLenum mode, - gl::Program *program, - const DrawCallVertexParams &vertexParams, - d3d11::InputLayout *inputLayoutOut); - - // Starting cache size. - static constexpr size_t kDefaultCacheSize = 1024; - - // The cache tries to clean up this many states at once. - static constexpr size_t kGCLimit = 128; - - using LayoutCache = angle::base::HashingMRUCache<PackedAttributeLayout, d3d11::InputLayout>; - LayoutCache mLayoutCache; - - d3d11::Buffer mPointSpriteVertexBuffer; - d3d11::Buffer mPointSpriteIndexBuffer; -}; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_INPUTLAYOUTCACHE_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/NativeWindow11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/NativeWindow11.h deleted file mode 100644 index ab234d4450..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/NativeWindow11.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// NativeWindow11.h: Defines NativeWindow11, a class for managing and performing operations on an -// EGLNativeWindowType for the D3D11 renderer. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_NATIVEWINDOW11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_NATIVEWINDOW11_H_ - -#include "common/debug.h" -#include "common/platform.h" - -#include "libANGLE/Config.h" -#include "libANGLE/renderer/d3d/NativeWindowD3D.h" - -namespace rx -{ - -class NativeWindow11 : public NativeWindowD3D -{ - public: - NativeWindow11(EGLNativeWindowType window) : NativeWindowD3D(window) {} - - virtual HRESULT createSwapChain(ID3D11Device *device, - IDXGIFactory *factory, - DXGI_FORMAT format, - UINT width, - UINT height, - UINT samples, - IDXGISwapChain **swapChain) = 0; - virtual void commitChange() = 0; -}; -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_NATIVEWINDOW11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/PixelTransfer11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/PixelTransfer11.cpp deleted file mode 100644 index 7d7ecb0976..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/PixelTransfer11.cpp +++ /dev/null @@ -1,258 +0,0 @@ -// -// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// PixelTransfer11.cpp: -// Implementation for buffer-to-texture and texture-to-buffer copies. -// Used to implement pixel transfers from unpack and to pack buffers. -// - -#include "libANGLE/renderer/d3d/d3d11/PixelTransfer11.h" - -#include "libANGLE/Buffer.h" -#include "libANGLE/Context.h" -#include "libANGLE/formatutils.h" -#include "libANGLE/renderer/d3d/d3d11/Buffer11.h" -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h" -#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h" -#include "libANGLE/renderer/d3d/d3d11/TextureStorage11.h" -#include "libANGLE/Texture.h" - -// Precompiled shaders -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/buffertotexture11_gs.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/buffertotexture11_ps_4f.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/buffertotexture11_ps_4i.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/buffertotexture11_ps_4ui.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/buffertotexture11_vs.h" - -namespace rx -{ - -PixelTransfer11::PixelTransfer11(Renderer11 *renderer) - : mRenderer(renderer), - mResourcesLoaded(false), - mBufferToTextureVS(), - mBufferToTextureGS(), - mParamsConstantBuffer(), - mCopyRasterizerState(), - mCopyDepthStencilState() -{ -} - -PixelTransfer11::~PixelTransfer11() -{ -} - -gl::Error PixelTransfer11::loadResources() -{ - if (mResourcesLoaded) - { - return gl::NoError(); - } - - D3D11_RASTERIZER_DESC rasterDesc; - rasterDesc.FillMode = D3D11_FILL_SOLID; - rasterDesc.CullMode = D3D11_CULL_NONE; - rasterDesc.FrontCounterClockwise = FALSE; - rasterDesc.DepthBias = 0; - rasterDesc.SlopeScaledDepthBias = 0.0f; - rasterDesc.DepthBiasClamp = 0.0f; - rasterDesc.DepthClipEnable = TRUE; - rasterDesc.ScissorEnable = FALSE; - rasterDesc.MultisampleEnable = FALSE; - rasterDesc.AntialiasedLineEnable = FALSE; - - ANGLE_TRY(mRenderer->allocateResource(rasterDesc, &mCopyRasterizerState)); - - D3D11_DEPTH_STENCIL_DESC depthStencilDesc; - depthStencilDesc.DepthEnable = true; - depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; - depthStencilDesc.DepthFunc = D3D11_COMPARISON_ALWAYS; - depthStencilDesc.StencilEnable = FALSE; - depthStencilDesc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK; - depthStencilDesc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK; - depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; - depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; - depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; - depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; - - ANGLE_TRY(mRenderer->allocateResource(depthStencilDesc, &mCopyDepthStencilState)); - - D3D11_BUFFER_DESC constantBufferDesc = { 0 }; - constantBufferDesc.ByteWidth = roundUp<UINT>(sizeof(CopyShaderParams), 32u); - constantBufferDesc.Usage = D3D11_USAGE_DYNAMIC; - constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - constantBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - constantBufferDesc.MiscFlags = 0; - constantBufferDesc.StructureByteStride = 0; - - ANGLE_TRY(mRenderer->allocateResource(constantBufferDesc, &mParamsConstantBuffer)); - mParamsConstantBuffer.setDebugName("PixelTransfer11 constant buffer"); - - // init shaders - ANGLE_TRY(mRenderer->allocateResource(ShaderData(g_VS_BufferToTexture), &mBufferToTextureVS)); - mBufferToTextureVS.setDebugName("BufferToTexture VS"); - - ANGLE_TRY(mRenderer->allocateResource(ShaderData(g_GS_BufferToTexture), &mBufferToTextureGS)); - mBufferToTextureGS.setDebugName("BufferToTexture GS"); - - ANGLE_TRY(buildShaderMap()); - - StructZero(&mParamsData); - - mResourcesLoaded = true; - - return gl::NoError(); -} - -void PixelTransfer11::setBufferToTextureCopyParams(const gl::Box &destArea, const gl::Extents &destSize, GLenum internalFormat, - const gl::PixelUnpackState &unpack, unsigned int offset, CopyShaderParams *parametersOut) -{ - StructZero(parametersOut); - - float texelCenterX = 0.5f / static_cast<float>(destSize.width - 1); - float texelCenterY = 0.5f / static_cast<float>(destSize.height - 1); - - unsigned int bytesPerPixel = gl::GetSizedInternalFormatInfo(internalFormat).pixelBytes; - unsigned int alignmentBytes = static_cast<unsigned int>(unpack.alignment); - unsigned int alignmentPixels = (alignmentBytes <= bytesPerPixel ? 1 : alignmentBytes / bytesPerPixel); - - parametersOut->FirstPixelOffset = offset / bytesPerPixel; - parametersOut->PixelsPerRow = static_cast<unsigned int>((unpack.rowLength > 0) ? unpack.rowLength : destArea.width); - parametersOut->RowStride = roundUp(parametersOut->PixelsPerRow, alignmentPixels); - parametersOut->RowsPerSlice = static_cast<unsigned int>(destArea.height); - parametersOut->PositionOffset[0] = texelCenterX + (destArea.x / float(destSize.width)) * 2.0f - 1.0f; - parametersOut->PositionOffset[1] = texelCenterY + ((destSize.height - destArea.y - 1) / float(destSize.height)) * 2.0f - 1.0f; - parametersOut->PositionScale[0] = 2.0f / static_cast<float>(destSize.width); - parametersOut->PositionScale[1] = -2.0f / static_cast<float>(destSize.height); - parametersOut->FirstSlice = destArea.z; -} - -gl::Error PixelTransfer11::copyBufferToTexture(const gl::Context *context, - const gl::PixelUnpackState &unpack, - unsigned int offset, - RenderTargetD3D *destRenderTarget, - GLenum destinationFormat, - GLenum sourcePixelsType, - const gl::Box &destArea) -{ - ANGLE_TRY(loadResources()); - - gl::Extents destSize = destRenderTarget->getExtents(); - - ASSERT(destArea.x >= 0 && destArea.x + destArea.width <= destSize.width && - destArea.y >= 0 && destArea.y + destArea.height <= destSize.height && - destArea.z >= 0 && destArea.z + destArea.depth <= destSize.depth ); - - const gl::Buffer &sourceBuffer = - *context->getGLState().getTargetBuffer(gl::BufferBinding::PixelUnpack); - - ASSERT(mRenderer->supportsFastCopyBufferToTexture(destinationFormat)); - - const d3d11::PixelShader *pixelShader = findBufferToTexturePS(destinationFormat); - ASSERT(pixelShader); - - // The SRV must be in the proper read format, which may be different from the destination format - // EG: for half float data, we can load full precision floats with implicit conversion - GLenum unsizedFormat = gl::GetUnsizedFormat(destinationFormat); - const gl::InternalFormat &sourceglFormatInfo = - gl::GetInternalFormatInfo(unsizedFormat, sourcePixelsType); - - const d3d11::Format &sourceFormatInfo = d3d11::Format::Get( - sourceglFormatInfo.sizedInternalFormat, mRenderer->getRenderer11DeviceCaps()); - DXGI_FORMAT srvFormat = sourceFormatInfo.srvFormat; - ASSERT(srvFormat != DXGI_FORMAT_UNKNOWN); - Buffer11 *bufferStorage11 = GetAs<Buffer11>(sourceBuffer.getImplementation()); - const d3d11::ShaderResourceView *bufferSRV = nullptr; - ANGLE_TRY_RESULT(bufferStorage11->getSRV(context, srvFormat), bufferSRV); - ASSERT(bufferSRV != nullptr); - - const d3d11::RenderTargetView &textureRTV = - GetAs<RenderTarget11>(destRenderTarget)->getRenderTargetView(); - ASSERT(textureRTV.valid()); - - CopyShaderParams shaderParams; - setBufferToTextureCopyParams(destArea, destSize, sourceglFormatInfo.sizedInternalFormat, unpack, - offset, &shaderParams); - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - // Are we doing a 2D or 3D copy? - const auto *geometryShader = ((destSize.depth > 1) ? &mBufferToTextureGS : nullptr); - StateManager11 *stateManager = mRenderer->getStateManager(); - - stateManager->setDrawShaders(&mBufferToTextureVS, geometryShader, pixelShader); - stateManager->setShaderResource(gl::SAMPLER_PIXEL, 0, bufferSRV); - stateManager->setInputLayout(nullptr); - stateManager->setPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); - - stateManager->setSingleVertexBuffer(nullptr, 0, 0); - stateManager->setSimpleBlendState(nullptr); - stateManager->setDepthStencilState(&mCopyDepthStencilState, 0xFFFFFFFF); - stateManager->setRasterizerState(&mCopyRasterizerState); - - stateManager->setRenderTarget(textureRTV.get(), nullptr); - - if (!StructEquals(mParamsData, shaderParams)) - { - d3d11::SetBufferData(deviceContext, mParamsConstantBuffer.get(), shaderParams); - mParamsData = shaderParams; - } - - stateManager->setVertexConstantBuffer(0, &mParamsConstantBuffer); - - // Set the viewport - stateManager->setSimpleViewport(destSize); - - UINT numPixels = (destArea.width * destArea.height * destArea.depth); - deviceContext->Draw(numPixels, 0); - - return gl::NoError(); -} - -gl::Error PixelTransfer11::buildShaderMap() -{ - d3d11::PixelShader bufferToTextureFloat; - d3d11::PixelShader bufferToTextureInt; - d3d11::PixelShader bufferToTextureUint; - - ANGLE_TRY( - mRenderer->allocateResource(ShaderData(g_PS_BufferToTexture_4F), &bufferToTextureFloat)); - ANGLE_TRY( - mRenderer->allocateResource(ShaderData(g_PS_BufferToTexture_4I), &bufferToTextureInt)); - ANGLE_TRY( - mRenderer->allocateResource(ShaderData(g_PS_BufferToTexture_4UI), &bufferToTextureUint)); - - bufferToTextureFloat.setDebugName("BufferToTexture RGBA ps"); - bufferToTextureInt.setDebugName("BufferToTexture RGBA-I ps"); - bufferToTextureUint.setDebugName("BufferToTexture RGBA-UI ps"); - - mBufferToTexturePSMap[GL_FLOAT] = std::move(bufferToTextureFloat); - mBufferToTexturePSMap[GL_INT] = std::move(bufferToTextureInt); - mBufferToTexturePSMap[GL_UNSIGNED_INT] = std::move(bufferToTextureUint); - - return gl::NoError(); -} - -const d3d11::PixelShader *PixelTransfer11::findBufferToTexturePS(GLenum internalFormat) const -{ - GLenum componentType = gl::GetSizedInternalFormatInfo(internalFormat).componentType; - if (componentType == GL_SIGNED_NORMALIZED || componentType == GL_UNSIGNED_NORMALIZED) - { - componentType = GL_FLOAT; - } - - auto shaderMapIt = mBufferToTexturePSMap.find(componentType); - return (shaderMapIt == mBufferToTexturePSMap.end() ? nullptr : &shaderMapIt->second); -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/PixelTransfer11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/PixelTransfer11.h deleted file mode 100644 index a93544247e..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/PixelTransfer11.h +++ /dev/null @@ -1,93 +0,0 @@ -// -// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// PixelTransfer11.h: -// Buffer-to-Texture and Texture-to-Buffer data transfers. -// Used to implement pixel unpack and pixel pack buffers in ES3. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_PIXELTRANSFER11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_PIXELTRANSFER11_H_ - -#include <GLES2/gl2.h> - -#include <map> - -#include "common/platform.h" -#include "libANGLE/Error.h" -#include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h" - -namespace gl -{ - -class Buffer; -struct Box; -struct Extents; -struct PixelUnpackState; - -} - -namespace rx -{ -class Renderer11; -class RenderTargetD3D; - -class PixelTransfer11 -{ - public: - explicit PixelTransfer11(Renderer11 *renderer); - ~PixelTransfer11(); - - // unpack: the source buffer is stored in the unpack state, and buffer strides - // offset: the start of the data within the unpack buffer - // destRenderTarget: individual slice/layer of a target texture - // destinationFormat/sourcePixelsType: determines shaders + shader parameters - // destArea: the sub-section of destRenderTarget to copy to - gl::Error copyBufferToTexture(const gl::Context *context, - const gl::PixelUnpackState &unpack, - unsigned int offset, - RenderTargetD3D *destRenderTarget, - GLenum destinationFormat, - GLenum sourcePixelsType, - const gl::Box &destArea); - - private: - - struct CopyShaderParams - { - unsigned int FirstPixelOffset; - unsigned int PixelsPerRow; - unsigned int RowStride; - unsigned int RowsPerSlice; - float PositionOffset[2]; - float PositionScale[2]; - int TexLocationOffset[2]; - int TexLocationScale[2]; - unsigned int FirstSlice; - }; - - static void setBufferToTextureCopyParams(const gl::Box &destArea, const gl::Extents &destSize, GLenum internalFormat, - const gl::PixelUnpackState &unpack, unsigned int offset, CopyShaderParams *parametersOut); - - gl::Error loadResources(); - gl::Error buildShaderMap(); - const d3d11::PixelShader *findBufferToTexturePS(GLenum internalFormat) const; - - Renderer11 *mRenderer; - - bool mResourcesLoaded; - std::map<GLenum, d3d11::PixelShader> mBufferToTexturePSMap; - d3d11::VertexShader mBufferToTextureVS; - d3d11::GeometryShader mBufferToTextureGS; - d3d11::Buffer mParamsConstantBuffer; - CopyShaderParams mParamsData; - - d3d11::RasterizerState mCopyRasterizerState; - d3d11::DepthStencilState mCopyDepthStencilState; -}; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_PIXELTRANSFER11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ProgramPipeline11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ProgramPipeline11.cpp deleted file mode 100644 index c9554431e5..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ProgramPipeline11.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// -// Copyright 2017 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// ProgramPipelineNULL.cpp: -// Implements the class methods for ProgramPipeline11. -// - -#include "libANGLE/renderer/d3d/d3d11/ProgramPipeline11.h" - -namespace rx -{ - -ProgramPipeline11::ProgramPipeline11(const gl::ProgramPipelineState &state) - : ProgramPipelineImpl(state) -{ -} - -ProgramPipeline11::~ProgramPipeline11() -{ -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ProgramPipeline11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ProgramPipeline11.h deleted file mode 100644 index cf838eec05..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ProgramPipeline11.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// Copyright 2017 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// ProgramPipeline11.h: -// Defines the class interface for ProgramPipeline11, implementing ProgramPipelineImpl. -// - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_PROGRAMPIPELINE11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_PROGRAMPIPELINE11_H_ - -#include "libANGLE/renderer/ProgramPipelineImpl.h" - -namespace rx -{ - -class ProgramPipeline11 : public ProgramPipelineImpl -{ - public: - ProgramPipeline11(const gl::ProgramPipelineState &state); - ~ProgramPipeline11() override; -}; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_PROGRAMPIPELINE11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Query11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Query11.cpp deleted file mode 100644 index 66b9476e7f..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Query11.cpp +++ /dev/null @@ -1,375 +0,0 @@ -// -// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Query11.cpp: Defines the rx::Query11 class which implements rx::QueryImpl. - -#include "libANGLE/renderer/d3d/d3d11/Query11.h" - -#include <GLES2/gl2ext.h> - -#include "common/utilities.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -namespace -{ - -GLuint64 MergeQueryResults(GLenum type, GLuint64 currentResult, GLuint64 newResult) -{ - switch (type) - { - case GL_ANY_SAMPLES_PASSED: - case GL_ANY_SAMPLES_PASSED_CONSERVATIVE: - return (currentResult == GL_TRUE || newResult == GL_TRUE) ? GL_TRUE : GL_FALSE; - - case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: - return currentResult + newResult; - - case GL_TIME_ELAPSED_EXT: - return currentResult + newResult; - - case GL_TIMESTAMP_EXT: - return newResult; - - case GL_COMMANDS_COMPLETED_CHROMIUM: - return newResult; - - default: - UNREACHABLE(); - return 0; - } -} - -} // anonymous namespace - -namespace rx -{ - -Query11::QueryState::QueryState() : query(), beginTimestamp(), endTimestamp(), finished(false) -{ -} - -Query11::QueryState::~QueryState() -{ -} - -Query11::Query11(Renderer11 *renderer, GLenum type) - : QueryImpl(type), mResult(0), mResultSum(0), mRenderer(renderer) -{ - mActiveQuery = std::unique_ptr<QueryState>(new QueryState()); -} - -Query11::~Query11() -{ - mRenderer->getStateManager()->onDeleteQueryObject(this); -} - -gl::Error Query11::begin() -{ - mResultSum = 0; - mRenderer->getStateManager()->onBeginQuery(this); - return resume(); -} - -gl::Error Query11::end() -{ - return pause(); -} - -gl::Error Query11::queryCounter() -{ - // This doesn't do anything for D3D11 as we don't support timestamps - ASSERT(getType() == GL_TIMESTAMP_EXT); - mResultSum = 0; - mPendingQueries.push_back(std::unique_ptr<QueryState>(new QueryState())); - return gl::NoError(); -} - -template <typename T> -gl::Error Query11::getResultBase(T *params) -{ - ASSERT(!mActiveQuery->query.valid()); - ANGLE_TRY(flush(true)); - ASSERT(mPendingQueries.empty()); - *params = static_cast<T>(mResultSum); - - return gl::NoError(); -} - -gl::Error Query11::getResult(GLint *params) -{ - return getResultBase(params); -} - -gl::Error Query11::getResult(GLuint *params) -{ - return getResultBase(params); -} - -gl::Error Query11::getResult(GLint64 *params) -{ - return getResultBase(params); -} - -gl::Error Query11::getResult(GLuint64 *params) -{ - return getResultBase(params); -} - -gl::Error Query11::isResultAvailable(bool *available) -{ - ANGLE_TRY(flush(false)); - - *available = mPendingQueries.empty(); - return gl::NoError(); -} - -gl::Error Query11::pause() -{ - if (mActiveQuery->query.valid()) - { - ID3D11DeviceContext *context = mRenderer->getDeviceContext(); - GLenum queryType = getType(); - - // If we are doing time elapsed query the end timestamp - if (queryType == GL_TIME_ELAPSED_EXT) - { - context->End(mActiveQuery->endTimestamp.get()); - } - - context->End(mActiveQuery->query.get()); - - mPendingQueries.push_back(std::move(mActiveQuery)); - mActiveQuery = std::unique_ptr<QueryState>(new QueryState()); - } - - return flush(false); -} - -gl::Error Query11::resume() -{ - if (!mActiveQuery->query.valid()) - { - ANGLE_TRY(flush(false)); - - GLenum queryType = getType(); - D3D11_QUERY d3dQueryType = gl_d3d11::ConvertQueryType(queryType); - - D3D11_QUERY_DESC queryDesc; - queryDesc.Query = d3dQueryType; - queryDesc.MiscFlags = 0; - - ANGLE_TRY(mRenderer->allocateResource(queryDesc, &mActiveQuery->query)); - - // If we are doing time elapsed we also need a query to actually query the timestamp - if (queryType == GL_TIME_ELAPSED_EXT) - { - D3D11_QUERY_DESC desc; - desc.Query = D3D11_QUERY_TIMESTAMP; - desc.MiscFlags = 0; - - ANGLE_TRY(mRenderer->allocateResource(desc, &mActiveQuery->beginTimestamp)); - ANGLE_TRY(mRenderer->allocateResource(desc, &mActiveQuery->endTimestamp)); - } - - ID3D11DeviceContext *context = mRenderer->getDeviceContext(); - - if (d3dQueryType != D3D11_QUERY_EVENT) - { - context->Begin(mActiveQuery->query.get()); - } - - // If we are doing time elapsed, query the begin timestamp - if (queryType == GL_TIME_ELAPSED_EXT) - { - context->End(mActiveQuery->beginTimestamp.get()); - } - } - - return gl::NoError(); -} - -gl::Error Query11::flush(bool force) -{ - while (!mPendingQueries.empty()) - { - QueryState *query = mPendingQueries.front().get(); - - do - { - ANGLE_TRY(testQuery(query)); - if (!query->finished && !force) - { - return gl::NoError(); - } - } while (!query->finished); - - mResultSum = MergeQueryResults(getType(), mResultSum, mResult); - mPendingQueries.pop_front(); - } - - return gl::NoError(); -} - -gl::Error Query11::testQuery(QueryState *queryState) -{ - if (!queryState->finished) - { - ID3D11DeviceContext *context = mRenderer->getDeviceContext(); - switch (getType()) - { - case GL_ANY_SAMPLES_PASSED_EXT: - case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT: - { - ASSERT(queryState->query.valid()); - UINT64 numPixels = 0; - HRESULT result = - context->GetData(queryState->query.get(), &numPixels, sizeof(numPixels), 0); - if (FAILED(result)) - { - return gl::OutOfMemory() - << "Failed to get the data of an internal query, " << gl::FmtHR(result); - } - - if (result == S_OK) - { - queryState->finished = true; - mResult = (numPixels > 0) ? GL_TRUE : GL_FALSE; - } - } - break; - - case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: - { - ASSERT(queryState->query.valid()); - D3D11_QUERY_DATA_SO_STATISTICS soStats = {0}; - HRESULT result = - context->GetData(queryState->query.get(), &soStats, sizeof(soStats), 0); - if (FAILED(result)) - { - return gl::OutOfMemory() - << "Failed to get the data of an internal query, " << gl::FmtHR(result); - } - - if (result == S_OK) - { - queryState->finished = true; - mResult = static_cast<GLuint64>(soStats.NumPrimitivesWritten); - } - } - break; - - case GL_TIME_ELAPSED_EXT: - { - ASSERT(queryState->query.valid()); - ASSERT(queryState->beginTimestamp.valid()); - ASSERT(queryState->endTimestamp.valid()); - D3D11_QUERY_DATA_TIMESTAMP_DISJOINT timeStats = {0}; - HRESULT result = - context->GetData(queryState->query.get(), &timeStats, sizeof(timeStats), 0); - if (FAILED(result)) - { - return gl::OutOfMemory() - << "Failed to get the data of an internal query, " << gl::FmtHR(result); - } - - if (result == S_OK) - { - UINT64 beginTime = 0; - HRESULT beginRes = context->GetData(queryState->beginTimestamp.get(), - &beginTime, sizeof(UINT64), 0); - if (FAILED(beginRes)) - { - return gl::OutOfMemory() << "Failed to get the data of an internal query, " - << gl::FmtHR(beginRes); - } - UINT64 endTime = 0; - HRESULT endRes = context->GetData(queryState->endTimestamp.get(), &endTime, - sizeof(UINT64), 0); - if (FAILED(endRes)) - { - return gl::OutOfMemory() << "Failed to get the data of an internal query, " - << gl::FmtHR(endRes); - } - - if (beginRes == S_OK && endRes == S_OK) - { - queryState->finished = true; - if (timeStats.Disjoint) - { - mRenderer->setGPUDisjoint(); - } - static_assert(sizeof(UINT64) == sizeof(unsigned long long), - "D3D UINT64 isn't 64 bits"); - - angle::CheckedNumeric<UINT64> checkedTime(endTime); - checkedTime -= beginTime; - checkedTime *= 1000000000ull; - checkedTime /= timeStats.Frequency; - if (checkedTime.IsValid()) - { - mResult = checkedTime.ValueOrDie(); - } - else - { - mResult = std::numeric_limits<GLuint64>::max() / timeStats.Frequency; - // If an overflow does somehow occur, there is no way the elapsed time - // is accurate, so we generate a disjoint event - mRenderer->setGPUDisjoint(); - } - } - } - } - break; - - case GL_TIMESTAMP_EXT: - { - // D3D11 doesn't support GL timestamp queries as D3D timestamps are not guaranteed - // to have any sort of continuity outside of a disjoint timestamp query block, which - // GL depends on - ASSERT(!queryState->query.valid()); - mResult = 0; - queryState->finished = true; - } - break; - - case GL_COMMANDS_COMPLETED_CHROMIUM: - { - ASSERT(queryState->query.valid()); - BOOL completed = 0; - HRESULT result = - context->GetData(queryState->query.get(), &completed, sizeof(completed), 0); - if (FAILED(result)) - { - return gl::OutOfMemory() - << "Failed to get the data of an internal query, " << gl::FmtHR(result); - } - - if (result == S_OK) - { - queryState->finished = true; - ASSERT(completed == TRUE); - mResult = (completed == TRUE) ? GL_TRUE : GL_FALSE; - } - } - break; - - default: - UNREACHABLE(); - break; - } - - if (!queryState->finished && mRenderer->testDeviceLost()) - { - mRenderer->notifyDeviceLost(); - return gl::OutOfMemory() << "Failed to test get query result, device is lost."; - } - } - - return gl::NoError(); -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Query11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Query11.h deleted file mode 100644 index a88a8892aa..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Query11.h +++ /dev/null @@ -1,68 +0,0 @@ -// -// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Query11.h: Defines the rx::Query11 class which implements rx::QueryImpl. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_QUERY11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_QUERY11_H_ - -#include <deque> - -#include "libANGLE/renderer/QueryImpl.h" -#include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h" - -namespace rx -{ -class Renderer11; - -class Query11 : public QueryImpl -{ - public: - Query11(Renderer11 *renderer, GLenum type); - ~Query11() override; - - gl::Error begin() override; - gl::Error end() override; - gl::Error queryCounter() override; - gl::Error getResult(GLint *params) override; - gl::Error getResult(GLuint *params) override; - gl::Error getResult(GLint64 *params) override; - gl::Error getResult(GLuint64 *params) override; - gl::Error isResultAvailable(bool *available) override; - - gl::Error pause(); - gl::Error resume(); - - private: - struct QueryState final : private angle::NonCopyable - { - QueryState(); - ~QueryState(); - - d3d11::Query query; - d3d11::Query beginTimestamp; - d3d11::Query endTimestamp; - bool finished; - }; - - gl::Error flush(bool force); - gl::Error testQuery(QueryState *queryState); - - template <typename T> - gl::Error getResultBase(T *params); - - GLuint64 mResult; - GLuint64 mResultSum; - - Renderer11 *mRenderer; - - std::unique_ptr<QueryState> mActiveQuery; - std::deque<std::unique_ptr<QueryState>> mPendingQueries; -}; - -} - -#endif // LIBANGLE_RENDERER_D3D_D3D11_QUERY11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.cpp deleted file mode 100644 index 5b85196c2e..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.cpp +++ /dev/null @@ -1,273 +0,0 @@ -// -// Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// RenderStateCache.cpp: Defines rx::RenderStateCache, a cache of Direct3D render -// state objects. - -#include "libANGLE/renderer/d3d/d3d11/RenderStateCache.h" - -#include <float.h> - -#include "common/debug.h" -#include "libANGLE/Framebuffer.h" -#include "libANGLE/FramebufferAttachment.h" -#include "libANGLE/renderer/d3d/FramebufferD3D.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" - -namespace rx -{ -using namespace gl_d3d11; - -RenderStateCache::RenderStateCache() - : mBlendStateCache(kMaxStates), - mRasterizerStateCache(kMaxStates), - mDepthStencilStateCache(kMaxStates), - mSamplerStateCache(kMaxStates) -{ -} - -RenderStateCache::~RenderStateCache() -{ -} - -void RenderStateCache::clear() -{ - mBlendStateCache.Clear(); - mRasterizerStateCache.Clear(); - mDepthStencilStateCache.Clear(); - mSamplerStateCache.Clear(); -} - -// static -d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Context *context, - const gl::Framebuffer *framebuffer, - const gl::BlendState &blendState) -{ - d3d11::BlendStateKey key; - FramebufferD3D *framebufferD3D = GetImplAs<FramebufferD3D>(framebuffer); - const gl::AttachmentList &colorbuffers = framebufferD3D->getColorAttachmentsForRender(context); - const UINT8 blendStateMask = - gl_d3d11::ConvertColorMask(blendState.colorMaskRed, blendState.colorMaskGreen, - blendState.colorMaskBlue, blendState.colorMaskAlpha); - - key.blendState = blendState; - - for (size_t i = 0; i < colorbuffers.size(); i++) - { - const gl::FramebufferAttachment *attachment = colorbuffers[i]; - - if (attachment) - { - key.rtvMax = static_cast<uint32_t>(i) + 1; - key.rtvMasks[i] = - (gl_d3d11::GetColorMask(*attachment->getFormat().info)) & blendStateMask; - } - } - - return key; -} - -gl::Error RenderStateCache::getBlendState(Renderer11 *renderer, - const d3d11::BlendStateKey &key, - const d3d11::BlendState **outBlendState) -{ - auto keyIter = mBlendStateCache.Get(key); - if (keyIter != mBlendStateCache.end()) - { - *outBlendState = &keyIter->second; - return gl::NoError(); - } - - TrimCache(kMaxStates, kGCLimit, "blend state", &mBlendStateCache); - - // Create a new blend state and insert it into the cache - D3D11_BLEND_DESC blendDesc; - D3D11_RENDER_TARGET_BLEND_DESC &rtDesc0 = blendDesc.RenderTarget[0]; - const gl::BlendState &blendState = key.blendState; - - blendDesc.AlphaToCoverageEnable = blendState.sampleAlphaToCoverage; - blendDesc.IndependentBlendEnable = key.rtvMax > 1 ? TRUE : FALSE; - - rtDesc0 = {}; - - if (blendState.blend) - { - rtDesc0.BlendEnable = true; - rtDesc0.SrcBlend = gl_d3d11::ConvertBlendFunc(blendState.sourceBlendRGB, false); - rtDesc0.DestBlend = gl_d3d11::ConvertBlendFunc(blendState.destBlendRGB, false); - rtDesc0.BlendOp = gl_d3d11::ConvertBlendOp(blendState.blendEquationRGB); - rtDesc0.SrcBlendAlpha = gl_d3d11::ConvertBlendFunc(blendState.sourceBlendAlpha, true); - rtDesc0.DestBlendAlpha = gl_d3d11::ConvertBlendFunc(blendState.destBlendAlpha, true); - rtDesc0.BlendOpAlpha = gl_d3d11::ConvertBlendOp(blendState.blendEquationAlpha); - } - - rtDesc0.RenderTargetWriteMask = key.rtvMasks[0]; - - for (unsigned int i = 1; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++) - { - blendDesc.RenderTarget[i] = rtDesc0; - blendDesc.RenderTarget[i].RenderTargetWriteMask = key.rtvMasks[i]; - } - - d3d11::BlendState d3dBlendState; - ANGLE_TRY(renderer->allocateResource(blendDesc, &d3dBlendState)); - const auto &iter = mBlendStateCache.Put(key, std::move(d3dBlendState)); - - *outBlendState = &iter->second; - - return gl::NoError(); -} - -gl::Error RenderStateCache::getRasterizerState(Renderer11 *renderer, - const gl::RasterizerState &rasterState, - bool scissorEnabled, - ID3D11RasterizerState **outRasterizerState) -{ - d3d11::RasterizerStateKey key; - key.rasterizerState = rasterState; - key.scissorEnabled = scissorEnabled ? 1 : 0; - - auto keyIter = mRasterizerStateCache.Get(key); - if (keyIter != mRasterizerStateCache.end()) - { - *outRasterizerState = keyIter->second.get(); - return gl::NoError(); - } - - TrimCache(kMaxStates, kGCLimit, "rasterizer state", &mRasterizerStateCache); - - D3D11_CULL_MODE cullMode = - gl_d3d11::ConvertCullMode(rasterState.cullFace, rasterState.cullMode); - - // Disable culling if drawing points - if (rasterState.pointDrawMode) - { - cullMode = D3D11_CULL_NONE; - } - - D3D11_RASTERIZER_DESC rasterDesc; - rasterDesc.FillMode = D3D11_FILL_SOLID; - rasterDesc.CullMode = cullMode; - rasterDesc.FrontCounterClockwise = (rasterState.frontFace == GL_CCW) ? FALSE : TRUE; - rasterDesc.DepthBiasClamp = 0.0f; // MSDN documentation of DepthBiasClamp implies a value of - // zero will preform no clamping, must be tested though. - rasterDesc.DepthClipEnable = TRUE; - rasterDesc.ScissorEnable = scissorEnabled ? TRUE : FALSE; - rasterDesc.MultisampleEnable = rasterState.multiSample; - rasterDesc.AntialiasedLineEnable = FALSE; - - if (rasterState.polygonOffsetFill) - { - rasterDesc.SlopeScaledDepthBias = rasterState.polygonOffsetFactor; - rasterDesc.DepthBias = (INT)rasterState.polygonOffsetUnits; - } - else - { - rasterDesc.SlopeScaledDepthBias = 0.0f; - rasterDesc.DepthBias = 0; - } - - d3d11::RasterizerState dx11RasterizerState; - ANGLE_TRY(renderer->allocateResource(rasterDesc, &dx11RasterizerState)); - *outRasterizerState = dx11RasterizerState.get(); - mRasterizerStateCache.Put(key, std::move(dx11RasterizerState)); - - return gl::NoError(); -} - -gl::Error RenderStateCache::getDepthStencilState(Renderer11 *renderer, - const gl::DepthStencilState &glState, - const d3d11::DepthStencilState **outDSState) -{ - auto keyIter = mDepthStencilStateCache.Get(glState); - if (keyIter != mDepthStencilStateCache.end()) - { - *outDSState = &keyIter->second; - return gl::NoError(); - } - - TrimCache(kMaxStates, kGCLimit, "depth stencil state", &mDepthStencilStateCache); - - D3D11_DEPTH_STENCIL_DESC dsDesc = {0}; - dsDesc.DepthEnable = glState.depthTest ? TRUE : FALSE; - dsDesc.DepthWriteMask = ConvertDepthMask(glState.depthMask); - dsDesc.DepthFunc = ConvertComparison(glState.depthFunc); - dsDesc.StencilEnable = glState.stencilTest ? TRUE : FALSE; - dsDesc.StencilReadMask = ConvertStencilMask(glState.stencilMask); - dsDesc.StencilWriteMask = ConvertStencilMask(glState.stencilWritemask); - dsDesc.FrontFace.StencilFailOp = ConvertStencilOp(glState.stencilFail); - dsDesc.FrontFace.StencilDepthFailOp = ConvertStencilOp(glState.stencilPassDepthFail); - dsDesc.FrontFace.StencilPassOp = ConvertStencilOp(glState.stencilPassDepthPass); - dsDesc.FrontFace.StencilFunc = ConvertComparison(glState.stencilFunc); - dsDesc.BackFace.StencilFailOp = ConvertStencilOp(glState.stencilBackFail); - dsDesc.BackFace.StencilDepthFailOp = ConvertStencilOp(glState.stencilBackPassDepthFail); - dsDesc.BackFace.StencilPassOp = ConvertStencilOp(glState.stencilBackPassDepthPass); - dsDesc.BackFace.StencilFunc = ConvertComparison(glState.stencilBackFunc); - - d3d11::DepthStencilState dx11DepthStencilState; - ANGLE_TRY(renderer->allocateResource(dsDesc, &dx11DepthStencilState)); - const auto &iter = mDepthStencilStateCache.Put(glState, std::move(dx11DepthStencilState)); - - *outDSState = &iter->second; - - return gl::NoError(); -} - -gl::Error RenderStateCache::getSamplerState(Renderer11 *renderer, - const gl::SamplerState &samplerState, - ID3D11SamplerState **outSamplerState) -{ - auto keyIter = mSamplerStateCache.Get(samplerState); - if (keyIter != mSamplerStateCache.end()) - { - *outSamplerState = keyIter->second.get(); - return gl::NoError(); - } - - TrimCache(kMaxStates, kGCLimit, "sampler state", &mSamplerStateCache); - - const auto &featureLevel = renderer->getRenderer11DeviceCaps().featureLevel; - - D3D11_SAMPLER_DESC samplerDesc; - samplerDesc.Filter = - gl_d3d11::ConvertFilter(samplerState.minFilter, samplerState.magFilter, - samplerState.maxAnisotropy, samplerState.compareMode); - samplerDesc.AddressU = gl_d3d11::ConvertTextureWrap(samplerState.wrapS); - samplerDesc.AddressV = gl_d3d11::ConvertTextureWrap(samplerState.wrapT); - samplerDesc.AddressW = gl_d3d11::ConvertTextureWrap(samplerState.wrapR); - samplerDesc.MipLODBias = 0; - samplerDesc.MaxAnisotropy = - gl_d3d11::ConvertMaxAnisotropy(samplerState.maxAnisotropy, featureLevel); - samplerDesc.ComparisonFunc = gl_d3d11::ConvertComparison(samplerState.compareFunc); - samplerDesc.BorderColor[0] = 0.0f; - samplerDesc.BorderColor[1] = 0.0f; - samplerDesc.BorderColor[2] = 0.0f; - samplerDesc.BorderColor[3] = 0.0f; - samplerDesc.MinLOD = samplerState.minLod; - samplerDesc.MaxLOD = samplerState.maxLod; - - if (featureLevel <= D3D_FEATURE_LEVEL_9_3) - { - // Check that maxLOD is nearly FLT_MAX (1000.0f is the default), since 9_3 doesn't support - // anything other than FLT_MAX. Note that Feature Level 9_* only supports GL ES 2.0, so the - // consumer of ANGLE can't modify the Max LOD themselves. - ASSERT(samplerState.maxLod >= 999.9f); - - // Now just set MaxLOD to FLT_MAX. Other parts of the renderer (e.g. the non-zero max LOD - // workaround) should take account of this. - samplerDesc.MaxLOD = FLT_MAX; - } - - d3d11::SamplerState dx11SamplerState; - ANGLE_TRY(renderer->allocateResource(samplerDesc, &dx11SamplerState)); - *outSamplerState = dx11SamplerState.get(); - mSamplerStateCache.Put(samplerState, std::move(dx11SamplerState)); - - return gl::NoError(); -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.h deleted file mode 100644 index 7501e83fc4..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.h +++ /dev/null @@ -1,123 +0,0 @@ -// -// Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// RenderStateCache.h: Defines rx::RenderStateCache, a cache of Direct3D render -// state objects. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_RENDERSTATECACHE_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_RENDERSTATECACHE_H_ - -#include "common/angleutils.h" -#include "libANGLE/Error.h" -#include "libANGLE/SizedMRUCache.h" -#include "libANGLE/angletypes.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -#include <unordered_map> - -namespace gl -{ -class Framebuffer; -} - -namespace std -{ -template <> -struct hash<rx::d3d11::BlendStateKey> -{ - size_t operator()(const rx::d3d11::BlendStateKey &key) const - { - return angle::ComputeGenericHash(key); - } -}; - -template <> -struct hash<rx::d3d11::RasterizerStateKey> -{ - size_t operator()(const rx::d3d11::RasterizerStateKey &key) const - { - return angle::ComputeGenericHash(key); - } -}; - -template <> -struct hash<gl::DepthStencilState> -{ - size_t operator()(const gl::DepthStencilState &key) const - { - return angle::ComputeGenericHash(key); - } -}; - -template <> -struct hash<gl::SamplerState> -{ - size_t operator()(const gl::SamplerState &key) const { return angle::ComputeGenericHash(key); } -}; -} // namespace std - -namespace rx -{ -class Renderer11; - -class RenderStateCache : angle::NonCopyable -{ - public: - RenderStateCache(); - virtual ~RenderStateCache(); - - void clear(); - - static d3d11::BlendStateKey GetBlendStateKey(const gl::Context *context, - const gl::Framebuffer *framebuffer, - const gl::BlendState &blendState); - gl::Error getBlendState(Renderer11 *renderer, - const d3d11::BlendStateKey &key, - const d3d11::BlendState **outBlendState); - gl::Error getRasterizerState(Renderer11 *renderer, - const gl::RasterizerState &rasterState, - bool scissorEnabled, - ID3D11RasterizerState **outRasterizerState); - gl::Error getDepthStencilState(Renderer11 *renderer, - const gl::DepthStencilState &dsState, - const d3d11::DepthStencilState **outDSState); - gl::Error getSamplerState(Renderer11 *renderer, - const gl::SamplerState &samplerState, - ID3D11SamplerState **outSamplerState); - - private: - // MSDN's documentation of ID3D11Device::CreateBlendState, ID3D11Device::CreateRasterizerState, - // ID3D11Device::CreateDepthStencilState and ID3D11Device::CreateSamplerState claims the maximum - // number of unique states of each type an application can create is 4096 - // TODO(ShahmeerEsmail): Revisit the cache sizes to make sure they are appropriate for most - // scenarios. - static constexpr unsigned int kMaxStates = 4096; - - // The cache tries to clean up this many states at once. - static constexpr unsigned int kGCLimit = 128; - - // Blend state cache - using BlendStateMap = angle::base::HashingMRUCache<d3d11::BlendStateKey, d3d11::BlendState>; - BlendStateMap mBlendStateCache; - - // Rasterizer state cache - using RasterizerStateMap = - angle::base::HashingMRUCache<d3d11::RasterizerStateKey, d3d11::RasterizerState>; - RasterizerStateMap mRasterizerStateCache; - - // Depth stencil state cache - using DepthStencilStateMap = - angle::base::HashingMRUCache<gl::DepthStencilState, d3d11::DepthStencilState>; - DepthStencilStateMap mDepthStencilStateCache; - - // Sample state cache - using SamplerStateMap = angle::base::HashingMRUCache<gl::SamplerState, d3d11::SamplerState>; - SamplerStateMap mSamplerStateCache; -}; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_RENDERSTATECACHE_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderTarget11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderTarget11.cpp deleted file mode 100644 index 594a382a72..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderTarget11.cpp +++ /dev/null @@ -1,405 +0,0 @@ -// -// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// RenderTarget11.cpp: Implements a DX11-specific wrapper for ID3D11View pointers -// retained by Renderbuffers. - -#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h" - -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/renderer/d3d/d3d11/SwapChain11.h" -#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h" - -namespace rx -{ - -namespace -{ -bool GetTextureProperties(ID3D11Resource *resource, unsigned int *mipLevels, unsigned int *samples) -{ - ID3D11Texture1D *texture1D = d3d11::DynamicCastComObject<ID3D11Texture1D>(resource); - if (texture1D) - { - D3D11_TEXTURE1D_DESC texDesc; - texture1D->GetDesc(&texDesc); - SafeRelease(texture1D); - - *mipLevels = texDesc.MipLevels; - *samples = 0; - - return true; - } - - ID3D11Texture2D *texture2D = d3d11::DynamicCastComObject<ID3D11Texture2D>(resource); - if (texture2D) - { - D3D11_TEXTURE2D_DESC texDesc; - texture2D->GetDesc(&texDesc); - SafeRelease(texture2D); - - *mipLevels = texDesc.MipLevels; - *samples = texDesc.SampleDesc.Count > 1 ? texDesc.SampleDesc.Count : 0; - - return true; - } - - ID3D11Texture3D *texture3D = d3d11::DynamicCastComObject<ID3D11Texture3D>(resource); - if (texture3D) - { - D3D11_TEXTURE3D_DESC texDesc; - texture3D->GetDesc(&texDesc); - SafeRelease(texture3D); - - *mipLevels = texDesc.MipLevels; - *samples = 0; - - return true; - } - - return false; -} - -unsigned int GetRTVSubresourceIndex(ID3D11Resource *resource, ID3D11RenderTargetView *view) -{ - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - view->GetDesc(&rtvDesc); - - unsigned int mipSlice = 0; - unsigned int arraySlice = 0; - - switch (rtvDesc.ViewDimension) - { - case D3D11_RTV_DIMENSION_TEXTURE1D: - mipSlice = rtvDesc.Texture1D.MipSlice; - arraySlice = 0; - break; - - case D3D11_RTV_DIMENSION_TEXTURE1DARRAY: - mipSlice = rtvDesc.Texture1DArray.MipSlice; - arraySlice = rtvDesc.Texture1DArray.FirstArraySlice; - break; - - case D3D11_RTV_DIMENSION_TEXTURE2D: - mipSlice = rtvDesc.Texture2D.MipSlice; - arraySlice = 0; - break; - - case D3D11_RTV_DIMENSION_TEXTURE2DARRAY: - mipSlice = rtvDesc.Texture2DArray.MipSlice; - arraySlice = rtvDesc.Texture2DArray.FirstArraySlice; - break; - - case D3D11_RTV_DIMENSION_TEXTURE2DMS: - mipSlice = 0; - arraySlice = 0; - break; - - case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY: - mipSlice = 0; - arraySlice = rtvDesc.Texture2DMSArray.FirstArraySlice; - break; - - case D3D11_RTV_DIMENSION_TEXTURE3D: - mipSlice = rtvDesc.Texture3D.MipSlice; - arraySlice = 0; - break; - - case D3D11_RTV_DIMENSION_UNKNOWN: - case D3D11_RTV_DIMENSION_BUFFER: - UNIMPLEMENTED(); - break; - - default: - UNREACHABLE(); - break; - } - - unsigned int mipLevels, samples; - GetTextureProperties(resource, &mipLevels, &samples); - - return D3D11CalcSubresource(mipSlice, arraySlice, mipLevels); -} - -unsigned int GetDSVSubresourceIndex(ID3D11Resource *resource, ID3D11DepthStencilView *view) -{ - D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; - view->GetDesc(&dsvDesc); - - unsigned int mipSlice = 0; - unsigned int arraySlice = 0; - - switch (dsvDesc.ViewDimension) - { - case D3D11_DSV_DIMENSION_TEXTURE1D: - mipSlice = dsvDesc.Texture1D.MipSlice; - arraySlice = 0; - break; - - case D3D11_DSV_DIMENSION_TEXTURE1DARRAY: - mipSlice = dsvDesc.Texture1DArray.MipSlice; - arraySlice = dsvDesc.Texture1DArray.FirstArraySlice; - break; - - case D3D11_DSV_DIMENSION_TEXTURE2D: - mipSlice = dsvDesc.Texture2D.MipSlice; - arraySlice = 0; - break; - - case D3D11_DSV_DIMENSION_TEXTURE2DARRAY: - mipSlice = dsvDesc.Texture2DArray.MipSlice; - arraySlice = dsvDesc.Texture2DArray.FirstArraySlice; - break; - - case D3D11_DSV_DIMENSION_TEXTURE2DMS: - mipSlice = 0; - arraySlice = 0; - break; - - case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY: - mipSlice = 0; - arraySlice = dsvDesc.Texture2DMSArray.FirstArraySlice; - break; - - case D3D11_DSV_DIMENSION_UNKNOWN: - UNIMPLEMENTED(); - break; - - default: - UNREACHABLE(); - break; - } - - unsigned int mipLevels, samples; - GetTextureProperties(resource, &mipLevels, &samples); - - return D3D11CalcSubresource(mipSlice, arraySlice, mipLevels); -} - -GLenum GetSurfaceRTFormat(bool depth, SwapChain11 *swapChain) -{ - return (depth ? swapChain->getDepthBufferInternalFormat() - : swapChain->getRenderTargetInternalFormat()); -} - -const d3d11::Format &GetSurfaceFormatSet(bool depth, SwapChain11 *swapChain, Renderer11 *renderer) -{ - return d3d11::Format::Get(GetSurfaceRTFormat(depth, swapChain), - renderer->getRenderer11DeviceCaps()); -} - -} // anonymous namespace - -RenderTarget11::RenderTarget11(const d3d11::Format &formatSet) : mFormatSet(formatSet) -{ -} - -RenderTarget11::~RenderTarget11() -{ - ASSERT(mBroadcastChannel.empty()); -} - -void RenderTarget11::signalDirty(const gl::Context *context) -{ - mBroadcastChannel.signal(context); - - // Clear the list. We can't do this in the receiver because it would mutate during iteration. - mBroadcastChannel.reset(); -} - -TextureRenderTarget11::TextureRenderTarget11(d3d11::RenderTargetView &&rtv, - const TextureHelper11 &resource, - const d3d11::SharedSRV &srv, - const d3d11::SharedSRV &blitSRV, - GLenum internalFormat, - const d3d11::Format &formatSet, - GLsizei width, - GLsizei height, - GLsizei depth, - GLsizei samples) - : RenderTarget11(formatSet), - mWidth(width), - mHeight(height), - mDepth(depth), - mInternalFormat(internalFormat), - mSamples(samples), - mSubresourceIndex(0), - mTexture(resource), - mRenderTarget(std::move(rtv)), - mDepthStencil(), - mShaderResource(srv.makeCopy()), - mBlitShaderResource(blitSRV.makeCopy()) -{ - if (mRenderTarget.valid() && mTexture.valid()) - { - mSubresourceIndex = GetRTVSubresourceIndex(mTexture.get(), mRenderTarget.get()); - } - ASSERT(mFormatSet.formatID != angle::Format::ID::NONE || mWidth == 0 || mHeight == 0); -} - -TextureRenderTarget11::TextureRenderTarget11(d3d11::DepthStencilView &&dsv, - const TextureHelper11 &resource, - const d3d11::SharedSRV &srv, - GLenum internalFormat, - const d3d11::Format &formatSet, - GLsizei width, - GLsizei height, - GLsizei depth, - GLsizei samples) - : RenderTarget11(formatSet), - mWidth(width), - mHeight(height), - mDepth(depth), - mInternalFormat(internalFormat), - mSamples(samples), - mSubresourceIndex(0), - mTexture(resource), - mRenderTarget(), - mDepthStencil(std::move(dsv)), - mShaderResource(srv.makeCopy()), - mBlitShaderResource() -{ - if (mDepthStencil.valid() && mTexture.valid()) - { - mSubresourceIndex = GetDSVSubresourceIndex(mTexture.get(), mDepthStencil.get()); - } - ASSERT(mFormatSet.formatID != angle::Format::ID::NONE || mWidth == 0 || mHeight == 0); -} - -TextureRenderTarget11::~TextureRenderTarget11() -{ -} - -const TextureHelper11 &TextureRenderTarget11::getTexture() const -{ - return mTexture; -} - -const d3d11::RenderTargetView &TextureRenderTarget11::getRenderTargetView() const -{ - return mRenderTarget; -} - -const d3d11::DepthStencilView &TextureRenderTarget11::getDepthStencilView() const -{ - return mDepthStencil; -} - -const d3d11::SharedSRV &TextureRenderTarget11::getShaderResourceView() const -{ - return mShaderResource; -} - -const d3d11::SharedSRV &TextureRenderTarget11::getBlitShaderResourceView() const -{ - return mBlitShaderResource; -} - -GLsizei TextureRenderTarget11::getWidth() const -{ - return mWidth; -} - -GLsizei TextureRenderTarget11::getHeight() const -{ - return mHeight; -} - -GLsizei TextureRenderTarget11::getDepth() const -{ - return mDepth; -} - -GLenum TextureRenderTarget11::getInternalFormat() const -{ - return mInternalFormat; -} - -GLsizei TextureRenderTarget11::getSamples() const -{ - return mSamples; -} - -unsigned int TextureRenderTarget11::getSubresourceIndex() const -{ - return mSubresourceIndex; -} - -SurfaceRenderTarget11::SurfaceRenderTarget11(SwapChain11 *swapChain, - Renderer11 *renderer, - bool depth) - : RenderTarget11(GetSurfaceFormatSet(depth, swapChain, renderer)), - mSwapChain(swapChain), - mDepth(depth) -{ - ASSERT(mSwapChain); -} - -SurfaceRenderTarget11::~SurfaceRenderTarget11() -{ -} - -GLsizei SurfaceRenderTarget11::getWidth() const -{ - return mSwapChain->getWidth(); -} - -GLsizei SurfaceRenderTarget11::getHeight() const -{ - return mSwapChain->getHeight(); -} - -GLsizei SurfaceRenderTarget11::getDepth() const -{ - return 1; -} - -GLenum SurfaceRenderTarget11::getInternalFormat() const -{ - return GetSurfaceRTFormat(mDepth, mSwapChain); -} - -GLsizei SurfaceRenderTarget11::getSamples() const -{ - return mSwapChain->getSamples(); -} - -const TextureHelper11 &SurfaceRenderTarget11::getTexture() const -{ - return (mDepth ? mSwapChain->getDepthStencilTexture() : mSwapChain->getOffscreenTexture()); -} - -const d3d11::RenderTargetView &SurfaceRenderTarget11::getRenderTargetView() const -{ - ASSERT(!mDepth); - return mSwapChain->getRenderTarget(); -} - -const d3d11::DepthStencilView &SurfaceRenderTarget11::getDepthStencilView() const -{ - ASSERT(mDepth); - return mSwapChain->getDepthStencil(); -} - -const d3d11::SharedSRV &SurfaceRenderTarget11::getShaderResourceView() const -{ - return (mDepth ? mSwapChain->getDepthStencilShaderResource() - : mSwapChain->getRenderTargetShaderResource()); -} - -const d3d11::SharedSRV &SurfaceRenderTarget11::getBlitShaderResourceView() const -{ - // The SurfaceRenderTargetView format should always be such that the normal SRV works for blits. - return getShaderResourceView(); -} - -unsigned int SurfaceRenderTarget11::getSubresourceIndex() const -{ - return 0; -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderTarget11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderTarget11.h deleted file mode 100644 index db49cac9f5..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderTarget11.h +++ /dev/null @@ -1,131 +0,0 @@ -// -// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// RenderTarget11.h: Defines a DX11-specific wrapper for ID3D11View pointers -// retained by Renderbuffers. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_RENDERTARGET11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_RENDERTARGET11_H_ - -#include "libANGLE/renderer/d3d/RenderTargetD3D.h" -#include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h" - -namespace rx -{ -class SwapChain11; -class Renderer11; - -class RenderTarget11 : public RenderTargetD3D -{ - public: - RenderTarget11(const d3d11::Format &formatSet); - ~RenderTarget11() override; - - virtual const TextureHelper11 &getTexture() const = 0; - virtual const d3d11::RenderTargetView &getRenderTargetView() const = 0; - virtual const d3d11::DepthStencilView &getDepthStencilView() const = 0; - virtual const d3d11::SharedSRV &getShaderResourceView() const = 0; - virtual const d3d11::SharedSRV &getBlitShaderResourceView() const = 0; - - virtual unsigned int getSubresourceIndex() const = 0; - - void signalDirty(const gl::Context *context) override; - OnRenderTargetDirtyChannel *getBroadcastChannel() { return &mBroadcastChannel; } - - const d3d11::Format &getFormatSet() const { return mFormatSet; } - - protected: - OnRenderTargetDirtyChannel mBroadcastChannel; - const d3d11::Format &mFormatSet; -}; - -class TextureRenderTarget11 : public RenderTarget11 -{ - public: - // TextureRenderTarget11 takes ownership of any D3D11 resources it is given and will AddRef them - TextureRenderTarget11(d3d11::RenderTargetView &&rtv, - const TextureHelper11 &resource, - const d3d11::SharedSRV &srv, - const d3d11::SharedSRV &blitSRV, - GLenum internalFormat, - const d3d11::Format &formatSet, - GLsizei width, - GLsizei height, - GLsizei depth, - GLsizei samples); - TextureRenderTarget11(d3d11::DepthStencilView &&dsv, - const TextureHelper11 &resource, - const d3d11::SharedSRV &srv, - GLenum internalFormat, - const d3d11::Format &formatSet, - GLsizei width, - GLsizei height, - GLsizei depth, - GLsizei samples); - ~TextureRenderTarget11() override; - - GLsizei getWidth() const override; - GLsizei getHeight() const override; - GLsizei getDepth() const override; - GLenum getInternalFormat() const override; - GLsizei getSamples() const override; - - const TextureHelper11 &getTexture() const override; - const d3d11::RenderTargetView &getRenderTargetView() const override; - const d3d11::DepthStencilView &getDepthStencilView() const override; - const d3d11::SharedSRV &getShaderResourceView() const override; - const d3d11::SharedSRV &getBlitShaderResourceView() const override; - - unsigned int getSubresourceIndex() const override; - - private: - GLsizei mWidth; - GLsizei mHeight; - GLsizei mDepth; - GLenum mInternalFormat; - GLsizei mSamples; - - unsigned int mSubresourceIndex; - TextureHelper11 mTexture; - d3d11::RenderTargetView mRenderTarget; - d3d11::DepthStencilView mDepthStencil; - d3d11::SharedSRV mShaderResource; - - // Shader resource view to use with internal blit shaders. Not set for depth/stencil render - // targets. - d3d11::SharedSRV mBlitShaderResource; -}; - -class SurfaceRenderTarget11 : public RenderTarget11 -{ - public: - SurfaceRenderTarget11(SwapChain11 *swapChain, Renderer11 *renderer, bool depth); - ~SurfaceRenderTarget11() override; - - GLsizei getWidth() const override; - GLsizei getHeight() const override; - GLsizei getDepth() const override; - GLenum getInternalFormat() const override; - GLsizei getSamples() const override; - - const TextureHelper11 &getTexture() const override; - const d3d11::RenderTargetView &getRenderTargetView() const override; - const d3d11::DepthStencilView &getDepthStencilView() const override; - const d3d11::SharedSRV &getShaderResourceView() const override; - const d3d11::SharedSRV &getBlitShaderResourceView() const override; - - unsigned int getSubresourceIndex() const override; - - private: - SwapChain11 *mSwapChain; - bool mDepth; -}; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_RENDERTARGET11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp deleted file mode 100644 index b0ef9abddc..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp +++ /dev/null @@ -1,4089 +0,0 @@ -// -// Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Renderer11.cpp: Implements a back-end specific class for the D3D11 renderer. - -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" - -#include <EGL/eglext.h> -#include <versionhelpers.h> -#include <sstream> - -#include "common/tls.h" -#include "common/utilities.h" -#include "libANGLE/Buffer.h" -#include "libANGLE/Context.h" -#include "libANGLE/Display.h" -#include "libANGLE/Framebuffer.h" -#include "libANGLE/FramebufferAttachment.h" -#include "libANGLE/Program.h" -#include "libANGLE/State.h" -#include "libANGLE/Surface.h" -#include "libANGLE/formatutils.h" -#include "libANGLE/histogram_macros.h" -#include "libANGLE/renderer/d3d/CompilerD3D.h" -#include "libANGLE/renderer/d3d/DeviceD3D.h" -#include "libANGLE/renderer/d3d/DisplayD3D.h" -#include "libANGLE/renderer/d3d/FramebufferD3D.h" -#include "libANGLE/renderer/d3d/IndexDataManager.h" -#include "libANGLE/renderer/d3d/ProgramD3D.h" -#include "libANGLE/renderer/d3d/RenderbufferD3D.h" -#include "libANGLE/renderer/d3d/ShaderD3D.h" -#include "libANGLE/renderer/d3d/SurfaceD3D.h" -#include "libANGLE/renderer/d3d/TextureD3D.h" -#include "libANGLE/renderer/d3d/VertexDataManager.h" -#include "libANGLE/renderer/d3d/d3d11/Blit11.h" -#include "libANGLE/renderer/d3d/d3d11/Buffer11.h" -#include "libANGLE/renderer/d3d/d3d11/Clear11.h" -#include "libANGLE/renderer/d3d/d3d11/Context11.h" -#include "libANGLE/renderer/d3d/d3d11/Fence11.h" -#include "libANGLE/renderer/d3d/d3d11/Framebuffer11.h" -#include "libANGLE/renderer/d3d/d3d11/Image11.h" -#include "libANGLE/renderer/d3d/d3d11/IndexBuffer11.h" -#include "libANGLE/renderer/d3d/d3d11/PixelTransfer11.h" -#include "libANGLE/renderer/d3d/d3d11/Query11.h" -#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h" -#include "libANGLE/renderer/d3d/d3d11/ShaderExecutable11.h" -#include "libANGLE/renderer/d3d/d3d11/StreamProducerNV12.h" -#include "libANGLE/renderer/d3d/d3d11/SwapChain11.h" -#include "libANGLE/renderer/d3d/d3d11/TextureStorage11.h" -#include "libANGLE/renderer/d3d/d3d11/TransformFeedback11.h" -#include "libANGLE/renderer/d3d/d3d11/Trim11.h" -#include "libANGLE/renderer/d3d/d3d11/VertexArray11.h" -#include "libANGLE/renderer/d3d/d3d11/VertexBuffer11.h" -#include "libANGLE/renderer/d3d/d3d11/dxgi_support_table.h" -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h" -#include "libANGLE/renderer/renderer_utils.h" -#include "third_party/trace_event/trace_event.h" - -#ifdef ANGLE_ENABLE_WINDOWS_STORE -#include "libANGLE/renderer/d3d/d3d11/winrt/NativeWindow11WinRT.h" -#else -#include "libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.h" -#endif - -// Include the D3D9 debug annotator header for use by the desktop D3D11 renderer -// because the D3D11 interface method ID3DUserDefinedAnnotation::GetStatus -// doesn't work with the Graphics Diagnostics tools in Visual Studio 2013. -#ifdef ANGLE_ENABLE_D3D9 -#include "libANGLE/renderer/d3d/d3d9/DebugAnnotator9.h" -#endif - -// Enable ANGLE_SKIP_DXGI_1_2_CHECK if there is not a possibility of using cross-process -// HWNDs or the Windows 7 Platform Update (KB2670838) is expected to be installed. -#ifndef ANGLE_SKIP_DXGI_1_2_CHECK -#define ANGLE_SKIP_DXGI_1_2_CHECK 0 -#endif - -namespace rx -{ - -namespace -{ - -enum -{ - MAX_TEXTURE_IMAGE_UNITS_VTF_SM4 = 16 -}; - -enum ANGLEFeatureLevel -{ - ANGLE_FEATURE_LEVEL_INVALID, - ANGLE_FEATURE_LEVEL_9_3, - ANGLE_FEATURE_LEVEL_10_0, - ANGLE_FEATURE_LEVEL_10_1, - ANGLE_FEATURE_LEVEL_11_0, - ANGLE_FEATURE_LEVEL_11_1, - NUM_ANGLE_FEATURE_LEVELS -}; - -ANGLEFeatureLevel GetANGLEFeatureLevel(D3D_FEATURE_LEVEL d3dFeatureLevel) -{ - switch (d3dFeatureLevel) - { - case D3D_FEATURE_LEVEL_9_3: - return ANGLE_FEATURE_LEVEL_9_3; - case D3D_FEATURE_LEVEL_10_0: - return ANGLE_FEATURE_LEVEL_10_0; - case D3D_FEATURE_LEVEL_10_1: - return ANGLE_FEATURE_LEVEL_10_1; - case D3D_FEATURE_LEVEL_11_0: - return ANGLE_FEATURE_LEVEL_11_0; - case D3D_FEATURE_LEVEL_11_1: - return ANGLE_FEATURE_LEVEL_11_1; - default: - return ANGLE_FEATURE_LEVEL_INVALID; - } -} - -void SetLineLoopIndices(GLuint *dest, size_t count) -{ - for (size_t i = 0; i < count; i++) - { - dest[i] = static_cast<GLuint>(i); - } - dest[count] = 0; -} - -template <typename T> -void CopyLineLoopIndices(const void *indices, GLuint *dest, size_t count) -{ - const T *srcPtr = static_cast<const T *>(indices); - for (size_t i = 0; i < count; ++i) - { - dest[i] = static_cast<GLuint>(srcPtr[i]); - } - dest[count] = static_cast<GLuint>(srcPtr[0]); -} - -void SetTriangleFanIndices(GLuint *destPtr, size_t numTris) -{ - for (size_t i = 0; i < numTris; i++) - { - destPtr[i * 3 + 0] = 0; - destPtr[i * 3 + 1] = static_cast<GLuint>(i) + 1; - destPtr[i * 3 + 2] = static_cast<GLuint>(i) + 2; - } -} - -template <typename T> -void CopyLineLoopIndicesWithRestart(const void *indices, - size_t count, - GLenum indexType, - std::vector<GLuint> *bufferOut) -{ - GLuint restartIndex = gl::GetPrimitiveRestartIndex(indexType); - GLuint d3dRestartIndex = static_cast<GLuint>(d3d11::GetPrimitiveRestartIndex()); - const T *srcPtr = static_cast<const T *>(indices); - Optional<GLuint> currentLoopStart; - - bufferOut->clear(); - - for (size_t indexIdx = 0; indexIdx < count; ++indexIdx) - { - GLuint value = static_cast<GLuint>(srcPtr[indexIdx]); - - if (value == restartIndex) - { - if (currentLoopStart.valid()) - { - bufferOut->push_back(currentLoopStart.value()); - bufferOut->push_back(d3dRestartIndex); - currentLoopStart.reset(); - } - } - else - { - bufferOut->push_back(value); - if (!currentLoopStart.valid()) - { - currentLoopStart = value; - } - } - } - - if (currentLoopStart.valid()) - { - bufferOut->push_back(currentLoopStart.value()); - } -} - -void GetLineLoopIndices(const void *indices, - GLenum indexType, - GLuint count, - bool usePrimitiveRestartFixedIndex, - std::vector<GLuint> *bufferOut) -{ - if (indexType != GL_NONE && usePrimitiveRestartFixedIndex) - { - switch (indexType) - { - case GL_UNSIGNED_BYTE: - CopyLineLoopIndicesWithRestart<GLubyte>(indices, count, indexType, bufferOut); - break; - case GL_UNSIGNED_SHORT: - CopyLineLoopIndicesWithRestart<GLushort>(indices, count, indexType, bufferOut); - break; - case GL_UNSIGNED_INT: - CopyLineLoopIndicesWithRestart<GLuint>(indices, count, indexType, bufferOut); - break; - default: - UNREACHABLE(); - break; - } - return; - } - - // For non-primitive-restart draws, the index count is static. - bufferOut->resize(static_cast<size_t>(count) + 1); - - switch (indexType) - { - // Non-indexed draw - case GL_NONE: - SetLineLoopIndices(&(*bufferOut)[0], count); - break; - case GL_UNSIGNED_BYTE: - CopyLineLoopIndices<GLubyte>(indices, &(*bufferOut)[0], count); - break; - case GL_UNSIGNED_SHORT: - CopyLineLoopIndices<GLushort>(indices, &(*bufferOut)[0], count); - break; - case GL_UNSIGNED_INT: - CopyLineLoopIndices<GLuint>(indices, &(*bufferOut)[0], count); - break; - default: - UNREACHABLE(); - break; - } -} - -template <typename T> -void CopyTriangleFanIndices(const void *indices, GLuint *destPtr, size_t numTris) -{ - const T *srcPtr = static_cast<const T *>(indices); - - for (size_t i = 0; i < numTris; i++) - { - destPtr[i * 3 + 0] = static_cast<GLuint>(srcPtr[0]); - destPtr[i * 3 + 1] = static_cast<GLuint>(srcPtr[i + 1]); - destPtr[i * 3 + 2] = static_cast<GLuint>(srcPtr[i + 2]); - } -} - -template <typename T> -void CopyTriangleFanIndicesWithRestart(const void *indices, - GLuint indexCount, - GLenum indexType, - std::vector<GLuint> *bufferOut) -{ - GLuint restartIndex = gl::GetPrimitiveRestartIndex(indexType); - GLuint d3dRestartIndex = gl::GetPrimitiveRestartIndex(GL_UNSIGNED_INT); - const T *srcPtr = static_cast<const T *>(indices); - Optional<GLuint> vertexA; - Optional<GLuint> vertexB; - - bufferOut->clear(); - - for (size_t indexIdx = 0; indexIdx < indexCount; ++indexIdx) - { - GLuint value = static_cast<GLuint>(srcPtr[indexIdx]); - - if (value == restartIndex) - { - bufferOut->push_back(d3dRestartIndex); - vertexA.reset(); - vertexB.reset(); - } - else - { - if (!vertexA.valid()) - { - vertexA = value; - } - else if (!vertexB.valid()) - { - vertexB = value; - } - else - { - bufferOut->push_back(vertexA.value()); - bufferOut->push_back(vertexB.value()); - bufferOut->push_back(value); - vertexB = value; - } - } - } -} - -void GetTriFanIndices(const void *indices, - GLenum indexType, - GLuint count, - bool usePrimitiveRestartFixedIndex, - std::vector<GLuint> *bufferOut) -{ - if (indexType != GL_NONE && usePrimitiveRestartFixedIndex) - { - switch (indexType) - { - case GL_UNSIGNED_BYTE: - CopyTriangleFanIndicesWithRestart<GLubyte>(indices, count, indexType, bufferOut); - break; - case GL_UNSIGNED_SHORT: - CopyTriangleFanIndicesWithRestart<GLushort>(indices, count, indexType, bufferOut); - break; - case GL_UNSIGNED_INT: - CopyTriangleFanIndicesWithRestart<GLuint>(indices, count, indexType, bufferOut); - break; - default: - UNREACHABLE(); - break; - } - return; - } - - // For non-primitive-restart draws, the index count is static. - GLuint numTris = count - 2; - bufferOut->resize(numTris * 3); - - switch (indexType) - { - // Non-indexed draw - case GL_NONE: - SetTriangleFanIndices(&(*bufferOut)[0], numTris); - break; - case GL_UNSIGNED_BYTE: - CopyTriangleFanIndices<GLubyte>(indices, &(*bufferOut)[0], numTris); - break; - case GL_UNSIGNED_SHORT: - CopyTriangleFanIndices<GLushort>(indices, &(*bufferOut)[0], numTris); - break; - case GL_UNSIGNED_INT: - CopyTriangleFanIndices<GLuint>(indices, &(*bufferOut)[0], numTris); - break; - default: - UNREACHABLE(); - break; - } -} - -bool DrawCallNeedsTranslation(const gl::Context *context, GLenum mode) -{ - const auto &glState = context->getGLState(); - const gl::VertexArray *vertexArray = glState.getVertexArray(); - VertexArray11 *vertexArray11 = GetImplAs<VertexArray11>(vertexArray); - // Direct drawing doesn't support dynamic attribute storage since it needs the first and count - // to translate when applyVertexBuffer. GL_LINE_LOOP and GL_TRIANGLE_FAN are not supported - // either since we need to simulate them in D3D. - if (vertexArray11->hasActiveDynamicAttrib(context) || mode == GL_LINE_LOOP || - mode == GL_TRIANGLE_FAN) - { - return true; - } - - ProgramD3D *programD3D = GetImplAs<ProgramD3D>(glState.getProgram()); - if (InstancedPointSpritesActive(programD3D, mode)) - { - return true; - } - - return false; -} - -bool IsArrayRTV(ID3D11RenderTargetView *rtv) -{ - D3D11_RENDER_TARGET_VIEW_DESC desc; - rtv->GetDesc(&desc); - if (desc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE1DARRAY && - desc.Texture1DArray.ArraySize > 1) - return true; - if (desc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY && - desc.Texture2DArray.ArraySize > 1) - return true; - if (desc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY && - desc.Texture2DMSArray.ArraySize > 1) - return true; - return false; -} - -int GetAdjustedInstanceCount(const gl::Program *program, int instanceCount) -{ - if (!program->usesMultiview()) - { - return instanceCount; - } - if (instanceCount == 0) - { - return program->getNumViews(); - } - return program->getNumViews() * instanceCount; -} - -const uint32_t ScratchMemoryBufferLifetime = 1000; - -void PopulateFormatDeviceCaps(ID3D11Device *device, - DXGI_FORMAT format, - UINT *outSupport, - UINT *outMaxSamples) -{ - if (FAILED(device->CheckFormatSupport(format, outSupport))) - { - *outSupport = 0; - } - - *outMaxSamples = 0; - for (UINT sampleCount = 2; sampleCount <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; sampleCount *= 2) - { - UINT qualityCount = 0; - if (FAILED(device->CheckMultisampleQualityLevels(format, sampleCount, &qualityCount)) || - qualityCount == 0) - { - break; - } - - *outMaxSamples = sampleCount; - } -} - -bool CullsEverything(const gl::State &glState) -{ - return (glState.getRasterizerState().cullFace && - glState.getRasterizerState().cullMode == gl::CullFaceMode::FrontAndBack); -} - -} // anonymous namespace - -Renderer11DeviceCaps::Renderer11DeviceCaps() = default; - -Renderer11::Renderer11(egl::Display *display) - : RendererD3D(display), - mCreateDebugDevice(false), - mStateCache(), - mStateManager(this), - mLastHistogramUpdateTime( - ANGLEPlatformCurrent()->monotonicallyIncreasingTime(ANGLEPlatformCurrent())), - mDebug(nullptr), - mScratchMemoryBuffer(ScratchMemoryBufferLifetime), - mAnnotator(nullptr) -{ - mLineLoopIB = nullptr; - mTriangleFanIB = nullptr; - - mBlit = nullptr; - mPixelTransfer = nullptr; - - mClear = nullptr; - - mTrim = nullptr; - - mRenderer11DeviceCaps.supportsClearView = false; - mRenderer11DeviceCaps.supportsConstantBufferOffsets = false; - mRenderer11DeviceCaps.supportsVpRtIndexWriteFromVertexShader = false; - mRenderer11DeviceCaps.supportsDXGI1_2 = false; - mRenderer11DeviceCaps.B5G6R5support = 0; - mRenderer11DeviceCaps.B4G4R4A4support = 0; - mRenderer11DeviceCaps.B5G5R5A1support = 0; - - mD3d11Module = nullptr; - mDxgiModule = nullptr; - mDCompModule = nullptr; - mCreatedWithDeviceEXT = false; - mEGLDevice = nullptr; - - mDevice = nullptr; - mDeviceContext = nullptr; - mDeviceContext1 = nullptr; - mDeviceContext3 = nullptr; - mDxgiAdapter = nullptr; - mDxgiFactory = nullptr; - - ZeroMemory(&mAdapterDescription, sizeof(mAdapterDescription)); - - if (mDisplay->getPlatform() == EGL_PLATFORM_ANGLE_ANGLE) - { - const auto &attributes = mDisplay->getAttributeMap(); - - EGLint requestedMajorVersion = static_cast<EGLint>( - attributes.get(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, EGL_DONT_CARE)); - EGLint requestedMinorVersion = static_cast<EGLint>( - attributes.get(EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, EGL_DONT_CARE)); - - if (requestedMajorVersion == EGL_DONT_CARE || requestedMajorVersion >= 11) - { - if (requestedMinorVersion == EGL_DONT_CARE || requestedMinorVersion >= 1) - { - // This could potentially lead to failed context creation if done on a system - // without the platform update which installs DXGI 1.2. Currently, for Chrome users - // D3D11 contexts are only created if the platform update is available, so this - // should not cause any issues. - mAvailableFeatureLevels.push_back(D3D_FEATURE_LEVEL_11_1); - } - if (requestedMinorVersion == EGL_DONT_CARE || requestedMinorVersion >= 0) - { - mAvailableFeatureLevels.push_back(D3D_FEATURE_LEVEL_11_0); - } - } - - if (requestedMajorVersion == EGL_DONT_CARE || requestedMajorVersion >= 10) - { - if (requestedMinorVersion == EGL_DONT_CARE || requestedMinorVersion >= 1) - { - mAvailableFeatureLevels.push_back(D3D_FEATURE_LEVEL_10_1); - } - if (requestedMinorVersion == EGL_DONT_CARE || requestedMinorVersion >= 0) - { - mAvailableFeatureLevels.push_back(D3D_FEATURE_LEVEL_10_0); - } - } - - if (requestedMajorVersion == 9 && requestedMinorVersion == 3) - { - if (requestedMinorVersion == EGL_DONT_CARE || requestedMinorVersion >= 3) - { - mAvailableFeatureLevels.push_back(D3D_FEATURE_LEVEL_9_3); - } -#if defined(ANGLE_ENABLE_WINDOWS_STORE) - if (requestedMinorVersion == EGL_DONT_CARE || requestedMinorVersion >= 2) - { - mAvailableFeatureLevels.push_back(D3D_FEATURE_LEVEL_9_2); - } - if (requestedMinorVersion == EGL_DONT_CARE || requestedMinorVersion >= 1) - { - mAvailableFeatureLevels.push_back(D3D_FEATURE_LEVEL_9_1); - } -#endif - } - - EGLint requestedDeviceType = static_cast<EGLint>(attributes.get( - EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE)); - switch (requestedDeviceType) - { - case EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE: - mRequestedDriverType = D3D_DRIVER_TYPE_HARDWARE; - break; - - case EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE: - mRequestedDriverType = D3D_DRIVER_TYPE_WARP; - break; - - case EGL_PLATFORM_ANGLE_DEVICE_TYPE_REFERENCE_ANGLE: - mRequestedDriverType = D3D_DRIVER_TYPE_REFERENCE; - break; - - case EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE: - mRequestedDriverType = D3D_DRIVER_TYPE_NULL; - break; - - default: - UNREACHABLE(); - } - - const EGLenum presentPath = static_cast<EGLenum>(attributes.get( - EGL_EXPERIMENTAL_PRESENT_PATH_ANGLE, EGL_EXPERIMENTAL_PRESENT_PATH_COPY_ANGLE)); - mPresentPathFastEnabled = (presentPath == EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE); - - mCreateDebugDevice = ShouldUseDebugLayers(attributes); - } - else if (display->getPlatform() == EGL_PLATFORM_DEVICE_EXT) - { - mEGLDevice = GetImplAs<DeviceD3D>(display->getDevice()); - ASSERT(mEGLDevice != nullptr); - mCreatedWithDeviceEXT = true; - - // Also set EGL_PLATFORM_ANGLE_ANGLE variables, in case they're used elsewhere in ANGLE - // mAvailableFeatureLevels defaults to empty - mRequestedDriverType = D3D_DRIVER_TYPE_UNKNOWN; - mPresentPathFastEnabled = false; - } - -// The D3D11 renderer must choose the D3D9 debug annotator because the D3D11 interface -// method ID3DUserDefinedAnnotation::GetStatus on desktop builds doesn't work with the Graphics -// Diagnostics tools in Visual Studio 2013. -// The D3D9 annotator works properly for both D3D11 and D3D9. -// Incorrect status reporting can cause ANGLE to log unnecessary debug events. -#ifdef ANGLE_ENABLE_D3D9 - mAnnotator = new DebugAnnotator9(); -#else - mAnnotator = new DebugAnnotator11(); -#endif - ASSERT(mAnnotator); - gl::InitializeDebugAnnotations(mAnnotator); -} - -Renderer11::~Renderer11() -{ - release(); -} - -#ifndef __d3d11_1_h__ -#define D3D11_MESSAGE_ID_DEVICE_DRAW_RENDERTARGETVIEW_NOT_SET ((D3D11_MESSAGE_ID)3146081) -#endif - -egl::Error Renderer11::initialize() -{ - HRESULT result = S_OK; - - ANGLE_TRY(initializeD3DDevice()); - -#if !defined(ANGLE_ENABLE_WINDOWS_STORE) -#if !ANGLE_SKIP_DXGI_1_2_CHECK - { - TRACE_EVENT0("gpu.angle", "Renderer11::initialize (DXGICheck)"); - // In order to create a swap chain for an HWND owned by another process, DXGI 1.2 is - // required. - // The easiest way to check is to query for a IDXGIDevice2. - bool requireDXGI1_2 = false; - HWND hwnd = WindowFromDC(mDisplay->getNativeDisplayId()); - if (hwnd) - { - DWORD currentProcessId = GetCurrentProcessId(); - DWORD wndProcessId; - GetWindowThreadProcessId(hwnd, &wndProcessId); - requireDXGI1_2 = (currentProcessId != wndProcessId); - } - else - { - requireDXGI1_2 = true; - } - - if (requireDXGI1_2) - { - IDXGIDevice2 *dxgiDevice2 = nullptr; - result = mDevice->QueryInterface(__uuidof(IDXGIDevice2), (void **)&dxgiDevice2); - if (FAILED(result)) - { - return egl::EglNotInitialized(D3D11_INIT_INCOMPATIBLE_DXGI) - << "DXGI 1.2 required to present to HWNDs owned by another process."; - } - SafeRelease(dxgiDevice2); - } - } -#endif -#endif - - { - TRACE_EVENT0("gpu.angle", "Renderer11::initialize (ComQueries)"); - // Cast the DeviceContext to a DeviceContext1 and DeviceContext3. - // This could fail on Windows 7 without the Platform Update. - // Don't error in this case- just don't use mDeviceContext1 or mDeviceContext3. - mDeviceContext1 = d3d11::DynamicCastComObject<ID3D11DeviceContext1>(mDeviceContext); - mDeviceContext3 = d3d11::DynamicCastComObject<ID3D11DeviceContext3>(mDeviceContext); - - IDXGIDevice *dxgiDevice = nullptr; - result = mDevice->QueryInterface(__uuidof(IDXGIDevice), (void **)&dxgiDevice); - - if (FAILED(result)) - { - return egl::EglNotInitialized(D3D11_INIT_OTHER_ERROR) << "Could not query DXGI device."; - } - - result = dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void **)&mDxgiAdapter); - - if (FAILED(result)) - { - return egl::EglNotInitialized(D3D11_INIT_OTHER_ERROR) - << "Could not retrieve DXGI adapter"; - } - - SafeRelease(dxgiDevice); - - IDXGIAdapter2 *dxgiAdapter2 = d3d11::DynamicCastComObject<IDXGIAdapter2>(mDxgiAdapter); - - // On D3D_FEATURE_LEVEL_9_*, IDXGIAdapter::GetDesc returns "Software Adapter" for the - // description string. - // If DXGI1.2 is available then IDXGIAdapter2::GetDesc2 can be used to get the actual - // hardware values. - if (mRenderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3 && dxgiAdapter2 != nullptr) - { - DXGI_ADAPTER_DESC2 adapterDesc2 = {}; - result = dxgiAdapter2->GetDesc2(&adapterDesc2); - if (SUCCEEDED(result)) - { - // Copy the contents of the DXGI_ADAPTER_DESC2 into mAdapterDescription (a - // DXGI_ADAPTER_DESC). - memcpy(mAdapterDescription.Description, adapterDesc2.Description, - sizeof(mAdapterDescription.Description)); - mAdapterDescription.VendorId = adapterDesc2.VendorId; - mAdapterDescription.DeviceId = adapterDesc2.DeviceId; - mAdapterDescription.SubSysId = adapterDesc2.SubSysId; - mAdapterDescription.Revision = adapterDesc2.Revision; - mAdapterDescription.DedicatedVideoMemory = adapterDesc2.DedicatedVideoMemory; - mAdapterDescription.DedicatedSystemMemory = adapterDesc2.DedicatedSystemMemory; - mAdapterDescription.SharedSystemMemory = adapterDesc2.SharedSystemMemory; - mAdapterDescription.AdapterLuid = adapterDesc2.AdapterLuid; - } - } - else - { - result = mDxgiAdapter->GetDesc(&mAdapterDescription); - } - - SafeRelease(dxgiAdapter2); - - if (FAILED(result)) - { - return egl::EglNotInitialized(D3D11_INIT_OTHER_ERROR) - << "Could not read DXGI adaptor description."; - } - - memset(mDescription, 0, sizeof(mDescription)); - wcstombs(mDescription, mAdapterDescription.Description, sizeof(mDescription) - 1); - - result = mDxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void **)&mDxgiFactory); - - if (!mDxgiFactory || FAILED(result)) - { - return egl::EglNotInitialized(D3D11_INIT_OTHER_ERROR) - << "Could not create DXGI factory."; - } - } - - // Disable some spurious D3D11 debug warnings to prevent them from flooding the output log - if (mCreateDebugDevice) - { - TRACE_EVENT0("gpu.angle", "Renderer11::initialize (HideWarnings)"); - ID3D11InfoQueue *infoQueue; - result = mDevice->QueryInterface(__uuidof(ID3D11InfoQueue), (void **)&infoQueue); - - if (SUCCEEDED(result)) - { - D3D11_MESSAGE_ID hideMessages[] = { - D3D11_MESSAGE_ID_DEVICE_DRAW_RENDERTARGETVIEW_NOT_SET}; - - D3D11_INFO_QUEUE_FILTER filter = {}; - filter.DenyList.NumIDs = static_cast<unsigned int>(ArraySize(hideMessages)); - filter.DenyList.pIDList = hideMessages; - - infoQueue->AddStorageFilterEntries(&filter); - SafeRelease(infoQueue); - } - } - -#if !defined(NDEBUG) - mDebug = d3d11::DynamicCastComObject<ID3D11Debug>(mDevice); -#endif - - ANGLE_TRY(initializeDevice()); - - return egl::NoError(); -} - -HRESULT Renderer11::callD3D11CreateDevice(PFN_D3D11_CREATE_DEVICE createDevice, bool debug) -{ - return createDevice( - nullptr, mRequestedDriverType, nullptr, debug ? D3D11_CREATE_DEVICE_DEBUG : 0, - mAvailableFeatureLevels.data(), static_cast<unsigned int>(mAvailableFeatureLevels.size()), - D3D11_SDK_VERSION, &mDevice, &(mRenderer11DeviceCaps.featureLevel), &mDeviceContext); -} - -egl::Error Renderer11::initializeD3DDevice() -{ - HRESULT result = S_OK; - - if (!mCreatedWithDeviceEXT) - { -#if !defined(ANGLE_ENABLE_WINDOWS_STORE) - PFN_D3D11_CREATE_DEVICE D3D11CreateDevice = nullptr; - { - SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.Renderer11InitializeDLLsMS"); - TRACE_EVENT0("gpu.angle", "Renderer11::initialize (Load DLLs)"); - mDxgiModule = LoadLibrary(TEXT("dxgi.dll")); - mD3d11Module = LoadLibrary(TEXT("d3d11.dll")); - mDCompModule = LoadLibrary(TEXT("dcomp.dll")); - - if (mD3d11Module == nullptr || mDxgiModule == nullptr) - { - return egl::EglNotInitialized(D3D11_INIT_MISSING_DEP) - << "Could not load D3D11 or DXGI library."; - } - - // create the D3D11 device - ASSERT(mDevice == nullptr); - D3D11CreateDevice = reinterpret_cast<PFN_D3D11_CREATE_DEVICE>( - GetProcAddress(mD3d11Module, "D3D11CreateDevice")); - - if (D3D11CreateDevice == nullptr) - { - return egl::EglNotInitialized(D3D11_INIT_MISSING_DEP) - << "Could not retrieve D3D11CreateDevice address."; - } - } -#endif - - if (mCreateDebugDevice) - { - TRACE_EVENT0("gpu.angle", "D3D11CreateDevice (Debug)"); - result = callD3D11CreateDevice(D3D11CreateDevice, true); - - if (result == E_INVALIDARG && mAvailableFeatureLevels.size() > 1u && - mAvailableFeatureLevels[0] == D3D_FEATURE_LEVEL_11_1) - { - // On older Windows platforms, D3D11.1 is not supported which returns E_INVALIDARG. - // Try again without passing D3D_FEATURE_LEVEL_11_1 in case we have other feature - // levels to fall back on. - mAvailableFeatureLevels.erase(mAvailableFeatureLevels.begin()); - result = callD3D11CreateDevice(D3D11CreateDevice, true); - } - - if (!mDevice || FAILED(result)) - { - WARN() << "Failed creating Debug D3D11 device - falling back to release runtime."; - } - } - - if (!mDevice || FAILED(result)) - { - SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.D3D11CreateDeviceMS"); - TRACE_EVENT0("gpu.angle", "D3D11CreateDevice"); - - result = callD3D11CreateDevice(D3D11CreateDevice, false); - - if (result == E_INVALIDARG && mAvailableFeatureLevels.size() > 1u && - mAvailableFeatureLevels[0] == D3D_FEATURE_LEVEL_11_1) - { - // On older Windows platforms, D3D11.1 is not supported which returns E_INVALIDARG. - // Try again without passing D3D_FEATURE_LEVEL_11_1 in case we have other feature - // levels to fall back on. - mAvailableFeatureLevels.erase(mAvailableFeatureLevels.begin()); - result = callD3D11CreateDevice(D3D11CreateDevice, false); - } - - // Cleanup done by destructor - if (!mDevice || FAILED(result)) - { - ANGLE_HISTOGRAM_SPARSE_SLOWLY("GPU.ANGLE.D3D11CreateDeviceError", - static_cast<int>(result)); - return egl::EglNotInitialized(D3D11_INIT_CREATEDEVICE_ERROR) - << "Could not create D3D11 device."; - } - } - } - else - { - // We should use the inputted D3D11 device instead - void *device = nullptr; - ANGLE_TRY(mEGLDevice->getDevice(&device)); - - ID3D11Device *d3dDevice = reinterpret_cast<ID3D11Device *>(device); - if (FAILED(d3dDevice->GetDeviceRemovedReason())) - { - return egl::EglNotInitialized() << "Inputted D3D11 device has been lost."; - } - - if (d3dDevice->GetFeatureLevel() < D3D_FEATURE_LEVEL_9_3) - { - return egl::EglNotInitialized() - << "Inputted D3D11 device must be Feature Level 9_3 or greater."; - } - - // The Renderer11 adds a ref to the inputted D3D11 device, like D3D11CreateDevice does. - mDevice = d3dDevice; - mDevice->AddRef(); - mDevice->GetImmediateContext(&mDeviceContext); - mRenderer11DeviceCaps.featureLevel = mDevice->GetFeatureLevel(); - } - - mResourceManager11.setAllocationsInitialized(mCreateDebugDevice); - - d3d11::SetDebugName(mDeviceContext, "DeviceContext"); - - return egl::NoError(); -} - -// do any one-time device initialization -// NOTE: this is also needed after a device lost/reset -// to reset the scene status and ensure the default states are reset. -egl::Error Renderer11::initializeDevice() -{ - SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.Renderer11InitializeDeviceMS"); - TRACE_EVENT0("gpu.angle", "Renderer11::initializeDevice"); - - populateRenderer11DeviceCaps(); - - mStateCache.clear(); - - ASSERT(!mBlit); - mBlit = new Blit11(this); - - ASSERT(!mClear); - mClear = new Clear11(this); - - const auto &attributes = mDisplay->getAttributeMap(); - // If automatic trim is enabled, DXGIDevice3::Trim( ) is called for the application - // automatically when an application is suspended by the OS. This feature is currently - // only supported for Windows Store applications. - EGLint enableAutoTrim = static_cast<EGLint>( - attributes.get(EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL_FALSE)); - - if (enableAutoTrim == EGL_TRUE) - { - ASSERT(!mTrim); - mTrim = new Trim11(this); - } - - ASSERT(!mPixelTransfer); - mPixelTransfer = new PixelTransfer11(this); - - const gl::Caps &rendererCaps = getNativeCaps(); - - if (mStateManager.initialize(rendererCaps, getNativeExtensions()).isError()) - { - return egl::EglBadAlloc() << "Error initializing state manager."; - } - - // Gather stats on DXGI and D3D feature level - ANGLE_HISTOGRAM_BOOLEAN("GPU.ANGLE.SupportsDXGI1_2", mRenderer11DeviceCaps.supportsDXGI1_2); - - ANGLEFeatureLevel angleFeatureLevel = GetANGLEFeatureLevel(mRenderer11DeviceCaps.featureLevel); - - // We don't actually request a 11_1 device, because of complications with the platform - // update. Instead we check if the mDeviceContext1 pointer cast succeeded. - // Note: we should support D3D11_0 always, but we aren't guaranteed to be at FL11_0 - // because the app can specify a lower version (such as 9_3) on Display creation. - if (mDeviceContext1 != nullptr) - { - angleFeatureLevel = ANGLE_FEATURE_LEVEL_11_1; - } - - ANGLE_HISTOGRAM_ENUMERATION("GPU.ANGLE.D3D11FeatureLevel", angleFeatureLevel, - NUM_ANGLE_FEATURE_LEVELS); - - return egl::NoError(); -} - -void Renderer11::populateRenderer11DeviceCaps() -{ - HRESULT hr = S_OK; - - LARGE_INTEGER version; - hr = mDxgiAdapter->CheckInterfaceSupport(__uuidof(IDXGIDevice), &version); - if (FAILED(hr)) - { - mRenderer11DeviceCaps.driverVersion.reset(); - ERR() << "Error querying driver version from DXGI Adapter."; - } - else - { - mRenderer11DeviceCaps.driverVersion = version; - } - - if (mDeviceContext1) - { - D3D11_FEATURE_DATA_D3D11_OPTIONS d3d11Options; - HRESULT result = mDevice->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS, &d3d11Options, - sizeof(D3D11_FEATURE_DATA_D3D11_OPTIONS)); - if (SUCCEEDED(result)) - { - mRenderer11DeviceCaps.supportsClearView = (d3d11Options.ClearView != FALSE); - mRenderer11DeviceCaps.supportsConstantBufferOffsets = - (d3d11Options.ConstantBufferOffsetting != FALSE); - } - } - - if (mDeviceContext3) - { - D3D11_FEATURE_DATA_D3D11_OPTIONS3 d3d11Options3; - HRESULT result = mDevice->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS3, &d3d11Options3, - sizeof(D3D11_FEATURE_DATA_D3D11_OPTIONS3)); - if (SUCCEEDED(result)) - { - mRenderer11DeviceCaps.supportsVpRtIndexWriteFromVertexShader = - (d3d11Options3.VPAndRTArrayIndexFromAnyShaderFeedingRasterizer == TRUE); - } - } - - mRenderer11DeviceCaps.supportsMultisampledDepthStencilSRVs = - mRenderer11DeviceCaps.featureLevel > D3D_FEATURE_LEVEL_10_0; - - if (getWorkarounds().disableB5G6R5Support) - { - mRenderer11DeviceCaps.B5G6R5support = 0; - mRenderer11DeviceCaps.B5G6R5maxSamples = 0; - } - else - { - PopulateFormatDeviceCaps(mDevice, DXGI_FORMAT_B5G6R5_UNORM, - &mRenderer11DeviceCaps.B5G6R5support, - &mRenderer11DeviceCaps.B5G6R5maxSamples); - } - - PopulateFormatDeviceCaps(mDevice, DXGI_FORMAT_B4G4R4A4_UNORM, - &mRenderer11DeviceCaps.B4G4R4A4support, - &mRenderer11DeviceCaps.B4G4R4A4maxSamples); - PopulateFormatDeviceCaps(mDevice, DXGI_FORMAT_B5G5R5A1_UNORM, - &mRenderer11DeviceCaps.B5G5R5A1support, - &mRenderer11DeviceCaps.B5G5R5A1maxSamples); - - IDXGIAdapter2 *dxgiAdapter2 = d3d11::DynamicCastComObject<IDXGIAdapter2>(mDxgiAdapter); - mRenderer11DeviceCaps.supportsDXGI1_2 = (dxgiAdapter2 != nullptr); - SafeRelease(dxgiAdapter2); -} - -gl::SupportedSampleSet Renderer11::generateSampleSetForEGLConfig( - const gl::TextureCaps &colorBufferFormatCaps, - const gl::TextureCaps &depthStencilBufferFormatCaps) const -{ - gl::SupportedSampleSet sampleCounts; - -#if 0 // Disabling support for multisampling with Qt5 as it's causing a crash in the D3D11 shaders. - - // Generate a new set from the set intersection of sample counts between the color and depth - // format caps. - std::set_intersection(colorBufferFormatCaps.sampleCounts.begin(), - colorBufferFormatCaps.sampleCounts.end(), - depthStencilBufferFormatCaps.sampleCounts.begin(), - depthStencilBufferFormatCaps.sampleCounts.end(), - std::inserter(sampleCounts, sampleCounts.begin())); - - // Format of GL_NONE results in no supported sample counts. - // Add back the color sample counts to the supported sample set. - if (depthStencilBufferFormatCaps.sampleCounts.empty()) - { - sampleCounts = colorBufferFormatCaps.sampleCounts; - } - else if (colorBufferFormatCaps.sampleCounts.empty()) - { - // Likewise, add back the depth sample counts to the supported sample set. - sampleCounts = depthStencilBufferFormatCaps.sampleCounts; - } - -#endif - - // Always support 0 samples - sampleCounts.insert(0); - - return sampleCounts; -} - -egl::ConfigSet Renderer11::generateConfigs() -{ - std::vector<GLenum> colorBufferFormats; - - // 32-bit supported formats - colorBufferFormats.push_back(GL_BGRA8_EXT); - colorBufferFormats.push_back(GL_RGBA8_OES); - - // 24-bit supported formats - colorBufferFormats.push_back(GL_RGB8_OES); - - if (mRenderer11DeviceCaps.featureLevel >= D3D_FEATURE_LEVEL_10_0) - { - // Additional high bit depth formats added in D3D 10.0 - // https://msdn.microsoft.com/en-us/library/windows/desktop/bb173064.aspx - colorBufferFormats.push_back(GL_RGBA16F); - colorBufferFormats.push_back(GL_RGB10_A2); - } - - if (!mPresentPathFastEnabled) - { - // 16-bit supported formats - // These aren't valid D3D11 swapchain formats, so don't expose them as configs - // if present path fast is active - colorBufferFormats.push_back(GL_RGBA4); - colorBufferFormats.push_back(GL_RGB5_A1); - colorBufferFormats.push_back(GL_RGB565); - } - - static const GLenum depthStencilBufferFormats[] = { - GL_NONE, GL_DEPTH24_STENCIL8_OES, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT16, - GL_STENCIL_INDEX8, - }; - - const gl::Caps &rendererCaps = getNativeCaps(); - const gl::TextureCapsMap &rendererTextureCaps = getNativeTextureCaps(); - - const EGLint optimalSurfaceOrientation = - mPresentPathFastEnabled ? 0 : EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE; - - egl::ConfigSet configs; - for (GLenum colorBufferInternalFormat : colorBufferFormats) - { - const gl::TextureCaps &colorBufferFormatCaps = - rendererTextureCaps.get(colorBufferInternalFormat); - if (!colorBufferFormatCaps.renderable) - { - continue; - } - - for (GLenum depthStencilBufferInternalFormat : depthStencilBufferFormats) - { - const gl::TextureCaps &depthStencilBufferFormatCaps = - rendererTextureCaps.get(depthStencilBufferInternalFormat); - if (!depthStencilBufferFormatCaps.renderable && - depthStencilBufferInternalFormat != GL_NONE) - { - continue; - } - - const gl::InternalFormat &colorBufferFormatInfo = - gl::GetSizedInternalFormatInfo(colorBufferInternalFormat); - const gl::InternalFormat &depthStencilBufferFormatInfo = - gl::GetSizedInternalFormatInfo(depthStencilBufferInternalFormat); - const gl::Version &maxVersion = getMaxSupportedESVersion(); - - const gl::SupportedSampleSet sampleCounts = - generateSampleSetForEGLConfig(colorBufferFormatCaps, depthStencilBufferFormatCaps); - - for (GLuint sampleCount : sampleCounts) - { - egl::Config config; - config.renderTargetFormat = colorBufferInternalFormat; - config.depthStencilFormat = depthStencilBufferInternalFormat; - config.bufferSize = colorBufferFormatInfo.pixelBytes * 8; - config.redSize = colorBufferFormatInfo.redBits; - config.greenSize = colorBufferFormatInfo.greenBits; - config.blueSize = colorBufferFormatInfo.blueBits; - config.luminanceSize = colorBufferFormatInfo.luminanceBits; - config.alphaSize = colorBufferFormatInfo.alphaBits; - config.alphaMaskSize = 0; - config.bindToTextureRGB = - ((colorBufferFormatInfo.format == GL_RGB) && (sampleCount <= 1)); - config.bindToTextureRGBA = (((colorBufferFormatInfo.format == GL_RGBA) || - (colorBufferFormatInfo.format == GL_BGRA_EXT)) && - (sampleCount <= 1)); - config.colorBufferType = EGL_RGB_BUFFER; - config.configCaveat = EGL_NONE; - config.configID = static_cast<EGLint>(configs.size() + 1); - - // PresentPathFast may not be conformant - config.conformant = 0; - if (!mPresentPathFastEnabled) - { - // Can only support a conformant ES2 with feature level greater than 10.0. - if (mRenderer11DeviceCaps.featureLevel >= D3D_FEATURE_LEVEL_10_0) - { - config.conformant |= EGL_OPENGL_ES2_BIT; - } - - // We can only support conformant ES3 on FL 10.1+ - if (maxVersion.major >= 3) - { - config.conformant |= EGL_OPENGL_ES3_BIT_KHR; - } - } - - config.depthSize = depthStencilBufferFormatInfo.depthBits; - config.level = 0; - config.matchNativePixmap = EGL_NONE; - config.maxPBufferWidth = rendererCaps.max2DTextureSize; - config.maxPBufferHeight = rendererCaps.max2DTextureSize; - config.maxPBufferPixels = - rendererCaps.max2DTextureSize * rendererCaps.max2DTextureSize; - config.maxSwapInterval = 4; - config.minSwapInterval = 0; - config.nativeRenderable = EGL_FALSE; - config.nativeVisualID = 0; - config.nativeVisualType = EGL_NONE; - - // Can't support ES3 at all without feature level 10.1 - config.renderableType = EGL_OPENGL_ES2_BIT; - if (maxVersion.major >= 3) - { - config.renderableType |= EGL_OPENGL_ES3_BIT_KHR; - } - - config.sampleBuffers = (sampleCount == 0) ? 0 : 1; - config.samples = sampleCount; - config.stencilSize = depthStencilBufferFormatInfo.stencilBits; - config.surfaceType = - EGL_PBUFFER_BIT | EGL_WINDOW_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT; - config.transparentType = EGL_NONE; - config.transparentRedValue = 0; - config.transparentGreenValue = 0; - config.transparentBlueValue = 0; - config.optimalOrientation = optimalSurfaceOrientation; - config.colorComponentType = gl_egl::GLComponentTypeToEGLColorComponentType( - colorBufferFormatInfo.componentType); - - configs.add(config); - } - } - } - - ASSERT(configs.size() > 0); - return configs; -} - -void Renderer11::generateDisplayExtensions(egl::DisplayExtensions *outExtensions) const -{ - outExtensions->createContextRobustness = true; - - if (getShareHandleSupport()) - { - outExtensions->d3dShareHandleClientBuffer = true; - outExtensions->surfaceD3DTexture2DShareHandle = true; - } - outExtensions->d3dTextureClientBuffer = true; - - outExtensions->keyedMutex = true; - outExtensions->querySurfacePointer = true; - outExtensions->windowFixedSize = true; - - // If present path fast is active then the surface orientation extension isn't supported - outExtensions->surfaceOrientation = !mPresentPathFastEnabled; - - // D3D11 does not support present with dirty rectangles until DXGI 1.2. - outExtensions->postSubBuffer = mRenderer11DeviceCaps.supportsDXGI1_2; - - outExtensions->deviceQuery = true; - - outExtensions->image = true; - outExtensions->imageBase = true; - outExtensions->glTexture2DImage = true; - outExtensions->glTextureCubemapImage = true; - outExtensions->glRenderbufferImage = true; - - outExtensions->stream = true; - outExtensions->streamConsumerGLTexture = true; - outExtensions->streamConsumerGLTextureYUV = true; - // Not all D3D11 devices support NV12 textures - if (getNV12TextureSupport()) - { - outExtensions->streamProducerD3DTextureNV12 = true; - } - - outExtensions->flexibleSurfaceCompatibility = true; - outExtensions->directComposition = !!mDCompModule; - - // Contexts are virtualized so textures can be shared globally - outExtensions->displayTextureShareGroup = true; - - // getSyncValues requires direct composition. - outExtensions->getSyncValues = outExtensions->directComposition; - - // D3D11 can be used without a swap chain - outExtensions->surfacelessContext = true; - - // All D3D feature levels support robust resource init - outExtensions->robustResourceInitialization = true; -} - -gl::Error Renderer11::flush() -{ - mDeviceContext->Flush(); - return gl::NoError(); -} - -gl::Error Renderer11::finish() -{ - if (!mSyncQuery.valid()) - { - D3D11_QUERY_DESC queryDesc; - queryDesc.Query = D3D11_QUERY_EVENT; - queryDesc.MiscFlags = 0; - - ANGLE_TRY(allocateResource(queryDesc, &mSyncQuery)); - } - - mDeviceContext->End(mSyncQuery.get()); - - HRESULT result = S_OK; - unsigned int attempt = 0; - do - { - unsigned int flushFrequency = 100; - UINT flags = (attempt % flushFrequency == 0) ? 0 : D3D11_ASYNC_GETDATA_DONOTFLUSH; - attempt++; - - result = mDeviceContext->GetData(mSyncQuery.get(), nullptr, 0, flags); - if (FAILED(result)) - { - return gl::OutOfMemory() << "Failed to get event query data, " << gl::FmtHR(result); - } - - if (result == S_FALSE) - { - // Keep polling, but allow other threads to do something useful first - ScheduleYield(); - } - - if (testDeviceLost()) - { - mDisplay->notifyDeviceLost(); - return gl::OutOfMemory() << "Device was lost while waiting for sync."; - } - } while (result == S_FALSE); - - return gl::NoError(); -} - -bool Renderer11::isValidNativeWindow(EGLNativeWindowType window) const -{ -#ifdef ANGLE_ENABLE_WINDOWS_STORE - return NativeWindow11WinRT::IsValidNativeWindow(window); -#else - return NativeWindow11Win32::IsValidNativeWindow(window); -#endif -} - -NativeWindowD3D *Renderer11::createNativeWindow(EGLNativeWindowType window, - const egl::Config *config, - const egl::AttributeMap &attribs) const -{ -#ifdef ANGLE_ENABLE_WINDOWS_STORE - UNUSED_VARIABLE(attribs); - return new NativeWindow11WinRT(window, config->alphaSize > 0); -#else - return new NativeWindow11Win32( - window, config->alphaSize > 0, - attribs.get(EGL_DIRECT_COMPOSITION_ANGLE, EGL_FALSE) == EGL_TRUE); -#endif -} - -egl::Error Renderer11::getD3DTextureInfo(const egl::Config *configuration, - IUnknown *d3dTexture, - EGLint *width, - EGLint *height, - GLenum *fboFormat) const -{ - ID3D11Texture2D *texture = d3d11::DynamicCastComObject<ID3D11Texture2D>(d3dTexture); - if (texture == nullptr) - { - return egl::EglBadParameter() << "client buffer is not a ID3D11Texture2D"; - } - - ID3D11Device *textureDevice = nullptr; - texture->GetDevice(&textureDevice); - if (textureDevice != mDevice) - { - SafeRelease(texture); - return egl::EglBadParameter() << "Texture's device does not match."; - } - SafeRelease(textureDevice); - - D3D11_TEXTURE2D_DESC desc = {0}; - texture->GetDesc(&desc); - SafeRelease(texture); - - if (width) - { - *width = static_cast<EGLint>(desc.Width); - } - if (height) - { - *height = static_cast<EGLint>(desc.Height); - } - if (static_cast<EGLint>(desc.SampleDesc.Count) != configuration->samples) - { - // Both the texture and EGL config sample count may not be the same when multi-sampling - // is disabled. The EGL sample count can be 0 but a D3D texture is always 1. Therefore, - // we must only check for a invalid match when the EGL config is non-zero or the texture is - // not one. - if (configuration->samples != 0 || desc.SampleDesc.Count != 1) - { - return egl::EglBadParameter() << "Texture's sample count does not match."; - } - } - // From table egl.restrictions in EGL_ANGLE_d3d_texture_client_buffer. - switch (desc.Format) - { - case DXGI_FORMAT_R8G8B8A8_UNORM: - case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: - case DXGI_FORMAT_B8G8R8A8_UNORM: - case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: - case DXGI_FORMAT_R16G16B16A16_FLOAT: - case DXGI_FORMAT_R32G32B32A32_FLOAT: - break; - - default: - return egl::EglBadParameter() - << "Unknown client buffer texture format: " << desc.Format; - } - - if (fboFormat) - { - const angle::Format &angleFormat = d3d11_angle::GetFormat(desc.Format); - *fboFormat = angleFormat.fboImplementationInternalFormat; - } - - return egl::NoError(); -} - -egl::Error Renderer11::validateShareHandle(const egl::Config *config, - HANDLE shareHandle, - const egl::AttributeMap &attribs) const -{ - if (shareHandle == nullptr) - { - return egl::EglBadParameter() << "NULL share handle."; - } - - ID3D11Resource *tempResource11 = nullptr; - HRESULT result = mDevice->OpenSharedResource(shareHandle, __uuidof(ID3D11Resource), - (void **)&tempResource11); - if (FAILED(result)) - { - return egl::EglBadParameter() << "Failed to open share handle, " << gl::FmtHR(result); - } - - ID3D11Texture2D *texture2D = d3d11::DynamicCastComObject<ID3D11Texture2D>(tempResource11); - SafeRelease(tempResource11); - - if (texture2D == nullptr) - { - return egl::EglBadParameter() - << "Failed to query ID3D11Texture2D object from share handle."; - } - - D3D11_TEXTURE2D_DESC desc = {0}; - texture2D->GetDesc(&desc); - SafeRelease(texture2D); - - EGLint width = attribs.getAsInt(EGL_WIDTH, 0); - EGLint height = attribs.getAsInt(EGL_HEIGHT, 0); - ASSERT(width != 0 && height != 0); - - const d3d11::Format &backbufferFormatInfo = - d3d11::Format::Get(config->renderTargetFormat, getRenderer11DeviceCaps()); - - if (desc.Width != static_cast<UINT>(width) || desc.Height != static_cast<UINT>(height) || - desc.Format != backbufferFormatInfo.texFormat || desc.MipLevels != 1 || desc.ArraySize != 1) - { - return egl::EglBadParameter() << "Invalid texture parameters in share handle texture."; - } - - return egl::NoError(); -} - -SwapChainD3D *Renderer11::createSwapChain(NativeWindowD3D *nativeWindow, - HANDLE shareHandle, - IUnknown *d3dTexture, - GLenum backBufferFormat, - GLenum depthBufferFormat, - EGLint orientation, - EGLint samples) -{ - return new SwapChain11(this, GetAs<NativeWindow11>(nativeWindow), shareHandle, d3dTexture, - backBufferFormat, depthBufferFormat, orientation, samples); -} - -void *Renderer11::getD3DDevice() -{ - return reinterpret_cast<void *>(mDevice); -} - -bool Renderer11::applyPrimitiveType(const gl::State &glState, GLenum mode, GLsizei count) -{ - D3D11_PRIMITIVE_TOPOLOGY primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; - - GLsizei minCount = 0; - - switch (mode) - { - case GL_POINTS: - { - bool usesPointSize = GetImplAs<ProgramD3D>(glState.getProgram())->usesPointSize(); - - // ProgramBinary assumes non-point rendering if gl_PointSize isn't written, - // which affects varying interpolation. Since the value of gl_PointSize is - // undefined when not written, just skip drawing to avoid unexpected results. - if (!usesPointSize && !glState.isTransformFeedbackActiveUnpaused()) - { - // Notify developers of risking undefined behavior. - WARN() << "Point rendering without writing to gl_PointSize."; - return false; - } - - // If instanced pointsprites are enabled and the shader uses gl_PointSize, the topology - // must be D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST. - if (usesPointSize && getWorkarounds().useInstancedPointSpriteEmulation) - { - primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; - } - else - { - primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_POINTLIST; - } - minCount = 1; - break; - } - case GL_LINES: - primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINELIST; - minCount = 2; - break; - case GL_LINE_LOOP: - primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP; - minCount = 2; - break; - case GL_LINE_STRIP: - primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP; - minCount = 2; - break; - case GL_TRIANGLES: - primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; - minCount = CullsEverything(glState) ? std::numeric_limits<GLsizei>::max() : 3; - break; - case GL_TRIANGLE_STRIP: - primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; - minCount = CullsEverything(glState) ? std::numeric_limits<GLsizei>::max() : 3; - break; - // emulate fans via rewriting index buffer - case GL_TRIANGLE_FAN: - primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; - minCount = CullsEverything(glState) ? std::numeric_limits<GLsizei>::max() : 3; - break; - default: - UNREACHABLE(); - return false; - } - - mStateManager.setPrimitiveTopology(primitiveTopology); - - return count >= minCount; -} - -gl::Error Renderer11::drawArrays(const gl::Context *context, - GLenum mode, - GLint startVertex, - GLsizei count, - GLsizei instances) -{ - const auto &glState = context->getGLState(); - - if (!applyPrimitiveType(glState, mode, count)) - { - return gl::NoError(); - } - - DrawCallVertexParams vertexParams(startVertex, count, instances); - ANGLE_TRY(mStateManager.applyVertexBuffer(context, mode, vertexParams, false)); - - if (glState.isTransformFeedbackActiveUnpaused()) - { - ANGLE_TRY(markTransformFeedbackUsage(context)); - } - - gl::Program *program = glState.getProgram(); - ASSERT(program != nullptr); - GLsizei adjustedInstanceCount = GetAdjustedInstanceCount(program, instances); - ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program); - - if (programD3D->usesGeometryShader(mode) && glState.isTransformFeedbackActiveUnpaused()) - { - // Since we use a geometry if-and-only-if we rewrite vertex streams, transform feedback - // won't get the correct output. To work around this, draw with *only* the stream out - // first (no pixel shader) to feed the stream out buffers and then draw again with the - // geometry shader + pixel shader to rasterize the primitives. - mStateManager.setPixelShader(nullptr); - - if (adjustedInstanceCount > 0) - { - mDeviceContext->DrawInstanced(count, adjustedInstanceCount, 0, 0); - } - else - { - mDeviceContext->Draw(count, 0); - } - - rx::ShaderExecutableD3D *pixelExe = nullptr; - ANGLE_TRY(programD3D->getPixelExecutableForCachedOutputLayout(&pixelExe, nullptr)); - - // Skip the draw call if rasterizer discard is enabled (or no fragment shader). - if (!pixelExe || glState.getRasterizerState().rasterizerDiscard) - { - return gl::NoError(); - } - - mStateManager.setPixelShader(&GetAs<ShaderExecutable11>(pixelExe)->getPixelShader()); - - // Retrieve the geometry shader. - rx::ShaderExecutableD3D *geometryExe = nullptr; - ANGLE_TRY(programD3D->getGeometryExecutableForPrimitiveType(context, mode, &geometryExe, - nullptr)); - - mStateManager.setGeometryShader( - &GetAs<ShaderExecutable11>(geometryExe)->getGeometryShader()); - - if (adjustedInstanceCount > 0) - { - mDeviceContext->DrawInstanced(count, adjustedInstanceCount, 0, 0); - } - else - { - mDeviceContext->Draw(count, 0); - } - return gl::NoError(); - } - - if (mode == GL_LINE_LOOP) - { - return drawLineLoop(context, count, GL_NONE, nullptr, 0, adjustedInstanceCount); - } - - if (mode == GL_TRIANGLE_FAN) - { - return drawTriangleFan(context, count, GL_NONE, nullptr, 0, adjustedInstanceCount); - } - - bool useInstancedPointSpriteEmulation = - programD3D->usesPointSize() && getWorkarounds().useInstancedPointSpriteEmulation; - - if (mode != GL_POINTS || !useInstancedPointSpriteEmulation) - { - if (adjustedInstanceCount == 0) - { - mDeviceContext->Draw(count, 0); - } - else - { - mDeviceContext->DrawInstanced(count, adjustedInstanceCount, 0, 0); - } - return gl::NoError(); - } - - // This code should not be reachable by multi-view programs. - ASSERT(program->usesMultiview() == false); - - // If the shader is writing to gl_PointSize, then pointsprites are being rendered. - // Emulating instanced point sprites for FL9_3 requires the topology to be - // D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST and DrawIndexedInstanced is called instead. - if (adjustedInstanceCount == 0) - { - mDeviceContext->DrawIndexedInstanced(6, count, 0, 0, 0); - return gl::NoError(); - } - - // If pointsprite emulation is used with glDrawArraysInstanced then we need to take a less - // efficent code path. Instanced rendering of emulated pointsprites requires a loop to draw each - // batch of points. An offset into the instanced data buffer is calculated and applied on each - // iteration to ensure all instances are rendered correctly. Each instance being rendered - // requires the inputlayout cache to reapply buffers and offsets. - for (GLsizei i = 0; i < instances; i++) - { - ANGLE_TRY(mStateManager.updateVertexOffsetsForPointSpritesEmulation(startVertex, i)); - mDeviceContext->DrawIndexedInstanced(6, count, 0, 0, 0); - } - - // This required by updateVertexOffsets... above but is outside of the loop for speed. - mStateManager.invalidateVertexBuffer(); - return gl::NoError(); -} - -gl::Error Renderer11::drawElements(const gl::Context *context, - GLenum mode, - GLsizei count, - GLenum type, - const void *indices, - GLsizei instances) -{ - const auto &glState = context->getGLState(); - - if (!applyPrimitiveType(glState, mode, count)) - { - return gl::NoError(); - } - - // Transform feedback is not allowed for DrawElements, this error should have been caught at the - // API validation layer. - ASSERT(!glState.isTransformFeedbackActiveUnpaused()); - - const auto &lazyIndexRange = context->getParams<gl::HasIndexRange>(); - - bool usePrimitiveRestartWorkaround = - UsePrimitiveRestartWorkaround(glState.isPrimitiveRestartEnabled(), type); - DrawCallVertexParams vertexParams(!usePrimitiveRestartWorkaround, lazyIndexRange, 0, instances); - - ANGLE_TRY(mStateManager.applyIndexBuffer(context, indices, count, type, lazyIndexRange, - usePrimitiveRestartWorkaround)); - ANGLE_TRY(mStateManager.applyVertexBuffer(context, mode, vertexParams, true)); - - int startVertex = static_cast<int>(vertexParams.firstVertex()); - int baseVertex = -startVertex; - - const gl::Program *program = glState.getProgram(); - GLsizei adjustedInstanceCount = GetAdjustedInstanceCount(program, instances); - - if (mode == GL_LINE_LOOP) - { - return drawLineLoop(context, count, type, indices, baseVertex, adjustedInstanceCount); - } - - if (mode == GL_TRIANGLE_FAN) - { - return drawTriangleFan(context, count, type, indices, baseVertex, adjustedInstanceCount); - } - - const ProgramD3D *programD3D = GetImplAs<ProgramD3D>(glState.getProgram()); - - if (mode != GL_POINTS || !programD3D->usesInstancedPointSpriteEmulation()) - { - if (adjustedInstanceCount == 0) - { - mDeviceContext->DrawIndexed(count, 0, baseVertex); - } - else - { - mDeviceContext->DrawIndexedInstanced(count, adjustedInstanceCount, 0, baseVertex, 0); - } - return gl::NoError(); - } - - // This code should not be reachable by multi-view programs. - ASSERT(program->usesMultiview() == false); - - // If the shader is writing to gl_PointSize, then pointsprites are being rendered. - // Emulating instanced point sprites for FL9_3 requires the topology to be - // D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST and DrawIndexedInstanced is called instead. - // - // The count parameter passed to drawElements represents the total number of instances to be - // rendered. Each instance is referenced by the bound index buffer from the the caller. - // - // Indexed pointsprite emulation replicates data for duplicate entries found in the index - // buffer. This is not an efficent rendering mechanism and is only used on downlevel renderers - // that do not support geometry shaders. - if (instances == 0) - { - mDeviceContext->DrawIndexedInstanced(6, count, 0, 0, 0); - return gl::NoError(); - } - - // If pointsprite emulation is used with glDrawElementsInstanced then we need to take a less - // efficent code path. Instanced rendering of emulated pointsprites requires a loop to draw each - // batch of points. An offset into the instanced data buffer is calculated and applied on each - // iteration to ensure all instances are rendered correctly. - GLsizei elementsToRender = vertexParams.vertexCount(); - - // Each instance being rendered requires the inputlayout cache to reapply buffers and offsets. - for (GLsizei i = 0; i < instances; i++) - { - ANGLE_TRY(mStateManager.updateVertexOffsetsForPointSpritesEmulation(startVertex, i)); - mDeviceContext->DrawIndexedInstanced(6, elementsToRender, 0, 0, 0); - } - mStateManager.invalidateVertexBuffer(); - return gl::NoError(); -} - -gl::Error Renderer11::drawArraysIndirect(const gl::Context *context, - GLenum mode, - const void *indirect) -{ - const auto &glState = context->getGLState(); - ASSERT(!glState.isTransformFeedbackActiveUnpaused()); - - if (!applyPrimitiveType(glState, mode, std::numeric_limits<int>::max() - 1)) - { - return gl::NoError(); - } - - gl::Buffer *drawIndirectBuffer = glState.getTargetBuffer(gl::BufferBinding::DrawIndirect); - ASSERT(drawIndirectBuffer); - Buffer11 *storage = GetImplAs<Buffer11>(drawIndirectBuffer); - uintptr_t offset = reinterpret_cast<uintptr_t>(indirect); - - if (!DrawCallNeedsTranslation(context, mode)) - { - DrawCallVertexParams vertexParams(0, 0, 0); - ANGLE_TRY(mStateManager.applyVertexBuffer(context, mode, vertexParams, false)); - ID3D11Buffer *buffer = nullptr; - ANGLE_TRY_RESULT(storage->getBuffer(context, BUFFER_USAGE_INDIRECT), buffer); - mDeviceContext->DrawInstancedIndirect(buffer, static_cast<unsigned int>(offset)); - return gl::NoError(); - } - - const uint8_t *bufferData = nullptr; - ANGLE_TRY(storage->getData(context, &bufferData)); - ASSERT(bufferData); - const gl::DrawArraysIndirectCommand *args = - reinterpret_cast<const gl::DrawArraysIndirectCommand *>(bufferData + offset); - GLuint count = args->count; - GLuint instances = args->instanceCount; - GLuint first = args->first; - - DrawCallVertexParams vertexParams(first, count, instances); - ANGLE_TRY(mStateManager.applyVertexBuffer(context, mode, vertexParams, false)); - - if (mode == GL_LINE_LOOP) - { - return drawLineLoop(context, count, GL_NONE, nullptr, 0, instances); - } - if (mode == GL_TRIANGLE_FAN) - { - return drawTriangleFan(context, count, GL_NONE, nullptr, 0, instances); - } - - mDeviceContext->DrawInstanced(count, instances, 0, 0); - return gl::NoError(); -} - -gl::Error Renderer11::drawElementsIndirect(const gl::Context *context, - GLenum mode, - GLenum type, - const void *indirect) -{ - const auto &glState = context->getGLState(); - ASSERT(!glState.isTransformFeedbackActiveUnpaused()); - - if (!applyPrimitiveType(glState, mode, std::numeric_limits<int>::max() - 1)) - { - return gl::NoError(); - } - - gl::Buffer *drawIndirectBuffer = glState.getTargetBuffer(gl::BufferBinding::DrawIndirect); - ASSERT(drawIndirectBuffer); - Buffer11 *storage = GetImplAs<Buffer11>(drawIndirectBuffer); - uintptr_t offset = reinterpret_cast<uintptr_t>(indirect); - - // TODO(jmadill): Remove the if statement and compute indirect parameters lazily. - bool usePrimitiveRestartWorkaround = - UsePrimitiveRestartWorkaround(glState.isPrimitiveRestartEnabled(), type); - - if (!DrawCallNeedsTranslation(context, mode) && !IsStreamingIndexData(context, type)) - { - ANGLE_TRY(mStateManager.applyIndexBuffer(context, nullptr, 0, type, gl::HasIndexRange(), - usePrimitiveRestartWorkaround)); - DrawCallVertexParams vertexParams(0, 0, 0); - ANGLE_TRY(mStateManager.applyVertexBuffer(context, mode, vertexParams, true)); - ID3D11Buffer *buffer = nullptr; - ANGLE_TRY_RESULT(storage->getBuffer(context, BUFFER_USAGE_INDIRECT), buffer); - mDeviceContext->DrawIndexedInstancedIndirect(buffer, static_cast<unsigned int>(offset)); - return gl::NoError(); - } - - const uint8_t *bufferData = nullptr; - ANGLE_TRY(storage->getData(context, &bufferData)); - ASSERT(bufferData); - - const gl::DrawElementsIndirectCommand *cmd = - reinterpret_cast<const gl::DrawElementsIndirectCommand *>(bufferData + offset); - GLsizei count = cmd->count; - GLuint instances = cmd->primCount; - GLuint firstIndex = cmd->firstIndex; - GLint baseVertex = cmd->baseVertex; - - // TODO(jmadill): Fix const cast. - const gl::Type &typeInfo = gl::GetTypeInfo(type); - const void *indices = - reinterpret_cast<const void *>(static_cast<uintptr_t>(firstIndex * typeInfo.bytes)); - gl::HasIndexRange lazyIndexRange(const_cast<gl::Context *>(context), count, type, indices); - - ANGLE_TRY(mStateManager.applyIndexBuffer(context, indices, count, type, lazyIndexRange, - usePrimitiveRestartWorkaround)); - - DrawCallVertexParams vertexParams(false, lazyIndexRange, baseVertex, instances); - - ANGLE_TRY(mStateManager.applyVertexBuffer(context, mode, vertexParams, true)); - - int baseVertexLocation = -static_cast<int>(lazyIndexRange.getIndexRange().value().start); - - if (mode == GL_LINE_LOOP) - { - return drawLineLoop(context, count, type, indices, baseVertexLocation, instances); - } - - if (mode == GL_TRIANGLE_FAN) - { - return drawTriangleFan(context, count, type, indices, baseVertexLocation, instances); - } - - mDeviceContext->DrawIndexedInstanced(count, instances, 0, baseVertexLocation, 0); - return gl::NoError(); -} - -gl::Error Renderer11::drawLineLoop(const gl::Context *context, - GLsizei count, - GLenum type, - const void *indexPointer, - int baseVertex, - int instances) -{ - const gl::State &glState = context->getGLState(); - gl::VertexArray *vao = glState.getVertexArray(); - gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get(); - - const void *indices = indexPointer; - - // Get the raw indices for an indexed draw - if (type != GL_NONE && elementArrayBuffer) - { - BufferD3D *storage = GetImplAs<BufferD3D>(elementArrayBuffer); - intptr_t offset = reinterpret_cast<intptr_t>(indices); - - const uint8_t *bufferData = nullptr; - ANGLE_TRY(storage->getData(context, &bufferData)); - - indices = bufferData + offset; - } - - if (!mLineLoopIB) - { - mLineLoopIB = new StreamingIndexBufferInterface(this); - gl::Error error = - mLineLoopIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT); - if (error.isError()) - { - SafeDelete(mLineLoopIB); - return error; - } - } - - // Checked by Renderer11::applyPrimitiveType - ASSERT(count >= 0); - - if (static_cast<unsigned int>(count) + 1 > - (std::numeric_limits<unsigned int>::max() / sizeof(unsigned int))) - { - return gl::OutOfMemory() << "Failed to create a 32-bit looping index buffer for " - "GL_LINE_LOOP, too many indices required."; - } - - GetLineLoopIndices(indices, type, static_cast<GLuint>(count), - glState.isPrimitiveRestartEnabled(), &mScratchIndexDataBuffer); - - unsigned int spaceNeeded = - static_cast<unsigned int>(sizeof(GLuint) * mScratchIndexDataBuffer.size()); - ANGLE_TRY(mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT)); - - void *mappedMemory = nullptr; - unsigned int offset; - ANGLE_TRY(mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory, &offset)); - - // Copy over the converted index data. - memcpy(mappedMemory, &mScratchIndexDataBuffer[0], - sizeof(GLuint) * mScratchIndexDataBuffer.size()); - - ANGLE_TRY(mLineLoopIB->unmapBuffer()); - - IndexBuffer11 *indexBuffer = GetAs<IndexBuffer11>(mLineLoopIB->getIndexBuffer()); - const d3d11::Buffer &d3dIndexBuffer = indexBuffer->getBuffer(); - DXGI_FORMAT indexFormat = indexBuffer->getIndexFormat(); - - mStateManager.setIndexBuffer(d3dIndexBuffer.get(), indexFormat, offset); - - UINT indexCount = static_cast<UINT>(mScratchIndexDataBuffer.size()); - - if (instances > 0) - { - mDeviceContext->DrawIndexedInstanced(indexCount, instances, 0, baseVertex, 0); - } - else - { - mDeviceContext->DrawIndexed(indexCount, 0, baseVertex); - } - - return gl::NoError(); -} - -gl::Error Renderer11::drawTriangleFan(const gl::Context *context, - GLsizei count, - GLenum type, - const void *indices, - int baseVertex, - int instances) -{ - const gl::State &glState = context->getGLState(); - gl::VertexArray *vao = glState.getVertexArray(); - gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get(); - - const void *indexPointer = indices; - - // Get the raw indices for an indexed draw - if (type != GL_NONE && elementArrayBuffer) - { - BufferD3D *storage = GetImplAs<BufferD3D>(elementArrayBuffer); - intptr_t offset = reinterpret_cast<intptr_t>(indices); - - const uint8_t *bufferData = nullptr; - ANGLE_TRY(storage->getData(context, &bufferData)); - - indexPointer = bufferData + offset; - } - - if (!mTriangleFanIB) - { - mTriangleFanIB = new StreamingIndexBufferInterface(this); - gl::Error error = - mTriangleFanIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT); - if (error.isError()) - { - SafeDelete(mTriangleFanIB); - return error; - } - } - - // Checked by Renderer11::applyPrimitiveType - ASSERT(count >= 3); - - const GLuint numTris = count - 2; - - if (numTris > (std::numeric_limits<unsigned int>::max() / (sizeof(unsigned int) * 3))) - { - return gl::OutOfMemory() << "Failed to create a scratch index buffer for GL_TRIANGLE_FAN, " - "too many indices required."; - } - - GetTriFanIndices(indexPointer, type, count, glState.isPrimitiveRestartEnabled(), - &mScratchIndexDataBuffer); - - const unsigned int spaceNeeded = - static_cast<unsigned int>(mScratchIndexDataBuffer.size() * sizeof(unsigned int)); - ANGLE_TRY(mTriangleFanIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT)); - - void *mappedMemory = nullptr; - unsigned int offset; - ANGLE_TRY(mTriangleFanIB->mapBuffer(spaceNeeded, &mappedMemory, &offset)); - - memcpy(mappedMemory, &mScratchIndexDataBuffer[0], spaceNeeded); - - ANGLE_TRY(mTriangleFanIB->unmapBuffer()); - - IndexBuffer11 *indexBuffer = GetAs<IndexBuffer11>(mTriangleFanIB->getIndexBuffer()); - const d3d11::Buffer &d3dIndexBuffer = indexBuffer->getBuffer(); - DXGI_FORMAT indexFormat = indexBuffer->getIndexFormat(); - - mStateManager.setIndexBuffer(d3dIndexBuffer.get(), indexFormat, offset); - - UINT indexCount = static_cast<UINT>(mScratchIndexDataBuffer.size()); - - if (instances > 0) - { - mDeviceContext->DrawIndexedInstanced(indexCount, instances, 0, baseVertex, 0); - } - else - { - mDeviceContext->DrawIndexed(indexCount, 0, baseVertex); - } - - return gl::NoError(); -} - -void Renderer11::releaseDeviceResources() -{ - mStateManager.deinitialize(); - mStateCache.clear(); - - SafeDelete(mLineLoopIB); - SafeDelete(mTriangleFanIB); - SafeDelete(mBlit); - SafeDelete(mClear); - SafeDelete(mTrim); - SafeDelete(mPixelTransfer); - - mSyncQuery.reset(); - - mCachedResolveTexture.reset(); -} - -// set notify to true to broadcast a message to all contexts of the device loss -bool Renderer11::testDeviceLost() -{ - bool isLost = false; - - if (!mDevice) - { - return true; - } - - // GetRemovedReason is used to test if the device is removed - HRESULT result = mDevice->GetDeviceRemovedReason(); - isLost = d3d11::isDeviceLostError(result); - - if (isLost) - { - ERR() << "The D3D11 device was removed, " << gl::FmtHR(result); - } - - return isLost; -} - -bool Renderer11::testDeviceResettable() -{ - // determine if the device is resettable by creating a dummy device - PFN_D3D11_CREATE_DEVICE D3D11CreateDevice = - (PFN_D3D11_CREATE_DEVICE)GetProcAddress(mD3d11Module, "D3D11CreateDevice"); - - if (D3D11CreateDevice == nullptr) - { - return false; - } - - ID3D11Device *dummyDevice; - D3D_FEATURE_LEVEL dummyFeatureLevel; - ID3D11DeviceContext *dummyContext; - UINT flags = (mCreateDebugDevice ? D3D11_CREATE_DEVICE_DEBUG : 0); - - ASSERT(mRequestedDriverType != D3D_DRIVER_TYPE_UNKNOWN); - HRESULT result = D3D11CreateDevice( - nullptr, mRequestedDriverType, nullptr, flags, mAvailableFeatureLevels.data(), - static_cast<unsigned int>(mAvailableFeatureLevels.size()), D3D11_SDK_VERSION, &dummyDevice, - &dummyFeatureLevel, &dummyContext); - - if (!mDevice || FAILED(result)) - { - return false; - } - - SafeRelease(dummyContext); - SafeRelease(dummyDevice); - - return true; -} - -void Renderer11::release() -{ - RendererD3D::cleanup(); - - mScratchMemoryBuffer.clear(); - - if (mAnnotator != nullptr) - { - gl::UninitializeDebugAnnotations(); - SafeDelete(mAnnotator); - } - - releaseDeviceResources(); - - if (!mCreatedWithDeviceEXT) - { - // Only delete the device if the Renderer11 owns it - // Otherwise we should keep it around in case we try to reinitialize the renderer later - SafeDelete(mEGLDevice); - } - - SafeRelease(mDxgiFactory); - SafeRelease(mDxgiAdapter); - - SafeRelease(mDeviceContext3); - SafeRelease(mDeviceContext1); - - if (mDeviceContext) - { - mDeviceContext->ClearState(); - mDeviceContext->Flush(); - SafeRelease(mDeviceContext); - } - - SafeRelease(mDevice); - SafeRelease(mDebug); - - if (mD3d11Module) - { - FreeLibrary(mD3d11Module); - mD3d11Module = nullptr; - } - - if (mDxgiModule) - { - FreeLibrary(mDxgiModule); - mDxgiModule = nullptr; - } - - if (mDCompModule) - { - FreeLibrary(mDCompModule); - mDCompModule = nullptr; - } - - mCompiler.release(); - - mSupportsShareHandles.reset(); -} - -bool Renderer11::resetDevice() -{ - // recreate everything - release(); - egl::Error result = initialize(); - - if (result.isError()) - { - ERR() << "Could not reinitialize D3D11 device: " << result; - return false; - } - - return true; -} - -std::string Renderer11::getRendererDescription() const -{ - std::ostringstream rendererString; - - rendererString << mDescription; - rendererString << " Direct3D11"; - - rendererString << " vs_" << getMajorShaderModel() << "_" << getMinorShaderModel() - << getShaderModelSuffix(); - rendererString << " ps_" << getMajorShaderModel() << "_" << getMinorShaderModel() - << getShaderModelSuffix(); - - return rendererString.str(); -} - -DeviceIdentifier Renderer11::getAdapterIdentifier() const -{ - // Don't use the AdapterLuid here, since that doesn't persist across reboot. - DeviceIdentifier deviceIdentifier = {0}; - deviceIdentifier.VendorId = mAdapterDescription.VendorId; - deviceIdentifier.DeviceId = mAdapterDescription.DeviceId; - deviceIdentifier.SubSysId = mAdapterDescription.SubSysId; - deviceIdentifier.Revision = mAdapterDescription.Revision; - deviceIdentifier.FeatureLevel = static_cast<UINT>(mRenderer11DeviceCaps.featureLevel); - - return deviceIdentifier; -} - -unsigned int Renderer11::getReservedVertexUniformVectors() const -{ - // Driver uniforms are stored in a separate constant buffer - return d3d11_gl::GetReservedVertexUniformVectors(mRenderer11DeviceCaps.featureLevel); -} - -unsigned int Renderer11::getReservedFragmentUniformVectors() const -{ - // Driver uniforms are stored in a separate constant buffer - return d3d11_gl::GetReservedFragmentUniformVectors(mRenderer11DeviceCaps.featureLevel); -} - -unsigned int Renderer11::getReservedVertexUniformBuffers() const -{ - // we reserve one buffer for the application uniforms, and one for driver uniforms - return 2; -} - -unsigned int Renderer11::getReservedFragmentUniformBuffers() const -{ - // we reserve one buffer for the application uniforms, and one for driver uniforms - return 2; -} - -d3d11::ANGLED3D11DeviceType Renderer11::getDeviceType() const -{ - if (mCreatedWithDeviceEXT) - { - return d3d11::GetDeviceType(mDevice); - } - - if ((mRequestedDriverType == D3D_DRIVER_TYPE_SOFTWARE) || - (mRequestedDriverType == D3D_DRIVER_TYPE_REFERENCE) || - (mRequestedDriverType == D3D_DRIVER_TYPE_NULL)) - { - return d3d11::ANGLE_D3D11_DEVICE_TYPE_SOFTWARE_REF_OR_NULL; - } - - if (mRequestedDriverType == D3D_DRIVER_TYPE_WARP) - { - return d3d11::ANGLE_D3D11_DEVICE_TYPE_WARP; - } - - return d3d11::ANGLE_D3D11_DEVICE_TYPE_HARDWARE; -} - -bool Renderer11::getShareHandleSupport() const -{ - if (mSupportsShareHandles.valid()) - { - return mSupportsShareHandles.value(); - } - - // We only currently support share handles with BGRA surfaces, because - // chrome needs BGRA. Once chrome fixes this, we should always support them. - if (!getNativeExtensions().textureFormatBGRA8888) - { - mSupportsShareHandles = false; - return false; - } - - // PIX doesn't seem to support using share handles, so disable them. - if (gl::DebugAnnotationsActive()) - { - mSupportsShareHandles = false; - return false; - } - - // Qt: we don't care about the 9_3 limitation -#if 0 - // Also disable share handles on Feature Level 9_3, since it doesn't support share handles on - // RGBA8 textures/swapchains. - if (mRenderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3) - { - mSupportsShareHandles = false; - return false; - } -#endif - - // Find out which type of D3D11 device the Renderer11 is using - d3d11::ANGLED3D11DeviceType deviceType = getDeviceType(); - if (deviceType == d3d11::ANGLE_D3D11_DEVICE_TYPE_UNKNOWN) - { - mSupportsShareHandles = false; - return false; - } - - if (deviceType == d3d11::ANGLE_D3D11_DEVICE_TYPE_SOFTWARE_REF_OR_NULL) - { - // Software/Reference/NULL devices don't support share handles - mSupportsShareHandles = false; - return false; - } - - if (deviceType == d3d11::ANGLE_D3D11_DEVICE_TYPE_WARP) - { -#ifndef ANGLE_ENABLE_WINDOWS_STORE - if (!IsWindows8OrGreater()) - { - // WARP on Windows 7 doesn't support shared handles - mSupportsShareHandles = false; - return false; - } -#endif // ANGLE_ENABLE_WINDOWS_STORE - - // WARP on Windows 8.0+ supports shared handles when shared with another WARP device - // TODO: allow applications to query for HARDWARE or WARP-specific share handles, - // to prevent them trying to use a WARP share handle with an a HW device (or - // vice-versa) - // e.g. by creating EGL_D3D11_[HARDWARE/WARP]_DEVICE_SHARE_HANDLE_ANGLE - mSupportsShareHandles = true; - return true; - } - - ASSERT(mCreatedWithDeviceEXT || mRequestedDriverType == D3D_DRIVER_TYPE_HARDWARE); - mSupportsShareHandles = true; - return true; -} - -bool Renderer11::getNV12TextureSupport() const -{ - HRESULT result; - UINT formatSupport; - result = mDevice->CheckFormatSupport(DXGI_FORMAT_NV12, &formatSupport); - if (result == E_FAIL) - { - return false; - } - return (formatSupport & D3D11_FORMAT_SUPPORT_TEXTURE2D) != 0; -} - -int Renderer11::getMajorShaderModel() const -{ - switch (mRenderer11DeviceCaps.featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_SHADER_MAJOR_VERSION; // 5 - case D3D_FEATURE_LEVEL_10_1: - return D3D10_1_SHADER_MAJOR_VERSION; // 4 - case D3D_FEATURE_LEVEL_10_0: - return D3D10_SHADER_MAJOR_VERSION; // 4 - case D3D_FEATURE_LEVEL_9_3: - return D3D10_SHADER_MAJOR_VERSION; // 4 - default: - UNREACHABLE(); - return 0; - } -} - -int Renderer11::getMinorShaderModel() const -{ - switch (mRenderer11DeviceCaps.featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_SHADER_MINOR_VERSION; // 0 - case D3D_FEATURE_LEVEL_10_1: - return D3D10_1_SHADER_MINOR_VERSION; // 1 - case D3D_FEATURE_LEVEL_10_0: - return D3D10_SHADER_MINOR_VERSION; // 0 - case D3D_FEATURE_LEVEL_9_3: - return D3D10_SHADER_MINOR_VERSION; // 0 - default: - UNREACHABLE(); - return 0; - } -} - -std::string Renderer11::getShaderModelSuffix() const -{ - switch (mRenderer11DeviceCaps.featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return ""; - case D3D_FEATURE_LEVEL_10_1: - return ""; - case D3D_FEATURE_LEVEL_10_0: - return ""; - case D3D_FEATURE_LEVEL_9_3: - return "_level_9_3"; - default: - UNREACHABLE(); - return ""; - } -} - -const angle::WorkaroundsD3D &RendererD3D::getWorkarounds() const -{ - if (!mWorkaroundsInitialized) - { - mWorkarounds = generateWorkarounds(); - mWorkaroundsInitialized = true; - } - - return mWorkarounds; -} - -gl::Error Renderer11::copyImageInternal(const gl::Context *context, - const gl::Framebuffer *framebuffer, - const gl::Rectangle &sourceRect, - GLenum destFormat, - const gl::Offset &destOffset, - RenderTargetD3D *destRenderTarget) -{ - const gl::FramebufferAttachment *colorAttachment = framebuffer->getReadColorbuffer(); - ASSERT(colorAttachment); - - RenderTarget11 *sourceRenderTarget = nullptr; - ANGLE_TRY(colorAttachment->getRenderTarget(context, &sourceRenderTarget)); - ASSERT(sourceRenderTarget); - - const d3d11::SharedSRV &source = sourceRenderTarget->getBlitShaderResourceView(); - ASSERT(source.valid()); - - const d3d11::RenderTargetView &dest = - GetAs<RenderTarget11>(destRenderTarget)->getRenderTargetView(); - ASSERT(dest.valid()); - - gl::Box sourceArea(sourceRect.x, sourceRect.y, 0, sourceRect.width, sourceRect.height, 1); - gl::Extents sourceSize(sourceRenderTarget->getWidth(), sourceRenderTarget->getHeight(), 1); - - const bool invertSource = UsePresentPathFast(this, colorAttachment); - if (invertSource) - { - sourceArea.y = sourceSize.height - sourceRect.y; - sourceArea.height = -sourceArea.height; - } - - gl::Box destArea(destOffset.x, destOffset.y, 0, sourceRect.width, sourceRect.height, 1); - gl::Extents destSize(destRenderTarget->getWidth(), destRenderTarget->getHeight(), 1); - - // Use nearest filtering because source and destination are the same size for the direct copy. - // Convert to the unsized format before calling copyTexture. - GLenum sourceFormat = colorAttachment->getFormat().info->format; - ANGLE_TRY(mBlit->copyTexture(context, source, sourceArea, sourceSize, sourceFormat, dest, - destArea, destSize, nullptr, gl::GetUnsizedFormat(destFormat), - GL_NEAREST, false, false, false)); - - return gl::NoError(); -} - -gl::Error Renderer11::copyImage2D(const gl::Context *context, - const gl::Framebuffer *framebuffer, - const gl::Rectangle &sourceRect, - GLenum destFormat, - const gl::Offset &destOffset, - TextureStorage *storage, - GLint level) -{ - TextureStorage11_2D *storage11 = GetAs<TextureStorage11_2D>(storage); - ASSERT(storage11); - - gl::ImageIndex index = gl::ImageIndex::Make2D(level); - RenderTargetD3D *destRenderTarget = nullptr; - ANGLE_TRY(storage11->getRenderTarget(context, index, &destRenderTarget)); - ASSERT(destRenderTarget); - - ANGLE_TRY(copyImageInternal(context, framebuffer, sourceRect, destFormat, destOffset, - destRenderTarget)); - - storage11->markLevelDirty(level); - - return gl::NoError(); -} - -gl::Error Renderer11::copyImageCube(const gl::Context *context, - const gl::Framebuffer *framebuffer, - const gl::Rectangle &sourceRect, - GLenum destFormat, - const gl::Offset &destOffset, - TextureStorage *storage, - GLenum target, - GLint level) -{ - TextureStorage11_Cube *storage11 = GetAs<TextureStorage11_Cube>(storage); - ASSERT(storage11); - - gl::ImageIndex index = gl::ImageIndex::MakeCube(target, level); - RenderTargetD3D *destRenderTarget = nullptr; - ANGLE_TRY(storage11->getRenderTarget(context, index, &destRenderTarget)); - ASSERT(destRenderTarget); - - ANGLE_TRY(copyImageInternal(context, framebuffer, sourceRect, destFormat, destOffset, - destRenderTarget)); - - storage11->markLevelDirty(level); - - return gl::NoError(); -} - -gl::Error Renderer11::copyImage3D(const gl::Context *context, - const gl::Framebuffer *framebuffer, - const gl::Rectangle &sourceRect, - GLenum destFormat, - const gl::Offset &destOffset, - TextureStorage *storage, - GLint level) -{ - TextureStorage11_3D *storage11 = GetAs<TextureStorage11_3D>(storage); - ASSERT(storage11); - - gl::ImageIndex index = gl::ImageIndex::Make3D(level, destOffset.z); - RenderTargetD3D *destRenderTarget = nullptr; - ANGLE_TRY(storage11->getRenderTarget(context, index, &destRenderTarget)); - ASSERT(destRenderTarget); - - ANGLE_TRY(copyImageInternal(context, framebuffer, sourceRect, destFormat, destOffset, - destRenderTarget)); - - storage11->markLevelDirty(level); - - return gl::NoError(); -} - -gl::Error Renderer11::copyImage2DArray(const gl::Context *context, - const gl::Framebuffer *framebuffer, - const gl::Rectangle &sourceRect, - GLenum destFormat, - const gl::Offset &destOffset, - TextureStorage *storage, - GLint level) -{ - TextureStorage11_2DArray *storage11 = GetAs<TextureStorage11_2DArray>(storage); - ASSERT(storage11); - - gl::ImageIndex index = gl::ImageIndex::Make2DArray(level, destOffset.z); - RenderTargetD3D *destRenderTarget = nullptr; - ANGLE_TRY(storage11->getRenderTarget(context, index, &destRenderTarget)); - ASSERT(destRenderTarget); - - ANGLE_TRY(copyImageInternal(context, framebuffer, sourceRect, destFormat, destOffset, - destRenderTarget)); - storage11->markLevelDirty(level); - - return gl::NoError(); -} - -gl::Error Renderer11::copyTexture(const gl::Context *context, - const gl::Texture *source, - GLint sourceLevel, - const gl::Rectangle &sourceRect, - GLenum destFormat, - const gl::Offset &destOffset, - TextureStorage *storage, - GLenum destTarget, - GLint destLevel, - bool unpackFlipY, - bool unpackPremultiplyAlpha, - bool unpackUnmultiplyAlpha) -{ - TextureD3D *sourceD3D = GetImplAs<TextureD3D>(source); - - TextureStorage *sourceStorage = nullptr; - ANGLE_TRY(sourceD3D->getNativeTexture(context, &sourceStorage)); - - TextureStorage11_2D *sourceStorage11 = GetAs<TextureStorage11_2D>(sourceStorage); - ASSERT(sourceStorage11); - - TextureStorage11 *destStorage11 = GetAs<TextureStorage11>(storage); - ASSERT(destStorage11); - - // Check for fast path where a CopySubresourceRegion can be used. - if (unpackPremultiplyAlpha == unpackUnmultiplyAlpha && !unpackFlipY && - source->getFormat(GL_TEXTURE_2D, sourceLevel).info->format == destFormat && - sourceStorage11->getFormatSet().texFormat == destStorage11->getFormatSet().texFormat) - { - const TextureHelper11 *sourceResource = nullptr; - ANGLE_TRY(sourceStorage11->getResource(context, &sourceResource)); - - gl::ImageIndex sourceIndex = gl::ImageIndex::Make2D(sourceLevel); - UINT sourceSubresource = sourceStorage11->getSubresourceIndex(sourceIndex); - - const TextureHelper11 *destResource = nullptr; - ANGLE_TRY(destStorage11->getResource(context, &destResource)); - - gl::ImageIndex destIndex = gl::ImageIndex::MakeGeneric(destTarget, destLevel); - UINT destSubresource = destStorage11->getSubresourceIndex(destIndex); - - D3D11_BOX sourceBox{ - static_cast<UINT>(sourceRect.x), - static_cast<UINT>(sourceRect.y), - 0u, - static_cast<UINT>(sourceRect.x + sourceRect.width), - static_cast<UINT>(sourceRect.y + sourceRect.height), - 1u, - }; - - mDeviceContext->CopySubresourceRegion(destResource->get(), destSubresource, destOffset.x, - destOffset.y, destOffset.z, sourceResource->get(), - sourceSubresource, &sourceBox); - } - else - { - const d3d11::SharedSRV *sourceSRV = nullptr; - ANGLE_TRY(sourceStorage11->getSRVLevels(context, sourceLevel, sourceLevel, &sourceSRV)); - - gl::ImageIndex destIndex = gl::ImageIndex::MakeGeneric(destTarget, destLevel); - RenderTargetD3D *destRenderTargetD3D = nullptr; - ANGLE_TRY(destStorage11->getRenderTarget(context, destIndex, &destRenderTargetD3D)); - - RenderTarget11 *destRenderTarget11 = GetAs<RenderTarget11>(destRenderTargetD3D); - - const d3d11::RenderTargetView &destRTV = destRenderTarget11->getRenderTargetView(); - ASSERT(destRTV.valid()); - - gl::Box sourceArea(sourceRect.x, sourceRect.y, 0, sourceRect.width, sourceRect.height, 1); - gl::Extents sourceSize( - static_cast<int>(source->getWidth(source->getTarget(), sourceLevel)), - static_cast<int>(source->getHeight(source->getTarget(), sourceLevel)), 1); - if (unpackFlipY) - { - sourceArea.y += sourceArea.height; - sourceArea.height = -sourceArea.height; - } - - gl::Box destArea(destOffset.x, destOffset.y, 0, sourceRect.width, sourceRect.height, 1); - gl::Extents destSize(destRenderTarget11->getWidth(), destRenderTarget11->getHeight(), 1); - - // Use nearest filtering because source and destination are the same size for the direct - // copy - GLenum sourceFormat = source->getFormat(GL_TEXTURE_2D, sourceLevel).info->format; - ANGLE_TRY(mBlit->copyTexture(context, *sourceSRV, sourceArea, sourceSize, sourceFormat, - destRTV, destArea, destSize, nullptr, destFormat, GL_NEAREST, - false, unpackPremultiplyAlpha, unpackUnmultiplyAlpha)); - } - - destStorage11->markLevelDirty(destLevel); - - return gl::NoError(); -} - -gl::Error Renderer11::copyCompressedTexture(const gl::Context *context, - const gl::Texture *source, - GLint sourceLevel, - TextureStorage *storage, - GLint destLevel) -{ - TextureStorage11_2D *destStorage11 = GetAs<TextureStorage11_2D>(storage); - ASSERT(destStorage11); - - const TextureHelper11 *destResource = nullptr; - ANGLE_TRY(destStorage11->getResource(context, &destResource)); - - gl::ImageIndex destIndex = gl::ImageIndex::Make2D(destLevel); - UINT destSubresource = destStorage11->getSubresourceIndex(destIndex); - - TextureD3D *sourceD3D = GetImplAs<TextureD3D>(source); - ASSERT(sourceD3D); - - TextureStorage *sourceStorage = nullptr; - ANGLE_TRY(sourceD3D->getNativeTexture(context, &sourceStorage)); - - TextureStorage11_2D *sourceStorage11 = GetAs<TextureStorage11_2D>(sourceStorage); - ASSERT(sourceStorage11); - - const TextureHelper11 *sourceResource = nullptr; - ANGLE_TRY(sourceStorage11->getResource(context, &sourceResource)); - - gl::ImageIndex sourceIndex = gl::ImageIndex::Make2D(sourceLevel); - UINT sourceSubresource = sourceStorage11->getSubresourceIndex(sourceIndex); - - mDeviceContext->CopySubresourceRegion(destResource->get(), destSubresource, 0, 0, 0, - sourceResource->get(), sourceSubresource, nullptr); - - return gl::NoError(); -} - -gl::Error Renderer11::createRenderTarget(int width, - int height, - GLenum format, - GLsizei samples, - RenderTargetD3D **outRT) -{ - const d3d11::Format &formatInfo = d3d11::Format::Get(format, mRenderer11DeviceCaps); - - const gl::TextureCaps &textureCaps = getNativeTextureCaps().get(format); - GLuint supportedSamples = textureCaps.getNearestSamples(samples); - - if (width > 0 && height > 0) - { - // Create texture resource - D3D11_TEXTURE2D_DESC desc; - desc.Width = width; - desc.Height = height; - desc.MipLevels = 1; - desc.ArraySize = 1; - desc.Format = formatInfo.texFormat; - desc.SampleDesc.Count = (supportedSamples == 0) ? 1 : supportedSamples; - desc.SampleDesc.Quality = 0; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.CPUAccessFlags = 0; - desc.MiscFlags = 0; - - // If a rendertarget or depthstencil format exists for this texture format, - // we'll flag it to allow binding that way. Shader resource views are a little - // more complicated. - bool bindRTV = false, bindDSV = false, bindSRV = false; - bindRTV = (formatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN); - bindDSV = (formatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN); - bindSRV = (formatInfo.srvFormat != DXGI_FORMAT_UNKNOWN); - - bool isMultisampledDepthStencil = bindDSV && desc.SampleDesc.Count > 1; - if (isMultisampledDepthStencil && - !mRenderer11DeviceCaps.supportsMultisampledDepthStencilSRVs) - { - bindSRV = false; - } - - desc.BindFlags = (bindRTV ? D3D11_BIND_RENDER_TARGET : 0) | - (bindDSV ? D3D11_BIND_DEPTH_STENCIL : 0) | - (bindSRV ? D3D11_BIND_SHADER_RESOURCE : 0); - - // The format must be either an RTV or a DSV - ASSERT(bindRTV != bindDSV); - - TextureHelper11 texture; - ANGLE_TRY(allocateTexture(desc, formatInfo, &texture)); - - d3d11::SharedSRV srv; - d3d11::SharedSRV blitSRV; - if (bindSRV) - { - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - srvDesc.Format = formatInfo.srvFormat; - srvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_SRV_DIMENSION_TEXTURE2D - : D3D11_SRV_DIMENSION_TEXTURE2DMS; - srvDesc.Texture2D.MostDetailedMip = 0; - srvDesc.Texture2D.MipLevels = 1; - - ANGLE_TRY(allocateResource(srvDesc, texture.get(), &srv)); - - if (formatInfo.blitSRVFormat != formatInfo.srvFormat) - { - D3D11_SHADER_RESOURCE_VIEW_DESC blitSRVDesc; - blitSRVDesc.Format = formatInfo.blitSRVFormat; - blitSRVDesc.ViewDimension = (supportedSamples == 0) - ? D3D11_SRV_DIMENSION_TEXTURE2D - : D3D11_SRV_DIMENSION_TEXTURE2DMS; - blitSRVDesc.Texture2D.MostDetailedMip = 0; - blitSRVDesc.Texture2D.MipLevels = 1; - - ANGLE_TRY(allocateResource(blitSRVDesc, texture.get(), &blitSRV)); - } - else - { - blitSRV = srv.makeCopy(); - } - } - - if (bindDSV) - { - D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; - dsvDesc.Format = formatInfo.dsvFormat; - dsvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_DSV_DIMENSION_TEXTURE2D - : D3D11_DSV_DIMENSION_TEXTURE2DMS; - dsvDesc.Texture2D.MipSlice = 0; - dsvDesc.Flags = 0; - - d3d11::DepthStencilView dsv; - ANGLE_TRY(allocateResource(dsvDesc, texture.get(), &dsv)); - - *outRT = new TextureRenderTarget11(std::move(dsv), texture, srv, format, formatInfo, - width, height, 1, supportedSamples); - } - else if (bindRTV) - { - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - rtvDesc.Format = formatInfo.rtvFormat; - rtvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_RTV_DIMENSION_TEXTURE2D - : D3D11_RTV_DIMENSION_TEXTURE2DMS; - rtvDesc.Texture2D.MipSlice = 0; - - d3d11::RenderTargetView rtv; - ANGLE_TRY(allocateResource(rtvDesc, texture.get(), &rtv)); - - if (formatInfo.dataInitializerFunction != nullptr) - { - const float clearValues[4] = {0.0f, 0.0f, 0.0f, 1.0f}; - mDeviceContext->ClearRenderTargetView(rtv.get(), clearValues); - } - - *outRT = new TextureRenderTarget11(std::move(rtv), texture, srv, blitSRV, format, - formatInfo, width, height, 1, supportedSamples); - } - else - { - UNREACHABLE(); - } - } - else - { - *outRT = new TextureRenderTarget11(d3d11::RenderTargetView(), TextureHelper11(), - d3d11::SharedSRV(), d3d11::SharedSRV(), format, - d3d11::Format::Get(GL_NONE, mRenderer11DeviceCaps), - width, height, 1, supportedSamples); - } - - return gl::NoError(); -} - -gl::Error Renderer11::createRenderTargetCopy(RenderTargetD3D *source, RenderTargetD3D **outRT) -{ - ASSERT(source != nullptr); - - RenderTargetD3D *newRT = nullptr; - ANGLE_TRY(createRenderTarget(source->getWidth(), source->getHeight(), - source->getInternalFormat(), source->getSamples(), &newRT)); - - RenderTarget11 *source11 = GetAs<RenderTarget11>(source); - RenderTarget11 *dest11 = GetAs<RenderTarget11>(newRT); - - mDeviceContext->CopySubresourceRegion(dest11->getTexture().get(), dest11->getSubresourceIndex(), - 0, 0, 0, source11->getTexture().get(), - source11->getSubresourceIndex(), nullptr); - *outRT = newRT; - return gl::NoError(); -} - -gl::Error Renderer11::loadExecutable(const uint8_t *function, - size_t length, - gl::ShaderType type, - const std::vector<D3DVarying> &streamOutVaryings, - bool separatedOutputBuffers, - ShaderExecutableD3D **outExecutable) -{ - ShaderData shaderData(function, length); - - switch (type) - { - case gl::SHADER_VERTEX: - { - d3d11::VertexShader vertexShader; - d3d11::GeometryShader streamOutShader; - ANGLE_TRY(allocateResource(shaderData, &vertexShader)); - - if (!streamOutVaryings.empty()) - { - std::vector<D3D11_SO_DECLARATION_ENTRY> soDeclaration; - soDeclaration.reserve(streamOutVaryings.size()); - - for (const auto &streamOutVarying : streamOutVaryings) - { - D3D11_SO_DECLARATION_ENTRY entry = {0}; - entry.Stream = 0; - entry.SemanticName = streamOutVarying.semanticName.c_str(); - entry.SemanticIndex = streamOutVarying.semanticIndex; - entry.StartComponent = 0; - entry.ComponentCount = static_cast<BYTE>(streamOutVarying.componentCount); - entry.OutputSlot = static_cast<BYTE>( - (separatedOutputBuffers ? streamOutVarying.outputSlot : 0)); - soDeclaration.push_back(entry); - } - - ANGLE_TRY(allocateResource(shaderData, &soDeclaration, &streamOutShader)); - } - - *outExecutable = new ShaderExecutable11(function, length, std::move(vertexShader), - std::move(streamOutShader)); - } - break; - case gl::SHADER_FRAGMENT: - { - d3d11::PixelShader pixelShader; - ANGLE_TRY(allocateResource(shaderData, &pixelShader)); - *outExecutable = new ShaderExecutable11(function, length, std::move(pixelShader)); - } - break; - case gl::SHADER_GEOMETRY: - { - d3d11::GeometryShader geometryShader; - ANGLE_TRY(allocateResource(shaderData, &geometryShader)); - *outExecutable = new ShaderExecutable11(function, length, std::move(geometryShader)); - } - break; - case gl::SHADER_COMPUTE: - { - d3d11::ComputeShader computeShader; - ANGLE_TRY(allocateResource(shaderData, &computeShader)); - *outExecutable = new ShaderExecutable11(function, length, std::move(computeShader)); - } - break; - default: - UNREACHABLE(); - return gl::InternalError(); - } - - return gl::NoError(); -} - -gl::Error Renderer11::compileToExecutable(gl::InfoLog &infoLog, - const std::string &shaderHLSL, - gl::ShaderType type, - const std::vector<D3DVarying> &streamOutVaryings, - bool separatedOutputBuffers, - const angle::CompilerWorkaroundsD3D &workarounds, - ShaderExecutableD3D **outExectuable) -{ - std::stringstream profileStream; - - switch (type) - { - case gl::SHADER_VERTEX: - profileStream << "vs"; - break; - case gl::SHADER_FRAGMENT: - profileStream << "ps"; - break; - case gl::SHADER_GEOMETRY: - profileStream << "gs"; - break; - case gl::SHADER_COMPUTE: - profileStream << "cs"; - break; - default: - UNREACHABLE(); - return gl::InternalError(); - } - - profileStream << "_" << getMajorShaderModel() << "_" << getMinorShaderModel() - << getShaderModelSuffix(); - std::string profile = profileStream.str(); - - UINT flags = D3DCOMPILE_OPTIMIZATION_LEVEL2; - - if (gl::DebugAnnotationsActive()) - { -#ifndef NDEBUG - flags = D3DCOMPILE_SKIP_OPTIMIZATION; -#endif - - flags |= D3DCOMPILE_DEBUG; - } - - if (workarounds.enableIEEEStrictness) - flags |= D3DCOMPILE_IEEE_STRICTNESS; - - // Sometimes D3DCompile will fail with the default compilation flags for complicated shaders - // when it would otherwise pass with alternative options. - // Try the default flags first and if compilation fails, try some alternatives. - std::vector<CompileConfig> configs; - configs.push_back(CompileConfig(flags, "default")); - configs.push_back(CompileConfig(flags | D3DCOMPILE_SKIP_VALIDATION, "skip validation")); - configs.push_back(CompileConfig(flags | D3DCOMPILE_SKIP_OPTIMIZATION, "skip optimization")); - - if (getMajorShaderModel() == 4 && getShaderModelSuffix() != "") - { - // Some shaders might cause a "blob content mismatch between level9 and d3d10 shader". - // e.g. dEQP-GLES2.functional.shaders.struct.local.loop_nested_struct_array_*. - // Using the [unroll] directive works around this, as does this D3DCompile flag. - configs.push_back( - CompileConfig(flags | D3DCOMPILE_AVOID_FLOW_CONTROL, "avoid flow control")); - } - - D3D_SHADER_MACRO loopMacros[] = {{"ANGLE_ENABLE_LOOP_FLATTEN", "1"}, {0, 0}}; - - // TODO(jmadill): Use ComPtr? - ID3DBlob *binary = nullptr; - std::string debugInfo; - ANGLE_TRY(mCompiler.compileToBinary(infoLog, shaderHLSL, profile, configs, loopMacros, &binary, - &debugInfo)); - - // It's possible that binary is NULL if the compiler failed in all configurations. Set the - // executable to NULL and return GL_NO_ERROR to signify that there was a link error but the - // internal state is still OK. - if (!binary) - { - *outExectuable = nullptr; - return gl::NoError(); - } - - gl::Error error = loadExecutable(reinterpret_cast<const uint8_t *>(binary->GetBufferPointer()), - binary->GetBufferSize(), type, streamOutVaryings, - separatedOutputBuffers, outExectuable); - - SafeRelease(binary); - if (error.isError()) - { - return error; - } - - if (!debugInfo.empty()) - { - (*outExectuable)->appendDebugInfo(debugInfo); - } - - return gl::NoError(); -} - -gl::Error Renderer11::ensureHLSLCompilerInitialized() -{ - return mCompiler.ensureInitialized(); -} - -UniformStorageD3D *Renderer11::createUniformStorage(size_t storageSize) -{ - return new UniformStorage11(storageSize); -} - -VertexBuffer *Renderer11::createVertexBuffer() -{ - return new VertexBuffer11(this); -} - -IndexBuffer *Renderer11::createIndexBuffer() -{ - return new IndexBuffer11(this); -} - -StreamProducerImpl *Renderer11::createStreamProducerD3DTextureNV12( - egl::Stream::ConsumerType consumerType, - const egl::AttributeMap &attribs) -{ - return new StreamProducerNV12(this); -} - -bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const -{ - ASSERT(getNativeExtensions().pixelBufferObject); - - const gl::InternalFormat &internalFormatInfo = gl::GetSizedInternalFormatInfo(internalFormat); - const d3d11::Format &d3d11FormatInfo = - d3d11::Format::Get(internalFormat, mRenderer11DeviceCaps); - - // sRGB formats do not work with D3D11 buffer SRVs - if (internalFormatInfo.colorEncoding == GL_SRGB) - { - return false; - } - - // We cannot support direct copies to non-color-renderable formats - if (d3d11FormatInfo.rtvFormat == DXGI_FORMAT_UNKNOWN) - { - return false; - } - - // We skip all 3-channel formats since sometimes format support is missing - if (internalFormatInfo.componentCount == 3) - { - return false; - } - - // We don't support formats which we can't represent without conversion - if (d3d11FormatInfo.format().glInternalFormat != internalFormat) - { - return false; - } - - // Buffer SRV creation for this format was not working on Windows 10. - if (d3d11FormatInfo.texFormat == DXGI_FORMAT_B5G5R5A1_UNORM) - { - return false; - } - - // This format is not supported as a buffer SRV. - if (d3d11FormatInfo.texFormat == DXGI_FORMAT_A8_UNORM) - { - return false; - } - - return true; -} - -gl::Error Renderer11::fastCopyBufferToTexture(const gl::Context *context, - const gl::PixelUnpackState &unpack, - unsigned int offset, - RenderTargetD3D *destRenderTarget, - GLenum destinationFormat, - GLenum sourcePixelsType, - const gl::Box &destArea) -{ - ASSERT(supportsFastCopyBufferToTexture(destinationFormat)); - return mPixelTransfer->copyBufferToTexture(context, unpack, offset, destRenderTarget, - destinationFormat, sourcePixelsType, destArea); -} - -ImageD3D *Renderer11::createImage() -{ - return new Image11(this); -} - -gl::Error Renderer11::generateMipmap(const gl::Context *context, ImageD3D *dest, ImageD3D *src) -{ - Image11 *dest11 = GetAs<Image11>(dest); - Image11 *src11 = GetAs<Image11>(src); - return Image11::GenerateMipmap(context, dest11, src11, mRenderer11DeviceCaps); -} - -gl::Error Renderer11::generateMipmapUsingD3D(const gl::Context *context, - TextureStorage *storage, - const gl::TextureState &textureState) -{ - TextureStorage11 *storage11 = GetAs<TextureStorage11>(storage); - - ASSERT(storage11->isRenderTarget()); - ASSERT(storage11->supportsNativeMipmapFunction()); - - const d3d11::SharedSRV *srv = nullptr; - ANGLE_TRY(storage11->getSRVLevels(context, textureState.getEffectiveBaseLevel(), - textureState.getEffectiveMaxLevel(), &srv)); - - mDeviceContext->GenerateMips(srv->get()); - - return gl::NoError(); -} - -gl::Error Renderer11::copyImage(const gl::Context *context, - ImageD3D *dest, - ImageD3D *source, - const gl::Rectangle &sourceRect, - const gl::Offset &destOffset, - bool unpackFlipY, - bool unpackPremultiplyAlpha, - bool unpackUnmultiplyAlpha) -{ - Image11 *dest11 = GetAs<Image11>(dest); - Image11 *src11 = GetAs<Image11>(source); - return Image11::CopyImage(context, dest11, src11, sourceRect, destOffset, unpackFlipY, - unpackPremultiplyAlpha, unpackUnmultiplyAlpha, mRenderer11DeviceCaps); -} - -TextureStorage *Renderer11::createTextureStorage2D(SwapChainD3D *swapChain) -{ - SwapChain11 *swapChain11 = GetAs<SwapChain11>(swapChain); - return new TextureStorage11_2D(this, swapChain11); -} - -TextureStorage *Renderer11::createTextureStorageEGLImage(EGLImageD3D *eglImage, - RenderTargetD3D *renderTargetD3D) -{ - return new TextureStorage11_EGLImage(this, eglImage, GetAs<RenderTarget11>(renderTargetD3D)); -} - -TextureStorage *Renderer11::createTextureStorageExternal( - egl::Stream *stream, - const egl::Stream::GLTextureDescription &desc) -{ - return new TextureStorage11_External(this, stream, desc); -} - -TextureStorage *Renderer11::createTextureStorage2D(GLenum internalformat, - bool renderTarget, - GLsizei width, - GLsizei height, - int levels, - bool hintLevelZeroOnly) -{ - return new TextureStorage11_2D(this, internalformat, renderTarget, width, height, levels, - hintLevelZeroOnly); -} - -TextureStorage *Renderer11::createTextureStorageCube(GLenum internalformat, - bool renderTarget, - int size, - int levels, - bool hintLevelZeroOnly) -{ - return new TextureStorage11_Cube(this, internalformat, renderTarget, size, levels, - hintLevelZeroOnly); -} - -TextureStorage *Renderer11::createTextureStorage3D(GLenum internalformat, - bool renderTarget, - GLsizei width, - GLsizei height, - GLsizei depth, - int levels) -{ - return new TextureStorage11_3D(this, internalformat, renderTarget, width, height, depth, - levels); -} - -TextureStorage *Renderer11::createTextureStorage2DArray(GLenum internalformat, - bool renderTarget, - GLsizei width, - GLsizei height, - GLsizei depth, - int levels) -{ - return new TextureStorage11_2DArray(this, internalformat, renderTarget, width, height, depth, - levels); -} - -TextureStorage *Renderer11::createTextureStorage2DMultisample(GLenum internalformat, - GLsizei width, - GLsizei height, - int levels, - int samples, - bool fixedSampleLocations) -{ - return new TextureStorage11_2DMultisample(this, internalformat, width, height, levels, samples, - fixedSampleLocations); -} - -gl::Error Renderer11::readFromAttachment(const gl::Context *context, - const gl::FramebufferAttachment &srcAttachment, - const gl::Rectangle &sourceArea, - GLenum format, - GLenum type, - GLuint outputPitch, - const gl::PixelPackState &pack, - uint8_t *pixelsOut) -{ - ASSERT(sourceArea.width >= 0); - ASSERT(sourceArea.height >= 0); - - const bool invertTexture = UsePresentPathFast(this, &srcAttachment); - - RenderTarget11 *rt11 = nullptr; - ANGLE_TRY(srcAttachment.getRenderTarget(context, &rt11)); - ASSERT(rt11->getTexture().valid()); - - const TextureHelper11 &textureHelper = rt11->getTexture(); - unsigned int sourceSubResource = rt11->getSubresourceIndex(); - - const gl::Extents &texSize = textureHelper.getExtents(); - - gl::Rectangle actualArea = sourceArea; - if (invertTexture) - { - actualArea.y = texSize.height - actualArea.y - actualArea.height; - } - - // Clamp read region to the defined texture boundaries, preventing out of bounds reads - // and reads of uninitialized data. - gl::Rectangle safeArea; - safeArea.x = gl::clamp(actualArea.x, 0, texSize.width); - safeArea.y = gl::clamp(actualArea.y, 0, texSize.height); - safeArea.width = - gl::clamp(actualArea.width + std::min(actualArea.x, 0), 0, texSize.width - safeArea.x); - safeArea.height = - gl::clamp(actualArea.height + std::min(actualArea.y, 0), 0, texSize.height - safeArea.y); - - ASSERT(safeArea.x >= 0 && safeArea.y >= 0); - ASSERT(safeArea.x + safeArea.width <= texSize.width); - ASSERT(safeArea.y + safeArea.height <= texSize.height); - - if (safeArea.width == 0 || safeArea.height == 0) - { - // no work to do - return gl::NoError(); - } - - gl::Extents safeSize(safeArea.width, safeArea.height, 1); - TextureHelper11 stagingHelper; - ANGLE_TRY_RESULT( - createStagingTexture(textureHelper.getTextureType(), textureHelper.getFormatSet(), safeSize, - StagingAccess::READ), - stagingHelper); - - TextureHelper11 resolvedTextureHelper; - - // "srcTexture" usually points to the source texture. - // For 2D multisampled textures, it points to the multisampled resolve texture. - const TextureHelper11 *srcTexture = &textureHelper; - - if (textureHelper.is2D() && textureHelper.getSampleCount() > 1) - { - D3D11_TEXTURE2D_DESC resolveDesc; - resolveDesc.Width = static_cast<UINT>(texSize.width); - resolveDesc.Height = static_cast<UINT>(texSize.height); - resolveDesc.MipLevels = 1; - resolveDesc.ArraySize = 1; - resolveDesc.Format = textureHelper.getFormat(); - resolveDesc.SampleDesc.Count = 1; - resolveDesc.SampleDesc.Quality = 0; - resolveDesc.Usage = D3D11_USAGE_DEFAULT; - resolveDesc.BindFlags = 0; - resolveDesc.CPUAccessFlags = 0; - resolveDesc.MiscFlags = 0; - - ANGLE_TRY( - allocateTexture(resolveDesc, textureHelper.getFormatSet(), &resolvedTextureHelper)); - - mDeviceContext->ResolveSubresource(resolvedTextureHelper.get(), 0, textureHelper.get(), - sourceSubResource, textureHelper.getFormat()); - - sourceSubResource = 0; - srcTexture = &resolvedTextureHelper; - } - - D3D11_BOX srcBox; - srcBox.left = static_cast<UINT>(safeArea.x); - srcBox.right = static_cast<UINT>(safeArea.x + safeArea.width); - srcBox.top = static_cast<UINT>(safeArea.y); - srcBox.bottom = static_cast<UINT>(safeArea.y + safeArea.height); - - // Select the correct layer from a 3D attachment - srcBox.front = 0; - if (textureHelper.is3D()) - { - srcBox.front = static_cast<UINT>(srcAttachment.layer()); - } - srcBox.back = srcBox.front + 1; - - mDeviceContext->CopySubresourceRegion(stagingHelper.get(), 0, 0, 0, 0, srcTexture->get(), - sourceSubResource, &srcBox); - - gl::Buffer *packBuffer = context->getGLState().getTargetBuffer(gl::BufferBinding::PixelPack); - if (!invertTexture) - { - PackPixelsParams packParams(safeArea, format, type, outputPitch, pack, packBuffer, 0); - return packPixels(stagingHelper, packParams, pixelsOut); - } - - // Create a new PixelPackState with reversed row order. Note that we can't just assign - // 'invertTexturePack' to be 'pack' (or memcpy) since that breaks the ref counting/object - // tracking in the 'pixelBuffer' members, causing leaks. Instead we must use - // pixelBuffer.set() twice, which performs the addRef/release correctly - gl::PixelPackState invertTexturePack; - invertTexturePack.alignment = pack.alignment; - invertTexturePack.reverseRowOrder = !pack.reverseRowOrder; - - PackPixelsParams packParams(safeArea, format, type, outputPitch, invertTexturePack, packBuffer, - 0); - gl::Error error = packPixels(stagingHelper, packParams, pixelsOut); - ANGLE_TRY(error); - return gl::NoError(); -} - -gl::Error Renderer11::packPixels(const TextureHelper11 &textureHelper, - const PackPixelsParams ¶ms, - uint8_t *pixelsOut) -{ - ID3D11Resource *readResource = textureHelper.get(); - - D3D11_MAPPED_SUBRESOURCE mapping; - HRESULT hr = mDeviceContext->Map(readResource, 0, D3D11_MAP_READ, 0, &mapping); - if (FAILED(hr)) - { - ASSERT(hr == E_OUTOFMEMORY); - return gl::OutOfMemory() << "Failed to map internal texture for reading, " << gl::FmtHR(hr); - } - - uint8_t *source = static_cast<uint8_t *>(mapping.pData); - int inputPitch = static_cast<int>(mapping.RowPitch); - - const auto &formatInfo = textureHelper.getFormatSet(); - ASSERT(formatInfo.format().glInternalFormat != GL_NONE); - - PackPixels(params, formatInfo.format(), inputPitch, source, pixelsOut); - - mDeviceContext->Unmap(readResource, 0); - - return gl::NoError(); -} - -gl::Error Renderer11::blitRenderbufferRect(const gl::Context *context, - const gl::Rectangle &readRectIn, - const gl::Rectangle &drawRectIn, - RenderTargetD3D *readRenderTarget, - RenderTargetD3D *drawRenderTarget, - GLenum filter, - const gl::Rectangle *scissor, - bool colorBlit, - bool depthBlit, - bool stencilBlit) -{ - // Since blitRenderbufferRect is called for each render buffer that needs to be blitted, - // it should never be the case that both color and depth/stencil need to be blitted at - // at the same time. - ASSERT(colorBlit != (depthBlit || stencilBlit)); - - RenderTarget11 *drawRenderTarget11 = GetAs<RenderTarget11>(drawRenderTarget); - if (!drawRenderTarget11) - { - return gl::OutOfMemory() - << "Failed to retrieve the internal draw render target from the draw framebuffer."; - } - - const TextureHelper11 &drawTexture = drawRenderTarget11->getTexture(); - unsigned int drawSubresource = drawRenderTarget11->getSubresourceIndex(); - - RenderTarget11 *readRenderTarget11 = GetAs<RenderTarget11>(readRenderTarget); - if (!readRenderTarget11) - { - return gl::OutOfMemory() - << "Failed to retrieve the internal read render target from the read framebuffer."; - } - - TextureHelper11 readTexture; - unsigned int readSubresource = 0; - d3d11::SharedSRV readSRV; - - if (readRenderTarget->isMultisampled()) - { - ANGLE_TRY_RESULT( - resolveMultisampledTexture(context, readRenderTarget11, depthBlit, stencilBlit), - readTexture); - - if (!stencilBlit) - { - const auto &readFormatSet = readTexture.getFormatSet(); - - D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc; - viewDesc.Format = readFormatSet.srvFormat; - viewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - viewDesc.Texture2D.MipLevels = 1; - viewDesc.Texture2D.MostDetailedMip = 0; - - ANGLE_TRY(allocateResource(viewDesc, readTexture.get(), &readSRV)); - } - } - else - { - ASSERT(readRenderTarget11); - readTexture = readRenderTarget11->getTexture(); - readSubresource = readRenderTarget11->getSubresourceIndex(); - readSRV = readRenderTarget11->getBlitShaderResourceView().makeCopy(); - if (!readSRV.valid()) - { - ASSERT(depthBlit || stencilBlit); - readSRV = readRenderTarget11->getShaderResourceView().makeCopy(); - } - ASSERT(readSRV.valid()); - } - - // Stencil blits don't use shaders. - ASSERT(readSRV.valid() || stencilBlit); - - const gl::Extents readSize(readRenderTarget->getWidth(), readRenderTarget->getHeight(), 1); - const gl::Extents drawSize(drawRenderTarget->getWidth(), drawRenderTarget->getHeight(), 1); - - // From the spec: - // "The actual region taken from the read framebuffer is limited to the intersection of the - // source buffers being transferred, which may include the color buffer selected by the read - // buffer, the depth buffer, and / or the stencil buffer depending on mask." - // This means negative x and y are out of bounds, and not to be read from. We handle this here - // by internally scaling the read and draw rectangles. - gl::Rectangle readRect = readRectIn; - gl::Rectangle drawRect = drawRectIn; - - auto flip = [](int val) { return val >= 0 ? 1 : -1; }; - - if (readRect.x > readSize.width && readRect.width < 0) - { - int delta = readRect.x - readSize.width; - readRect.x -= delta; - readRect.width += delta; - - int drawDelta = delta * flip(drawRect.width); - drawRect.x += drawDelta; - drawRect.width -= drawDelta; - } - - if (readRect.y > readSize.height && readRect.height < 0) - { - int delta = readRect.y - readSize.height; - readRect.y -= delta; - readRect.height += delta; - - int drawDelta = delta * flip(drawRect.height); - drawRect.y += drawDelta; - drawRect.height -= drawDelta; - } - - auto readToDrawX = [&drawRectIn, &readRectIn](int readOffset) { - double readToDrawScale = - static_cast<double>(drawRectIn.width) / static_cast<double>(readRectIn.width); - return static_cast<int>(round(static_cast<double>(readOffset) * readToDrawScale)); - }; - if (readRect.x < 0) - { - int readOffset = -readRect.x; - readRect.x += readOffset; - readRect.width -= readOffset; - - int drawOffset = readToDrawX(readOffset); - drawRect.x += drawOffset; - drawRect.width -= drawOffset; - } - - auto readToDrawY = [&drawRectIn, &readRectIn](int readOffset) { - double readToDrawScale = - static_cast<double>(drawRectIn.height) / static_cast<double>(readRectIn.height); - return static_cast<int>(round(static_cast<double>(readOffset) * readToDrawScale)); - }; - if (readRect.y < 0) - { - int readOffset = -readRect.y; - readRect.y += readOffset; - readRect.height -= readOffset; - - int drawOffset = readToDrawY(readOffset); - drawRect.y += drawOffset; - drawRect.height -= drawOffset; - } - - if (readRect.x1() < 0) - { - int readOffset = -readRect.x1(); - readRect.width += readOffset; - - int drawOffset = readToDrawX(readOffset); - drawRect.width += drawOffset; - } - - if (readRect.y1() < 0) - { - int readOffset = -readRect.y1(); - readRect.height += readOffset; - - int drawOffset = readToDrawY(readOffset); - drawRect.height += drawOffset; - } - - if (readRect.x1() > readSize.width) - { - int delta = readRect.x1() - readSize.width; - readRect.width -= delta; - drawRect.width -= delta * flip(drawRect.width); - } - - if (readRect.y1() > readSize.height) - { - int delta = readRect.y1() - readSize.height; - readRect.height -= delta; - drawRect.height -= delta * flip(drawRect.height); - } - - bool scissorNeeded = scissor && gl::ClipRectangle(drawRect, *scissor, nullptr); - - const auto &destFormatInfo = - gl::GetSizedInternalFormatInfo(drawRenderTarget->getInternalFormat()); - const auto &srcFormatInfo = - gl::GetSizedInternalFormatInfo(readRenderTarget->getInternalFormat()); - const auto &formatSet = drawRenderTarget11->getFormatSet(); - const auto &nativeFormat = formatSet.format(); - - // Some blits require masking off emulated texture channels. eg: from RGBA8 to RGB8, we - // emulate RGB8 with RGBA8, so we need to mask off the alpha channel when we copy. - - gl::Color<bool> colorMask; - colorMask.red = - (srcFormatInfo.redBits > 0) && (destFormatInfo.redBits == 0) && (nativeFormat.redBits > 0); - colorMask.green = (srcFormatInfo.greenBits > 0) && (destFormatInfo.greenBits == 0) && - (nativeFormat.greenBits > 0); - colorMask.blue = (srcFormatInfo.blueBits > 0) && (destFormatInfo.blueBits == 0) && - (nativeFormat.blueBits > 0); - colorMask.alpha = (srcFormatInfo.alphaBits > 0) && (destFormatInfo.alphaBits == 0) && - (nativeFormat.alphaBits > 0); - - // We only currently support masking off the alpha channel. - bool colorMaskingNeeded = colorMask.alpha; - ASSERT(!colorMask.red && !colorMask.green && !colorMask.blue); - - bool wholeBufferCopy = !scissorNeeded && !colorMaskingNeeded && readRect.x == 0 && - readRect.width == readSize.width && readRect.y == 0 && - readRect.height == readSize.height && drawRect.x == 0 && - drawRect.width == drawSize.width && drawRect.y == 0 && - drawRect.height == drawSize.height; - - bool stretchRequired = readRect.width != drawRect.width || readRect.height != drawRect.height; - - bool flipRequired = - readRect.width < 0 || readRect.height < 0 || drawRect.width < 0 || drawRect.height < 0; - - bool outOfBounds = readRect.x < 0 || readRect.x + readRect.width > readSize.width || - readRect.y < 0 || readRect.y + readRect.height > readSize.height || - drawRect.x < 0 || drawRect.x + drawRect.width > drawSize.width || - drawRect.y < 0 || drawRect.y + drawRect.height > drawSize.height; - - bool partialDSBlit = - (nativeFormat.depthBits > 0 && depthBlit) != (nativeFormat.stencilBits > 0 && stencilBlit); - - if (readRenderTarget11->getFormatSet().formatID == - drawRenderTarget11->getFormatSet().formatID && - !stretchRequired && !outOfBounds && !flipRequired && !partialDSBlit && - !colorMaskingNeeded && (!(depthBlit || stencilBlit) || wholeBufferCopy)) - { - UINT dstX = drawRect.x; - UINT dstY = drawRect.y; - - D3D11_BOX readBox; - readBox.left = readRect.x; - readBox.right = readRect.x + readRect.width; - readBox.top = readRect.y; - readBox.bottom = readRect.y + readRect.height; - readBox.front = 0; - readBox.back = 1; - - if (scissorNeeded) - { - // drawRect is guaranteed to have positive width and height because stretchRequired is - // false. - ASSERT(drawRect.width >= 0 || drawRect.height >= 0); - - if (drawRect.x < scissor->x) - { - dstX = scissor->x; - readBox.left += (scissor->x - drawRect.x); - } - if (drawRect.y < scissor->y) - { - dstY = scissor->y; - readBox.top += (scissor->y - drawRect.y); - } - if (drawRect.x + drawRect.width > scissor->x + scissor->width) - { - readBox.right -= ((drawRect.x + drawRect.width) - (scissor->x + scissor->width)); - } - if (drawRect.y + drawRect.height > scissor->y + scissor->height) - { - readBox.bottom -= ((drawRect.y + drawRect.height) - (scissor->y + scissor->height)); - } - } - - // D3D11 needs depth-stencil CopySubresourceRegions to have a NULL pSrcBox - // We also require complete framebuffer copies for depth-stencil blit. - D3D11_BOX *pSrcBox = wholeBufferCopy ? nullptr : &readBox; - - mDeviceContext->CopySubresourceRegion(drawTexture.get(), drawSubresource, dstX, dstY, 0, - readTexture.get(), readSubresource, pSrcBox); - } - else - { - gl::Box readArea(readRect.x, readRect.y, 0, readRect.width, readRect.height, 1); - gl::Box drawArea(drawRect.x, drawRect.y, 0, drawRect.width, drawRect.height, 1); - - if (depthBlit && stencilBlit) - { - ANGLE_TRY(mBlit->copyDepthStencil(readTexture, readSubresource, readArea, readSize, - drawTexture, drawSubresource, drawArea, drawSize, - scissor)); - } - else if (depthBlit) - { - const d3d11::DepthStencilView &drawDSV = drawRenderTarget11->getDepthStencilView(); - ASSERT(readSRV.valid()); - ANGLE_TRY(mBlit->copyDepth(context, readSRV, readArea, readSize, drawDSV, drawArea, - drawSize, scissor)); - } - else if (stencilBlit) - { - ANGLE_TRY(mBlit->copyStencil(context, readTexture, readSubresource, readArea, readSize, - drawTexture, drawSubresource, drawArea, drawSize, - scissor)); - } - else - { - const d3d11::RenderTargetView &drawRTV = drawRenderTarget11->getRenderTargetView(); - - // We don't currently support masking off any other channel than alpha - bool maskOffAlpha = colorMaskingNeeded && colorMask.alpha; - ASSERT(readSRV.valid()); - ANGLE_TRY(mBlit->copyTexture( - context, readSRV, readArea, readSize, srcFormatInfo.format, drawRTV, drawArea, - drawSize, scissor, destFormatInfo.format, filter, maskOffAlpha, false, false)); - } - } - - return gl::NoError(); -} - -bool Renderer11::isES3Capable() const -{ - return (d3d11_gl::GetMaximumClientVersion(mRenderer11DeviceCaps.featureLevel).major > 2); -} - -RendererClass Renderer11::getRendererClass() const -{ - return RENDERER_D3D11; -} - -void Renderer11::onSwap() -{ - // Send histogram updates every half hour - const double kHistogramUpdateInterval = 30 * 60; - - auto *platform = ANGLEPlatformCurrent(); - const double currentTime = platform->monotonicallyIncreasingTime(platform); - const double timeSinceLastUpdate = currentTime - mLastHistogramUpdateTime; - - if (timeSinceLastUpdate > kHistogramUpdateInterval) - { - updateHistograms(); - mLastHistogramUpdateTime = currentTime; - } -} - -void Renderer11::updateHistograms() -{ - // Update the buffer CPU memory histogram - { - size_t sizeSum = 0; - for (const Buffer11 *buffer : mAliveBuffers) - { - sizeSum += buffer->getTotalCPUBufferMemoryBytes(); - } - const int kOneMegaByte = 1024 * 1024; - ANGLE_HISTOGRAM_MEMORY_MB("GPU.ANGLE.Buffer11CPUMemoryMB", - static_cast<int>(sizeSum) / kOneMegaByte); - } -} - -void Renderer11::onBufferCreate(const Buffer11 *created) -{ - mAliveBuffers.insert(created); -} - -void Renderer11::onBufferDelete(const Buffer11 *deleted) -{ - mAliveBuffers.erase(deleted); -} - -gl::ErrorOrResult<TextureHelper11> Renderer11::resolveMultisampledTexture( - const gl::Context *context, - RenderTarget11 *renderTarget, - bool depth, - bool stencil) -{ - if (depth && !stencil) - { - return mBlit->resolveDepth(context, renderTarget); - } - - if (stencil) - { - return mBlit->resolveStencil(context, renderTarget, depth); - } - - const auto &formatSet = renderTarget->getFormatSet(); - - ASSERT(renderTarget->isMultisampled()); - const d3d11::SharedSRV &sourceSRV = renderTarget->getShaderResourceView(); - D3D11_SHADER_RESOURCE_VIEW_DESC sourceSRVDesc; - sourceSRV.get()->GetDesc(&sourceSRVDesc); - ASSERT(sourceSRVDesc.ViewDimension == D3D_SRV_DIMENSION_TEXTURE2DMS); - - if (!mCachedResolveTexture.valid() || - mCachedResolveTexture.getExtents().width != renderTarget->getWidth() || - mCachedResolveTexture.getExtents().height != renderTarget->getHeight() || - mCachedResolveTexture.getFormat() != formatSet.texFormat) - { - D3D11_TEXTURE2D_DESC resolveDesc; - resolveDesc.Width = renderTarget->getWidth(); - resolveDesc.Height = renderTarget->getHeight(); - resolveDesc.MipLevels = 1; - resolveDesc.ArraySize = 1; - resolveDesc.Format = formatSet.texFormat; - resolveDesc.SampleDesc.Count = 1; - resolveDesc.SampleDesc.Quality = 0; - resolveDesc.Usage = D3D11_USAGE_DEFAULT; - resolveDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - resolveDesc.CPUAccessFlags = 0; - resolveDesc.MiscFlags = 0; - - ANGLE_TRY(allocateTexture(resolveDesc, formatSet, &mCachedResolveTexture)); - } - - mDeviceContext->ResolveSubresource(mCachedResolveTexture.get(), 0, - renderTarget->getTexture().get(), - renderTarget->getSubresourceIndex(), formatSet.texFormat); - return mCachedResolveTexture; -} - -bool Renderer11::getLUID(LUID *adapterLuid) const -{ - adapterLuid->HighPart = 0; - adapterLuid->LowPart = 0; - - if (!mDxgiAdapter) - { - return false; - } - - DXGI_ADAPTER_DESC adapterDesc; - if (FAILED(mDxgiAdapter->GetDesc(&adapterDesc))) - { - return false; - } - - *adapterLuid = adapterDesc.AdapterLuid; - return true; -} - -VertexConversionType Renderer11::getVertexConversionType( - gl::VertexFormatType vertexFormatType) const -{ - return d3d11::GetVertexFormatInfo(vertexFormatType, mRenderer11DeviceCaps.featureLevel) - .conversionType; -} - -GLenum Renderer11::getVertexComponentType(gl::VertexFormatType vertexFormatType) const -{ - const auto &format = - d3d11::GetVertexFormatInfo(vertexFormatType, mRenderer11DeviceCaps.featureLevel); - return d3d11::GetComponentType(format.nativeFormat); -} - -gl::ErrorOrResult<unsigned int> Renderer11::getVertexSpaceRequired( - const gl::VertexAttribute &attrib, - const gl::VertexBinding &binding, - GLsizei count, - GLsizei instances) const -{ - if (!attrib.enabled) - { - return 16u; - } - - unsigned int elementCount = 0; - const unsigned int divisor = binding.getDivisor(); - if (instances == 0 || divisor == 0) - { - elementCount = count; - } - else - { - // Round up to divisor, if possible - elementCount = UnsignedCeilDivide(static_cast<unsigned int>(instances), divisor); - } - - gl::VertexFormatType formatType = gl::GetVertexFormatType(attrib); - const D3D_FEATURE_LEVEL featureLevel = mRenderer11DeviceCaps.featureLevel; - const d3d11::VertexFormat &vertexFormatInfo = - d3d11::GetVertexFormatInfo(formatType, featureLevel); - const d3d11::DXGIFormatSize &dxgiFormatInfo = - d3d11::GetDXGIFormatSizeInfo(vertexFormatInfo.nativeFormat); - unsigned int elementSize = dxgiFormatInfo.pixelBytes; - if (elementSize > std::numeric_limits<unsigned int>::max() / elementCount) - { - return gl::OutOfMemory() << "New vertex buffer size would result in an overflow."; - } - - return elementSize * elementCount; -} - -void Renderer11::generateCaps(gl::Caps *outCaps, - gl::TextureCapsMap *outTextureCaps, - gl::Extensions *outExtensions, - gl::Limitations *outLimitations) const -{ - d3d11_gl::GenerateCaps(mDevice, mDeviceContext, mRenderer11DeviceCaps, outCaps, outTextureCaps, - outExtensions, outLimitations); -} - -angle::WorkaroundsD3D Renderer11::generateWorkarounds() const -{ - return d3d11::GenerateWorkarounds(mRenderer11DeviceCaps, mAdapterDescription); -} - -egl::Error Renderer11::getEGLDevice(DeviceImpl **device) -{ - if (mEGLDevice == nullptr) - { - ASSERT(mDevice != nullptr); - mEGLDevice = new DeviceD3D(); - egl::Error error = mEGLDevice->initialize(reinterpret_cast<void *>(mDevice), - EGL_D3D11_DEVICE_ANGLE, EGL_FALSE); - - if (error.isError()) - { - SafeDelete(mEGLDevice); - return error; - } - } - - *device = static_cast<DeviceImpl *>(mEGLDevice); - return egl::NoError(); -} - -ContextImpl *Renderer11::createContext(const gl::ContextState &state) -{ - return new Context11(state, this); -} - -FramebufferImpl *Renderer11::createDefaultFramebuffer(const gl::FramebufferState &state) -{ - return new Framebuffer11(state, this); -} - -gl::Error Renderer11::getScratchMemoryBuffer(size_t requestedSize, angle::MemoryBuffer **bufferOut) -{ - if (!mScratchMemoryBuffer.get(requestedSize, bufferOut)) - { - return gl::OutOfMemory() << "Failed to allocate internal buffer."; - } - return gl::NoError(); -} - -gl::Version Renderer11::getMaxSupportedESVersion() const -{ - return d3d11_gl::GetMaximumClientVersion(mRenderer11DeviceCaps.featureLevel); -} - -gl::DebugAnnotator *Renderer11::getAnnotator() -{ - return mAnnotator; -} - -gl::Error Renderer11::applyComputeShader(const gl::Context *context) -{ - ANGLE_TRY(ensureHLSLCompilerInitialized()); - - const auto &glState = context->getGLState(); - ProgramD3D *programD3D = GetImplAs<ProgramD3D>(glState.getProgram()); - - ShaderExecutableD3D *computeExe = nullptr; - ANGLE_TRY(programD3D->getComputeExecutable(&computeExe)); - ASSERT(computeExe != nullptr); - - mStateManager.setComputeShader(&GetAs<ShaderExecutable11>(computeExe)->getComputeShader()); - ANGLE_TRY(mStateManager.applyComputeUniforms(programD3D)); - - return gl::NoError(); -} - -gl::Error Renderer11::dispatchCompute(const gl::Context *context, - GLuint numGroupsX, - GLuint numGroupsY, - GLuint numGroupsZ) -{ - ANGLE_TRY(mStateManager.updateStateForCompute(context, numGroupsX, numGroupsY, numGroupsZ)); - ANGLE_TRY(applyComputeShader(context)); - - mDeviceContext->Dispatch(numGroupsX, numGroupsY, numGroupsZ); - - return gl::NoError(); -} - -gl::ErrorOrResult<TextureHelper11> Renderer11::createStagingTexture( - ResourceType textureType, - const d3d11::Format &formatSet, - const gl::Extents &size, - StagingAccess readAndWriteAccess) -{ - if (textureType == ResourceType::Texture2D) - { - D3D11_TEXTURE2D_DESC stagingDesc; - stagingDesc.Width = size.width; - stagingDesc.Height = size.height; - stagingDesc.MipLevels = 1; - stagingDesc.ArraySize = 1; - stagingDesc.Format = formatSet.texFormat; - stagingDesc.SampleDesc.Count = 1; - stagingDesc.SampleDesc.Quality = 0; - stagingDesc.Usage = D3D11_USAGE_STAGING; - stagingDesc.BindFlags = 0; - stagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; - stagingDesc.MiscFlags = 0; - - if (readAndWriteAccess == StagingAccess::READ_WRITE) - { - stagingDesc.CPUAccessFlags |= D3D11_CPU_ACCESS_WRITE; - } - - TextureHelper11 stagingTex; - ANGLE_TRY(allocateTexture(stagingDesc, formatSet, &stagingTex)); - return stagingTex; - } - ASSERT(textureType == ResourceType::Texture3D); - - D3D11_TEXTURE3D_DESC stagingDesc; - stagingDesc.Width = size.width; - stagingDesc.Height = size.height; - stagingDesc.Depth = 1; - stagingDesc.MipLevels = 1; - stagingDesc.Format = formatSet.texFormat; - stagingDesc.Usage = D3D11_USAGE_STAGING; - stagingDesc.BindFlags = 0; - stagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; - stagingDesc.MiscFlags = 0; - - TextureHelper11 stagingTex; - ANGLE_TRY(allocateTexture(stagingDesc, formatSet, &stagingTex)); - return stagingTex; -} - -gl::Error Renderer11::allocateTexture(const D3D11_TEXTURE2D_DESC &desc, - const d3d11::Format &format, - const D3D11_SUBRESOURCE_DATA *initData, - TextureHelper11 *textureOut) -{ - d3d11::Texture2D texture; - ANGLE_TRY(mResourceManager11.allocate(this, &desc, initData, &texture)); - textureOut->init(std::move(texture), desc, format); - return gl::NoError(); -} - -gl::Error Renderer11::allocateTexture(const D3D11_TEXTURE3D_DESC &desc, - const d3d11::Format &format, - const D3D11_SUBRESOURCE_DATA *initData, - TextureHelper11 *textureOut) -{ - d3d11::Texture3D texture; - ANGLE_TRY(mResourceManager11.allocate(this, &desc, initData, &texture)); - textureOut->init(std::move(texture), desc, format); - return gl::NoError(); -} - -gl::Error Renderer11::getBlendState(const d3d11::BlendStateKey &key, - const d3d11::BlendState **outBlendState) -{ - return mStateCache.getBlendState(this, key, outBlendState); -} - -gl::Error Renderer11::getRasterizerState(const gl::RasterizerState &rasterState, - bool scissorEnabled, - ID3D11RasterizerState **outRasterizerState) -{ - return mStateCache.getRasterizerState(this, rasterState, scissorEnabled, outRasterizerState); -} - -gl::Error Renderer11::getDepthStencilState(const gl::DepthStencilState &dsState, - const d3d11::DepthStencilState **outDSState) -{ - return mStateCache.getDepthStencilState(this, dsState, outDSState); -} - -gl::Error Renderer11::getSamplerState(const gl::SamplerState &samplerState, - ID3D11SamplerState **outSamplerState) -{ - return mStateCache.getSamplerState(this, samplerState, outSamplerState); -} - -gl::Error Renderer11::clearRenderTarget(RenderTargetD3D *renderTarget, - const gl::ColorF &clearColorValue, - const float clearDepthValue, - const unsigned int clearStencilValue) -{ - RenderTarget11 *rt11 = GetAs<RenderTarget11>(renderTarget); - - if (rt11->getDepthStencilView().valid()) - { - const auto &format = rt11->getFormatSet(); - const UINT clearFlags = (format.format().depthBits > 0 ? D3D11_CLEAR_DEPTH : 0) | - (format.format().stencilBits ? D3D11_CLEAR_STENCIL : 0); - mDeviceContext->ClearDepthStencilView(rt11->getDepthStencilView().get(), clearFlags, - clearDepthValue, - static_cast<UINT8>(clearStencilValue)); - return gl::NoError(); - } - - ASSERT(rt11->getRenderTargetView().valid()); - ID3D11RenderTargetView *rtv = rt11->getRenderTargetView().get(); - - // There are complications with some types of RTV and FL 9_3 with ClearRenderTargetView. - // See https://msdn.microsoft.com/en-us/library/windows/desktop/ff476388(v=vs.85).aspx - ASSERT(mRenderer11DeviceCaps.featureLevel > D3D_FEATURE_LEVEL_9_3 || !IsArrayRTV(rtv)); - - const auto &d3d11Format = rt11->getFormatSet(); - const auto &glFormat = gl::GetSizedInternalFormatInfo(renderTarget->getInternalFormat()); - - gl::ColorF safeClearColor = clearColorValue; - - if (d3d11Format.format().alphaBits > 0 && glFormat.alphaBits == 0) - { - safeClearColor.alpha = 1.0f; - } - - mDeviceContext->ClearRenderTargetView(rtv, &safeClearColor.red); - return gl::NoError(); -} - -bool Renderer11::canSelectViewInVertexShader() const -{ - return !getWorkarounds().selectViewInGeometryShader && - getRenderer11DeviceCaps().supportsVpRtIndexWriteFromVertexShader; -} - -gl::Error Renderer11::markTransformFeedbackUsage(const gl::Context *context) -{ - const gl::State &glState = context->getGLState(); - const gl::TransformFeedback *transformFeedback = glState.getCurrentTransformFeedback(); - for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++) - { - const gl::OffsetBindingPointer<gl::Buffer> &binding = - transformFeedback->getIndexedBuffer(i); - if (binding.get() != nullptr) - { - BufferD3D *bufferD3D = GetImplAs<BufferD3D>(binding.get()); - ANGLE_TRY(bufferD3D->markTransformFeedbackUsage(context)); - } - } - - return gl::NoError(); -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Renderer11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Renderer11.h deleted file mode 100644 index a8c24e681b..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Renderer11.h +++ /dev/null @@ -1,576 +0,0 @@ -// -// Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Renderer11.h: Defines a back-end specific class for the D3D11 renderer. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_RENDERER11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_RENDERER11_H_ - -#include "common/angleutils.h" -#include "common/mathutil.h" -#include "libANGLE/AttributeMap.h" -#include "libANGLE/angletypes.h" -#include "libANGLE/renderer/d3d/HLSLCompiler.h" -#include "libANGLE/renderer/d3d/ProgramD3D.h" -#include "libANGLE/renderer/d3d/RenderTargetD3D.h" -#include "libANGLE/renderer/d3d/RendererD3D.h" -#include "libANGLE/renderer/d3d/d3d11/DebugAnnotator11.h" -#include "libANGLE/renderer/d3d/d3d11/RenderStateCache.h" -#include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h" -#include "libANGLE/renderer/d3d/d3d11/StateManager11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -namespace gl -{ -class FramebufferAttachment; -struct ImageIndex; -} - -namespace rx -{ -class Blit11; -class Buffer11; -class Clear11; -class Context11; -class IndexDataManager; -struct PackPixelsParams; -class PixelTransfer11; -class RenderTarget11; -class StreamingIndexBufferInterface; -class Trim11; -class VertexDataManager; - -struct Renderer11DeviceCaps -{ - Renderer11DeviceCaps(); - - D3D_FEATURE_LEVEL featureLevel; - bool supportsDXGI1_2; // Support for DXGI 1.2 - bool supportsClearView; // Support for ID3D11DeviceContext1::ClearView - bool supportsConstantBufferOffsets; // Support for Constant buffer offset - bool supportsVpRtIndexWriteFromVertexShader; // VP/RT can be selected in the Vertex Shader - // stage. - bool supportsMultisampledDepthStencilSRVs; // D3D feature level 10.0 no longer allows creation - // of textures with both the bind SRV and DSV flags - // when multisampled. Textures will need to be - // resolved before reading. crbug.com/656989 - UINT B5G6R5support; // Bitfield of D3D11_FORMAT_SUPPORT values for DXGI_FORMAT_B5G6R5_UNORM - UINT B5G6R5maxSamples; // Maximum number of samples supported by DXGI_FORMAT_B5G6R5_UNORM - UINT B4G4R4A4support; // Bitfield of D3D11_FORMAT_SUPPORT values for DXGI_FORMAT_B4G4R4A4_UNORM - UINT B4G4R4A4maxSamples; // Maximum number of samples supported by DXGI_FORMAT_B4G4R4A4_UNORM - UINT B5G5R5A1support; // Bitfield of D3D11_FORMAT_SUPPORT values for DXGI_FORMAT_B5G5R5A1_UNORM - UINT B5G5R5A1maxSamples; // Maximum number of samples supported by DXGI_FORMAT_B5G5R5A1_UNORM - Optional<LARGE_INTEGER> driverVersion; // Four-part driver version number. -}; - -enum -{ - MAX_VERTEX_UNIFORM_VECTORS_D3D11 = 1024, - MAX_FRAGMENT_UNIFORM_VECTORS_D3D11 = 1024 -}; - -// Possible reasons RendererD3D initialize can fail -enum D3D11InitError -{ - // The renderer loaded successfully - D3D11_INIT_SUCCESS = 0, - // Failed to load the ANGLE & D3D compiler libraries - D3D11_INIT_COMPILER_ERROR, - // Failed to load a necessary DLL (non-compiler) - D3D11_INIT_MISSING_DEP, - // CreateDevice returned E_INVALIDARG - D3D11_INIT_CREATEDEVICE_INVALIDARG, - // CreateDevice failed with an error other than invalid arg - D3D11_INIT_CREATEDEVICE_ERROR, - // DXGI 1.2 required but not found - D3D11_INIT_INCOMPATIBLE_DXGI, - // Other initialization error - D3D11_INIT_OTHER_ERROR, - // CreateDevice returned E_FAIL - D3D11_INIT_CREATEDEVICE_FAIL, - // CreateDevice returned E_NOTIMPL - D3D11_INIT_CREATEDEVICE_NOTIMPL, - // CreateDevice returned E_OUTOFMEMORY - D3D11_INIT_CREATEDEVICE_OUTOFMEMORY, - // CreateDevice returned DXGI_ERROR_INVALID_CALL - D3D11_INIT_CREATEDEVICE_INVALIDCALL, - // CreateDevice returned DXGI_ERROR_SDK_COMPONENT_MISSING - D3D11_INIT_CREATEDEVICE_COMPONENTMISSING, - // CreateDevice returned DXGI_ERROR_WAS_STILL_DRAWING - D3D11_INIT_CREATEDEVICE_WASSTILLDRAWING, - // CreateDevice returned DXGI_ERROR_NOT_CURRENTLY_AVAILABLE - D3D11_INIT_CREATEDEVICE_NOTAVAILABLE, - // CreateDevice returned DXGI_ERROR_DEVICE_HUNG - D3D11_INIT_CREATEDEVICE_DEVICEHUNG, - // CreateDevice returned NULL - D3D11_INIT_CREATEDEVICE_NULL, - NUM_D3D11_INIT_ERRORS -}; - -class Renderer11 : public RendererD3D -{ - public: - explicit Renderer11(egl::Display *display); - ~Renderer11() override; - - egl::Error initialize() override; - bool resetDevice() override; - - egl::ConfigSet generateConfigs() override; - void generateDisplayExtensions(egl::DisplayExtensions *outExtensions) const override; - - ContextImpl *createContext(const gl::ContextState &state) override; - - gl::Error flush(); - gl::Error finish(); - - bool isValidNativeWindow(EGLNativeWindowType window) const override; - NativeWindowD3D *createNativeWindow(EGLNativeWindowType window, - const egl::Config *config, - const egl::AttributeMap &attribs) const override; - - SwapChainD3D *createSwapChain(NativeWindowD3D *nativeWindow, - HANDLE shareHandle, - IUnknown *d3dTexture, - GLenum backBufferFormat, - GLenum depthBufferFormat, - EGLint orientation, - EGLint samples) override; - egl::Error getD3DTextureInfo(const egl::Config *configuration, - IUnknown *d3dTexture, - EGLint *width, - EGLint *height, - GLenum *fboFormat) const override; - egl::Error validateShareHandle(const egl::Config *config, - HANDLE shareHandle, - const egl::AttributeMap &attribs) const override; - - bool applyPrimitiveType(const gl::State &glState, GLenum mode, GLsizei count); - - // lost device - bool testDeviceLost() override; - bool testDeviceResettable() override; - - std::string getRendererDescription() const; - DeviceIdentifier getAdapterIdentifier() const override; - - unsigned int getReservedVertexUniformVectors() const; - unsigned int getReservedFragmentUniformVectors() const; - unsigned int getReservedVertexUniformBuffers() const; - unsigned int getReservedFragmentUniformBuffers() const; - - bool getShareHandleSupport() const; - - bool getNV12TextureSupport() const; - - int getMajorShaderModel() const override; - int getMinorShaderModel() const override; - std::string getShaderModelSuffix() const override; - - // Pixel operations - gl::Error copyImage2D(const gl::Context *context, - const gl::Framebuffer *framebuffer, - const gl::Rectangle &sourceRect, - GLenum destFormat, - const gl::Offset &destOffset, - TextureStorage *storage, - GLint level) override; - gl::Error copyImageCube(const gl::Context *context, - const gl::Framebuffer *framebuffer, - const gl::Rectangle &sourceRect, - GLenum destFormat, - const gl::Offset &destOffset, - TextureStorage *storage, - GLenum target, - GLint level) override; - gl::Error copyImage3D(const gl::Context *context, - const gl::Framebuffer *framebuffer, - const gl::Rectangle &sourceRect, - GLenum destFormat, - const gl::Offset &destOffset, - TextureStorage *storage, - GLint level) override; - gl::Error copyImage2DArray(const gl::Context *context, - const gl::Framebuffer *framebuffer, - const gl::Rectangle &sourceRect, - GLenum destFormat, - const gl::Offset &destOffset, - TextureStorage *storage, - GLint level) override; - - gl::Error copyTexture(const gl::Context *context, - const gl::Texture *source, - GLint sourceLevel, - const gl::Rectangle &sourceRect, - GLenum destFormat, - const gl::Offset &destOffset, - TextureStorage *storage, - GLenum destTarget, - GLint destLevel, - bool unpackFlipY, - bool unpackPremultiplyAlpha, - bool unpackUnmultiplyAlpha) override; - gl::Error copyCompressedTexture(const gl::Context *context, - const gl::Texture *source, - GLint sourceLevel, - TextureStorage *storage, - GLint destLevel) override; - - // RenderTarget creation - gl::Error createRenderTarget(int width, - int height, - GLenum format, - GLsizei samples, - RenderTargetD3D **outRT) override; - gl::Error createRenderTargetCopy(RenderTargetD3D *source, RenderTargetD3D **outRT) override; - - // Shader operations - gl::Error loadExecutable(const uint8_t *function, - size_t length, - gl::ShaderType type, - const std::vector<D3DVarying> &streamOutVaryings, - bool separatedOutputBuffers, - ShaderExecutableD3D **outExecutable) override; - gl::Error compileToExecutable(gl::InfoLog &infoLog, - const std::string &shaderHLSL, - gl::ShaderType type, - const std::vector<D3DVarying> &streamOutVaryings, - bool separatedOutputBuffers, - const angle::CompilerWorkaroundsD3D &workarounds, - ShaderExecutableD3D **outExectuable) override; - gl::Error ensureHLSLCompilerInitialized() override; - - UniformStorageD3D *createUniformStorage(size_t storageSize) override; - - // Image operations - ImageD3D *createImage() override; - gl::Error generateMipmap(const gl::Context *context, ImageD3D *dest, ImageD3D *source) override; - gl::Error generateMipmapUsingD3D(const gl::Context *context, - TextureStorage *storage, - const gl::TextureState &textureState) override; - gl::Error copyImage(const gl::Context *context, - ImageD3D *dest, - ImageD3D *source, - const gl::Rectangle &sourceRect, - const gl::Offset &destOffset, - bool unpackFlipY, - bool unpackPremultiplyAlpha, - bool unpackUnmultiplyAlpha) override; - TextureStorage *createTextureStorage2D(SwapChainD3D *swapChain) override; - TextureStorage *createTextureStorageEGLImage(EGLImageD3D *eglImage, - RenderTargetD3D *renderTargetD3D) override; - TextureStorage *createTextureStorageExternal( - egl::Stream *stream, - const egl::Stream::GLTextureDescription &desc) override; - TextureStorage *createTextureStorage2D(GLenum internalformat, - bool renderTarget, - GLsizei width, - GLsizei height, - int levels, - bool hintLevelZeroOnly) override; - TextureStorage *createTextureStorageCube(GLenum internalformat, - bool renderTarget, - int size, - int levels, - bool hintLevelZeroOnly) override; - TextureStorage *createTextureStorage3D(GLenum internalformat, - bool renderTarget, - GLsizei width, - GLsizei height, - GLsizei depth, - int levels) override; - TextureStorage *createTextureStorage2DArray(GLenum internalformat, - bool renderTarget, - GLsizei width, - GLsizei height, - GLsizei depth, - int levels) override; - TextureStorage *createTextureStorage2DMultisample(GLenum internalformat, - GLsizei width, - GLsizei height, - int levels, - int samples, - bool fixedSampleLocations) override; - - VertexBuffer *createVertexBuffer() override; - IndexBuffer *createIndexBuffer() override; - - // Stream Creation - StreamProducerImpl *createStreamProducerD3DTextureNV12( - egl::Stream::ConsumerType consumerType, - const egl::AttributeMap &attribs) override; - - // D3D11-renderer specific methods - ID3D11Device *getDevice() { return mDevice; } - void *getD3DDevice() override; - ID3D11DeviceContext *getDeviceContext() { return mDeviceContext; }; - ID3D11DeviceContext1 *getDeviceContext1IfSupported() { return mDeviceContext1; }; - IDXGIFactory *getDxgiFactory() { return mDxgiFactory; }; - - gl::Error getBlendState(const d3d11::BlendStateKey &key, - const d3d11::BlendState **outBlendState); - gl::Error getRasterizerState(const gl::RasterizerState &rasterState, - bool scissorEnabled, - ID3D11RasterizerState **outRasterizerState); - gl::Error getDepthStencilState(const gl::DepthStencilState &dsState, - const d3d11::DepthStencilState **outDSState); - gl::Error getSamplerState(const gl::SamplerState &samplerState, - ID3D11SamplerState **outSamplerState); - - Blit11 *getBlitter() { return mBlit; } - Clear11 *getClearer() { return mClear; } - gl::DebugAnnotator *getAnnotator(); - - // Buffer-to-texture and Texture-to-buffer copies - bool supportsFastCopyBufferToTexture(GLenum internalFormat) const override; - gl::Error fastCopyBufferToTexture(const gl::Context *context, - const gl::PixelUnpackState &unpack, - unsigned int offset, - RenderTargetD3D *destRenderTarget, - GLenum destinationFormat, - GLenum sourcePixelsType, - const gl::Box &destArea) override; - - gl::Error packPixels(const TextureHelper11 &textureHelper, - const PackPixelsParams ¶ms, - uint8_t *pixelsOut); - - bool getLUID(LUID *adapterLuid) const override; - VertexConversionType getVertexConversionType( - gl::VertexFormatType vertexFormatType) const override; - GLenum getVertexComponentType(gl::VertexFormatType vertexFormatType) const override; - - // Warning: you should ensure binding really matches attrib.bindingIndex before using this - // function. - gl::ErrorOrResult<unsigned int> getVertexSpaceRequired(const gl::VertexAttribute &attrib, - const gl::VertexBinding &binding, - GLsizei count, - GLsizei instances) const override; - - gl::Error readFromAttachment(const gl::Context *context, - const gl::FramebufferAttachment &srcAttachment, - const gl::Rectangle &sourceArea, - GLenum format, - GLenum type, - GLuint outputPitch, - const gl::PixelPackState &pack, - uint8_t *pixels); - - gl::Error blitRenderbufferRect(const gl::Context *context, - const gl::Rectangle &readRect, - const gl::Rectangle &drawRect, - RenderTargetD3D *readRenderTarget, - RenderTargetD3D *drawRenderTarget, - GLenum filter, - const gl::Rectangle *scissor, - bool colorBlit, - bool depthBlit, - bool stencilBlit); - - bool isES3Capable() const; - const Renderer11DeviceCaps &getRenderer11DeviceCaps() const { return mRenderer11DeviceCaps; }; - - RendererClass getRendererClass() const override; - StateManager11 *getStateManager() { return &mStateManager; } - - void onSwap(); - void onBufferCreate(const Buffer11 *created); - void onBufferDelete(const Buffer11 *deleted); - - egl::Error getEGLDevice(DeviceImpl **device) override; - - gl::Error drawArrays(const gl::Context *context, - GLenum mode, - GLint startVertex, - GLsizei count, - GLsizei instances); - - gl::Error drawElements(const gl::Context *context, - GLenum mode, - GLsizei count, - GLenum type, - const void *indices, - GLsizei instances); - - gl::Error drawArraysIndirect(const gl::Context *context, GLenum mode, const void *indirect); - gl::Error drawElementsIndirect(const gl::Context *context, - GLenum mode, - GLenum type, - const void *indirect); - - // Necessary hack for default framebuffers in D3D. - FramebufferImpl *createDefaultFramebuffer(const gl::FramebufferState &state) override; - - gl::Error getScratchMemoryBuffer(size_t requestedSize, angle::MemoryBuffer **bufferOut); - - gl::Version getMaxSupportedESVersion() const override; - - gl::Error dispatchCompute(const gl::Context *context, - GLuint numGroupsX, - GLuint numGroupsY, - GLuint numGroupsZ); - gl::Error applyComputeShader(const gl::Context *context); - - gl::ErrorOrResult<TextureHelper11> createStagingTexture(ResourceType textureType, - const d3d11::Format &formatSet, - const gl::Extents &size, - StagingAccess readAndWriteAccess); - - template <typename DescT, typename ResourceT> - gl::Error allocateResource(const DescT &desc, ResourceT *resourceOut) - { - return mResourceManager11.allocate(this, &desc, nullptr, resourceOut); - } - - template <typename DescT, typename InitDataT, typename ResourceT> - gl::Error allocateResource(const DescT &desc, InitDataT *initData, ResourceT *resourceOut) - { - return mResourceManager11.allocate(this, &desc, initData, resourceOut); - } - - template <typename InitDataT, typename ResourceT> - gl::Error allocateResourceNoDesc(InitDataT *initData, ResourceT *resourceOut) - { - return mResourceManager11.allocate(this, nullptr, initData, resourceOut); - } - - template <typename DescT> - gl::Error allocateTexture(const DescT &desc, - const d3d11::Format &format, - TextureHelper11 *textureOut) - { - return allocateTexture(desc, format, nullptr, textureOut); - } - - gl::Error allocateTexture(const D3D11_TEXTURE2D_DESC &desc, - const d3d11::Format &format, - const D3D11_SUBRESOURCE_DATA *initData, - TextureHelper11 *textureOut); - - gl::Error allocateTexture(const D3D11_TEXTURE3D_DESC &desc, - const d3d11::Format &format, - const D3D11_SUBRESOURCE_DATA *initData, - TextureHelper11 *textureOut); - - gl::Error clearRenderTarget(RenderTargetD3D *renderTarget, - const gl::ColorF &clearColorValue, - const float clearDepthValue, - const unsigned int clearStencilValue) override; - - bool canSelectViewInVertexShader() const override; - - private: - void generateCaps(gl::Caps *outCaps, - gl::TextureCapsMap *outTextureCaps, - gl::Extensions *outExtensions, - gl::Limitations *outLimitations) const override; - - angle::WorkaroundsD3D generateWorkarounds() const override; - - gl::Error drawLineLoop(const gl::Context *context, - GLsizei count, - GLenum type, - const void *indices, - int baseVertex, - int instances); - gl::Error drawTriangleFan(const gl::Context *context, - GLsizei count, - GLenum type, - const void *indices, - int baseVertex, - int instances); - - gl::ErrorOrResult<TextureHelper11> resolveMultisampledTexture(const gl::Context *context, - RenderTarget11 *renderTarget, - bool depth, - bool stencil); - - void populateRenderer11DeviceCaps(); - - void updateHistograms(); - - gl::Error copyImageInternal(const gl::Context *context, - const gl::Framebuffer *framebuffer, - const gl::Rectangle &sourceRect, - GLenum destFormat, - const gl::Offset &destOffset, - RenderTargetD3D *destRenderTarget); - - gl::SupportedSampleSet generateSampleSetForEGLConfig( - const gl::TextureCaps &colorBufferFormatCaps, - const gl::TextureCaps &depthStencilBufferFormatCaps) const; - - HRESULT callD3D11CreateDevice(PFN_D3D11_CREATE_DEVICE createDevice, bool debug); - egl::Error initializeD3DDevice(); - egl::Error initializeDevice(); - void releaseDeviceResources(); - void release(); - - d3d11::ANGLED3D11DeviceType getDeviceType() const; - - gl::Error markTransformFeedbackUsage(const gl::Context *context); - - HMODULE mD3d11Module; - HMODULE mDxgiModule; - HMODULE mDCompModule; - std::vector<D3D_FEATURE_LEVEL> mAvailableFeatureLevels; - D3D_DRIVER_TYPE mRequestedDriverType; - bool mCreateDebugDevice; - bool mCreatedWithDeviceEXT; - DeviceD3D *mEGLDevice; - - HLSLCompiler mCompiler; - - RenderStateCache mStateCache; - - StateManager11 mStateManager; - - StreamingIndexBufferInterface *mLineLoopIB; - StreamingIndexBufferInterface *mTriangleFanIB; - - // Texture copy resources - Blit11 *mBlit; - PixelTransfer11 *mPixelTransfer; - - // Masked clear resources - Clear11 *mClear; - - // Perform trim for D3D resources - Trim11 *mTrim; - - // Sync query - d3d11::Query mSyncQuery; - - // Created objects state tracking - std::set<const Buffer11 *> mAliveBuffers; - - double mLastHistogramUpdateTime; - - ID3D11Device *mDevice; - Renderer11DeviceCaps mRenderer11DeviceCaps; - ID3D11DeviceContext *mDeviceContext; - ID3D11DeviceContext1 *mDeviceContext1; - ID3D11DeviceContext3 *mDeviceContext3; - IDXGIAdapter *mDxgiAdapter; - DXGI_ADAPTER_DESC mAdapterDescription; - char mDescription[128]; - IDXGIFactory *mDxgiFactory; - ID3D11Debug *mDebug; - - std::vector<GLuint> mScratchIndexDataBuffer; - - angle::ScratchBuffer mScratchMemoryBuffer; - - gl::DebugAnnotator *mAnnotator; - - mutable Optional<bool> mSupportsShareHandles; - ResourceManager11 mResourceManager11; - - TextureHelper11 mCachedResolveTexture; -}; - -} // namespace rx -#endif // LIBANGLE_RENDERER_D3D_D3D11_RENDERER11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ResourceManager11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ResourceManager11.cpp deleted file mode 100644 index c228380a34..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ResourceManager11.cpp +++ /dev/null @@ -1,533 +0,0 @@ -// -// Copyright 2017 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// ResourceManager11: -// Centralized point of allocation for all D3D11 Resources. - -#include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h" - -#include "common/debug.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" - -namespace rx -{ - -namespace -{ - -constexpr uint8_t kDebugInitTextureDataValue = 0x48; -constexpr FLOAT kDebugColorInitClearValue[4] = {0.3f, 0.5f, 0.7f, 0.5f}; -constexpr FLOAT kDebugDepthInitValue = 0.2f; -constexpr UINT8 kDebugStencilInitValue = 3; - -uint64_t ComputeMippedMemoryUsage(unsigned int width, - unsigned int height, - unsigned int depth, - uint64_t pixelSize, - unsigned int mipLevels) -{ - uint64_t sizeSum = 0; - - for (unsigned int level = 0; level < mipLevels; ++level) - { - unsigned int mipWidth = std::max(width >> level, 1u); - unsigned int mipHeight = std::max(height >> level, 1u); - unsigned int mipDepth = std::max(depth >> level, 1u); - sizeSum += static_cast<uint64_t>(mipWidth * mipHeight * mipDepth) * pixelSize; - } - - return sizeSum; -} - -uint64_t ComputeMemoryUsage(const D3D11_TEXTURE2D_DESC *desc) -{ - ASSERT(desc); - uint64_t pixelBytes = - static_cast<uint64_t>(d3d11::GetDXGIFormatSizeInfo(desc->Format).pixelBytes); - return ComputeMippedMemoryUsage(desc->Width, desc->Height, 1, pixelBytes, desc->MipLevels); -} - -uint64_t ComputeMemoryUsage(const D3D11_TEXTURE3D_DESC *desc) -{ - ASSERT(desc); - uint64_t pixelBytes = - static_cast<uint64_t>(d3d11::GetDXGIFormatSizeInfo(desc->Format).pixelBytes); - return ComputeMippedMemoryUsage(desc->Width, desc->Height, desc->Depth, pixelBytes, - desc->MipLevels); -} - -uint64_t ComputeMemoryUsage(const D3D11_BUFFER_DESC *desc) -{ - ASSERT(desc); - return static_cast<uint64_t>(desc->ByteWidth); -} - -template <typename T> -uint64_t ComputeMemoryUsage(const T *desc) -{ - return 0; -} - -template <ResourceType ResourceT> -uint64_t ComputeGenericMemoryUsage(ID3D11DeviceChild *genericResource) -{ - auto *typedResource = static_cast<GetD3D11Type<ResourceT> *>(genericResource); - GetDescType<ResourceT> desc; - typedResource->GetDesc(&desc); - return ComputeMemoryUsage(&desc); -} - -uint64_t ComputeGenericMemoryUsage(ResourceType resourceType, ID3D11DeviceChild *resource) -{ - switch (resourceType) - { - case ResourceType::Texture2D: - return ComputeGenericMemoryUsage<ResourceType::Texture2D>(resource); - case ResourceType::Texture3D: - return ComputeGenericMemoryUsage<ResourceType::Texture3D>(resource); - case ResourceType::Buffer: - return ComputeGenericMemoryUsage<ResourceType::Buffer>(resource); - - default: - return 0; - } -} - -HRESULT CreateResource(ID3D11Device *device, - const D3D11_BLEND_DESC *desc, - void * /*initData*/, - ID3D11BlendState **blendState) -{ - return device->CreateBlendState(desc, blendState); -} - -HRESULT CreateResource(ID3D11Device *device, - const D3D11_BUFFER_DESC *desc, - const D3D11_SUBRESOURCE_DATA *initData, - ID3D11Buffer **buffer) -{ - return device->CreateBuffer(desc, initData, buffer); -} - -HRESULT CreateResource(ID3D11Device *device, - const ShaderData *desc, - void * /*initData*/, - ID3D11ComputeShader **resourceOut) -{ - return device->CreateComputeShader(desc->get(), desc->size(), nullptr, resourceOut); -} - -HRESULT CreateResource(ID3D11Device *device, - const D3D11_DEPTH_STENCIL_DESC *desc, - void * /*initData*/, - ID3D11DepthStencilState **resourceOut) -{ - return device->CreateDepthStencilState(desc, resourceOut); -} - -HRESULT CreateResource(ID3D11Device *device, - const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, - ID3D11Resource *resource, - ID3D11DepthStencilView **resourceOut) -{ - return device->CreateDepthStencilView(resource, desc, resourceOut); -} - -HRESULT CreateResource(ID3D11Device *device, - const ShaderData *desc, - const std::vector<D3D11_SO_DECLARATION_ENTRY> *initData, - ID3D11GeometryShader **resourceOut) -{ - if (initData) - { - return device->CreateGeometryShaderWithStreamOutput( - desc->get(), desc->size(), initData->data(), static_cast<UINT>(initData->size()), - nullptr, 0, 0, nullptr, resourceOut); - } - else - { - return device->CreateGeometryShader(desc->get(), desc->size(), nullptr, resourceOut); - } -} - -HRESULT CreateResource(ID3D11Device *device, - const InputElementArray *desc, - const ShaderData *initData, - ID3D11InputLayout **resourceOut) -{ - return device->CreateInputLayout(desc->get(), static_cast<UINT>(desc->size()), initData->get(), - initData->size(), resourceOut); -} - -HRESULT CreateResource(ID3D11Device *device, - const ShaderData *desc, - void * /*initData*/, - ID3D11PixelShader **resourceOut) -{ - return device->CreatePixelShader(desc->get(), desc->size(), nullptr, resourceOut); -} - -HRESULT CreateResource(ID3D11Device *device, - const D3D11_QUERY_DESC *desc, - void * /*initData*/, - ID3D11Query **resourceOut) -{ - return device->CreateQuery(desc, resourceOut); -} - -HRESULT CreateResource(ID3D11Device *device, - const D3D11_RASTERIZER_DESC *desc, - void * /*initData*/, - ID3D11RasterizerState **rasterizerState) -{ - return device->CreateRasterizerState(desc, rasterizerState); -} - -HRESULT CreateResource(ID3D11Device *device, - const D3D11_RENDER_TARGET_VIEW_DESC *desc, - ID3D11Resource *resource, - ID3D11RenderTargetView **renderTargetView) -{ - return device->CreateRenderTargetView(resource, desc, renderTargetView); -} - -HRESULT CreateResource(ID3D11Device *device, - const D3D11_SAMPLER_DESC *desc, - void * /*initData*/, - ID3D11SamplerState **resourceOut) -{ - return device->CreateSamplerState(desc, resourceOut); -} - -HRESULT CreateResource(ID3D11Device *device, - const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, - ID3D11Resource *resource, - ID3D11ShaderResourceView **resourceOut) -{ - return device->CreateShaderResourceView(resource, desc, resourceOut); -} - -HRESULT CreateResource(ID3D11Device *device, - const D3D11_TEXTURE2D_DESC *desc, - const D3D11_SUBRESOURCE_DATA *initData, - ID3D11Texture2D **texture) -{ - return device->CreateTexture2D(desc, initData, texture); -} - -HRESULT CreateResource(ID3D11Device *device, - const D3D11_TEXTURE3D_DESC *desc, - const D3D11_SUBRESOURCE_DATA *initData, - ID3D11Texture3D **texture) -{ - return device->CreateTexture3D(desc, initData, texture); -} - -HRESULT CreateResource(ID3D11Device *device, - const ShaderData *desc, - void * /*initData*/, - ID3D11VertexShader **resourceOut) -{ - return device->CreateVertexShader(desc->get(), desc->size(), nullptr, resourceOut); -} - -DXGI_FORMAT GetTypedDepthStencilFormat(DXGI_FORMAT dxgiFormat) -{ - switch (dxgiFormat) - { - case DXGI_FORMAT_R16_TYPELESS: - return DXGI_FORMAT_D16_UNORM; - case DXGI_FORMAT_R24G8_TYPELESS: - return DXGI_FORMAT_D24_UNORM_S8_UINT; - case DXGI_FORMAT_R32_TYPELESS: - return DXGI_FORMAT_D32_FLOAT; - case DXGI_FORMAT_R32G8X24_TYPELESS: - return DXGI_FORMAT_D32_FLOAT_S8X24_UINT; - default: - return dxgiFormat; - } -} - -template <typename DescT, typename ResourceT> -gl::Error ClearResource(Renderer11 *renderer, const DescT *desc, ResourceT *texture) -{ - // No-op. - return gl::NoError(); -} - -template <> -gl::Error ClearResource(Renderer11 *renderer, - const D3D11_TEXTURE2D_DESC *desc, - ID3D11Texture2D *texture) -{ - ID3D11DeviceContext *context = renderer->getDeviceContext(); - - if ((desc->BindFlags & D3D11_BIND_DEPTH_STENCIL) != 0) - { - D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; - dsvDesc.Flags = 0; - dsvDesc.Format = GetTypedDepthStencilFormat(desc->Format); - - const auto &format = d3d11_angle::GetFormat(dsvDesc.Format); - UINT clearFlags = (format.depthBits > 0 ? D3D11_CLEAR_DEPTH : 0) | - (format.stencilBits > 0 ? D3D11_CLEAR_STENCIL : 0); - - // Must process each mip level individually. - for (UINT mipLevel = 0; mipLevel < desc->MipLevels; ++mipLevel) - { - if (desc->SampleDesc.Count == 0) - { - dsvDesc.Texture2D.MipSlice = mipLevel; - dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; - } - else - { - dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS; - } - - d3d11::DepthStencilView dsv; - ANGLE_TRY(renderer->allocateResource(dsvDesc, texture, &dsv)); - - context->ClearDepthStencilView(dsv.get(), clearFlags, kDebugDepthInitValue, - kDebugStencilInitValue); - } - } - else - { - ASSERT((desc->BindFlags & D3D11_BIND_RENDER_TARGET) != 0); - d3d11::RenderTargetView rtv; - ANGLE_TRY(renderer->allocateResourceNoDesc(texture, &rtv)); - - context->ClearRenderTargetView(rtv.get(), kDebugColorInitClearValue); - } - - return gl::NoError(); -} - -template <> -gl::Error ClearResource(Renderer11 *renderer, - const D3D11_TEXTURE3D_DESC *desc, - ID3D11Texture3D *texture) -{ - ID3D11DeviceContext *context = renderer->getDeviceContext(); - - ASSERT((desc->BindFlags & D3D11_BIND_DEPTH_STENCIL) == 0); - ASSERT((desc->BindFlags & D3D11_BIND_RENDER_TARGET) != 0); - - d3d11::RenderTargetView rtv; - ANGLE_TRY(renderer->allocateResourceNoDesc(texture, &rtv)); - - context->ClearRenderTargetView(rtv.get(), kDebugColorInitClearValue); - return gl::NoError(); -} - -#define ANGLE_RESOURCE_STRINGIFY_OP(NAME, RESTYPE, D3D11TYPE, DESCTYPE, INITDATATYPE) #RESTYPE, - -constexpr std::array<const char *, NumResourceTypes> kResourceTypeNames = { - {ANGLE_RESOURCE_TYPE_OP(Stringify, ANGLE_RESOURCE_STRINGIFY_OP)}}; -static_assert(kResourceTypeNames[NumResourceTypes - 1] != nullptr, - "All members must be initialized."); - -} // anonymous namespace - -// ResourceManager11 Implementation. -ResourceManager11::ResourceManager11() - : mInitializeAllocations(false), - mAllocatedResourceCounts({{}}), - mAllocatedResourceDeviceMemory({{}}) -{ -} - -ResourceManager11::~ResourceManager11() -{ - for (size_t count : mAllocatedResourceCounts) - { - ASSERT(count == 0); - } - - for (uint64_t memorySize : mAllocatedResourceDeviceMemory) - { - ASSERT(memorySize == 0); - } -} - -template <typename T> -gl::Error ResourceManager11::allocate(Renderer11 *renderer, - const GetDescFromD3D11<T> *desc, - GetInitDataFromD3D11<T> *initData, - Resource11<T> *resourceOut) -{ - ID3D11Device *device = renderer->getDevice(); - T *resource = nullptr; - - GetInitDataFromD3D11<T> *shadowInitData = initData; - if (!shadowInitData && mInitializeAllocations) - { - shadowInitData = createInitDataIfNeeded<T>(desc); - } - - HRESULT hr = CreateResource(device, desc, shadowInitData, &resource); - if (FAILED(hr)) - { - ASSERT(!resource); - if (d3d11::isDeviceLostError(hr)) - { - renderer->notifyDeviceLost(); - } - return gl::OutOfMemory() << "Error allocating " - << std::string(kResourceTypeNames[ResourceTypeIndex<T>()]) << ". " - << gl::FmtHR(hr); - } - - if (!shadowInitData && mInitializeAllocations) - { - ANGLE_TRY(ClearResource(renderer, desc, resource)); - } - - ASSERT(resource); - incrResource(GetResourceTypeFromD3D11<T>(), ComputeMemoryUsage(desc)); - *resourceOut = std::move(Resource11<T>(resource, this)); - return gl::NoError(); -} - -void ResourceManager11::incrResource(ResourceType resourceType, uint64_t memorySize) -{ - size_t typeIndex = ResourceTypeIndex(resourceType); - - mAllocatedResourceCounts[typeIndex]++; - mAllocatedResourceDeviceMemory[typeIndex] += memorySize; - - // This checks for integer overflow. - ASSERT(mAllocatedResourceCounts[typeIndex] > 0); - ASSERT(mAllocatedResourceDeviceMemory[typeIndex] >= memorySize); -} - -void ResourceManager11::decrResource(ResourceType resourceType, uint64_t memorySize) -{ - size_t typeIndex = ResourceTypeIndex(resourceType); - - ASSERT(mAllocatedResourceCounts[typeIndex] > 0); - mAllocatedResourceCounts[typeIndex]--; - ASSERT(mAllocatedResourceDeviceMemory[typeIndex] >= memorySize); - mAllocatedResourceDeviceMemory[typeIndex] -= memorySize; -} - -void ResourceManager11::onReleaseGeneric(ResourceType resourceType, ID3D11DeviceChild *resource) -{ - ASSERT(resource); - decrResource(resourceType, ComputeGenericMemoryUsage(resourceType, resource)); -} - -template <> -const D3D11_SUBRESOURCE_DATA *ResourceManager11::createInitDataIfNeeded<ID3D11Texture2D>( - const D3D11_TEXTURE2D_DESC *desc) -{ - ASSERT(desc); - - if ((desc->BindFlags & (D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_RENDER_TARGET)) != 0) - { - // This will be done using ClearView methods. - return nullptr; - } - - size_t requiredSize = static_cast<size_t>(ComputeMemoryUsage(desc)); - if (mZeroMemory.size() < requiredSize) - { - mZeroMemory.resize(requiredSize); - mZeroMemory.fill(kDebugInitTextureDataValue); - } - - const auto &formatSizeInfo = d3d11::GetDXGIFormatSizeInfo(desc->Format); - - UINT subresourceCount = desc->MipLevels * desc->ArraySize; - if (mShadowInitData.size() < subresourceCount) - { - mShadowInitData.resize(subresourceCount); - } - - for (UINT mipLevel = 0; mipLevel < desc->MipLevels; ++mipLevel) - { - for (UINT arrayIndex = 0; arrayIndex < desc->ArraySize; ++arrayIndex) - { - UINT subresourceIndex = D3D11CalcSubresource(mipLevel, arrayIndex, desc->MipLevels); - D3D11_SUBRESOURCE_DATA *data = &mShadowInitData[subresourceIndex]; - - UINT levelWidth = std::max(desc->Width >> mipLevel, 1u); - UINT levelHeight = std::max(desc->Height >> mipLevel, 1u); - - data->SysMemPitch = levelWidth * formatSizeInfo.pixelBytes; - data->SysMemSlicePitch = data->SysMemPitch * levelHeight; - data->pSysMem = mZeroMemory.data(); - } - } - - return mShadowInitData.data(); -} - -template <> -const D3D11_SUBRESOURCE_DATA *ResourceManager11::createInitDataIfNeeded<ID3D11Texture3D>( - const D3D11_TEXTURE3D_DESC *desc) -{ - ASSERT(desc); - - if ((desc->BindFlags & D3D11_BIND_RENDER_TARGET) != 0) - { - // This will be done using ClearView methods. - return nullptr; - } - - size_t requiredSize = static_cast<size_t>(ComputeMemoryUsage(desc)); - if (mZeroMemory.size() < requiredSize) - { - mZeroMemory.resize(requiredSize); - mZeroMemory.fill(kDebugInitTextureDataValue); - } - - const auto &formatSizeInfo = d3d11::GetDXGIFormatSizeInfo(desc->Format); - - UINT subresourceCount = desc->MipLevels; - if (mShadowInitData.size() < subresourceCount) - { - mShadowInitData.resize(subresourceCount); - } - - for (UINT mipLevel = 0; mipLevel < desc->MipLevels; ++mipLevel) - { - UINT subresourceIndex = D3D11CalcSubresource(mipLevel, 0, desc->MipLevels); - D3D11_SUBRESOURCE_DATA *data = &mShadowInitData[subresourceIndex]; - - UINT levelWidth = std::max(desc->Width >> mipLevel, 1u); - UINT levelHeight = std::max(desc->Height >> mipLevel, 1u); - - data->SysMemPitch = levelWidth * formatSizeInfo.pixelBytes; - data->SysMemSlicePitch = data->SysMemPitch * levelHeight; - data->pSysMem = mZeroMemory.data(); - } - - return mShadowInitData.data(); -} - -template <typename T> -GetInitDataFromD3D11<T> *ResourceManager11::createInitDataIfNeeded(const GetDescFromD3D11<T> *desc) -{ - // No-op. - return nullptr; -} - -void ResourceManager11::setAllocationsInitialized(bool initialize) -{ - mInitializeAllocations = initialize; -} - -#define ANGLE_INSTANTIATE_OP(NAME, RESTYPE, D3D11TYPE, DESCTYPE, INITDATATYPE) \ - \ -template \ -gl::Error \ - ResourceManager11::allocate(Renderer11 *, const DESCTYPE *, INITDATATYPE *, \ - Resource11<D3D11TYPE> *); - -ANGLE_RESOURCE_TYPE_OP(Instantitate, ANGLE_INSTANTIATE_OP) -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ResourceManager11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ResourceManager11.h deleted file mode 100644 index 0bdde9f8b6..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ResourceManager11.h +++ /dev/null @@ -1,366 +0,0 @@ -// -// Copyright 2017 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// ResourceManager11: -// Centralized point of allocation for all D3D11 Resources. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_RESOURCEFACTORY11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_RESOURCEFACTORY11_H_ - -#include <array> -#include <memory> - -#include "common/MemoryBuffer.h" -#include "common/angleutils.h" -#include "common/debug.h" -#include "libANGLE/Error.h" -#include "libANGLE/renderer/renderer_utils.h" - -namespace rx -{ -// These two methods are declared here to prevent circular includes. -namespace d3d11 -{ -HRESULT SetDebugName(ID3D11DeviceChild *resource, const char *name); - -template <typename T> -HRESULT SetDebugName(angle::ComPtr<T> &resource, const char *name) -{ - return SetDebugName(resource.Get(), name); -} -} // namespace d3d11 - -class Renderer11; -class ResourceManager11; -template <typename T> -class SharedResource11; -class TextureHelper11; - -using InputElementArray = WrappedArray<D3D11_INPUT_ELEMENT_DESC>; -using ShaderData = WrappedArray<uint8_t>; - -// Format: ResourceType, D3D11 type, DESC type, init data type. -#define ANGLE_RESOURCE_TYPE_OP(NAME, OP) \ - OP(NAME, BlendState, ID3D11BlendState, D3D11_BLEND_DESC, void) \ - OP(NAME, Buffer, ID3D11Buffer, D3D11_BUFFER_DESC, const D3D11_SUBRESOURCE_DATA) \ - OP(NAME, ComputeShader, ID3D11ComputeShader, ShaderData, void) \ - OP(NAME, DepthStencilState, ID3D11DepthStencilState, D3D11_DEPTH_STENCIL_DESC, void) \ - OP(NAME, DepthStencilView, ID3D11DepthStencilView, D3D11_DEPTH_STENCIL_VIEW_DESC, \ - ID3D11Resource) \ - OP(NAME, GeometryShader, ID3D11GeometryShader, ShaderData, \ - const std::vector<D3D11_SO_DECLARATION_ENTRY>) \ - OP(NAME, InputLayout, ID3D11InputLayout, InputElementArray, const ShaderData) \ - OP(NAME, PixelShader, ID3D11PixelShader, ShaderData, void) \ - OP(NAME, Query, ID3D11Query, D3D11_QUERY_DESC, void) \ - OP(NAME, RasterizerState, ID3D11RasterizerState, D3D11_RASTERIZER_DESC, void) \ - OP(NAME, RenderTargetView, ID3D11RenderTargetView, D3D11_RENDER_TARGET_VIEW_DESC, \ - ID3D11Resource) \ - OP(NAME, SamplerState, ID3D11SamplerState, D3D11_SAMPLER_DESC, void) \ - OP(NAME, ShaderResourceView, ID3D11ShaderResourceView, D3D11_SHADER_RESOURCE_VIEW_DESC, \ - ID3D11Resource) \ - OP(NAME, Texture2D, ID3D11Texture2D, D3D11_TEXTURE2D_DESC, const D3D11_SUBRESOURCE_DATA) \ - OP(NAME, Texture3D, ID3D11Texture3D, D3D11_TEXTURE3D_DESC, const D3D11_SUBRESOURCE_DATA) \ - OP(NAME, VertexShader, ID3D11VertexShader, ShaderData, void) - -#define ANGLE_RESOURCE_TYPE_LIST(NAME, RESTYPE, D3D11TYPE, DESCTYPE, INITDATATYPE) RESTYPE, - -enum class ResourceType -{ - ANGLE_RESOURCE_TYPE_OP(List, ANGLE_RESOURCE_TYPE_LIST) Last -}; - -#undef ANGLE_RESOURCE_TYPE_LIST - -constexpr size_t ResourceTypeIndex(ResourceType resourceType) -{ - return static_cast<size_t>(resourceType); -} - -constexpr size_t NumResourceTypes = ResourceTypeIndex(ResourceType::Last); - -#define ANGLE_RESOURCE_TYPE_TO_D3D11(NAME, RESTYPE, D3D11TYPE, DESCTYPE, INITDATATYPE) \ - \ -template<> struct NAME<ResourceType::RESTYPE> \ - { \ - using Value = D3D11TYPE; \ - }; - -#define ANGLE_RESOURCE_TYPE_TO_DESC(NAME, RESTYPE, D3D11TYPE, DESCTYPE, INITDATATYPE) \ - \ -template<> struct NAME<ResourceType::RESTYPE> \ - { \ - using Value = DESCTYPE; \ - }; - -#define ANGLE_RESOURCE_TYPE_TO_INIT_DATA(NAME, RESTYPE, D3D11TYPE, DESCTYPE, INITDATATYPE) \ - \ -template<> struct NAME<ResourceType::RESTYPE> \ - { \ - using Value = INITDATATYPE; \ - }; - -#define ANGLE_RESOURCE_TYPE_TO_TYPE(NAME, OP) \ - template <ResourceType Param> \ - struct NAME; \ - ANGLE_RESOURCE_TYPE_OP(NAME, OP) \ - \ -template<ResourceType Param> struct NAME \ - { \ - }; \ - \ -template<ResourceType Param> using Get##NAME = typename NAME<Param>::Value; - -ANGLE_RESOURCE_TYPE_TO_TYPE(D3D11Type, ANGLE_RESOURCE_TYPE_TO_D3D11) -ANGLE_RESOURCE_TYPE_TO_TYPE(DescType, ANGLE_RESOURCE_TYPE_TO_DESC) -ANGLE_RESOURCE_TYPE_TO_TYPE(InitDataType, ANGLE_RESOURCE_TYPE_TO_INIT_DATA) - -#undef ANGLE_RESOURCE_TYPE_TO_D3D11 -#undef ANGLE_RESOURCE_TYPE_TO_DESC -#undef ANGLE_RESOURCE_TYPE_TO_INIT_DATA -#undef ANGLE_RESOURCE_TYPE_TO_TYPE - -#define ANGLE_TYPE_TO_RESOURCE_TYPE(NAME, OP) \ - template <typename Param> \ - struct NAME; \ - ANGLE_RESOURCE_TYPE_OP(NAME, OP) \ - \ -template<typename Param> struct NAME \ - { \ - }; \ - \ -template<typename Param> constexpr ResourceType Get##NAME() \ - { \ - return NAME<Param>::Value; \ - } - -#define ANGLE_D3D11_TO_RESOURCE_TYPE(NAME, RESTYPE, D3D11TYPE, DESCTYPE, INITDATATYPE) \ - \ -template<> struct NAME<D3D11TYPE> \ - { \ - static constexpr ResourceType Value = ResourceType::RESTYPE; \ - }; - -ANGLE_TYPE_TO_RESOURCE_TYPE(ResourceTypeFromD3D11, ANGLE_D3D11_TO_RESOURCE_TYPE) - -#undef ANGLE_D3D11_TO_RESOURCE_TYPE -#undef ANGLE_TYPE_TO_RESOURCE_TYPE - -template <typename T> -using GetDescFromD3D11 = GetDescType<ResourceTypeFromD3D11<T>::Value>; - -template <typename T> -using GetInitDataFromD3D11 = GetInitDataType<ResourceTypeFromD3D11<T>::Value>; - -template <typename T> -constexpr size_t ResourceTypeIndex() -{ - return static_cast<size_t>(GetResourceTypeFromD3D11<T>()); -} - -template <typename T> -struct TypedData -{ - TypedData() {} - ~TypedData(); - - T *object = nullptr; - ResourceManager11 *manager = nullptr; -}; - -// Smart pointer type. Wraps the resource and a factory for safe deletion. -template <typename T, template <class> class Pointer, typename DataT> -class Resource11Base : angle::NonCopyable -{ - public: - T *get() const { return mData->object; } - T *const *getPointer() const { return &mData->object; } - - void setDebugName(const char *name) { d3d11::SetDebugName(mData->object, name); } - - void set(T *object) - { - ASSERT(!valid()); - mData->object = object; - } - - bool valid() const { return (mData->object != nullptr); } - - void reset() - { - if (valid()) - mData.reset(new DataT()); - } - - ResourceSerial getSerial() const - { - return ResourceSerial(reinterpret_cast<uintptr_t>(mData->object)); - } - - protected: - friend class TextureHelper11; - - Resource11Base() : mData(new DataT()) {} - - Resource11Base(Resource11Base &&movedObj) : mData(new DataT()) - { - std::swap(mData, movedObj.mData); - } - - virtual ~Resource11Base() { mData.reset(); } - - Resource11Base &operator=(Resource11Base &&movedObj) - { - std::swap(mData, movedObj.mData); - return *this; - } - - Pointer<DataT> mData; -}; - -template <typename T> -using UniquePtr = typename std::unique_ptr<T, std::default_delete<T>>; - -template <typename ResourceT> -class Resource11 : public Resource11Base<ResourceT, UniquePtr, TypedData<ResourceT>> -{ - public: - Resource11() {} - Resource11(Resource11 &&other) - : Resource11Base<ResourceT, UniquePtr, TypedData<ResourceT>>(std::move(other)) - { - } - Resource11 &operator=(Resource11 &&other) - { - std::swap(this->mData, other.mData); - return *this; - } - - private: - template <typename T> - friend class SharedResource11; - friend class ResourceManager11; - - Resource11(ResourceT *object, ResourceManager11 *manager) - { - this->mData->object = object; - this->mData->manager = manager; - } -}; - -template <typename T> -class SharedResource11 : public Resource11Base<T, std::shared_ptr, TypedData<T>> -{ - public: - SharedResource11() {} - SharedResource11(SharedResource11 &&movedObj) - : Resource11Base<T, std::shared_ptr, TypedData<T>>(std::move(movedObj)) - { - } - - SharedResource11 &operator=(SharedResource11 &&other) - { - std::swap(this->mData, other.mData); - return *this; - } - - SharedResource11 makeCopy() const - { - SharedResource11 copy; - copy.mData = this->mData; - return std::move(copy); - } - - private: - friend class ResourceManager11; - SharedResource11(Resource11<T> &&obj) : Resource11Base<T, std::shared_ptr, TypedData<T>>() - { - std::swap(this->mData->manager, obj.mData->manager); - - // Can't use std::swap because of ID3D11Resource. - auto temp = this->mData->object; - this->mData->object = obj.mData->object; - obj.mData->object = static_cast<T *>(temp); - } -}; - -class ResourceManager11 final : angle::NonCopyable -{ - public: - ResourceManager11(); - ~ResourceManager11(); - - template <typename T> - gl::Error allocate(Renderer11 *renderer, - const GetDescFromD3D11<T> *desc, - GetInitDataFromD3D11<T> *initData, - Resource11<T> *resourceOut); - - template <typename T> - gl::Error allocate(Renderer11 *renderer, - const GetDescFromD3D11<T> *desc, - GetInitDataFromD3D11<T> *initData, - SharedResource11<T> *sharedRes) - { - Resource11<T> res; - ANGLE_TRY(allocate(renderer, desc, initData, &res)); - *sharedRes = std::move(res); - return gl::NoError(); - } - - template <typename T> - void onRelease(T *resource) - { - onReleaseGeneric(GetResourceTypeFromD3D11<T>(), resource); - } - - void onReleaseGeneric(ResourceType resourceType, ID3D11DeviceChild *resource); - - void setAllocationsInitialized(bool initialize); - - private: - void incrResource(ResourceType resourceType, uint64_t memorySize); - void decrResource(ResourceType resourceType, uint64_t memorySize); - - template <typename T> - GetInitDataFromD3D11<T> *createInitDataIfNeeded(const GetDescFromD3D11<T> *desc); - - bool mInitializeAllocations; - - std::array<size_t, NumResourceTypes> mAllocatedResourceCounts; - std::array<uint64_t, NumResourceTypes> mAllocatedResourceDeviceMemory; - angle::MemoryBuffer mZeroMemory; - - std::vector<D3D11_SUBRESOURCE_DATA> mShadowInitData; -}; - -template <typename ResourceT> -TypedData<ResourceT>::~TypedData() -{ - if (object) - { - // We can have a nullptr factory when holding passed-in resources. - if (manager) - { - manager->onRelease(object); - } - object->Release(); - } -} - -#define ANGLE_RESOURCE_TYPE_CLASS(NAME, RESTYPE, D3D11TYPE, DESCTYPE, INITDATATYPE) \ - using RESTYPE = Resource11<D3D11TYPE>; - -namespace d3d11 -{ -ANGLE_RESOURCE_TYPE_OP(ClassList, ANGLE_RESOURCE_TYPE_CLASS) - -using SharedSRV = SharedResource11<ID3D11ShaderResourceView>; -} // namespace d3d11 - -#undef ANGLE_RESOURCE_TYPE_CLASS - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_RESOURCEFACTORY11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ShaderExecutable11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ShaderExecutable11.cpp deleted file mode 100644 index 73a530add0..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ShaderExecutable11.cpp +++ /dev/null @@ -1,119 +0,0 @@ -// -// Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// ShaderExecutable11.cpp: Implements a D3D11-specific class to contain shader -// executable implementation details. - -#include "libANGLE/renderer/d3d/d3d11/ShaderExecutable11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" - -namespace rx -{ - -ShaderExecutable11::ShaderExecutable11(const void *function, - size_t length, - d3d11::PixelShader &&executable) - : ShaderExecutableD3D(function, length), - mPixelExecutable(std::move(executable)), - mVertexExecutable(), - mGeometryExecutable(), - mStreamOutExecutable(), - mComputeExecutable() -{ -} - -ShaderExecutable11::ShaderExecutable11(const void *function, - size_t length, - d3d11::VertexShader &&executable, - d3d11::GeometryShader &&streamOut) - : ShaderExecutableD3D(function, length), - mPixelExecutable(), - mVertexExecutable(std::move(executable)), - mGeometryExecutable(), - mStreamOutExecutable(std::move(streamOut)), - mComputeExecutable() -{ -} - -ShaderExecutable11::ShaderExecutable11(const void *function, - size_t length, - d3d11::GeometryShader &&executable) - : ShaderExecutableD3D(function, length), - mPixelExecutable(), - mVertexExecutable(), - mGeometryExecutable(std::move(executable)), - mStreamOutExecutable(), - mComputeExecutable() -{ -} - -ShaderExecutable11::ShaderExecutable11(const void *function, - size_t length, - d3d11::ComputeShader &&executable) - : ShaderExecutableD3D(function, length), - mPixelExecutable(), - mVertexExecutable(), - mGeometryExecutable(), - mStreamOutExecutable(), - mComputeExecutable(std::move(executable)) -{ -} - -ShaderExecutable11::~ShaderExecutable11() -{ -} - -const d3d11::VertexShader &ShaderExecutable11::getVertexShader() const -{ - return mVertexExecutable; -} - -const d3d11::PixelShader &ShaderExecutable11::getPixelShader() const -{ - return mPixelExecutable; -} - -const d3d11::GeometryShader &ShaderExecutable11::getGeometryShader() const -{ - return mGeometryExecutable; -} - -const d3d11::GeometryShader &ShaderExecutable11::getStreamOutShader() const -{ - return mStreamOutExecutable; -} - -const d3d11::ComputeShader &ShaderExecutable11::getComputeShader() const -{ - return mComputeExecutable; -} - -UniformStorage11::UniformStorage11(size_t initialSize) - : UniformStorageD3D(initialSize), mConstantBuffer() -{ -} - -UniformStorage11::~UniformStorage11() -{ -} - -gl::Error UniformStorage11::getConstantBuffer(Renderer11 *renderer, const d3d11::Buffer **bufferOut) -{ - if (size() > 0 && !mConstantBuffer.valid()) - { - D3D11_BUFFER_DESC desc = {0}; - desc.ByteWidth = static_cast<unsigned int>(size()); - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - - ANGLE_TRY(renderer->allocateResource(desc, &mConstantBuffer)); - } - - *bufferOut = &mConstantBuffer; - return gl::NoError(); -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ShaderExecutable11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ShaderExecutable11.h deleted file mode 100644 index 3f417578a3..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/ShaderExecutable11.h +++ /dev/null @@ -1,62 +0,0 @@ -// -// Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// ShaderExecutable11.h: Defines a D3D11-specific class to contain shader -// executable implementation details. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_SHADEREXECUTABLE11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_SHADEREXECUTABLE11_H_ - -#include "libANGLE/renderer/d3d/ShaderExecutableD3D.h" -#include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h" - -namespace rx -{ -class Renderer11; -class UniformStorage11; - -class ShaderExecutable11 : public ShaderExecutableD3D -{ - public: - ShaderExecutable11(const void *function, size_t length, d3d11::PixelShader &&executable); - ShaderExecutable11(const void *function, - size_t length, - d3d11::VertexShader &&executable, - d3d11::GeometryShader &&streamOut); - ShaderExecutable11(const void *function, size_t length, d3d11::GeometryShader &&executable); - ShaderExecutable11(const void *function, size_t length, d3d11::ComputeShader &&executable); - - ~ShaderExecutable11() override; - - const d3d11::PixelShader &getPixelShader() const; - const d3d11::VertexShader &getVertexShader() const; - const d3d11::GeometryShader &getGeometryShader() const; - const d3d11::GeometryShader &getStreamOutShader() const; - const d3d11::ComputeShader &getComputeShader() const; - - private: - d3d11::PixelShader mPixelExecutable; - d3d11::VertexShader mVertexExecutable; - d3d11::GeometryShader mGeometryExecutable; - d3d11::GeometryShader mStreamOutExecutable; - d3d11::ComputeShader mComputeExecutable; -}; - -class UniformStorage11 : public UniformStorageD3D -{ - public: - UniformStorage11(size_t initialSize); - ~UniformStorage11() override; - - gl::Error getConstantBuffer(Renderer11 *renderer, const d3d11::Buffer **bufferOut); - - private: - d3d11::Buffer mConstantBuffer; -}; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_SHADEREXECUTABLE11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/StateManager11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/StateManager11.cpp deleted file mode 100644 index e9902d3f14..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/StateManager11.cpp +++ /dev/null @@ -1,3075 +0,0 @@ -// -// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// StateManager11.cpp: Defines a class for caching D3D11 state - -#include "libANGLE/renderer/d3d/d3d11/StateManager11.h" - -#include "common/bitset_utils.h" -#include "common/utilities.h" -#include "libANGLE/Context.h" -#include "libANGLE/Query.h" -#include "libANGLE/VertexArray.h" -#include "libANGLE/renderer/d3d/TextureD3D.h" -#include "libANGLE/renderer/d3d/d3d11/Buffer11.h" -#include "libANGLE/renderer/d3d/d3d11/Context11.h" -#include "libANGLE/renderer/d3d/d3d11/Framebuffer11.h" -#include "libANGLE/renderer/d3d/d3d11/IndexBuffer11.h" -#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/ShaderExecutable11.h" -#include "libANGLE/renderer/d3d/d3d11/TextureStorage11.h" -#include "libANGLE/renderer/d3d/d3d11/TransformFeedback11.h" -#include "libANGLE/renderer/d3d/d3d11/VertexArray11.h" - -namespace rx -{ - -namespace -{ -bool ImageIndexConflictsWithSRV(const gl::ImageIndex &index, D3D11_SHADER_RESOURCE_VIEW_DESC desc) -{ - unsigned mipLevel = index.mipIndex; - GLint layerIndex = index.layerIndex; - GLenum type = index.type; - - switch (desc.ViewDimension) - { - case D3D11_SRV_DIMENSION_TEXTURE2D: - { - bool allLevels = (desc.Texture2D.MipLevels == std::numeric_limits<UINT>::max()); - unsigned int maxSrvMip = desc.Texture2D.MipLevels + desc.Texture2D.MostDetailedMip; - maxSrvMip = allLevels ? INT_MAX : maxSrvMip; - - unsigned mipMin = index.mipIndex; - unsigned mipMax = (layerIndex == -1) ? INT_MAX : layerIndex; - - return type == GL_TEXTURE_2D && - gl::RangeUI(mipMin, mipMax) - .intersects(gl::RangeUI(desc.Texture2D.MostDetailedMip, maxSrvMip)); - } - - case D3D11_SRV_DIMENSION_TEXTURE2DARRAY: - { - bool allLevels = (desc.Texture2DArray.MipLevels == std::numeric_limits<UINT>::max()); - unsigned int maxSrvMip = - desc.Texture2DArray.MipLevels + desc.Texture2DArray.MostDetailedMip; - maxSrvMip = allLevels ? INT_MAX : maxSrvMip; - - unsigned maxSlice = desc.Texture2DArray.FirstArraySlice + desc.Texture2DArray.ArraySize; - - // Cube maps can be mapped to Texture2DArray SRVs - return (type == GL_TEXTURE_2D_ARRAY || gl::IsCubeMapTextureTarget(type)) && - desc.Texture2DArray.MostDetailedMip <= mipLevel && mipLevel < maxSrvMip && - desc.Texture2DArray.FirstArraySlice <= static_cast<UINT>(layerIndex) && - static_cast<UINT>(layerIndex) < maxSlice; - } - - case D3D11_SRV_DIMENSION_TEXTURECUBE: - { - bool allLevels = (desc.TextureCube.MipLevels == std::numeric_limits<UINT>::max()); - unsigned int maxSrvMip = desc.TextureCube.MipLevels + desc.TextureCube.MostDetailedMip; - maxSrvMip = allLevels ? INT_MAX : maxSrvMip; - - return gl::IsCubeMapTextureTarget(type) && - desc.TextureCube.MostDetailedMip <= mipLevel && mipLevel < maxSrvMip; - } - - case D3D11_SRV_DIMENSION_TEXTURE3D: - { - bool allLevels = (desc.Texture3D.MipLevels == std::numeric_limits<UINT>::max()); - unsigned int maxSrvMip = desc.Texture3D.MipLevels + desc.Texture3D.MostDetailedMip; - maxSrvMip = allLevels ? INT_MAX : maxSrvMip; - - return type == GL_TEXTURE_3D && desc.Texture3D.MostDetailedMip <= mipLevel && - mipLevel < maxSrvMip; - } - default: - // We only handle the cases corresponding to valid image indexes - UNIMPLEMENTED(); - } - - return false; -} - -// Does *not* increment the resource ref count!! -ID3D11Resource *GetViewResource(ID3D11View *view) -{ - ID3D11Resource *resource = nullptr; - ASSERT(view); - view->GetResource(&resource); - resource->Release(); - return resource; -} - -int GetWrapBits(GLenum wrap) -{ - switch (wrap) - { - case GL_CLAMP_TO_EDGE: - return 0x1; - case GL_REPEAT: - return 0x2; - case GL_MIRRORED_REPEAT: - return 0x3; - default: - UNREACHABLE(); - return 0; - } -} - -Optional<size_t> FindFirstNonInstanced( - const std::vector<const TranslatedAttribute *> ¤tAttributes) -{ - for (size_t index = 0; index < currentAttributes.size(); ++index) - { - if (currentAttributes[index]->divisor == 0) - { - return Optional<size_t>(index); - } - } - - return Optional<size_t>::Invalid(); -} - -void SortAttributesByLayout(const gl::Program *program, - const std::vector<TranslatedAttribute> &vertexArrayAttribs, - const std::vector<TranslatedAttribute> ¤tValueAttribs, - AttribIndexArray *sortedD3DSemanticsOut, - std::vector<const TranslatedAttribute *> *sortedAttributesOut) -{ - sortedAttributesOut->clear(); - - const auto &locationToSemantic = - GetImplAs<ProgramD3D>(program)->getAttribLocationToD3DSemantics(); - - for (auto locationIndex : program->getActiveAttribLocationsMask()) - { - int d3dSemantic = locationToSemantic[locationIndex]; - if (sortedAttributesOut->size() <= static_cast<size_t>(d3dSemantic)) - { - sortedAttributesOut->resize(d3dSemantic + 1); - } - - (*sortedD3DSemanticsOut)[d3dSemantic] = d3dSemantic; - - const auto *arrayAttrib = &vertexArrayAttribs[locationIndex]; - if (arrayAttrib->attribute && arrayAttrib->attribute->enabled) - { - (*sortedAttributesOut)[d3dSemantic] = arrayAttrib; - } - else - { - ASSERT(currentValueAttribs[locationIndex].attribute); - (*sortedAttributesOut)[d3dSemantic] = ¤tValueAttribs[locationIndex]; - } - } -} - -void UpdateUniformBuffer(ID3D11DeviceContext *deviceContext, - UniformStorage11 *storage, - const d3d11::Buffer *buffer) -{ - deviceContext->UpdateSubresource(buffer->get(), 0, nullptr, storage->getDataPointer(0, 0), 0, - 0); -} - -} // anonymous namespace - -// StateManager11::SRVCache Implementation. - -StateManager11::SRVCache::SRVCache() : mHighestUsedSRV(0) -{ -} - -StateManager11::SRVCache::~SRVCache() -{ -} - -void StateManager11::SRVCache::update(size_t resourceIndex, ID3D11ShaderResourceView *srv) -{ - ASSERT(resourceIndex < mCurrentSRVs.size()); - SRVRecord *record = &mCurrentSRVs[resourceIndex]; - - record->srv = reinterpret_cast<uintptr_t>(srv); - if (srv) - { - record->resource = reinterpret_cast<uintptr_t>(GetViewResource(srv)); - srv->GetDesc(&record->desc); - mHighestUsedSRV = std::max(resourceIndex + 1, mHighestUsedSRV); - } - else - { - record->resource = 0; - - if (resourceIndex + 1 == mHighestUsedSRV) - { - do - { - --mHighestUsedSRV; - } while (mHighestUsedSRV > 0 && mCurrentSRVs[mHighestUsedSRV].srv == 0); - } - } -} - -void StateManager11::SRVCache::clear() -{ - if (mCurrentSRVs.empty()) - { - return; - } - - memset(&mCurrentSRVs[0], 0, sizeof(SRVRecord) * mCurrentSRVs.size()); - mHighestUsedSRV = 0; -} - -// ShaderConstants11 implementation - -ShaderConstants11::ShaderConstants11() - : mVertexDirty(true), - mPixelDirty(true), - mComputeDirty(true), - mSamplerMetadataVSDirty(true), - mSamplerMetadataPSDirty(true), - mSamplerMetadataCSDirty(true) -{ -} - -ShaderConstants11::~ShaderConstants11() -{ -} - -void ShaderConstants11::init(const gl::Caps &caps) -{ - mSamplerMetadataVS.resize(caps.maxVertexTextureImageUnits); - mSamplerMetadataPS.resize(caps.maxTextureImageUnits); - mSamplerMetadataCS.resize(caps.maxComputeTextureImageUnits); -} - -size_t ShaderConstants11::getRequiredBufferSize(gl::SamplerType samplerType) const -{ - switch (samplerType) - { - case gl::SAMPLER_VERTEX: - return sizeof(Vertex) + mSamplerMetadataVS.size() * sizeof(SamplerMetadata); - case gl::SAMPLER_PIXEL: - return sizeof(Pixel) + mSamplerMetadataPS.size() * sizeof(SamplerMetadata); - case gl::SAMPLER_COMPUTE: - return sizeof(Compute) + mSamplerMetadataCS.size() * sizeof(SamplerMetadata); - default: - UNREACHABLE(); - return 0; - } -} - -void ShaderConstants11::markDirty() -{ - mVertexDirty = true; - mPixelDirty = true; - mComputeDirty = true; - mSamplerMetadataVSDirty = true; - mSamplerMetadataPSDirty = true; - mSamplerMetadataCSDirty = true; -} - -bool ShaderConstants11::updateSamplerMetadata(SamplerMetadata *data, const gl::Texture &texture) -{ - bool dirty = false; - unsigned int baseLevel = texture.getTextureState().getEffectiveBaseLevel(); - GLenum sizedFormat = - texture.getFormat(texture.getTarget(), baseLevel).info->sizedInternalFormat; - if (data->baseLevel != static_cast<int>(baseLevel)) - { - data->baseLevel = static_cast<int>(baseLevel); - dirty = true; - } - - // Some metadata is needed only for integer textures. We avoid updating the constant buffer - // unnecessarily by changing the data only in case the texture is an integer texture and - // the values have changed. - bool needIntegerTextureMetadata = false; - // internalFormatBits == 0 means a 32-bit texture in the case of integer textures. - int internalFormatBits = 0; - switch (sizedFormat) - { - case GL_RGBA32I: - case GL_RGBA32UI: - case GL_RGB32I: - case GL_RGB32UI: - case GL_RG32I: - case GL_RG32UI: - case GL_R32I: - case GL_R32UI: - needIntegerTextureMetadata = true; - break; - case GL_RGBA16I: - case GL_RGBA16UI: - case GL_RGB16I: - case GL_RGB16UI: - case GL_RG16I: - case GL_RG16UI: - case GL_R16I: - case GL_R16UI: - needIntegerTextureMetadata = true; - internalFormatBits = 16; - break; - case GL_RGBA8I: - case GL_RGBA8UI: - case GL_RGB8I: - case GL_RGB8UI: - case GL_RG8I: - case GL_RG8UI: - case GL_R8I: - case GL_R8UI: - needIntegerTextureMetadata = true; - internalFormatBits = 8; - break; - case GL_RGB10_A2UI: - needIntegerTextureMetadata = true; - internalFormatBits = 10; - break; - default: - break; - } - if (needIntegerTextureMetadata) - { - if (data->internalFormatBits != internalFormatBits) - { - data->internalFormatBits = internalFormatBits; - dirty = true; - } - // Pack the wrap values into one integer so we can fit all the metadata in one 4-integer - // vector. - GLenum wrapS = texture.getWrapS(); - GLenum wrapT = texture.getWrapT(); - GLenum wrapR = texture.getWrapR(); - int wrapModes = GetWrapBits(wrapS) | (GetWrapBits(wrapT) << 2) | (GetWrapBits(wrapR) << 4); - if (data->wrapModes != wrapModes) - { - data->wrapModes = wrapModes; - dirty = true; - } - } - - return dirty; -} - -void ShaderConstants11::setComputeWorkGroups(GLuint numGroupsX, - GLuint numGroupsY, - GLuint numGroupsZ) -{ - mCompute.numWorkGroups[0] = numGroupsX; - mCompute.numWorkGroups[1] = numGroupsY; - mCompute.numWorkGroups[2] = numGroupsZ; - mComputeDirty = true; -} - -void ShaderConstants11::setMultiviewWriteToViewportIndex(GLfloat index) -{ - mVertex.multiviewWriteToViewportIndex = index; - mVertexDirty = true; - mPixel.multiviewWriteToViewportIndex = index; - mPixelDirty = true; -} - -void ShaderConstants11::onViewportChange(const gl::Rectangle &glViewport, - const D3D11_VIEWPORT &dxViewport, - bool is9_3, - bool presentPathFast) -{ - mVertexDirty = true; - mPixelDirty = true; - - // On Feature Level 9_*, we must emulate large and/or negative viewports in the shaders - // using viewAdjust (like the D3D9 renderer). - if (is9_3) - { - mVertex.viewAdjust[0] = static_cast<float>((glViewport.width - dxViewport.Width) + - 2 * (glViewport.x - dxViewport.TopLeftX)) / - dxViewport.Width; - mVertex.viewAdjust[1] = static_cast<float>((glViewport.height - dxViewport.Height) + - 2 * (glViewport.y - dxViewport.TopLeftY)) / - dxViewport.Height; - mVertex.viewAdjust[2] = static_cast<float>(glViewport.width) / dxViewport.Width; - mVertex.viewAdjust[3] = static_cast<float>(glViewport.height) / dxViewport.Height; - } - - mPixel.viewCoords[0] = glViewport.width * 0.5f; - mPixel.viewCoords[1] = glViewport.height * 0.5f; - mPixel.viewCoords[2] = glViewport.x + (glViewport.width * 0.5f); - mPixel.viewCoords[3] = glViewport.y + (glViewport.height * 0.5f); - - // Instanced pointsprite emulation requires ViewCoords to be defined in the - // the vertex shader. - mVertex.viewCoords[0] = mPixel.viewCoords[0]; - mVertex.viewCoords[1] = mPixel.viewCoords[1]; - mVertex.viewCoords[2] = mPixel.viewCoords[2]; - mVertex.viewCoords[3] = mPixel.viewCoords[3]; - - const float zNear = dxViewport.MinDepth; - const float zFar = dxViewport.MaxDepth; - - mPixel.depthFront[0] = (zFar - zNear) * 0.5f; - mPixel.depthFront[1] = (zNear + zFar) * 0.5f; - - mVertex.depthRange[0] = zNear; - mVertex.depthRange[1] = zFar; - mVertex.depthRange[2] = zFar - zNear; - - mPixel.depthRange[0] = zNear; - mPixel.depthRange[1] = zFar; - mPixel.depthRange[2] = zFar - zNear; - - mPixel.viewScale[0] = 1.0f; - mPixel.viewScale[1] = presentPathFast ? 1.0f : -1.0f; - // Updates to the multiviewWriteToViewportIndex member are to be handled whenever the draw - // framebuffer's layout is changed. - - mVertex.viewScale[0] = mPixel.viewScale[0]; - mVertex.viewScale[1] = mPixel.viewScale[1]; -} - -void ShaderConstants11::onSamplerChange(gl::SamplerType samplerType, - unsigned int samplerIndex, - const gl::Texture &texture) -{ - switch (samplerType) - { - case gl::SAMPLER_VERTEX: - if (updateSamplerMetadata(&mSamplerMetadataVS[samplerIndex], texture)) - { - mSamplerMetadataVSDirty = true; - } - break; - case gl::SAMPLER_PIXEL: - if (updateSamplerMetadata(&mSamplerMetadataPS[samplerIndex], texture)) - { - mSamplerMetadataPSDirty = true; - } - break; - case gl::SAMPLER_COMPUTE: - if (updateSamplerMetadata(&mSamplerMetadataCS[samplerIndex], texture)) - { - mSamplerMetadataCSDirty = true; - } - break; - default: - UNREACHABLE(); - break; - } -} - -gl::Error ShaderConstants11::updateBuffer(ID3D11DeviceContext *deviceContext, - gl::SamplerType samplerType, - const ProgramD3D &programD3D, - const d3d11::Buffer &driverConstantBuffer) -{ - bool dirty = false; - size_t dataSize = 0; - const uint8_t *data = nullptr; - const uint8_t *samplerData = nullptr; - - switch (samplerType) - { - case gl::SAMPLER_VERTEX: - dirty = mVertexDirty || mSamplerMetadataVSDirty; - dataSize = sizeof(Vertex); - data = reinterpret_cast<const uint8_t *>(&mVertex); - samplerData = reinterpret_cast<const uint8_t *>(mSamplerMetadataVS.data()); - mVertexDirty = false; - mSamplerMetadataVSDirty = false; - break; - case gl::SAMPLER_PIXEL: - dirty = mPixelDirty || mSamplerMetadataPSDirty; - dataSize = sizeof(Pixel); - data = reinterpret_cast<const uint8_t *>(&mPixel); - samplerData = reinterpret_cast<const uint8_t *>(mSamplerMetadataPS.data()); - mPixelDirty = false; - mSamplerMetadataPSDirty = false; - break; - case gl::SAMPLER_COMPUTE: - dirty = mComputeDirty || mSamplerMetadataCSDirty; - dataSize = sizeof(Compute); - data = reinterpret_cast<const uint8_t *>(&mCompute); - samplerData = reinterpret_cast<const uint8_t *>(mSamplerMetadataCS.data()); - mComputeDirty = false; - mSamplerMetadataCSDirty = false; - break; - default: - UNREACHABLE(); - break; - } - - ASSERT(driverConstantBuffer.valid()); - - if (!dirty) - { - return gl::NoError(); - } - - // Previous buffer contents are discarded, so we need to refresh the whole buffer. - D3D11_MAPPED_SUBRESOURCE mapping = {0}; - HRESULT result = - deviceContext->Map(driverConstantBuffer.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mapping); - - if (FAILED(result)) - { - return gl::OutOfMemory() << "Internal error mapping constant buffer: " << gl::FmtHR(result); - } - - size_t samplerDataBytes = sizeof(SamplerMetadata) * programD3D.getUsedSamplerRange(samplerType); - - memcpy(mapping.pData, data, dataSize); - memcpy(reinterpret_cast<uint8_t *>(mapping.pData) + dataSize, samplerData, samplerDataBytes); - - deviceContext->Unmap(driverConstantBuffer.get(), 0); - - return gl::NoError(); -} - -static const GLenum QueryTypes[] = {GL_ANY_SAMPLES_PASSED, GL_ANY_SAMPLES_PASSED_CONSERVATIVE, - GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, GL_TIME_ELAPSED_EXT, - GL_COMMANDS_COMPLETED_CHROMIUM}; - -StateManager11::StateManager11(Renderer11 *renderer) - : mRenderer(renderer), - mInternalDirtyBits(), - mCurBlendColor(0, 0, 0, 0), - mCurSampleMask(0), - mCurStencilRef(0), - mCurStencilBackRef(0), - mCurStencilSize(0), - mCurScissorEnabled(false), - mCurScissorRect(), - mCurViewport(), - mCurNear(0.0f), - mCurFar(0.0f), - mViewportBounds(), - mRenderTargetIsDirty(true), - mCurPresentPathFastEnabled(false), - mCurPresentPathFastColorBufferHeight(0), - mDirtyCurrentValueAttribs(), - mCurrentValueAttribs(), - mCurrentInputLayout(), - mInputLayoutIsDirty(false), - mVertexAttribsNeedTranslation(false), - mDirtyVertexBufferRange(gl::MAX_VERTEX_ATTRIBS, 0), - mCurrentPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_UNDEFINED), - mDirtySwizzles(false), - mAppliedIB(nullptr), - mAppliedIBFormat(DXGI_FORMAT_UNKNOWN), - mAppliedIBOffset(0), - mIndexBufferIsDirty(false), - mVertexDataManager(renderer), - mIndexDataManager(renderer), - mIsMultiviewEnabled(false), - mEmptySerial(mRenderer->generateSerial()), - mIsTransformFeedbackCurrentlyActiveUnpaused(false) -{ - mCurBlendState.blend = false; - mCurBlendState.sourceBlendRGB = GL_ONE; - mCurBlendState.destBlendRGB = GL_ZERO; - mCurBlendState.sourceBlendAlpha = GL_ONE; - mCurBlendState.destBlendAlpha = GL_ZERO; - mCurBlendState.blendEquationRGB = GL_FUNC_ADD; - mCurBlendState.blendEquationAlpha = GL_FUNC_ADD; - mCurBlendState.colorMaskRed = true; - mCurBlendState.colorMaskBlue = true; - mCurBlendState.colorMaskGreen = true; - mCurBlendState.colorMaskAlpha = true; - mCurBlendState.sampleAlphaToCoverage = false; - mCurBlendState.dither = false; - - mCurDepthStencilState.depthTest = false; - mCurDepthStencilState.depthFunc = GL_LESS; - mCurDepthStencilState.depthMask = true; - mCurDepthStencilState.stencilTest = false; - mCurDepthStencilState.stencilMask = true; - mCurDepthStencilState.stencilFail = GL_KEEP; - mCurDepthStencilState.stencilPassDepthFail = GL_KEEP; - mCurDepthStencilState.stencilPassDepthPass = GL_KEEP; - mCurDepthStencilState.stencilWritemask = static_cast<GLuint>(-1); - mCurDepthStencilState.stencilBackFunc = GL_ALWAYS; - mCurDepthStencilState.stencilBackMask = static_cast<GLuint>(-1); - mCurDepthStencilState.stencilBackFail = GL_KEEP; - mCurDepthStencilState.stencilBackPassDepthFail = GL_KEEP; - mCurDepthStencilState.stencilBackPassDepthPass = GL_KEEP; - mCurDepthStencilState.stencilBackWritemask = static_cast<GLuint>(-1); - - mCurRasterState.rasterizerDiscard = false; - mCurRasterState.cullFace = false; - mCurRasterState.cullMode = gl::CullFaceMode::Back; - mCurRasterState.frontFace = GL_CCW; - mCurRasterState.polygonOffsetFill = false; - mCurRasterState.polygonOffsetFactor = 0.0f; - mCurRasterState.polygonOffsetUnits = 0.0f; - mCurRasterState.pointDrawMode = false; - mCurRasterState.multiSample = false; - - // Start with all internal dirty bits set. - mInternalDirtyBits.set(); - - // Initially all current value attributes must be updated on first use. - mDirtyCurrentValueAttribs.set(); - - mCurrentVertexBuffers.fill(nullptr); - mCurrentVertexStrides.fill(std::numeric_limits<UINT>::max()); - mCurrentVertexOffsets.fill(std::numeric_limits<UINT>::max()); -} - -StateManager11::~StateManager11() -{ -} - -template <typename SRVType> -void StateManager11::setShaderResourceInternal(gl::SamplerType shaderType, - UINT resourceSlot, - const SRVType *srv) -{ - auto ¤tSRVs = (shaderType == gl::SAMPLER_VERTEX ? mCurVertexSRVs : mCurPixelSRVs); - - ASSERT(static_cast<size_t>(resourceSlot) < currentSRVs.size()); - const SRVRecord &record = currentSRVs[resourceSlot]; - - if (record.srv != reinterpret_cast<uintptr_t>(srv)) - { - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - ID3D11ShaderResourceView *srvPtr = srv ? srv->get() : nullptr; - if (shaderType == gl::SAMPLER_VERTEX) - { - deviceContext->VSSetShaderResources(resourceSlot, 1, &srvPtr); - } - else - { - deviceContext->PSSetShaderResources(resourceSlot, 1, &srvPtr); - } - - currentSRVs.update(resourceSlot, srvPtr); - } -} - -void StateManager11::updateStencilSizeIfChanged(bool depthStencilInitialized, - unsigned int stencilSize) -{ - if (!depthStencilInitialized || stencilSize != mCurStencilSize) - { - mCurStencilSize = stencilSize; - mInternalDirtyBits.set(DIRTY_BIT_DEPTH_STENCIL_STATE); - } -} - -void StateManager11::checkPresentPath(const gl::Context *context) -{ - if (!mRenderer->presentPathFastEnabled()) - return; - - const auto *framebuffer = context->getGLState().getDrawFramebuffer(); - const auto *firstColorAttachment = framebuffer->getFirstColorbuffer(); - const bool presentPathFastActive = UsePresentPathFast(mRenderer, firstColorAttachment); - - const int colorBufferHeight = firstColorAttachment ? firstColorAttachment->getSize().height : 0; - - if ((mCurPresentPathFastEnabled != presentPathFastActive) || - (presentPathFastActive && (colorBufferHeight != mCurPresentPathFastColorBufferHeight))) - { - mCurPresentPathFastEnabled = presentPathFastActive; - mCurPresentPathFastColorBufferHeight = colorBufferHeight; - - // Scissor rect may need to be vertically inverted - mInternalDirtyBits.set(DIRTY_BIT_SCISSOR_STATE); - - // Cull Mode may need to be inverted - mInternalDirtyBits.set(DIRTY_BIT_RASTERIZER_STATE); - - // Viewport may need to be vertically inverted - invalidateViewport(context); - } -} - -gl::Error StateManager11::updateStateForCompute(const gl::Context *context, - GLuint numGroupsX, - GLuint numGroupsY, - GLuint numGroupsZ) -{ - mShaderConstants.setComputeWorkGroups(numGroupsX, numGroupsY, numGroupsZ); - - // TODO(jmadill): Use dirty bits. - const auto &glState = context->getGLState(); - auto *programD3D = GetImplAs<ProgramD3D>(glState.getProgram()); - programD3D->updateSamplerMapping(); - - // TODO(jmadill): Use dirty bits. - ANGLE_TRY(generateSwizzlesForShader(context, gl::SAMPLER_COMPUTE)); - - // TODO(jmadill): More complete implementation. - ANGLE_TRY(syncTextures(context)); - - // TODO(Xinghua): applyUniformBuffers for compute shader. - - return gl::NoError(); -} - -void StateManager11::syncState(const gl::Context *context, const gl::State::DirtyBits &dirtyBits) -{ - if (!dirtyBits.any()) - { - return; - } - - const auto &state = context->getGLState(); - - for (auto dirtyBit : dirtyBits) - { - switch (dirtyBit) - { - case gl::State::DIRTY_BIT_BLEND_EQUATIONS: - { - const gl::BlendState &blendState = state.getBlendState(); - if (blendState.blendEquationRGB != mCurBlendState.blendEquationRGB || - blendState.blendEquationAlpha != mCurBlendState.blendEquationAlpha) - { - mInternalDirtyBits.set(DIRTY_BIT_BLEND_STATE); - } - break; - } - case gl::State::DIRTY_BIT_BLEND_FUNCS: - { - const gl::BlendState &blendState = state.getBlendState(); - if (blendState.sourceBlendRGB != mCurBlendState.sourceBlendRGB || - blendState.destBlendRGB != mCurBlendState.destBlendRGB || - blendState.sourceBlendAlpha != mCurBlendState.sourceBlendAlpha || - blendState.destBlendAlpha != mCurBlendState.destBlendAlpha) - { - mInternalDirtyBits.set(DIRTY_BIT_BLEND_STATE); - } - break; - } - case gl::State::DIRTY_BIT_BLEND_ENABLED: - if (state.getBlendState().blend != mCurBlendState.blend) - { - mInternalDirtyBits.set(DIRTY_BIT_BLEND_STATE); - } - break; - case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED: - if (state.getBlendState().sampleAlphaToCoverage != - mCurBlendState.sampleAlphaToCoverage) - { - mInternalDirtyBits.set(DIRTY_BIT_BLEND_STATE); - } - break; - case gl::State::DIRTY_BIT_DITHER_ENABLED: - if (state.getBlendState().dither != mCurBlendState.dither) - { - mInternalDirtyBits.set(DIRTY_BIT_BLEND_STATE); - } - break; - case gl::State::DIRTY_BIT_COLOR_MASK: - { - const gl::BlendState &blendState = state.getBlendState(); - if (blendState.colorMaskRed != mCurBlendState.colorMaskRed || - blendState.colorMaskGreen != mCurBlendState.colorMaskGreen || - blendState.colorMaskBlue != mCurBlendState.colorMaskBlue || - blendState.colorMaskAlpha != mCurBlendState.colorMaskAlpha) - { - mInternalDirtyBits.set(DIRTY_BIT_BLEND_STATE); - } - break; - } - case gl::State::DIRTY_BIT_BLEND_COLOR: - if (state.getBlendColor() != mCurBlendColor) - { - mInternalDirtyBits.set(DIRTY_BIT_BLEND_STATE); - } - break; - case gl::State::DIRTY_BIT_DEPTH_MASK: - if (state.getDepthStencilState().depthMask != mCurDepthStencilState.depthMask) - { - mInternalDirtyBits.set(DIRTY_BIT_DEPTH_STENCIL_STATE); - } - break; - case gl::State::DIRTY_BIT_DEPTH_TEST_ENABLED: - if (state.getDepthStencilState().depthTest != mCurDepthStencilState.depthTest) - { - mInternalDirtyBits.set(DIRTY_BIT_DEPTH_STENCIL_STATE); - } - break; - case gl::State::DIRTY_BIT_DEPTH_FUNC: - if (state.getDepthStencilState().depthFunc != mCurDepthStencilState.depthFunc) - { - mInternalDirtyBits.set(DIRTY_BIT_DEPTH_STENCIL_STATE); - } - break; - case gl::State::DIRTY_BIT_STENCIL_TEST_ENABLED: - if (state.getDepthStencilState().stencilTest != mCurDepthStencilState.stencilTest) - { - mInternalDirtyBits.set(DIRTY_BIT_DEPTH_STENCIL_STATE); - } - break; - case gl::State::DIRTY_BIT_STENCIL_FUNCS_FRONT: - { - const gl::DepthStencilState &depthStencil = state.getDepthStencilState(); - if (depthStencil.stencilFunc != mCurDepthStencilState.stencilFunc || - depthStencil.stencilMask != mCurDepthStencilState.stencilMask || - state.getStencilRef() != mCurStencilRef) - { - mInternalDirtyBits.set(DIRTY_BIT_DEPTH_STENCIL_STATE); - } - break; - } - case gl::State::DIRTY_BIT_STENCIL_FUNCS_BACK: - { - const gl::DepthStencilState &depthStencil = state.getDepthStencilState(); - if (depthStencil.stencilBackFunc != mCurDepthStencilState.stencilBackFunc || - depthStencil.stencilBackMask != mCurDepthStencilState.stencilBackMask || - state.getStencilBackRef() != mCurStencilBackRef) - { - mInternalDirtyBits.set(DIRTY_BIT_DEPTH_STENCIL_STATE); - } - break; - } - case gl::State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT: - if (state.getDepthStencilState().stencilWritemask != - mCurDepthStencilState.stencilWritemask) - { - mInternalDirtyBits.set(DIRTY_BIT_DEPTH_STENCIL_STATE); - } - break; - case gl::State::DIRTY_BIT_STENCIL_WRITEMASK_BACK: - if (state.getDepthStencilState().stencilBackWritemask != - mCurDepthStencilState.stencilBackWritemask) - { - mInternalDirtyBits.set(DIRTY_BIT_DEPTH_STENCIL_STATE); - } - break; - case gl::State::DIRTY_BIT_STENCIL_OPS_FRONT: - { - const gl::DepthStencilState &depthStencil = state.getDepthStencilState(); - if (depthStencil.stencilFail != mCurDepthStencilState.stencilFail || - depthStencil.stencilPassDepthFail != - mCurDepthStencilState.stencilPassDepthFail || - depthStencil.stencilPassDepthPass != mCurDepthStencilState.stencilPassDepthPass) - { - mInternalDirtyBits.set(DIRTY_BIT_DEPTH_STENCIL_STATE); - } - break; - } - case gl::State::DIRTY_BIT_STENCIL_OPS_BACK: - { - const gl::DepthStencilState &depthStencil = state.getDepthStencilState(); - if (depthStencil.stencilBackFail != mCurDepthStencilState.stencilBackFail || - depthStencil.stencilBackPassDepthFail != - mCurDepthStencilState.stencilBackPassDepthFail || - depthStencil.stencilBackPassDepthPass != - mCurDepthStencilState.stencilBackPassDepthPass) - { - mInternalDirtyBits.set(DIRTY_BIT_DEPTH_STENCIL_STATE); - } - break; - } - case gl::State::DIRTY_BIT_CULL_FACE_ENABLED: - if (state.getRasterizerState().cullFace != mCurRasterState.cullFace) - { - mInternalDirtyBits.set(DIRTY_BIT_RASTERIZER_STATE); - } - break; - case gl::State::DIRTY_BIT_CULL_FACE: - if (state.getRasterizerState().cullMode != mCurRasterState.cullMode) - { - mInternalDirtyBits.set(DIRTY_BIT_RASTERIZER_STATE); - } - break; - case gl::State::DIRTY_BIT_FRONT_FACE: - if (state.getRasterizerState().frontFace != mCurRasterState.frontFace) - { - mInternalDirtyBits.set(DIRTY_BIT_RASTERIZER_STATE); - } - break; - case gl::State::DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED: - if (state.getRasterizerState().polygonOffsetFill != - mCurRasterState.polygonOffsetFill) - { - mInternalDirtyBits.set(DIRTY_BIT_RASTERIZER_STATE); - } - break; - case gl::State::DIRTY_BIT_POLYGON_OFFSET: - { - const gl::RasterizerState &rasterState = state.getRasterizerState(); - if (rasterState.polygonOffsetFactor != mCurRasterState.polygonOffsetFactor || - rasterState.polygonOffsetUnits != mCurRasterState.polygonOffsetUnits) - { - mInternalDirtyBits.set(DIRTY_BIT_RASTERIZER_STATE); - } - break; - } - case gl::State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED: - if (state.getRasterizerState().rasterizerDiscard != - mCurRasterState.rasterizerDiscard) - { - mInternalDirtyBits.set(DIRTY_BIT_RASTERIZER_STATE); - - // Enabling/disabling rasterizer discard affects the pixel shader. - invalidateShaders(); - } - break; - case gl::State::DIRTY_BIT_SCISSOR: - if (state.getScissor() != mCurScissorRect) - { - mInternalDirtyBits.set(DIRTY_BIT_SCISSOR_STATE); - } - break; - case gl::State::DIRTY_BIT_SCISSOR_TEST_ENABLED: - if (state.isScissorTestEnabled() != mCurScissorEnabled) - { - mInternalDirtyBits.set(DIRTY_BIT_SCISSOR_STATE); - // Rasterizer state update needs mCurScissorsEnabled and updates when it changes - mInternalDirtyBits.set(DIRTY_BIT_RASTERIZER_STATE); - } - break; - case gl::State::DIRTY_BIT_DEPTH_RANGE: - if (state.getNearPlane() != mCurNear || state.getFarPlane() != mCurFar) - { - invalidateViewport(context); - } - break; - case gl::State::DIRTY_BIT_VIEWPORT: - if (state.getViewport() != mCurViewport) - { - invalidateViewport(context); - } - break; - case gl::State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING: - invalidateRenderTarget(); - if (mIsMultiviewEnabled) - { - handleMultiviewDrawFramebufferChange(context); - } - break; - case gl::State::DIRTY_BIT_VERTEX_ARRAY_BINDING: - invalidateVertexBuffer(); - // Force invalidate the current value attributes, since the VertexArray11 keeps an - // internal cache of TranslatedAttributes, and they CurrentValue attributes are - // owned by the StateManager11/Context. - mDirtyCurrentValueAttribs.set(); - // Invalidate the cached index buffer. - mIndexBufferIsDirty = true; - break; - case gl::State::DIRTY_BIT_TEXTURE_BINDINGS: - invalidateTexturesAndSamplers(); - break; - case gl::State::DIRTY_BIT_SAMPLER_BINDINGS: - invalidateTexturesAndSamplers(); - break; - case gl::State::DIRTY_BIT_PROGRAM_EXECUTABLE: - { - mInternalDirtyBits.set(DIRTY_BIT_SHADERS); - invalidateVertexBuffer(); - invalidateRenderTarget(); - invalidateTexturesAndSamplers(); - invalidateProgramUniforms(); - invalidateProgramUniformBuffers(); - gl::VertexArray *vao = state.getVertexArray(); - if (mIsMultiviewEnabled && vao != nullptr) - { - // If ANGLE_multiview is enabled, the attribute divisor has to be updated for - // each binding. - VertexArray11 *vao11 = GetImplAs<VertexArray11>(vao); - const gl::Program *program = state.getProgram(); - int numViews = 1; - if (program != nullptr && program->usesMultiview()) - { - numViews = program->getNumViews(); - } - vao11->markAllAttributeDivisorsForAdjustment(numViews); - } - break; - } - case gl::State::DIRTY_BIT_CURRENT_VALUES: - { - for (auto attribIndex : state.getAndResetDirtyCurrentValues()) - { - invalidateCurrentValueAttrib(attribIndex); - } - } - default: - break; - } - } - - // TODO(jmadill): Input layout and vertex buffer state. -} - -void StateManager11::handleMultiviewDrawFramebufferChange(const gl::Context *context) -{ - const auto &glState = context->getGLState(); - const gl::Framebuffer *drawFramebuffer = glState.getDrawFramebuffer(); - ASSERT(drawFramebuffer != nullptr); - - // Update viewport offsets. - const std::vector<gl::Offset> *attachmentViewportOffsets = - drawFramebuffer->getViewportOffsets(); - const std::vector<gl::Offset> &viewportOffsets = - attachmentViewportOffsets != nullptr - ? *attachmentViewportOffsets - : gl::FramebufferAttachment::GetDefaultViewportOffsetVector(); - if (mViewportOffsets != viewportOffsets) - { - mViewportOffsets = viewportOffsets; - - // Because new viewport offsets are to be applied, we have to mark the internal viewport and - // scissor state as dirty. - invalidateViewport(context); - mInternalDirtyBits.set(DIRTY_BIT_SCISSOR_STATE); - } - switch (drawFramebuffer->getMultiviewLayout()) - { - case GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE: - mShaderConstants.setMultiviewWriteToViewportIndex(1.0f); - break; - case GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE: - // Because the base view index is applied as an offset to the 2D texture array when the - // RTV is created, we just have to pass a boolean to select which code path is to be - // used. - mShaderConstants.setMultiviewWriteToViewportIndex(0.0f); - break; - default: - // There is no need to update the value in the constant buffer if the active framebuffer - // object does not have a multiview layout. - break; - } -} - -gl::Error StateManager11::syncBlendState(const gl::Context *context, - const gl::Framebuffer *framebuffer, - const gl::BlendState &blendState, - const gl::ColorF &blendColor, - unsigned int sampleMask) -{ - const d3d11::BlendState *dxBlendState = nullptr; - const d3d11::BlendStateKey &key = - RenderStateCache::GetBlendStateKey(context, framebuffer, blendState); - - ANGLE_TRY(mRenderer->getBlendState(key, &dxBlendState)); - - ASSERT(dxBlendState != nullptr); - - float blendColors[4] = {0.0f}; - if (blendState.sourceBlendRGB != GL_CONSTANT_ALPHA && - blendState.sourceBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA && - blendState.destBlendRGB != GL_CONSTANT_ALPHA && - blendState.destBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA) - { - blendColors[0] = blendColor.red; - blendColors[1] = blendColor.green; - blendColors[2] = blendColor.blue; - blendColors[3] = blendColor.alpha; - } - else - { - blendColors[0] = blendColor.alpha; - blendColors[1] = blendColor.alpha; - blendColors[2] = blendColor.alpha; - blendColors[3] = blendColor.alpha; - } - - mRenderer->getDeviceContext()->OMSetBlendState(dxBlendState->get(), blendColors, sampleMask); - - mCurBlendState = blendState; - mCurBlendColor = blendColor; - mCurSampleMask = sampleMask; - - return gl::NoError(); -} - -gl::Error StateManager11::syncDepthStencilState(const gl::State &glState) -{ - mCurDepthStencilState = glState.getDepthStencilState(); - mCurStencilRef = glState.getStencilRef(); - mCurStencilBackRef = glState.getStencilBackRef(); - - // get the maximum size of the stencil ref - unsigned int maxStencil = 0; - if (mCurDepthStencilState.stencilTest && mCurStencilSize > 0) - { - maxStencil = (1 << mCurStencilSize) - 1; - } - ASSERT((mCurDepthStencilState.stencilWritemask & maxStencil) == - (mCurDepthStencilState.stencilBackWritemask & maxStencil)); - ASSERT(mCurStencilRef == mCurStencilBackRef); - ASSERT((mCurDepthStencilState.stencilMask & maxStencil) == - (mCurDepthStencilState.stencilBackMask & maxStencil)); - - gl::DepthStencilState modifiedGLState = glState.getDepthStencilState(); - - ASSERT(mCurDisableDepth.valid() && mCurDisableStencil.valid()); - - if (mCurDisableDepth.value()) - { - modifiedGLState.depthTest = false; - modifiedGLState.depthMask = false; - } - - if (mCurDisableStencil.value()) - { - modifiedGLState.stencilWritemask = 0; - modifiedGLState.stencilBackWritemask = 0; - modifiedGLState.stencilTest = false; - } - - const d3d11::DepthStencilState *d3dState = nullptr; - ANGLE_TRY(mRenderer->getDepthStencilState(modifiedGLState, &d3dState)); - ASSERT(d3dState); - - // Max D3D11 stencil reference value is 0xFF, - // corresponding to the max 8 bits in a stencil buffer - // GL specifies we should clamp the ref value to the - // nearest bit depth when doing stencil ops - static_assert(D3D11_DEFAULT_STENCIL_READ_MASK == 0xFF, - "Unexpected value of D3D11_DEFAULT_STENCIL_READ_MASK"); - static_assert(D3D11_DEFAULT_STENCIL_WRITE_MASK == 0xFF, - "Unexpected value of D3D11_DEFAULT_STENCIL_WRITE_MASK"); - UINT dxStencilRef = std::min<UINT>(mCurStencilRef, 0xFFu); - - mRenderer->getDeviceContext()->OMSetDepthStencilState(d3dState->get(), dxStencilRef); - - return gl::NoError(); -} - -gl::Error StateManager11::syncRasterizerState(const gl::Context *context, bool pointDrawMode) -{ - // TODO: Remove pointDrawMode and multiSample from gl::RasterizerState. - gl::RasterizerState rasterState = context->getGLState().getRasterizerState(); - rasterState.pointDrawMode = pointDrawMode; - rasterState.multiSample = mCurRasterState.multiSample; - - ID3D11RasterizerState *dxRasterState = nullptr; - - if (mCurPresentPathFastEnabled) - { - gl::RasterizerState modifiedRasterState = rasterState; - - // If prseent path fast is active then we need invert the front face state. - // This ensures that both gl_FrontFacing is correct, and front/back culling - // is performed correctly. - if (modifiedRasterState.frontFace == GL_CCW) - { - modifiedRasterState.frontFace = GL_CW; - } - else - { - ASSERT(modifiedRasterState.frontFace == GL_CW); - modifiedRasterState.frontFace = GL_CCW; - } - - ANGLE_TRY( - mRenderer->getRasterizerState(modifiedRasterState, mCurScissorEnabled, &dxRasterState)); - } - else - { - ANGLE_TRY(mRenderer->getRasterizerState(rasterState, mCurScissorEnabled, &dxRasterState)); - } - - mRenderer->getDeviceContext()->RSSetState(dxRasterState); - - mCurRasterState = rasterState; - - return gl::NoError(); -} - -void StateManager11::syncScissorRectangle(const gl::Rectangle &scissor, bool enabled) -{ - int modifiedScissorY = scissor.y; - if (mCurPresentPathFastEnabled) - { - modifiedScissorY = mCurPresentPathFastColorBufferHeight - scissor.height - scissor.y; - } - - if (enabled) - { - std::array<D3D11_RECT, gl::IMPLEMENTATION_ANGLE_MULTIVIEW_MAX_VIEWS> rectangles; - const UINT numRectangles = static_cast<UINT>(mViewportOffsets.size()); - for (UINT i = 0u; i < numRectangles; ++i) - { - D3D11_RECT &rect = rectangles[i]; - int x = scissor.x + mViewportOffsets[i].x; - int y = modifiedScissorY + mViewportOffsets[i].y; - rect.left = std::max(0, x); - rect.top = std::max(0, y); - rect.right = x + std::max(0, scissor.width); - rect.bottom = y + std::max(0, scissor.height); - } - mRenderer->getDeviceContext()->RSSetScissorRects(numRectangles, rectangles.data()); - } - - mCurScissorRect = scissor; - mCurScissorEnabled = enabled; -} - -void StateManager11::syncViewport(const gl::Context *context) -{ - const auto &glState = context->getGLState(); - gl::Framebuffer *framebuffer = glState.getDrawFramebuffer(); - float actualZNear = gl::clamp01(glState.getNearPlane()); - float actualZFar = gl::clamp01(glState.getFarPlane()); - - const auto &caps = context->getCaps(); - int dxMaxViewportBoundsX = static_cast<int>(caps.maxViewportWidth); - int dxMaxViewportBoundsY = static_cast<int>(caps.maxViewportHeight); - int dxMinViewportBoundsX = -dxMaxViewportBoundsX; - int dxMinViewportBoundsY = -dxMaxViewportBoundsY; - - bool is9_3 = mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_9_3; - - if (is9_3) - { - // Feature Level 9 viewports shouldn't exceed the dimensions of the rendertarget. - dxMaxViewportBoundsX = static_cast<int>(mViewportBounds.width); - dxMaxViewportBoundsY = static_cast<int>(mViewportBounds.height); - dxMinViewportBoundsX = 0; - dxMinViewportBoundsY = 0; - } - - const auto &viewport = glState.getViewport(); - std::array<D3D11_VIEWPORT, gl::IMPLEMENTATION_ANGLE_MULTIVIEW_MAX_VIEWS> dxViewports; - const UINT numRectangles = static_cast<UINT>(mViewportOffsets.size()); - - int dxViewportTopLeftX = 0; - int dxViewportTopLeftY = 0; - int dxViewportWidth = 0; - int dxViewportHeight = 0; - - for (UINT i = 0u; i < numRectangles; ++i) - { - dxViewportTopLeftX = gl::clamp(viewport.x + mViewportOffsets[i].x, dxMinViewportBoundsX, - dxMaxViewportBoundsX); - dxViewportTopLeftY = gl::clamp(viewport.y + mViewportOffsets[i].y, dxMinViewportBoundsY, - dxMaxViewportBoundsY); - dxViewportWidth = gl::clamp(viewport.width, 0, dxMaxViewportBoundsX - dxViewportTopLeftX); - dxViewportHeight = gl::clamp(viewport.height, 0, dxMaxViewportBoundsY - dxViewportTopLeftY); - - D3D11_VIEWPORT &dxViewport = dxViewports[i]; - dxViewport.TopLeftX = static_cast<float>(dxViewportTopLeftX); - if (mCurPresentPathFastEnabled) - { - // When present path fast is active and we're rendering to framebuffer 0, we must invert - // the viewport in Y-axis. - // NOTE: We delay the inversion until right before the call to RSSetViewports, and leave - // dxViewportTopLeftY unchanged. This allows us to calculate viewAdjust below using the - // unaltered dxViewportTopLeftY value. - dxViewport.TopLeftY = static_cast<float>(mCurPresentPathFastColorBufferHeight - - dxViewportTopLeftY - dxViewportHeight); - } - else - { - dxViewport.TopLeftY = static_cast<float>(dxViewportTopLeftY); - } - - // The es 3.1 spec section 9.2 states that, "If there are no attachments, rendering - // will be limited to a rectangle having a lower left of (0, 0) and an upper right of - // (width, height), where width and height are the framebuffer object's default width - // and height." See http://anglebug.com/1594 - // If the Framebuffer has no color attachment and the default width or height is smaller - // than the current viewport, use the smaller of the two sizes. - // If framebuffer default width or height is 0, the params should not set. - if (!framebuffer->getFirstNonNullAttachment() && - (framebuffer->getDefaultWidth() || framebuffer->getDefaultHeight())) - { - dxViewport.Width = - static_cast<GLfloat>(std::min(viewport.width, framebuffer->getDefaultWidth())); - dxViewport.Height = - static_cast<GLfloat>(std::min(viewport.height, framebuffer->getDefaultHeight())); - } - else - { - dxViewport.Width = static_cast<float>(dxViewportWidth); - dxViewport.Height = static_cast<float>(dxViewportHeight); - } - dxViewport.MinDepth = actualZNear; - dxViewport.MaxDepth = actualZFar; - } - - mRenderer->getDeviceContext()->RSSetViewports(numRectangles, dxViewports.data()); - - mCurViewport = viewport; - mCurNear = actualZNear; - mCurFar = actualZFar; - - const D3D11_VIEWPORT adjustViewport = {static_cast<FLOAT>(dxViewportTopLeftX), - static_cast<FLOAT>(dxViewportTopLeftY), - static_cast<FLOAT>(dxViewportWidth), - static_cast<FLOAT>(dxViewportHeight), - actualZNear, - actualZFar}; - mShaderConstants.onViewportChange(viewport, adjustViewport, is9_3, mCurPresentPathFastEnabled); -} - -void StateManager11::invalidateRenderTarget() -{ - mRenderTargetIsDirty = true; -} - -void StateManager11::processFramebufferInvalidation(const gl::Context *context) -{ - if (!mRenderTargetIsDirty) - { - return; - } - - ASSERT(context); - - mRenderTargetIsDirty = false; - mInternalDirtyBits.set(DIRTY_BIT_RENDER_TARGET); - - // The pixel shader is dependent on the output layout. - invalidateShaders(); - - // The D3D11 blend state is heavily dependent on the current render target. - mInternalDirtyBits.set(DIRTY_BIT_BLEND_STATE); - - gl::Framebuffer *fbo = context->getGLState().getDrawFramebuffer(); - ASSERT(fbo); - - // Disable the depth test/depth write if we are using a stencil-only attachment. - // This is because ANGLE emulates stencil-only with D24S8 on D3D11 - we should neither read - // nor write to the unused depth part of this emulated texture. - bool disableDepth = (!fbo->hasDepth() && fbo->hasStencil()); - - // Similarly we disable the stencil portion of the DS attachment if the app only binds depth. - bool disableStencil = (fbo->hasDepth() && !fbo->hasStencil()); - - if (!mCurDisableDepth.valid() || disableDepth != mCurDisableDepth.value() || - !mCurDisableStencil.valid() || disableStencil != mCurDisableStencil.value()) - { - mInternalDirtyBits.set(DIRTY_BIT_DEPTH_STENCIL_STATE); - mCurDisableDepth = disableDepth; - mCurDisableStencil = disableStencil; - } - - bool multiSample = (fbo->getCachedSamples(context) != 0); - if (multiSample != mCurRasterState.multiSample) - { - mInternalDirtyBits.set(DIRTY_BIT_RASTERIZER_STATE); - mCurRasterState.multiSample = multiSample; - } - - checkPresentPath(context); - - if (mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_9_3) - { - const auto *firstAttachment = fbo->getFirstNonNullAttachment(); - if (firstAttachment) - { - const auto &size = firstAttachment->getSize(); - if (mViewportBounds.width != size.width || mViewportBounds.height != size.height) - { - mViewportBounds = gl::Extents(size.width, size.height, 1); - invalidateViewport(context); - } - } - } -} - -void StateManager11::invalidateBoundViews() -{ - mCurVertexSRVs.clear(); - mCurPixelSRVs.clear(); - - invalidateRenderTarget(); -} - -void StateManager11::invalidateVertexBuffer() -{ - unsigned int limit = std::min<unsigned int>(mRenderer->getNativeCaps().maxVertexAttributes, - gl::MAX_VERTEX_ATTRIBS); - mDirtyVertexBufferRange = gl::RangeUI(0, limit); - mInputLayoutIsDirty = true; - mInternalDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_ATTRIBS); - invalidateVertexAttributeTranslation(); -} - -void StateManager11::invalidateViewport(const gl::Context *context) -{ - mInternalDirtyBits.set(DIRTY_BIT_VIEWPORT_STATE); - - // Viewport affects the driver constants. - invalidateDriverUniforms(); -} - -void StateManager11::invalidateTexturesAndSamplers() -{ - mInternalDirtyBits.set(DIRTY_BIT_TEXTURE_AND_SAMPLER_STATE); - invalidateSwizzles(); - - // Texture state affects the driver uniforms (base level, etc). - invalidateDriverUniforms(); -} - -void StateManager11::invalidateSwizzles() -{ - mDirtySwizzles = true; -} - -void StateManager11::invalidateProgramUniforms() -{ - mInternalDirtyBits.set(DIRTY_BIT_PROGRAM_UNIFORMS); -} - -void StateManager11::invalidateDriverUniforms() -{ - mInternalDirtyBits.set(DIRTY_BIT_DRIVER_UNIFORMS); -} - -void StateManager11::invalidateProgramUniformBuffers() -{ - mInternalDirtyBits.set(DIRTY_BIT_PROGRAM_UNIFORM_BUFFERS); -} - -void StateManager11::invalidateConstantBuffer(unsigned int slot) -{ - if (slot == d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DRIVER) - { - invalidateDriverUniforms(); - } - else if (slot == d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DEFAULT_UNIFORM_BLOCK) - { - invalidateProgramUniforms(); - } - else - { - invalidateProgramUniformBuffers(); - } -} - -void StateManager11::invalidateShaders() -{ - mInternalDirtyBits.set(DIRTY_BIT_SHADERS); -} - -void StateManager11::setRenderTarget(ID3D11RenderTargetView *rtv, ID3D11DepthStencilView *dsv) -{ - if ((rtv && unsetConflictingView(rtv)) || (dsv && unsetConflictingView(dsv))) - { - mInternalDirtyBits.set(DIRTY_BIT_TEXTURE_AND_SAMPLER_STATE); - } - - mRenderer->getDeviceContext()->OMSetRenderTargets(1, &rtv, dsv); - mInternalDirtyBits.set(DIRTY_BIT_RENDER_TARGET); -} - -void StateManager11::setRenderTargets(ID3D11RenderTargetView **rtvs, - UINT numRTVs, - ID3D11DepthStencilView *dsv) -{ - bool anyDirty = false; - - for (UINT rtvIndex = 0; rtvIndex < numRTVs; ++rtvIndex) - { - anyDirty = anyDirty || unsetConflictingView(rtvs[rtvIndex]); - } - - if (dsv) - { - anyDirty = anyDirty || unsetConflictingView(dsv); - } - - if (anyDirty) - { - mInternalDirtyBits.set(DIRTY_BIT_TEXTURE_AND_SAMPLER_STATE); - } - - mRenderer->getDeviceContext()->OMSetRenderTargets(numRTVs, (numRTVs > 0) ? rtvs : nullptr, dsv); - mInternalDirtyBits.set(DIRTY_BIT_RENDER_TARGET); -} - -void StateManager11::invalidateVertexAttributeTranslation() -{ - mVertexAttribsNeedTranslation = true; -} - -void StateManager11::onBeginQuery(Query11 *query) -{ - mCurrentQueries.insert(query); -} - -void StateManager11::onDeleteQueryObject(Query11 *query) -{ - mCurrentQueries.erase(query); -} - -gl::Error StateManager11::onMakeCurrent(const gl::Context *context) -{ - const gl::State &state = context->getGLState(); - - for (Query11 *query : mCurrentQueries) - { - ANGLE_TRY(query->pause()); - } - mCurrentQueries.clear(); - - for (GLenum queryType : QueryTypes) - { - gl::Query *query = state.getActiveQuery(queryType); - if (query != nullptr) - { - Query11 *query11 = GetImplAs<Query11>(query); - ANGLE_TRY(query11->resume()); - mCurrentQueries.insert(query11); - } - } - - return gl::NoError(); -} - -gl::Error StateManager11::clearTextures(gl::SamplerType samplerType, - size_t rangeStart, - size_t rangeEnd) -{ - if (rangeStart == rangeEnd) - { - return gl::NoError(); - } - - auto ¤tSRVs = (samplerType == gl::SAMPLER_VERTEX ? mCurVertexSRVs : mCurPixelSRVs); - - gl::Range<size_t> clearRange(rangeStart, std::min(rangeEnd, currentSRVs.highestUsed())); - if (clearRange.empty()) - { - return gl::NoError(); - } - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - if (samplerType == gl::SAMPLER_VERTEX) - { - deviceContext->VSSetShaderResources(static_cast<unsigned int>(clearRange.low()), - static_cast<unsigned int>(clearRange.length()), - &mNullSRVs[0]); - } - else - { - deviceContext->PSSetShaderResources(static_cast<unsigned int>(clearRange.low()), - static_cast<unsigned int>(clearRange.length()), - &mNullSRVs[0]); - } - - for (size_t samplerIndex : clearRange) - { - currentSRVs.update(samplerIndex, nullptr); - } - - return gl::NoError(); -} - -bool StateManager11::unsetConflictingView(ID3D11View *view) -{ - uintptr_t resource = reinterpret_cast<uintptr_t>(GetViewResource(view)); - return unsetConflictingSRVs(gl::SAMPLER_VERTEX, resource, nullptr) || - unsetConflictingSRVs(gl::SAMPLER_PIXEL, resource, nullptr); -} - -bool StateManager11::unsetConflictingSRVs(gl::SamplerType samplerType, - uintptr_t resource, - const gl::ImageIndex *index) -{ - auto ¤tSRVs = (samplerType == gl::SAMPLER_VERTEX ? mCurVertexSRVs : mCurPixelSRVs); - - bool foundOne = false; - - for (size_t resourceIndex = 0; resourceIndex < currentSRVs.size(); ++resourceIndex) - { - auto &record = currentSRVs[resourceIndex]; - - if (record.srv && record.resource == resource && - (!index || ImageIndexConflictsWithSRV(*index, record.desc))) - { - setShaderResourceInternal<d3d11::ShaderResourceView>( - samplerType, static_cast<UINT>(resourceIndex), nullptr); - foundOne = true; - } - } - - return foundOne; -} - -void StateManager11::unsetConflictingAttachmentResources( - const gl::FramebufferAttachment *attachment, - ID3D11Resource *resource) -{ - // Unbind render target SRVs from the shader here to prevent D3D11 warnings. - if (attachment->type() == GL_TEXTURE) - { - uintptr_t resourcePtr = reinterpret_cast<uintptr_t>(resource); - const gl::ImageIndex &index = attachment->getTextureImageIndex(); - // The index doesn't need to be corrected for the small compressed texture workaround - // because a rendertarget is never compressed. - unsetConflictingSRVs(gl::SAMPLER_VERTEX, resourcePtr, &index); - unsetConflictingSRVs(gl::SAMPLER_PIXEL, resourcePtr, &index); - } - else if (attachment->type() == GL_FRAMEBUFFER_DEFAULT) - { - uintptr_t resourcePtr = reinterpret_cast<uintptr_t>(resource); - unsetConflictingSRVs(gl::SAMPLER_VERTEX, resourcePtr, nullptr); - unsetConflictingSRVs(gl::SAMPLER_PIXEL, resourcePtr, nullptr); - } -} - -gl::Error StateManager11::initialize(const gl::Caps &caps, const gl::Extensions &extensions) -{ - mCurVertexSRVs.initialize(caps.maxVertexTextureImageUnits); - mCurPixelSRVs.initialize(caps.maxTextureImageUnits); - - // Initialize cached NULL SRV block - mNullSRVs.resize(caps.maxTextureImageUnits, nullptr); - - mCurrentValueAttribs.resize(caps.maxVertexAttributes); - - mForceSetVertexSamplerStates.resize(caps.maxVertexTextureImageUnits, true); - mForceSetPixelSamplerStates.resize(caps.maxTextureImageUnits, true); - mForceSetComputeSamplerStates.resize(caps.maxComputeTextureImageUnits, true); - - mCurVertexSamplerStates.resize(caps.maxVertexTextureImageUnits); - mCurPixelSamplerStates.resize(caps.maxTextureImageUnits); - mCurComputeSamplerStates.resize(caps.maxComputeTextureImageUnits); - - mShaderConstants.init(caps); - - mIsMultiviewEnabled = extensions.multiview; - mViewportOffsets.resize(1u); - - ANGLE_TRY(mVertexDataManager.initialize()); - - mCurrentAttributes.reserve(gl::MAX_VERTEX_ATTRIBS); - - return gl::NoError(); -} - -void StateManager11::deinitialize() -{ - mCurrentValueAttribs.clear(); - mInputLayoutCache.clear(); - mVertexDataManager.deinitialize(); - mIndexDataManager.deinitialize(); - - mDriverConstantBufferVS.reset(); - mDriverConstantBufferPS.reset(); - mDriverConstantBufferCS.reset(); -} - -gl::Error StateManager11::syncFramebuffer(const gl::Context *context, gl::Framebuffer *framebuffer) -{ - Framebuffer11 *framebuffer11 = GetImplAs<Framebuffer11>(framebuffer); - - // Applies the render target surface, depth stencil surface, viewport rectangle and - // scissor rectangle to the renderer - ASSERT(framebuffer && !framebuffer->hasAnyDirtyBit() && framebuffer->cachedComplete()); - - // Check for zero-sized default framebuffer, which is a special case. - // in this case we do not wish to modify any state and just silently return false. - // this will not report any gl error but will cause the calling method to return. - if (framebuffer->id() == 0) - { - ASSERT(!framebuffer11->hasAnyInternalDirtyBit()); - const gl::Extents &size = framebuffer->getFirstColorbuffer()->getSize(); - if (size.width == 0 || size.height == 0) - { - return gl::NoError(); - } - } - - RTVArray framebufferRTVs = {{}}; - - const auto &colorRTs = framebuffer11->getCachedColorRenderTargets(); - - size_t appliedRTIndex = 0; - bool skipInactiveRTs = mRenderer->getWorkarounds().mrtPerfWorkaround; - const auto &drawStates = framebuffer->getDrawBufferStates(); - gl::DrawBufferMask activeProgramOutputs = - context->getContextState().getState().getProgram()->getActiveOutputVariables(); - UINT maxExistingRT = 0; - - for (size_t rtIndex = 0; rtIndex < colorRTs.size(); ++rtIndex) - { - const RenderTarget11 *renderTarget = colorRTs[rtIndex]; - - // Skip inactive rendertargets if the workaround is enabled. - if (skipInactiveRTs && - (!renderTarget || drawStates[rtIndex] == GL_NONE || !activeProgramOutputs[rtIndex])) - { - continue; - } - - if (renderTarget) - { - framebufferRTVs[appliedRTIndex] = renderTarget->getRenderTargetView().get(); - ASSERT(framebufferRTVs[appliedRTIndex]); - maxExistingRT = static_cast<UINT>(appliedRTIndex) + 1; - - // Unset conflicting texture SRVs - const auto *attachment = framebuffer->getColorbuffer(rtIndex); - ASSERT(attachment); - unsetConflictingAttachmentResources(attachment, renderTarget->getTexture().get()); - } - - appliedRTIndex++; - } - - // Get the depth stencil buffers - ID3D11DepthStencilView *framebufferDSV = nullptr; - const auto *depthStencilRenderTarget = framebuffer11->getCachedDepthStencilRenderTarget(); - if (depthStencilRenderTarget) - { - framebufferDSV = depthStencilRenderTarget->getDepthStencilView().get(); - ASSERT(framebufferDSV); - - // Unset conflicting texture SRVs - const auto *attachment = framebuffer->getDepthOrStencilbuffer(); - ASSERT(attachment); - unsetConflictingAttachmentResources(attachment, - depthStencilRenderTarget->getTexture().get()); - } - - // TODO(jmadill): Use context caps? - ASSERT(maxExistingRT <= static_cast<UINT>(mRenderer->getNativeCaps().maxDrawBuffers)); - - // Apply the render target and depth stencil - mRenderer->getDeviceContext()->OMSetRenderTargets(maxExistingRT, framebufferRTVs.data(), - framebufferDSV); - - return gl::NoError(); -} - -void StateManager11::invalidateCurrentValueAttrib(size_t attribIndex) -{ - mDirtyCurrentValueAttribs.set(attribIndex); - mInternalDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_ATTRIBS); -} - -gl::Error StateManager11::syncCurrentValueAttribs(const gl::State &glState) -{ - const auto &activeAttribsMask = glState.getProgram()->getActiveAttribLocationsMask(); - const auto &dirtyActiveAttribs = (activeAttribsMask & mDirtyCurrentValueAttribs); - - if (!dirtyActiveAttribs.any()) - { - return gl::NoError(); - } - - const auto &vertexAttributes = glState.getVertexArray()->getVertexAttributes(); - const auto &vertexBindings = glState.getVertexArray()->getVertexBindings(); - mDirtyCurrentValueAttribs = (mDirtyCurrentValueAttribs & ~dirtyActiveAttribs); - - for (auto attribIndex : dirtyActiveAttribs) - { - if (vertexAttributes[attribIndex].enabled) - continue; - - const auto *attrib = &vertexAttributes[attribIndex]; - const auto ¤tValue = glState.getVertexAttribCurrentValue(attribIndex); - TranslatedAttribute *currentValueAttrib = &mCurrentValueAttribs[attribIndex]; - currentValueAttrib->currentValueType = currentValue.Type; - currentValueAttrib->attribute = attrib; - currentValueAttrib->binding = &vertexBindings[attrib->bindingIndex]; - - mDirtyVertexBufferRange.extend(static_cast<unsigned int>(attribIndex)); - mInputLayoutIsDirty = true; - - ANGLE_TRY(mVertexDataManager.storeCurrentValue(currentValue, currentValueAttrib, - static_cast<size_t>(attribIndex))); - } - - return gl::NoError(); -} - -void StateManager11::setInputLayout(const d3d11::InputLayout *inputLayout) -{ - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - if (inputLayout == nullptr) - { - if (!mCurrentInputLayout.empty()) - { - deviceContext->IASetInputLayout(nullptr); - mCurrentInputLayout.clear(); - mInputLayoutIsDirty = true; - } - } - else if (inputLayout->getSerial() != mCurrentInputLayout) - { - deviceContext->IASetInputLayout(inputLayout->get()); - mCurrentInputLayout = inputLayout->getSerial(); - mInputLayoutIsDirty = true; - } -} - -bool StateManager11::queueVertexBufferChange(size_t bufferIndex, - ID3D11Buffer *buffer, - UINT stride, - UINT offset) -{ - if (buffer != mCurrentVertexBuffers[bufferIndex] || - stride != mCurrentVertexStrides[bufferIndex] || - offset != mCurrentVertexOffsets[bufferIndex]) - { - mInputLayoutIsDirty = true; - mDirtyVertexBufferRange.extend(static_cast<unsigned int>(bufferIndex)); - - mCurrentVertexBuffers[bufferIndex] = buffer; - mCurrentVertexStrides[bufferIndex] = stride; - mCurrentVertexOffsets[bufferIndex] = offset; - return true; - } - - return false; -} - -bool StateManager11::queueVertexOffsetChange(size_t bufferIndex, UINT offsetOnly) -{ - if (offsetOnly != mCurrentVertexOffsets[bufferIndex]) - { - mInputLayoutIsDirty = true; - mDirtyVertexBufferRange.extend(static_cast<unsigned int>(bufferIndex)); - mCurrentVertexOffsets[bufferIndex] = offsetOnly; - return true; - } - return false; -} - -void StateManager11::applyVertexBufferChanges() -{ - if (mDirtyVertexBufferRange.empty()) - { - return; - } - - ASSERT(mDirtyVertexBufferRange.high() <= gl::MAX_VERTEX_ATTRIBS); - - UINT start = static_cast<UINT>(mDirtyVertexBufferRange.low()); - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - deviceContext->IASetVertexBuffers(start, static_cast<UINT>(mDirtyVertexBufferRange.length()), - &mCurrentVertexBuffers[start], &mCurrentVertexStrides[start], - &mCurrentVertexOffsets[start]); - - mDirtyVertexBufferRange = gl::RangeUI(gl::MAX_VERTEX_ATTRIBS, 0); -} - -void StateManager11::setSingleVertexBuffer(const d3d11::Buffer *buffer, UINT stride, UINT offset) -{ - ID3D11Buffer *native = buffer ? buffer->get() : nullptr; - if (queueVertexBufferChange(0, native, stride, offset)) - { - applyVertexBufferChanges(); - } -} - -gl::Error StateManager11::updateState(const gl::Context *context, GLenum drawMode) -{ - const auto &glState = context->getGLState(); - auto *programD3D = GetImplAs<ProgramD3D>(glState.getProgram()); - - // TODO(jmadill): Use dirty bits. - processFramebufferInvalidation(context); - - // TODO(jmadill): Use dirty bits. - if (programD3D->updateSamplerMapping() == ProgramD3D::SamplerMapping::WasDirty) - { - invalidateTexturesAndSamplers(); - } - - // TODO(jmadill): Use dirty bits. - if (programD3D->areVertexUniformsDirty() || programD3D->areFragmentUniformsDirty()) - { - mInternalDirtyBits.set(DIRTY_BIT_PROGRAM_UNIFORMS); - } - - // Transform feedback affects the stream-out geometry shader. - // TODO(jmadill): Use dirty bits. - if (glState.isTransformFeedbackActiveUnpaused() != mIsTransformFeedbackCurrentlyActiveUnpaused) - { - mIsTransformFeedbackCurrentlyActiveUnpaused = glState.isTransformFeedbackActiveUnpaused(); - invalidateShaders(); - } - - // Swizzling can cause internal state changes with blit shaders. - if (mDirtySwizzles) - { - ANGLE_TRY(generateSwizzles(context)); - mDirtySwizzles = false; - } - - gl::Framebuffer *framebuffer = glState.getDrawFramebuffer(); - Framebuffer11 *framebuffer11 = GetImplAs<Framebuffer11>(framebuffer); - ANGLE_TRY(framebuffer11->markAttachmentsDirty(context)); - - if (framebuffer11->hasAnyInternalDirtyBit()) - { - ASSERT(framebuffer->id() != 0); - framebuffer11->syncInternalState(context); - } - - bool pointDrawMode = (drawMode == GL_POINTS); - if (pointDrawMode != mCurRasterState.pointDrawMode) - { - mInternalDirtyBits.set(DIRTY_BIT_RASTERIZER_STATE); - - // Changing from points to not points (or vice-versa) affects the geometry shader. - invalidateShaders(); - } - - // TODO(jiawei.shao@intel.com): This can be recomputed only on framebuffer or multisample mask - // state changes. - RenderTarget11 *firstRT = framebuffer11->getFirstRenderTarget(); - int samples = (firstRT ? firstRT->getSamples() : 0); - unsigned int sampleMask = GetBlendSampleMask(glState, samples); - if (sampleMask != mCurSampleMask) - { - mInternalDirtyBits.set(DIRTY_BIT_BLEND_STATE); - } - - // Changing the vertex attribute state can affect the vertex shader. - gl::VertexArray *vao = glState.getVertexArray(); - VertexArray11 *vao11 = GetImplAs<VertexArray11>(vao); - if (vao11->flushAttribUpdates(context)) - { - mInternalDirtyBits.set(DIRTY_BIT_SHADERS); - } - - auto dirtyBitsCopy = mInternalDirtyBits; - mInternalDirtyBits.reset(); - - for (auto dirtyBit : dirtyBitsCopy) - { - switch (dirtyBit) - { - case DIRTY_BIT_RENDER_TARGET: - ANGLE_TRY(syncFramebuffer(context, framebuffer)); - break; - case DIRTY_BIT_VIEWPORT_STATE: - syncViewport(context); - break; - case DIRTY_BIT_SCISSOR_STATE: - syncScissorRectangle(glState.getScissor(), glState.isScissorTestEnabled()); - break; - case DIRTY_BIT_RASTERIZER_STATE: - ANGLE_TRY(syncRasterizerState(context, pointDrawMode)); - break; - case DIRTY_BIT_BLEND_STATE: - ANGLE_TRY(syncBlendState(context, framebuffer, glState.getBlendState(), - glState.getBlendColor(), sampleMask)); - break; - case DIRTY_BIT_DEPTH_STENCIL_STATE: - ANGLE_TRY(syncDepthStencilState(glState)); - break; - case DIRTY_BIT_TEXTURE_AND_SAMPLER_STATE: - // TODO(jmadill): More fine-grained update. - ANGLE_TRY(syncTextures(context)); - break; - case DIRTY_BIT_PROGRAM_UNIFORMS: - ANGLE_TRY(applyUniforms(programD3D)); - break; - case DIRTY_BIT_DRIVER_UNIFORMS: - // This must happen after viewport sync; the viewport affects builtin uniforms. - ANGLE_TRY(applyDriverUniforms(*programD3D)); - break; - case DIRTY_BIT_PROGRAM_UNIFORM_BUFFERS: - ANGLE_TRY(syncUniformBuffers(context, programD3D)); - break; - case DIRTY_BIT_SHADERS: - ANGLE_TRY(syncProgram(context, drawMode)); - break; - case DIRTY_BIT_CURRENT_VALUE_ATTRIBS: - ANGLE_TRY(syncCurrentValueAttribs(glState)); - break; - default: - UNREACHABLE(); - break; - } - } - - ANGLE_TRY(syncTransformFeedbackBuffers(context)); - - // Check that we haven't set any dirty bits in the flushing of the dirty bits loop. - ASSERT(mInternalDirtyBits.none()); - - return gl::NoError(); -} - -void StateManager11::setShaderResourceShared(gl::SamplerType shaderType, - UINT resourceSlot, - const d3d11::SharedSRV *srv) -{ - setShaderResourceInternal(shaderType, resourceSlot, srv); - - // TODO(jmadill): Narrower dirty region. - mInternalDirtyBits.set(DIRTY_BIT_TEXTURE_AND_SAMPLER_STATE); -} - -void StateManager11::setShaderResource(gl::SamplerType shaderType, - UINT resourceSlot, - const d3d11::ShaderResourceView *srv) -{ - setShaderResourceInternal(shaderType, resourceSlot, srv); - - // TODO(jmadill): Narrower dirty region. - mInternalDirtyBits.set(DIRTY_BIT_TEXTURE_AND_SAMPLER_STATE); -} - -void StateManager11::setPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY primitiveTopology) -{ - if (primitiveTopology != mCurrentPrimitiveTopology) - { - mRenderer->getDeviceContext()->IASetPrimitiveTopology(primitiveTopology); - mCurrentPrimitiveTopology = primitiveTopology; - } -} - -void StateManager11::setDrawShaders(const d3d11::VertexShader *vertexShader, - const d3d11::GeometryShader *geometryShader, - const d3d11::PixelShader *pixelShader) -{ - setVertexShader(vertexShader); - setGeometryShader(geometryShader); - setPixelShader(pixelShader); -} - -void StateManager11::setVertexShader(const d3d11::VertexShader *shader) -{ - ResourceSerial serial = shader ? shader->getSerial() : ResourceSerial(0); - - if (serial != mAppliedVertexShader) - { - ID3D11VertexShader *appliedShader = shader ? shader->get() : nullptr; - mRenderer->getDeviceContext()->VSSetShader(appliedShader, nullptr, 0); - mAppliedVertexShader = serial; - invalidateShaders(); - } -} - -void StateManager11::setGeometryShader(const d3d11::GeometryShader *shader) -{ - ResourceSerial serial = shader ? shader->getSerial() : ResourceSerial(0); - - if (serial != mAppliedGeometryShader) - { - ID3D11GeometryShader *appliedShader = shader ? shader->get() : nullptr; - mRenderer->getDeviceContext()->GSSetShader(appliedShader, nullptr, 0); - mAppliedGeometryShader = serial; - invalidateShaders(); - } -} - -void StateManager11::setPixelShader(const d3d11::PixelShader *shader) -{ - ResourceSerial serial = shader ? shader->getSerial() : ResourceSerial(0); - - if (serial != mAppliedPixelShader) - { - ID3D11PixelShader *appliedShader = shader ? shader->get() : nullptr; - mRenderer->getDeviceContext()->PSSetShader(appliedShader, nullptr, 0); - mAppliedPixelShader = serial; - invalidateShaders(); - } -} - -void StateManager11::setComputeShader(const d3d11::ComputeShader *shader) -{ - ResourceSerial serial = shader ? shader->getSerial() : ResourceSerial(0); - - if (serial != mAppliedComputeShader) - { - ID3D11ComputeShader *appliedShader = shader ? shader->get() : nullptr; - mRenderer->getDeviceContext()->CSSetShader(appliedShader, nullptr, 0); - mAppliedComputeShader = serial; - // TODO(jmadill): Dirty bits for compute. - } -} - -void StateManager11::setVertexConstantBuffer(unsigned int slot, const d3d11::Buffer *buffer) -{ - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - auto ¤tSerial = mCurrentConstantBufferVS[slot]; - - mCurrentConstantBufferVSOffset[slot] = 0; - mCurrentConstantBufferVSSize[slot] = 0; - - if (buffer) - { - if (currentSerial != buffer->getSerial()) - { - deviceContext->VSSetConstantBuffers(slot, 1, buffer->getPointer()); - currentSerial = buffer->getSerial(); - invalidateConstantBuffer(slot); - } - } - else - { - if (!currentSerial.empty()) - { - ID3D11Buffer *nullBuffer = nullptr; - deviceContext->VSSetConstantBuffers(slot, 1, &nullBuffer); - currentSerial.clear(); - invalidateConstantBuffer(slot); - } - } -} - -void StateManager11::setPixelConstantBuffer(unsigned int slot, const d3d11::Buffer *buffer) -{ - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - auto ¤tSerial = mCurrentConstantBufferPS[slot]; - - mCurrentConstantBufferPSOffset[slot] = 0; - mCurrentConstantBufferPSSize[slot] = 0; - - if (buffer) - { - if (currentSerial != buffer->getSerial()) - { - deviceContext->PSSetConstantBuffers(slot, 1, buffer->getPointer()); - currentSerial = buffer->getSerial(); - invalidateConstantBuffer(slot); - } - } - else - { - if (!currentSerial.empty()) - { - ID3D11Buffer *nullBuffer = nullptr; - deviceContext->PSSetConstantBuffers(slot, 1, &nullBuffer); - currentSerial.clear(); - invalidateConstantBuffer(slot); - } - } -} - -void StateManager11::setDepthStencilState(const d3d11::DepthStencilState *depthStencilState, - UINT stencilRef) -{ - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - if (depthStencilState) - { - deviceContext->OMSetDepthStencilState(depthStencilState->get(), stencilRef); - } - else - { - deviceContext->OMSetDepthStencilState(nullptr, stencilRef); - } - - mInternalDirtyBits.set(DIRTY_BIT_DEPTH_STENCIL_STATE); -} - -void StateManager11::setSimpleBlendState(const d3d11::BlendState *blendState) -{ - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - if (blendState) - { - deviceContext->OMSetBlendState(blendState->get(), nullptr, 0xFFFFFFFF); - } - else - { - deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFFF); - } - - mInternalDirtyBits.set(DIRTY_BIT_BLEND_STATE); -} - -void StateManager11::setRasterizerState(const d3d11::RasterizerState *rasterizerState) -{ - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - if (rasterizerState) - { - deviceContext->RSSetState(rasterizerState->get()); - } - else - { - deviceContext->RSSetState(nullptr); - } - - mInternalDirtyBits.set(DIRTY_BIT_RASTERIZER_STATE); -} - -void StateManager11::setSimpleViewport(const gl::Extents &extents) -{ - setSimpleViewport(extents.width, extents.height); -} - -void StateManager11::setSimpleViewport(int width, int height) -{ - D3D11_VIEWPORT viewport; - viewport.TopLeftX = 0; - viewport.TopLeftY = 0; - viewport.Width = static_cast<FLOAT>(width); - viewport.Height = static_cast<FLOAT>(height); - viewport.MinDepth = 0.0f; - viewport.MaxDepth = 1.0f; - - mRenderer->getDeviceContext()->RSSetViewports(1, &viewport); - mInternalDirtyBits.set(DIRTY_BIT_VIEWPORT_STATE); -} - -void StateManager11::setSimplePixelTextureAndSampler(const d3d11::SharedSRV &srv, - const d3d11::SamplerState &samplerState) -{ - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - setShaderResourceInternal(gl::SAMPLER_PIXEL, 0, &srv); - deviceContext->PSSetSamplers(0, 1, samplerState.getPointer()); - - mInternalDirtyBits.set(DIRTY_BIT_TEXTURE_AND_SAMPLER_STATE); - mForceSetPixelSamplerStates[0] = true; -} - -void StateManager11::setSimpleScissorRect(const gl::Rectangle &glRect) -{ - D3D11_RECT scissorRect; - scissorRect.left = glRect.x; - scissorRect.right = glRect.x + glRect.width; - scissorRect.top = glRect.y; - scissorRect.bottom = glRect.y + glRect.height; - setScissorRectD3D(scissorRect); -} - -void StateManager11::setScissorRectD3D(const D3D11_RECT &d3dRect) -{ - mRenderer->getDeviceContext()->RSSetScissorRects(1, &d3dRect); - mInternalDirtyBits.set(DIRTY_BIT_SCISSOR_STATE); -} - -// For each Direct3D sampler of either the pixel or vertex stage, -// looks up the corresponding OpenGL texture image unit and texture type, -// and sets the texture and its addressing/filtering state (or NULL when inactive). -// Sampler mapping needs to be up-to-date on the program object before this is called. -gl::Error StateManager11::applyTextures(const gl::Context *context, gl::SamplerType shaderType) -{ - const auto &glState = context->getGLState(); - const auto &caps = context->getCaps(); - ProgramD3D *programD3D = GetImplAs<ProgramD3D>(glState.getProgram()); - - ASSERT(!programD3D->isSamplerMappingDirty()); - - // TODO(jmadill): Use the Program's sampler bindings. - const auto &completeTextures = glState.getCompleteTextureCache(); - - unsigned int samplerRange = programD3D->getUsedSamplerRange(shaderType); - for (unsigned int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++) - { - GLint textureUnit = programD3D->getSamplerMapping(shaderType, samplerIndex, caps); - ASSERT(textureUnit != -1); - gl::Texture *texture = completeTextures[textureUnit]; - - // A nullptr texture indicates incomplete. - if (texture) - { - gl::Sampler *samplerObject = glState.getSampler(textureUnit); - - const gl::SamplerState &samplerState = - samplerObject ? samplerObject->getSamplerState() : texture->getSamplerState(); - - ANGLE_TRY(setSamplerState(context, shaderType, samplerIndex, texture, samplerState)); - ANGLE_TRY(setTexture(context, shaderType, samplerIndex, texture)); - } - else - { - GLenum textureType = programD3D->getSamplerTextureType(shaderType, samplerIndex); - - // Texture is not sampler complete or it is in use by the framebuffer. Bind the - // incomplete texture. - gl::Texture *incompleteTexture = nullptr; - ANGLE_TRY(mRenderer->getIncompleteTexture(context, textureType, &incompleteTexture)); - ANGLE_TRY(setSamplerState(context, shaderType, samplerIndex, incompleteTexture, - incompleteTexture->getSamplerState())); - ANGLE_TRY(setTexture(context, shaderType, samplerIndex, incompleteTexture)); - } - } - - // Set all the remaining textures to NULL - size_t samplerCount = (shaderType == gl::SAMPLER_PIXEL) ? caps.maxTextureImageUnits - : caps.maxVertexTextureImageUnits; - ANGLE_TRY(clearTextures(shaderType, samplerRange, samplerCount)); - - return gl::NoError(); -} - -gl::Error StateManager11::syncTextures(const gl::Context *context) -{ - ANGLE_TRY(applyTextures(context, gl::SAMPLER_VERTEX)); - ANGLE_TRY(applyTextures(context, gl::SAMPLER_PIXEL)); - return gl::NoError(); -} - -gl::Error StateManager11::setSamplerState(const gl::Context *context, - gl::SamplerType type, - int index, - gl::Texture *texture, - const gl::SamplerState &samplerState) -{ -#if !defined(NDEBUG) - // Storage should exist, texture should be complete. Only verified in Debug. - TextureD3D *textureD3D = GetImplAs<TextureD3D>(texture); - TextureStorage *storage = nullptr; - ANGLE_TRY(textureD3D->getNativeTexture(context, &storage)); - ASSERT(storage); -#endif // !defined(NDEBUG) - - auto *deviceContext = mRenderer->getDeviceContext(); - - if (type == gl::SAMPLER_PIXEL) - { - ASSERT(static_cast<unsigned int>(index) < mRenderer->getNativeCaps().maxTextureImageUnits); - - if (mForceSetPixelSamplerStates[index] || - memcmp(&samplerState, &mCurPixelSamplerStates[index], sizeof(gl::SamplerState)) != 0) - { - ID3D11SamplerState *dxSamplerState = nullptr; - ANGLE_TRY(mRenderer->getSamplerState(samplerState, &dxSamplerState)); - - ASSERT(dxSamplerState != nullptr); - deviceContext->PSSetSamplers(index, 1, &dxSamplerState); - - mCurPixelSamplerStates[index] = samplerState; - } - - mForceSetPixelSamplerStates[index] = false; - } - else if (type == gl::SAMPLER_VERTEX) - { - ASSERT(static_cast<unsigned int>(index) < - mRenderer->getNativeCaps().maxVertexTextureImageUnits); - - if (mForceSetVertexSamplerStates[index] || - memcmp(&samplerState, &mCurVertexSamplerStates[index], sizeof(gl::SamplerState)) != 0) - { - ID3D11SamplerState *dxSamplerState = nullptr; - ANGLE_TRY(mRenderer->getSamplerState(samplerState, &dxSamplerState)); - - ASSERT(dxSamplerState != nullptr); - deviceContext->VSSetSamplers(index, 1, &dxSamplerState); - - mCurVertexSamplerStates[index] = samplerState; - } - - mForceSetVertexSamplerStates[index] = false; - } - else if (type == gl::SAMPLER_COMPUTE) - { - ASSERT(static_cast<unsigned int>(index) < - mRenderer->getNativeCaps().maxComputeTextureImageUnits); - - if (mForceSetComputeSamplerStates[index] || - memcmp(&samplerState, &mCurComputeSamplerStates[index], sizeof(gl::SamplerState)) != 0) - { - ID3D11SamplerState *dxSamplerState = nullptr; - ANGLE_TRY(mRenderer->getSamplerState(samplerState, &dxSamplerState)); - - ASSERT(dxSamplerState != nullptr); - deviceContext->CSSetSamplers(index, 1, &dxSamplerState); - - mCurComputeSamplerStates[index] = samplerState; - } - - mForceSetComputeSamplerStates[index] = false; - } - else - UNREACHABLE(); - - // Sampler metadata that's passed to shaders in uniforms is stored separately from rest of the - // sampler state since having it in contiguous memory makes it possible to memcpy to a constant - // buffer, and it doesn't affect the state set by PSSetSamplers/VSSetSamplers. - mShaderConstants.onSamplerChange(type, index, *texture); - - return gl::NoError(); -} - -gl::Error StateManager11::setTexture(const gl::Context *context, - gl::SamplerType type, - int index, - gl::Texture *texture) -{ - const d3d11::SharedSRV *textureSRV = nullptr; - - if (texture) - { - TextureD3D *textureImpl = GetImplAs<TextureD3D>(texture); - - TextureStorage *texStorage = nullptr; - ANGLE_TRY(textureImpl->getNativeTexture(context, &texStorage)); - - // Texture should be complete and have a storage - ASSERT(texStorage); - - TextureStorage11 *storage11 = GetAs<TextureStorage11>(texStorage); - - ANGLE_TRY(storage11->getSRV(context, texture->getTextureState(), &textureSRV)); - - // If we get an invalid SRV here, something went wrong in the texture class and we're - // unexpectedly missing the shader resource view. - ASSERT(textureSRV->valid()); - - textureImpl->resetDirty(); - } - - ASSERT( - (type == gl::SAMPLER_PIXEL && - static_cast<unsigned int>(index) < mRenderer->getNativeCaps().maxTextureImageUnits) || - (type == gl::SAMPLER_VERTEX && - static_cast<unsigned int>(index) < mRenderer->getNativeCaps().maxVertexTextureImageUnits)); - - setShaderResourceInternal(type, index, textureSRV); - return gl::NoError(); -} - -// Things that affect a program's dirtyness: -// 1. Directly changing the program executable -> triggered in StateManager11::syncState. -// 2. The vertex attribute layout -> triggered in VertexArray11::syncState/signal. -// 3. The fragment shader's rendertargets -> triggered in Framebuffer11::syncState/signal. -// 4. Enabling/disabling rasterizer discard. -> triggered in StateManager11::syncState. -// 5. Enabling/disabling transform feedback. -> checked in StateManager11::updateState. -// 6. An internal shader was used. -> triggered in StateManager11::set*Shader. -// 7. Drawing with/without point sprites. -> checked in StateManager11::updateState. -// TODO(jmadill): Use dirty bits for transform feedback. -gl::Error StateManager11::syncProgram(const gl::Context *context, GLenum drawMode) -{ - Context11 *context11 = GetImplAs<Context11>(context); - ANGLE_TRY(context11->triggerDrawCallProgramRecompilation(context, drawMode)); - - const auto &glState = context->getGLState(); - const auto *va11 = GetImplAs<VertexArray11>(glState.getVertexArray()); - auto *programD3D = GetImplAs<ProgramD3D>(glState.getProgram()); - - programD3D->updateCachedInputLayout(va11->getCurrentStateSerial(), glState); - - // Binaries must be compiled before the sync. - ASSERT(programD3D->hasVertexExecutableForCachedInputLayout()); - ASSERT(programD3D->hasGeometryExecutableForPrimitiveType(drawMode)); - ASSERT(programD3D->hasPixelExecutableForCachedOutputLayout()); - - ShaderExecutableD3D *vertexExe = nullptr; - ANGLE_TRY(programD3D->getVertexExecutableForCachedInputLayout(&vertexExe, nullptr)); - - ShaderExecutableD3D *pixelExe = nullptr; - ANGLE_TRY(programD3D->getPixelExecutableForCachedOutputLayout(&pixelExe, nullptr)); - - ShaderExecutableD3D *geometryExe = nullptr; - ANGLE_TRY(programD3D->getGeometryExecutableForPrimitiveType(context, drawMode, &geometryExe, - nullptr)); - - const d3d11::VertexShader *vertexShader = - (vertexExe ? &GetAs<ShaderExecutable11>(vertexExe)->getVertexShader() : nullptr); - - // Skip pixel shader if we're doing rasterizer discard. - const d3d11::PixelShader *pixelShader = nullptr; - if (!glState.getRasterizerState().rasterizerDiscard) - { - pixelShader = (pixelExe ? &GetAs<ShaderExecutable11>(pixelExe)->getPixelShader() : nullptr); - } - - const d3d11::GeometryShader *geometryShader = nullptr; - if (glState.isTransformFeedbackActiveUnpaused()) - { - geometryShader = - (vertexExe ? &GetAs<ShaderExecutable11>(vertexExe)->getStreamOutShader() : nullptr); - } - else - { - geometryShader = - (geometryExe ? &GetAs<ShaderExecutable11>(geometryExe)->getGeometryShader() : nullptr); - } - - setDrawShaders(vertexShader, geometryShader, pixelShader); - - // Explicitly clear the shaders dirty bit. - mInternalDirtyBits.reset(DIRTY_BIT_SHADERS); - - return gl::NoError(); -} - -gl::Error StateManager11::applyVertexBuffer(const gl::Context *context, - GLenum mode, - const DrawCallVertexParams &vertexParams, - bool isIndexedRendering) -{ - const auto &state = context->getGLState(); - const gl::VertexArray *vertexArray = state.getVertexArray(); - VertexArray11 *vertexArray11 = GetImplAs<VertexArray11>(vertexArray); - - if (mVertexAttribsNeedTranslation) - { - ANGLE_TRY(vertexArray11->updateDirtyAndDynamicAttribs(context, &mVertexDataManager, - vertexParams)); - mInputLayoutIsDirty = true; - - // Determine if we need to update attribs on the next draw. - mVertexAttribsNeedTranslation = (vertexArray11->hasActiveDynamicAttrib(context)); - } - - if (!mLastFirstVertex.valid() || mLastFirstVertex.value() != vertexParams.firstVertex()) - { - mLastFirstVertex = vertexParams.firstVertex(); - mInputLayoutIsDirty = true; - } - - if (!mInputLayoutIsDirty) - { - return gl::NoError(); - } - - const auto &vertexArrayAttribs = vertexArray11->getTranslatedAttribs(); - gl::Program *program = state.getProgram(); - - // Sort the attributes according to ensure we re-use similar input layouts. - AttribIndexArray sortedSemanticIndices; - SortAttributesByLayout(program, vertexArrayAttribs, mCurrentValueAttribs, - &sortedSemanticIndices, &mCurrentAttributes); - - auto featureLevel = mRenderer->getRenderer11DeviceCaps().featureLevel; - - // If we are using FL 9_3, make sure the first attribute is not instanced - if (featureLevel <= D3D_FEATURE_LEVEL_9_3 && !mCurrentAttributes.empty()) - { - if (mCurrentAttributes[0]->divisor > 0) - { - Optional<size_t> firstNonInstancedIndex = FindFirstNonInstanced(mCurrentAttributes); - if (firstNonInstancedIndex.valid()) - { - size_t index = firstNonInstancedIndex.value(); - std::swap(mCurrentAttributes[0], mCurrentAttributes[index]); - std::swap(sortedSemanticIndices[0], sortedSemanticIndices[index]); - } - } - } - - // Update the applied input layout by querying the cache. - ANGLE_TRY(mInputLayoutCache.updateInputLayout(mRenderer, state, mCurrentAttributes, mode, - sortedSemanticIndices, vertexParams)); - - // Update the applied vertex buffers. - ANGLE_TRY(mInputLayoutCache.applyVertexBuffers(context, mCurrentAttributes, mode, - vertexParams.firstVertex(), isIndexedRendering)); - - // InputLayoutCache::applyVertexBuffers calls through to the Bufer11 to get the native vertex - // buffer (ID3D11Buffer *). Because we allocate these buffers lazily, this will trigger - // allocation. This in turn will signal that the buffer is dirty. Since we just resolved the - // dirty-ness in VertexArray11::updateDirtyAndDynamicAttribs, this can make us do a needless - // update on the second draw call. - // Hence we clear the flags here, after we've applied vertex data, since we know everything - // is clean. This is a bit of a hack. - vertexArray11->clearDirtyAndPromoteDynamicAttribs(context, vertexParams); - - mInputLayoutIsDirty = false; - return gl::NoError(); -} - -gl::Error StateManager11::applyIndexBuffer(const gl::Context *context, - const void *indices, - GLsizei count, - GLenum type, - const gl::HasIndexRange &lazyIndexRange, - bool usePrimitiveRestartWorkaround) -{ - const auto &glState = context->getGLState(); - gl::VertexArray *vao = glState.getVertexArray(); - VertexArray11 *vao11 = GetImplAs<VertexArray11>(vao); - - GLenum destElementType = - GetIndexTranslationDestType(type, lazyIndexRange, usePrimitiveRestartWorkaround); - - if (!vao11->updateElementArrayStorage(context, type, destElementType, indices) && - !mIndexBufferIsDirty) - { - // No streaming or index buffer application necessary. - return gl::NoError(); - } - - gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get(); - - TranslatedIndexData *indexInfo = vao11->getCachedIndexInfo(); - ANGLE_TRY(mIndexDataManager.prepareIndexData(context, type, destElementType, count, - elementArrayBuffer, indices, indexInfo)); - - ID3D11Buffer *buffer = nullptr; - DXGI_FORMAT bufferFormat = - (indexInfo->indexType == GL_UNSIGNED_INT) ? DXGI_FORMAT_R32_UINT : DXGI_FORMAT_R16_UINT; - - if (indexInfo->storage) - { - Buffer11 *storage = GetAs<Buffer11>(indexInfo->storage); - ANGLE_TRY_RESULT(storage->getBuffer(context, BUFFER_USAGE_INDEX), buffer); - } - else - { - IndexBuffer11 *indexBuffer = GetAs<IndexBuffer11>(indexInfo->indexBuffer); - buffer = indexBuffer->getBuffer().get(); - } - - // Track dirty indices in the index range cache. - indexInfo->srcIndexData.srcIndicesChanged = - syncIndexBuffer(buffer, bufferFormat, indexInfo->startOffset); - - mIndexBufferIsDirty = false; - - vao11->setCachedIndexInfoValid(); - return gl::NoError(); -} - -void StateManager11::setIndexBuffer(ID3D11Buffer *buffer, - DXGI_FORMAT indexFormat, - unsigned int offset) -{ - if (syncIndexBuffer(buffer, indexFormat, offset)) - { - mIndexBufferIsDirty = true; - } -} - -bool StateManager11::syncIndexBuffer(ID3D11Buffer *buffer, - DXGI_FORMAT indexFormat, - unsigned int offset) -{ - if (buffer != mAppliedIB || indexFormat != mAppliedIBFormat || offset != mAppliedIBOffset) - { - mRenderer->getDeviceContext()->IASetIndexBuffer(buffer, indexFormat, offset); - - mAppliedIB = buffer; - mAppliedIBFormat = indexFormat; - mAppliedIBOffset = offset; - return true; - } - - return false; -} - -// Vertex buffer is invalidated outside this function. -gl::Error StateManager11::updateVertexOffsetsForPointSpritesEmulation(GLint startVertex, - GLsizei emulatedInstanceId) -{ - return mInputLayoutCache.updateVertexOffsetsForPointSpritesEmulation( - mRenderer, mCurrentAttributes, startVertex, emulatedInstanceId); -} - -gl::Error StateManager11::generateSwizzle(const gl::Context *context, gl::Texture *texture) -{ - if (!texture) - { - return gl::NoError(); - } - - TextureD3D *textureD3D = GetImplAs<TextureD3D>(texture); - ASSERT(textureD3D); - - TextureStorage *texStorage = nullptr; - ANGLE_TRY(textureD3D->getNativeTexture(context, &texStorage)); - - if (texStorage) - { - TextureStorage11 *storage11 = GetAs<TextureStorage11>(texStorage); - const gl::TextureState &textureState = texture->getTextureState(); - ANGLE_TRY(storage11->generateSwizzles(context, textureState.getSwizzleState())); - } - - return gl::NoError(); -} - -gl::Error StateManager11::generateSwizzlesForShader(const gl::Context *context, - gl::SamplerType type) -{ - const auto &glState = context->getGLState(); - ProgramD3D *programD3D = GetImplAs<ProgramD3D>(glState.getProgram()); - - unsigned int samplerRange = programD3D->getUsedSamplerRange(type); - - for (unsigned int i = 0; i < samplerRange; i++) - { - GLenum textureType = programD3D->getSamplerTextureType(type, i); - GLint textureUnit = programD3D->getSamplerMapping(type, i, context->getCaps()); - if (textureUnit != -1) - { - gl::Texture *texture = glState.getSamplerTexture(textureUnit, textureType); - ASSERT(texture); - if (texture->getTextureState().swizzleRequired()) - { - ANGLE_TRY(generateSwizzle(context, texture)); - } - } - } - - return gl::NoError(); -} - -gl::Error StateManager11::generateSwizzles(const gl::Context *context) -{ - ANGLE_TRY(generateSwizzlesForShader(context, gl::SAMPLER_VERTEX)); - ANGLE_TRY(generateSwizzlesForShader(context, gl::SAMPLER_PIXEL)); - return gl::NoError(); -} - -gl::Error StateManager11::applyUniforms(ProgramD3D *programD3D) -{ - UniformStorage11 *vertexUniformStorage = - GetAs<UniformStorage11>(&programD3D->getVertexUniformStorage()); - UniformStorage11 *fragmentUniformStorage = - GetAs<UniformStorage11>(&programD3D->getFragmentUniformStorage()); - ASSERT(vertexUniformStorage); - ASSERT(fragmentUniformStorage); - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - const d3d11::Buffer *vertexConstantBuffer = nullptr; - ANGLE_TRY(vertexUniformStorage->getConstantBuffer(mRenderer, &vertexConstantBuffer)); - const d3d11::Buffer *pixelConstantBuffer = nullptr; - ANGLE_TRY(fragmentUniformStorage->getConstantBuffer(mRenderer, &pixelConstantBuffer)); - - if (vertexUniformStorage->size() > 0 && programD3D->areVertexUniformsDirty()) - { - UpdateUniformBuffer(deviceContext, vertexUniformStorage, vertexConstantBuffer); - } - - if (fragmentUniformStorage->size() > 0 && programD3D->areFragmentUniformsDirty()) - { - UpdateUniformBuffer(deviceContext, fragmentUniformStorage, pixelConstantBuffer); - } - - unsigned int slot = d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DEFAULT_UNIFORM_BLOCK; - - if (mCurrentConstantBufferVS[slot] != vertexConstantBuffer->getSerial()) - { - deviceContext->VSSetConstantBuffers(slot, 1, vertexConstantBuffer->getPointer()); - mCurrentConstantBufferVS[slot] = vertexConstantBuffer->getSerial(); - mCurrentConstantBufferVSOffset[slot] = 0; - mCurrentConstantBufferVSSize[slot] = 0; - } - - if (mCurrentConstantBufferPS[slot] != pixelConstantBuffer->getSerial()) - { - deviceContext->PSSetConstantBuffers(slot, 1, pixelConstantBuffer->getPointer()); - mCurrentConstantBufferPS[slot] = pixelConstantBuffer->getSerial(); - mCurrentConstantBufferPSOffset[slot] = 0; - mCurrentConstantBufferPSSize[slot] = 0; - } - - programD3D->markUniformsClean(); - - return gl::NoError(); -} - -gl::Error StateManager11::applyDriverUniforms(const ProgramD3D &programD3D) -{ - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - if (!mDriverConstantBufferVS.valid()) - { - size_t requiredSize = mShaderConstants.getRequiredBufferSize(gl::SAMPLER_VERTEX); - - D3D11_BUFFER_DESC constantBufferDescription = {0}; - d3d11::InitConstantBufferDesc(&constantBufferDescription, requiredSize); - ANGLE_TRY(mRenderer->allocateResource(constantBufferDescription, &mDriverConstantBufferVS)); - - ID3D11Buffer *driverVSConstants = mDriverConstantBufferVS.get(); - deviceContext->VSSetConstantBuffers(d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DRIVER, 1, - &driverVSConstants); - } - - if (!mDriverConstantBufferPS.valid()) - { - size_t requiredSize = mShaderConstants.getRequiredBufferSize(gl::SAMPLER_PIXEL); - - D3D11_BUFFER_DESC constantBufferDescription = {0}; - d3d11::InitConstantBufferDesc(&constantBufferDescription, requiredSize); - ANGLE_TRY(mRenderer->allocateResource(constantBufferDescription, &mDriverConstantBufferPS)); - - ID3D11Buffer *driverVSConstants = mDriverConstantBufferPS.get(); - deviceContext->PSSetConstantBuffers(d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DRIVER, 1, - &driverVSConstants); - } - - // Sampler metadata and driver constants need to coexist in the same constant buffer to conserve - // constant buffer slots. We update both in the constant buffer if needed. - ANGLE_TRY(mShaderConstants.updateBuffer(deviceContext, gl::SAMPLER_VERTEX, programD3D, - mDriverConstantBufferVS)); - ANGLE_TRY(mShaderConstants.updateBuffer(deviceContext, gl::SAMPLER_PIXEL, programD3D, - mDriverConstantBufferPS)); - - // needed for the point sprite geometry shader - // GSSetConstantBuffers triggers device removal on 9_3, so we should only call it for ES3. - if (mRenderer->isES3Capable()) - { - if (mCurrentGeometryConstantBuffer != mDriverConstantBufferPS.getSerial()) - { - ASSERT(mDriverConstantBufferPS.valid()); - deviceContext->GSSetConstantBuffers(0, 1, mDriverConstantBufferPS.getPointer()); - mCurrentGeometryConstantBuffer = mDriverConstantBufferPS.getSerial(); - } - } - - return gl::NoError(); -} - -gl::Error StateManager11::applyComputeUniforms(ProgramD3D *programD3D) -{ - UniformStorage11 *computeUniformStorage = - GetAs<UniformStorage11>(&programD3D->getComputeUniformStorage()); - ASSERT(computeUniformStorage); - - const d3d11::Buffer *constantBuffer = nullptr; - ANGLE_TRY(computeUniformStorage->getConstantBuffer(mRenderer, &constantBuffer)); - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - if (computeUniformStorage->size() > 0 && programD3D->areComputeUniformsDirty()) - { - UpdateUniformBuffer(deviceContext, computeUniformStorage, constantBuffer); - programD3D->markUniformsClean(); - } - - if (mCurrentComputeConstantBuffer != constantBuffer->getSerial()) - { - deviceContext->CSSetConstantBuffers( - d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DEFAULT_UNIFORM_BLOCK, 1, - constantBuffer->getPointer()); - mCurrentComputeConstantBuffer = constantBuffer->getSerial(); - } - - if (!mDriverConstantBufferCS.valid()) - { - size_t requiredSize = mShaderConstants.getRequiredBufferSize(gl::SAMPLER_COMPUTE); - - D3D11_BUFFER_DESC constantBufferDescription = {0}; - d3d11::InitConstantBufferDesc(&constantBufferDescription, requiredSize); - ANGLE_TRY(mRenderer->allocateResource(constantBufferDescription, &mDriverConstantBufferCS)); - ID3D11Buffer *buffer = mDriverConstantBufferCS.get(); - deviceContext->CSSetConstantBuffers(d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DRIVER, 1, - &buffer); - } - - ANGLE_TRY(mShaderConstants.updateBuffer(deviceContext, gl::SAMPLER_COMPUTE, *programD3D, - mDriverConstantBufferCS)); - - return gl::NoError(); -} - -gl::Error StateManager11::syncUniformBuffers(const gl::Context *context, ProgramD3D *programD3D) -{ - unsigned int reservedVertex = mRenderer->getReservedVertexUniformBuffers(); - unsigned int reservedFragment = mRenderer->getReservedFragmentUniformBuffers(); - - programD3D->updateUniformBufferCache(context->getCaps(), reservedVertex, reservedFragment); - - const auto &vertexUniformBuffers = programD3D->getVertexUniformBufferCache(); - const auto &fragmentUniformBuffers = programD3D->getFragmentUniformBufferCache(); - const auto &glState = context->getGLState(); - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - ID3D11DeviceContext1 *deviceContext1 = mRenderer->getDeviceContext1IfSupported(); - - for (size_t bufferIndex = 0; bufferIndex < vertexUniformBuffers.size(); bufferIndex++) - { - GLint binding = vertexUniformBuffers[bufferIndex]; - - if (binding == -1) - { - continue; - } - - const auto &uniformBuffer = glState.getIndexedUniformBuffer(binding); - GLintptr uniformBufferOffset = uniformBuffer.getOffset(); - GLsizeiptr uniformBufferSize = uniformBuffer.getSize(); - - if (uniformBuffer.get() == nullptr) - { - continue; - } - - Buffer11 *bufferStorage = GetImplAs<Buffer11>(uniformBuffer.get()); - const d3d11::Buffer *constantBuffer = nullptr; - UINT firstConstant = 0; - UINT numConstants = 0; - - ANGLE_TRY(bufferStorage->getConstantBufferRange(context, uniformBufferOffset, - uniformBufferSize, &constantBuffer, - &firstConstant, &numConstants)); - - ASSERT(constantBuffer); - - if (mCurrentConstantBufferVS[bufferIndex] == constantBuffer->getSerial() && - mCurrentConstantBufferVSOffset[bufferIndex] == uniformBufferOffset && - mCurrentConstantBufferVSSize[bufferIndex] == uniformBufferSize) - { - continue; - } - - unsigned int appliedIndex = reservedVertex + static_cast<unsigned int>(bufferIndex); - - if (firstConstant != 0 && uniformBufferSize != 0) - { - ASSERT(numConstants != 0); - deviceContext1->VSSetConstantBuffers1(appliedIndex, 1, constantBuffer->getPointer(), - &firstConstant, &numConstants); - } - else - { - deviceContext->VSSetConstantBuffers(appliedIndex, 1, constantBuffer->getPointer()); - } - - mCurrentConstantBufferVS[appliedIndex] = constantBuffer->getSerial(); - mCurrentConstantBufferVSOffset[appliedIndex] = uniformBufferOffset; - mCurrentConstantBufferVSSize[appliedIndex] = uniformBufferSize; - } - - for (size_t bufferIndex = 0; bufferIndex < fragmentUniformBuffers.size(); bufferIndex++) - { - GLint binding = fragmentUniformBuffers[bufferIndex]; - - if (binding == -1) - { - continue; - } - - const auto &uniformBuffer = glState.getIndexedUniformBuffer(binding); - GLintptr uniformBufferOffset = uniformBuffer.getOffset(); - GLsizeiptr uniformBufferSize = uniformBuffer.getSize(); - - if (uniformBuffer.get() == nullptr) - { - continue; - } - - Buffer11 *bufferStorage = GetImplAs<Buffer11>(uniformBuffer.get()); - const d3d11::Buffer *constantBuffer = nullptr; - UINT firstConstant = 0; - UINT numConstants = 0; - - ANGLE_TRY(bufferStorage->getConstantBufferRange(context, uniformBufferOffset, - uniformBufferSize, &constantBuffer, - &firstConstant, &numConstants)); - - ASSERT(constantBuffer); - - if (mCurrentConstantBufferPS[bufferIndex] == constantBuffer->getSerial() && - mCurrentConstantBufferPSOffset[bufferIndex] == uniformBufferOffset && - mCurrentConstantBufferPSSize[bufferIndex] == uniformBufferSize) - { - continue; - } - - unsigned int appliedIndex = reservedFragment + static_cast<unsigned int>(bufferIndex); - - if (firstConstant != 0 && uniformBufferSize != 0) - { - deviceContext1->PSSetConstantBuffers1(appliedIndex, 1, constantBuffer->getPointer(), - &firstConstant, &numConstants); - } - else - { - deviceContext->PSSetConstantBuffers(appliedIndex, 1, constantBuffer->getPointer()); - } - - mCurrentConstantBufferPS[appliedIndex] = constantBuffer->getSerial(); - mCurrentConstantBufferPSOffset[appliedIndex] = uniformBufferOffset; - mCurrentConstantBufferPSSize[appliedIndex] = uniformBufferSize; - } - - return gl::NoError(); -} - -gl::Error StateManager11::syncTransformFeedbackBuffers(const gl::Context *context) -{ - const auto &glState = context->getGLState(); - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - // If transform feedback is not active, unbind all buffers - if (!glState.isTransformFeedbackActiveUnpaused()) - { - if (mAppliedTFSerial != mEmptySerial) - { - deviceContext->SOSetTargets(0, nullptr, nullptr); - mAppliedTFSerial = mEmptySerial; - } - return gl::NoError(); - } - - gl::TransformFeedback *transformFeedback = glState.getCurrentTransformFeedback(); - TransformFeedback11 *tf11 = GetImplAs<TransformFeedback11>(transformFeedback); - if (mAppliedTFSerial == tf11->getSerial() && !tf11->isDirty()) - { - return gl::NoError(); - } - - const std::vector<ID3D11Buffer *> *soBuffers = nullptr; - ANGLE_TRY_RESULT(tf11->getSOBuffers(context), soBuffers); - const std::vector<UINT> &soOffsets = tf11->getSOBufferOffsets(); - - deviceContext->SOSetTargets(tf11->getNumSOBuffers(), soBuffers->data(), soOffsets.data()); - - mAppliedTFSerial = tf11->getSerial(); - tf11->onApply(); - - return gl::NoError(); -} - -// DrawCallVertexParams implementation. -DrawCallVertexParams::DrawCallVertexParams(GLint firstVertex, - GLsizei vertexCount, - GLsizei instances) - : mHasIndexRange(nullptr), - mFirstVertex(firstVertex), - mVertexCount(vertexCount), - mInstances(instances), - mBaseVertex(0) -{ -} - -// Use when in a drawElements call. -DrawCallVertexParams::DrawCallVertexParams(bool firstVertexDefinitelyZero, - const gl::HasIndexRange &hasIndexRange, - GLint baseVertex, - GLsizei instances) - : mHasIndexRange(&hasIndexRange), - mFirstVertex(), - mVertexCount(0), - mInstances(instances), - mBaseVertex(baseVertex) -{ - if (firstVertexDefinitelyZero) - { - mFirstVertex = baseVertex; - } -} - -GLint DrawCallVertexParams::firstVertex() const -{ - if (!mFirstVertex.valid()) - { - ensureResolved(); - ASSERT(mFirstVertex.valid()); - } - return mFirstVertex.value(); -} - -GLsizei DrawCallVertexParams::vertexCount() const -{ - ensureResolved(); - return mVertexCount; -} - -GLsizei DrawCallVertexParams::instances() const -{ - return mInstances; -} - -void DrawCallVertexParams::ensureResolved() const -{ - if (mHasIndexRange) - { - ASSERT(!mFirstVertex.valid() || mFirstVertex == mBaseVertex); - - // Resolve the index range now if we need to. - const auto &indexRange = mHasIndexRange->getIndexRange().value(); - mFirstVertex = mBaseVertex + static_cast<GLint>(indexRange.start); - mVertexCount = static_cast<GLsizei>(indexRange.vertexCount()); - mHasIndexRange = nullptr; - } -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/StateManager11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/StateManager11.h deleted file mode 100644 index e48bc83a22..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/StateManager11.h +++ /dev/null @@ -1,557 +0,0 @@ -// -// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// StateManager11.h: Defines a class for caching D3D11 state - -#ifndef LIBANGLE_RENDERER_D3D11_STATEMANAGER11_H_ -#define LIBANGLE_RENDERER_D3D11_STATEMANAGER11_H_ - -#include <array> - -#include "libANGLE/ContextState.h" -#include "libANGLE/State.h" -#include "libANGLE/angletypes.h" -#include "libANGLE/renderer/d3d/IndexDataManager.h" -#include "libANGLE/renderer/d3d/RendererD3D.h" -#include "libANGLE/renderer/d3d/d3d11/InputLayoutCache.h" -#include "libANGLE/renderer/d3d/d3d11/Query11.h" -#include "libANGLE/renderer/d3d/d3d11/RenderStateCache.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -namespace rx -{ - -struct RenderTargetDesc; -struct Renderer11DeviceCaps; - -class ShaderConstants11 : angle::NonCopyable -{ - public: - ShaderConstants11(); - ~ShaderConstants11(); - - void init(const gl::Caps &caps); - size_t getRequiredBufferSize(gl::SamplerType samplerType) const; - void markDirty(); - - void setComputeWorkGroups(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ); - void setMultiviewWriteToViewportIndex(GLfloat index); - void onViewportChange(const gl::Rectangle &glViewport, - const D3D11_VIEWPORT &dxViewport, - bool is9_3, - bool presentPathFast); - void onSamplerChange(gl::SamplerType samplerType, - unsigned int samplerIndex, - const gl::Texture &texture); - - gl::Error updateBuffer(ID3D11DeviceContext *deviceContext, - gl::SamplerType samplerType, - const ProgramD3D &programD3D, - const d3d11::Buffer &driverConstantBuffer); - - private: - struct Vertex - { - Vertex() - : depthRange{.0f}, - viewAdjust{.0f}, - viewCoords{.0f}, - viewScale{.0f}, - multiviewWriteToViewportIndex{.0f}, - padding{.0f} - { - } - - float depthRange[4]; - float viewAdjust[4]; - float viewCoords[4]; - float viewScale[2]; - // multiviewWriteToViewportIndex is used to select either the side-by-side or layered - // code-path in the GS. It's value, if set, is either 0.0f or 1.0f. The value is updated - // whenever a multi-view draw framebuffer is made active. - float multiviewWriteToViewportIndex; - - // Added here to manually pad the struct. - float padding; - }; - - struct Pixel - { - Pixel() - : depthRange{.0f}, - viewCoords{.0f}, - depthFront{.0f}, - viewScale{.0f}, - multiviewWriteToViewportIndex(0), - padding(0) - { - } - - float depthRange[4]; - float viewCoords[4]; - float depthFront[4]; - float viewScale[2]; - // multiviewWriteToViewportIndex is used to select either the side-by-side or layered - // code-path in the GS. It's value, if set, is either 0.0f or 1.0f. The value is updated - // whenever a multi-view draw framebuffer is made active. - float multiviewWriteToViewportIndex; - - // Added here to manually pad the struct. - float padding; - }; - - struct Compute - { - Compute() : numWorkGroups{0u}, padding(0u) {} - unsigned int numWorkGroups[3]; - unsigned int padding; // This just pads the struct to 16 bytes - }; - - struct SamplerMetadata - { - SamplerMetadata() : baseLevel(0), internalFormatBits(0), wrapModes(0), padding(0) {} - - int baseLevel; - int internalFormatBits; - int wrapModes; - int padding; // This just pads the struct to 16 bytes - }; - - static_assert(sizeof(SamplerMetadata) == 16u, - "Sampler metadata struct must be one 4-vec / 16 bytes."); - - // Return true if dirty. - bool updateSamplerMetadata(SamplerMetadata *data, const gl::Texture &texture); - - Vertex mVertex; - bool mVertexDirty; - Pixel mPixel; - bool mPixelDirty; - Compute mCompute; - bool mComputeDirty; - - std::vector<SamplerMetadata> mSamplerMetadataVS; - bool mSamplerMetadataVSDirty; - std::vector<SamplerMetadata> mSamplerMetadataPS; - bool mSamplerMetadataPSDirty; - std::vector<SamplerMetadata> mSamplerMetadataCS; - bool mSamplerMetadataCSDirty; -}; - -class DrawCallVertexParams final : angle::NonCopyable -{ - public: - // Use when in a drawArrays call. - DrawCallVertexParams(GLint firstVertex, GLsizei vertexCount, GLsizei instances); - - // Use when in a drawElements call. - DrawCallVertexParams(bool firstVertexDefinitelyZero, - const gl::HasIndexRange &hasIndexRange, - GLint baseVertex, - GLsizei instances); - - // It should be possible to also use an overload to handle the 'slow' indirect draw path. - // TODO(jmadill): Indirect draw slow path overload. - - GLint firstVertex() const; - GLsizei vertexCount() const; - GLsizei instances() const; - - private: - void ensureResolved() const; - - mutable const gl::HasIndexRange *mHasIndexRange; - mutable Optional<GLint> mFirstVertex; - mutable GLsizei mVertexCount; - GLsizei mInstances; - GLint mBaseVertex; -}; - -class StateManager11 final : angle::NonCopyable -{ - public: - StateManager11(Renderer11 *renderer); - ~StateManager11(); - - gl::Error initialize(const gl::Caps &caps, const gl::Extensions &extensions); - void deinitialize(); - - void syncState(const gl::Context *context, const gl::State::DirtyBits &dirtyBits); - - gl::Error updateStateForCompute(const gl::Context *context, - GLuint numGroupsX, - GLuint numGroupsY, - GLuint numGroupsZ); - - void updateStencilSizeIfChanged(bool depthStencilInitialized, unsigned int stencilSize); - - // These invalidations methods are called externally. - - // Called from TextureStorage11. - void invalidateBoundViews(); - - // Called from VertexArray11::updateVertexAttribStorage. - void invalidateCurrentValueAttrib(size_t attribIndex); - - // Checks are done on a framebuffer state change to trigger other state changes. - // The Context is allowed to be nullptr for these methods, when called in EGL init code. - void invalidateRenderTarget(); - - // Called by instanced point sprite emulation. - void invalidateVertexBuffer(); - - // Called by Framebuffer11::syncState for the default sized viewport. - void invalidateViewport(const gl::Context *context); - - // Called by TextureStorage11::markLevelDirty. - void invalidateSwizzles(); - - // Called by the Framebuffer11 and VertexArray11. - void invalidateShaders(); - - // Called by VertexArray11 to trigger attribute translation. - void invalidateVertexAttributeTranslation(); - - void setRenderTarget(ID3D11RenderTargetView *rtv, ID3D11DepthStencilView *dsv); - void setRenderTargets(ID3D11RenderTargetView **rtvs, UINT numRtvs, ID3D11DepthStencilView *dsv); - - void onBeginQuery(Query11 *query); - void onDeleteQueryObject(Query11 *query); - gl::Error onMakeCurrent(const gl::Context *context); - - void setInputLayout(const d3d11::InputLayout *inputLayout); - - // TODO(jmadill): Migrate to d3d11::Buffer. - bool queueVertexBufferChange(size_t bufferIndex, - ID3D11Buffer *buffer, - UINT stride, - UINT offset); - bool queueVertexOffsetChange(size_t bufferIndex, UINT offsetOnly); - void applyVertexBufferChanges(); - - void setSingleVertexBuffer(const d3d11::Buffer *buffer, UINT stride, UINT offset); - - gl::Error updateState(const gl::Context *context, GLenum drawMode); - - void setShaderResourceShared(gl::SamplerType shaderType, - UINT resourceSlot, - const d3d11::SharedSRV *srv); - void setShaderResource(gl::SamplerType shaderType, - UINT resourceSlot, - const d3d11::ShaderResourceView *srv); - void setPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY primitiveTopology); - - void setDrawShaders(const d3d11::VertexShader *vertexShader, - const d3d11::GeometryShader *geometryShader, - const d3d11::PixelShader *pixelShader); - void setVertexShader(const d3d11::VertexShader *shader); - void setGeometryShader(const d3d11::GeometryShader *shader); - void setPixelShader(const d3d11::PixelShader *shader); - void setComputeShader(const d3d11::ComputeShader *shader); - void setVertexConstantBuffer(unsigned int slot, const d3d11::Buffer *buffer); - void setPixelConstantBuffer(unsigned int slot, const d3d11::Buffer *buffer); - void setDepthStencilState(const d3d11::DepthStencilState *depthStencilState, UINT stencilRef); - void setSimpleBlendState(const d3d11::BlendState *blendState); - void setRasterizerState(const d3d11::RasterizerState *rasterizerState); - void setSimpleViewport(const gl::Extents &viewportExtents); - void setSimpleViewport(int width, int height); - void setSimplePixelTextureAndSampler(const d3d11::SharedSRV &srv, - const d3d11::SamplerState &samplerState); - void setSimpleScissorRect(const gl::Rectangle &glRect); - void setScissorRectD3D(const D3D11_RECT &d3dRect); - - // Not handled by an internal dirty bit because of the extra draw parameters. - gl::Error applyVertexBuffer(const gl::Context *context, - GLenum mode, - const DrawCallVertexParams &vertexParams, - bool isIndexedRendering); - - gl::Error applyIndexBuffer(const gl::Context *context, - const void *indices, - GLsizei count, - GLenum type, - const gl::HasIndexRange &lazyIndexRange, - bool usePrimitiveRestartWorkaround); - - void setIndexBuffer(ID3D11Buffer *buffer, DXGI_FORMAT indexFormat, unsigned int offset); - - gl::Error updateVertexOffsetsForPointSpritesEmulation(GLint startVertex, - GLsizei emulatedInstanceId); - - // TODO(jmadill): Should be private. - gl::Error applyComputeUniforms(ProgramD3D *programD3D); - - // Only used in testing. - InputLayoutCache *getInputLayoutCache() { return &mInputLayoutCache; } - - private: - template <typename SRVType> - void setShaderResourceInternal(gl::SamplerType shaderType, - UINT resourceSlot, - const SRVType *srv); - - bool unsetConflictingView(ID3D11View *view); - bool unsetConflictingSRVs(gl::SamplerType shaderType, - uintptr_t resource, - const gl::ImageIndex *index); - void unsetConflictingAttachmentResources(const gl::FramebufferAttachment *attachment, - ID3D11Resource *resource); - - gl::Error syncBlendState(const gl::Context *context, - const gl::Framebuffer *framebuffer, - const gl::BlendState &blendState, - const gl::ColorF &blendColor, - unsigned int sampleMask); - - gl::Error syncDepthStencilState(const gl::State &glState); - - gl::Error syncRasterizerState(const gl::Context *context, bool pointDrawMode); - - void syncScissorRectangle(const gl::Rectangle &scissor, bool enabled); - - void syncViewport(const gl::Context *context); - - void checkPresentPath(const gl::Context *context); - - gl::Error syncFramebuffer(const gl::Context *context, gl::Framebuffer *framebuffer); - gl::Error syncProgram(const gl::Context *context, GLenum drawMode); - - gl::Error syncTextures(const gl::Context *context); - gl::Error applyTextures(const gl::Context *context, gl::SamplerType shaderType); - - gl::Error setSamplerState(const gl::Context *context, - gl::SamplerType type, - int index, - gl::Texture *texture, - const gl::SamplerState &sampler); - gl::Error setTexture(const gl::Context *context, - gl::SamplerType type, - int index, - gl::Texture *texture); - - // Faster than calling setTexture a jillion times - gl::Error clearTextures(gl::SamplerType samplerType, size_t rangeStart, size_t rangeEnd); - void handleMultiviewDrawFramebufferChange(const gl::Context *context); - - gl::Error syncCurrentValueAttribs(const gl::State &glState); - - gl::Error generateSwizzle(const gl::Context *context, gl::Texture *texture); - gl::Error generateSwizzlesForShader(const gl::Context *context, gl::SamplerType type); - gl::Error generateSwizzles(const gl::Context *context); - - gl::Error applyDriverUniforms(const ProgramD3D &programD3D); - gl::Error applyUniforms(ProgramD3D *programD3D); - - gl::Error syncUniformBuffers(const gl::Context *context, ProgramD3D *programD3D); - gl::Error syncTransformFeedbackBuffers(const gl::Context *context); - - // These are currently only called internally. - void invalidateTexturesAndSamplers(); - void invalidateDriverUniforms(); - void invalidateProgramUniforms(); - void invalidateProgramUniformBuffers(); - void invalidateConstantBuffer(unsigned int slot); - - // Called by the Framebuffer11 directly. - void processFramebufferInvalidation(const gl::Context *context); - - bool syncIndexBuffer(ID3D11Buffer *buffer, DXGI_FORMAT indexFormat, unsigned int offset); - - enum DirtyBitType - { - DIRTY_BIT_RENDER_TARGET, - DIRTY_BIT_VIEWPORT_STATE, - DIRTY_BIT_SCISSOR_STATE, - DIRTY_BIT_RASTERIZER_STATE, - DIRTY_BIT_BLEND_STATE, - DIRTY_BIT_DEPTH_STENCIL_STATE, - DIRTY_BIT_TEXTURE_AND_SAMPLER_STATE, - DIRTY_BIT_PROGRAM_UNIFORMS, - DIRTY_BIT_DRIVER_UNIFORMS, - DIRTY_BIT_PROGRAM_UNIFORM_BUFFERS, - DIRTY_BIT_SHADERS, - DIRTY_BIT_CURRENT_VALUE_ATTRIBS, - DIRTY_BIT_INVALID, - DIRTY_BIT_MAX = DIRTY_BIT_INVALID, - }; - - using DirtyBits = angle::BitSet<DIRTY_BIT_MAX>; - - Renderer11 *mRenderer; - - // Internal dirty bits. - DirtyBits mInternalDirtyBits; - - // Blend State - gl::BlendState mCurBlendState; - gl::ColorF mCurBlendColor; - unsigned int mCurSampleMask; - - // Currently applied depth stencil state - gl::DepthStencilState mCurDepthStencilState; - int mCurStencilRef; - int mCurStencilBackRef; - unsigned int mCurStencilSize; - Optional<bool> mCurDisableDepth; - Optional<bool> mCurDisableStencil; - - // Currently applied rasterizer state - gl::RasterizerState mCurRasterState; - - // Currently applied scissor rectangle state - bool mCurScissorEnabled; - gl::Rectangle mCurScissorRect; - - // Currently applied viewport state - gl::Rectangle mCurViewport; - float mCurNear; - float mCurFar; - - // The viewport offsets are guaranteed to be updated whenever the gl::State::DirtyBits are - // resolved and can be applied to the viewport and scissor whenever the internal viewport and - // scissor bits are resolved. - std::vector<gl::Offset> mViewportOffsets; - - // Things needed in viewport state - ShaderConstants11 mShaderConstants; - - // Render target variables - gl::Extents mViewportBounds; - bool mRenderTargetIsDirty; - - // EGL_ANGLE_experimental_present_path variables - bool mCurPresentPathFastEnabled; - int mCurPresentPathFastColorBufferHeight; - - // Queries that are currently active in this state - std::set<Query11 *> mCurrentQueries; - - // Currently applied textures - struct SRVRecord - { - uintptr_t srv; - uintptr_t resource; - D3D11_SHADER_RESOURCE_VIEW_DESC desc; - }; - - // A cache of current SRVs that also tracks the highest 'used' (non-NULL) SRV - // We might want to investigate a more robust approach that is also fast when there's - // a large gap between used SRVs (e.g. if SRV 0 and 7 are non-NULL, this approach will - // waste time on SRVs 1-6.) - class SRVCache : angle::NonCopyable - { - public: - SRVCache(); - ~SRVCache(); - - void initialize(size_t size) { mCurrentSRVs.resize(size); } - - size_t size() const { return mCurrentSRVs.size(); } - size_t highestUsed() const { return mHighestUsedSRV; } - - const SRVRecord &operator[](size_t index) const { return mCurrentSRVs[index]; } - void clear(); - void update(size_t resourceIndex, ID3D11ShaderResourceView *srv); - - private: - std::vector<SRVRecord> mCurrentSRVs; - size_t mHighestUsedSRV; - }; - - SRVCache mCurVertexSRVs; - SRVCache mCurPixelSRVs; - - // A block of NULL pointers, cached so we don't re-allocate every draw call - std::vector<ID3D11ShaderResourceView *> mNullSRVs; - - // Current translations of "Current-Value" data - owned by Context, not VertexArray. - gl::AttributesMask mDirtyCurrentValueAttribs; - std::vector<TranslatedAttribute> mCurrentValueAttribs; - - // Current applied input layout. - ResourceSerial mCurrentInputLayout; - bool mInputLayoutIsDirty; - bool mVertexAttribsNeedTranslation; - - // Current applied vertex states. - // TODO(jmadill): Figure out how to use ResourceSerial here. - std::array<ID3D11Buffer *, gl::MAX_VERTEX_ATTRIBS> mCurrentVertexBuffers; - std::array<UINT, gl::MAX_VERTEX_ATTRIBS> mCurrentVertexStrides; - std::array<UINT, gl::MAX_VERTEX_ATTRIBS> mCurrentVertexOffsets; - gl::RangeUI mDirtyVertexBufferRange; - - // Currently applied primitive topology - D3D11_PRIMITIVE_TOPOLOGY mCurrentPrimitiveTopology; - - // Currently applied shaders - ResourceSerial mAppliedVertexShader; - ResourceSerial mAppliedGeometryShader; - ResourceSerial mAppliedPixelShader; - ResourceSerial mAppliedComputeShader; - - // Currently applied sampler states - std::vector<bool> mForceSetVertexSamplerStates; - std::vector<gl::SamplerState> mCurVertexSamplerStates; - - std::vector<bool> mForceSetPixelSamplerStates; - std::vector<gl::SamplerState> mCurPixelSamplerStates; - - std::vector<bool> mForceSetComputeSamplerStates; - std::vector<gl::SamplerState> mCurComputeSamplerStates; - - // Special dirty bit for swizzles. Since they use internal shaders, must be done in a pre-pass. - bool mDirtySwizzles; - - // Currently applied index buffer - ID3D11Buffer *mAppliedIB; - DXGI_FORMAT mAppliedIBFormat; - unsigned int mAppliedIBOffset; - bool mIndexBufferIsDirty; - - // Vertex, index and input layouts - VertexDataManager mVertexDataManager; - IndexDataManager mIndexDataManager; - InputLayoutCache mInputLayoutCache; - std::vector<const TranslatedAttribute *> mCurrentAttributes; - Optional<GLint> mLastFirstVertex; - - // ANGLE_multiview. - bool mIsMultiviewEnabled; - - // Driver Constants. - d3d11::Buffer mDriverConstantBufferVS; - d3d11::Buffer mDriverConstantBufferPS; - d3d11::Buffer mDriverConstantBufferCS; - - ResourceSerial mCurrentComputeConstantBuffer; - ResourceSerial mCurrentGeometryConstantBuffer; - - template <typename T> - using VertexConstantBufferArray = - std::array<T, gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS>; - - VertexConstantBufferArray<ResourceSerial> mCurrentConstantBufferVS; - VertexConstantBufferArray<GLintptr> mCurrentConstantBufferVSOffset; - VertexConstantBufferArray<GLsizeiptr> mCurrentConstantBufferVSSize; - - template <typename T> - using FragmentConstantBufferArray = - std::array<T, gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS>; - - FragmentConstantBufferArray<ResourceSerial> mCurrentConstantBufferPS; - FragmentConstantBufferArray<GLintptr> mCurrentConstantBufferPSOffset; - FragmentConstantBufferArray<GLsizeiptr> mCurrentConstantBufferPSSize; - - // Currently applied transform feedback buffers - Serial mAppliedTFSerial; - - Serial mEmptySerial; - - bool mIsTransformFeedbackCurrentlyActiveUnpaused; -}; - -} // namespace rx -#endif // LIBANGLE_RENDERER_D3D11_STATEMANAGER11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/StreamProducerNV12.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/StreamProducerNV12.cpp deleted file mode 100644 index 1981b5f7b2..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/StreamProducerNV12.cpp +++ /dev/null @@ -1,102 +0,0 @@ -// -// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// StreamProducerNV12.cpp: Implements the stream producer for NV12 textures - -#include "libANGLE/renderer/d3d/d3d11/StreamProducerNV12.h" - -#include "common/utilities.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -namespace rx -{ - -StreamProducerNV12::StreamProducerNV12(Renderer11 *renderer) - : mRenderer(renderer), mTexture(nullptr), mArraySlice(0), mTextureWidth(0), mTextureHeight(0) -{ -} - -StreamProducerNV12::~StreamProducerNV12() -{ - SafeRelease(mTexture); -} - -egl::Error StreamProducerNV12::validateD3DNV12Texture(void *pointer) const -{ - ID3D11Texture2D *textureD3D = static_cast<ID3D11Texture2D *>(pointer); - - // Check that the texture originated from our device - ID3D11Device *device; - textureD3D->GetDevice(&device); - if (device != mRenderer->getDevice()) - { - return egl::EglBadParameter() << "Texture not created on ANGLE D3D device"; - } - - // Get the description and validate it - D3D11_TEXTURE2D_DESC desc; - textureD3D->GetDesc(&desc); - if (desc.Format != DXGI_FORMAT_NV12) - { - return egl::EglBadParameter() << "Texture format not DXGI_FORMAT_NV12"; - } - if (desc.Width < 1 || desc.Height < 1) - { - return egl::EglBadParameter() << "Texture is of size 0"; - } - if ((desc.Width % 2) != 0 || (desc.Height % 2) != 0) - { - return egl::EglBadParameter() << "Texture dimensions are not even"; - } - return egl::NoError(); -} - -void StreamProducerNV12::postD3DNV12Texture(void *pointer, const egl::AttributeMap &attributes) -{ - ASSERT(pointer != nullptr); - ID3D11Texture2D *textureD3D = static_cast<ID3D11Texture2D *>(pointer); - - // Check that the texture originated from our device - ID3D11Device *device; - textureD3D->GetDevice(&device); - - // Get the description - D3D11_TEXTURE2D_DESC desc; - textureD3D->GetDesc(&desc); - - // Release the previous texture if there is one - SafeRelease(mTexture); - - mTexture = textureD3D; - mTexture->AddRef(); - mTextureWidth = desc.Width; - mTextureHeight = desc.Height; - mArraySlice = static_cast<UINT>(attributes.get(EGL_D3D_TEXTURE_SUBRESOURCE_ID_ANGLE, 0)); -} - -egl::Stream::GLTextureDescription StreamProducerNV12::getGLFrameDescription(int planeIndex) -{ - // The UV plane of NV12 textures has half the width/height of the Y plane - egl::Stream::GLTextureDescription desc; - desc.width = (planeIndex == 0) ? mTextureWidth : (mTextureWidth / 2); - desc.height = (planeIndex == 0) ? mTextureHeight : (mTextureHeight / 2); - desc.internalFormat = (planeIndex == 0) ? GL_R8 : GL_RG8; - desc.mipLevels = 0; - return desc; -} - -ID3D11Texture2D *StreamProducerNV12::getD3DTexture() -{ - return mTexture; -} - -UINT StreamProducerNV12::getArraySlice() -{ - return mArraySlice; -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/StreamProducerNV12.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/StreamProducerNV12.h deleted file mode 100644 index 304c9dfe53..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/StreamProducerNV12.h +++ /dev/null @@ -1,44 +0,0 @@ -// -// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// StreamProducerNV12.h: Interface for a NV12 texture stream producer - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_STREAM11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_STREAM11_H_ - -#include "libANGLE/renderer/StreamProducerImpl.h" - -namespace rx -{ -class Renderer11; - -class StreamProducerNV12 : public StreamProducerImpl -{ - public: - StreamProducerNV12(Renderer11 *renderer); - ~StreamProducerNV12() override; - - egl::Error validateD3DNV12Texture(void *pointer) const override; - void postD3DNV12Texture(void *pointer, const egl::AttributeMap &attributes) override; - egl::Stream::GLTextureDescription getGLFrameDescription(int planeIndex) override; - - // Gets a pointer to the internal D3D texture - ID3D11Texture2D *getD3DTexture(); - - // Gets the slice index for the D3D texture that the frame is in - UINT getArraySlice(); - - private: - Renderer11 *mRenderer; - - ID3D11Texture2D *mTexture; - UINT mArraySlice; - UINT mTextureWidth; - UINT mTextureHeight; -}; -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_STREAM11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/SwapChain11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/SwapChain11.cpp deleted file mode 100644 index 9ece77ecbc..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/SwapChain11.cpp +++ /dev/null @@ -1,1075 +0,0 @@ -// -// Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// SwapChain11.cpp: Implements a back-end specific class for the D3D11 swap chain. - -#include "libANGLE/renderer/d3d/d3d11/SwapChain11.h" - -#include <EGL/eglext.h> - -#include "libANGLE/features.h" -#include "libANGLE/renderer/d3d/d3d11/NativeWindow11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h" -#include "third_party/trace_event/trace_event.h" - -// Precompiled shaders -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthrough2d11vs.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgba2d11ps.h" -#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgba2dms11ps.h" - -#ifdef ANGLE_ENABLE_KEYEDMUTEX -#define ANGLE_RESOURCE_SHARE_TYPE D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX -#else -#define ANGLE_RESOURCE_SHARE_TYPE D3D11_RESOURCE_MISC_SHARED -#endif - -namespace rx -{ - -namespace -{ -// To avoid overflow in QPC to Microseconds calculations, since we multiply -// by kMicrosecondsPerSecond, then the QPC value should not exceed -// (2^63 - 1) / 1E6. If it exceeds that threshold, we divide then multiply. -static constexpr int64_t kQPCOverflowThreshold = 0x8637BD05AF7; -static constexpr int64_t kMicrosecondsPerSecond = 1000000; - -bool NeedsOffscreenTexture(Renderer11 *renderer, NativeWindow11 *nativeWindow, EGLint orientation) -{ - // We don't need an offscreen texture if either orientation = INVERT_Y, - // or present path fast is enabled and we're not rendering onto an offscreen surface. - return orientation != EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE && - !(renderer->presentPathFastEnabled() && nativeWindow->getNativeWindow()); -} -} // anonymous namespace - -SwapChain11::SwapChain11(Renderer11 *renderer, - NativeWindow11 *nativeWindow, - HANDLE shareHandle, - IUnknown *d3dTexture, - GLenum backBufferFormat, - GLenum depthBufferFormat, - EGLint orientation, - EGLint samples) - : SwapChainD3D(shareHandle, d3dTexture, backBufferFormat, depthBufferFormat), - mRenderer(renderer), - mWidth(-1), - mHeight(-1), - mOrientation(orientation), - mAppCreatedShareHandle(mShareHandle != nullptr), - mSwapInterval(0), - mPassThroughResourcesInit(false), - mNativeWindow(nativeWindow), - mFirstSwap(true), - mSwapChain(nullptr), - mSwapChain1(nullptr), - mKeyedMutex(nullptr), - mBackBufferTexture(), - mBackBufferRTView(), - mBackBufferSRView(), - mNeedsOffscreenTexture(NeedsOffscreenTexture(renderer, nativeWindow, orientation)), - mOffscreenTexture(), - mOffscreenRTView(), - mOffscreenSRView(), - mNeedsOffscreenTextureCopy(false), - mOffscreenTextureCopyForSRV(), - mDepthStencilTexture(), - mDepthStencilDSView(), - mDepthStencilSRView(), - mQuadVB(), - mPassThroughSampler(), - mPassThroughIL(), - mPassThroughVS(), - mPassThroughPS(), - mPassThroughRS(), - mColorRenderTarget(this, renderer, false), - mDepthStencilRenderTarget(this, renderer, true), - mEGLSamples(samples) -{ - // Sanity check that if present path fast is active then we're using the default orientation - ASSERT(!mRenderer->presentPathFastEnabled() || orientation == 0); - - // Get the performance counter - LARGE_INTEGER counterFreqency = {}; - BOOL success = QueryPerformanceFrequency(&counterFreqency); - ASSERT(success); - - mQPCFrequency = counterFreqency.QuadPart; -} - -SwapChain11::~SwapChain11() -{ - release(); -} - -void SwapChain11::release() -{ - // TODO(jmadill): Should probably signal that the RenderTarget is dirty. - - SafeRelease(mSwapChain1); - SafeRelease(mSwapChain); - SafeRelease(mKeyedMutex); - mBackBufferTexture.reset(); - mBackBufferRTView.reset(); - mBackBufferSRView.reset(); - mOffscreenTexture.reset(); - mOffscreenRTView.reset(); - mOffscreenSRView.reset(); - mDepthStencilTexture.reset(); - mDepthStencilDSView.reset(); - mDepthStencilSRView.reset(); - mQuadVB.reset(); - mPassThroughSampler.reset(); - mPassThroughIL.reset(); - mPassThroughVS.reset(); - mPassThroughPS.reset(); - mPassThroughRS.reset(); - - if (!mAppCreatedShareHandle) - { - mShareHandle = nullptr; - } -} - -void SwapChain11::releaseOffscreenColorBuffer() -{ - mOffscreenTexture.reset(); - mOffscreenRTView.reset(); - mOffscreenSRView.reset(); - mNeedsOffscreenTextureCopy = false; - mOffscreenTextureCopyForSRV.reset(); -} - -void SwapChain11::releaseOffscreenDepthBuffer() -{ - mDepthStencilTexture.reset(); - mDepthStencilDSView.reset(); - mDepthStencilSRView.reset(); -} - -EGLint SwapChain11::resetOffscreenBuffers(const gl::Context *context, - int backbufferWidth, - int backbufferHeight) -{ - if (mNeedsOffscreenTexture) - { - EGLint result = resetOffscreenColorBuffer(context, backbufferWidth, backbufferHeight); - if (result != EGL_SUCCESS) - { - return result; - } - } - - EGLint result = resetOffscreenDepthBuffer(backbufferWidth, backbufferHeight); - if (result != EGL_SUCCESS) - { - return result; - } - - mWidth = backbufferWidth; - mHeight = backbufferHeight; - - return EGL_SUCCESS; -} - -EGLint SwapChain11::resetOffscreenColorBuffer(const gl::Context *context, - int backbufferWidth, - int backbufferHeight) -{ - ASSERT(mNeedsOffscreenTexture); - - TRACE_EVENT0("gpu.angle", "SwapChain11::resetOffscreenTexture"); - ID3D11Device *device = mRenderer->getDevice(); - - ASSERT(device != nullptr); - - // D3D11 does not allow zero size textures - ASSERT(backbufferWidth >= 1); - ASSERT(backbufferHeight >= 1); - - // Preserve the render target content - TextureHelper11 previousOffscreenTexture(std::move(mOffscreenTexture)); - const int previousWidth = mWidth; - const int previousHeight = mHeight; - - releaseOffscreenColorBuffer(); - - const d3d11::Format &backbufferFormatInfo = - d3d11::Format::Get(mOffscreenRenderTargetFormat, mRenderer->getRenderer11DeviceCaps()); - D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0}; - - // If the app passed in a share handle or D3D texture, open the resource - // See EGL_ANGLE_d3d_share_handle_client_buffer and EGL_ANGLE_d3d_texture_client_buffer - if (mAppCreatedShareHandle || mD3DTexture != nullptr) - { - if (mAppCreatedShareHandle) - { - ID3D11Resource *tempResource11; - HRESULT result = device->OpenSharedResource(mShareHandle, __uuidof(ID3D11Resource), - (void **)&tempResource11); - ASSERT(SUCCEEDED(result)); - - mOffscreenTexture.set(d3d11::DynamicCastComObject<ID3D11Texture2D>(tempResource11), - backbufferFormatInfo); - SafeRelease(tempResource11); - } - else if (mD3DTexture != nullptr) - { - mOffscreenTexture.set(d3d11::DynamicCastComObject<ID3D11Texture2D>(mD3DTexture), - backbufferFormatInfo); - } - else - { - UNREACHABLE(); - } - ASSERT(mOffscreenTexture.valid()); - mOffscreenTexture.getDesc(&offscreenTextureDesc); - - // Fail if the offscreen texture is not renderable. - if ((offscreenTextureDesc.BindFlags & D3D11_BIND_RENDER_TARGET) == 0) - { - ERR() << "Could not use provided offscreen texture, texture not renderable."; - release(); - return EGL_BAD_SURFACE; - } - } - else - { - const bool useSharedResource = - !mNativeWindow->getNativeWindow() && mRenderer->getShareHandleSupport(); - - offscreenTextureDesc.Width = backbufferWidth; - offscreenTextureDesc.Height = backbufferHeight; - offscreenTextureDesc.Format = backbufferFormatInfo.texFormat; - offscreenTextureDesc.MipLevels = 1; - offscreenTextureDesc.ArraySize = 1; - offscreenTextureDesc.SampleDesc.Count = getD3DSamples(); - offscreenTextureDesc.SampleDesc.Quality = 0; - offscreenTextureDesc.Usage = D3D11_USAGE_DEFAULT; - offscreenTextureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; - offscreenTextureDesc.CPUAccessFlags = 0; - offscreenTextureDesc.MiscFlags = useSharedResource ? ANGLE_RESOURCE_SHARE_TYPE : 0; - - gl::Error err = mRenderer->allocateTexture(offscreenTextureDesc, backbufferFormatInfo, - &mOffscreenTexture); - if (err.isError()) - { - ERR() << "Could not create offscreen texture, " << err; - release(); - return EGL_BAD_ALLOC; - } - - mOffscreenTexture.setDebugName("Offscreen back buffer texture"); - - // EGL_ANGLE_surface_d3d_texture_2d_share_handle requires that we store a share handle for the client - if (useSharedResource) - { - IDXGIResource *offscreenTextureResource = nullptr; - HRESULT result = mOffscreenTexture.get()->QueryInterface( - __uuidof(IDXGIResource), (void **)&offscreenTextureResource); - - // Fall back to no share handle on failure - if (FAILED(result)) - { - ERR() << "Could not query offscreen texture resource, " << gl::FmtHR(result); - } - else - { - result = offscreenTextureResource->GetSharedHandle(&mShareHandle); - SafeRelease(offscreenTextureResource); - - if (FAILED(result)) - { - mShareHandle = nullptr; - ERR() << "Could not get offscreen texture shared handle, " << gl::FmtHR(result); - } - } - } - } - - // This may return null if the original texture was created without a keyed mutex. - mKeyedMutex = d3d11::DynamicCastComObject<IDXGIKeyedMutex>(mOffscreenTexture.get()); - - D3D11_RENDER_TARGET_VIEW_DESC offscreenRTVDesc; - offscreenRTVDesc.Format = backbufferFormatInfo.rtvFormat; - offscreenRTVDesc.ViewDimension = - (mEGLSamples <= 1) ? D3D11_RTV_DIMENSION_TEXTURE2D : D3D11_RTV_DIMENSION_TEXTURE2DMS; - offscreenRTVDesc.Texture2D.MipSlice = 0; - - gl::Error err = - mRenderer->allocateResource(offscreenRTVDesc, mOffscreenTexture.get(), &mOffscreenRTView); - ASSERT(!err.isError()); - mOffscreenRTView.setDebugName("Offscreen back buffer render target"); - - D3D11_SHADER_RESOURCE_VIEW_DESC offscreenSRVDesc; - offscreenSRVDesc.Format = backbufferFormatInfo.srvFormat; - offscreenSRVDesc.ViewDimension = - (mEGLSamples <= 1) ? D3D11_SRV_DIMENSION_TEXTURE2D : D3D11_SRV_DIMENSION_TEXTURE2DMS; - offscreenSRVDesc.Texture2D.MostDetailedMip = 0; - offscreenSRVDesc.Texture2D.MipLevels = static_cast<UINT>(-1); - - if (offscreenTextureDesc.BindFlags & D3D11_BIND_SHADER_RESOURCE) - { - err = mRenderer->allocateResource(offscreenSRVDesc, mOffscreenTexture.get(), - &mOffscreenSRView); - ASSERT(!err.isError()); - mOffscreenSRView.setDebugName("Offscreen back buffer shader resource"); - } - else - { - // Special case for external textures that cannot support sampling. Since internally we - // assume our SwapChain is always readable, we make a copy texture that is compatible. - mNeedsOffscreenTextureCopy = true; - } - - if (previousOffscreenTexture.valid()) - { - D3D11_BOX sourceBox = {0}; - sourceBox.left = 0; - sourceBox.right = std::min(previousWidth, backbufferWidth); - sourceBox.top = std::max(previousHeight - backbufferHeight, 0); - sourceBox.bottom = previousHeight; - sourceBox.front = 0; - sourceBox.back = 1; - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - const int yoffset = std::max(backbufferHeight - previousHeight, 0); - deviceContext->CopySubresourceRegion(mOffscreenTexture.get(), 0, 0, yoffset, 0, - previousOffscreenTexture.get(), 0, &sourceBox); - - if (mSwapChain) - { - swapRect(context, 0, 0, backbufferWidth, backbufferHeight); - } - } - - return EGL_SUCCESS; -} - -EGLint SwapChain11::resetOffscreenDepthBuffer(int backbufferWidth, int backbufferHeight) -{ - releaseOffscreenDepthBuffer(); - - if (mDepthBufferFormat != GL_NONE) - { - const d3d11::Format &depthBufferFormatInfo = - d3d11::Format::Get(mDepthBufferFormat, mRenderer->getRenderer11DeviceCaps()); - - D3D11_TEXTURE2D_DESC depthStencilTextureDesc; - depthStencilTextureDesc.Width = backbufferWidth; - depthStencilTextureDesc.Height = backbufferHeight; - depthStencilTextureDesc.Format = depthBufferFormatInfo.texFormat; - depthStencilTextureDesc.MipLevels = 1; - depthStencilTextureDesc.ArraySize = 1; - depthStencilTextureDesc.SampleDesc.Count = getD3DSamples(); - depthStencilTextureDesc.Usage = D3D11_USAGE_DEFAULT; - depthStencilTextureDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; - - // If there is a multisampled offscreen color texture, the offscreen depth-stencil texture - // must also have the same quality value. - if (mOffscreenTexture.valid() && getD3DSamples() > 1) - { - D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0}; - mOffscreenTexture.getDesc(&offscreenTextureDesc); - depthStencilTextureDesc.SampleDesc.Quality = offscreenTextureDesc.SampleDesc.Quality; - } - else - { - depthStencilTextureDesc.SampleDesc.Quality = 0; - } - - // Only create an SRV if it is supported - bool depthStencilSRV = - depthBufferFormatInfo.srvFormat != DXGI_FORMAT_UNKNOWN && - (mRenderer->getRenderer11DeviceCaps().supportsMultisampledDepthStencilSRVs || - depthStencilTextureDesc.SampleDesc.Count <= 1); - if (depthStencilSRV) - { - depthStencilTextureDesc.BindFlags |= D3D11_BIND_SHADER_RESOURCE; - } - - depthStencilTextureDesc.CPUAccessFlags = 0; - depthStencilTextureDesc.MiscFlags = 0; - - gl::Error err = mRenderer->allocateTexture(depthStencilTextureDesc, depthBufferFormatInfo, - &mDepthStencilTexture); - if (err.isError()) - { - ERR() << "Could not create depthstencil surface for new swap chain, " << err; - release(); - return EGL_BAD_ALLOC; - } - mDepthStencilTexture.setDebugName("Offscreen depth stencil texture"); - - D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilDesc; - depthStencilDesc.Format = depthBufferFormatInfo.dsvFormat; - depthStencilDesc.ViewDimension = - (mEGLSamples <= 1) ? D3D11_DSV_DIMENSION_TEXTURE2D : D3D11_DSV_DIMENSION_TEXTURE2DMS; - depthStencilDesc.Flags = 0; - depthStencilDesc.Texture2D.MipSlice = 0; - - err = mRenderer->allocateResource(depthStencilDesc, mDepthStencilTexture.get(), - &mDepthStencilDSView); - ASSERT(!err.isError()); - mDepthStencilDSView.setDebugName("Offscreen depth stencil view"); - - if (depthStencilSRV) - { - D3D11_SHADER_RESOURCE_VIEW_DESC depthStencilSRVDesc; - depthStencilSRVDesc.Format = depthBufferFormatInfo.srvFormat; - depthStencilSRVDesc.ViewDimension = (mEGLSamples <= 1) - ? D3D11_SRV_DIMENSION_TEXTURE2D - : D3D11_SRV_DIMENSION_TEXTURE2DMS; - depthStencilSRVDesc.Texture2D.MostDetailedMip = 0; - depthStencilSRVDesc.Texture2D.MipLevels = static_cast<UINT>(-1); - - err = mRenderer->allocateResource(depthStencilSRVDesc, mDepthStencilTexture.get(), - &mDepthStencilSRView); - ASSERT(!err.isError()); - mDepthStencilSRView.setDebugName("Offscreen depth stencil shader resource"); - } - } - - return EGL_SUCCESS; -} - -EGLint SwapChain11::resize(const gl::Context *context, - EGLint backbufferWidth, - EGLint backbufferHeight) -{ - TRACE_EVENT0("gpu.angle", "SwapChain11::resize"); - ID3D11Device *device = mRenderer->getDevice(); - - if (device == nullptr) - { - return EGL_BAD_ACCESS; - } - - // EGL allows creating a surface with 0x0 dimension, however, DXGI does not like 0x0 swapchains - if (backbufferWidth < 1 || backbufferHeight < 1) - { - return EGL_SUCCESS; - } - - // Don't resize unnecessarily - if (mWidth == backbufferWidth && mHeight == backbufferHeight) - { - return EGL_SUCCESS; - } - - // Can only call resize if we have already created our swap buffer and resources - ASSERT(mSwapChain && mBackBufferTexture.valid() && mBackBufferRTView.valid() && - mBackBufferSRView.valid()); - - mBackBufferTexture.reset(); - mBackBufferRTView.reset(); - mBackBufferSRView.reset(); - - // Resize swap chain - DXGI_SWAP_CHAIN_DESC desc; - HRESULT result = mSwapChain->GetDesc(&desc); - if (FAILED(result)) - { - ERR() << "Error reading swap chain description, " << gl::FmtHR(result); - release(); - return EGL_BAD_ALLOC; - } - - result = mSwapChain->ResizeBuffers(desc.BufferCount, backbufferWidth, backbufferHeight, getSwapChainNativeFormat(), 0); - - if (FAILED(result)) - { - ERR() << "Error resizing swap chain buffers, " << gl::FmtHR(result); - release(); - - if (d3d11::isDeviceLostError(result)) - { - return EGL_CONTEXT_LOST; - } - else - { - return EGL_BAD_ALLOC; - } - } - - ID3D11Texture2D *backbufferTexture = nullptr; - result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), - reinterpret_cast<void **>(&backbufferTexture)); - ASSERT(SUCCEEDED(result)); - if (SUCCEEDED(result)) - { -#ifndef ANGLE_ENABLE_WINDOWS_STORE - if (mNativeWindow->getNativeWindow()) - InvalidateRect(mNativeWindow->getNativeWindow(), nullptr, FALSE); -#endif - const auto &format = - d3d11::Format::Get(mOffscreenRenderTargetFormat, mRenderer->getRenderer11DeviceCaps()); - mBackBufferTexture.set(backbufferTexture, format); - mBackBufferTexture.setDebugName("Back buffer texture"); - - gl::Error err = - mRenderer->allocateResourceNoDesc(mBackBufferTexture.get(), &mBackBufferRTView); - ASSERT(!err.isError()); - mBackBufferRTView.setDebugName("Back buffer render target"); - - err = mRenderer->allocateResourceNoDesc(mBackBufferTexture.get(), &mBackBufferSRView); - ASSERT(!err.isError()); - mBackBufferSRView.setDebugName("Back buffer shader resource"); - } - - mFirstSwap = true; - - return resetOffscreenBuffers(context, backbufferWidth, backbufferHeight); -} - -DXGI_FORMAT SwapChain11::getSwapChainNativeFormat() const -{ - // Return a render target format for offscreen rendering is supported by IDXGISwapChain. - // MSDN https://msdn.microsoft.com/en-us/library/windows/desktop/bb173064(v=vs.85).aspx - switch (mOffscreenRenderTargetFormat) - { - case GL_RGBA8: - case GL_RGBA4: - case GL_RGB5_A1: - case GL_RGB8: - case GL_RGB565: - return DXGI_FORMAT_R8G8B8A8_UNORM; - - case GL_BGRA8_EXT: - return DXGI_FORMAT_B8G8R8A8_UNORM; - - case GL_RGB10_A2: - return DXGI_FORMAT_R10G10B10A2_UNORM; - - case GL_RGBA16F: - return DXGI_FORMAT_R16G16B16A16_FLOAT; - - default: - UNREACHABLE(); - return DXGI_FORMAT_UNKNOWN; - } -} - -EGLint SwapChain11::reset(const gl::Context *context, - EGLint backbufferWidth, - EGLint backbufferHeight, - EGLint swapInterval) -{ - mSwapInterval = static_cast<unsigned int>(swapInterval); - if (mSwapInterval > 4) - { - // IDXGISwapChain::Present documentation states that valid sync intervals are in the [0,4] - // range - return EGL_BAD_PARAMETER; - } - - // If the swap chain already exists, just resize - if (mSwapChain != nullptr) - { - return resize(context, backbufferWidth, backbufferHeight); - } - - TRACE_EVENT0("gpu.angle", "SwapChain11::reset"); - ID3D11Device *device = mRenderer->getDevice(); - - if (device == nullptr) - { - return EGL_BAD_ACCESS; - } - - // Release specific resources to free up memory for the new render target, while the - // old render target still exists for the purpose of preserving its contents. - SafeRelease(mSwapChain1); - SafeRelease(mSwapChain); - mBackBufferTexture.reset(); - mBackBufferRTView.reset(); - - // EGL allows creating a surface with 0x0 dimension, however, DXGI does not like 0x0 swapchains - if (backbufferWidth < 1 || backbufferHeight < 1) - { - releaseOffscreenColorBuffer(); - return EGL_SUCCESS; - } - - if (mNativeWindow->getNativeWindow()) - { - HRESULT result = mNativeWindow->createSwapChain( - device, mRenderer->getDxgiFactory(), getSwapChainNativeFormat(), backbufferWidth, - backbufferHeight, getD3DSamples(), &mSwapChain); - - if (FAILED(result)) - { - ERR() << "Could not create additional swap chains or offscreen surfaces, " - << gl::FmtHR(result); - release(); - - if (d3d11::isDeviceLostError(result)) - { - return EGL_CONTEXT_LOST; - } - else - { - return EGL_BAD_ALLOC; - } - } - - if (mRenderer->getRenderer11DeviceCaps().supportsDXGI1_2) - { - mSwapChain1 = d3d11::DynamicCastComObject<IDXGISwapChain1>(mSwapChain); - } - - ID3D11Texture2D *backbufferTex = nullptr; - result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), - reinterpret_cast<LPVOID *>(&backbufferTex)); - ASSERT(SUCCEEDED(result)); - const auto &format = - d3d11::Format::Get(mOffscreenRenderTargetFormat, mRenderer->getRenderer11DeviceCaps()); - mBackBufferTexture.set(backbufferTex, format); - mBackBufferTexture.setDebugName("Back buffer texture"); - - gl::Error err = - mRenderer->allocateResourceNoDesc(mBackBufferTexture.get(), &mBackBufferRTView); - ASSERT(!err.isError()); - mBackBufferRTView.setDebugName("Back buffer render target"); - - err = mRenderer->allocateResourceNoDesc(mBackBufferTexture.get(), &mBackBufferSRView); - ASSERT(!err.isError()); - mBackBufferSRView.setDebugName("Back buffer shader resource view"); - } - - mFirstSwap = true; - - return resetOffscreenBuffers(context, backbufferWidth, backbufferHeight); -} - -void SwapChain11::initPassThroughResources() -{ - if (mPassThroughResourcesInit) - { - return; - } - - TRACE_EVENT0("gpu.angle", "SwapChain11::initPassThroughResources"); - ID3D11Device *device = mRenderer->getDevice(); - - ASSERT(device != nullptr); - - // Make sure our resources are all not allocated, when we create - ASSERT(!mQuadVB.valid() && !mPassThroughSampler.valid()); - ASSERT(!mPassThroughIL.valid() && !mPassThroughVS.valid() && !mPassThroughPS.valid()); - - D3D11_BUFFER_DESC vbDesc; - vbDesc.ByteWidth = sizeof(d3d11::PositionTexCoordVertex) * 4; - vbDesc.Usage = D3D11_USAGE_DYNAMIC; - vbDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - vbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - vbDesc.MiscFlags = 0; - vbDesc.StructureByteStride = 0; - - gl::Error err = mRenderer->allocateResource(vbDesc, &mQuadVB); - ASSERT(!err.isError()); - mQuadVB.setDebugName("Swap chain quad vertex buffer"); - - D3D11_SAMPLER_DESC samplerDesc; - samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; - samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; - samplerDesc.MipLODBias = 0.0f; - samplerDesc.MaxAnisotropy = 0; - samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; - samplerDesc.BorderColor[0] = 0.0f; - samplerDesc.BorderColor[1] = 0.0f; - samplerDesc.BorderColor[2] = 0.0f; - samplerDesc.BorderColor[3] = 0.0f; - samplerDesc.MinLOD = 0; - samplerDesc.MaxLOD = D3D11_FLOAT32_MAX; - - err = mRenderer->allocateResource(samplerDesc, &mPassThroughSampler); - ASSERT(!err.isError()); - mPassThroughSampler.setDebugName("Swap chain pass through sampler"); - - D3D11_INPUT_ELEMENT_DESC quadLayout[] = - { - { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - }; - - InputElementArray quadElements(quadLayout); - ShaderData vertexShaderData(g_VS_Passthrough2D); - - err = mRenderer->allocateResource(quadElements, &vertexShaderData, &mPassThroughIL); - ASSERT(!err.isError()); - mPassThroughIL.setDebugName("Swap chain pass through layout"); - - err = mRenderer->allocateResource(vertexShaderData, &mPassThroughVS); - ASSERT(!err.isError()); - mPassThroughVS.setDebugName("Swap chain pass through vertex shader"); - - if (mEGLSamples <= 1) - { - ShaderData pixelShaderData(g_PS_PassthroughRGBA2D); - err = mRenderer->allocateResource(pixelShaderData, &mPassThroughPS); - } - else - { - ShaderData pixelShaderData(g_PS_PassthroughRGBA2DMS); - err = mRenderer->allocateResource(pixelShaderData, &mPassThroughPS); - } - - ASSERT(!err.isError()); - mPassThroughPS.setDebugName("Swap chain pass through pixel shader"); - - // Use the default rasterizer state but without culling - D3D11_RASTERIZER_DESC rasterizerDesc; - rasterizerDesc.FillMode = D3D11_FILL_SOLID; - rasterizerDesc.CullMode = D3D11_CULL_NONE; - rasterizerDesc.FrontCounterClockwise = FALSE; - rasterizerDesc.DepthBias = 0; - rasterizerDesc.SlopeScaledDepthBias = 0.0f; - rasterizerDesc.DepthBiasClamp = 0.0f; - rasterizerDesc.DepthClipEnable = TRUE; - rasterizerDesc.ScissorEnable = FALSE; - rasterizerDesc.MultisampleEnable = FALSE; - rasterizerDesc.AntialiasedLineEnable = FALSE; - - err = mRenderer->allocateResource(rasterizerDesc, &mPassThroughRS); - ASSERT(!err.isError()); - mPassThroughRS.setDebugName("Swap chain pass through rasterizer state"); - - mPassThroughResourcesInit = true; -} - -// parameters should be validated/clamped by caller -EGLint SwapChain11::swapRect(const gl::Context *context, - EGLint x, - EGLint y, - EGLint width, - EGLint height) -{ - if (mNeedsOffscreenTexture) - { - EGLint result = copyOffscreenToBackbuffer(context, x, y, width, height); - if (result != EGL_SUCCESS) - { - return result; - } - } - - EGLint result = present(context, x, y, width, height); - if (result != EGL_SUCCESS) - { - return result; - } - - mRenderer->onSwap(); - - return EGL_SUCCESS; -} - -EGLint SwapChain11::copyOffscreenToBackbuffer(const gl::Context *context, - EGLint x, - EGLint y, - EGLint width, - EGLint height) -{ - if (!mSwapChain) - { - return EGL_SUCCESS; - } - - initPassThroughResources(); - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - // Set vertices - D3D11_MAPPED_SUBRESOURCE mappedResource; - HRESULT result = - deviceContext->Map(mQuadVB.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - if (FAILED(result)) - { - return EGL_BAD_ACCESS; - } - - d3d11::PositionTexCoordVertex *vertices = static_cast<d3d11::PositionTexCoordVertex*>(mappedResource.pData); - - // Create a quad in homogeneous coordinates - float x1 = (x / float(width)) * 2.0f - 1.0f; - float y1 = (y / float(height)) * 2.0f - 1.0f; - float x2 = ((x + width) / float(width)) * 2.0f - 1.0f; - float y2 = ((y + height) / float(height)) * 2.0f - 1.0f; - - float u1 = x / float(width); - float v1 = y / float(height); - float u2 = (x + width) / float(width); - float v2 = (y + height) / float(height); - // Invert the quad vertices depending on the surface orientation. - if ((mOrientation & EGL_SURFACE_ORIENTATION_INVERT_X_ANGLE) != 0) - { - std::swap(x1, x2); - } - if ((mOrientation & EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE) != 0) - { - std::swap(y1, y2); - } - - d3d11::SetPositionTexCoordVertex(&vertices[0], x1, y1, u1, v1); - d3d11::SetPositionTexCoordVertex(&vertices[1], x1, y2, u1, v2); - d3d11::SetPositionTexCoordVertex(&vertices[2], x2, y1, u2, v1); - d3d11::SetPositionTexCoordVertex(&vertices[3], x2, y2, u2, v2); - - deviceContext->Unmap(mQuadVB.get(), 0); - - StateManager11 *stateManager = mRenderer->getStateManager(); - - constexpr UINT stride = sizeof(d3d11::PositionTexCoordVertex); - stateManager->setSingleVertexBuffer(&mQuadVB, stride, 0); - - // Apply state - stateManager->setDepthStencilState(nullptr, 0xFFFFFFFF); - stateManager->setSimpleBlendState(nullptr); - stateManager->setRasterizerState(&mPassThroughRS); - - // Apply shaders - stateManager->setInputLayout(&mPassThroughIL); - stateManager->setPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); - stateManager->setDrawShaders(&mPassThroughVS, nullptr, &mPassThroughPS); - - // Apply render targets. Use the proxy context in display. - stateManager->setRenderTarget(mBackBufferRTView.get(), nullptr); - - // Set the viewport - stateManager->setSimpleViewport(width, height); - - // Apply textures - stateManager->setSimplePixelTextureAndSampler(mOffscreenSRView, mPassThroughSampler); - - // Draw - deviceContext->Draw(4, 0); - - return EGL_SUCCESS; -} - -EGLint SwapChain11::present(const gl::Context *context, - EGLint x, - EGLint y, - EGLint width, - EGLint height) -{ - if (!mSwapChain) - { - return EGL_SUCCESS; - } - - UINT swapInterval = mSwapInterval; -#if ANGLE_VSYNC == ANGLE_DISABLED - swapInterval = 0; -#endif - - HRESULT result = S_OK; - - // Use IDXGISwapChain1::Present1 with a dirty rect if DXGI 1.2 is available. - // Dirty rect present is not supported with a multisampled swapchain. - if (mSwapChain1 != nullptr && mEGLSamples <= 1) - { - if (mFirstSwap) - { - // Can't swap with a dirty rect if this swap chain has never swapped before - DXGI_PRESENT_PARAMETERS params = {0, nullptr, nullptr, nullptr}; - result = mSwapChain1->Present1(swapInterval, 0, ¶ms); - } - else - { - RECT rect = {static_cast<LONG>(x), static_cast<LONG>(mHeight - y - height), - static_cast<LONG>(x + width), static_cast<LONG>(mHeight - y)}; - DXGI_PRESENT_PARAMETERS params = {1, &rect, nullptr, nullptr}; - result = mSwapChain1->Present1(swapInterval, 0, ¶ms); - } - } - else - { - result = mSwapChain->Present(swapInterval, 0); - } - - mFirstSwap = false; - - // Some swapping mechanisms such as DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL unbind the current render - // target. Mark it dirty. Use the proxy context in display since there is none available. - mRenderer->getStateManager()->invalidateRenderTarget(); - - if (result == DXGI_ERROR_DEVICE_REMOVED) - { - ERR() << "Present failed: the D3D11 device was removed, " - << gl::FmtHR(mRenderer->getDevice()->GetDeviceRemovedReason()); - return EGL_CONTEXT_LOST; - } - else if (result == DXGI_ERROR_DEVICE_RESET) - { - ERR() << "Present failed: the D3D11 device was reset from a bad command."; - return EGL_CONTEXT_LOST; - } - else if (FAILED(result)) - { - ERR() << "Present failed with " << gl::FmtHR(result); - } - - mNativeWindow->commitChange(); - - return EGL_SUCCESS; -} - -const TextureHelper11 &SwapChain11::getOffscreenTexture() -{ - return mNeedsOffscreenTexture ? mOffscreenTexture : mBackBufferTexture; -} - -const d3d11::RenderTargetView &SwapChain11::getRenderTarget() -{ - return mNeedsOffscreenTexture ? mOffscreenRTView : mBackBufferRTView; -} - -const d3d11::SharedSRV &SwapChain11::getRenderTargetShaderResource() -{ - if (!mNeedsOffscreenTexture) - { - ASSERT(mBackBufferSRView.valid()); - return mBackBufferSRView; - } - - if (!mNeedsOffscreenTextureCopy) - { - ASSERT(mOffscreenSRView.valid()); - return mOffscreenSRView; - } - - if (!mOffscreenTextureCopyForSRV.valid()) - { - const d3d11::Format &backbufferFormatInfo = - d3d11::Format::Get(mOffscreenRenderTargetFormat, mRenderer->getRenderer11DeviceCaps()); - - D3D11_TEXTURE2D_DESC offscreenCopyDesc; - mOffscreenTexture.getDesc(&offscreenCopyDesc); - - offscreenCopyDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - offscreenCopyDesc.MiscFlags = 0; - offscreenCopyDesc.CPUAccessFlags = 0; - gl::Error err = mRenderer->allocateTexture(offscreenCopyDesc, backbufferFormatInfo, - &mOffscreenTextureCopyForSRV); - ASSERT(!err.isError()); - mOffscreenTextureCopyForSRV.setDebugName("Offscreen back buffer copy for SRV"); - - D3D11_SHADER_RESOURCE_VIEW_DESC offscreenSRVDesc; - offscreenSRVDesc.Format = backbufferFormatInfo.srvFormat; - offscreenSRVDesc.ViewDimension = - (mEGLSamples <= 1) ? D3D11_SRV_DIMENSION_TEXTURE2D : D3D11_SRV_DIMENSION_TEXTURE2DMS; - offscreenSRVDesc.Texture2D.MostDetailedMip = 0; - offscreenSRVDesc.Texture2D.MipLevels = static_cast<UINT>(-1); - - err = mRenderer->allocateResource(offscreenSRVDesc, mOffscreenTextureCopyForSRV.get(), - &mOffscreenSRView); - ASSERT(!err.isError()); - mOffscreenSRView.setDebugName("Offscreen back buffer shader resource"); - } - - // Need to copy the offscreen texture into the shader-readable copy, since it's external and - // we don't know if the copy is up-to-date. This works around the problem we have when the app - // passes in a texture that isn't shader-readable. - mRenderer->getDeviceContext()->CopyResource(mOffscreenTextureCopyForSRV.get(), - mOffscreenTexture.get()); - return mOffscreenSRView; -} - -const d3d11::DepthStencilView &SwapChain11::getDepthStencil() -{ - return mDepthStencilDSView; -} - -const d3d11::SharedSRV &SwapChain11::getDepthStencilShaderResource() -{ - return mDepthStencilSRView; -} - -const TextureHelper11 &SwapChain11::getDepthStencilTexture() -{ - return mDepthStencilTexture; -} - -void *SwapChain11::getKeyedMutex() -{ - return mKeyedMutex; -} - -void SwapChain11::recreate() -{ - // possibly should use this method instead of reset -} - -void *rx::SwapChain11::getDevice() -{ - return mRenderer->getDevice(); -} - -RenderTargetD3D *SwapChain11::getColorRenderTarget() -{ - return &mColorRenderTarget; -} - -RenderTargetD3D *SwapChain11::getDepthStencilRenderTarget() -{ - return &mDepthStencilRenderTarget; -} - -egl::Error SwapChain11::getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc) -{ - if (!mSwapChain) - { - return egl::EglNotInitialized() << "Swap chain uninitialized"; - } - - DXGI_FRAME_STATISTICS stats = {}; - HRESULT result = mSwapChain->GetFrameStatistics(&stats); - - if (FAILED(result)) - { - return egl::EglBadAlloc() << "Failed to get frame statistics, " << gl::FmtHR(result); - } - - // Conversion from DXGI_FRAME_STATISTICS to the output values: - // stats.SyncRefreshCount -> msc - // stats.PresentCount -> sbc - // stats.SyncQPCTime -> ust with conversion to microseconds via QueryPerformanceFrequency - *msc = stats.SyncRefreshCount; - *sbc = stats.PresentCount; - - LONGLONG syncQPCValue = stats.SyncQPCTime.QuadPart; - // If the QPC Value is below the overflow threshold, we proceed with - // simple multiply and divide. - if (syncQPCValue < kQPCOverflowThreshold) - { - *ust = syncQPCValue * kMicrosecondsPerSecond / mQPCFrequency; - } - else - { - // Otherwise, calculate microseconds in a round about manner to avoid - // overflow and precision issues. - int64_t wholeSeconds = syncQPCValue / mQPCFrequency; - int64_t leftoverTicks = syncQPCValue - (wholeSeconds * mQPCFrequency); - *ust = wholeSeconds * kMicrosecondsPerSecond + - leftoverTicks * kMicrosecondsPerSecond / mQPCFrequency; - } - - return egl::NoError(); -} - -UINT SwapChain11::getD3DSamples() const -{ - return (mEGLSamples == 0) ? 1 : mEGLSamples; -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/SwapChain11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/SwapChain11.h deleted file mode 100644 index eca068210b..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/SwapChain11.h +++ /dev/null @@ -1,137 +0,0 @@ -// -// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// SwapChain11.h: Defines a back-end specific class for the D3D11 swap chain. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_SWAPCHAIN11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_SWAPCHAIN11_H_ - -#include "common/angleutils.h" -#include "libANGLE/renderer/d3d/SwapChainD3D.h" -#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h" - -namespace rx -{ -class Renderer11; -class NativeWindow11; - -class SwapChain11 final : public SwapChainD3D -{ - public: - SwapChain11(Renderer11 *renderer, - NativeWindow11 *nativeWindow, - HANDLE shareHandle, - IUnknown *d3dTexture, - GLenum backBufferFormat, - GLenum depthBufferFormat, - EGLint orientation, - EGLint samples); - ~SwapChain11() override; - - EGLint resize(const gl::Context *context, - EGLint backbufferWidth, - EGLint backbufferHeight) override; - EGLint reset(const gl::Context *context, - EGLint backbufferWidth, - EGLint backbufferHeight, - EGLint swapInterval) override; - EGLint swapRect(const gl::Context *context, - EGLint x, - EGLint y, - EGLint width, - EGLint height) override; - void recreate() override; - - RenderTargetD3D *getColorRenderTarget() override; - RenderTargetD3D *getDepthStencilRenderTarget() override; - - const TextureHelper11 &getOffscreenTexture(); - const d3d11::RenderTargetView &getRenderTarget(); - const d3d11::SharedSRV &getRenderTargetShaderResource(); - - const TextureHelper11 &getDepthStencilTexture(); - const d3d11::DepthStencilView &getDepthStencil(); - const d3d11::SharedSRV &getDepthStencilShaderResource(); - - EGLint getWidth() const { return mWidth; } - EGLint getHeight() const { return mHeight; } - void *getKeyedMutex() override; - EGLint getSamples() const { return mEGLSamples; } - - void *getDevice() override; - - egl::Error getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc) override; - - private: - void release(); - void initPassThroughResources(); - - void releaseOffscreenColorBuffer(); - void releaseOffscreenDepthBuffer(); - EGLint resetOffscreenBuffers(const gl::Context *context, - int backbufferWidth, - int backbufferHeight); - EGLint resetOffscreenColorBuffer(const gl::Context *context, - int backbufferWidth, - int backbufferHeight); - EGLint resetOffscreenDepthBuffer(int backbufferWidth, int backbufferHeight); - - DXGI_FORMAT getSwapChainNativeFormat() const; - - EGLint copyOffscreenToBackbuffer(const gl::Context *context, - EGLint x, - EGLint y, - EGLint width, - EGLint height); - EGLint present(const gl::Context *context, EGLint x, EGLint y, EGLint width, EGLint height); - UINT getD3DSamples() const; - - Renderer11 *mRenderer; - EGLint mWidth; - EGLint mHeight; - const EGLint mOrientation; - bool mAppCreatedShareHandle; - unsigned int mSwapInterval; - bool mPassThroughResourcesInit; - - NativeWindow11 *mNativeWindow; // Handler for the Window that the surface is created for. - - bool mFirstSwap; - IDXGISwapChain *mSwapChain; - IDXGISwapChain1 *mSwapChain1; - IDXGIKeyedMutex *mKeyedMutex; - - TextureHelper11 mBackBufferTexture; - d3d11::RenderTargetView mBackBufferRTView; - d3d11::SharedSRV mBackBufferSRView; - - const bool mNeedsOffscreenTexture; - TextureHelper11 mOffscreenTexture; - d3d11::RenderTargetView mOffscreenRTView; - d3d11::SharedSRV mOffscreenSRView; - bool mNeedsOffscreenTextureCopy; - TextureHelper11 mOffscreenTextureCopyForSRV; - - TextureHelper11 mDepthStencilTexture; - d3d11::DepthStencilView mDepthStencilDSView; - d3d11::SharedSRV mDepthStencilSRView; - - d3d11::Buffer mQuadVB; - d3d11::SamplerState mPassThroughSampler; - d3d11::InputLayout mPassThroughIL; - d3d11::VertexShader mPassThroughVS; - d3d11::PixelShader mPassThroughPS; - d3d11::RasterizerState mPassThroughRS; - - SurfaceRenderTarget11 mColorRenderTarget; - SurfaceRenderTarget11 mDepthStencilRenderTarget; - - EGLint mEGLSamples; - LONGLONG mQPCFrequency; -}; - -} // namespace rx -#endif // LIBANGLE_RENDERER_D3D_D3D11_SWAPCHAIN11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/TextureStorage11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/TextureStorage11.cpp deleted file mode 100644 index b702450ded..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/TextureStorage11.cpp +++ /dev/null @@ -1,3155 +0,0 @@ -// -// Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// TextureStorage11.cpp: Implements the abstract rx::TextureStorage11 class and its concrete derived -// classes TextureStorage11_2D and TextureStorage11_Cube, which act as the interface to the D3D11 -// texture. - -#include "libANGLE/renderer/d3d/d3d11/TextureStorage11.h" - -#include <tuple> - -#include "common/MemoryBuffer.h" -#include "common/utilities.h" -#include "libANGLE/formatutils.h" -#include "libANGLE/ImageIndex.h" -#include "libANGLE/renderer/d3d/d3d11/Blit11.h" -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" -#include "libANGLE/renderer/d3d/d3d11/Image11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h" -#include "libANGLE/renderer/d3d/d3d11/StreamProducerNV12.h" -#include "libANGLE/renderer/d3d/d3d11/SwapChain11.h" -#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h" -#include "libANGLE/renderer/d3d/EGLImageD3D.h" -#include "libANGLE/renderer/d3d/TextureD3D.h" - -namespace rx -{ - -namespace -{ - -void InvalidateRenderTarget(const gl::Context *context, RenderTarget11 *renderTarget) -{ - if (renderTarget) - { - renderTarget->signalDirty(context); - } -} - -RenderTarget11 *GetRenderTarget(std::unique_ptr<RenderTarget11> *pointer) -{ - return pointer->get(); -} - -template <typename KeyT> -RenderTarget11 *GetRenderTarget(std::pair<KeyT, std::unique_ptr<RenderTarget11>> *pair) -{ - return pair->second.get(); -} - -template <typename T> -void InvalidateRenderTargetContainer(const gl::Context *context, T *renderTargetContainer) -{ - for (auto &rt : *renderTargetContainer) - { - InvalidateRenderTarget(context, GetRenderTarget(&rt)); - } -} - -} // anonymous namespace - -TextureStorage11::SRVKey::SRVKey(int baseLevel, int mipLevels, bool swizzle, bool dropStencil) - : baseLevel(baseLevel), mipLevels(mipLevels), swizzle(swizzle), dropStencil(dropStencil) -{ -} - -bool TextureStorage11::SRVKey::operator<(const SRVKey &rhs) const -{ - return std::tie(baseLevel, mipLevels, swizzle, dropStencil) < - std::tie(rhs.baseLevel, rhs.mipLevels, rhs.swizzle, rhs.dropStencil); -} - -TextureStorage11::TextureStorage11(Renderer11 *renderer, - UINT bindFlags, - UINT miscFlags, - GLenum internalFormat) - : mRenderer(renderer), - mTopLevel(0), - mMipLevels(0), - mFormatInfo(d3d11::Format::Get(internalFormat, mRenderer->getRenderer11DeviceCaps())), - mTextureWidth(0), - mTextureHeight(0), - mTextureDepth(0), - mDropStencilTexture(), - mBindFlags(bindFlags), - mMiscFlags(miscFlags) -{ -} - -TextureStorage11::~TextureStorage11() -{ - mSrvCache.clear(); -} - -DWORD TextureStorage11::GetTextureBindFlags(GLenum internalFormat, - const Renderer11DeviceCaps &renderer11DeviceCaps, - bool renderTarget) -{ - UINT bindFlags = 0; - - const d3d11::Format &formatInfo = d3d11::Format::Get(internalFormat, renderer11DeviceCaps); - if (formatInfo.srvFormat != DXGI_FORMAT_UNKNOWN) - { - bindFlags |= D3D11_BIND_SHADER_RESOURCE; - } - if (formatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN) - { - bindFlags |= D3D11_BIND_DEPTH_STENCIL; - } - if (formatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN && renderTarget) - { - bindFlags |= D3D11_BIND_RENDER_TARGET; - } - - return bindFlags; -} - -DWORD TextureStorage11::GetTextureMiscFlags(GLenum internalFormat, - const Renderer11DeviceCaps &renderer11DeviceCaps, - bool renderTarget, - int levels) -{ - UINT miscFlags = 0; - - const d3d11::Format &formatInfo = d3d11::Format::Get(internalFormat, renderer11DeviceCaps); - if (renderTarget && levels > 1) - { - if (d3d11::SupportsMipGen(formatInfo.texFormat, renderer11DeviceCaps.featureLevel)) - { - miscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS; - } - } - - return miscFlags; -} - -UINT TextureStorage11::getBindFlags() const -{ - return mBindFlags; -} - -UINT TextureStorage11::getMiscFlags() const -{ - return mMiscFlags; -} - -int TextureStorage11::getTopLevel() const -{ - // Applying top level is meant to be encapsulated inside TextureStorage11. - UNREACHABLE(); - return mTopLevel; -} - -bool TextureStorage11::isRenderTarget() const -{ - return (mBindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL)) != 0; -} - -bool TextureStorage11::isManaged() const -{ - return false; -} - -bool TextureStorage11::supportsNativeMipmapFunction() const -{ - return (mMiscFlags & D3D11_RESOURCE_MISC_GENERATE_MIPS) != 0; -} - -int TextureStorage11::getLevelCount() const -{ - return mMipLevels - mTopLevel; -} - -int TextureStorage11::getLevelWidth(int mipLevel) const -{ - return std::max(static_cast<int>(mTextureWidth) >> mipLevel, 1); -} - -int TextureStorage11::getLevelHeight(int mipLevel) const -{ - return std::max(static_cast<int>(mTextureHeight) >> mipLevel, 1); -} - -int TextureStorage11::getLevelDepth(int mipLevel) const -{ - return std::max(static_cast<int>(mTextureDepth) >> mipLevel, 1); -} - -gl::Error TextureStorage11::getMippedResource(const gl::Context *context, - const TextureHelper11 **outResource) -{ - return getResource(context, outResource); -} - -UINT TextureStorage11::getSubresourceIndex(const gl::ImageIndex &index) const -{ - UINT mipSlice = static_cast<UINT>(index.mipIndex + mTopLevel); - UINT arraySlice = static_cast<UINT>(index.hasLayer() ? index.layerIndex : 0); - UINT subresource = D3D11CalcSubresource(mipSlice, arraySlice, mMipLevels); - ASSERT(subresource != std::numeric_limits<UINT>::max()); - return subresource; -} - -gl::Error TextureStorage11::getSRV(const gl::Context *context, - const gl::TextureState &textureState, - const d3d11::SharedSRV **outSRV) -{ - // Make sure to add the level offset for our tiny compressed texture workaround - const GLuint effectiveBaseLevel = textureState.getEffectiveBaseLevel(); - bool swizzleRequired = textureState.swizzleRequired(); - bool mipmapping = gl::IsMipmapFiltered(textureState.getSamplerState()); - unsigned int mipLevels = - mipmapping ? (textureState.getEffectiveMaxLevel() - effectiveBaseLevel + 1) : 1; - - // Make sure there's 'mipLevels' mipmap levels below the base level (offset by the top level, - // which corresponds to GL level 0) - mipLevels = std::min(mipLevels, mMipLevels - mTopLevel - effectiveBaseLevel); - - if (mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_9_3) - { - ASSERT(!swizzleRequired); - ASSERT(mipLevels == 1 || mipLevels == mMipLevels); - } - - if (mRenderer->getWorkarounds().zeroMaxLodWorkaround) - { - // We must ensure that the level zero texture is in sync with mipped texture. - ANGLE_TRY(useLevelZeroWorkaroundTexture(context, mipLevels == 1)); - } - - if (swizzleRequired) - { - verifySwizzleExists(textureState.getSwizzleState()); - } - - // We drop the stencil when sampling from the SRV if three conditions hold: - // 1. the drop stencil workaround is enabled. - bool workaround = mRenderer->getWorkarounds().emulateTinyStencilTextures; - // 2. this is a stencil texture. - bool hasStencil = (mFormatInfo.format().stencilBits > 0); - // 3. the texture has a 1x1 or 2x2 mip. - int effectiveTopLevel = effectiveBaseLevel + mipLevels - 1; - bool hasSmallMips = - (getLevelWidth(effectiveTopLevel) <= 2 || getLevelHeight(effectiveTopLevel) <= 2); - - bool useDropStencil = (workaround && hasStencil && hasSmallMips); - SRVKey key(effectiveBaseLevel, mipLevels, swizzleRequired, useDropStencil); - if (useDropStencil) - { - // Ensure drop texture gets created. - DropStencil result = DropStencil::CREATED; - ANGLE_TRY_RESULT(ensureDropStencilTexture(context), result); - - // Clear the SRV cache if necessary. - // TODO(jmadill): Re-use find query result. - auto srvEntry = mSrvCache.find(key); - if (result == DropStencil::CREATED && srvEntry != mSrvCache.end()) - { - mSrvCache.erase(key); - } - } - - ANGLE_TRY(getCachedOrCreateSRV(context, key, outSRV)); - - return gl::NoError(); -} - -gl::Error TextureStorage11::getCachedOrCreateSRV(const gl::Context *context, - const SRVKey &key, - const d3d11::SharedSRV **outSRV) -{ - auto iter = mSrvCache.find(key); - if (iter != mSrvCache.end()) - { - *outSRV = &iter->second; - return gl::NoError(); - } - - const TextureHelper11 *texture = nullptr; - DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN; - - if (key.swizzle) - { - const auto &swizzleFormat = - mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()); - ASSERT(!key.dropStencil || swizzleFormat.format().stencilBits == 0); - ANGLE_TRY(getSwizzleTexture(&texture)); - format = swizzleFormat.srvFormat; - } - else if (key.dropStencil) - { - ASSERT(mDropStencilTexture.valid()); - texture = &mDropStencilTexture; - format = DXGI_FORMAT_R32_FLOAT; - } - else - { - ANGLE_TRY(getResource(context, &texture)); - format = mFormatInfo.srvFormat; - } - - d3d11::SharedSRV srv; - - ANGLE_TRY(createSRV(context, key.baseLevel, key.mipLevels, format, *texture, &srv)); - - const auto &insertIt = mSrvCache.insert(std::make_pair(key, std::move(srv))); - *outSRV = &insertIt.first->second; - - return gl::NoError(); -} - -gl::Error TextureStorage11::getSRVLevel(const gl::Context *context, - int mipLevel, - bool blitSRV, - const d3d11::SharedSRV **outSRV) -{ - ASSERT(mipLevel >= 0 && mipLevel < getLevelCount()); - - auto &levelSRVs = (blitSRV) ? mLevelBlitSRVs : mLevelSRVs; - auto &otherLevelSRVs = (blitSRV) ? mLevelSRVs : mLevelBlitSRVs; - - if (!levelSRVs[mipLevel].valid()) - { - // Only create a different SRV for blit if blit format is different from regular srv format - if (otherLevelSRVs[mipLevel].valid() && mFormatInfo.srvFormat == mFormatInfo.blitSRVFormat) - { - levelSRVs[mipLevel] = otherLevelSRVs[mipLevel].makeCopy(); - } - else - { - const TextureHelper11 *resource = nullptr; - ANGLE_TRY(getResource(context, &resource)); - - DXGI_FORMAT resourceFormat = - blitSRV ? mFormatInfo.blitSRVFormat : mFormatInfo.srvFormat; - ANGLE_TRY( - createSRV(context, mipLevel, 1, resourceFormat, *resource, &levelSRVs[mipLevel])); - } - } - - *outSRV = &levelSRVs[mipLevel]; - - return gl::NoError(); -} - -gl::Error TextureStorage11::getSRVLevels(const gl::Context *context, - GLint baseLevel, - GLint maxLevel, - const d3d11::SharedSRV **outSRV) -{ - unsigned int mipLevels = maxLevel - baseLevel + 1; - - // Make sure there's 'mipLevels' mipmap levels below the base level (offset by the top level, - // which corresponds to GL level 0) - mipLevels = std::min(mipLevels, mMipLevels - mTopLevel - baseLevel); - - if (mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_9_3) - { - ASSERT(mipLevels == 1 || mipLevels == mMipLevels); - } - - if (mRenderer->getWorkarounds().zeroMaxLodWorkaround) - { - // We must ensure that the level zero texture is in sync with mipped texture. - ANGLE_TRY(useLevelZeroWorkaroundTexture(context, mipLevels == 1)); - } - - // TODO(jmadill): Assert we don't need to drop stencil. - - SRVKey key(baseLevel, mipLevels, false, false); - ANGLE_TRY(getCachedOrCreateSRV(context, key, outSRV)); - - return gl::NoError(); -} - -const d3d11::Format &TextureStorage11::getFormatSet() const -{ - return mFormatInfo; -} - -gl::Error TextureStorage11::generateSwizzles(const gl::Context *context, - const gl::SwizzleState &swizzleTarget) -{ - for (int level = 0; level < getLevelCount(); level++) - { - // Check if the swizzle for this level is out of date - if (mSwizzleCache[level] != swizzleTarget) - { - // Need to re-render the swizzle for this level - const d3d11::SharedSRV *sourceSRV = nullptr; - ANGLE_TRY(getSRVLevel(context, level, true, &sourceSRV)); - - const d3d11::RenderTargetView *destRTV; - ANGLE_TRY(getSwizzleRenderTarget(level, &destRTV)); - - gl::Extents size(getLevelWidth(level), getLevelHeight(level), getLevelDepth(level)); - - Blit11 *blitter = mRenderer->getBlitter(); - - ANGLE_TRY(blitter->swizzleTexture(context, *sourceSRV, *destRTV, size, swizzleTarget)); - - mSwizzleCache[level] = swizzleTarget; - } - } - - return gl::NoError(); -} - -void TextureStorage11::markLevelDirty(int mipLevel) -{ - if (mipLevel >= 0 && static_cast<size_t>(mipLevel) < mSwizzleCache.size()) - { - // The default constructor of SwizzleState has GL_INVALID_INDEX for all channels which is - // not a valid swizzle combination - if (mSwizzleCache[mipLevel] != gl::SwizzleState()) - { - // TODO(jmadill): Invalidate specific swizzle. - mRenderer->getStateManager()->invalidateSwizzles(); - mSwizzleCache[mipLevel] = gl::SwizzleState(); - } - } - - if (mDropStencilTexture.valid()) - { - mDropStencilTexture.reset(); - } -} - -void TextureStorage11::markDirty() -{ - for (size_t mipLevel = 0; mipLevel < mSwizzleCache.size(); ++mipLevel) - { - markLevelDirty(static_cast<int>(mipLevel)); - } -} - -gl::Error TextureStorage11::updateSubresourceLevel(const gl::Context *context, - const TextureHelper11 &srcTexture, - unsigned int sourceSubresource, - const gl::ImageIndex &index, - const gl::Box ©Area) -{ - ASSERT(srcTexture.valid()); - - const GLint level = index.mipIndex; - - markLevelDirty(level); - - gl::Extents texSize(getLevelWidth(level), getLevelHeight(level), getLevelDepth(level)); - - bool fullCopy = copyArea.x == 0 && copyArea.y == 0 && copyArea.z == 0 && - copyArea.width == texSize.width && copyArea.height == texSize.height && - copyArea.depth == texSize.depth; - - const TextureHelper11 *dstTexture = nullptr; - - // If the zero-LOD workaround is active and we want to update a level greater than zero, then we - // should update the mipmapped texture, even if mapmaps are currently disabled. - if (index.mipIndex > 0 && mRenderer->getWorkarounds().zeroMaxLodWorkaround) - { - ANGLE_TRY(getMippedResource(context, &dstTexture)); - } - else - { - ANGLE_TRY(getResource(context, &dstTexture)); - } - - unsigned int dstSubresource = getSubresourceIndex(index); - - ASSERT(dstTexture->valid()); - - const d3d11::DXGIFormatSize &dxgiFormatSizeInfo = - d3d11::GetDXGIFormatSizeInfo(mFormatInfo.texFormat); - if (!fullCopy && mFormatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN) - { - // CopySubresourceRegion cannot copy partial depth stencils, use the blitter instead - Blit11 *blitter = mRenderer->getBlitter(); - return blitter->copyDepthStencil(srcTexture, sourceSubresource, copyArea, texSize, - *dstTexture, dstSubresource, copyArea, texSize, nullptr); - } - - D3D11_BOX srcBox; - srcBox.left = copyArea.x; - srcBox.top = copyArea.y; - srcBox.right = - copyArea.x + roundUp(static_cast<UINT>(copyArea.width), dxgiFormatSizeInfo.blockWidth); - srcBox.bottom = - copyArea.y + roundUp(static_cast<UINT>(copyArea.height), dxgiFormatSizeInfo.blockHeight); - srcBox.front = copyArea.z; - srcBox.back = copyArea.z + copyArea.depth; - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - deviceContext->CopySubresourceRegion(dstTexture->get(), dstSubresource, copyArea.x, copyArea.y, - copyArea.z, srcTexture.get(), sourceSubresource, - fullCopy ? nullptr : &srcBox); - return gl::NoError(); -} - -gl::Error TextureStorage11::copySubresourceLevel(const gl::Context *context, - const TextureHelper11 &dstTexture, - unsigned int dstSubresource, - const gl::ImageIndex &index, - const gl::Box ®ion) -{ - ASSERT(dstTexture.valid()); - - const TextureHelper11 *srcTexture = nullptr; - - // If the zero-LOD workaround is active and we want to update a level greater than zero, then we - // should update the mipmapped texture, even if mapmaps are currently disabled. - if (index.mipIndex > 0 && mRenderer->getWorkarounds().zeroMaxLodWorkaround) - { - ANGLE_TRY(getMippedResource(context, &srcTexture)); - } - else - { - ANGLE_TRY(getResource(context, &srcTexture)); - } - - ASSERT(srcTexture->valid()); - - unsigned int srcSubresource = getSubresourceIndex(index); - - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - // D3D11 can't perform partial CopySubresourceRegion on depth/stencil textures, so pSrcBox - // should be nullptr. - D3D11_BOX srcBox; - D3D11_BOX *pSrcBox = nullptr; - if (mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_9_3) - { - GLsizei width = region.width; - GLsizei height = region.height; - d3d11::MakeValidSize(false, mFormatInfo.texFormat, &width, &height, nullptr); - - // Keep srcbox as nullptr if we're dealing with tiny mips of compressed textures. - if (width == region.width && height == region.height) - { - // However, D3D10Level9 doesn't always perform CopySubresourceRegion correctly unless - // the source box is specified. This is okay, since we don't perform - // CopySubresourceRegion on depth/stencil textures on 9_3. - ASSERT(mFormatInfo.dsvFormat == DXGI_FORMAT_UNKNOWN); - srcBox.left = region.x; - srcBox.right = region.x + region.width; - srcBox.top = region.y; - srcBox.bottom = region.y + region.height; - srcBox.front = region.z; - srcBox.back = region.z + region.depth; - pSrcBox = &srcBox; - } - } - - deviceContext->CopySubresourceRegion(dstTexture.get(), dstSubresource, region.x, region.y, - region.z, srcTexture->get(), srcSubresource, pSrcBox); - - return gl::NoError(); -} - -gl::Error TextureStorage11::generateMipmap(const gl::Context *context, - const gl::ImageIndex &sourceIndex, - const gl::ImageIndex &destIndex) -{ - ASSERT(sourceIndex.layerIndex == destIndex.layerIndex); - - markLevelDirty(destIndex.mipIndex); - - RenderTargetD3D *source = nullptr; - ANGLE_TRY(getRenderTarget(context, sourceIndex, &source)); - - RenderTargetD3D *dest = nullptr; - ANGLE_TRY(getRenderTarget(context, destIndex, &dest)); - - RenderTarget11 *rt11 = GetAs<RenderTarget11>(source); - const d3d11::SharedSRV &sourceSRV = rt11->getBlitShaderResourceView(); - const d3d11::RenderTargetView &destRTV = rt11->getRenderTargetView(); - - gl::Box sourceArea(0, 0, 0, source->getWidth(), source->getHeight(), source->getDepth()); - gl::Extents sourceSize(source->getWidth(), source->getHeight(), source->getDepth()); - - gl::Box destArea(0, 0, 0, dest->getWidth(), dest->getHeight(), dest->getDepth()); - gl::Extents destSize(dest->getWidth(), dest->getHeight(), dest->getDepth()); - - Blit11 *blitter = mRenderer->getBlitter(); - GLenum format = gl::GetUnsizedFormat(source->getInternalFormat()); - return blitter->copyTexture(context, sourceSRV, sourceArea, sourceSize, format, destRTV, - destArea, destSize, nullptr, format, GL_LINEAR, false, false, - false); -} - -void TextureStorage11::verifySwizzleExists(const gl::SwizzleState &swizzleState) -{ - for (unsigned int level = 0; level < mMipLevels; level++) - { - ASSERT(mSwizzleCache[level] == swizzleState); - } -} - -void TextureStorage11::clearSRVCache() -{ - markDirty(); - mSrvCache.clear(); - - for (size_t level = 0; level < mLevelSRVs.size(); level++) - { - mLevelSRVs[level].reset(); - mLevelBlitSRVs[level].reset(); - } -} - -gl::Error TextureStorage11::copyToStorage(const gl::Context *context, TextureStorage *destStorage) -{ - ASSERT(destStorage); - - const TextureHelper11 *sourceResouce = nullptr; - ANGLE_TRY(getResource(context, &sourceResouce)); - - TextureStorage11 *dest11 = GetAs<TextureStorage11>(destStorage); - const TextureHelper11 *destResource = nullptr; - ANGLE_TRY(dest11->getResource(context, &destResource)); - - ID3D11DeviceContext *immediateContext = mRenderer->getDeviceContext(); - immediateContext->CopyResource(destResource->get(), sourceResouce->get()); - - dest11->markDirty(); - - return gl::NoError(); -} - -gl::Error TextureStorage11::setData(const gl::Context *context, - const gl::ImageIndex &index, - ImageD3D *image, - const gl::Box *destBox, - GLenum type, - const gl::PixelUnpackState &unpack, - const uint8_t *pixelData) -{ - ASSERT(!image->isDirty()); - - markLevelDirty(index.mipIndex); - - const TextureHelper11 *resource = nullptr; - ANGLE_TRY(getResource(context, &resource)); - ASSERT(resource && resource->valid()); - - UINT destSubresource = getSubresourceIndex(index); - - const gl::InternalFormat &internalFormatInfo = - gl::GetInternalFormatInfo(image->getInternalFormat(), type); - - gl::Box levelBox(0, 0, 0, getLevelWidth(index.mipIndex), getLevelHeight(index.mipIndex), - getLevelDepth(index.mipIndex)); - bool fullUpdate = (destBox == nullptr || *destBox == levelBox); - ASSERT(internalFormatInfo.depthBits == 0 || fullUpdate); - - // TODO(jmadill): Handle compressed formats - // Compressed formats have different load syntax, so we'll have to handle them with slightly - // different logic. Will implemnent this in a follow-up patch, and ensure we do not use SetData - // with compressed formats in the calling logic. - ASSERT(!internalFormatInfo.compressed); - - const int imageWidth = static_cast<int>(image->getWidth()); - const int width = destBox ? destBox->width : imageWidth; - const int imageHeight = static_cast<int>(image->getHeight()); - const int height = destBox ? destBox->height : imageHeight; - const int imageDepth = static_cast<int>(image->getDepth()); - const int depth = destBox ? destBox->depth : imageDepth; - if (imageWidth < width || imageHeight < height || imageDepth < depth) - fullUpdate = true; - GLuint srcRowPitch = 0; - ANGLE_TRY_RESULT( - internalFormatInfo.computeRowPitch(type, width, unpack.alignment, unpack.rowLength), - srcRowPitch); - GLuint srcDepthPitch = 0; - ANGLE_TRY_RESULT(internalFormatInfo.computeDepthPitch(height, unpack.imageHeight, srcRowPitch), - srcDepthPitch); - GLuint srcSkipBytes = 0; - ANGLE_TRY_RESULT( - internalFormatInfo.computeSkipBytes(srcRowPitch, srcDepthPitch, unpack, index.is3D()), - srcSkipBytes); - - const d3d11::Format &d3d11Format = - d3d11::Format::Get(image->getInternalFormat(), mRenderer->getRenderer11DeviceCaps()); - const d3d11::DXGIFormatSize &dxgiFormatInfo = - d3d11::GetDXGIFormatSizeInfo(d3d11Format.texFormat); - - const size_t outputPixelSize = dxgiFormatInfo.pixelBytes; - - UINT bufferRowPitch = static_cast<unsigned int>(outputPixelSize) * width; - UINT bufferDepthPitch = bufferRowPitch * height; - - const size_t neededSize = bufferDepthPitch * depth; - angle::MemoryBuffer *conversionBuffer = nullptr; - const uint8_t *data = nullptr; - - LoadImageFunctionInfo loadFunctionInfo = d3d11Format.getLoadFunctions()(type); - if (loadFunctionInfo.requiresConversion) - { - ANGLE_TRY(mRenderer->getScratchMemoryBuffer(neededSize, &conversionBuffer)); - loadFunctionInfo.loadFunction(width, height, depth, pixelData + srcSkipBytes, srcRowPitch, - srcDepthPitch, conversionBuffer->data(), bufferRowPitch, - bufferDepthPitch); - data = conversionBuffer->data(); - } - else - { - data = pixelData + srcSkipBytes; - bufferRowPitch = srcRowPitch; - bufferDepthPitch = srcDepthPitch; - } - - ID3D11DeviceContext *immediateContext = mRenderer->getDeviceContext(); - - if (!fullUpdate) - { - ASSERT(destBox); - - D3D11_BOX destD3DBox; - destD3DBox.left = destBox->x; - destD3DBox.right = destBox->x + destBox->width; - destD3DBox.top = destBox->y; - destD3DBox.bottom = destBox->y + destBox->height; - destD3DBox.front = destBox->z; - destD3DBox.back = destBox->z + destBox->depth; - - immediateContext->UpdateSubresource(resource->get(), destSubresource, &destD3DBox, data, - bufferRowPitch, bufferDepthPitch); - } - else - { - immediateContext->UpdateSubresource(resource->get(), destSubresource, nullptr, data, - bufferRowPitch, bufferDepthPitch); - } - - return gl::NoError(); -} - -gl::ErrorOrResult<TextureStorage11::DropStencil> TextureStorage11::ensureDropStencilTexture( - const gl::Context *context) -{ - UNIMPLEMENTED(); - return gl::InternalError() << "Drop stencil texture not implemented."; -} - -TextureStorage11_2D::TextureStorage11_2D(Renderer11 *renderer, SwapChain11 *swapchain) - : TextureStorage11(renderer, - D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, - 0, - swapchain->getRenderTargetInternalFormat()), - mTexture(swapchain->getOffscreenTexture()), - mLevelZeroTexture(), - mLevelZeroRenderTarget(nullptr), - mUseLevelZeroTexture(false), - mSwizzleTexture() -{ - for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++) - { - mAssociatedImages[i] = nullptr; - mRenderTarget[i] = nullptr; - } - - D3D11_TEXTURE2D_DESC texDesc; - mTexture.getDesc(&texDesc); - mMipLevels = texDesc.MipLevels; - mTextureWidth = texDesc.Width; - mTextureHeight = texDesc.Height; - mTextureDepth = 1; - mHasKeyedMutex = (texDesc.MiscFlags & D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX) != 0; -} - -TextureStorage11_2D::TextureStorage11_2D(Renderer11 *renderer, - GLenum internalformat, - bool renderTarget, - GLsizei width, - GLsizei height, - int levels, - bool hintLevelZeroOnly) - : TextureStorage11( - renderer, - GetTextureBindFlags(internalformat, renderer->getRenderer11DeviceCaps(), renderTarget), - GetTextureMiscFlags(internalformat, - renderer->getRenderer11DeviceCaps(), - renderTarget, - levels), - internalformat), - mTexture(), - mHasKeyedMutex(false), - mLevelZeroTexture(), - mLevelZeroRenderTarget(nullptr), - mUseLevelZeroTexture(hintLevelZeroOnly && levels > 1), - mSwizzleTexture() -{ - for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++) - { - mAssociatedImages[i] = nullptr; - mRenderTarget[i] = nullptr; - } - - d3d11::MakeValidSize(false, mFormatInfo.texFormat, &width, &height, &mTopLevel); - mMipLevels = mTopLevel + levels; - mTextureWidth = width; - mTextureHeight = height; - mTextureDepth = 1; - - // The LevelZeroOnly hint should only be true if the zero max LOD workaround is active. - ASSERT(!mUseLevelZeroTexture || mRenderer->getWorkarounds().zeroMaxLodWorkaround); -} - -gl::Error TextureStorage11_2D::onDestroy(const gl::Context *context) -{ - for (unsigned i = 0; i < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++) - { - if (mAssociatedImages[i] != nullptr) - { - mAssociatedImages[i]->verifyAssociatedStorageValid(this); - - // We must let the Images recover their data before we delete it from the - // TextureStorage. - ANGLE_TRY(mAssociatedImages[i]->recoverFromAssociatedStorage(context)); - } - } - - if (mHasKeyedMutex) - { - // If the keyed mutex is released that will unbind it and cause the state cache to become - // desynchronized. - mRenderer->getStateManager()->invalidateBoundViews(); - } - - // Invalidate RenderTargets. - InvalidateRenderTargetContainer(context, &mRenderTarget); - InvalidateRenderTarget(context, mLevelZeroRenderTarget.get()); - - return gl::NoError(); -} - -TextureStorage11_2D::~TextureStorage11_2D() -{ -} - -gl::Error TextureStorage11_2D::copyToStorage(const gl::Context *context, - TextureStorage *destStorage) -{ - ASSERT(destStorage); - - TextureStorage11_2D *dest11 = GetAs<TextureStorage11_2D>(destStorage); - ID3D11DeviceContext *immediateContext = mRenderer->getDeviceContext(); - - if (mRenderer->getWorkarounds().zeroMaxLodWorkaround) - { - // If either mTexture or mLevelZeroTexture exist, then we need to copy them into the - // corresponding textures in destStorage. - if (mTexture.valid()) - { - ANGLE_TRY(dest11->useLevelZeroWorkaroundTexture(context, false)); - - const TextureHelper11 *destResource = nullptr; - ANGLE_TRY(dest11->getResource(context, &destResource)); - - immediateContext->CopyResource(destResource->get(), mTexture.get()); - } - - if (mLevelZeroTexture.valid()) - { - ANGLE_TRY(dest11->useLevelZeroWorkaroundTexture(context, true)); - - const TextureHelper11 *destResource = nullptr; - ANGLE_TRY(dest11->getResource(context, &destResource)); - - immediateContext->CopyResource(destResource->get(), mLevelZeroTexture.get()); - } - - return gl::NoError(); - } - - const TextureHelper11 *sourceResouce = nullptr; - ANGLE_TRY(getResource(context, &sourceResouce)); - - const TextureHelper11 *destResource = nullptr; - ANGLE_TRY(dest11->getResource(context, &destResource)); - - immediateContext->CopyResource(destResource->get(), sourceResouce->get()); - dest11->markDirty(); - - return gl::NoError(); -} - -gl::Error TextureStorage11_2D::useLevelZeroWorkaroundTexture(const gl::Context *context, - bool useLevelZeroTexture) -{ - bool lastSetting = mUseLevelZeroTexture; - - if (useLevelZeroTexture && mMipLevels > 1) - { - if (!mUseLevelZeroTexture && mTexture.valid()) - { - ANGLE_TRY(ensureTextureExists(1)); - - // Pull data back from the mipped texture if necessary. - ASSERT(mLevelZeroTexture.valid()); - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - deviceContext->CopySubresourceRegion(mLevelZeroTexture.get(), 0, 0, 0, 0, - mTexture.get(), 0, nullptr); - } - - mUseLevelZeroTexture = true; - } - else - { - if (mUseLevelZeroTexture && mLevelZeroTexture.valid()) - { - ANGLE_TRY(ensureTextureExists(mMipLevels)); - - // Pull data back from the level zero texture if necessary. - ASSERT(mTexture.valid()); - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - deviceContext->CopySubresourceRegion(mTexture.get(), 0, 0, 0, 0, - mLevelZeroTexture.get(), 0, nullptr); - } - - mUseLevelZeroTexture = false; - } - - if (lastSetting != mUseLevelZeroTexture) - { - // Mark everything as dirty to be conservative. - if (mLevelZeroRenderTarget) - { - mLevelZeroRenderTarget->signalDirty(context); - } - for (auto &renderTarget : mRenderTarget) - { - if (renderTarget) - { - renderTarget->signalDirty(context); - } - } - } - - return gl::NoError(); -} - -void TextureStorage11_2D::associateImage(Image11 *image, const gl::ImageIndex &index) -{ - const GLint level = index.mipIndex; - - ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS); - - if (0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) - { - mAssociatedImages[level] = image; - } -} - -void TextureStorage11_2D::verifyAssociatedImageValid(const gl::ImageIndex &index, - Image11 *expectedImage) -{ - const GLint level = index.mipIndex; - - ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS); - // This validation check should never return false. It means the Image/TextureStorage - // association is broken. - ASSERT(mAssociatedImages[level] == expectedImage); -} - -// disassociateImage allows an Image to end its association with a Storage. -void TextureStorage11_2D::disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) -{ - const GLint level = index.mipIndex; - - ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS); - ASSERT(mAssociatedImages[level] == expectedImage); - mAssociatedImages[level] = nullptr; -} - -// releaseAssociatedImage prepares the Storage for a new Image association. It lets the old Image -// recover its data before ending the association. -gl::Error TextureStorage11_2D::releaseAssociatedImage(const gl::Context *context, - const gl::ImageIndex &index, - Image11 *incomingImage) -{ - const GLint level = index.mipIndex; - - ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS); - - if (0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) - { - // No need to let the old Image recover its data, if it is also the incoming Image. - if (mAssociatedImages[level] != nullptr && mAssociatedImages[level] != incomingImage) - { - // Ensure that the Image is still associated with this TextureStorage. - mAssociatedImages[level]->verifyAssociatedStorageValid(this); - - // Force the image to recover from storage before its data is overwritten. - // This will reset mAssociatedImages[level] to nullptr too. - ANGLE_TRY(mAssociatedImages[level]->recoverFromAssociatedStorage(context)); - } - } - - return gl::NoError(); -} - -gl::Error TextureStorage11_2D::getResource(const gl::Context *context, - const TextureHelper11 **outResource) -{ - if (mUseLevelZeroTexture && mMipLevels > 1) - { - ANGLE_TRY(ensureTextureExists(1)); - - *outResource = &mLevelZeroTexture; - return gl::NoError(); - } - - ANGLE_TRY(ensureTextureExists(mMipLevels)); - - *outResource = &mTexture; - return gl::NoError(); -} - -gl::Error TextureStorage11_2D::getMippedResource(const gl::Context *context, - const TextureHelper11 **outResource) -{ - // This shouldn't be called unless the zero max LOD workaround is active. - ASSERT(mRenderer->getWorkarounds().zeroMaxLodWorkaround); - - ANGLE_TRY(ensureTextureExists(mMipLevels)); - - *outResource = &mTexture; - return gl::NoError(); -} - -gl::Error TextureStorage11_2D::ensureTextureExists(int mipLevels) -{ - // If mMipLevels = 1 then always use mTexture rather than mLevelZeroTexture. - bool useLevelZeroTexture = mRenderer->getWorkarounds().zeroMaxLodWorkaround - ? (mipLevels == 1) && (mMipLevels > 1) - : false; - TextureHelper11 *outputTexture = useLevelZeroTexture ? &mLevelZeroTexture : &mTexture; - - // 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 - if (!outputTexture->valid() && mTextureWidth > 0 && mTextureHeight > 0) - { - ASSERT(mipLevels > 0); - - D3D11_TEXTURE2D_DESC desc; - desc.Width = mTextureWidth; // Compressed texture size constraints? - desc.Height = mTextureHeight; - desc.MipLevels = mipLevels; - desc.ArraySize = 1; - desc.Format = mFormatInfo.texFormat; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = getBindFlags(); - desc.CPUAccessFlags = 0; - desc.MiscFlags = getMiscFlags(); - - ANGLE_TRY(mRenderer->allocateTexture(desc, mFormatInfo, outputTexture)); - outputTexture->setDebugName("TexStorage2D.Texture"); - } - - return gl::NoError(); -} - -gl::Error TextureStorage11_2D::getRenderTarget(const gl::Context *context, - const gl::ImageIndex &index, - RenderTargetD3D **outRT) -{ - ASSERT(!index.hasLayer()); - - const int level = index.mipIndex; - ASSERT(level >= 0 && level < getLevelCount()); - - // In GL ES 2.0, the application can only render to level zero of the texture (Section 4.4.3 of - // the GLES 2.0 spec, page 113 of version 2.0.25). Other parts of TextureStorage11_2D could - // create RTVs on non-zero levels of the texture (e.g. generateMipmap). - // On Feature Level 9_3, this is unlikely to be useful. The renderer can't create SRVs on the - // individual levels of the texture, so methods like generateMipmap can't do anything useful - // with non-zero-level RTVs. Therefore if level > 0 on 9_3 then there's almost certainly - // something wrong. - ASSERT( - !(mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_9_3 && level > 0)); - ASSERT(outRT); - if (mRenderTarget[level]) - { - *outRT = mRenderTarget[level].get(); - return gl::NoError(); - } - - if (mRenderer->getWorkarounds().zeroMaxLodWorkaround) - { - ASSERT(index.mipIndex == 0); - ANGLE_TRY(useLevelZeroWorkaroundTexture(context, true)); - } - - const TextureHelper11 *texture = nullptr; - ANGLE_TRY(getResource(context, &texture)); - - const d3d11::SharedSRV *srv = nullptr; - ANGLE_TRY(getSRVLevel(context, level, false, &srv)); - - const d3d11::SharedSRV *blitSRV = nullptr; - ANGLE_TRY(getSRVLevel(context, level, true, &blitSRV)); - - if (mUseLevelZeroTexture) - { - if (!mLevelZeroRenderTarget) - { - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - rtvDesc.Format = mFormatInfo.rtvFormat; - rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; - rtvDesc.Texture2D.MipSlice = mTopLevel + level; - - d3d11::RenderTargetView rtv; - ANGLE_TRY(mRenderer->allocateResource(rtvDesc, mLevelZeroTexture.get(), &rtv)); - - mLevelZeroRenderTarget.reset(new TextureRenderTarget11( - std::move(rtv), mLevelZeroTexture, d3d11::SharedSRV(), d3d11::SharedSRV(), - mFormatInfo.internalFormat, getFormatSet(), getLevelWidth(level), - getLevelHeight(level), 1, 0)); - } - - *outRT = mLevelZeroRenderTarget.get(); - return gl::NoError(); - } - - if (mFormatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN) - { - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - rtvDesc.Format = mFormatInfo.rtvFormat; - rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; - rtvDesc.Texture2D.MipSlice = mTopLevel + level; - - d3d11::RenderTargetView rtv; - ANGLE_TRY(mRenderer->allocateResource(rtvDesc, texture->get(), &rtv)); - - mRenderTarget[level].reset(new TextureRenderTarget11( - std::move(rtv), *texture, *srv, *blitSRV, mFormatInfo.internalFormat, getFormatSet(), - getLevelWidth(level), getLevelHeight(level), 1, 0)); - - *outRT = mRenderTarget[level].get(); - return gl::NoError(); - } - - ASSERT(mFormatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN); - - D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; - dsvDesc.Format = mFormatInfo.dsvFormat; - dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; - dsvDesc.Texture2D.MipSlice = mTopLevel + level; - dsvDesc.Flags = 0; - - d3d11::DepthStencilView dsv; - ANGLE_TRY(mRenderer->allocateResource(dsvDesc, texture->get(), &dsv)); - - mRenderTarget[level].reset(new TextureRenderTarget11( - std::move(dsv), *texture, *srv, mFormatInfo.internalFormat, getFormatSet(), - getLevelWidth(level), getLevelHeight(level), 1, 0)); - - *outRT = mRenderTarget[level].get(); - return gl::NoError(); -} - -gl::Error TextureStorage11_2D::createSRV(const gl::Context *context, - int baseLevel, - int mipLevels, - DXGI_FORMAT format, - const TextureHelper11 &texture, - d3d11::SharedSRV *outSRV) -{ - ASSERT(outSRV); - - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - srvDesc.Format = format; - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - srvDesc.Texture2D.MostDetailedMip = mTopLevel + baseLevel; - srvDesc.Texture2D.MipLevels = mipLevels; - - const TextureHelper11 *srvTexture = &texture; - - if (mRenderer->getWorkarounds().zeroMaxLodWorkaround) - { - ASSERT(mTopLevel == 0); - ASSERT(baseLevel == 0); - // This code also assumes that the incoming texture equals either mLevelZeroTexture or - // mTexture. - - if (mipLevels == 1 && mMipLevels > 1) - { - // We must use a SRV on the level-zero-only texture. - ANGLE_TRY(ensureTextureExists(1)); - srvTexture = &mLevelZeroTexture; - } - else - { - ASSERT(mipLevels == static_cast<int>(mMipLevels)); - ASSERT(mTexture.valid() && texture == mTexture); - srvTexture = &mTexture; - } - } - - ANGLE_TRY(mRenderer->allocateResource(srvDesc, srvTexture->get(), outSRV)); - outSRV->setDebugName("TexStorage2D.SRV"); - - return gl::NoError(); -} - -gl::Error TextureStorage11_2D::getSwizzleTexture(const TextureHelper11 **outTexture) -{ - ASSERT(outTexture); - - if (!mSwizzleTexture.valid()) - { - const auto &format = mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()); - - D3D11_TEXTURE2D_DESC desc; - desc.Width = mTextureWidth; - desc.Height = mTextureHeight; - desc.MipLevels = mMipLevels; - desc.ArraySize = 1; - desc.Format = format.texFormat; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; - desc.CPUAccessFlags = 0; - desc.MiscFlags = 0; - - ANGLE_TRY(mRenderer->allocateTexture(desc, format, &mSwizzleTexture)); - mSwizzleTexture.setDebugName("TexStorage2D.SwizzleTexture"); - } - - *outTexture = &mSwizzleTexture; - return gl::NoError(); -} - -gl::Error TextureStorage11_2D::getSwizzleRenderTarget(int mipLevel, - const d3d11::RenderTargetView **outRTV) -{ - ASSERT(mipLevel >= 0 && mipLevel < getLevelCount()); - ASSERT(outRTV); - - if (!mSwizzleRenderTargets[mipLevel].valid()) - { - const TextureHelper11 *swizzleTexture = nullptr; - ANGLE_TRY(getSwizzleTexture(&swizzleTexture)); - - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - rtvDesc.Format = - mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()).rtvFormat; - rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; - rtvDesc.Texture2D.MipSlice = mTopLevel + mipLevel; - - ANGLE_TRY(mRenderer->allocateResource(rtvDesc, mSwizzleTexture.get(), - &mSwizzleRenderTargets[mipLevel])); - } - - *outRTV = &mSwizzleRenderTargets[mipLevel]; - return gl::NoError(); -} - -gl::ErrorOrResult<TextureStorage11::DropStencil> TextureStorage11_2D::ensureDropStencilTexture( - const gl::Context *context) -{ - if (mDropStencilTexture.valid()) - { - return DropStencil::ALREADY_EXISTS; - } - - D3D11_TEXTURE2D_DESC dropDesc = {}; - dropDesc.ArraySize = 1; - dropDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL; - dropDesc.CPUAccessFlags = 0; - dropDesc.Format = DXGI_FORMAT_R32_TYPELESS; - dropDesc.Height = mTextureHeight; - dropDesc.MipLevels = mMipLevels; - dropDesc.MiscFlags = 0; - dropDesc.SampleDesc.Count = 1; - dropDesc.SampleDesc.Quality = 0; - dropDesc.Usage = D3D11_USAGE_DEFAULT; - dropDesc.Width = mTextureWidth; - - const auto &format = - d3d11::Format::Get(GL_DEPTH_COMPONENT32F, mRenderer->getRenderer11DeviceCaps()); - ANGLE_TRY(mRenderer->allocateTexture(dropDesc, format, &mDropStencilTexture)); - mDropStencilTexture.setDebugName("TexStorage2D.DropStencil"); - - ANGLE_TRY(initDropStencilTexture(context, gl::ImageIndexIterator::Make2D(0, mMipLevels))); - - return DropStencil::CREATED; -} - -TextureStorage11_External::TextureStorage11_External( - Renderer11 *renderer, - egl::Stream *stream, - const egl::Stream::GLTextureDescription &glDesc) - : TextureStorage11(renderer, D3D11_BIND_SHADER_RESOURCE, 0, glDesc.internalFormat) -{ - ASSERT(stream->getProducerType() == egl::Stream::ProducerType::D3D11TextureNV12); - StreamProducerNV12 *producer = static_cast<StreamProducerNV12 *>(stream->getImplementation()); - mTexture.set(producer->getD3DTexture(), mFormatInfo); - mSubresourceIndex = producer->getArraySlice(); - mTexture.get()->AddRef(); - mMipLevels = 1; - - D3D11_TEXTURE2D_DESC desc; - mTexture.getDesc(&desc); - mTextureWidth = desc.Width; - mTextureHeight = desc.Height; - mTextureDepth = 1; - mHasKeyedMutex = (desc.MiscFlags & D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX) != 0; -} - -gl::Error TextureStorage11_External::onDestroy(const gl::Context *context) -{ - if (mHasKeyedMutex) - { - // If the keyed mutex is released that will unbind it and cause the state cache to become - // desynchronized. - mRenderer->getStateManager()->invalidateBoundViews(); - } - - return gl::NoError(); -} - -TextureStorage11_External::~TextureStorage11_External() -{ -} - -gl::Error TextureStorage11_External::copyToStorage(const gl::Context *context, - TextureStorage *destStorage) -{ - UNIMPLEMENTED(); - return gl::NoError(); -} - -void TextureStorage11_External::associateImage(Image11 *image, const gl::ImageIndex &index) -{ - ASSERT(index.mipIndex == 0); - mAssociatedImage = image; -} - -void TextureStorage11_External::verifyAssociatedImageValid(const gl::ImageIndex &index, - Image11 *expectedImage) -{ - ASSERT(index.mipIndex == 0 && mAssociatedImage == expectedImage); -} - -void TextureStorage11_External::disassociateImage(const gl::ImageIndex &index, - Image11 *expectedImage) -{ - ASSERT(index.mipIndex == 0); - ASSERT(mAssociatedImage == expectedImage); - mAssociatedImage = nullptr; -} - -gl::Error TextureStorage11_External::releaseAssociatedImage(const gl::Context *context, - const gl::ImageIndex &index, - Image11 *incomingImage) -{ - ASSERT(index.mipIndex == 0); - - if (mAssociatedImage != nullptr && mAssociatedImage != incomingImage) - { - mAssociatedImage->verifyAssociatedStorageValid(this); - - ANGLE_TRY(mAssociatedImage->recoverFromAssociatedStorage(context)); - } - - return gl::NoError(); -} - -gl::Error TextureStorage11_External::getResource(const gl::Context *context, - const TextureHelper11 **outResource) -{ - *outResource = &mTexture; - return gl::NoError(); -} - -gl::Error TextureStorage11_External::getMippedResource(const gl::Context *context, - const TextureHelper11 **outResource) -{ - *outResource = &mTexture; - return gl::NoError(); -} - -gl::Error TextureStorage11_External::getRenderTarget(const gl::Context *context, - const gl::ImageIndex &index, - RenderTargetD3D **outRT) -{ - // Render targets are not supported for external textures - UNREACHABLE(); - return gl::InternalError(); -} - -gl::Error TextureStorage11_External::createSRV(const gl::Context *context, - int baseLevel, - int mipLevels, - DXGI_FORMAT format, - const TextureHelper11 &texture, - d3d11::SharedSRV *outSRV) -{ - // Since external textures are treates as non-mipmapped textures, we ignore mipmap levels and - // use the specified subresource ID the storage was created with. - ASSERT(mipLevels == 1); - ASSERT(outSRV); - - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - srvDesc.Format = format; - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; - // subresource index is equal to the mip level for 2D textures - srvDesc.Texture2DArray.MostDetailedMip = 0; - srvDesc.Texture2DArray.MipLevels = 1; - srvDesc.Texture2DArray.FirstArraySlice = mSubresourceIndex; - srvDesc.Texture2DArray.ArraySize = 1; - - ANGLE_TRY(mRenderer->allocateResource(srvDesc, texture.get(), outSRV)); - outSRV->setDebugName("TexStorage2D.SRV"); - - return gl::NoError(); -} - -gl::Error TextureStorage11_External::getSwizzleTexture(const TextureHelper11 **outTexture) -{ - UNIMPLEMENTED(); - return gl::InternalError(); -} - -gl::Error TextureStorage11_External::getSwizzleRenderTarget(int mipLevel, - const d3d11::RenderTargetView **outRTV) -{ - UNIMPLEMENTED(); - return gl::InternalError(); -} - -TextureStorage11_EGLImage::TextureStorage11_EGLImage(Renderer11 *renderer, - EGLImageD3D *eglImage, - RenderTarget11 *renderTarget11) - : TextureStorage11(renderer, - D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, - 0, - renderTarget11->getInternalFormat()), - mImage(eglImage), - mCurrentRenderTarget(0), - mSwizzleTexture(), - mSwizzleRenderTargets(gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) -{ - mCurrentRenderTarget = reinterpret_cast<uintptr_t>(renderTarget11); - - mMipLevels = 1; - mTextureWidth = renderTarget11->getWidth(); - mTextureHeight = renderTarget11->getHeight(); - mTextureDepth = 1; -} - -TextureStorage11_EGLImage::~TextureStorage11_EGLImage() -{ -} - -gl::Error TextureStorage11_EGLImage::getResource(const gl::Context *context, - const TextureHelper11 **outResource) -{ - ANGLE_TRY(checkForUpdatedRenderTarget(context)); - - RenderTarget11 *renderTarget11 = nullptr; - ANGLE_TRY(getImageRenderTarget(context, &renderTarget11)); - *outResource = &renderTarget11->getTexture(); - return gl::NoError(); -} - -gl::Error TextureStorage11_EGLImage::getSRV(const gl::Context *context, - const gl::TextureState &textureState, - const d3d11::SharedSRV **outSRV) -{ - ANGLE_TRY(checkForUpdatedRenderTarget(context)); - return TextureStorage11::getSRV(context, textureState, outSRV); -} - -gl::Error TextureStorage11_EGLImage::getMippedResource(const gl::Context *context, - const TextureHelper11 **) -{ - // This shouldn't be called unless the zero max LOD workaround is active. - // EGL images are unavailable in this configuration. - UNREACHABLE(); - return gl::InternalError(); -} - -gl::Error TextureStorage11_EGLImage::getRenderTarget(const gl::Context *context, - const gl::ImageIndex &index, - RenderTargetD3D **outRT) -{ - ASSERT(!index.hasLayer()); - ASSERT(index.mipIndex == 0); - - ANGLE_TRY(checkForUpdatedRenderTarget(context)); - - return mImage->getRenderTarget(context, outRT); -} - -gl::Error TextureStorage11_EGLImage::copyToStorage(const gl::Context *context, - TextureStorage *destStorage) -{ - const TextureHelper11 *sourceResouce = nullptr; - ANGLE_TRY(getResource(context, &sourceResouce)); - - ASSERT(destStorage); - TextureStorage11_2D *dest11 = GetAs<TextureStorage11_2D>(destStorage); - const TextureHelper11 *destResource = nullptr; - ANGLE_TRY(dest11->getResource(context, &destResource)); - - ID3D11DeviceContext *immediateContext = mRenderer->getDeviceContext(); - immediateContext->CopyResource(destResource->get(), sourceResouce->get()); - - dest11->markDirty(); - - return gl::NoError(); -} - -void TextureStorage11_EGLImage::associateImage(Image11 *, const gl::ImageIndex &) -{ -} - -void TextureStorage11_EGLImage::disassociateImage(const gl::ImageIndex &, Image11 *) -{ -} - -void TextureStorage11_EGLImage::verifyAssociatedImageValid(const gl::ImageIndex &, Image11 *) -{ -} - -gl::Error TextureStorage11_EGLImage::releaseAssociatedImage(const gl::Context *context, - const gl::ImageIndex &, - Image11 *) -{ - return gl::NoError(); -} - -gl::Error TextureStorage11_EGLImage::useLevelZeroWorkaroundTexture(const gl::Context *context, bool) -{ - UNREACHABLE(); - return gl::InternalError(); -} - -gl::Error TextureStorage11_EGLImage::getSwizzleTexture(const TextureHelper11 **outTexture) -{ - ASSERT(outTexture); - - if (!mSwizzleTexture.valid()) - { - const auto &format = mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()); - - D3D11_TEXTURE2D_DESC desc; - desc.Width = mTextureWidth; - desc.Height = mTextureHeight; - desc.MipLevels = mMipLevels; - desc.ArraySize = 1; - desc.Format = format.texFormat; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; - desc.CPUAccessFlags = 0; - desc.MiscFlags = 0; - - ANGLE_TRY(mRenderer->allocateTexture(desc, format, &mSwizzleTexture)); - mSwizzleTexture.setDebugName("TexStorageEGLImage.SwizzleTexture"); - } - - *outTexture = &mSwizzleTexture; - return gl::NoError(); -} - -gl::Error TextureStorage11_EGLImage::getSwizzleRenderTarget(int mipLevel, - const d3d11::RenderTargetView **outRTV) -{ - ASSERT(mipLevel >= 0 && mipLevel < getLevelCount()); - ASSERT(outRTV); - - if (!mSwizzleRenderTargets[mipLevel].valid()) - { - const TextureHelper11 *swizzleTexture = nullptr; - ANGLE_TRY(getSwizzleTexture(&swizzleTexture)); - - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - rtvDesc.Format = - mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()).rtvFormat; - rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; - rtvDesc.Texture2D.MipSlice = mTopLevel + mipLevel; - - ANGLE_TRY(mRenderer->allocateResource(rtvDesc, mSwizzleTexture.get(), - &mSwizzleRenderTargets[mipLevel])); - } - - *outRTV = &mSwizzleRenderTargets[mipLevel]; - return gl::NoError(); -} - -gl::Error TextureStorage11_EGLImage::checkForUpdatedRenderTarget(const gl::Context *context) -{ - RenderTarget11 *renderTarget11 = nullptr; - ANGLE_TRY(getImageRenderTarget(context, &renderTarget11)); - - if (mCurrentRenderTarget != reinterpret_cast<uintptr_t>(renderTarget11)) - { - clearSRVCache(); - mCurrentRenderTarget = reinterpret_cast<uintptr_t>(renderTarget11); - } - - return gl::NoError(); -} - -gl::Error TextureStorage11_EGLImage::createSRV(const gl::Context *context, - int baseLevel, - int mipLevels, - DXGI_FORMAT format, - const TextureHelper11 &texture, - d3d11::SharedSRV *outSRV) -{ - ASSERT(baseLevel == 0); - ASSERT(mipLevels == 1); - ASSERT(outSRV); - - // Create a new SRV only for the swizzle texture. Otherwise just return the Image's - // RenderTarget's SRV. - if (texture == mSwizzleTexture) - { - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - srvDesc.Format = format; - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - srvDesc.Texture2D.MostDetailedMip = mTopLevel + baseLevel; - srvDesc.Texture2D.MipLevels = mipLevels; - - ANGLE_TRY(mRenderer->allocateResource(srvDesc, texture.get(), outSRV)); - outSRV->setDebugName("TexStorageEGLImage.SRV"); - } - else - { - RenderTarget11 *renderTarget = nullptr; - ANGLE_TRY(getImageRenderTarget(context, &renderTarget)); - - ASSERT(texture == renderTarget->getTexture()); - - *outSRV = renderTarget->getShaderResourceView().makeCopy(); - } - - return gl::NoError(); -} - -gl::Error TextureStorage11_EGLImage::getImageRenderTarget(const gl::Context *context, - RenderTarget11 **outRT) const -{ - RenderTargetD3D *renderTargetD3D = nullptr; - ANGLE_TRY(mImage->getRenderTarget(context, &renderTargetD3D)); - *outRT = GetAs<RenderTarget11>(renderTargetD3D); - return gl::NoError(); -} - -TextureStorage11_Cube::TextureStorage11_Cube(Renderer11 *renderer, - GLenum internalformat, - bool renderTarget, - int size, - int levels, - bool hintLevelZeroOnly) - : TextureStorage11( - renderer, - GetTextureBindFlags(internalformat, renderer->getRenderer11DeviceCaps(), renderTarget), - GetTextureMiscFlags(internalformat, - renderer->getRenderer11DeviceCaps(), - renderTarget, - levels), - internalformat), - mTexture(), - mLevelZeroTexture(), - mUseLevelZeroTexture(hintLevelZeroOnly && levels > 1), - mSwizzleTexture() -{ - for (unsigned int level = 0; level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS; level++) - { - for (unsigned int face = 0; face < gl::CUBE_FACE_COUNT; face++) - { - mAssociatedImages[face][level] = nullptr; - mRenderTarget[face][level] = nullptr; - } - } - - for (unsigned int face = 0; face < gl::CUBE_FACE_COUNT; face++) - { - mLevelZeroRenderTarget[face] = nullptr; - } - - // adjust size if needed for compressed textures - int height = size; - d3d11::MakeValidSize(false, mFormatInfo.texFormat, &size, &height, &mTopLevel); - - mMipLevels = mTopLevel + levels; - mTextureWidth = size; - mTextureHeight = size; - mTextureDepth = 1; - - // The LevelZeroOnly hint should only be true if the zero max LOD workaround is active. - ASSERT(!mUseLevelZeroTexture || mRenderer->getWorkarounds().zeroMaxLodWorkaround); -} - -gl::Error TextureStorage11_Cube::onDestroy(const gl::Context *context) -{ - for (unsigned int level = 0; level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS; level++) - { - for (unsigned int face = 0; face < gl::CUBE_FACE_COUNT; face++) - { - if (mAssociatedImages[face][level] != nullptr) - { - mAssociatedImages[face][level]->verifyAssociatedStorageValid(this); - - // We must let the Images recover their data before we delete it from the - // TextureStorage. - ANGLE_TRY(mAssociatedImages[face][level]->recoverFromAssociatedStorage(context)); - } - } - } - - for (auto &faceRenderTargets : mRenderTarget) - { - InvalidateRenderTargetContainer(context, &faceRenderTargets); - } - InvalidateRenderTargetContainer(context, &mLevelZeroRenderTarget); - - return gl::NoError(); -} - -TextureStorage11_Cube::~TextureStorage11_Cube() -{ -} - -UINT TextureStorage11_Cube::getSubresourceIndex(const gl::ImageIndex &index) const -{ - if (mRenderer->getWorkarounds().zeroMaxLodWorkaround && mUseLevelZeroTexture && - index.mipIndex == 0) - { - UINT arraySlice = static_cast<UINT>(index.hasLayer() ? index.layerIndex : 0); - UINT subresource = D3D11CalcSubresource(0, arraySlice, 1); - ASSERT(subresource != std::numeric_limits<UINT>::max()); - return subresource; - } - else - { - UINT mipSlice = static_cast<UINT>(index.mipIndex + mTopLevel); - UINT arraySlice = static_cast<UINT>(index.hasLayer() ? index.layerIndex : 0); - UINT subresource = D3D11CalcSubresource(mipSlice, arraySlice, mMipLevels); - ASSERT(subresource != std::numeric_limits<UINT>::max()); - return subresource; - } -} - -gl::Error TextureStorage11_Cube::copyToStorage(const gl::Context *context, - TextureStorage *destStorage) -{ - ASSERT(destStorage); - - TextureStorage11_Cube *dest11 = GetAs<TextureStorage11_Cube>(destStorage); - - if (mRenderer->getWorkarounds().zeroMaxLodWorkaround) - { - ID3D11DeviceContext *immediateContext = mRenderer->getDeviceContext(); - - // If either mTexture or mLevelZeroTexture exist, then we need to copy them into the - // corresponding textures in destStorage. - if (mTexture.valid()) - { - ANGLE_TRY(dest11->useLevelZeroWorkaroundTexture(context, false)); - - const TextureHelper11 *destResource = nullptr; - ANGLE_TRY(dest11->getResource(context, &destResource)); - - immediateContext->CopyResource(destResource->get(), mTexture.get()); - } - - if (mLevelZeroTexture.valid()) - { - ANGLE_TRY(dest11->useLevelZeroWorkaroundTexture(context, true)); - - const TextureHelper11 *destResource = nullptr; - ANGLE_TRY(dest11->getResource(context, &destResource)); - - immediateContext->CopyResource(destResource->get(), mLevelZeroTexture.get()); - } - } - else - { - const TextureHelper11 *sourceResouce = nullptr; - ANGLE_TRY(getResource(context, &sourceResouce)); - - const TextureHelper11 *destResource = nullptr; - ANGLE_TRY(dest11->getResource(context, &destResource)); - - ID3D11DeviceContext *immediateContext = mRenderer->getDeviceContext(); - immediateContext->CopyResource(destResource->get(), sourceResouce->get()); - } - - dest11->markDirty(); - - return gl::NoError(); -} - -gl::Error TextureStorage11_Cube::useLevelZeroWorkaroundTexture(const gl::Context *context, - bool useLevelZeroTexture) -{ - if (useLevelZeroTexture && mMipLevels > 1) - { - if (!mUseLevelZeroTexture && mTexture.valid()) - { - ANGLE_TRY(ensureTextureExists(1)); - - // Pull data back from the mipped texture if necessary. - ASSERT(mLevelZeroTexture.valid()); - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - for (int face = 0; face < 6; face++) - { - deviceContext->CopySubresourceRegion(mLevelZeroTexture.get(), - D3D11CalcSubresource(0, face, 1), 0, 0, 0, - mTexture.get(), face * mMipLevels, nullptr); - } - } - - mUseLevelZeroTexture = true; - } - else - { - if (mUseLevelZeroTexture && mLevelZeroTexture.valid()) - { - ANGLE_TRY(ensureTextureExists(mMipLevels)); - - // Pull data back from the level zero texture if necessary. - ASSERT(mTexture.valid()); - ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); - - for (int face = 0; face < 6; face++) - { - deviceContext->CopySubresourceRegion(mTexture.get(), - D3D11CalcSubresource(0, face, mMipLevels), 0, - 0, 0, mLevelZeroTexture.get(), face, nullptr); - } - } - - mUseLevelZeroTexture = false; - } - - return gl::NoError(); -} - -void TextureStorage11_Cube::associateImage(Image11 *image, const gl::ImageIndex &index) -{ - const GLint level = index.mipIndex; - const GLint layerTarget = index.layerIndex; - - ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS); - ASSERT(0 <= layerTarget && layerTarget < static_cast<GLint>(gl::CUBE_FACE_COUNT)); - - if (0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) - { - if (0 <= layerTarget && layerTarget < static_cast<GLint>(gl::CUBE_FACE_COUNT)) - { - mAssociatedImages[layerTarget][level] = image; - } - } -} - -void TextureStorage11_Cube::verifyAssociatedImageValid(const gl::ImageIndex &index, - Image11 *expectedImage) -{ - const GLint level = index.mipIndex; - const GLint layerTarget = index.layerIndex; - - ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS); - ASSERT(0 <= layerTarget && layerTarget < static_cast<GLint>(gl::CUBE_FACE_COUNT)); - // This validation check should never return false. It means the Image/TextureStorage - // association is broken. - ASSERT(mAssociatedImages[layerTarget][level] == expectedImage); -} - -// disassociateImage allows an Image to end its association with a Storage. -void TextureStorage11_Cube::disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) -{ - const GLint level = index.mipIndex; - const GLint layerTarget = index.layerIndex; - - ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS); - ASSERT(0 <= layerTarget && layerTarget < static_cast<GLint>(gl::CUBE_FACE_COUNT)); - ASSERT(mAssociatedImages[layerTarget][level] == expectedImage); - mAssociatedImages[layerTarget][level] = nullptr; -} - -// releaseAssociatedImage prepares the Storage for a new Image association. It lets the old Image -// recover its data before ending the association. -gl::Error TextureStorage11_Cube::releaseAssociatedImage(const gl::Context *context, - const gl::ImageIndex &index, - Image11 *incomingImage) -{ - const GLint level = index.mipIndex; - const GLint layerTarget = index.layerIndex; - - ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS); - ASSERT(0 <= layerTarget && layerTarget < static_cast<GLint>(gl::CUBE_FACE_COUNT)); - - if ((0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)) - { - if (0 <= layerTarget && layerTarget < static_cast<GLint>(gl::CUBE_FACE_COUNT)) - { - // No need to let the old Image recover its data, if it is also the incoming Image. - if (mAssociatedImages[layerTarget][level] != nullptr && - mAssociatedImages[layerTarget][level] != incomingImage) - { - // Ensure that the Image is still associated with this TextureStorage. - mAssociatedImages[layerTarget][level]->verifyAssociatedStorageValid(this); - - // Force the image to recover from storage before its data is overwritten. - // This will reset mAssociatedImages[level] to nullptr too. - ANGLE_TRY( - mAssociatedImages[layerTarget][level]->recoverFromAssociatedStorage(context)); - } - } - } - - return gl::NoError(); -} - -gl::Error TextureStorage11_Cube::getResource(const gl::Context *context, - const TextureHelper11 **outResource) -{ - if (mUseLevelZeroTexture && mMipLevels > 1) - { - ANGLE_TRY(ensureTextureExists(1)); - *outResource = &mLevelZeroTexture; - return gl::NoError(); - } - else - { - ANGLE_TRY(ensureTextureExists(mMipLevels)); - *outResource = &mTexture; - return gl::NoError(); - } -} - -gl::Error TextureStorage11_Cube::getMippedResource(const gl::Context *context, - const TextureHelper11 **outResource) -{ - // This shouldn't be called unless the zero max LOD workaround is active. - ASSERT(mRenderer->getWorkarounds().zeroMaxLodWorkaround); - - ANGLE_TRY(ensureTextureExists(mMipLevels)); - *outResource = &mTexture; - return gl::NoError(); -} - -gl::Error TextureStorage11_Cube::ensureTextureExists(int mipLevels) -{ - // If mMipLevels = 1 then always use mTexture rather than mLevelZeroTexture. - bool useLevelZeroTexture = mRenderer->getWorkarounds().zeroMaxLodWorkaround - ? (mipLevels == 1) && (mMipLevels > 1) - : false; - TextureHelper11 *outputTexture = useLevelZeroTexture ? &mLevelZeroTexture : &mTexture; - - // if the size is not positive this should be treated as an incomplete texture - // we handle that here by skipping the d3d texture creation - if (!outputTexture->valid() && mTextureWidth > 0 && mTextureHeight > 0) - { - ASSERT(mMipLevels > 0); - - D3D11_TEXTURE2D_DESC desc; - desc.Width = mTextureWidth; - desc.Height = mTextureHeight; - desc.MipLevels = mipLevels; - desc.ArraySize = gl::CUBE_FACE_COUNT; - desc.Format = mFormatInfo.texFormat; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = getBindFlags(); - desc.CPUAccessFlags = 0; - desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE | getMiscFlags(); - - ANGLE_TRY(mRenderer->allocateTexture(desc, mFormatInfo, outputTexture)); - outputTexture->setDebugName("TexStorageCube.Texture"); - } - - return gl::NoError(); -} - -gl::Error TextureStorage11_Cube::createRenderTargetSRV(const TextureHelper11 &texture, - const gl::ImageIndex &index, - DXGI_FORMAT resourceFormat, - d3d11::SharedSRV *srv) const -{ - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - srvDesc.Format = resourceFormat; - srvDesc.Texture2DArray.MostDetailedMip = mTopLevel + index.mipIndex; - srvDesc.Texture2DArray.MipLevels = 1; - srvDesc.Texture2DArray.FirstArraySlice = index.layerIndex; - srvDesc.Texture2DArray.ArraySize = 1; - - if (mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_10_0) - { - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; - } - else - { - // Will be used with Texture2D sampler, not TextureCube - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; - } - - ANGLE_TRY(mRenderer->allocateResource(srvDesc, texture.get(), srv)); - return gl::NoError(); -} - -gl::Error TextureStorage11_Cube::getRenderTarget(const gl::Context *context, - const gl::ImageIndex &index, - RenderTargetD3D **outRT) -{ - const int faceIndex = index.layerIndex; - const int level = index.mipIndex; - - ASSERT(level >= 0 && level < getLevelCount()); - ASSERT(faceIndex >= 0 && faceIndex < static_cast<GLint>(gl::CUBE_FACE_COUNT)); - - if (!mRenderTarget[faceIndex][level]) - { - if (mRenderer->getWorkarounds().zeroMaxLodWorkaround) - { - ASSERT(index.mipIndex == 0); - ANGLE_TRY(useLevelZeroWorkaroundTexture(context, true)); - } - - const TextureHelper11 *texture = nullptr; - ANGLE_TRY(getResource(context, &texture)); - - if (mUseLevelZeroTexture) - { - if (!mLevelZeroRenderTarget[faceIndex]) - { - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - rtvDesc.Format = mFormatInfo.rtvFormat; - rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; - rtvDesc.Texture2DArray.MipSlice = mTopLevel + level; - rtvDesc.Texture2DArray.FirstArraySlice = faceIndex; - rtvDesc.Texture2DArray.ArraySize = 1; - - d3d11::RenderTargetView rtv; - ANGLE_TRY(mRenderer->allocateResource(rtvDesc, mLevelZeroTexture.get(), &rtv)); - - mLevelZeroRenderTarget[faceIndex].reset(new TextureRenderTarget11( - std::move(rtv), mLevelZeroTexture, d3d11::SharedSRV(), d3d11::SharedSRV(), - mFormatInfo.internalFormat, getFormatSet(), getLevelWidth(level), - getLevelHeight(level), 1, 0)); - } - - ASSERT(outRT); - *outRT = mLevelZeroRenderTarget[faceIndex].get(); - return gl::NoError(); - } - - d3d11::SharedSRV srv; - ANGLE_TRY(createRenderTargetSRV(*texture, index, mFormatInfo.srvFormat, &srv)); - d3d11::SharedSRV blitSRV; - if (mFormatInfo.blitSRVFormat != mFormatInfo.srvFormat) - { - ANGLE_TRY(createRenderTargetSRV(*texture, index, mFormatInfo.blitSRVFormat, &blitSRV)); - } - else - { - blitSRV = srv.makeCopy(); - } - - srv.setDebugName("TexStorageCube.RenderTargetSRV"); - - if (mFormatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN) - { - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - rtvDesc.Format = mFormatInfo.rtvFormat; - rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; - rtvDesc.Texture2DArray.MipSlice = mTopLevel + level; - rtvDesc.Texture2DArray.FirstArraySlice = faceIndex; - rtvDesc.Texture2DArray.ArraySize = 1; - - d3d11::RenderTargetView rtv; - ANGLE_TRY(mRenderer->allocateResource(rtvDesc, texture->get(), &rtv)); - rtv.setDebugName("TexStorageCube.RenderTargetRTV"); - - mRenderTarget[faceIndex][level].reset(new TextureRenderTarget11( - std::move(rtv), *texture, srv, blitSRV, mFormatInfo.internalFormat, getFormatSet(), - getLevelWidth(level), getLevelHeight(level), 1, 0)); - } - else if (mFormatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN) - { - D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; - dsvDesc.Format = mFormatInfo.dsvFormat; - dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY; - dsvDesc.Flags = 0; - dsvDesc.Texture2DArray.MipSlice = mTopLevel + level; - dsvDesc.Texture2DArray.FirstArraySlice = faceIndex; - dsvDesc.Texture2DArray.ArraySize = 1; - - d3d11::DepthStencilView dsv; - ANGLE_TRY(mRenderer->allocateResource(dsvDesc, texture->get(), &dsv)); - dsv.setDebugName("TexStorageCube.RenderTargetDSV"); - - mRenderTarget[faceIndex][level].reset(new TextureRenderTarget11( - std::move(dsv), *texture, srv, mFormatInfo.internalFormat, getFormatSet(), - getLevelWidth(level), getLevelHeight(level), 1, 0)); - } - else - { - UNREACHABLE(); - } - } - - ASSERT(outRT); - *outRT = mRenderTarget[faceIndex][level].get(); - return gl::NoError(); -} - -gl::Error TextureStorage11_Cube::createSRV(const gl::Context *context, - int baseLevel, - int mipLevels, - DXGI_FORMAT format, - const TextureHelper11 &texture, - d3d11::SharedSRV *outSRV) -{ - ASSERT(outSRV); - - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - srvDesc.Format = format; - - // Unnormalized integer cube maps are not supported by DX11; we emulate them as an array of six - // 2D textures - const GLenum componentType = d3d11::GetComponentType(format); - if (componentType == GL_INT || componentType == GL_UNSIGNED_INT) - { - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; - srvDesc.Texture2DArray.MostDetailedMip = mTopLevel + baseLevel; - srvDesc.Texture2DArray.MipLevels = mipLevels; - srvDesc.Texture2DArray.FirstArraySlice = 0; - srvDesc.Texture2DArray.ArraySize = gl::CUBE_FACE_COUNT; - } - else - { - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; - srvDesc.TextureCube.MipLevels = mipLevels; - srvDesc.TextureCube.MostDetailedMip = mTopLevel + baseLevel; - } - - const TextureHelper11 *srvTexture = &texture; - - if (mRenderer->getWorkarounds().zeroMaxLodWorkaround) - { - ASSERT(mTopLevel == 0); - ASSERT(baseLevel == 0); - // This code also assumes that the incoming texture equals either mLevelZeroTexture or - // mTexture. - - if (mipLevels == 1 && mMipLevels > 1) - { - // We must use a SRV on the level-zero-only texture. - ANGLE_TRY(ensureTextureExists(1)); - srvTexture = &mLevelZeroTexture; - } - else - { - ASSERT(mipLevels == static_cast<int>(mMipLevels)); - ASSERT(mTexture.valid() && texture == mTexture); - srvTexture = &mTexture; - } - } - - ANGLE_TRY(mRenderer->allocateResource(srvDesc, srvTexture->get(), outSRV)); - outSRV->setDebugName("TexStorageCube.SRV"); - - return gl::NoError(); -} - -gl::Error TextureStorage11_Cube::getSwizzleTexture(const TextureHelper11 **outTexture) -{ - ASSERT(outTexture); - - if (!mSwizzleTexture.valid()) - { - const auto &format = mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()); - - D3D11_TEXTURE2D_DESC desc; - desc.Width = mTextureWidth; - desc.Height = mTextureHeight; - desc.MipLevels = mMipLevels; - desc.ArraySize = gl::CUBE_FACE_COUNT; - desc.Format = format.texFormat; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; - desc.CPUAccessFlags = 0; - desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE; - - ANGLE_TRY(mRenderer->allocateTexture(desc, format, &mSwizzleTexture)); - mSwizzleTexture.setDebugName("TexStorageCube.SwizzleTexture"); - } - - *outTexture = &mSwizzleTexture; - return gl::NoError(); -} - -gl::Error TextureStorage11_Cube::getSwizzleRenderTarget(int mipLevel, - const d3d11::RenderTargetView **outRTV) -{ - ASSERT(mipLevel >= 0 && mipLevel < getLevelCount()); - ASSERT(outRTV); - - if (!mSwizzleRenderTargets[mipLevel].valid()) - { - const TextureHelper11 *swizzleTexture = nullptr; - ANGLE_TRY(getSwizzleTexture(&swizzleTexture)); - - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - rtvDesc.Format = - mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()).rtvFormat; - rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; - rtvDesc.Texture2DArray.MipSlice = mTopLevel + mipLevel; - rtvDesc.Texture2DArray.FirstArraySlice = 0; - rtvDesc.Texture2DArray.ArraySize = gl::CUBE_FACE_COUNT; - - ANGLE_TRY(mRenderer->allocateResource(rtvDesc, mSwizzleTexture.get(), - &mSwizzleRenderTargets[mipLevel])); - } - - *outRTV = &mSwizzleRenderTargets[mipLevel]; - return gl::NoError(); -} - -gl::Error TextureStorage11::initDropStencilTexture(const gl::Context *context, - const gl::ImageIndexIterator &it) -{ - const TextureHelper11 *sourceTexture = nullptr; - ANGLE_TRY(getResource(context, &sourceTexture)); - - gl::ImageIndexIterator itCopy = it; - - while (itCopy.hasNext()) - { - gl::ImageIndex index = itCopy.next(); - gl::Box wholeArea(0, 0, 0, getLevelWidth(index.mipIndex), getLevelHeight(index.mipIndex), - 1); - gl::Extents wholeSize(wholeArea.width, wholeArea.height, 1); - UINT subresource = getSubresourceIndex(index); - ANGLE_TRY(mRenderer->getBlitter()->copyDepthStencil( - *sourceTexture, subresource, wholeArea, wholeSize, mDropStencilTexture, subresource, - wholeArea, wholeSize, nullptr)); - } - - return gl::NoError(); -} - -gl::ErrorOrResult<TextureStorage11::DropStencil> TextureStorage11_Cube::ensureDropStencilTexture( - const gl::Context *context) -{ - if (mDropStencilTexture.valid()) - { - return DropStencil::ALREADY_EXISTS; - } - - D3D11_TEXTURE2D_DESC dropDesc = {}; - dropDesc.ArraySize = 6; - dropDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL; - dropDesc.CPUAccessFlags = 0; - dropDesc.Format = DXGI_FORMAT_R32_TYPELESS; - dropDesc.Height = mTextureHeight; - dropDesc.MipLevels = mMipLevels; - dropDesc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE; - dropDesc.SampleDesc.Count = 1; - dropDesc.SampleDesc.Quality = 0; - dropDesc.Usage = D3D11_USAGE_DEFAULT; - dropDesc.Width = mTextureWidth; - - const auto &format = - d3d11::Format::Get(GL_DEPTH_COMPONENT32F, mRenderer->getRenderer11DeviceCaps()); - ANGLE_TRY(mRenderer->allocateTexture(dropDesc, format, &mDropStencilTexture)); - mDropStencilTexture.setDebugName("TexStorageCube.DropStencil"); - - ANGLE_TRY(initDropStencilTexture(context, gl::ImageIndexIterator::MakeCube(0, mMipLevels))); - - return DropStencil::CREATED; -} - -TextureStorage11_3D::TextureStorage11_3D(Renderer11 *renderer, - GLenum internalformat, - bool renderTarget, - GLsizei width, - GLsizei height, - GLsizei depth, - int levels) - : TextureStorage11( - renderer, - GetTextureBindFlags(internalformat, renderer->getRenderer11DeviceCaps(), renderTarget), - GetTextureMiscFlags(internalformat, - renderer->getRenderer11DeviceCaps(), - renderTarget, - levels), - internalformat) -{ - for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++) - { - mAssociatedImages[i] = nullptr; - mLevelRenderTargets[i] = nullptr; - } - - // adjust size if needed for compressed textures - d3d11::MakeValidSize(false, mFormatInfo.texFormat, &width, &height, &mTopLevel); - - mMipLevels = mTopLevel + levels; - mTextureWidth = width; - mTextureHeight = height; - mTextureDepth = depth; -} - -gl::Error TextureStorage11_3D::onDestroy(const gl::Context *context) -{ - for (unsigned i = 0; i < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++) - { - if (mAssociatedImages[i] != nullptr) - { - mAssociatedImages[i]->verifyAssociatedStorageValid(this); - - // We must let the Images recover their data before we delete it from the - // TextureStorage. - ANGLE_TRY(mAssociatedImages[i]->recoverFromAssociatedStorage(context)); - } - } - - InvalidateRenderTargetContainer(context, &mLevelRenderTargets); - InvalidateRenderTargetContainer(context, &mLevelLayerRenderTargets); - - return gl::NoError(); -} - -TextureStorage11_3D::~TextureStorage11_3D() -{ -} - -void TextureStorage11_3D::associateImage(Image11 *image, const gl::ImageIndex &index) -{ - const GLint level = index.mipIndex; - - ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS); - - if (0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) - { - mAssociatedImages[level] = image; - } -} - -void TextureStorage11_3D::verifyAssociatedImageValid(const gl::ImageIndex &index, - Image11 *expectedImage) -{ - const GLint level = index.mipIndex; - - ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS); - // This validation check should never return false. It means the Image/TextureStorage - // association is broken. - ASSERT(mAssociatedImages[level] == expectedImage); -} - -// disassociateImage allows an Image to end its association with a Storage. -void TextureStorage11_3D::disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) -{ - const GLint level = index.mipIndex; - - ASSERT(0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS); - ASSERT(mAssociatedImages[level] == expectedImage); - mAssociatedImages[level] = nullptr; -} - -// releaseAssociatedImage prepares the Storage for a new Image association. It lets the old Image -// recover its data before ending the association. -gl::Error TextureStorage11_3D::releaseAssociatedImage(const gl::Context *context, - const gl::ImageIndex &index, - Image11 *incomingImage) -{ - const GLint level = index.mipIndex; - - ASSERT((0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)); - - if (0 <= level && level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) - { - // No need to let the old Image recover its data, if it is also the incoming Image. - if (mAssociatedImages[level] != nullptr && mAssociatedImages[level] != incomingImage) - { - // Ensure that the Image is still associated with this TextureStorage. - mAssociatedImages[level]->verifyAssociatedStorageValid(this); - - // Force the image to recover from storage before its data is overwritten. - // This will reset mAssociatedImages[level] to nullptr too. - ANGLE_TRY(mAssociatedImages[level]->recoverFromAssociatedStorage(context)); - } - } - - return gl::NoError(); -} - -gl::Error TextureStorage11_3D::getResource(const gl::Context *context, - const TextureHelper11 **outResource) -{ - // 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. - if (!mTexture.valid() && mTextureWidth > 0 && mTextureHeight > 0 && mTextureDepth > 0) - { - ASSERT(mMipLevels > 0); - - D3D11_TEXTURE3D_DESC desc; - desc.Width = mTextureWidth; - desc.Height = mTextureHeight; - desc.Depth = mTextureDepth; - desc.MipLevels = mMipLevels; - desc.Format = mFormatInfo.texFormat; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = getBindFlags(); - desc.CPUAccessFlags = 0; - desc.MiscFlags = getMiscFlags(); - - ANGLE_TRY(mRenderer->allocateTexture(desc, mFormatInfo, &mTexture)); - mTexture.setDebugName("TexStorage3D.Texture"); - } - - *outResource = &mTexture; - return gl::NoError(); -} - -gl::Error TextureStorage11_3D::createSRV(const gl::Context *context, - int baseLevel, - int mipLevels, - DXGI_FORMAT format, - const TextureHelper11 &texture, - d3d11::SharedSRV *outSRV) -{ - ASSERT(outSRV); - - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - srvDesc.Format = format; - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; - srvDesc.Texture3D.MostDetailedMip = baseLevel; - srvDesc.Texture3D.MipLevels = mipLevels; - - ANGLE_TRY(mRenderer->allocateResource(srvDesc, texture.get(), outSRV)); - outSRV->setDebugName("TexStorage3D.SRV"); - - return gl::NoError(); -} - -gl::Error TextureStorage11_3D::getRenderTarget(const gl::Context *context, - const gl::ImageIndex &index, - RenderTargetD3D **outRT) -{ - const int mipLevel = index.mipIndex; - ASSERT(mipLevel >= 0 && mipLevel < getLevelCount()); - - ASSERT(mFormatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN); - - if (!index.hasLayer()) - { - if (!mLevelRenderTargets[mipLevel]) - { - const TextureHelper11 *texture = nullptr; - ANGLE_TRY(getResource(context, &texture)); - - const d3d11::SharedSRV *srv = nullptr; - ANGLE_TRY(getSRVLevel(context, mipLevel, false, &srv)); - - const d3d11::SharedSRV *blitSRV = nullptr; - ANGLE_TRY(getSRVLevel(context, mipLevel, true, &blitSRV)); - - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - rtvDesc.Format = mFormatInfo.rtvFormat; - rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D; - rtvDesc.Texture3D.MipSlice = mTopLevel + mipLevel; - rtvDesc.Texture3D.FirstWSlice = 0; - rtvDesc.Texture3D.WSize = static_cast<UINT>(-1); - - d3d11::RenderTargetView rtv; - ANGLE_TRY(mRenderer->allocateResource(rtvDesc, texture->get(), &rtv)); - rtv.setDebugName("TexStorage3D.RTV"); - - mLevelRenderTargets[mipLevel].reset(new TextureRenderTarget11( - std::move(rtv), *texture, *srv, *blitSRV, mFormatInfo.internalFormat, - getFormatSet(), getLevelWidth(mipLevel), getLevelHeight(mipLevel), - getLevelDepth(mipLevel), 0)); - } - - ASSERT(outRT); - *outRT = mLevelRenderTargets[mipLevel].get(); - return gl::NoError(); - } - - const int layer = index.layerIndex; - - LevelLayerKey key(mipLevel, layer); - if (mLevelLayerRenderTargets.find(key) == mLevelLayerRenderTargets.end()) - { - const TextureHelper11 *texture = nullptr; - ANGLE_TRY(getResource(context, &texture)); - - // TODO, what kind of SRV is expected here? - const d3d11::SharedSRV srv; - const d3d11::SharedSRV blitSRV; - - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - rtvDesc.Format = mFormatInfo.rtvFormat; - rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D; - rtvDesc.Texture3D.MipSlice = mTopLevel + mipLevel; - rtvDesc.Texture3D.FirstWSlice = layer; - rtvDesc.Texture3D.WSize = 1; - - d3d11::RenderTargetView rtv; - ANGLE_TRY(mRenderer->allocateResource(rtvDesc, texture->get(), &rtv)); - rtv.setDebugName("TexStorage3D.LayerRTV"); - - mLevelLayerRenderTargets[key].reset(new TextureRenderTarget11( - std::move(rtv), *texture, srv, blitSRV, mFormatInfo.internalFormat, getFormatSet(), - getLevelWidth(mipLevel), getLevelHeight(mipLevel), 1, 0)); - } - - ASSERT(outRT); - *outRT = mLevelLayerRenderTargets[key].get(); - return gl::NoError(); -} - -gl::Error TextureStorage11_3D::getSwizzleTexture(const TextureHelper11 **outTexture) -{ - ASSERT(outTexture); - - if (!mSwizzleTexture.valid()) - { - const auto &format = mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()); - - D3D11_TEXTURE3D_DESC desc; - desc.Width = mTextureWidth; - desc.Height = mTextureHeight; - desc.Depth = mTextureDepth; - desc.MipLevels = mMipLevels; - desc.Format = format.texFormat; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; - desc.CPUAccessFlags = 0; - desc.MiscFlags = 0; - - ANGLE_TRY(mRenderer->allocateTexture(desc, format, &mSwizzleTexture)); - mSwizzleTexture.setDebugName("TexStorage3D.SwizzleTexture"); - } - - *outTexture = &mSwizzleTexture; - return gl::NoError(); -} - -gl::Error TextureStorage11_3D::getSwizzleRenderTarget(int mipLevel, - const d3d11::RenderTargetView **outRTV) -{ - ASSERT(mipLevel >= 0 && mipLevel < getLevelCount()); - ASSERT(outRTV); - - if (!mSwizzleRenderTargets[mipLevel].valid()) - { - const TextureHelper11 *swizzleTexture = nullptr; - ANGLE_TRY(getSwizzleTexture(&swizzleTexture)); - - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - rtvDesc.Format = - mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()).rtvFormat; - rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D; - rtvDesc.Texture3D.MipSlice = mTopLevel + mipLevel; - rtvDesc.Texture3D.FirstWSlice = 0; - rtvDesc.Texture3D.WSize = static_cast<UINT>(-1); - - ANGLE_TRY(mRenderer->allocateResource(rtvDesc, mSwizzleTexture.get(), - &mSwizzleRenderTargets[mipLevel])); - mSwizzleRenderTargets[mipLevel].setDebugName("TexStorage3D.SwizzleRTV"); - } - - *outRTV = &mSwizzleRenderTargets[mipLevel]; - return gl::NoError(); -} - -TextureStorage11_2DArray::TextureStorage11_2DArray(Renderer11 *renderer, - GLenum internalformat, - bool renderTarget, - GLsizei width, - GLsizei height, - GLsizei depth, - int levels) - : TextureStorage11( - renderer, - GetTextureBindFlags(internalformat, renderer->getRenderer11DeviceCaps(), renderTarget), - GetTextureMiscFlags(internalformat, - renderer->getRenderer11DeviceCaps(), - renderTarget, - levels), - internalformat) -{ - // adjust size if needed for compressed textures - d3d11::MakeValidSize(false, mFormatInfo.texFormat, &width, &height, &mTopLevel); - - mMipLevels = mTopLevel + levels; - mTextureWidth = width; - mTextureHeight = height; - mTextureDepth = depth; -} - -gl::Error TextureStorage11_2DArray::onDestroy(const gl::Context *context) -{ - for (auto iter : mAssociatedImages) - { - if (iter.second) - { - iter.second->verifyAssociatedStorageValid(this); - - // We must let the Images recover their data before we delete it from the - // TextureStorage. - ANGLE_TRY(iter.second->recoverFromAssociatedStorage(context)); - } - } - mAssociatedImages.clear(); - - InvalidateRenderTargetContainer(context, &mRenderTargets); - - return gl::NoError(); -} - -TextureStorage11_2DArray::~TextureStorage11_2DArray() -{ -} - -void TextureStorage11_2DArray::associateImage(Image11 *image, const gl::ImageIndex &index) -{ - const GLint level = index.mipIndex; - const GLint layerTarget = index.layerIndex; - const GLint numLayers = index.numLayers; - - ASSERT(0 <= level && level < getLevelCount()); - - if (0 <= level && level < getLevelCount()) - { - LevelLayerRangeKey key(level, layerTarget, numLayers); - mAssociatedImages[key] = image; - } -} - -void TextureStorage11_2DArray::verifyAssociatedImageValid(const gl::ImageIndex &index, - Image11 *expectedImage) -{ - const GLint level = index.mipIndex; - const GLint layerTarget = index.layerIndex; - const GLint numLayers = index.numLayers; - - LevelLayerRangeKey key(level, layerTarget, numLayers); - - // This validation check should never return false. It means the Image/TextureStorage - // association is broken. - bool retValue = (mAssociatedImages.find(key) != mAssociatedImages.end() && - (mAssociatedImages[key] == expectedImage)); - ASSERT(retValue); -} - -// disassociateImage allows an Image to end its association with a Storage. -void TextureStorage11_2DArray::disassociateImage(const gl::ImageIndex &index, - Image11 *expectedImage) -{ - const GLint level = index.mipIndex; - const GLint layerTarget = index.layerIndex; - const GLint numLayers = index.numLayers; - - LevelLayerRangeKey key(level, layerTarget, numLayers); - - bool imageAssociationCorrect = (mAssociatedImages.find(key) != mAssociatedImages.end() && - (mAssociatedImages[key] == expectedImage)); - ASSERT(imageAssociationCorrect); - mAssociatedImages[key] = nullptr; -} - -// releaseAssociatedImage prepares the Storage for a new Image association. It lets the old Image -// recover its data before ending the association. -gl::Error TextureStorage11_2DArray::releaseAssociatedImage(const gl::Context *context, - const gl::ImageIndex &index, - Image11 *incomingImage) -{ - const GLint level = index.mipIndex; - const GLint layerTarget = index.layerIndex; - const GLint numLayers = index.numLayers; - - LevelLayerRangeKey key(level, layerTarget, numLayers); - - if (mAssociatedImages.find(key) != mAssociatedImages.end()) - { - if (mAssociatedImages[key] != nullptr && mAssociatedImages[key] != incomingImage) - { - // Ensure that the Image is still associated with this TextureStorage. - mAssociatedImages[key]->verifyAssociatedStorageValid(this); - - // Force the image to recover from storage before its data is overwritten. - // This will reset mAssociatedImages[level] to nullptr too. - ANGLE_TRY(mAssociatedImages[key]->recoverFromAssociatedStorage(context)); - } - } - - return gl::NoError(); -} - -gl::Error TextureStorage11_2DArray::getResource(const gl::Context *context, - const TextureHelper11 **outResource) -{ - // 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 - if (!mTexture.valid() && mTextureWidth > 0 && mTextureHeight > 0 && mTextureDepth > 0) - { - ASSERT(mMipLevels > 0); - - D3D11_TEXTURE2D_DESC desc; - desc.Width = mTextureWidth; - desc.Height = mTextureHeight; - desc.MipLevels = mMipLevels; - desc.ArraySize = mTextureDepth; - desc.Format = mFormatInfo.texFormat; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = getBindFlags(); - desc.CPUAccessFlags = 0; - desc.MiscFlags = getMiscFlags(); - - ANGLE_TRY(mRenderer->allocateTexture(desc, mFormatInfo, &mTexture)); - mTexture.setDebugName("TexStorage2DArray.Texture"); - } - - *outResource = &mTexture; - return gl::NoError(); -} - -gl::Error TextureStorage11_2DArray::createSRV(const gl::Context *context, - int baseLevel, - int mipLevels, - DXGI_FORMAT format, - const TextureHelper11 &texture, - d3d11::SharedSRV *outSRV) -{ - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - srvDesc.Format = format; - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; - srvDesc.Texture2DArray.MostDetailedMip = mTopLevel + baseLevel; - srvDesc.Texture2DArray.MipLevels = mipLevels; - srvDesc.Texture2DArray.FirstArraySlice = 0; - srvDesc.Texture2DArray.ArraySize = mTextureDepth; - - ANGLE_TRY(mRenderer->allocateResource(srvDesc, texture.get(), outSRV)); - outSRV->setDebugName("TexStorage2DArray.SRV"); - - return gl::NoError(); -} - -gl::Error TextureStorage11_2DArray::createRenderTargetSRV(const TextureHelper11 &texture, - const gl::ImageIndex &index, - DXGI_FORMAT resourceFormat, - d3d11::SharedSRV *srv) const -{ - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - srvDesc.Format = resourceFormat; - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; - srvDesc.Texture2DArray.MostDetailedMip = mTopLevel + index.mipIndex; - srvDesc.Texture2DArray.MipLevels = 1; - srvDesc.Texture2DArray.FirstArraySlice = index.layerIndex; - srvDesc.Texture2DArray.ArraySize = index.numLayers; - - ANGLE_TRY(mRenderer->allocateResource(srvDesc, texture.get(), srv)); - - return gl::NoError(); -} - -gl::Error TextureStorage11_2DArray::getRenderTarget(const gl::Context *context, - const gl::ImageIndex &index, - RenderTargetD3D **outRT) -{ - ASSERT(index.hasLayer()); - - const int mipLevel = index.mipIndex; - const int layer = index.layerIndex; - const int numLayers = index.numLayers; - - ASSERT(mipLevel >= 0 && mipLevel < getLevelCount()); - - LevelLayerRangeKey key(mipLevel, layer, numLayers); - if (mRenderTargets.find(key) == mRenderTargets.end()) - { - const TextureHelper11 *texture = nullptr; - ANGLE_TRY(getResource(context, &texture)); - d3d11::SharedSRV srv; - ANGLE_TRY(createRenderTargetSRV(*texture, index, mFormatInfo.srvFormat, &srv)); - d3d11::SharedSRV blitSRV; - if (mFormatInfo.blitSRVFormat != mFormatInfo.srvFormat) - { - ANGLE_TRY(createRenderTargetSRV(*texture, index, mFormatInfo.blitSRVFormat, &blitSRV)); - } - else - { - blitSRV = srv.makeCopy(); - } - - srv.setDebugName("TexStorage2DArray.RenderTargetSRV"); - - if (mFormatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN) - { - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - rtvDesc.Format = mFormatInfo.rtvFormat; - rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; - rtvDesc.Texture2DArray.MipSlice = mTopLevel + mipLevel; - rtvDesc.Texture2DArray.FirstArraySlice = layer; - rtvDesc.Texture2DArray.ArraySize = numLayers; - - d3d11::RenderTargetView rtv; - ANGLE_TRY(mRenderer->allocateResource(rtvDesc, texture->get(), &rtv)); - rtv.setDebugName("TexStorage2DArray.RenderTargetRTV"); - - mRenderTargets[key].reset(new TextureRenderTarget11( - std::move(rtv), *texture, srv, blitSRV, mFormatInfo.internalFormat, getFormatSet(), - getLevelWidth(mipLevel), getLevelHeight(mipLevel), 1, 0)); - } - else - { - ASSERT(mFormatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN); - - D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; - dsvDesc.Format = mFormatInfo.dsvFormat; - dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY; - dsvDesc.Texture2DArray.MipSlice = mTopLevel + mipLevel; - dsvDesc.Texture2DArray.FirstArraySlice = layer; - dsvDesc.Texture2DArray.ArraySize = numLayers; - dsvDesc.Flags = 0; - - d3d11::DepthStencilView dsv; - ANGLE_TRY(mRenderer->allocateResource(dsvDesc, texture->get(), &dsv)); - dsv.setDebugName("TexStorage2DArray.RenderTargetDSV"); - - mRenderTargets[key].reset(new TextureRenderTarget11( - std::move(dsv), *texture, srv, mFormatInfo.internalFormat, getFormatSet(), - getLevelWidth(mipLevel), getLevelHeight(mipLevel), 1, 0)); - } - } - - ASSERT(outRT); - *outRT = mRenderTargets[key].get(); - return gl::NoError(); -} - -gl::Error TextureStorage11_2DArray::getSwizzleTexture(const TextureHelper11 **outTexture) -{ - if (!mSwizzleTexture.valid()) - { - const auto &format = mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()); - - D3D11_TEXTURE2D_DESC desc; - desc.Width = mTextureWidth; - desc.Height = mTextureHeight; - desc.MipLevels = mMipLevels; - desc.ArraySize = mTextureDepth; - desc.Format = format.texFormat; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; - desc.CPUAccessFlags = 0; - desc.MiscFlags = 0; - - ANGLE_TRY(mRenderer->allocateTexture(desc, format, &mSwizzleTexture)); - mSwizzleTexture.setDebugName("TexStorage2DArray.SwizzleTexture"); - } - - *outTexture = &mSwizzleTexture; - return gl::NoError(); -} - -gl::Error TextureStorage11_2DArray::getSwizzleRenderTarget(int mipLevel, - const d3d11::RenderTargetView **outRTV) -{ - ASSERT(mipLevel >= 0 && mipLevel < getLevelCount()); - ASSERT(outRTV); - - if (!mSwizzleRenderTargets[mipLevel].valid()) - { - const TextureHelper11 *swizzleTexture = nullptr; - ANGLE_TRY(getSwizzleTexture(&swizzleTexture)); - - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - rtvDesc.Format = - mFormatInfo.getSwizzleFormat(mRenderer->getRenderer11DeviceCaps()).rtvFormat; - rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; - rtvDesc.Texture2DArray.MipSlice = mTopLevel + mipLevel; - rtvDesc.Texture2DArray.FirstArraySlice = 0; - rtvDesc.Texture2DArray.ArraySize = mTextureDepth; - - ANGLE_TRY(mRenderer->allocateResource(rtvDesc, mSwizzleTexture.get(), - &mSwizzleRenderTargets[mipLevel])); - } - - *outRTV = &mSwizzleRenderTargets[mipLevel]; - return gl::NoError(); -} - -gl::ErrorOrResult<TextureStorage11::DropStencil> TextureStorage11_2DArray::ensureDropStencilTexture( - const gl::Context *context) -{ - if (mDropStencilTexture.valid()) - { - return DropStencil::ALREADY_EXISTS; - } - - D3D11_TEXTURE2D_DESC dropDesc = {}; - dropDesc.ArraySize = mTextureDepth; - dropDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL; - dropDesc.CPUAccessFlags = 0; - dropDesc.Format = DXGI_FORMAT_R32_TYPELESS; - dropDesc.Height = mTextureHeight; - dropDesc.MipLevels = mMipLevels; - dropDesc.MiscFlags = 0; - dropDesc.SampleDesc.Count = 1; - dropDesc.SampleDesc.Quality = 0; - dropDesc.Usage = D3D11_USAGE_DEFAULT; - dropDesc.Width = mTextureWidth; - - const auto &format = - d3d11::Format::Get(GL_DEPTH_COMPONENT32F, mRenderer->getRenderer11DeviceCaps()); - ANGLE_TRY(mRenderer->allocateTexture(dropDesc, format, &mDropStencilTexture)); - mDropStencilTexture.setDebugName("TexStorage2DArray.DropStencil"); - - std::vector<GLsizei> layerCounts(mMipLevels, mTextureDepth); - - ANGLE_TRY(initDropStencilTexture( - context, gl::ImageIndexIterator::Make2DArray(0, mMipLevels, layerCounts.data()))); - - return DropStencil::CREATED; -} - -TextureStorage11_2DMultisample::TextureStorage11_2DMultisample(Renderer11 *renderer, - GLenum internalformat, - GLsizei width, - GLsizei height, - int levels, - int samples, - bool fixedSampleLocations) - : TextureStorage11( - renderer, - GetTextureBindFlags(internalformat, renderer->getRenderer11DeviceCaps(), true), - GetTextureMiscFlags(internalformat, renderer->getRenderer11DeviceCaps(), true, levels), - internalformat), - mTexture(), - mRenderTarget(nullptr) -{ - // adjust size if needed for compressed textures - d3d11::MakeValidSize(false, mFormatInfo.texFormat, &width, &height, &mTopLevel); - - mMipLevels = 1; - mTextureWidth = width; - mTextureHeight = height; - mTextureDepth = 1; - mSamples = samples; - mFixedSampleLocations = fixedSampleLocations; -} - -gl::Error TextureStorage11_2DMultisample::onDestroy(const gl::Context *context) -{ - InvalidateRenderTarget(context, mRenderTarget.get()); - mRenderTarget.reset(); - return gl::NoError(); -} - -TextureStorage11_2DMultisample::~TextureStorage11_2DMultisample() -{ -} - -gl::Error TextureStorage11_2DMultisample::copyToStorage(const gl::Context *context, - TextureStorage *destStorage) -{ - UNIMPLEMENTED(); - return gl::InternalError() << "copyToStorage is unimplemented"; -} - -void TextureStorage11_2DMultisample::associateImage(Image11 *image, const gl::ImageIndex &index) -{ -} - -void TextureStorage11_2DMultisample::verifyAssociatedImageValid(const gl::ImageIndex &index, - Image11 *expectedImage) -{ -} - -void TextureStorage11_2DMultisample::disassociateImage(const gl::ImageIndex &index, - Image11 *expectedImage) -{ -} - -gl::Error TextureStorage11_2DMultisample::releaseAssociatedImage(const gl::Context *context, - const gl::ImageIndex &index, - Image11 *incomingImage) -{ - return gl::NoError(); -} - -gl::Error TextureStorage11_2DMultisample::getResource(const gl::Context *context, - const TextureHelper11 **outResource) -{ - ANGLE_TRY(ensureTextureExists(1)); - - *outResource = &mTexture; - return gl::NoError(); -} - -gl::Error TextureStorage11_2DMultisample::ensureTextureExists(int mipLevels) -{ - // For Multisampled textures, mipLevels always equals 1. - ASSERT(mipLevels == 1); - - // 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 - if (!mTexture.valid() && mTextureWidth > 0 && mTextureHeight > 0) - { - D3D11_TEXTURE2D_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Width = mTextureWidth; // Compressed texture size constraints? - desc.Height = mTextureHeight; - desc.MipLevels = mipLevels; - desc.ArraySize = 1; - desc.Format = mFormatInfo.texFormat; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = getBindFlags(); - desc.CPUAccessFlags = 0; - desc.MiscFlags = getMiscFlags(); - - const gl::TextureCaps &textureCaps = - mRenderer->getNativeTextureCaps().get(mFormatInfo.internalFormat); - GLuint supportedSamples = textureCaps.getNearestSamples(mSamples); - desc.SampleDesc.Count = (supportedSamples == 0) ? 1 : supportedSamples; - desc.SampleDesc.Quality = static_cast<UINT>(D3D11_STANDARD_MULTISAMPLE_PATTERN); - - ANGLE_TRY(mRenderer->allocateTexture(desc, mFormatInfo, &mTexture)); - mTexture.setDebugName("TexStorage2DMS.Texture"); - } - - return gl::NoError(); -} - -gl::Error TextureStorage11_2DMultisample::getRenderTarget(const gl::Context *context, - const gl::ImageIndex &index, - RenderTargetD3D **outRT) -{ - ASSERT(!index.hasLayer()); - - const int level = index.mipIndex; - ASSERT(level == 0); - - ASSERT(outRT); - if (mRenderTarget) - { - *outRT = mRenderTarget.get(); - return gl::NoError(); - } - - const TextureHelper11 *texture = nullptr; - ANGLE_TRY(getResource(context, &texture)); - - const d3d11::SharedSRV *srv = nullptr; - ANGLE_TRY(getSRVLevel(context, level, false, &srv)); - - const d3d11::SharedSRV *blitSRV = nullptr; - ANGLE_TRY(getSRVLevel(context, level, true, &blitSRV)); - - if (mFormatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN) - { - D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; - rtvDesc.Format = mFormatInfo.rtvFormat; - rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS; - - d3d11::RenderTargetView rtv; - ANGLE_TRY(mRenderer->allocateResource(rtvDesc, texture->get(), &rtv)); - - mRenderTarget.reset(new TextureRenderTarget11( - std::move(rtv), *texture, *srv, *blitSRV, mFormatInfo.internalFormat, getFormatSet(), - getLevelWidth(level), getLevelHeight(level), 1, mSamples)); - - *outRT = mRenderTarget.get(); - return gl::NoError(); - } - - ASSERT(mFormatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN); - - D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; - dsvDesc.Format = mFormatInfo.dsvFormat; - dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS; - dsvDesc.Flags = 0; - - d3d11::DepthStencilView dsv; - ANGLE_TRY(mRenderer->allocateResource(dsvDesc, texture->get(), &dsv)); - - mRenderTarget.reset(new TextureRenderTarget11( - std::move(dsv), *texture, *srv, mFormatInfo.internalFormat, getFormatSet(), - getLevelWidth(level), getLevelHeight(level), 1, mSamples)); - - *outRT = mRenderTarget.get(); - return gl::NoError(); -} - -gl::Error TextureStorage11_2DMultisample::createSRV(const gl::Context *context, - int baseLevel, - int mipLevels, - DXGI_FORMAT format, - const TextureHelper11 &texture, - d3d11::SharedSRV *outSRV) -{ - ASSERT(outSRV); - - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - srvDesc.Format = format; - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS; - - ANGLE_TRY(mRenderer->allocateResource(srvDesc, texture.get(), outSRV)); - outSRV->setDebugName("TexStorage2DMS.SRV"); - return gl::NoError(); -} - -gl::Error TextureStorage11_2DMultisample::getSwizzleTexture(const TextureHelper11 **outTexture) -{ - UNIMPLEMENTED(); - return gl::InternalError() << "getSwizzleTexture is unimplemented."; -} - -gl::Error TextureStorage11_2DMultisample::getSwizzleRenderTarget( - int mipLevel, - const d3d11::RenderTargetView **outRTV) -{ - UNIMPLEMENTED(); - return gl::InternalError() << "getSwizzleRenderTarget is unimplemented."; -} - -gl::ErrorOrResult<TextureStorage11::DropStencil> -TextureStorage11_2DMultisample::ensureDropStencilTexture(const gl::Context *context) -{ - UNIMPLEMENTED(); - return gl::InternalError() << "Drop stencil texture not implemented."; -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/TextureStorage11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/TextureStorage11.h deleted file mode 100644 index 336aa495a8..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/TextureStorage11.h +++ /dev/null @@ -1,589 +0,0 @@ -// -// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// TextureStorage11.h: Defines the abstract rx::TextureStorage11 class and its concrete derived -// classes TextureStorage11_2D and TextureStorage11_Cube, which act as the interface to the D3D11 texture. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_TEXTURESTORAGE11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_TEXTURESTORAGE11_H_ - -#include "libANGLE/Error.h" -#include "libANGLE/Texture.h" -#include "libANGLE/renderer/d3d/TextureStorage.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h" - -#include <array> -#include <map> - -namespace gl -{ -struct ImageIndex; -} - -namespace rx -{ -class EGLImageD3D; -class RenderTargetD3D; -class RenderTarget11; -class Renderer11; -class SwapChain11; -class Image11; -struct Renderer11DeviceCaps; - -template <typename T> -using TexLevelArray = std::array<T, gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS>; - -template <typename T> -using CubeFaceArray = std::array<T, gl::CUBE_FACE_COUNT>; - -class TextureStorage11 : public TextureStorage -{ - public: - ~TextureStorage11() override; - - static DWORD GetTextureBindFlags(GLenum internalFormat, const Renderer11DeviceCaps &renderer11DeviceCaps, bool renderTarget); - static DWORD GetTextureMiscFlags(GLenum internalFormat, const Renderer11DeviceCaps &renderer11DeviceCaps, bool renderTarget, int levels); - - UINT getBindFlags() const; - UINT getMiscFlags() const; - const d3d11::Format &getFormatSet() const; - gl::Error getSRVLevels(const gl::Context *context, - GLint baseLevel, - GLint maxLevel, - const d3d11::SharedSRV **outSRV); - gl::Error generateSwizzles(const gl::Context *context, const gl::SwizzleState &swizzleTarget); - void markLevelDirty(int mipLevel); - void markDirty(); - - gl::Error updateSubresourceLevel(const gl::Context *context, - const TextureHelper11 &texture, - unsigned int sourceSubresource, - const gl::ImageIndex &index, - const gl::Box ©Area); - - gl::Error copySubresourceLevel(const gl::Context *context, - const TextureHelper11 &dstTexture, - unsigned int dstSubresource, - const gl::ImageIndex &index, - const gl::Box ®ion); - - // TextureStorage virtual functions - int getTopLevel() const override; - bool isRenderTarget() const override; - bool isManaged() const override; - bool supportsNativeMipmapFunction() const override; - int getLevelCount() const override; - gl::Error generateMipmap(const gl::Context *context, - const gl::ImageIndex &sourceIndex, - const gl::ImageIndex &destIndex) override; - gl::Error copyToStorage(const gl::Context *context, TextureStorage *destStorage) override; - gl::Error setData(const gl::Context *context, - const gl::ImageIndex &index, - ImageD3D *image, - const gl::Box *destBox, - GLenum type, - const gl::PixelUnpackState &unpack, - const uint8_t *pixelData) override; - - virtual gl::Error getSRV(const gl::Context *context, - const gl::TextureState &textureState, - const d3d11::SharedSRV **outSRV); - virtual UINT getSubresourceIndex(const gl::ImageIndex &index) const; - virtual gl::Error getResource(const gl::Context *context, - const TextureHelper11 **outResource) = 0; - virtual void associateImage(Image11* image, const gl::ImageIndex &index) = 0; - virtual void disassociateImage(const gl::ImageIndex &index, Image11* expectedImage) = 0; - virtual void verifyAssociatedImageValid(const gl::ImageIndex &index, - Image11 *expectedImage) = 0; - virtual gl::Error releaseAssociatedImage(const gl::Context *context, - const gl::ImageIndex &index, - Image11 *incomingImage) = 0; - - protected: - TextureStorage11(Renderer11 *renderer, UINT bindFlags, UINT miscFlags, GLenum internalFormat); - int getLevelWidth(int mipLevel) const; - int getLevelHeight(int mipLevel) const; - int getLevelDepth(int mipLevel) const; - - // Some classes (e.g. TextureStorage11_2D) will override getMippedResource. - virtual gl::Error getMippedResource(const gl::Context *context, - const TextureHelper11 **outResource); - - virtual gl::Error getSwizzleTexture(const TextureHelper11 **outTexture) = 0; - virtual gl::Error getSwizzleRenderTarget(int mipLevel, - const d3d11::RenderTargetView **outRTV) = 0; - gl::Error getSRVLevel(const gl::Context *context, - int mipLevel, - bool blitSRV, - const d3d11::SharedSRV **outSRV); - - // Get a version of a depth texture with only depth information, not stencil. - enum DropStencil - { - CREATED, - ALREADY_EXISTS - }; - virtual gl::ErrorOrResult<DropStencil> ensureDropStencilTexture(const gl::Context *context); - gl::Error initDropStencilTexture(const gl::Context *context, const gl::ImageIndexIterator &it); - - // The baseLevel parameter should *not* have mTopLevel applied. - virtual gl::Error createSRV(const gl::Context *context, - int baseLevel, - int mipLevels, - DXGI_FORMAT format, - const TextureHelper11 &texture, - d3d11::SharedSRV *outSRV) = 0; - - void verifySwizzleExists(const gl::SwizzleState &swizzleState); - - // Clear all cached non-swizzle SRVs and invalidate the swizzle cache. - void clearSRVCache(); - - Renderer11 *mRenderer; - int mTopLevel; - unsigned int mMipLevels; - - const d3d11::Format &mFormatInfo; - unsigned int mTextureWidth; - unsigned int mTextureHeight; - unsigned int mTextureDepth; - - TexLevelArray<gl::SwizzleState> mSwizzleCache; - TextureHelper11 mDropStencilTexture; - - private: - const UINT mBindFlags; - const UINT mMiscFlags; - - struct SRVKey - { - SRVKey(int baseLevel, int mipLevels, bool swizzle, bool dropStencil); - - bool operator<(const SRVKey &rhs) const; - - int baseLevel = 0; // Without mTopLevel applied. - int mipLevels = 0; - bool swizzle = false; - bool dropStencil = false; - }; - typedef std::map<SRVKey, d3d11::SharedSRV> SRVCache; - - gl::Error getCachedOrCreateSRV(const gl::Context *context, - const SRVKey &key, - const d3d11::SharedSRV **outSRV); - - SRVCache mSrvCache; - TexLevelArray<d3d11::SharedSRV> mLevelSRVs; - TexLevelArray<d3d11::SharedSRV> mLevelBlitSRVs; -}; - -class TextureStorage11_2D : public TextureStorage11 -{ - public: - TextureStorage11_2D(Renderer11 *renderer, SwapChain11 *swapchain); - TextureStorage11_2D(Renderer11 *renderer, GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, int levels, bool hintLevelZeroOnly = false); - ~TextureStorage11_2D() override; - - gl::Error onDestroy(const gl::Context *context) override; - - gl::Error getResource(const gl::Context *context, const TextureHelper11 **outResource) override; - gl::Error getMippedResource(const gl::Context *context, - const TextureHelper11 **outResource) override; - gl::Error getRenderTarget(const gl::Context *context, - const gl::ImageIndex &index, - RenderTargetD3D **outRT) override; - - gl::Error copyToStorage(const gl::Context *context, TextureStorage *destStorage) override; - - void associateImage(Image11 *image, const gl::ImageIndex &index) override; - void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override; - void verifyAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override; - gl::Error releaseAssociatedImage(const gl::Context *context, - const gl::ImageIndex &index, - Image11 *incomingImage) override; - - gl::Error useLevelZeroWorkaroundTexture(const gl::Context *context, - bool useLevelZeroTexture) override; - - protected: - gl::Error getSwizzleTexture(const TextureHelper11 **outTexture) override; - gl::Error getSwizzleRenderTarget(int mipLevel, const d3d11::RenderTargetView **outRTV) override; - - gl::ErrorOrResult<DropStencil> ensureDropStencilTexture(const gl::Context *context) override; - - gl::Error ensureTextureExists(int mipLevels); - - private: - gl::Error createSRV(const gl::Context *context, - int baseLevel, - int mipLevels, - DXGI_FORMAT format, - const TextureHelper11 &texture, - d3d11::SharedSRV *outSRV) override; - - TextureHelper11 mTexture; - TexLevelArray<std::unique_ptr<RenderTarget11>> mRenderTarget; - bool mHasKeyedMutex; - - // These are members related to the zero max-LOD workaround. - // D3D11 Feature Level 9_3 can't disable mipmaps on a mipmapped texture (i.e. solely sample from level zero). - // These members are used to work around this limitation. - // Usually only mTexture XOR mLevelZeroTexture will exist. - // For example, if an app creates a texture with only one level, then 9_3 will only create mLevelZeroTexture. - // However, in some scenarios, both textures have to be created. This incurs additional memory overhead. - // One example of this is an application that creates a texture, calls glGenerateMipmap, and then disables mipmaps on the texture. - // A more likely example is an app that creates an empty texture, renders to it, and then calls glGenerateMipmap - // TODO: In this rendering scenario, release the mLevelZeroTexture after mTexture has been created to save memory. - TextureHelper11 mLevelZeroTexture; - std::unique_ptr<RenderTarget11> mLevelZeroRenderTarget; - bool mUseLevelZeroTexture; - - // Swizzle-related variables - TextureHelper11 mSwizzleTexture; - TexLevelArray<d3d11::RenderTargetView> mSwizzleRenderTargets; - - TexLevelArray<Image11 *> mAssociatedImages; -}; - -class TextureStorage11_External : public TextureStorage11 -{ - public: - TextureStorage11_External(Renderer11 *renderer, - egl::Stream *stream, - const egl::Stream::GLTextureDescription &glDesc); - ~TextureStorage11_External() override; - - gl::Error onDestroy(const gl::Context *context) override; - - gl::Error getResource(const gl::Context *context, const TextureHelper11 **outResource) override; - gl::Error getMippedResource(const gl::Context *context, - const TextureHelper11 **outResource) override; - gl::Error getRenderTarget(const gl::Context *context, - const gl::ImageIndex &index, - RenderTargetD3D **outRT) override; - - gl::Error copyToStorage(const gl::Context *context, TextureStorage *destStorage) override; - - void associateImage(Image11 *image, const gl::ImageIndex &index) override; - void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override; - void verifyAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override; - gl::Error releaseAssociatedImage(const gl::Context *context, - const gl::ImageIndex &index, - Image11 *incomingImage) override; - - protected: - gl::Error getSwizzleTexture(const TextureHelper11 **outTexture) override; - gl::Error getSwizzleRenderTarget(int mipLevel, const d3d11::RenderTargetView **outRTV) override; - - private: - gl::Error createSRV(const gl::Context *context, - int baseLevel, - int mipLevels, - DXGI_FORMAT format, - const TextureHelper11 &texture, - d3d11::SharedSRV *outSRV) override; - - TextureHelper11 mTexture; - int mSubresourceIndex; - bool mHasKeyedMutex; - - Image11 *mAssociatedImage; -}; - -class TextureStorage11_EGLImage final : public TextureStorage11 -{ - public: - TextureStorage11_EGLImage(Renderer11 *renderer, - EGLImageD3D *eglImage, - RenderTarget11 *renderTarget11); - ~TextureStorage11_EGLImage() override; - - gl::Error getResource(const gl::Context *context, const TextureHelper11 **outResource) override; - gl::Error getSRV(const gl::Context *context, - const gl::TextureState &textureState, - const d3d11::SharedSRV **outSRV) override; - gl::Error getMippedResource(const gl::Context *context, - const TextureHelper11 **outResource) override; - gl::Error getRenderTarget(const gl::Context *context, - const gl::ImageIndex &index, - RenderTargetD3D **outRT) override; - - gl::Error copyToStorage(const gl::Context *context, TextureStorage *destStorage) override; - - void associateImage(Image11 *image, const gl::ImageIndex &index) override; - void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override; - void verifyAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override; - gl::Error releaseAssociatedImage(const gl::Context *context, - const gl::ImageIndex &index, - Image11 *incomingImage) override; - - gl::Error useLevelZeroWorkaroundTexture(const gl::Context *context, - bool useLevelZeroTexture) override; - - protected: - gl::Error getSwizzleTexture(const TextureHelper11 **outTexture) override; - gl::Error getSwizzleRenderTarget(int mipLevel, const d3d11::RenderTargetView **outRTV) override; - - private: - // Check if the EGL image's render target has been updated due to orphaning and delete - // any SRVs and other resources based on the image's old render target. - gl::Error checkForUpdatedRenderTarget(const gl::Context *context); - - gl::Error createSRV(const gl::Context *context, - int baseLevel, - int mipLevels, - DXGI_FORMAT format, - const TextureHelper11 &texture, - d3d11::SharedSRV *outSRV) override; - - gl::Error getImageRenderTarget(const gl::Context *context, RenderTarget11 **outRT) const; - - EGLImageD3D *mImage; - uintptr_t mCurrentRenderTarget; - - // Swizzle-related variables - TextureHelper11 mSwizzleTexture; - std::vector<d3d11::RenderTargetView> mSwizzleRenderTargets; -}; - -class TextureStorage11_Cube : public TextureStorage11 -{ - public: - TextureStorage11_Cube(Renderer11 *renderer, GLenum internalformat, bool renderTarget, int size, int levels, bool hintLevelZeroOnly); - ~TextureStorage11_Cube() override; - - gl::Error onDestroy(const gl::Context *context) override; - - UINT getSubresourceIndex(const gl::ImageIndex &index) const override; - - gl::Error getResource(const gl::Context *context, const TextureHelper11 **outResource) override; - gl::Error getMippedResource(const gl::Context *context, - const TextureHelper11 **outResource) override; - gl::Error getRenderTarget(const gl::Context *context, - const gl::ImageIndex &index, - RenderTargetD3D **outRT) override; - - gl::Error copyToStorage(const gl::Context *context, TextureStorage *destStorage) override; - - void associateImage(Image11 *image, const gl::ImageIndex &index) override; - void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override; - void verifyAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override; - gl::Error releaseAssociatedImage(const gl::Context *context, - const gl::ImageIndex &index, - Image11 *incomingImage) override; - - gl::Error useLevelZeroWorkaroundTexture(const gl::Context *context, - bool useLevelZeroTexture) override; - - protected: - gl::Error getSwizzleTexture(const TextureHelper11 **outTexture) override; - gl::Error getSwizzleRenderTarget(int mipLevel, const d3d11::RenderTargetView **outRTV) override; - - gl::ErrorOrResult<DropStencil> ensureDropStencilTexture(const gl::Context *context) override; - - gl::Error ensureTextureExists(int mipLevels); - - private: - gl::Error createSRV(const gl::Context *context, - int baseLevel, - int mipLevels, - DXGI_FORMAT format, - const TextureHelper11 &texture, - d3d11::SharedSRV *outSRV) override; - gl::Error createRenderTargetSRV(const TextureHelper11 &texture, - const gl::ImageIndex &index, - DXGI_FORMAT resourceFormat, - d3d11::SharedSRV *srv) const; - - TextureHelper11 mTexture; - CubeFaceArray<TexLevelArray<std::unique_ptr<RenderTarget11>>> mRenderTarget; - - // Level-zero workaround members. See TextureStorage11_2D's workaround members for a description. - TextureHelper11 mLevelZeroTexture; - CubeFaceArray<std::unique_ptr<RenderTarget11>> mLevelZeroRenderTarget; - bool mUseLevelZeroTexture; - - TextureHelper11 mSwizzleTexture; - TexLevelArray<d3d11::RenderTargetView> mSwizzleRenderTargets; - - CubeFaceArray<TexLevelArray<Image11 *>> mAssociatedImages; -}; - -class TextureStorage11_3D : public TextureStorage11 -{ - public: - TextureStorage11_3D(Renderer11 *renderer, GLenum internalformat, bool renderTarget, - GLsizei width, GLsizei height, GLsizei depth, int levels); - ~TextureStorage11_3D() override; - - gl::Error onDestroy(const gl::Context *context) override; - - gl::Error getResource(const gl::Context *context, const TextureHelper11 **outResource) override; - - // Handles both layer and non-layer RTs - gl::Error getRenderTarget(const gl::Context *context, - const gl::ImageIndex &index, - RenderTargetD3D **outRT) override; - - void associateImage(Image11 *image, const gl::ImageIndex &index) override; - void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override; - void verifyAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override; - gl::Error releaseAssociatedImage(const gl::Context *context, - const gl::ImageIndex &index, - Image11 *incomingImage) override; - - protected: - gl::Error getSwizzleTexture(const TextureHelper11 **outTexture) override; - gl::Error getSwizzleRenderTarget(int mipLevel, const d3d11::RenderTargetView **outRTV) override; - - private: - gl::Error createSRV(const gl::Context *context, - int baseLevel, - int mipLevels, - DXGI_FORMAT format, - const TextureHelper11 &texture, - d3d11::SharedSRV *outSRV) override; - - typedef std::pair<int, int> LevelLayerKey; - std::map<LevelLayerKey, std::unique_ptr<RenderTarget11>> mLevelLayerRenderTargets; - - TexLevelArray<std::unique_ptr<RenderTarget11>> mLevelRenderTargets; - - TextureHelper11 mTexture; - TextureHelper11 mSwizzleTexture; - TexLevelArray<d3d11::RenderTargetView> mSwizzleRenderTargets; - - TexLevelArray<Image11 *> mAssociatedImages; -}; - -class TextureStorage11_2DArray : public TextureStorage11 -{ - public: - TextureStorage11_2DArray(Renderer11 *renderer, GLenum internalformat, bool renderTarget, - GLsizei width, GLsizei height, GLsizei depth, int levels); - ~TextureStorage11_2DArray() override; - - gl::Error onDestroy(const gl::Context *context) override; - - gl::Error getResource(const gl::Context *context, const TextureHelper11 **outResource) override; - gl::Error getRenderTarget(const gl::Context *context, - const gl::ImageIndex &index, - RenderTargetD3D **outRT) override; - - void associateImage(Image11 *image, const gl::ImageIndex &index) override; - void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override; - void verifyAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override; - gl::Error releaseAssociatedImage(const gl::Context *context, - const gl::ImageIndex &index, - Image11 *incomingImage) override; - - protected: - gl::Error getSwizzleTexture(const TextureHelper11 **outTexture) override; - gl::Error getSwizzleRenderTarget(int mipLevel, const d3d11::RenderTargetView **outRTV) override; - - gl::ErrorOrResult<DropStencil> ensureDropStencilTexture(const gl::Context *context) override; - - private: - struct LevelLayerRangeKey - { - LevelLayerRangeKey(int mipLevelIn, int layerIn, int numLayersIn) - : mipLevel(mipLevelIn), layer(layerIn), numLayers(numLayersIn) - { - } - bool operator<(const LevelLayerRangeKey &other) const - { - if (mipLevel != other.mipLevel) - { - return mipLevel < other.mipLevel; - } - if (layer != other.layer) - { - return layer < other.layer; - } - return numLayers < other.numLayers; - } - int mipLevel; - int layer; - int numLayers; - }; - - private: - gl::Error createSRV(const gl::Context *context, - int baseLevel, - int mipLevels, - DXGI_FORMAT format, - const TextureHelper11 &texture, - d3d11::SharedSRV *outSRV) override; - gl::Error createRenderTargetSRV(const TextureHelper11 &texture, - const gl::ImageIndex &index, - DXGI_FORMAT resourceFormat, - d3d11::SharedSRV *srv) const; - - std::map<LevelLayerRangeKey, std::unique_ptr<RenderTarget11>> mRenderTargets; - - TextureHelper11 mTexture; - - TextureHelper11 mSwizzleTexture; - TexLevelArray<d3d11::RenderTargetView> mSwizzleRenderTargets; - - typedef std::map<LevelLayerRangeKey, Image11 *> ImageMap; - ImageMap mAssociatedImages; -}; - -class TextureStorage11_2DMultisample : public TextureStorage11 -{ - public: - TextureStorage11_2DMultisample(Renderer11 *renderer, - GLenum internalformat, - GLsizei width, - GLsizei height, - int levels, - int samples, - bool fixedSampleLocations); - ~TextureStorage11_2DMultisample() override; - - gl::Error onDestroy(const gl::Context *context) override; - - gl::Error getResource(const gl::Context *context, const TextureHelper11 **outResource) override; - gl::Error getRenderTarget(const gl::Context *context, - const gl::ImageIndex &index, - RenderTargetD3D **outRT) override; - - gl::Error copyToStorage(const gl::Context *context, TextureStorage *destStorage) override; - - void associateImage(Image11 *image, const gl::ImageIndex &index) override; - void disassociateImage(const gl::ImageIndex &index, Image11 *expectedImage) override; - void verifyAssociatedImageValid(const gl::ImageIndex &index, Image11 *expectedImage) override; - gl::Error releaseAssociatedImage(const gl::Context *context, - const gl::ImageIndex &index, - Image11 *incomingImage) override; - - protected: - gl::Error getSwizzleTexture(const TextureHelper11 **outTexture) override; - gl::Error getSwizzleRenderTarget(int mipLevel, const d3d11::RenderTargetView **outRTV) override; - - gl::ErrorOrResult<DropStencil> ensureDropStencilTexture(const gl::Context *context) override; - - gl::Error ensureTextureExists(int mipLevels); - - private: - gl::Error createSRV(const gl::Context *context, - int baseLevel, - int mipLevels, - DXGI_FORMAT format, - const TextureHelper11 &texture, - d3d11::SharedSRV *outSRV) override; - - TextureHelper11 mTexture; - std::unique_ptr<RenderTarget11> mRenderTarget; - - unsigned int mSamples; - GLboolean mFixedSampleLocations; -}; -} - -#endif // LIBANGLE_RENDERER_D3D_D3D11_TEXTURESTORAGE11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/TransformFeedback11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/TransformFeedback11.cpp deleted file mode 100644 index 4b08edf71f..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/TransformFeedback11.cpp +++ /dev/null @@ -1,124 +0,0 @@ -// -// Copyright 2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// TransformFeedbackD3D.cpp is a no-op implementation for both the D3D9 and D3D11 renderers. - -#include "libANGLE/renderer/d3d/d3d11/TransformFeedback11.h" - -#include "libANGLE/Buffer.h" -#include "libANGLE/renderer/d3d/d3d11/Buffer11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" - -namespace rx -{ - -TransformFeedback11::TransformFeedback11(const gl::TransformFeedbackState &state, - Renderer11 *renderer) - : TransformFeedbackImpl(state), - mRenderer(renderer), - mIsDirty(true), - mBuffers(state.getIndexedBuffers().size(), nullptr), - mBufferOffsets(state.getIndexedBuffers().size(), 0), - mSerial(mRenderer->generateSerial()) -{ -} - -TransformFeedback11::~TransformFeedback11() -{ -} - -void TransformFeedback11::begin(GLenum primitiveMode) -{ - // Reset all the cached offsets to the binding offsets - mIsDirty = true; - for (size_t bindingIdx = 0; bindingIdx < mBuffers.size(); bindingIdx++) - { - const auto &binding = mState.getIndexedBuffer(bindingIdx); - if (binding.get() != nullptr) - { - mBufferOffsets[bindingIdx] = static_cast<UINT>(binding.getOffset()); - } - else - { - mBufferOffsets[bindingIdx] = 0; - } - } -} - -void TransformFeedback11::end() -{ - if (mRenderer->getWorkarounds().flushAfterEndingTransformFeedback) - { - mRenderer->getDeviceContext()->Flush(); - } -} - -void TransformFeedback11::pause() -{ -} - -void TransformFeedback11::resume() -{ -} - -void TransformFeedback11::bindGenericBuffer(const gl::BindingPointer<gl::Buffer> &binding) -{ -} - -void TransformFeedback11::bindIndexedBuffer(size_t index, - const gl::OffsetBindingPointer<gl::Buffer> &binding) -{ - mIsDirty = true; - mBufferOffsets[index] = static_cast<UINT>(binding.getOffset()); -} - -void TransformFeedback11::onApply() -{ - mIsDirty = false; - - // Change all buffer offsets to -1 so that if any of them need to be re-applied, the are set to - // append - std::fill(mBufferOffsets.begin(), mBufferOffsets.end(), -1); -} - -bool TransformFeedback11::isDirty() const -{ - return mIsDirty; -} - -UINT TransformFeedback11::getNumSOBuffers() const -{ - return static_cast<UINT>(mBuffers.size()); -} - -gl::ErrorOrResult<const std::vector<ID3D11Buffer *> *> TransformFeedback11::getSOBuffers( - const gl::Context *context) -{ - for (size_t bindingIdx = 0; bindingIdx < mBuffers.size(); bindingIdx++) - { - const auto &binding = mState.getIndexedBuffer(bindingIdx); - if (binding.get() != nullptr) - { - Buffer11 *storage = GetImplAs<Buffer11>(binding.get()); - ANGLE_TRY_RESULT(storage->getBuffer(context, BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK), - mBuffers[bindingIdx]); - } - } - - return &mBuffers; -} - -const std::vector<UINT> &TransformFeedback11::getSOBufferOffsets() const -{ - return mBufferOffsets; -} - -Serial TransformFeedback11::getSerial() const -{ - return mSerial; -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/TransformFeedback11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/TransformFeedback11.h deleted file mode 100644 index cc9fcc335a..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/TransformFeedback11.h +++ /dev/null @@ -1,60 +0,0 @@ -// -// Copyright 2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// TransformFeedback11.h: Implements the abstract rx::TransformFeedbackImpl class. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_TRANSFORMFEEDBACK11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_TRANSFORMFEEDBACK11_H_ - -#include "common/platform.h" - -#include "libANGLE/Error.h" -#include "libANGLE/angletypes.h" -#include "libANGLE/renderer/TransformFeedbackImpl.h" -#include "libANGLE/renderer/renderer_utils.h" - -namespace rx -{ - -class Renderer11; - -class TransformFeedback11 : public TransformFeedbackImpl -{ - public: - TransformFeedback11(const gl::TransformFeedbackState &state, Renderer11 *renderer); - ~TransformFeedback11() override; - - void begin(GLenum primitiveMode) override; - void end() override; - void pause() override; - void resume() override; - - void bindGenericBuffer(const gl::BindingPointer<gl::Buffer> &binding) override; - void bindIndexedBuffer(size_t index, - const gl::OffsetBindingPointer<gl::Buffer> &binding) override; - - void onApply(); - - bool isDirty() const; - - UINT getNumSOBuffers() const; - gl::ErrorOrResult<const std::vector<ID3D11Buffer *> *> getSOBuffers(const gl::Context *context); - const std::vector<UINT> &getSOBufferOffsets() const; - - Serial getSerial() const; - - private: - Renderer11 *mRenderer; - - bool mIsDirty; - std::vector<ID3D11Buffer *> mBuffers; - std::vector<UINT> mBufferOffsets; - - Serial mSerial; -}; -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_TRANSFORMFEEDBACK11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Trim11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Trim11.cpp deleted file mode 100644 index 29185a9d93..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Trim11.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// -// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Trim11.cpp: Trim support utility class. - -#include "libANGLE/renderer/d3d/d3d11/Trim11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -#if defined (ANGLE_ENABLE_WINDOWS_STORE) -#include <wrl.h> -#include <wrl/wrappers/corewrappers.h> -#include <windows.applicationmodel.core.h> -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::ApplicationModel; -using namespace ABI::Windows::ApplicationModel::Core; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Foundation::Collections; -#endif - -namespace rx -{ - -Trim11::Trim11(rx::Renderer11 *renderer) - : mRenderer(renderer) -{ - bool result = true; - result = registerForRendererTrimRequest(); - ASSERT(result); -} - -Trim11::~Trim11() -{ - unregisterForRendererTrimRequest(); -} - -void Trim11::trim() -{ - if (!mRenderer) - { - return; - } - -#if defined (ANGLE_ENABLE_WINDOWS_STORE) - ID3D11Device* device = mRenderer->getDevice(); - IDXGIDevice3 *dxgiDevice3 = d3d11::DynamicCastComObject<IDXGIDevice3>(device); - if (dxgiDevice3) - { - dxgiDevice3->Trim(); - } - SafeRelease(dxgiDevice3); -#endif -} - -bool Trim11::registerForRendererTrimRequest() -{ -#if defined (ANGLE_ENABLE_WINDOWS_STORE) - ICoreApplication* coreApplication = nullptr; - HRESULT result = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication).Get(), &coreApplication); - if (SUCCEEDED(result)) - { - auto suspendHandler = Callback<IEventHandler<SuspendingEventArgs*>>( - [this](IInspectable*, ISuspendingEventArgs*) -> HRESULT - { - trim(); - return S_OK; - }); - result = coreApplication->add_Suspending(suspendHandler.Get(), &mApplicationSuspendedEventToken); - } - SafeRelease(coreApplication); - - if (FAILED(result)) - { - return false; - } -#endif - return true; -} - -void Trim11::unregisterForRendererTrimRequest() -{ -#if defined (ANGLE_ENABLE_WINDOWS_STORE) - if (mApplicationSuspendedEventToken.value != 0) - { - ICoreApplication* coreApplication = nullptr; - if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication).Get(), &coreApplication))) - { - coreApplication->remove_Suspending(mApplicationSuspendedEventToken); - } - mApplicationSuspendedEventToken.value = 0; - SafeRelease(coreApplication); - } -#endif -} - -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Trim11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Trim11.h deleted file mode 100644 index 69fa05a57b..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/Trim11.h +++ /dev/null @@ -1,43 +0,0 @@ -// -// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Trim11.h: Trim support utility class. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_TRIM11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_TRIM11_H_ - -#include "common/angleutils.h" -#include "libANGLE/angletypes.h" -#include "libANGLE/Error.h" - -#if defined(ANGLE_ENABLE_WINDOWS_STORE) -#include <EventToken.h> -#endif - -namespace rx -{ -class Renderer11; - -class Trim11 : angle::NonCopyable -{ - public: - explicit Trim11(Renderer11 *renderer); - ~Trim11(); - - private: - Renderer11 *mRenderer; -#if defined (ANGLE_ENABLE_WINDOWS_STORE) - EventRegistrationToken mApplicationSuspendedEventToken; -#endif - - void trim(); - bool registerForRendererTrimRequest(); - void unregisterForRendererTrimRequest(); -}; - -} - -#endif // LIBANGLE_RENDERER_D3D_D3D11_TRIM11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/VertexArray11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/VertexArray11.cpp deleted file mode 100644 index 97c29415ed..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/VertexArray11.cpp +++ /dev/null @@ -1,413 +0,0 @@ -// -// Copyright 2016 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// VertexArray11: -// Implementation of rx::VertexArray11. -// - -#include "libANGLE/renderer/d3d/d3d11/VertexArray11.h" - -#include "common/bitset_utils.h" -#include "libANGLE/Context.h" -#include "libANGLE/renderer/d3d/d3d11/Buffer11.h" -#include "libANGLE/renderer/d3d/d3d11/Context11.h" - -using namespace angle; - -namespace rx -{ - -namespace -{ -OnBufferDataDirtyChannel *GetBufferBroadcastChannel(Buffer11 *buffer11, - IndexStorageType storageType) -{ - switch (storageType) - { - case IndexStorageType::Direct: - return buffer11->getDirectBroadcastChannel(); - case IndexStorageType::Static: - return buffer11->getStaticBroadcastChannel(); - case IndexStorageType::Dynamic: - return buffer11 ? buffer11->getStaticBroadcastChannel() : nullptr; - default: - UNREACHABLE(); - return nullptr; - } -} -} // anonymous namespace - -VertexArray11::VertexArray11(const gl::VertexArrayState &data) - : VertexArrayImpl(data), - mAttributeStorageTypes(data.getMaxAttribs(), VertexStorageType::CURRENT_VALUE), - mTranslatedAttribs(data.getMaxAttribs()), - mCurrentArrayBuffers(data.getMaxAttribs()), - mCurrentElementArrayBuffer(), - mOnArrayBufferDataDirty(), - mOnElementArrayBufferDataDirty(this, mCurrentArrayBuffers.size()), - mAppliedNumViewsToDivisor(1), - mLastElementType(GL_NONE), - mLastDrawElementsOffset(0), - mCurrentElementArrayStorage(IndexStorageType::Invalid), - mCachedIndexInfoValid(false) -{ - for (size_t attribIndex = 0; attribIndex < mCurrentArrayBuffers.size(); ++attribIndex) - { - mOnArrayBufferDataDirty.emplace_back(this, attribIndex); - } -} - -VertexArray11::~VertexArray11() -{ -} - -void VertexArray11::destroy(const gl::Context *context) -{ - for (auto &buffer : mCurrentArrayBuffers) - { - if (buffer.get()) - { - buffer.set(context, nullptr); - } - } - - mCurrentElementArrayBuffer.set(context, nullptr); -} - -void VertexArray11::syncState(const gl::Context *context, - const gl::VertexArray::DirtyBits &dirtyBits) -{ - ASSERT(dirtyBits.any()); - - // Generate a state serial. This serial is used in the program class to validate the cached - // input layout, and skip recomputation in the fast path. - Renderer11 *renderer = GetImplAs<Context11>(context)->getRenderer(); - mCurrentStateSerial = renderer->generateSerial(); - - // TODO(jmadill): Individual attribute invalidation. - renderer->getStateManager()->invalidateVertexBuffer(); - - for (auto dirtyBit : dirtyBits) - { - if (dirtyBit == gl::VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER) - { - mCachedIndexInfoValid = false; - mLastElementType = GL_NONE; - } - else - { - size_t index = gl::VertexArray::GetVertexIndexFromDirtyBit(dirtyBit); - // TODO(jiawei.shao@intel.com): Vertex Attrib Bindings - ASSERT(index == mState.getBindingIndexFromAttribIndex(index)); - mAttribsToUpdate.set(index); - } - } -} - -bool VertexArray11::flushAttribUpdates(const gl::Context *context) -{ - if (mAttribsToUpdate.any()) - { - const auto &activeLocations = - context->getGLState().getProgram()->getActiveAttribLocationsMask(); - - // Skip attrib locations the program doesn't use. - gl::AttributesMask activeToUpdate = mAttribsToUpdate & activeLocations; - - for (auto toUpdateIndex : activeToUpdate) - { - mAttribsToUpdate.reset(toUpdateIndex); - updateVertexAttribStorage(context, toUpdateIndex); - } - - return true; - } - - return false; -} - -bool VertexArray11::updateElementArrayStorage(const gl::Context *context, - GLenum elementType, - GLenum destElementType, - const void *indices) -{ - unsigned int offset = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(indices)); - - if (mCachedIndexInfoValid && mLastElementType == elementType && - offset == mLastDrawElementsOffset) - { - // Dynamic index buffers must be re-streamed every draw. - return (mCurrentElementArrayStorage == IndexStorageType::Dynamic); - } - - gl::Buffer *newBuffer = mState.getElementArrayBuffer().get(); - gl::Buffer *oldBuffer = mCurrentElementArrayBuffer.get(); - bool needsTranslation = false; - IndexStorageType newStorageType = ClassifyIndexStorage( - context->getGLState(), newBuffer, elementType, destElementType, offset, &needsTranslation); - - if (newBuffer != oldBuffer) - { - mCurrentElementArrayBuffer.set(context, newBuffer); - } - - if (newStorageType != mCurrentElementArrayStorage || newBuffer != oldBuffer) - { - Buffer11 *newBuffer11 = SafeGetImplAs<Buffer11>(newBuffer); - - auto *newChannel = GetBufferBroadcastChannel(newBuffer11, newStorageType); - - mCurrentElementArrayStorage = newStorageType; - mOnElementArrayBufferDataDirty.bind(newChannel); - needsTranslation = true; - } - - if (mLastDrawElementsOffset != offset) - { - needsTranslation = true; - mLastDrawElementsOffset = offset; - } - - if (mLastElementType != elementType) - { - needsTranslation = true; - mLastElementType = elementType; - } - - // TODO(jmadill): We should probably promote static usage immediately, because this can change - // the storage type for dynamic buffers. - return needsTranslation || !mCachedIndexInfoValid; -} - -void VertexArray11::updateVertexAttribStorage(const gl::Context *context, size_t attribIndex) -{ - const auto &attrib = mState.getVertexAttribute(attribIndex); - const auto &binding = mState.getBindingFromAttribIndex(attribIndex); - - // Note: having an unchanged storage type doesn't mean the attribute is clean. - auto oldStorageType = mAttributeStorageTypes[attribIndex]; - auto newStorageType = ClassifyAttributeStorage(attrib, binding); - - mAttributeStorageTypes[attribIndex] = newStorageType; - - StateManager11 *stateManager = GetImplAs<Context11>(context)->getRenderer()->getStateManager(); - - if (newStorageType == VertexStorageType::DYNAMIC) - { - if (oldStorageType != VertexStorageType::DYNAMIC) - { - // Sync dynamic attribs in a different set. - mAttribsToTranslate.reset(attribIndex); - mDynamicAttribsMask.set(attribIndex); - } - } - else - { - mAttribsToTranslate.set(attribIndex); - stateManager->invalidateVertexAttributeTranslation(); - - if (oldStorageType == VertexStorageType::DYNAMIC) - { - ASSERT(mDynamicAttribsMask[attribIndex]); - mDynamicAttribsMask.reset(attribIndex); - } - } - - gl::Buffer *oldBufferGL = mCurrentArrayBuffers[attribIndex].get(); - gl::Buffer *newBufferGL = binding.getBuffer().get(); - Buffer11 *oldBuffer11 = oldBufferGL ? GetImplAs<Buffer11>(oldBufferGL) : nullptr; - Buffer11 *newBuffer11 = newBufferGL ? GetImplAs<Buffer11>(newBufferGL) : nullptr; - - if (oldBuffer11 != newBuffer11 || oldStorageType != newStorageType) - { - OnBufferDataDirtyChannel *newChannel = nullptr; - - if (newStorageType == VertexStorageType::CURRENT_VALUE) - { - stateManager->invalidateCurrentValueAttrib(attribIndex); - } - else if (newBuffer11 != nullptr) - { - // Note that for static callbacks, promotion to a static buffer from a dynamic buffer - // means we need to tag dynamic buffers with static callbacks. - switch (newStorageType) - { - case VertexStorageType::DIRECT: - newChannel = newBuffer11->getDirectBroadcastChannel(); - break; - case VertexStorageType::STATIC: - case VertexStorageType::DYNAMIC: - newChannel = newBuffer11->getStaticBroadcastChannel(); - break; - default: - UNREACHABLE(); - break; - } - } - - mOnArrayBufferDataDirty[attribIndex].bind(newChannel); - mCurrentArrayBuffers[attribIndex].set(context, binding.getBuffer().get()); - } -} - -bool VertexArray11::hasActiveDynamicAttrib(const gl::Context *context) -{ - flushAttribUpdates(context); - const auto &activeLocations = - context->getGLState().getProgram()->getActiveAttribLocationsMask(); - auto activeDynamicAttribs = (mDynamicAttribsMask & activeLocations); - return activeDynamicAttribs.any(); -} - -gl::Error VertexArray11::updateDirtyAndDynamicAttribs(const gl::Context *context, - VertexDataManager *vertexDataManager, - const DrawCallVertexParams &vertexParams) -{ - flushAttribUpdates(context); - - const auto &glState = context->getGLState(); - const gl::Program *program = glState.getProgram(); - const auto &activeLocations = program->getActiveAttribLocationsMask(); - const auto &attribs = mState.getVertexAttributes(); - const auto &bindings = mState.getVertexBindings(); - mAppliedNumViewsToDivisor = - (program != nullptr && program->usesMultiview()) ? program->getNumViews() : 1; - - if (mAttribsToTranslate.any()) - { - // Skip attrib locations the program doesn't use, saving for the next frame. - gl::AttributesMask dirtyActiveAttribs = (mAttribsToTranslate & activeLocations); - - for (auto dirtyAttribIndex : dirtyActiveAttribs) - { - mAttribsToTranslate.reset(dirtyAttribIndex); - - auto *translatedAttrib = &mTranslatedAttribs[dirtyAttribIndex]; - const auto ¤tValue = glState.getVertexAttribCurrentValue(dirtyAttribIndex); - - // Record basic attrib info - translatedAttrib->attribute = &attribs[dirtyAttribIndex]; - translatedAttrib->binding = &bindings[translatedAttrib->attribute->bindingIndex]; - translatedAttrib->currentValueType = currentValue.Type; - translatedAttrib->divisor = - translatedAttrib->binding->getDivisor() * mAppliedNumViewsToDivisor; - - switch (mAttributeStorageTypes[dirtyAttribIndex]) - { - case VertexStorageType::DIRECT: - VertexDataManager::StoreDirectAttrib(translatedAttrib); - break; - case VertexStorageType::STATIC: - { - ANGLE_TRY(VertexDataManager::StoreStaticAttrib(context, translatedAttrib)); - break; - } - case VertexStorageType::CURRENT_VALUE: - // Current value attribs are managed by the StateManager11. - break; - default: - UNREACHABLE(); - break; - } - } - } - - if (mDynamicAttribsMask.any()) - { - auto activeDynamicAttribs = (mDynamicAttribsMask & activeLocations); - if (activeDynamicAttribs.none()) - { - return gl::NoError(); - } - - for (auto dynamicAttribIndex : activeDynamicAttribs) - { - auto *dynamicAttrib = &mTranslatedAttribs[dynamicAttribIndex]; - const auto ¤tValue = glState.getVertexAttribCurrentValue(dynamicAttribIndex); - - // Record basic attrib info - dynamicAttrib->attribute = &attribs[dynamicAttribIndex]; - dynamicAttrib->binding = &bindings[dynamicAttrib->attribute->bindingIndex]; - dynamicAttrib->currentValueType = currentValue.Type; - dynamicAttrib->divisor = - dynamicAttrib->binding->getDivisor() * mAppliedNumViewsToDivisor; - } - - ANGLE_TRY(vertexDataManager->storeDynamicAttribs( - context, &mTranslatedAttribs, activeDynamicAttribs, vertexParams.firstVertex(), - vertexParams.vertexCount(), vertexParams.instances())); - } - - return gl::NoError(); -} - -const std::vector<TranslatedAttribute> &VertexArray11::getTranslatedAttribs() const -{ - return mTranslatedAttribs; -} - -void VertexArray11::signal(size_t channelID, const gl::Context *context) -{ - if (channelID == mAttributeStorageTypes.size()) - { - mCachedIndexInfoValid = false; - mLastElementType = GL_NONE; - mLastDrawElementsOffset = 0; - } - else - { - ASSERT(mAttributeStorageTypes[channelID] != VertexStorageType::CURRENT_VALUE); - - // This can change a buffer's storage, we'll need to re-check. - mAttribsToUpdate.set(channelID); - - // Changing the vertex attribute state can affect the vertex shader. - Renderer11 *renderer = GetImplAs<Context11>(context)->getRenderer(); - renderer->getStateManager()->invalidateShaders(); - } -} - -void VertexArray11::clearDirtyAndPromoteDynamicAttribs(const gl::Context *context, - const DrawCallVertexParams &vertexParams) -{ - const gl::State &state = context->getGLState(); - const gl::Program *program = state.getProgram(); - const auto &activeLocations = program->getActiveAttribLocationsMask(); - mAttribsToUpdate &= ~activeLocations; - - // Promote to static after we clear the dirty attributes, otherwise we can lose dirtyness. - auto activeDynamicAttribs = (mDynamicAttribsMask & activeLocations); - if (activeDynamicAttribs.any()) - { - VertexDataManager::PromoteDynamicAttribs(context, mTranslatedAttribs, activeDynamicAttribs, - vertexParams.vertexCount()); - } -} - -void VertexArray11::markAllAttributeDivisorsForAdjustment(int numViews) -{ - if (mAppliedNumViewsToDivisor != numViews) - { - mAppliedNumViewsToDivisor = numViews; - mAttribsToUpdate.set(); - } -} - -TranslatedIndexData *VertexArray11::getCachedIndexInfo() -{ - return &mCachedIndexInfo; -} - -void VertexArray11::setCachedIndexInfoValid() -{ - mCachedIndexInfoValid = true; -} - -bool VertexArray11::isCachedIndexInfoValid() const -{ - return mCachedIndexInfoValid; -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/VertexArray11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/VertexArray11.h deleted file mode 100644 index 4cdc92531d..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/VertexArray11.h +++ /dev/null @@ -1,99 +0,0 @@ -// -// Copyright 2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// VertexArray11.h: Defines the rx::VertexArray11 class which implements rx::VertexArrayImpl. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_VERTEXARRAY11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_VERTEXARRAY11_H_ - -#include "libANGLE/Framebuffer.h" -#include "libANGLE/renderer/VertexArrayImpl.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/signal_utils.h" - -namespace rx -{ -class Renderer11; - -class VertexArray11 : public VertexArrayImpl, public OnBufferDataDirtyReceiver -{ - public: - VertexArray11(const gl::VertexArrayState &data); - ~VertexArray11() override; - void destroy(const gl::Context *context) override; - - void syncState(const gl::Context *context, - const gl::VertexArray::DirtyBits &dirtyBits) override; - // This will flush any pending attrib updates and then check the dynamic attribs mask. - bool hasActiveDynamicAttrib(const gl::Context *context); - gl::Error updateDirtyAndDynamicAttribs(const gl::Context *context, - VertexDataManager *vertexDataManager, - const DrawCallVertexParams &vertexParams); - void clearDirtyAndPromoteDynamicAttribs(const gl::Context *context, - const DrawCallVertexParams &vertexParams); - - const std::vector<TranslatedAttribute> &getTranslatedAttribs() const; - - // SignalReceiver implementation - void signal(size_t channelID, const gl::Context *context) override; - - Serial getCurrentStateSerial() const { return mCurrentStateSerial; } - - // In case of a multi-view program change, we have to update all attributes so that the divisor - // is adjusted. - void markAllAttributeDivisorsForAdjustment(int numViews); - - bool flushAttribUpdates(const gl::Context *context); - - // Returns true if the element array buffer needs to be translated. - bool updateElementArrayStorage(const gl::Context *context, - GLenum elementType, - GLenum destElementType, - const void *indices); - - TranslatedIndexData *getCachedIndexInfo(); - void setCachedIndexInfoValid(); - bool isCachedIndexInfoValid() const; - - private: - void updateVertexAttribStorage(const gl::Context *context, size_t attribIndex); - - std::vector<VertexStorageType> mAttributeStorageTypes; - std::vector<TranslatedAttribute> mTranslatedAttribs; - - // The mask of attributes marked as dynamic. - gl::AttributesMask mDynamicAttribsMask; - - // A mask of attributes that need to be re-evaluated. - gl::AttributesMask mAttribsToUpdate; - - // A set of attributes we know are dirty, and need to be re-translated. - gl::AttributesMask mAttribsToTranslate; - - // We need to keep a safe pointer to the Buffer so we can attach the correct dirty callbacks. - std::vector<gl::BindingPointer<gl::Buffer>> mCurrentArrayBuffers; - gl::BindingPointer<gl::Buffer> mCurrentElementArrayBuffer; - - std::vector<OnBufferDataDirtyBinding> mOnArrayBufferDataDirty; - OnBufferDataDirtyBinding mOnElementArrayBufferDataDirty; - - Serial mCurrentStateSerial; - - // The numViews value used to adjust the divisor. - int mAppliedNumViewsToDivisor; - - // If the index buffer needs re-streaming. - GLenum mLastElementType; - unsigned int mLastDrawElementsOffset; - IndexStorageType mCurrentElementArrayStorage; - TranslatedIndexData mCachedIndexInfo; - bool mCachedIndexInfoValid; -}; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_VERTEXARRAY11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.cpp deleted file mode 100644 index 611bd0f18b..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.cpp +++ /dev/null @@ -1,184 +0,0 @@ -// -// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// VertexBuffer11.cpp: Defines the D3D11 VertexBuffer implementation. - -#include "libANGLE/renderer/d3d/d3d11/VertexBuffer11.h" - -#include "libANGLE/Buffer.h" -#include "libANGLE/VertexAttribute.h" -#include "libANGLE/formatutils.h" -#include "libANGLE/renderer/d3d/d3d11/Buffer11.h" -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -namespace rx -{ - -VertexBuffer11::VertexBuffer11(Renderer11 *const renderer) - : mRenderer(renderer), - mBuffer(), - mBufferSize(0), - mDynamicUsage(false), - mMappedResourceData(nullptr) -{ -} - -VertexBuffer11::~VertexBuffer11() -{ - ASSERT(mMappedResourceData == nullptr); -} - -gl::Error VertexBuffer11::initialize(unsigned int size, bool dynamicUsage) -{ - mBuffer.reset(); - updateSerial(); - - if (size > 0) - { - D3D11_BUFFER_DESC bufferDesc; - bufferDesc.ByteWidth = size; - bufferDesc.Usage = D3D11_USAGE_DYNAMIC; - bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - bufferDesc.MiscFlags = 0; - bufferDesc.StructureByteStride = 0; - - ANGLE_TRY(mRenderer->allocateResource(bufferDesc, &mBuffer)); - - if (dynamicUsage) - { - mBuffer.setDebugName("VertexBuffer11 (dynamic)"); - } - else - { - mBuffer.setDebugName("VertexBuffer11 (static)"); - } - } - - mBufferSize = size; - mDynamicUsage = dynamicUsage; - - return gl::NoError(); -} - -gl::Error VertexBuffer11::mapResource() -{ - if (mMappedResourceData == nullptr) - { - ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext(); - - D3D11_MAPPED_SUBRESOURCE mappedResource; - - HRESULT result = - dxContext->Map(mBuffer.get(), 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mappedResource); - if (FAILED(result)) - { - return gl::OutOfMemory() - << "Failed to map internal vertex buffer, " << gl::FmtHR(result); - } - - mMappedResourceData = reinterpret_cast<uint8_t *>(mappedResource.pData); - } - - return gl::NoError(); -} - -void VertexBuffer11::hintUnmapResource() -{ - if (mMappedResourceData != nullptr) - { - ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext(); - dxContext->Unmap(mBuffer.get(), 0); - - mMappedResourceData = nullptr; - } -} - -gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, - const gl::VertexBinding &binding, - GLenum currentValueType, - GLint start, - GLsizei count, - GLsizei instances, - unsigned int offset, - const uint8_t *sourceData) -{ - if (!mBuffer.valid()) - { - return gl::OutOfMemory() << "Internal vertex buffer is not initialized."; - } - - int inputStride = static_cast<int>(ComputeVertexAttributeStride(attrib, binding)); - - // This will map the resource if it isn't already mapped. - ANGLE_TRY(mapResource()); - - uint8_t *output = mMappedResourceData + offset; - - const uint8_t *input = sourceData; - - if (instances == 0 || binding.getDivisor() == 0) - { - input += inputStride * start; - } - - gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib, currentValueType); - const D3D_FEATURE_LEVEL featureLevel = mRenderer->getRenderer11DeviceCaps().featureLevel; - const d3d11::VertexFormat &vertexFormatInfo = - d3d11::GetVertexFormatInfo(vertexFormatType, featureLevel); - ASSERT(vertexFormatInfo.copyFunction != nullptr); - vertexFormatInfo.copyFunction(input, inputStride, count, output); - - return gl::NoError(); -} - -unsigned int VertexBuffer11::getBufferSize() const -{ - return mBufferSize; -} - -gl::Error VertexBuffer11::setBufferSize(unsigned int size) -{ - if (size > mBufferSize) - { - return initialize(size, mDynamicUsage); - } - else - { - return gl::NoError(); - } -} - -gl::Error VertexBuffer11::discard() -{ - if (!mBuffer.valid()) - { - return gl::OutOfMemory() << "Internal vertex buffer is not initialized."; - } - - ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext(); - - D3D11_MAPPED_SUBRESOURCE mappedResource; - HRESULT result = dxContext->Map(mBuffer.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - if (FAILED(result)) - { - return gl::OutOfMemory() << "Failed to map internal buffer for discarding, " - << gl::FmtHR(result); - } - - dxContext->Unmap(mBuffer.get(), 0); - - return gl::NoError(); -} - -const d3d11::Buffer &VertexBuffer11::getBuffer() const -{ - return mBuffer; -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.h deleted file mode 100644 index ab619ae503..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.h +++ /dev/null @@ -1,62 +0,0 @@ -// -// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// VertexBuffer11.h: Defines the D3D11 VertexBuffer implementation. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_VERTEXBUFFER11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_VERTEXBUFFER11_H_ - -#include <stdint.h> - -#include "libANGLE/renderer/d3d/VertexBuffer.h" -#include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h" - -namespace rx -{ -class Renderer11; - -class VertexBuffer11 : public VertexBuffer -{ - public: - explicit VertexBuffer11(Renderer11 *const renderer); - - gl::Error initialize(unsigned int size, bool dynamicUsage) override; - - // Warning: you should ensure binding really matches attrib.bindingIndex before using this - // function. - gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, - const gl::VertexBinding &binding, - GLenum currentValueType, - GLint start, - GLsizei count, - GLsizei instances, - unsigned int offset, - const uint8_t *sourceData) override; - - unsigned int getBufferSize() const override; - gl::Error setBufferSize(unsigned int size) override; - gl::Error discard() override; - - void hintUnmapResource() override; - - const d3d11::Buffer &getBuffer() const; - - private: - ~VertexBuffer11() override; - gl::Error mapResource(); - - Renderer11 *const mRenderer; - - d3d11::Buffer mBuffer; - unsigned int mBufferSize; - bool mDynamicUsage; - - uint8_t *mMappedResourceData; -}; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_VERTEXBUFFER11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/copyvertex.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/copyvertex.h deleted file mode 100644 index 5501e361f1..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/copyvertex.h +++ /dev/null @@ -1,40 +0,0 @@ -// -// Copyright (c) 2013-2015 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// copyvertex.h: Defines D3D11 vertex buffer copying and conversion functions - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_COPYVERTEX_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_COPYVERTEX_H_ - -#include "common/mathutil.h" - -namespace rx -{ - -// 'alphaDefaultValueBits' gives the default value for the alpha channel (4th component) -template <typename T, size_t inputComponentCount, size_t outputComponentCount, uint32_t alphaDefaultValueBits> -inline void CopyNativeVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output); - -template <size_t inputComponentCount, size_t outputComponentCount> -inline void Copy8SintTo16SintVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output); - -template <size_t componentCount> -inline void Copy8SnormTo16SnormVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output); - -template <size_t inputComponentCount, size_t outputComponentCount> -inline void Copy32FixedTo32FVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output); - -template <typename T, size_t inputComponentCount, size_t outputComponentCount, bool normalized> -inline void CopyTo32FVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output); - -template <bool isSigned, bool normalized, bool toFloat> -inline void CopyXYZ10W2ToXYZW32FVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output); - -} - -#include "copyvertex.inl" - -#endif // LIBANGLE_RENDERER_D3D_D3D11_COPYVERTEX_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/copyvertex.inl b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/copyvertex.inl deleted file mode 100644 index 7c5c157c6f..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/copyvertex.inl +++ /dev/null @@ -1,386 +0,0 @@ -// -// Copyright (c) 2014-2015 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -namespace rx -{ - -template <typename T, size_t inputComponentCount, size_t outputComponentCount, uint32_t alphaDefaultValueBits> -inline void CopyNativeVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output) -{ - const size_t attribSize = sizeof(T)* inputComponentCount; - - if (attribSize == stride && inputComponentCount == outputComponentCount) - { - memcpy(output, input, count * attribSize); - return; - } - - if (inputComponentCount == outputComponentCount) - { - for (size_t i = 0; i < count; i++) - { - const T *offsetInput = reinterpret_cast<const T*>(input + (i * stride)); - T *offsetOutput = reinterpret_cast<T*>(output) + i * outputComponentCount; - - memcpy(offsetOutput, offsetInput, attribSize); - } - return; - } - - const T defaultAlphaValue = gl::bitCast<T>(alphaDefaultValueBits); - const size_t lastNonAlphaOutputComponent = std::min<size_t>(outputComponentCount, 3); - - for (size_t i = 0; i < count; i++) - { - const T *offsetInput = reinterpret_cast<const T*>(input + (i * stride)); - T *offsetOutput = reinterpret_cast<T*>(output) + i * outputComponentCount; - - memcpy(offsetOutput, offsetInput, attribSize); - - if (inputComponentCount < lastNonAlphaOutputComponent) - { - // Set the remaining G/B channels to 0. - size_t numComponents = (lastNonAlphaOutputComponent - inputComponentCount); - memset(&offsetOutput[inputComponentCount], 0, numComponents * sizeof(T)); - } - - if (inputComponentCount < outputComponentCount && outputComponentCount == 4) - { - // Set the remaining alpha channel to the defaultAlphaValue. - offsetOutput[3] = defaultAlphaValue; - } - } -} - -template <size_t inputComponentCount, size_t outputComponentCount> -inline void Copy8SintTo16SintVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output) -{ - const size_t lastNonAlphaOutputComponent = std::min<size_t>(outputComponentCount, 3); - - for (size_t i = 0; i < count; i++) - { - const GLbyte *offsetInput = reinterpret_cast<const GLbyte*>(input + i * stride); - GLshort *offsetOutput = reinterpret_cast<GLshort*>(output)+i * outputComponentCount; - - for (size_t j = 0; j < inputComponentCount; j++) - { - offsetOutput[j] = static_cast<GLshort>(offsetInput[j]); - } - - for (size_t j = inputComponentCount; j < lastNonAlphaOutputComponent; j++) - { - // Set remaining G/B channels to 0. - offsetOutput[j] = 0; - } - - if (inputComponentCount < outputComponentCount && outputComponentCount == 4) - { - // On integer formats, we must set the Alpha channel to 1 if it's unused. - offsetOutput[3] = 1; - } - } -} - -template <size_t inputComponentCount, size_t outputComponentCount> -inline void Copy8SnormTo16SnormVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output) -{ - for (size_t i = 0; i < count; i++) - { - const GLbyte *offsetInput = reinterpret_cast<const GLbyte*>(input + i * stride); - GLshort *offsetOutput = reinterpret_cast<GLshort*>(output) + i * outputComponentCount; - - for (size_t j = 0; j < inputComponentCount; j++) - { - // The original GLbyte value ranges from -128 to +127 (INT8_MAX). - // When converted to GLshort, the value must be scaled to between -32768 and +32767 (INT16_MAX). - if (offsetInput[j] > 0) - { - offsetOutput[j] = offsetInput[j] << 8 | offsetInput[j] << 1 | ((offsetInput[j] & 0x40) >> 6); - } - else - { - offsetOutput[j] = offsetInput[j] << 8; - } - } - - for (size_t j = inputComponentCount; j < std::min<size_t>(outputComponentCount, 3); j++) - { - // Set remaining G/B channels to 0. - offsetOutput[j] = 0; - } - - if (inputComponentCount < outputComponentCount && outputComponentCount == 4) - { - // On normalized formats, we must set the Alpha channel to the max value if it's unused. - offsetOutput[3] = INT16_MAX; - } - } -} - -template <size_t inputComponentCount, size_t outputComponentCount> -inline void Copy32FixedTo32FVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output) -{ - static const float divisor = 1.0f / (1 << 16); - - for (size_t i = 0; i < count; i++) - { - const GLfixed* offsetInput = reinterpret_cast<const GLfixed*>(input + (stride * i)); - float* offsetOutput = reinterpret_cast<float*>(output) + i * outputComponentCount; - - for (size_t j = 0; j < inputComponentCount; j++) - { - offsetOutput[j] = static_cast<float>(offsetInput[j]) * divisor; - } - - // 4-component output formats would need special padding in the alpha channel. - static_assert(!(inputComponentCount < 4 && outputComponentCount == 4), - "An inputComponentCount less than 4 and an outputComponentCount equal to 4 is not supported."); - - for (size_t j = inputComponentCount; j < outputComponentCount; j++) - { - offsetOutput[j] = 0.0f; - } - } -} - -template <typename T, size_t inputComponentCount, size_t outputComponentCount, bool normalized> -inline void CopyTo32FVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output) -{ - typedef std::numeric_limits<T> NL; - - for (size_t i = 0; i < count; i++) - { - const T *offsetInput = reinterpret_cast<const T*>(input + (stride * i)); - float *offsetOutput = reinterpret_cast<float*>(output) + i * outputComponentCount; - - for (size_t j = 0; j < inputComponentCount; j++) - { - if (normalized) - { - if (NL::is_signed) - { - const float divisor = 1.0f / (2 * static_cast<float>(NL::max()) + 1); - offsetOutput[j] = (2 * static_cast<float>(offsetInput[j]) + 1) * divisor; - } - else - { - offsetOutput[j] = static_cast<float>(offsetInput[j]) / NL::max(); - } - } - else - { - offsetOutput[j] = static_cast<float>(offsetInput[j]); - } - } - - // This would require special padding. - static_assert(!(inputComponentCount < 4 && outputComponentCount == 4), - "An inputComponentCount less than 4 and an outputComponentCount equal to 4 is not supported."); - - for (size_t j = inputComponentCount; j < outputComponentCount; j++) - { - offsetOutput[j] = 0.0f; - } - } -} - -namespace priv -{ - -template <bool isSigned, bool normalized, bool toFloat> -static inline void CopyPackedRGB(uint32_t data, uint8_t *output) -{ - const uint32_t rgbSignMask = 0x200; // 1 set at the 9 bit - const uint32_t negativeMask = 0xFFFFFC00; // All bits from 10 to 31 set to 1 - - if (toFloat) - { - GLfloat *floatOutput = reinterpret_cast<GLfloat*>(output); - if (isSigned) - { - GLfloat finalValue = 0; - if (data & rgbSignMask) - { - int negativeNumber = data | negativeMask; - finalValue = static_cast<GLfloat>(negativeNumber); - } - else - { - finalValue = static_cast<GLfloat>(data); - } - - if (normalized) - { - const int32_t maxValue = 0x1FF; // 1 set in bits 0 through 8 - const int32_t minValue = 0xFFFFFE01; // Inverse of maxValue - - // A 10-bit two's complement number has the possibility of being minValue - 1 but - // OpenGL's normalization rules dictate that it should be clamped to minValue in this - // case. - if (finalValue < minValue) - { - finalValue = minValue; - } - - const int32_t halfRange = (maxValue - minValue) >> 1; - *floatOutput = ((finalValue - minValue) / halfRange) - 1.0f; - } - else - { - *floatOutput = finalValue; - } - } - else - { - if (normalized) - { - const uint32_t maxValue = 0x3FF; // 1 set in bits 0 through 9 - *floatOutput = static_cast<GLfloat>(data) / static_cast<GLfloat>(maxValue); - } - else - { - *floatOutput = static_cast<GLfloat>(data); - } - } - } - else - { - if (isSigned) - { - GLshort *intOutput = reinterpret_cast<GLshort*>(output); - - if (data & rgbSignMask) - { - *intOutput = static_cast<GLshort>(data | negativeMask); - } - else - { - *intOutput = static_cast<GLshort>(data); - } - } - else - { - GLushort *uintOutput = reinterpret_cast<GLushort*>(output); - *uintOutput = static_cast<GLushort>(data); - } - } -} - -template <bool isSigned, bool normalized, bool toFloat> -inline void CopyPackedAlpha(uint32_t data, uint8_t *output) -{ - if (toFloat) - { - GLfloat *floatOutput = reinterpret_cast<GLfloat*>(output); - if (isSigned) - { - if (normalized) - { - switch (data) - { - case 0x0: *floatOutput = 0.0f; break; - case 0x1: *floatOutput = 1.0f; break; - case 0x2: *floatOutput = -1.0f; break; - case 0x3: *floatOutput = -1.0f; break; - default: UNREACHABLE(); - } - } - else - { - switch (data) - { - case 0x0: *floatOutput = 0.0f; break; - case 0x1: *floatOutput = 1.0f; break; - case 0x2: *floatOutput = -2.0f; break; - case 0x3: *floatOutput = -1.0f; break; - default: UNREACHABLE(); - } - } - } - else - { - if (normalized) - { - switch (data) - { - case 0x0: *floatOutput = 0.0f / 3.0f; break; - case 0x1: *floatOutput = 1.0f / 3.0f; break; - case 0x2: *floatOutput = 2.0f / 3.0f; break; - case 0x3: *floatOutput = 3.0f / 3.0f; break; - default: UNREACHABLE(); - } - } - else - { - switch (data) - { - case 0x0: *floatOutput = 0.0f; break; - case 0x1: *floatOutput = 1.0f; break; - case 0x2: *floatOutput = 2.0f; break; - case 0x3: *floatOutput = 3.0f; break; - default: UNREACHABLE(); - } - } - } - } - else - { - if (isSigned) - { - GLshort *intOutput = reinterpret_cast<GLshort*>(output); - switch (data) - { - case 0x0: *intOutput = 0; break; - case 0x1: *intOutput = 1; break; - case 0x2: *intOutput = -2; break; - case 0x3: *intOutput = -1; break; - default: UNREACHABLE(); - } - } - else - { - GLushort *uintOutput = reinterpret_cast<GLushort*>(output); - switch (data) - { - case 0x0: *uintOutput = 0; break; - case 0x1: *uintOutput = 1; break; - case 0x2: *uintOutput = 2; break; - case 0x3: *uintOutput = 3; break; - default: UNREACHABLE(); - } - } - } -} - -} - -template <bool isSigned, bool normalized, bool toFloat> -inline void CopyXYZ10W2ToXYZW32FVertexData(const uint8_t *input, size_t stride, size_t count, uint8_t *output) -{ - const size_t outputComponentSize = toFloat ? 4 : 2; - const size_t componentCount = 4; - - const uint32_t rgbMask = 0x3FF; // 1 set in bits 0 through 9 - const size_t redShift = 0; // red is bits 0 through 9 - const size_t greenShift = 10; // green is bits 10 through 19 - const size_t blueShift = 20; // blue is bits 20 through 29 - - const uint32_t alphaMask = 0x3; // 1 set in bits 0 and 1 - const size_t alphaShift = 30; // Alpha is the 30 and 31 bits - - for (size_t i = 0; i < count; i++) - { - GLuint packedValue = *reinterpret_cast<const GLuint*>(input + (i * stride)); - uint8_t *offsetOutput = output + (i * outputComponentSize * componentCount); - - priv::CopyPackedRGB<isSigned, normalized, toFloat>( (packedValue >> redShift) & rgbMask, offsetOutput + (0 * outputComponentSize)); - priv::CopyPackedRGB<isSigned, normalized, toFloat>( (packedValue >> greenShift) & rgbMask, offsetOutput + (1 * outputComponentSize)); - priv::CopyPackedRGB<isSigned, normalized, toFloat>( (packedValue >> blueShift) & rgbMask, offsetOutput + (2 * outputComponentSize)); - priv::CopyPackedAlpha<isSigned, normalized, toFloat>((packedValue >> alphaShift) & alphaMask, offsetOutput + (3 * outputComponentSize)); - } -} - -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/dxgi_format_data.json b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/dxgi_format_data.json deleted file mode 100644 index 891d30d252..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/dxgi_format_data.json +++ /dev/null @@ -1,118 +0,0 @@ -{ - "UNKNOWN": "NONE", - "R32G32B32A32_TYPELESS": "", - "R32G32B32A32_FLOAT": "", - "R32G32B32A32_UINT": "", - "R32G32B32A32_SINT": "", - "R32G32B32_TYPELESS": "", - "R32G32B32_FLOAT": "", - "R32G32B32_UINT": "", - "R32G32B32_SINT": "", - "R16G16B16A16_TYPELESS": "", - "R16G16B16A16_FLOAT": "", - "R16G16B16A16_UNORM": "", - "R16G16B16A16_UINT": "", - "R16G16B16A16_SNORM": "", - "R16G16B16A16_SINT": "", - "R32G32_TYPELESS": "", - "R32G32_FLOAT": "", - "R32G32_UINT": "", - "R32G32_SINT": "", - "R32G8X24_TYPELESS": "", - "D32_FLOAT_S8X24_UINT": "", - "R32_FLOAT_X8X24_TYPELESS": "", - "X32_TYPELESS_G8X24_UINT": "", - "R10G10B10A2_TYPELESS": "", - "R10G10B10A2_UNORM": "", - "R10G10B10A2_UINT": "", - "R11G11B10_FLOAT": "", - "R8G8B8A8_TYPELESS": "", - "R8G8B8A8_UNORM": "", - "R8G8B8A8_UNORM_SRGB": "", - "R8G8B8A8_UINT": "", - "R8G8B8A8_SNORM": "", - "R8G8B8A8_SINT": "", - "R16G16_TYPELESS": "", - "R16G16_FLOAT": "", - "R16G16_UNORM": "", - "R16G16_UINT": "", - "R16G16_SNORM": "", - "R16G16_SINT": "", - "R32_TYPELESS": "", - "D32_FLOAT": "", - "R32_FLOAT": "", - "R32_UINT": "", - "R32_SINT": "", - "R24G8_TYPELESS": "", - "D24_UNORM_S8_UINT": "", - "R24_UNORM_X8_TYPELESS": "", - "X24_TYPELESS_G8_UINT": "", - "R8G8_TYPELESS": "", - "R8G8_UNORM": "", - "R8G8_UINT": "", - "R8G8_SNORM": "", - "R8G8_SINT": "", - "R16_TYPELESS": "", - "R16_FLOAT": "", - "D16_UNORM": "", - "R16_UNORM": "", - "R16_UINT": "", - "R16_SNORM": "", - "R16_SINT": "", - "R8_TYPELESS": "", - "R8_UNORM": "", - "R8_UINT": "", - "R8_SNORM": "", - "R8_SINT": "", - "A8_UNORM": "", - "R1_UNORM": "", - "R9G9B9E5_SHAREDEXP": "", - "R8G8_B8G8_UNORM": "", - "G8R8_G8B8_UNORM": "", - "BC1_TYPELESS": "", - "BC1_UNORM": "BC1_RGBA_UNORM_BLOCK", - "BC1_UNORM_SRGB": "BC1_RGBA_UNORM_SRGB_BLOCK", - "BC2_TYPELESS": "", - "BC2_UNORM": "BC2_RGBA_UNORM_BLOCK", - "BC2_UNORM_SRGB": "BC2_RGBA_UNORM_SRGB_BLOCK", - "BC3_TYPELESS": "", - "BC3_UNORM": "BC3_RGBA_UNORM_BLOCK", - "BC3_UNORM_SRGB": "BC3_RGBA_UNORM_SRGB_BLOCK", - "BC4_TYPELESS": "", - "BC4_UNORM": "", - "BC4_SNORM": "", - "BC5_TYPELESS": "", - "BC5_UNORM": "", - "BC5_SNORM": "", - "B5G6R5_UNORM": "", - "B5G5R5A1_UNORM": "", - "B8G8R8A8_UNORM": "", - "B8G8R8X8_UNORM": "", - "R10G10B10_XR_BIAS_A2_UNORM": "", - "B8G8R8A8_TYPELESS": "", - "B8G8R8A8_UNORM_SRGB": "", - "B8G8R8X8_TYPELESS": "", - "B8G8R8X8_UNORM_SRGB": "", - "BC6H_TYPELESS": "", - "BC6H_UF16": "", - "BC6H_SF16": "", - "BC7_TYPELESS": "", - "BC7_UNORM": "", - "BC7_UNORM_SRGB": "", - "AYUV": "", - "Y410": "", - "Y416": "", - "NV12": "", - "P010": "", - "P016": "", - "420_OPAQUE": "", - "YUY2": "", - "Y210": "", - "Y216": "", - "NV11": "", - "AI44": "", - "IA44": "", - "P8": "", - "A8P8": "", - "B4G4R4A4_UNORM": "" -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/dxgi_format_map_autogen.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/dxgi_format_map_autogen.cpp deleted file mode 100644 index b0697bc5db..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/dxgi_format_map_autogen.cpp +++ /dev/null @@ -1,516 +0,0 @@ -// GENERATED FILE - DO NOT EDIT. -// Generated by gen_dxgi_format_table.py using data from dxgi_format_data.json. -// -// Copyright 2017 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// DXGI format info: -// Determining metadata about a DXGI format. - -#include "libANGLE/renderer/Format.h" - -using namespace angle; - -namespace rx -{ - -namespace d3d11 -{ - -GLenum GetComponentType(DXGI_FORMAT dxgiFormat) -{ - switch (dxgiFormat) - { - case DXGI_FORMAT_420_OPAQUE: - break; - case DXGI_FORMAT_A8P8: - break; - case DXGI_FORMAT_A8_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_AI44: - break; - case DXGI_FORMAT_AYUV: - break; - case DXGI_FORMAT_B4G4R4A4_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_B5G5R5A1_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_B5G6R5_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_B8G8R8A8_TYPELESS: - break; - case DXGI_FORMAT_B8G8R8A8_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_B8G8R8X8_TYPELESS: - break; - case DXGI_FORMAT_B8G8R8X8_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_BC1_TYPELESS: - break; - case DXGI_FORMAT_BC1_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_BC1_UNORM_SRGB: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_BC2_TYPELESS: - break; - case DXGI_FORMAT_BC2_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_BC2_UNORM_SRGB: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_BC3_TYPELESS: - break; - case DXGI_FORMAT_BC3_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_BC3_UNORM_SRGB: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_BC4_SNORM: - return GL_SIGNED_NORMALIZED; - case DXGI_FORMAT_BC4_TYPELESS: - break; - case DXGI_FORMAT_BC4_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_BC5_SNORM: - return GL_SIGNED_NORMALIZED; - case DXGI_FORMAT_BC5_TYPELESS: - break; - case DXGI_FORMAT_BC5_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_BC6H_SF16: - break; - case DXGI_FORMAT_BC6H_TYPELESS: - break; - case DXGI_FORMAT_BC6H_UF16: - break; - case DXGI_FORMAT_BC7_TYPELESS: - break; - case DXGI_FORMAT_BC7_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_BC7_UNORM_SRGB: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_D16_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_D24_UNORM_S8_UINT: - break; - case DXGI_FORMAT_D32_FLOAT: - return GL_FLOAT; - case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: - break; - case DXGI_FORMAT_G8R8_G8B8_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_IA44: - break; - case DXGI_FORMAT_NV11: - break; - case DXGI_FORMAT_NV12: - break; - case DXGI_FORMAT_P010: - break; - case DXGI_FORMAT_P016: - break; - case DXGI_FORMAT_P8: - break; - case DXGI_FORMAT_R10G10B10A2_TYPELESS: - break; - case DXGI_FORMAT_R10G10B10A2_UINT: - return GL_UNSIGNED_INT; - case DXGI_FORMAT_R10G10B10A2_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_R11G11B10_FLOAT: - return GL_FLOAT; - case DXGI_FORMAT_R16G16B16A16_FLOAT: - return GL_FLOAT; - case DXGI_FORMAT_R16G16B16A16_SINT: - return GL_INT; - case DXGI_FORMAT_R16G16B16A16_SNORM: - return GL_SIGNED_NORMALIZED; - case DXGI_FORMAT_R16G16B16A16_TYPELESS: - break; - case DXGI_FORMAT_R16G16B16A16_UINT: - return GL_UNSIGNED_INT; - case DXGI_FORMAT_R16G16B16A16_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_R16G16_FLOAT: - return GL_FLOAT; - case DXGI_FORMAT_R16G16_SINT: - return GL_INT; - case DXGI_FORMAT_R16G16_SNORM: - return GL_SIGNED_NORMALIZED; - case DXGI_FORMAT_R16G16_TYPELESS: - break; - case DXGI_FORMAT_R16G16_UINT: - return GL_UNSIGNED_INT; - case DXGI_FORMAT_R16G16_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_R16_FLOAT: - return GL_FLOAT; - case DXGI_FORMAT_R16_SINT: - return GL_INT; - case DXGI_FORMAT_R16_SNORM: - return GL_SIGNED_NORMALIZED; - case DXGI_FORMAT_R16_TYPELESS: - break; - case DXGI_FORMAT_R16_UINT: - return GL_UNSIGNED_INT; - case DXGI_FORMAT_R16_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_R1_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_R24G8_TYPELESS: - break; - case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_R32G32B32A32_FLOAT: - return GL_FLOAT; - case DXGI_FORMAT_R32G32B32A32_SINT: - return GL_INT; - case DXGI_FORMAT_R32G32B32A32_TYPELESS: - break; - case DXGI_FORMAT_R32G32B32A32_UINT: - return GL_UNSIGNED_INT; - case DXGI_FORMAT_R32G32B32_FLOAT: - return GL_FLOAT; - case DXGI_FORMAT_R32G32B32_SINT: - return GL_INT; - case DXGI_FORMAT_R32G32B32_TYPELESS: - break; - case DXGI_FORMAT_R32G32B32_UINT: - return GL_UNSIGNED_INT; - case DXGI_FORMAT_R32G32_FLOAT: - return GL_FLOAT; - case DXGI_FORMAT_R32G32_SINT: - return GL_INT; - case DXGI_FORMAT_R32G32_TYPELESS: - break; - case DXGI_FORMAT_R32G32_UINT: - return GL_UNSIGNED_INT; - case DXGI_FORMAT_R32G8X24_TYPELESS: - break; - case DXGI_FORMAT_R32_FLOAT: - return GL_FLOAT; - case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: - return GL_FLOAT; - case DXGI_FORMAT_R32_SINT: - return GL_INT; - case DXGI_FORMAT_R32_TYPELESS: - break; - case DXGI_FORMAT_R32_UINT: - return GL_UNSIGNED_INT; - case DXGI_FORMAT_R8G8B8A8_SINT: - return GL_INT; - case DXGI_FORMAT_R8G8B8A8_SNORM: - return GL_SIGNED_NORMALIZED; - case DXGI_FORMAT_R8G8B8A8_TYPELESS: - break; - case DXGI_FORMAT_R8G8B8A8_UINT: - return GL_UNSIGNED_INT; - case DXGI_FORMAT_R8G8B8A8_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_R8G8_B8G8_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_R8G8_SINT: - return GL_INT; - case DXGI_FORMAT_R8G8_SNORM: - return GL_SIGNED_NORMALIZED; - case DXGI_FORMAT_R8G8_TYPELESS: - break; - case DXGI_FORMAT_R8G8_UINT: - return GL_UNSIGNED_INT; - case DXGI_FORMAT_R8G8_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_R8_SINT: - return GL_INT; - case DXGI_FORMAT_R8_SNORM: - return GL_SIGNED_NORMALIZED; - case DXGI_FORMAT_R8_TYPELESS: - break; - case DXGI_FORMAT_R8_UINT: - return GL_UNSIGNED_INT; - case DXGI_FORMAT_R8_UNORM: - return GL_UNSIGNED_NORMALIZED; - case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: - return GL_FLOAT; - case DXGI_FORMAT_UNKNOWN: - break; - case DXGI_FORMAT_X24_TYPELESS_G8_UINT: - return GL_UNSIGNED_INT; - case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: - return GL_UNSIGNED_INT; - case DXGI_FORMAT_Y210: - break; - case DXGI_FORMAT_Y216: - break; - case DXGI_FORMAT_Y410: - break; - case DXGI_FORMAT_Y416: - break; - case DXGI_FORMAT_YUY2: - break; - default: - break; - } - - UNREACHABLE(); - return GL_NONE; -} - -} // namespace d3d11 - -namespace d3d11_angle -{ - -const Format &GetFormat(DXGI_FORMAT dxgiFormat) -{ - switch (dxgiFormat) - { - case DXGI_FORMAT_420_OPAQUE: - break; - case DXGI_FORMAT_A8P8: - break; - case DXGI_FORMAT_A8_UNORM: - return Format::Get(Format::ID::A8_UNORM); - case DXGI_FORMAT_AI44: - break; - case DXGI_FORMAT_AYUV: - break; - case DXGI_FORMAT_B4G4R4A4_UNORM: - return Format::Get(Format::ID::B4G4R4A4_UNORM); - case DXGI_FORMAT_B5G5R5A1_UNORM: - return Format::Get(Format::ID::B5G5R5A1_UNORM); - case DXGI_FORMAT_B5G6R5_UNORM: - return Format::Get(Format::ID::B5G6R5_UNORM); - case DXGI_FORMAT_B8G8R8A8_TYPELESS: - break; - case DXGI_FORMAT_B8G8R8A8_UNORM: - return Format::Get(Format::ID::B8G8R8A8_UNORM); - case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: - return Format::Get(Format::ID::B8G8R8A8_UNORM_SRGB); - case DXGI_FORMAT_B8G8R8X8_TYPELESS: - break; - case DXGI_FORMAT_B8G8R8X8_UNORM: - return Format::Get(Format::ID::B8G8R8X8_UNORM); - case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: - break; - case DXGI_FORMAT_BC1_TYPELESS: - break; - case DXGI_FORMAT_BC1_UNORM: - return Format::Get(Format::ID::BC1_RGBA_UNORM_BLOCK); - case DXGI_FORMAT_BC1_UNORM_SRGB: - return Format::Get(Format::ID::BC1_RGBA_UNORM_SRGB_BLOCK); - case DXGI_FORMAT_BC2_TYPELESS: - break; - case DXGI_FORMAT_BC2_UNORM: - return Format::Get(Format::ID::BC2_RGBA_UNORM_BLOCK); - case DXGI_FORMAT_BC2_UNORM_SRGB: - return Format::Get(Format::ID::BC2_RGBA_UNORM_SRGB_BLOCK); - case DXGI_FORMAT_BC3_TYPELESS: - break; - case DXGI_FORMAT_BC3_UNORM: - return Format::Get(Format::ID::BC3_RGBA_UNORM_BLOCK); - case DXGI_FORMAT_BC3_UNORM_SRGB: - return Format::Get(Format::ID::BC3_RGBA_UNORM_SRGB_BLOCK); - case DXGI_FORMAT_BC4_SNORM: - break; - case DXGI_FORMAT_BC4_TYPELESS: - break; - case DXGI_FORMAT_BC4_UNORM: - break; - case DXGI_FORMAT_BC5_SNORM: - break; - case DXGI_FORMAT_BC5_TYPELESS: - break; - case DXGI_FORMAT_BC5_UNORM: - break; - case DXGI_FORMAT_BC6H_SF16: - break; - case DXGI_FORMAT_BC6H_TYPELESS: - break; - case DXGI_FORMAT_BC6H_UF16: - break; - case DXGI_FORMAT_BC7_TYPELESS: - break; - case DXGI_FORMAT_BC7_UNORM: - break; - case DXGI_FORMAT_BC7_UNORM_SRGB: - break; - case DXGI_FORMAT_D16_UNORM: - return Format::Get(Format::ID::D16_UNORM); - case DXGI_FORMAT_D24_UNORM_S8_UINT: - return Format::Get(Format::ID::D24_UNORM_S8_UINT); - case DXGI_FORMAT_D32_FLOAT: - return Format::Get(Format::ID::D32_FLOAT); - case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: - return Format::Get(Format::ID::D32_FLOAT_S8X24_UINT); - case DXGI_FORMAT_G8R8_G8B8_UNORM: - break; - case DXGI_FORMAT_IA44: - break; - case DXGI_FORMAT_NV11: - break; - case DXGI_FORMAT_NV12: - break; - case DXGI_FORMAT_P010: - break; - case DXGI_FORMAT_P016: - break; - case DXGI_FORMAT_P8: - break; - case DXGI_FORMAT_R10G10B10A2_TYPELESS: - break; - case DXGI_FORMAT_R10G10B10A2_UINT: - return Format::Get(Format::ID::R10G10B10A2_UINT); - case DXGI_FORMAT_R10G10B10A2_UNORM: - return Format::Get(Format::ID::R10G10B10A2_UNORM); - case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: - break; - case DXGI_FORMAT_R11G11B10_FLOAT: - return Format::Get(Format::ID::R11G11B10_FLOAT); - case DXGI_FORMAT_R16G16B16A16_FLOAT: - return Format::Get(Format::ID::R16G16B16A16_FLOAT); - case DXGI_FORMAT_R16G16B16A16_SINT: - return Format::Get(Format::ID::R16G16B16A16_SINT); - case DXGI_FORMAT_R16G16B16A16_SNORM: - return Format::Get(Format::ID::R16G16B16A16_SNORM); - case DXGI_FORMAT_R16G16B16A16_TYPELESS: - break; - case DXGI_FORMAT_R16G16B16A16_UINT: - return Format::Get(Format::ID::R16G16B16A16_UINT); - case DXGI_FORMAT_R16G16B16A16_UNORM: - return Format::Get(Format::ID::R16G16B16A16_UNORM); - case DXGI_FORMAT_R16G16_FLOAT: - return Format::Get(Format::ID::R16G16_FLOAT); - case DXGI_FORMAT_R16G16_SINT: - return Format::Get(Format::ID::R16G16_SINT); - case DXGI_FORMAT_R16G16_SNORM: - return Format::Get(Format::ID::R16G16_SNORM); - case DXGI_FORMAT_R16G16_TYPELESS: - break; - case DXGI_FORMAT_R16G16_UINT: - return Format::Get(Format::ID::R16G16_UINT); - case DXGI_FORMAT_R16G16_UNORM: - return Format::Get(Format::ID::R16G16_UNORM); - case DXGI_FORMAT_R16_FLOAT: - return Format::Get(Format::ID::R16_FLOAT); - case DXGI_FORMAT_R16_SINT: - return Format::Get(Format::ID::R16_SINT); - case DXGI_FORMAT_R16_SNORM: - return Format::Get(Format::ID::R16_SNORM); - case DXGI_FORMAT_R16_TYPELESS: - break; - case DXGI_FORMAT_R16_UINT: - return Format::Get(Format::ID::R16_UINT); - case DXGI_FORMAT_R16_UNORM: - return Format::Get(Format::ID::R16_UNORM); - case DXGI_FORMAT_R1_UNORM: - break; - case DXGI_FORMAT_R24G8_TYPELESS: - break; - case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: - break; - case DXGI_FORMAT_R32G32B32A32_FLOAT: - return Format::Get(Format::ID::R32G32B32A32_FLOAT); - case DXGI_FORMAT_R32G32B32A32_SINT: - return Format::Get(Format::ID::R32G32B32A32_SINT); - case DXGI_FORMAT_R32G32B32A32_TYPELESS: - break; - case DXGI_FORMAT_R32G32B32A32_UINT: - return Format::Get(Format::ID::R32G32B32A32_UINT); - case DXGI_FORMAT_R32G32B32_FLOAT: - return Format::Get(Format::ID::R32G32B32_FLOAT); - case DXGI_FORMAT_R32G32B32_SINT: - return Format::Get(Format::ID::R32G32B32_SINT); - case DXGI_FORMAT_R32G32B32_TYPELESS: - break; - case DXGI_FORMAT_R32G32B32_UINT: - return Format::Get(Format::ID::R32G32B32_UINT); - case DXGI_FORMAT_R32G32_FLOAT: - return Format::Get(Format::ID::R32G32_FLOAT); - case DXGI_FORMAT_R32G32_SINT: - return Format::Get(Format::ID::R32G32_SINT); - case DXGI_FORMAT_R32G32_TYPELESS: - break; - case DXGI_FORMAT_R32G32_UINT: - return Format::Get(Format::ID::R32G32_UINT); - case DXGI_FORMAT_R32G8X24_TYPELESS: - break; - case DXGI_FORMAT_R32_FLOAT: - return Format::Get(Format::ID::R32_FLOAT); - case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: - break; - case DXGI_FORMAT_R32_SINT: - return Format::Get(Format::ID::R32_SINT); - case DXGI_FORMAT_R32_TYPELESS: - break; - case DXGI_FORMAT_R32_UINT: - return Format::Get(Format::ID::R32_UINT); - case DXGI_FORMAT_R8G8B8A8_SINT: - return Format::Get(Format::ID::R8G8B8A8_SINT); - case DXGI_FORMAT_R8G8B8A8_SNORM: - return Format::Get(Format::ID::R8G8B8A8_SNORM); - case DXGI_FORMAT_R8G8B8A8_TYPELESS: - break; - case DXGI_FORMAT_R8G8B8A8_UINT: - return Format::Get(Format::ID::R8G8B8A8_UINT); - case DXGI_FORMAT_R8G8B8A8_UNORM: - return Format::Get(Format::ID::R8G8B8A8_UNORM); - case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: - return Format::Get(Format::ID::R8G8B8A8_UNORM_SRGB); - case DXGI_FORMAT_R8G8_B8G8_UNORM: - break; - case DXGI_FORMAT_R8G8_SINT: - return Format::Get(Format::ID::R8G8_SINT); - case DXGI_FORMAT_R8G8_SNORM: - return Format::Get(Format::ID::R8G8_SNORM); - case DXGI_FORMAT_R8G8_TYPELESS: - break; - case DXGI_FORMAT_R8G8_UINT: - return Format::Get(Format::ID::R8G8_UINT); - case DXGI_FORMAT_R8G8_UNORM: - return Format::Get(Format::ID::R8G8_UNORM); - case DXGI_FORMAT_R8_SINT: - return Format::Get(Format::ID::R8_SINT); - case DXGI_FORMAT_R8_SNORM: - return Format::Get(Format::ID::R8_SNORM); - case DXGI_FORMAT_R8_TYPELESS: - break; - case DXGI_FORMAT_R8_UINT: - return Format::Get(Format::ID::R8_UINT); - case DXGI_FORMAT_R8_UNORM: - return Format::Get(Format::ID::R8_UNORM); - case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: - return Format::Get(Format::ID::R9G9B9E5_SHAREDEXP); - case DXGI_FORMAT_UNKNOWN: - return Format::Get(Format::ID::NONE); - case DXGI_FORMAT_X24_TYPELESS_G8_UINT: - break; - case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: - break; - case DXGI_FORMAT_Y210: - break; - case DXGI_FORMAT_Y216: - break; - case DXGI_FORMAT_Y410: - break; - case DXGI_FORMAT_Y416: - break; - case DXGI_FORMAT_YUY2: - break; - default: - break; - } - - UNREACHABLE(); - return Format::Get(Format::ID::NONE); -} - -} // namespace d3d11_angle - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/dxgi_support_data.json b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/dxgi_support_data.json deleted file mode 100644 index 942745674f..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/dxgi_support_data.json +++ /dev/null @@ -1,1279 +0,0 @@ -[ - { - "DXGI_FORMAT_UNKNOWN": - { - "texture2D": "never", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R32G32B32A32_TYPELESS": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R32G32B32A32_FLOAT": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "10_0check10_1always", - "renderTarget": "always", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "always" - }, - "DXGI_FORMAT_R32G32B32A32_UINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R32G32B32A32_SINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R32G32B32_TYPELESS": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R32G32B32_FLOAT": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "11_0check", - "renderTarget": "check", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R32G32B32_UINT": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "check", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R32G32B32_SINT": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "check", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R16G16B16A16_TYPELESS": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R16G16B16A16_FLOAT": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "9_3check_10_0always", - "renderTarget": "always", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "always" - }, - "DXGI_FORMAT_R16G16B16A16_UNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "always", - "renderTarget": "always", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "always" - }, - "DXGI_FORMAT_R16G16B16A16_UINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R16G16B16A16_SNORM": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "10_0", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "10_0" - }, - "DXGI_FORMAT_R16G16B16A16_SINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R32G32_TYPELESS": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R32G32_FLOAT": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "10_0check10_1always", - "renderTarget": "always", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "10_0" - }, - "DXGI_FORMAT_R32G32_UINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R32G32_SINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R32G8X24_TYPELESS": - { - "texture2D": "10_0", - "texture3D": "never", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_D32_FLOAT_S8X24_UINT": - { - "texture2D": "always", - "texture3D": "never", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "check", - "depthStencil": "10_0", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS": - { - "texture2D": "always", - "texture3D": "never", - "textureCube": "always", - "shaderSample": "10_0check10_1always", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_X32_TYPELESS_G8X24_UINT": - { - "texture2D": "always", - "texture3D": "never", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R10G10B10A2_TYPELESS": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R10G10B10A2_UNORM": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "10_0", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "10_0" - }, - "DXGI_FORMAT_R10G10B10A2_UINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R11G11B10_FLOAT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "10_0", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "10_0" - }, - "DXGI_FORMAT_R8G8B8A8_TYPELESS": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R8G8B8A8_UNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "always", - "renderTarget": "always", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "always" - }, - "DXGI_FORMAT_R8G8B8A8_UNORM_SRGB": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "always", - "renderTarget": "always", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "always" - }, - "DXGI_FORMAT_R8G8B8A8_UINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R8G8B8A8_SNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "always", - "renderTarget": "always", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "10_0" - }, - "DXGI_FORMAT_R8G8B8A8_SINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R16G16_TYPELESS": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R16G16_FLOAT": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "10_0", - "renderTarget": "always", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "always" - }, - "DXGI_FORMAT_R16G16_UNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "always", - "renderTarget": "always", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "always" - }, - "DXGI_FORMAT_R16G16_UINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R16G16_SNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "always", - "renderTarget": "always", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "10_0" - }, - "DXGI_FORMAT_R16G16_SINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R32_TYPELESS": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_D32_FLOAT": - { - "texture2D": "always", - "texture3D": "never", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "check", - "depthStencil": "10_0", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R32_FLOAT": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "10_0check10_1always", - "renderTarget": "always", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "always" - }, - "DXGI_FORMAT_R32_UINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R32_SINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R24G8_TYPELESS": - { - "texture2D": "always", - "texture3D": "never", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_D24_UNORM_S8_UINT": - { - "texture2D": "always", - "texture3D": "never", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "check", - "depthStencil": "always" - }, - "DXGI_FORMAT_R24_UNORM_X8_TYPELESS": - { - "texture2D": "always", - "texture3D": "never", - "textureCube": "always", - "shaderSample": "10_0check10_1always", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_X24_TYPELESS_G8_UINT": - { - "texture2D": "always", - "texture3D": "never", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R8G8_TYPELESS": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R8G8_UNORM": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "9_3check_10_0always", - "renderTarget": "9_3check_10_0always", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "10_0" - }, - "DXGI_FORMAT_R8G8_UINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R8G8_SNORM": - { - "texture2D": "always", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "always", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "10_0" - }, - "DXGI_FORMAT_R8G8_SINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R16_TYPELESS": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R16_FLOAT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "10_0", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "10_0" - }, - "DXGI_FORMAT_D16_UNORM": - { - "texture2D": "always", - "texture3D": "never", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "check", - "depthStencil": "always", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R16_UNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "always", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "10_0" - }, - "DXGI_FORMAT_R16_UINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R16_SNORM": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "10_0", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "10_0" - }, - "DXGI_FORMAT_R16_SINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R8_TYPELESS": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R8_UNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "always", - "renderTarget": "9_3check_10_0always", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "10_0" - }, - "DXGI_FORMAT_R8_UINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R8_SNORM": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "10_0", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "10_0" - }, - "DXGI_FORMAT_R8_SINT": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "never", - "renderTarget": "10_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_A8_UNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "10_0", - "renderTarget": "always", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "10_0" - }, - "DXGI_FORMAT_R1_UNORM": - { - "texture2D": "always", - "texture3D": "11_0", - "textureCube": "11_0", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R9G9B9E5_SHAREDEXP": - { - "texture2D": "10_0", - "texture3D": "10_0", - "textureCube": "10_0", - "shaderSample": "10_0", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R8G8_B8G8_UNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "10_0", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_G8R8_G8B8_UNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "10_0", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC1_TYPELESS": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC1_UNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "always", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC1_UNORM_SRGB": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "always", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC2_TYPELESS": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC2_UNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "always", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC2_UNORM_SRGB": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "always", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC3_TYPELESS": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC3_UNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "always", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC3_UNORM_SRGB": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "always", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC4_TYPELESS": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC4_UNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "10_0", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC4_SNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "10_0", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC5_TYPELESS": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC5_UNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "10_0", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC5_SNORM": - { - "texture2D": "always", - "texture3D": "always", - "textureCube": "always", - "shaderSample": "10_0", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_B5G6R5_UNORM": - { - "texture2D": "dxgi1_2", - "texture3D": "dxgi1_2", - "textureCube": "dxgi1_2", - "shaderSample": "dxgi1_2", - "renderTarget": "dxgi1_2", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "dxgi1_2" - }, - "DXGI_FORMAT_B5G5R5A1_UNORM": - { - "texture2D": "dxgi1_2", - "texture3D": "dxgi1_2", - "textureCube": "dxgi1_2", - "shaderSample": "dxgi1_2", - "renderTarget": "check", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "dxgi1_2" - }, - "DXGI_FORMAT_B8G8R8A8_UNORM": - { - "texture2D": "check", - "texture3D": "check", - "textureCube": "check", - "shaderSample": "9_3always_10_0check11_0always", - "renderTarget": "9_3always_10_0check11_0always", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "always" - }, - "DXGI_FORMAT_B8G8R8X8_UNORM": - { - "texture2D": "check", - "texture3D": "check", - "textureCube": "check", - "shaderSample": "10_0check11_0always", - "renderTarget": "11_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM": - { - "texture2D": "check", - "texture3D": "check", - "textureCube": "never", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_B8G8R8A8_TYPELESS": - { - "texture2D": "check", - "texture3D": "check", - "textureCube": "check", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_B8G8R8A8_UNORM_SRGB": - { - "texture2D": "check", - "texture3D": "check", - "textureCube": "check", - "shaderSample": "10_0check11_0always", - "renderTarget": "11_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_B8G8R8X8_TYPELESS": - { - "texture2D": "check", - "texture3D": "check", - "textureCube": "check", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_B8G8R8X8_UNORM_SRGB": - { - "texture2D": "check", - "texture3D": "check", - "textureCube": "check", - "shaderSample": "10_0check11_0always", - "renderTarget": "11_0", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC6H_TYPELESS": - { - "texture2D": "11_0", - "texture3D": "11_0", - "textureCube": "11_0", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC6H_UF16": - { - "texture2D": "11_0", - "texture3D": "11_0", - "textureCube": "11_0", - "shaderSample": "11_0", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC6H_SF16": - { - "texture2D": "11_0", - "texture3D": "11_0", - "textureCube": "11_0", - "shaderSample": "11_0", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC7_TYPELESS": - { - "texture2D": "11_0", - "texture3D": "11_0", - "textureCube": "11_0", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC7_UNORM": - { - "texture2D": "11_0", - "texture3D": "11_0", - "textureCube": "11_0", - "shaderSample": "11_0", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_BC7_UNORM_SRGB": - { - "texture2D": "11_0", - "texture3D": "11_0", - "textureCube": "11_0", - "shaderSample": "11_0", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_AYUV": - { - "texture2D": "11_1", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "11_1", - "renderTarget": "11_1", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_Y410": - { - "texture2D": "11_1", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "11_1", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_Y416": - { - "texture2D": "11_1", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "11_1", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_NV12": - { - "texture2D": "11_1", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "11_1", - "renderTarget": "11_1", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_P010": - { - "texture2D": "11_1", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "11_1", - "renderTarget": "11_1", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_P016": - { - "texture2D": "11_1", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "11_1", - "renderTarget": "11_1", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_420_OPAQUE": - { - "texture2D": "11_1", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_YUY2": - { - "texture2D": "11_1", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "11_1", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_Y210": - { - "texture2D": "11_1", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "11_1", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_Y216": - { - "texture2D": "11_1", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "11_1", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_NV11": - { - "texture2D": "11_1", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "11_1", - "renderTarget": "11_1", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_AI44": - { - "texture2D": "11_1", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_IA44": - { - "texture2D": "11_1", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_P8": - { - "texture2D": "11_1", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_A8P8": - { - "texture2D": "11_1", - "texture3D": "never", - "textureCube": "never", - "shaderSample": "never", - "renderTarget": "never", - "multisampleRT": "never", - "depthStencil": "never", - "mipAutoGen": "never" - }, - "DXGI_FORMAT_B4G4R4A4_UNORM": - { - "texture2D": "dxgi1_2", - "texture3D": "dxgi1_2", - "textureCube": "dxgi1_2", - "shaderSample": "dxgi1_2", - "renderTarget": "check", - "multisampleRT": "check", - "depthStencil": "never", - "mipAutoGen": "dxgi1_2" - } - } -] diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/dxgi_support_table.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/dxgi_support_table.cpp deleted file mode 100644 index 4d7e46bdf2..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/dxgi_support_table.cpp +++ /dev/null @@ -1,3042 +0,0 @@ -// GENERATED FILE - DO NOT EDIT. See dxgi_support_data.json. -// -// Copyright 2015 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// dxgi_support_table: -// Queries for DXGI support of various texture formats. Depends on DXGI -// version, D3D feature level, and is sometimes guaranteed or optional. -// - -#include "libANGLE/renderer/d3d/d3d11/dxgi_support_table.h" - -#include "common/debug.h" - -namespace rx -{ - -namespace d3d11 -{ - -#define F_2D D3D11_FORMAT_SUPPORT_TEXTURE2D -#define F_3D D3D11_FORMAT_SUPPORT_TEXTURE3D -#define F_CUBE D3D11_FORMAT_SUPPORT_TEXTURECUBE -#define F_SAMPLE D3D11_FORMAT_SUPPORT_SHADER_SAMPLE -#define F_RT D3D11_FORMAT_SUPPORT_RENDER_TARGET -#define F_MS D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET -#define F_DS D3D11_FORMAT_SUPPORT_DEPTH_STENCIL -#define F_MIPGEN D3D11_FORMAT_SUPPORT_MIP_AUTOGEN - -namespace -{ - -const DXGISupport &GetDefaultSupport() -{ - static UINT AllSupportFlags = - D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURE3D | - D3D11_FORMAT_SUPPORT_TEXTURECUBE | D3D11_FORMAT_SUPPORT_SHADER_SAMPLE | - D3D11_FORMAT_SUPPORT_RENDER_TARGET | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET | - D3D11_FORMAT_SUPPORT_DEPTH_STENCIL | D3D11_FORMAT_SUPPORT_MIP_AUTOGEN; - static const DXGISupport defaultSupport(0, 0, AllSupportFlags); - return defaultSupport; -} - -const DXGISupport &GetDXGISupport_9_3(DXGI_FORMAT dxgiFormat) -{ - // clang-format off - switch (dxgiFormat) - { - case DXGI_FORMAT_420_OPAQUE: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_A8P8: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_A8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_AI44: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_AYUV: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_B4G4R4A4_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_SAMPLE, F_DS, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_B5G5R5A1_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_SAMPLE, F_DS, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_B5G6R5_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_B8G8R8A8_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, F_2D | F_3D | F_CUBE); - return info; - } - case DXGI_FORMAT_B8G8R8A8_UNORM: - { - static const DXGISupport info(F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_2D | F_3D | F_CUBE | F_MS); - return info; - } - case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: - { - static const DXGISupport info(0, F_DS | F_MIPGEN, F_2D | F_3D | F_CUBE | F_MS); - return info; - } - case DXGI_FORMAT_B8G8R8X8_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, F_2D | F_3D | F_CUBE); - return info; - } - case DXGI_FORMAT_B8G8R8X8_UNORM: - { - static const DXGISupport info(0, F_DS | F_MIPGEN, F_2D | F_3D | F_CUBE | F_MS); - return info; - } - case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: - { - static const DXGISupport info(0, F_DS | F_MIPGEN, F_2D | F_3D | F_CUBE | F_MS); - return info; - } - case DXGI_FORMAT_BC1_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC1_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC1_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC2_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC2_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC2_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC3_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC3_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC3_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC4_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC4_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC4_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC5_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC5_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC5_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC6H_SF16: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC6H_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC6H_UF16: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC7_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC7_UNORM: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC7_UNORM_SRGB: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_D16_UNORM: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_MIPGEN | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_D24_UNORM_S8_UINT: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_D32_FLOAT: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_MIPGEN | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_MIPGEN | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_G8R8_G8B8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_IA44: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_NV11: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_NV12: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_P010: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_P016: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_P8: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R10G10B10A2_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R10G10B10A2_UINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R10G10B10A2_UNORM: - { - static const DXGISupport info(0, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: - { - static const DXGISupport info(0, F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, F_2D | F_3D); - return info; - } - case DXGI_FORMAT_R11G11B10_FLOAT: - { - static const DXGISupport info(0, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT, F_DS, F_MS | F_SAMPLE); - return info; - } - case DXGI_FORMAT_R16G16B16A16_SINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_SNORM: - { - static const DXGISupport info(0, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R16G16B16A16_UINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_SINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R16G16_UINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16_FLOAT: - { - static const DXGISupport info(0, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16_SINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16_SNORM: - { - static const DXGISupport info(0, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R16_UINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R1_UNORM: - { - static const DXGISupport info(F_2D, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R24G8_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_R32G32B32A32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R32G32B32A32_SINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G32B32A32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32G32B32A32_UINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G32B32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R32G32B32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_SAMPLE, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R32G32B32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32G32B32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_SAMPLE, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R32G32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R32G32_SINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32G32_UINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G8X24_TYPELESS: - { - static const DXGISupport info(0, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_R32_SINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32_UINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_SINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R8G8B8A8_UINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_B8G8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_R8G8_SINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_SNORM: - { - static const DXGISupport info(F_2D | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R8G8_UINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_UNORM: - { - static const DXGISupport info(0, F_DS, F_MS | F_RT | F_SAMPLE); - return info; - } - case DXGI_FORMAT_R8_SINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8_SNORM: - { - static const DXGISupport info(0, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R8_UINT: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_UNKNOWN: - { - static const DXGISupport info(0, F_2D | F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_X24_TYPELESS_G8_UINT: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_Y210: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_Y216: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_Y410: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_Y416: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_YUY2: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - - default: - UNREACHABLE(); - return GetDefaultSupport(); - } - // clang-format on -} - -const DXGISupport &GetDXGISupport_10_0(DXGI_FORMAT dxgiFormat) -{ - // clang-format off - switch (dxgiFormat) - { - case DXGI_FORMAT_420_OPAQUE: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_A8P8: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_A8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_AI44: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_AYUV: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_B4G4R4A4_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_SAMPLE, F_DS, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_B5G5R5A1_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_SAMPLE, F_DS, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_B5G6R5_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_B8G8R8A8_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, F_2D | F_3D | F_CUBE); - return info; - } - case DXGI_FORMAT_B8G8R8A8_UNORM: - { - static const DXGISupport info(F_MIPGEN, F_DS, F_2D | F_3D | F_CUBE | F_MS | F_RT | F_SAMPLE); - return info; - } - case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: - { - static const DXGISupport info(0, F_DS | F_MIPGEN, F_2D | F_3D | F_CUBE | F_MS | F_SAMPLE); - return info; - } - case DXGI_FORMAT_B8G8R8X8_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, F_2D | F_3D | F_CUBE); - return info; - } - case DXGI_FORMAT_B8G8R8X8_UNORM: - { - static const DXGISupport info(0, F_DS | F_MIPGEN, F_2D | F_3D | F_CUBE | F_MS | F_SAMPLE); - return info; - } - case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: - { - static const DXGISupport info(0, F_DS | F_MIPGEN, F_2D | F_3D | F_CUBE | F_MS | F_SAMPLE); - return info; - } - case DXGI_FORMAT_BC1_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC1_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC1_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC2_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC2_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC2_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC3_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC3_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC3_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC4_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC4_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC4_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC5_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC5_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC5_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC6H_SF16: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC6H_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC6H_UF16: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC7_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC7_UNORM: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC7_UNORM_SRGB: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_D16_UNORM: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_MIPGEN | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_D24_UNORM_S8_UINT: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_D32_FLOAT: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_MIPGEN | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_MIPGEN | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_G8R8_G8B8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_IA44: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_NV11: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_NV12: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_P010: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_P016: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_P8: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R10G10B10A2_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R10G10B10A2_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R10G10B10A2_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: - { - static const DXGISupport info(0, F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, F_2D | F_3D); - return info; - } - case DXGI_FORMAT_R11G11B10_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R16G16B16A16_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R16G16_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R16_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R1_UNORM: - { - static const DXGISupport info(F_2D, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R24G8_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT, F_SAMPLE); - return info; - } - case DXGI_FORMAT_R32G32B32A32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT, F_DS, F_MS | F_SAMPLE); - return info; - } - case DXGI_FORMAT_R32G32B32A32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G32B32A32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32G32B32A32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G32B32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R32G32B32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_SAMPLE, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R32G32B32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32G32B32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_SAMPLE, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R32G32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT, F_DS, F_MS | F_SAMPLE); - return info; - } - case DXGI_FORMAT_R32G32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32G32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G8X24_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT, F_DS, F_MS | F_SAMPLE); - return info; - } - case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT, F_SAMPLE); - return info; - } - case DXGI_FORMAT_R32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R8G8B8A8_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_B8G8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_R8G8_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R8G8_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R8_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_UNKNOWN: - { - static const DXGISupport info(0, F_2D | F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_X24_TYPELESS_G8_UINT: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_Y210: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_Y216: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_Y410: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_Y416: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_YUY2: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - - default: - UNREACHABLE(); - return GetDefaultSupport(); - } - // clang-format on -} - -const DXGISupport &GetDXGISupport_10_1(DXGI_FORMAT dxgiFormat) -{ - // clang-format off - switch (dxgiFormat) - { - case DXGI_FORMAT_420_OPAQUE: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_A8P8: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_A8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_AI44: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_AYUV: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_B4G4R4A4_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_SAMPLE, F_DS, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_B5G5R5A1_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_SAMPLE, F_DS, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_B5G6R5_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_B8G8R8A8_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, F_2D | F_3D | F_CUBE); - return info; - } - case DXGI_FORMAT_B8G8R8A8_UNORM: - { - static const DXGISupport info(F_MIPGEN, F_DS, F_2D | F_3D | F_CUBE | F_MS | F_RT | F_SAMPLE); - return info; - } - case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: - { - static const DXGISupport info(0, F_DS | F_MIPGEN, F_2D | F_3D | F_CUBE | F_MS | F_SAMPLE); - return info; - } - case DXGI_FORMAT_B8G8R8X8_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, F_2D | F_3D | F_CUBE); - return info; - } - case DXGI_FORMAT_B8G8R8X8_UNORM: - { - static const DXGISupport info(0, F_DS | F_MIPGEN, F_2D | F_3D | F_CUBE | F_MS | F_SAMPLE); - return info; - } - case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: - { - static const DXGISupport info(0, F_DS | F_MIPGEN, F_2D | F_3D | F_CUBE | F_MS | F_SAMPLE); - return info; - } - case DXGI_FORMAT_BC1_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC1_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC1_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC2_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC2_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC2_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC3_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC3_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC3_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC4_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC4_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC4_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC5_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC5_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC5_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC6H_SF16: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC6H_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC6H_UF16: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC7_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC7_UNORM: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC7_UNORM_SRGB: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_D16_UNORM: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_MIPGEN | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_D24_UNORM_S8_UINT: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_D32_FLOAT: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_MIPGEN | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_MIPGEN | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_G8R8_G8B8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_IA44: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_NV11: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_NV12: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_P010: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_P016: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_P8: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R10G10B10A2_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R10G10B10A2_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R10G10B10A2_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: - { - static const DXGISupport info(0, F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, F_2D | F_3D); - return info; - } - case DXGI_FORMAT_R11G11B10_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R16G16B16A16_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R16G16_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R16_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R1_UNORM: - { - static const DXGISupport info(F_2D, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R24G8_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE | F_SAMPLE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_R32G32B32A32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R32G32B32A32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G32B32A32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32G32B32A32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G32B32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R32G32B32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_SAMPLE, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R32G32B32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32G32B32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_SAMPLE, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R32G32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R32G32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32G32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G8X24_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE | F_SAMPLE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_R32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R8G8B8A8_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_B8G8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_R8G8_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R8G8_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R8_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_UNKNOWN: - { - static const DXGISupport info(0, F_2D | F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_X24_TYPELESS_G8_UINT: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_Y210: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_Y216: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_Y410: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_Y416: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_YUY2: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - - default: - UNREACHABLE(); - return GetDefaultSupport(); - } - // clang-format on -} - -const DXGISupport &GetDXGISupport_11_0(DXGI_FORMAT dxgiFormat) -{ - // clang-format off - switch (dxgiFormat) - { - case DXGI_FORMAT_420_OPAQUE: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_A8P8: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_A8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_AI44: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_AYUV: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_B4G4R4A4_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_SAMPLE, F_DS, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_B5G5R5A1_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_SAMPLE, F_DS, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_B5G6R5_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_B8G8R8A8_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, F_2D | F_3D | F_CUBE); - return info; - } - case DXGI_FORMAT_B8G8R8A8_UNORM: - { - static const DXGISupport info(F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_2D | F_3D | F_CUBE | F_MS); - return info; - } - case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: - { - static const DXGISupport info(F_RT | F_SAMPLE, F_DS | F_MIPGEN, F_2D | F_3D | F_CUBE | F_MS); - return info; - } - case DXGI_FORMAT_B8G8R8X8_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, F_2D | F_3D | F_CUBE); - return info; - } - case DXGI_FORMAT_B8G8R8X8_UNORM: - { - static const DXGISupport info(F_RT | F_SAMPLE, F_DS | F_MIPGEN, F_2D | F_3D | F_CUBE | F_MS); - return info; - } - case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: - { - static const DXGISupport info(F_RT | F_SAMPLE, F_DS | F_MIPGEN, F_2D | F_3D | F_CUBE | F_MS); - return info; - } - case DXGI_FORMAT_BC1_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC1_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC1_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC2_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC2_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC2_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC3_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC3_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC3_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC4_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC4_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC4_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC5_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC5_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC5_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC6H_SF16: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC6H_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC6H_UF16: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC7_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC7_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC7_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_D16_UNORM: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_MIPGEN | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_D24_UNORM_S8_UINT: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_D32_FLOAT: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_MIPGEN | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_MIPGEN | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_G8R8_G8B8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_IA44: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_NV11: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_NV12: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_P010: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_P016: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_P8: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R10G10B10A2_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R10G10B10A2_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R10G10B10A2_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: - { - static const DXGISupport info(0, F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, F_2D | F_3D); - return info; - } - case DXGI_FORMAT_R11G11B10_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R16G16B16A16_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R16G16_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R16_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R1_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R24G8_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE | F_SAMPLE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_R32G32B32A32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R32G32B32A32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G32B32A32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32G32B32A32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G32B32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R32G32B32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_SAMPLE, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R32G32B32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32G32B32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_SAMPLE, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R32G32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R32G32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32G32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G8X24_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE | F_SAMPLE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_R32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R8G8B8A8_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_B8G8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_R8G8_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R8G8_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R8_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_UNKNOWN: - { - static const DXGISupport info(0, F_2D | F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_X24_TYPELESS_G8_UINT: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_Y210: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_Y216: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_Y410: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_Y416: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_YUY2: - { - static const DXGISupport info(0, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - - default: - UNREACHABLE(); - return GetDefaultSupport(); - } - // clang-format on -} - -const DXGISupport &GetDXGISupport_11_1(DXGI_FORMAT dxgiFormat) -{ - // clang-format off - switch (dxgiFormat) - { - case DXGI_FORMAT_420_OPAQUE: - { - static const DXGISupport info(F_2D, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_A8P8: - { - static const DXGISupport info(F_2D, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_A8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_AI44: - { - static const DXGISupport info(F_2D, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_AYUV: - { - static const DXGISupport info(F_2D | F_RT | F_SAMPLE, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_B4G4R4A4_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_SAMPLE, F_DS, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_B5G5R5A1_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_SAMPLE, F_DS, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_B5G6R5_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_B8G8R8A8_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, F_2D | F_3D | F_CUBE); - return info; - } - case DXGI_FORMAT_B8G8R8A8_UNORM: - { - static const DXGISupport info(F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_2D | F_3D | F_CUBE | F_MS); - return info; - } - case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: - { - static const DXGISupport info(F_RT | F_SAMPLE, F_DS | F_MIPGEN, F_2D | F_3D | F_CUBE | F_MS); - return info; - } - case DXGI_FORMAT_B8G8R8X8_TYPELESS: - { - static const DXGISupport info(0, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, F_2D | F_3D | F_CUBE); - return info; - } - case DXGI_FORMAT_B8G8R8X8_UNORM: - { - static const DXGISupport info(F_RT | F_SAMPLE, F_DS | F_MIPGEN, F_2D | F_3D | F_CUBE | F_MS); - return info; - } - case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: - { - static const DXGISupport info(F_RT | F_SAMPLE, F_DS | F_MIPGEN, F_2D | F_3D | F_CUBE | F_MS); - return info; - } - case DXGI_FORMAT_BC1_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC1_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC1_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC2_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC2_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC2_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC3_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC3_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC3_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC4_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC4_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC4_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC5_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC5_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC5_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC6H_SF16: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC6H_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC6H_UF16: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC7_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_BC7_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_BC7_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_D16_UNORM: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_MIPGEN | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_D24_UNORM_S8_UINT: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_D32_FLOAT: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_MIPGEN | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: - { - static const DXGISupport info(F_2D | F_CUBE | F_DS, F_3D | F_MIPGEN | F_RT | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_G8R8_G8B8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_IA44: - { - static const DXGISupport info(F_2D, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_NV11: - { - static const DXGISupport info(F_2D | F_RT | F_SAMPLE, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_NV12: - { - static const DXGISupport info(F_2D | F_RT | F_SAMPLE, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_P010: - { - static const DXGISupport info(F_2D | F_RT | F_SAMPLE, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_P016: - { - static const DXGISupport info(F_2D | F_RT | F_SAMPLE, F_3D | F_CUBE | F_DS | F_MIPGEN, F_MS); - return info; - } - case DXGI_FORMAT_P8: - { - static const DXGISupport info(F_2D, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R10G10B10A2_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R10G10B10A2_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R10G10B10A2_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: - { - static const DXGISupport info(0, F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, F_2D | F_3D); - return info; - } - case DXGI_FORMAT_R11G11B10_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R16G16B16A16_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16B16A16_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R16G16_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16G16_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R16_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R16_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R16_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R1_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R24G8_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE | F_SAMPLE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_R32G32B32A32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R32G32B32A32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G32B32A32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32G32B32A32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G32B32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R32G32B32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_SAMPLE, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R32G32B32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32G32B32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_SAMPLE, F_MS | F_RT); - return info; - } - case DXGI_FORMAT_R32G32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R32G32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32G32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32G8X24_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32_FLOAT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: - { - static const DXGISupport info(F_2D | F_CUBE | F_SAMPLE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_R32_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R32_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R32_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R8G8B8A8_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_B8G8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_R8G8_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R8G8_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8G8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8_SINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8_SNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R8_TYPELESS: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE, F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_R8_UINT: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_RT, F_DS | F_MIPGEN | F_SAMPLE, F_MS); - return info; - } - case DXGI_FORMAT_R8_UNORM: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_MIPGEN | F_RT | F_SAMPLE, F_DS, F_MS); - return info; - } - case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: - { - static const DXGISupport info(F_2D | F_3D | F_CUBE | F_SAMPLE, F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_UNKNOWN: - { - static const DXGISupport info(0, F_2D | F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_X24_TYPELESS_G8_UINT: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: - { - static const DXGISupport info(F_2D | F_CUBE, F_3D | F_DS | F_MIPGEN | F_MS | F_RT | F_SAMPLE, 0); - return info; - } - case DXGI_FORMAT_Y210: - { - static const DXGISupport info(F_2D | F_SAMPLE, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_Y216: - { - static const DXGISupport info(F_2D | F_SAMPLE, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_Y410: - { - static const DXGISupport info(F_2D | F_SAMPLE, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_Y416: - { - static const DXGISupport info(F_2D | F_SAMPLE, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - case DXGI_FORMAT_YUY2: - { - static const DXGISupport info(F_2D | F_SAMPLE, F_3D | F_CUBE | F_DS | F_MIPGEN | F_MS | F_RT, 0); - return info; - } - - default: - UNREACHABLE(); - return GetDefaultSupport(); - } - // clang-format on -} - -} - -#undef F_2D -#undef F_3D -#undef F_CUBE -#undef F_SAMPLE -#undef F_RT -#undef F_MS -#undef F_DS -#undef F_MIPGEN - -const DXGISupport &GetDXGISupport(DXGI_FORMAT dxgiFormat, D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_9_3: - return GetDXGISupport_9_3(dxgiFormat); - case D3D_FEATURE_LEVEL_10_0: - return GetDXGISupport_10_0(dxgiFormat); - case D3D_FEATURE_LEVEL_10_1: - return GetDXGISupport_10_1(dxgiFormat); - case D3D_FEATURE_LEVEL_11_0: - return GetDXGISupport_11_0(dxgiFormat); - case D3D_FEATURE_LEVEL_11_1: - return GetDXGISupport_11_1(dxgiFormat); - default: - return GetDefaultSupport(); - } -} - -} // namespace d3d11 - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/dxgi_support_table.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/dxgi_support_table.h deleted file mode 100644 index a818f376ef..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/dxgi_support_table.h +++ /dev/null @@ -1,49 +0,0 @@ -// -// Copyright 2015 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// dxgi_support_table: -// Queries for DXGI support of various texture formats. Depends on DXGI -// version, D3D feature level, and is sometimes guaranteed or optional. -// - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_DXGI_SUPPORT_TABLE_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_DXGI_SUPPORT_TABLE_H_ - -#include "common/platform.h" - -namespace rx -{ - -namespace d3d11 -{ - -struct DXGISupport -{ - DXGISupport() - : alwaysSupportedFlags(0), - neverSupportedFlags(0), - optionallySupportedFlags(0) - { - } - - DXGISupport(UINT alwaysSupportedIn, UINT neverSupportedIn, UINT optionallySupportedIn) - : alwaysSupportedFlags(alwaysSupportedIn), - neverSupportedFlags(neverSupportedIn), - optionallySupportedFlags(optionallySupportedIn) - { - } - - UINT alwaysSupportedFlags; - UINT neverSupportedFlags; - UINT optionallySupportedFlags; -}; - -const DXGISupport &GetDXGISupport(DXGI_FORMAT dxgiFormat, D3D_FEATURE_LEVEL featureLevel); - -} // namespace d3d11 - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_DXGI_SUPPORT_TABLE_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/formatutils11.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/formatutils11.cpp deleted file mode 100644 index ce4edd26db..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/formatutils11.cpp +++ /dev/null @@ -1,1023 +0,0 @@ -// -// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// formatutils11.cpp: Queries for GL image formats and their translations to D3D11 -// formats. - -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" - -#include "image_util/copyimage.h" -#include "image_util/generatemip.h" -#include "image_util/loadimage.h" - -#include "libANGLE/formatutils.h" -#include "libANGLE/renderer/d3d/d3d11/copyvertex.h" -#include "libANGLE/renderer/d3d/d3d11/dxgi_support_table.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" - -namespace rx -{ - -namespace d3d11 -{ - -bool SupportsMipGen(DXGI_FORMAT dxgiFormat, D3D_FEATURE_LEVEL featureLevel) -{ - const auto &support = GetDXGISupport(dxgiFormat, featureLevel); - ASSERT((support.optionallySupportedFlags & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN) == 0); - return ((support.alwaysSupportedFlags & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN) != 0); -} - -DXGIFormatSize::DXGIFormatSize(GLuint pixelBits, GLuint blockWidth, GLuint blockHeight) - : pixelBytes(pixelBits / 8), blockWidth(blockWidth), blockHeight(blockHeight) -{ -} - -const DXGIFormatSize &GetDXGIFormatSizeInfo(DXGI_FORMAT format) -{ - static const DXGIFormatSize sizeUnknown(0, 0, 0); - static const DXGIFormatSize size128(128, 1, 1); - static const DXGIFormatSize size96(96, 1, 1); - static const DXGIFormatSize size64(64, 1, 1); - static const DXGIFormatSize size32(32, 1, 1); - static const DXGIFormatSize size16(16, 1, 1); - static const DXGIFormatSize size8(8, 1, 1); - static const DXGIFormatSize sizeBC1(64, 4, 4); - static const DXGIFormatSize sizeBC2(128, 4, 4); - static const DXGIFormatSize sizeBC3(128, 4, 4); - static const DXGIFormatSize sizeBC4(64, 4, 4); - static const DXGIFormatSize sizeBC5(128, 4, 4); - static const DXGIFormatSize sizeBC6H(128, 4, 4); - static const DXGIFormatSize sizeBC7(128, 4, 4); - switch (format) - { - case DXGI_FORMAT_UNKNOWN: - return sizeUnknown; - case DXGI_FORMAT_R32G32B32A32_TYPELESS: - case DXGI_FORMAT_R32G32B32A32_FLOAT: - case DXGI_FORMAT_R32G32B32A32_UINT: - case DXGI_FORMAT_R32G32B32A32_SINT: - return size128; - case DXGI_FORMAT_R32G32B32_TYPELESS: - case DXGI_FORMAT_R32G32B32_FLOAT: - case DXGI_FORMAT_R32G32B32_UINT: - case DXGI_FORMAT_R32G32B32_SINT: - return size96; - case DXGI_FORMAT_R16G16B16A16_TYPELESS: - case DXGI_FORMAT_R16G16B16A16_FLOAT: - case DXGI_FORMAT_R16G16B16A16_UNORM: - case DXGI_FORMAT_R16G16B16A16_UINT: - case DXGI_FORMAT_R16G16B16A16_SNORM: - case DXGI_FORMAT_R16G16B16A16_SINT: - case DXGI_FORMAT_R32G32_TYPELESS: - case DXGI_FORMAT_R32G32_FLOAT: - case DXGI_FORMAT_R32G32_UINT: - case DXGI_FORMAT_R32G32_SINT: - case DXGI_FORMAT_R32G8X24_TYPELESS: - case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: - case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: - case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: - return size64; - case DXGI_FORMAT_R10G10B10A2_TYPELESS: - case DXGI_FORMAT_R10G10B10A2_UNORM: - case DXGI_FORMAT_R10G10B10A2_UINT: - case DXGI_FORMAT_R11G11B10_FLOAT: - case DXGI_FORMAT_R8G8B8A8_TYPELESS: - case DXGI_FORMAT_R8G8B8A8_UNORM: - case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: - case DXGI_FORMAT_R8G8B8A8_UINT: - case DXGI_FORMAT_R8G8B8A8_SNORM: - case DXGI_FORMAT_R8G8B8A8_SINT: - case DXGI_FORMAT_R16G16_TYPELESS: - case DXGI_FORMAT_R16G16_FLOAT: - case DXGI_FORMAT_R16G16_UNORM: - case DXGI_FORMAT_R16G16_UINT: - case DXGI_FORMAT_R16G16_SNORM: - case DXGI_FORMAT_R16G16_SINT: - case DXGI_FORMAT_R32_TYPELESS: - case DXGI_FORMAT_D32_FLOAT: - case DXGI_FORMAT_R32_FLOAT: - case DXGI_FORMAT_R32_UINT: - case DXGI_FORMAT_R32_SINT: - case DXGI_FORMAT_R24G8_TYPELESS: - case DXGI_FORMAT_D24_UNORM_S8_UINT: - case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: - case DXGI_FORMAT_X24_TYPELESS_G8_UINT: - return size32; - case DXGI_FORMAT_R8G8_TYPELESS: - case DXGI_FORMAT_R8G8_UNORM: - case DXGI_FORMAT_R8G8_UINT: - case DXGI_FORMAT_R8G8_SNORM: - case DXGI_FORMAT_R8G8_SINT: - case DXGI_FORMAT_R16_TYPELESS: - case DXGI_FORMAT_R16_FLOAT: - case DXGI_FORMAT_D16_UNORM: - case DXGI_FORMAT_R16_UNORM: - case DXGI_FORMAT_R16_UINT: - case DXGI_FORMAT_R16_SNORM: - case DXGI_FORMAT_R16_SINT: - return size16; - case DXGI_FORMAT_R8_TYPELESS: - case DXGI_FORMAT_R8_UNORM: - case DXGI_FORMAT_R8_UINT: - case DXGI_FORMAT_R8_SNORM: - case DXGI_FORMAT_R8_SINT: - case DXGI_FORMAT_A8_UNORM: - return size8; - case DXGI_FORMAT_R1_UNORM: - UNREACHABLE(); - return sizeUnknown; - case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: - case DXGI_FORMAT_R8G8_B8G8_UNORM: - case DXGI_FORMAT_G8R8_G8B8_UNORM: - return size32; - case DXGI_FORMAT_BC1_TYPELESS: - case DXGI_FORMAT_BC1_UNORM: - case DXGI_FORMAT_BC1_UNORM_SRGB: - return sizeBC1; - case DXGI_FORMAT_BC2_TYPELESS: - case DXGI_FORMAT_BC2_UNORM: - case DXGI_FORMAT_BC2_UNORM_SRGB: - return sizeBC2; - case DXGI_FORMAT_BC3_TYPELESS: - case DXGI_FORMAT_BC3_UNORM: - case DXGI_FORMAT_BC3_UNORM_SRGB: - return sizeBC3; - case DXGI_FORMAT_BC4_TYPELESS: - case DXGI_FORMAT_BC4_UNORM: - case DXGI_FORMAT_BC4_SNORM: - return sizeBC4; - case DXGI_FORMAT_BC5_TYPELESS: - case DXGI_FORMAT_BC5_UNORM: - case DXGI_FORMAT_BC5_SNORM: - return sizeBC5; - case DXGI_FORMAT_B5G6R5_UNORM: - case DXGI_FORMAT_B5G5R5A1_UNORM: - return size16; - case DXGI_FORMAT_B8G8R8A8_UNORM: - case DXGI_FORMAT_B8G8R8X8_UNORM: - case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: - case DXGI_FORMAT_B8G8R8A8_TYPELESS: - case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: - case DXGI_FORMAT_B8G8R8X8_TYPELESS: - case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: - return size32; - case DXGI_FORMAT_BC6H_TYPELESS: - case DXGI_FORMAT_BC6H_UF16: - case DXGI_FORMAT_BC6H_SF16: - return sizeBC6H; - case DXGI_FORMAT_BC7_TYPELESS: - case DXGI_FORMAT_BC7_UNORM: - case DXGI_FORMAT_BC7_UNORM_SRGB: - return sizeBC7; - case DXGI_FORMAT_AYUV: - case DXGI_FORMAT_Y410: - case DXGI_FORMAT_Y416: - case DXGI_FORMAT_NV12: - case DXGI_FORMAT_P010: - case DXGI_FORMAT_P016: - case DXGI_FORMAT_420_OPAQUE: - case DXGI_FORMAT_YUY2: - case DXGI_FORMAT_Y210: - case DXGI_FORMAT_Y216: - case DXGI_FORMAT_NV11: - case DXGI_FORMAT_AI44: - case DXGI_FORMAT_IA44: - case DXGI_FORMAT_P8: - case DXGI_FORMAT_A8P8: - UNREACHABLE(); - return sizeUnknown; - case DXGI_FORMAT_B4G4R4A4_UNORM: - return size16; - default: - UNREACHABLE(); - return sizeUnknown; - } -} - -constexpr VertexFormat::VertexFormat() - : conversionType(VERTEX_CONVERT_NONE), nativeFormat(DXGI_FORMAT_UNKNOWN), copyFunction(nullptr) -{ -} - -constexpr VertexFormat::VertexFormat(VertexConversionType conversionTypeIn, - DXGI_FORMAT nativeFormatIn, - VertexCopyFunction copyFunctionIn) - : conversionType(conversionTypeIn), nativeFormat(nativeFormatIn), copyFunction(copyFunctionIn) -{ -} - -const VertexFormat *GetVertexFormatInfo_FL_9_3(gl::VertexFormatType vertexFormatType) -{ - // D3D11 Feature Level 9_3 doesn't support as many formats for vertex buffer resource as Feature - // Level 10_0+. - // http://msdn.microsoft.com/en-us/library/windows/desktop/ff471324(v=vs.85).aspx - - switch (vertexFormatType) - { - // GL_BYTE -- unnormalized - case gl::VERTEX_FORMAT_SBYTE1: - { - static constexpr VertexFormat info(VERTEX_CONVERT_BOTH, DXGI_FORMAT_R16G16_SINT, - &Copy8SintTo16SintVertexData<1, 2>); - return &info; - } - case gl::VERTEX_FORMAT_SBYTE2: - { - static constexpr VertexFormat info(VERTEX_CONVERT_BOTH, DXGI_FORMAT_R16G16_SINT, - &Copy8SintTo16SintVertexData<2, 2>); - return &info; - } - case gl::VERTEX_FORMAT_SBYTE3: - { - static constexpr VertexFormat info(VERTEX_CONVERT_BOTH, DXGI_FORMAT_R16G16B16A16_SINT, - &Copy8SintTo16SintVertexData<3, 4>); - return &info; - } - case gl::VERTEX_FORMAT_SBYTE4: - { - static constexpr VertexFormat info(VERTEX_CONVERT_BOTH, DXGI_FORMAT_R16G16B16A16_SINT, - &Copy8SintTo16SintVertexData<4, 4>); - return &info; - } - - // GL_BYTE -- normalized - case gl::VERTEX_FORMAT_SBYTE1_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16_SNORM, - &Copy8SnormTo16SnormVertexData<1, 2>); - return &info; - } - case gl::VERTEX_FORMAT_SBYTE2_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16_SNORM, - &Copy8SnormTo16SnormVertexData<2, 2>); - return &info; - } - case gl::VERTEX_FORMAT_SBYTE3_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_SNORM, - &Copy8SnormTo16SnormVertexData<3, 4>); - return &info; - } - case gl::VERTEX_FORMAT_SBYTE4_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_SNORM, - &Copy8SnormTo16SnormVertexData<4, 4>); - return &info; - } - - // GL_UNSIGNED_BYTE -- un-normalized - // NOTE: 3 and 4 component unnormalized GL_UNSIGNED_BYTE should use the default format - // table. - case gl::VERTEX_FORMAT_UBYTE1: - { - static constexpr VertexFormat info(VERTEX_CONVERT_BOTH, DXGI_FORMAT_R8G8B8A8_UINT, - &CopyNativeVertexData<GLubyte, 1, 4, 1>); - return &info; - } - case gl::VERTEX_FORMAT_UBYTE2: - { - static constexpr VertexFormat info(VERTEX_CONVERT_BOTH, DXGI_FORMAT_R8G8B8A8_UINT, - &CopyNativeVertexData<GLubyte, 2, 4, 1>); - return &info; - } - - // GL_UNSIGNED_BYTE -- normalized - // NOTE: 3 and 4 component normalized GL_UNSIGNED_BYTE should use the default format table. - - // GL_UNSIGNED_BYTE -- normalized - case gl::VERTEX_FORMAT_UBYTE1_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_UNORM, - &CopyNativeVertexData<GLubyte, 1, 4, UINT8_MAX>); - return &info; - } - case gl::VERTEX_FORMAT_UBYTE2_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_UNORM, - &CopyNativeVertexData<GLubyte, 2, 4, UINT8_MAX>); - return &info; - } - - // GL_SHORT -- un-normalized - // NOTE: 2, 3 and 4 component unnormalized GL_SHORT should use the default format table. - case gl::VERTEX_FORMAT_SSHORT1: - { - static constexpr VertexFormat info(VERTEX_CONVERT_BOTH, DXGI_FORMAT_R16G16_SINT, - &CopyNativeVertexData<GLshort, 1, 2, 0>); - return &info; - } - - // GL_SHORT -- normalized - // NOTE: 2, 3 and 4 component normalized GL_SHORT should use the default format table. - case gl::VERTEX_FORMAT_SSHORT1_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16_SNORM, - &CopyNativeVertexData<GLshort, 1, 2, 0>); - return &info; - } - - // GL_UNSIGNED_SHORT -- un-normalized - case gl::VERTEX_FORMAT_USHORT1: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32_FLOAT, - &CopyTo32FVertexData<GLushort, 1, 2, false>); - return &info; - } - case gl::VERTEX_FORMAT_USHORT2: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32_FLOAT, - &CopyTo32FVertexData<GLushort, 2, 2, false>); - return &info; - } - case gl::VERTEX_FORMAT_USHORT3: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32_FLOAT, - &CopyTo32FVertexData<GLushort, 3, 3, false>); - return &info; - } - case gl::VERTEX_FORMAT_USHORT4: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, - &CopyTo32FVertexData<GLushort, 4, 4, false>); - return &info; - } - - // GL_UNSIGNED_SHORT -- normalized - case gl::VERTEX_FORMAT_USHORT1_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32_FLOAT, - &CopyTo32FVertexData<GLushort, 1, 2, true>); - return &info; - } - case gl::VERTEX_FORMAT_USHORT2_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32_FLOAT, - &CopyTo32FVertexData<GLushort, 2, 2, true>); - return &info; - } - case gl::VERTEX_FORMAT_USHORT3_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32_FLOAT, - &CopyTo32FVertexData<GLushort, 3, 3, true>); - return &info; - } - case gl::VERTEX_FORMAT_USHORT4_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, - &CopyTo32FVertexData<GLushort, 4, 4, true>); - return &info; - } - - // GL_FIXED - // TODO: Add test to verify that this works correctly. - // NOTE: 2, 3 and 4 component GL_FIXED should use the default format table. - case gl::VERTEX_FORMAT_FIXED1: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32_FLOAT, - &Copy32FixedTo32FVertexData<1, 2>); - return &info; - } - - // GL_FLOAT - // TODO: Add test to verify that this works correctly. - // NOTE: 2, 3 and 4 component GL_FLOAT should use the default format table. - case gl::VERTEX_FORMAT_FLOAT1: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32_FLOAT, - &CopyNativeVertexData<GLfloat, 1, 2, 0>); - return &info; - } - - default: - return nullptr; - } -} - -const VertexFormat &GetVertexFormatInfo(gl::VertexFormatType vertexFormatType, D3D_FEATURE_LEVEL featureLevel) -{ - if (featureLevel == D3D_FEATURE_LEVEL_9_3) - { - const VertexFormat *result = GetVertexFormatInfo_FL_9_3(vertexFormatType); - if (result) - { - return *result; - } - } - - switch (vertexFormatType) - { - // - // Float formats - // - - // GL_BYTE -- un-normalized - case gl::VERTEX_FORMAT_SBYTE1: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R8_SINT, - &CopyNativeVertexData<GLbyte, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_SBYTE2: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R8G8_SINT, - &CopyNativeVertexData<GLbyte, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_SBYTE3: - { - static constexpr VertexFormat info(VERTEX_CONVERT_BOTH, DXGI_FORMAT_R8G8B8A8_SINT, - &CopyNativeVertexData<GLbyte, 3, 4, 1>); - return info; - } - case gl::VERTEX_FORMAT_SBYTE4: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R8G8B8A8_SINT, - &CopyNativeVertexData<GLbyte, 4, 4, 0>); - return info; - } - - // GL_BYTE -- normalized - case gl::VERTEX_FORMAT_SBYTE1_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_SNORM, - &CopyNativeVertexData<GLbyte, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_SBYTE2_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_SNORM, - &CopyNativeVertexData<GLbyte, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_SBYTE3_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_SNORM, - &CopyNativeVertexData<GLbyte, 3, 4, INT8_MAX>); - return info; - } - case gl::VERTEX_FORMAT_SBYTE4_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8B8A8_SNORM, - &CopyNativeVertexData<GLbyte, 4, 4, 0>); - return info; - } - - // GL_UNSIGNED_BYTE -- un-normalized - case gl::VERTEX_FORMAT_UBYTE1: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R8_UINT, - &CopyNativeVertexData<GLubyte, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_UBYTE2: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R8G8_UINT, - &CopyNativeVertexData<GLubyte, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_UBYTE3: - { - static constexpr VertexFormat info(VERTEX_CONVERT_BOTH, DXGI_FORMAT_R8G8B8A8_UINT, - &CopyNativeVertexData<GLubyte, 3, 4, 1>); - return info; - } - case gl::VERTEX_FORMAT_UBYTE4: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R8G8B8A8_UINT, - &CopyNativeVertexData<GLubyte, 4, 4, 0>); - return info; - } - - // GL_UNSIGNED_BYTE -- normalized - case gl::VERTEX_FORMAT_UBYTE1_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_UNORM, - &CopyNativeVertexData<GLubyte, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_UBYTE2_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_UNORM, - &CopyNativeVertexData<GLubyte, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_UBYTE3_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_UNORM, - &CopyNativeVertexData<GLubyte, 3, 4, UINT8_MAX>); - return info; - } - case gl::VERTEX_FORMAT_UBYTE4_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8B8A8_UNORM, - &CopyNativeVertexData<GLubyte, 4, 4, 0>); - return info; - } - - // GL_SHORT -- un-normalized - case gl::VERTEX_FORMAT_SSHORT1: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R16_SINT, - &CopyNativeVertexData<GLshort, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_SSHORT2: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R16G16_SINT, - &CopyNativeVertexData<GLshort, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_SSHORT3: - { - static constexpr VertexFormat info(VERTEX_CONVERT_BOTH, DXGI_FORMAT_R16G16B16A16_SINT, - &CopyNativeVertexData<GLshort, 3, 4, 1>); - return info; - } - case gl::VERTEX_FORMAT_SSHORT4: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R16G16B16A16_SINT, - &CopyNativeVertexData<GLshort, 4, 4, 0>); - return info; - } - - // GL_SHORT -- normalized - case gl::VERTEX_FORMAT_SSHORT1_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_SNORM, - &CopyNativeVertexData<GLshort, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_SSHORT2_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_SNORM, - &CopyNativeVertexData<GLshort, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_SSHORT3_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_SNORM, - &CopyNativeVertexData<GLshort, 3, 4, INT16_MAX>); - return info; - } - case gl::VERTEX_FORMAT_SSHORT4_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16B16A16_SNORM, - &CopyNativeVertexData<GLshort, 4, 4, 0>); - return info; - } - - // GL_UNSIGNED_SHORT -- un-normalized - case gl::VERTEX_FORMAT_USHORT1: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R16_UINT, - &CopyNativeVertexData<GLushort, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_USHORT2: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R16G16_UINT, - &CopyNativeVertexData<GLushort, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_USHORT3: - { - static constexpr VertexFormat info(VERTEX_CONVERT_BOTH, DXGI_FORMAT_R16G16B16A16_UINT, - &CopyNativeVertexData<GLushort, 3, 4, 1>); - return info; - } - case gl::VERTEX_FORMAT_USHORT4: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R16G16B16A16_UINT, - &CopyNativeVertexData<GLushort, 4, 4, 0>); - return info; - } - - // GL_UNSIGNED_SHORT -- normalized - case gl::VERTEX_FORMAT_USHORT1_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_UNORM, - &CopyNativeVertexData<GLushort, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_USHORT2_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_UNORM, - &CopyNativeVertexData<GLushort, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_USHORT3_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_UNORM, - &CopyNativeVertexData<GLushort, 3, 4, UINT16_MAX>); - return info; - } - case gl::VERTEX_FORMAT_USHORT4_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16B16A16_UNORM, - &CopyNativeVertexData<GLushort, 4, 4, 0>); - return info; - } - - // GL_INT -- un-normalized - case gl::VERTEX_FORMAT_SINT1: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R32_SINT, - &CopyNativeVertexData<GLint, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_SINT2: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32_SINT, - &CopyNativeVertexData<GLint, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_SINT3: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32B32_SINT, - &CopyNativeVertexData<GLint, 3, 3, 0>); - return info; - } - case gl::VERTEX_FORMAT_SINT4: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32B32A32_SINT, - &CopyNativeVertexData<GLint, 4, 4, 0>); - return info; - } - - // GL_INT -- normalized - case gl::VERTEX_FORMAT_SINT1_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32_FLOAT, - &CopyTo32FVertexData<GLint, 1, 1, true>); - return info; - } - case gl::VERTEX_FORMAT_SINT2_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32_FLOAT, - &CopyTo32FVertexData<GLint, 2, 2, true>); - return info; - } - case gl::VERTEX_FORMAT_SINT3_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32_FLOAT, - &CopyTo32FVertexData<GLint, 3, 3, true>); - return info; - } - case gl::VERTEX_FORMAT_SINT4_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, - &CopyTo32FVertexData<GLint, 4, 4, true>); - return info; - } - - // GL_UNSIGNED_INT -- un-normalized - case gl::VERTEX_FORMAT_UINT1: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R32_UINT, - &CopyNativeVertexData<GLuint, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_UINT2: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32_UINT, - &CopyNativeVertexData<GLuint, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_UINT3: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32B32_UINT, - &CopyNativeVertexData<GLuint, 3, 3, 0>); - return info; - } - case gl::VERTEX_FORMAT_UINT4: - { - static constexpr VertexFormat info(VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32B32A32_UINT, - &CopyNativeVertexData<GLuint, 4, 4, 0>); - return info; - } - - // GL_UNSIGNED_INT -- normalized - case gl::VERTEX_FORMAT_UINT1_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32_FLOAT, - &CopyTo32FVertexData<GLuint, 1, 1, true>); - return info; - } - case gl::VERTEX_FORMAT_UINT2_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32_FLOAT, - &CopyTo32FVertexData<GLuint, 2, 2, true>); - return info; - } - case gl::VERTEX_FORMAT_UINT3_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32_FLOAT, - &CopyTo32FVertexData<GLuint, 3, 3, true>); - return info; - } - case gl::VERTEX_FORMAT_UINT4_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, - &CopyTo32FVertexData<GLuint, 4, 4, true>); - return info; - } - - // GL_FIXED - case gl::VERTEX_FORMAT_FIXED1: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32_FLOAT, - &Copy32FixedTo32FVertexData<1, 1>); - return info; - } - case gl::VERTEX_FORMAT_FIXED2: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32_FLOAT, - &Copy32FixedTo32FVertexData<2, 2>); - return info; - } - case gl::VERTEX_FORMAT_FIXED3: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32_FLOAT, - &Copy32FixedTo32FVertexData<3, 3>); - return info; - } - case gl::VERTEX_FORMAT_FIXED4: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, - &Copy32FixedTo32FVertexData<4, 4>); - return info; - } - - // GL_HALF_FLOAT - case gl::VERTEX_FORMAT_HALF1: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_FLOAT, - &CopyNativeVertexData<GLhalf, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_HALF2: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_FLOAT, - &CopyNativeVertexData<GLhalf, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_HALF3: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_FLOAT, - &CopyNativeVertexData<GLhalf, 3, 4, gl::Float16One>); - return info; - } - case gl::VERTEX_FORMAT_HALF4: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16B16A16_FLOAT, - &CopyNativeVertexData<GLhalf, 4, 4, 0>); - return info; - } - - // GL_FLOAT - case gl::VERTEX_FORMAT_FLOAT1: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R32_FLOAT, - &CopyNativeVertexData<GLfloat, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_FLOAT2: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32_FLOAT, - &CopyNativeVertexData<GLfloat, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_FLOAT3: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32_FLOAT, - &CopyNativeVertexData<GLfloat, 3, 3, 0>); - return info; - } - case gl::VERTEX_FORMAT_FLOAT4: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32A32_FLOAT, - &CopyNativeVertexData<GLfloat, 4, 4, 0>); - return info; - } - - // GL_INT_2_10_10_10_REV - case gl::VERTEX_FORMAT_SINT210: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, - &CopyXYZ10W2ToXYZW32FVertexData<true, false, true>); - return info; - } - case gl::VERTEX_FORMAT_SINT210_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, - &CopyXYZ10W2ToXYZW32FVertexData<true, true, true>); - return info; - } - - // GL_UNSIGNED_INT_2_10_10_10_REV - case gl::VERTEX_FORMAT_UINT210: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, - &CopyXYZ10W2ToXYZW32FVertexData<false, false, true>); - return info; - } - case gl::VERTEX_FORMAT_UINT210_NORM: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R10G10B10A2_UNORM, - &CopyNativeVertexData<GLuint, 1, 1, 0>); - return info; - } - - // - // Integer Formats - // - - // GL_BYTE - case gl::VERTEX_FORMAT_SBYTE1_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_SINT, - &CopyNativeVertexData<GLbyte, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_SBYTE2_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_SINT, - &CopyNativeVertexData<GLbyte, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_SBYTE3_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_SINT, - &CopyNativeVertexData<GLbyte, 3, 4, 1>); - return info; - } - case gl::VERTEX_FORMAT_SBYTE4_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8B8A8_SINT, - &CopyNativeVertexData<GLbyte, 4, 4, 0>); - return info; - } - - // GL_UNSIGNED_BYTE - case gl::VERTEX_FORMAT_UBYTE1_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_UINT, - &CopyNativeVertexData<GLubyte, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_UBYTE2_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_UINT, - &CopyNativeVertexData<GLubyte, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_UBYTE3_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_UINT, - &CopyNativeVertexData<GLubyte, 3, 4, 1>); - return info; - } - case gl::VERTEX_FORMAT_UBYTE4_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8B8A8_UINT, - &CopyNativeVertexData<GLubyte, 4, 4, 0>); - return info; - } - - // GL_SHORT - case gl::VERTEX_FORMAT_SSHORT1_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_SINT, - &CopyNativeVertexData<GLshort, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_SSHORT2_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_SINT, - &CopyNativeVertexData<GLshort, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_SSHORT3_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_SINT, - &CopyNativeVertexData<GLshort, 3, 4, 1>); - return info; - } - case gl::VERTEX_FORMAT_SSHORT4_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16B16A16_SINT, - &CopyNativeVertexData<GLshort, 4, 4, 0>); - return info; - } - - // GL_UNSIGNED_SHORT - case gl::VERTEX_FORMAT_USHORT1_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_UINT, - &CopyNativeVertexData<GLushort, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_USHORT2_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_UINT, - &CopyNativeVertexData<GLushort, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_USHORT3_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_UINT, - &CopyNativeVertexData<GLushort, 3, 4, 1>); - return info; - } - case gl::VERTEX_FORMAT_USHORT4_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16B16A16_UINT, - &CopyNativeVertexData<GLushort, 4, 4, 0>); - return info; - } - - // GL_INT - case gl::VERTEX_FORMAT_SINT1_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R32_SINT, - &CopyNativeVertexData<GLint, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_SINT2_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32_SINT, - &CopyNativeVertexData<GLint, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_SINT3_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32_SINT, - &CopyNativeVertexData<GLint, 3, 3, 0>); - return info; - } - case gl::VERTEX_FORMAT_SINT4_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32A32_SINT, - &CopyNativeVertexData<GLint, 4, 4, 0>); - return info; - } - - // GL_UNSIGNED_INT - case gl::VERTEX_FORMAT_UINT1_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R32_SINT, - &CopyNativeVertexData<GLuint, 1, 1, 0>); - return info; - } - case gl::VERTEX_FORMAT_UINT2_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32_SINT, - &CopyNativeVertexData<GLuint, 2, 2, 0>); - return info; - } - case gl::VERTEX_FORMAT_UINT3_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32_SINT, - &CopyNativeVertexData<GLuint, 3, 3, 0>); - return info; - } - case gl::VERTEX_FORMAT_UINT4_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32A32_SINT, - &CopyNativeVertexData<GLuint, 4, 4, 0>); - return info; - } - - // GL_INT_2_10_10_10_REV - case gl::VERTEX_FORMAT_SINT210_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_SINT, - &CopyXYZ10W2ToXYZW32FVertexData<true, true, false>); - return info; - } - - // GL_UNSIGNED_INT_2_10_10_10_REV - case gl::VERTEX_FORMAT_UINT210_INT: - { - static constexpr VertexFormat info(VERTEX_CONVERT_NONE, DXGI_FORMAT_R10G10B10A2_UINT, - &CopyNativeVertexData<GLuint, 1, 1, 0>); - return info; - } - - default: - { - static constexpr VertexFormat info; - return info; - } - } -} - -} // namespace d3d11 - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/formatutils11.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/formatutils11.h deleted file mode 100644 index 883d338377..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/formatutils11.h +++ /dev/null @@ -1,71 +0,0 @@ -// -// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// formatutils11.h: Queries for GL image formats and their translations to D3D11 -// formats. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_FORMATUTILS11_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_FORMATUTILS11_H_ - -#include <map> - -#include "common/platform.h" -#include "libANGLE/angletypes.h" -#include "libANGLE/formatutils.h" -#include "libANGLE/renderer/renderer_utils.h" -#include "libANGLE/renderer/d3d/formatutilsD3D.h" - -namespace rx -{ -struct Renderer11DeviceCaps; - -namespace d3d11 -{ - -// A texture might be stored as DXGI_FORMAT_R16_TYPELESS but store integer components, -// which are accessed through an DXGI_FORMAT_R16_SINT view. It's easy to write code which queries -// information about the wrong format. Therefore, use of this should be avoided where possible. - -bool SupportsMipGen(DXGI_FORMAT dxgiFormat, D3D_FEATURE_LEVEL featureLevel); - -struct DXGIFormatSize -{ - DXGIFormatSize(GLuint pixelBits, GLuint blockWidth, GLuint blockHeight); - - GLuint pixelBytes; - GLuint blockWidth; - GLuint blockHeight; -}; -const DXGIFormatSize &GetDXGIFormatSizeInfo(DXGI_FORMAT format); - -struct VertexFormat : private angle::NonCopyable -{ - constexpr VertexFormat(); - constexpr VertexFormat(VertexConversionType conversionType, - DXGI_FORMAT nativeFormat, - VertexCopyFunction copyFunction); - - VertexConversionType conversionType; - DXGI_FORMAT nativeFormat; - VertexCopyFunction copyFunction; -}; - -const VertexFormat &GetVertexFormatInfo(gl::VertexFormatType vertexFormatType, - D3D_FEATURE_LEVEL featureLevel); - -// Auto-generated in dxgi_format_map_autogen.cpp. -GLenum GetComponentType(DXGI_FORMAT dxgiFormat); - -} // namespace d3d11 - -namespace d3d11_angle -{ -const angle::Format &GetFormat(DXGI_FORMAT dxgiFormat); -} - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_FORMATUTILS11_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/renderer11_utils.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/renderer11_utils.cpp deleted file mode 100644 index d059b36120..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/renderer11_utils.cpp +++ /dev/null @@ -1,2421 +0,0 @@ -// -// Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// renderer11_utils.cpp: Conversion functions and other utility routines -// specific to the D3D11 renderer. - -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -#include <algorithm> - -#include "common/debug.h" -#include "libANGLE/Buffer.h" -#include "libANGLE/Context.h" -#include "libANGLE/Framebuffer.h" -#include "libANGLE/Program.h" -#include "libANGLE/State.h" -#include "libANGLE/VertexArray.h" -#include "libANGLE/formatutils.h" -#include "libANGLE/renderer/d3d/BufferD3D.h" -#include "libANGLE/renderer/d3d/FramebufferD3D.h" -#include "libANGLE/renderer/d3d/IndexBuffer.h" -#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h" -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" -#include "libANGLE/renderer/d3d/d3d11/dxgi_support_table.h" -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" -#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h" -#include "libANGLE/renderer/driver_utils.h" -#include "platform/Platform.h" -#include "platform/WorkaroundsD3D.h" - -namespace rx -{ - -namespace d3d11_gl -{ -namespace -{ -// Standard D3D sample positions from -// https://msdn.microsoft.com/en-us/library/windows/desktop/ff476218.aspx -using SamplePositionsArray = std::array<float, 32>; -static constexpr std::array<SamplePositionsArray, 5> kSamplePositions = { - {{{0.5f, 0.5f}}, - {{0.75f, 0.75f, 0.25f, 0.25f}}, - {{0.375f, 0.125f, 0.875f, 0.375f, 0.125f, 0.625f, 0.625f, 0.875f}}, - {{0.5625f, 0.3125f, 0.4375f, 0.6875f, 0.8125f, 0.5625f, 0.3125f, 0.1875f, 0.1875f, 0.8125f, - 0.0625f, 0.4375f, 0.6875f, 0.9375f, 0.9375f, 0.0625f}}, - {{0.5625f, 0.5625f, 0.4375f, 0.3125f, 0.3125f, 0.625f, 0.75f, 0.4375f, - 0.1875f, 0.375f, 0.625f, 0.8125f, 0.8125f, 0.6875f, 0.6875f, 0.1875f, - 0.375f, 0.875f, 0.5f, 0.0625f, 0.25f, 0.125f, 0.125f, 0.75f, - 0.0f, 0.5f, 0.9375f, 0.25f, 0.875f, 0.9375f, 0.0625f, 0.0f}}}}; - -// Helper functor for querying DXGI support. Saves passing the parameters repeatedly. -class DXGISupportHelper : angle::NonCopyable -{ - public: - DXGISupportHelper(ID3D11Device *device, D3D_FEATURE_LEVEL featureLevel) - : mDevice(device), mFeatureLevel(featureLevel) - { - } - - bool query(DXGI_FORMAT dxgiFormat, UINT supportMask) - { - if (dxgiFormat == DXGI_FORMAT_UNKNOWN) - return false; - - auto dxgiSupport = d3d11::GetDXGISupport(dxgiFormat, mFeatureLevel); - - UINT supportedBits = dxgiSupport.alwaysSupportedFlags; - - if ((dxgiSupport.optionallySupportedFlags & supportMask) != 0) - { - UINT formatSupport; - if (SUCCEEDED(mDevice->CheckFormatSupport(dxgiFormat, &formatSupport))) - { - supportedBits |= (formatSupport & supportMask); - } - else - { - // TODO(jmadill): find out why we fail this call sometimes in FL9_3 - // ERR() << "Error checking format support for format 0x" << std::hex << dxgiFormat; - } - } - - return ((supportedBits & supportMask) == supportMask); - } - - private: - ID3D11Device *mDevice; - D3D_FEATURE_LEVEL mFeatureLevel; -}; - -gl::TextureCaps GenerateTextureFormatCaps(gl::Version maxClientVersion, - GLenum internalFormat, - ID3D11Device *device, - const Renderer11DeviceCaps &renderer11DeviceCaps) -{ - gl::TextureCaps textureCaps; - - DXGISupportHelper support(device, renderer11DeviceCaps.featureLevel); - const d3d11::Format &formatInfo = d3d11::Format::Get(internalFormat, renderer11DeviceCaps); - - const gl::InternalFormat &internalFormatInfo = gl::GetSizedInternalFormatInfo(internalFormat); - - UINT texSupportMask = D3D11_FORMAT_SUPPORT_TEXTURE2D; - if (internalFormatInfo.depthBits == 0 && internalFormatInfo.stencilBits == 0) - { - texSupportMask |= D3D11_FORMAT_SUPPORT_TEXTURECUBE; - if (maxClientVersion.major > 2) - { - texSupportMask |= D3D11_FORMAT_SUPPORT_TEXTURE3D; - } - } - - textureCaps.texturable = support.query(formatInfo.texFormat, texSupportMask); - textureCaps.filterable = - support.query(formatInfo.srvFormat, D3D11_FORMAT_SUPPORT_SHADER_SAMPLE); - textureCaps.renderable = - (support.query(formatInfo.rtvFormat, D3D11_FORMAT_SUPPORT_RENDER_TARGET)) || - (support.query(formatInfo.dsvFormat, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)); - - DXGI_FORMAT renderFormat = DXGI_FORMAT_UNKNOWN; - if (formatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN) - { - renderFormat = formatInfo.dsvFormat; - } - else if (formatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN) - { - renderFormat = formatInfo.rtvFormat; - } - if (renderFormat != DXGI_FORMAT_UNKNOWN && - support.query(renderFormat, D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET)) - { - // Assume 1x - textureCaps.sampleCounts.insert(1); - - for (unsigned int sampleCount = 2; sampleCount <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; - sampleCount *= 2) - { - UINT qualityCount = 0; - if (SUCCEEDED(device->CheckMultisampleQualityLevels(renderFormat, sampleCount, - &qualityCount))) - { - // Assume we always support lower sample counts - if (qualityCount == 0) - { - break; - } - textureCaps.sampleCounts.insert(sampleCount); - } - } - } - - return textureCaps; -} - -bool GetNPOTTextureSupport(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return true; - - // From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476876.aspx - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return false; - - default: - UNREACHABLE(); - return false; - } -} - -float GetMaximumAnisotropy(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_MAX_MAXANISOTROPY; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_MAX_MAXANISOTROPY; - - // From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476876.aspx - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - return 16; - - case D3D_FEATURE_LEVEL_9_1: - return D3D_FL9_1_DEFAULT_MAX_ANISOTROPY; - - default: - UNREACHABLE(); - return 0; - } -} - -bool GetOcclusionQuerySupport(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return true; - - // From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476150.aspx - // ID3D11Device::CreateQuery - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - return true; - case D3D_FEATURE_LEVEL_9_1: - return false; - - default: - UNREACHABLE(); - return false; - } -} - -bool GetEventQuerySupport(D3D_FEATURE_LEVEL featureLevel) -{ - // From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476150.aspx - // ID3D11Device::CreateQuery - - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return true; - - default: - UNREACHABLE(); - return false; - } -} - -bool GetInstancingSupport(D3D_FEATURE_LEVEL featureLevel) -{ - // From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476150.aspx - // ID3D11Device::CreateInputLayout - - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return true; - - // Feature Level 9_3 supports instancing, but slot 0 in the input layout must not be - // instanced. - // D3D9 has a similar restriction, where stream 0 must not be instanced. - // This restriction can be worked around by remapping any non-instanced slot to slot - // 0. - // This works because HLSL uses shader semantics to match the vertex inputs to the - // elements in the input layout, rather than the slots. - // Note that we only support instancing via ANGLE_instanced_array on 9_3, since 9_3 - // doesn't support OpenGL ES 3.0 - case D3D_FEATURE_LEVEL_9_3: - return true; - - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return false; - - default: - UNREACHABLE(); - return false; - } -} - -bool GetFramebufferMultisampleSupport(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return true; - - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return false; - - default: - UNREACHABLE(); - return false; - } -} - -bool GetFramebufferBlitSupport(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return true; - - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return false; - - default: - UNREACHABLE(); - return false; - } -} - -bool GetDerivativeInstructionSupport(D3D_FEATURE_LEVEL featureLevel) -{ - // http://msdn.microsoft.com/en-us/library/windows/desktop/bb509588.aspx states that - // shader model - // ps_2_x is required for the ddx (and other derivative functions). - - // http://msdn.microsoft.com/en-us/library/windows/desktop/ff476876.aspx states that - // feature level - // 9.3 supports shader model ps_2_x. - - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - case D3D_FEATURE_LEVEL_9_3: - return true; - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return false; - - default: - UNREACHABLE(); - return false; - } -} - -bool GetShaderTextureLODSupport(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return true; - - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return false; - - default: - UNREACHABLE(); - return false; - } -} - -size_t GetMaximumSimultaneousRenderTargets(D3D_FEATURE_LEVEL featureLevel) -{ - // From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476150.aspx - // ID3D11Device::CreateInputLayout - - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; - - case D3D_FEATURE_LEVEL_9_3: - return D3D_FL9_3_SIMULTANEOUS_RENDER_TARGET_COUNT; - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return D3D_FL9_1_SIMULTANEOUS_RENDER_TARGET_COUNT; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximum2DTextureSize(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; - - case D3D_FEATURE_LEVEL_9_3: - return D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION; - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumCubeMapTextureSize(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_REQ_TEXTURECUBE_DIMENSION; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_REQ_TEXTURECUBE_DIMENSION; - - case D3D_FEATURE_LEVEL_9_3: - return D3D_FL9_3_REQ_TEXTURECUBE_DIMENSION; - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return D3D_FL9_1_REQ_TEXTURECUBE_DIMENSION; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximum2DTextureArraySize(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION; - - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 0; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximum3DTextureSize(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_REQ_TEXTURE3D_U_V_OR_W_DIMENSION; - - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return D3D_FL9_1_REQ_TEXTURE3D_U_V_OR_W_DIMENSION; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumViewportSize(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_VIEWPORT_BOUNDS_MAX; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_VIEWPORT_BOUNDS_MAX; - - // No constants for D3D11 Feature Level 9 viewport size limits, use the maximum - // texture sizes - case D3D_FEATURE_LEVEL_9_3: - return D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION; - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumDrawIndexedIndexCount(D3D_FEATURE_LEVEL featureLevel) -{ - // D3D11 allows up to 2^32 elements, but we report max signed int for convenience since - // that's what's - // returned from glGetInteger - static_assert(D3D11_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP == 32, - "Unexpected D3D11 constant value."); - static_assert(D3D10_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP == 32, - "Unexpected D3D11 constant value."); - - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return std::numeric_limits<GLint>::max(); - - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - return D3D_FL9_2_IA_PRIMITIVE_MAX_COUNT; - case D3D_FEATURE_LEVEL_9_1: - return D3D_FL9_1_IA_PRIMITIVE_MAX_COUNT; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumDrawVertexCount(D3D_FEATURE_LEVEL featureLevel) -{ - // D3D11 allows up to 2^32 elements, but we report max signed int for convenience since - // that's what's - // returned from glGetInteger - static_assert(D3D11_REQ_DRAW_VERTEX_COUNT_2_TO_EXP == 32, "Unexpected D3D11 constant value."); - static_assert(D3D10_REQ_DRAW_VERTEX_COUNT_2_TO_EXP == 32, "Unexpected D3D11 constant value."); - - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return std::numeric_limits<GLint>::max(); - - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - return D3D_FL9_2_IA_PRIMITIVE_MAX_COUNT; - case D3D_FEATURE_LEVEL_9_1: - return D3D_FL9_1_IA_PRIMITIVE_MAX_COUNT; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumVertexInputSlots(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_STANDARD_VERTEX_ELEMENT_COUNT; - - case D3D_FEATURE_LEVEL_10_1: - return D3D10_1_STANDARD_VERTEX_ELEMENT_COUNT; - case D3D_FEATURE_LEVEL_10_0: - return D3D10_STANDARD_VERTEX_ELEMENT_COUNT; - - // From http://http://msdn.microsoft.com/en-us/library/windows/desktop/ff476876.aspx - // "Max Input Slots" - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 16; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumVertexUniformVectors(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT; - - // From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476149.aspx - // ID3D11DeviceContext::VSSetConstantBuffers - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 255 - d3d11_gl::GetReservedVertexUniformVectors(featureLevel); - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumVertexUniformBlocks(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - - d3d11::RESERVED_CONSTANT_BUFFER_SLOT_COUNT; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - - d3d11::RESERVED_CONSTANT_BUFFER_SLOT_COUNT; - - // Uniform blocks not supported on D3D11 Feature Level 9 - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 0; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetReservedVertexOutputVectors(D3D_FEATURE_LEVEL featureLevel) -{ - // According to The OpenGL ES Shading Language specifications - // (Language Version 1.00 section 10.16, Language Version 3.10 section 12.21) - // built-in special variables (e.g. gl_FragCoord, or gl_PointCoord) - // which are statically used in the shader should be included in the variable packing - // algorithm. - // Therefore, we should not reserve output vectors for them. - - switch (featureLevel) - { - // We must reserve one output vector for dx_Position. - // We also reserve one for gl_Position, which we unconditionally output on Feature - // Levels 10_0+, - // even if it's unused in the shader (e.g. for transform feedback). TODO: This could - // be improved. - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return 2; - - // Just reserve dx_Position on Feature Level 9, since we don't ever need to output - // gl_Position. - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 1; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumVertexOutputVectors(D3D_FEATURE_LEVEL featureLevel) -{ - static_assert(gl::IMPLEMENTATION_MAX_VARYING_VECTORS == D3D11_VS_OUTPUT_REGISTER_COUNT, - "Unexpected D3D11 constant value."); - - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_VS_OUTPUT_REGISTER_COUNT - GetReservedVertexOutputVectors(featureLevel); - - case D3D_FEATURE_LEVEL_10_1: - return D3D10_1_VS_OUTPUT_REGISTER_COUNT - GetReservedVertexOutputVectors(featureLevel); - case D3D_FEATURE_LEVEL_10_0: - return D3D10_VS_OUTPUT_REGISTER_COUNT - GetReservedVertexOutputVectors(featureLevel); - - // Use Shader Model 2.X limits - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 8 - GetReservedVertexOutputVectors(featureLevel); - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumVertexTextureUnits(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; - - // Vertex textures not supported on D3D11 Feature Level 9 according to - // http://msdn.microsoft.com/en-us/library/windows/desktop/ff476149.aspx - // ID3D11DeviceContext::VSSetSamplers and ID3D11DeviceContext::VSSetShaderResources - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 0; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumPixelUniformVectors(D3D_FEATURE_LEVEL featureLevel) -{ - // TODO(geofflang): Remove hard-coded limit once the gl-uniform-arrays test can pass - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return 1024; // D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return 1024; // D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT; - - // From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476149.aspx - // ID3D11DeviceContext::PSSetConstantBuffers - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 32 - d3d11_gl::GetReservedFragmentUniformVectors(featureLevel); - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumPixelUniformBlocks(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - - d3d11::RESERVED_CONSTANT_BUFFER_SLOT_COUNT; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - - d3d11::RESERVED_CONSTANT_BUFFER_SLOT_COUNT; - - // Uniform blocks not supported on D3D11 Feature Level 9 - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 0; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumPixelInputVectors(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_PS_INPUT_REGISTER_COUNT - GetReservedVertexOutputVectors(featureLevel); - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_PS_INPUT_REGISTER_COUNT - GetReservedVertexOutputVectors(featureLevel); - - // Use Shader Model 2.X limits - case D3D_FEATURE_LEVEL_9_3: - return 8 - GetReservedVertexOutputVectors(featureLevel); - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 8 - GetReservedVertexOutputVectors(featureLevel); - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumPixelTextureUnits(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; - - // http://msdn.microsoft.com/en-us/library/windows/desktop/ff476149.aspx - // ID3D11DeviceContext::PSSetShaderResources - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 16; - - default: - UNREACHABLE(); - return 0; - } -} - -std::array<GLuint, 3> GetMaxComputeWorkGroupCount(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return {{D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, - D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, - D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION}}; - break; - default: - return {{0, 0, 0}}; - } -} - -std::array<GLuint, 3> GetMaxComputeWorkGroupSize(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return {{D3D11_CS_THREAD_GROUP_MAX_X, D3D11_CS_THREAD_GROUP_MAX_Y, - D3D11_CS_THREAD_GROUP_MAX_Z}}; - break; - default: - return {{0, 0, 0}}; - } -} - -size_t GetMaxComputeWorkGroupInvocations(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_CS_THREAD_GROUP_MAX_THREADS_PER_GROUP; - default: - return 0; - } -} - -size_t GetMaximumComputeUniformVectors(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT; - default: - return 0; - } -} - -size_t GetMaximumComputeUniformBlocks(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - - d3d11::RESERVED_CONSTANT_BUFFER_SLOT_COUNT; - default: - return 0; - } -} - -size_t GetMaximumComputeTextureUnits(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; - default: - return 0; - } -} - -size_t GetMaximumImageUnits(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - // TODO(xinghua.cao@intel.com): Get a more accurate limit. For now using - // the minimum requirement for GLES 3.1. - return 4; - default: - return 0; - } -} - -size_t GetMaximumComputeImageUniforms(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - // TODO(xinghua.cao@intel.com): Get a more accurate limit. For now using - // the minimum requirement for GLES 3.1. - return 4; - default: - return 0; - } -} - -int GetMinimumTexelOffset(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_COMMONSHADER_TEXEL_OFFSET_MAX_NEGATIVE; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_COMMONSHADER_TEXEL_OFFSET_MAX_NEGATIVE; - - // Sampling functions with offsets are not available below shader model 4.0. - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 0; - - default: - UNREACHABLE(); - return 0; - } -} - -int GetMaximumTexelOffset(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_COMMONSHADER_TEXEL_OFFSET_MAX_POSITIVE; - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D11_COMMONSHADER_TEXEL_OFFSET_MAX_POSITIVE; - - // Sampling functions with offsets are not available below shader model 4.0. - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 0; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumConstantBufferSize(D3D_FEATURE_LEVEL featureLevel) -{ - // Returns a size_t despite the limit being a GLuint64 because size_t is the maximum - // size of - // any buffer that could be allocated. - - const size_t bytesPerComponent = 4 * sizeof(float); - - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * bytesPerComponent; - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * bytesPerComponent; - - // Limits from http://msdn.microsoft.com/en-us/library/windows/desktop/ff476501.aspx - // remarks section - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 4096 * bytesPerComponent; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumStreamOutputBuffers(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_SO_BUFFER_SLOT_COUNT; - - case D3D_FEATURE_LEVEL_10_1: - return D3D10_1_SO_BUFFER_SLOT_COUNT; - case D3D_FEATURE_LEVEL_10_0: - return D3D10_SO_BUFFER_SLOT_COUNT; - - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 0; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumStreamOutputInterleavedComponents(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return GetMaximumVertexOutputVectors(featureLevel) * 4; - - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 0; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumStreamOutputSeparateComponents(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return GetMaximumStreamOutputInterleavedComponents(featureLevel) / - GetMaximumStreamOutputBuffers(featureLevel); - - // D3D 10 and 10.1 only allow one output per output slot if an output slot other - // than zero is used. - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return 4; - - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 0; - - default: - UNREACHABLE(); - return 0; - } -} - -size_t GetMaximumRenderToBufferWindowSize(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_REQ_RENDER_TO_BUFFER_WINDOW_WIDTH; - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return D3D10_REQ_RENDER_TO_BUFFER_WINDOW_WIDTH; - - // REQ_RENDER_TO_BUFFER_WINDOW_WIDTH not supported on D3D11 Feature Level 9, - // use the maximum texture sizes - case D3D_FEATURE_LEVEL_9_3: - return D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION; - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION; - - default: - UNREACHABLE(); - return 0; - } -} - -IntelDriverVersion GetIntelDriverVersion(const Optional<LARGE_INTEGER> driverVersion) -{ - if (!driverVersion.valid()) - return IntelDriverVersion(0); - - // According to http://www.intel.com/content/www/us/en/support/graphics-drivers/000005654.html, - // only the fourth part is necessary since it stands for the driver specific unique version - // number. - WORD part = LOWORD(driverVersion.value().LowPart); - return IntelDriverVersion(part); -} - -} // anonymous namespace - -unsigned int GetReservedVertexUniformVectors(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return 0; - - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 3; // dx_ViewAdjust, dx_ViewCoords and dx_ViewScale - - default: - UNREACHABLE(); - return 0; - } -} - -unsigned int GetReservedFragmentUniformVectors(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return 0; - - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 3; - - default: - UNREACHABLE(); - return 0; - } -} - -gl::Version GetMaximumClientVersion(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return gl::Version(3, 1); - case D3D_FEATURE_LEVEL_10_1: - return gl::Version(3, 0); - - case D3D_FEATURE_LEVEL_10_0: - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return gl::Version(2, 0); - - default: - UNREACHABLE(); - return gl::Version(0, 0); - } -} - -unsigned int GetMaxViewportAndScissorRectanglesPerPipeline(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 1; - default: - UNREACHABLE(); - return 0; - } -} - -bool IsMultiviewSupported(D3D_FEATURE_LEVEL featureLevel) -{ - // The ANGLE_multiview extension can always be supported in D3D11 through geometry shaders. - switch (featureLevel) - { - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return true; - default: - return false; - } -} - -unsigned int GetMaxSampleMaskWords(D3D_FEATURE_LEVEL featureLevel) -{ - switch (featureLevel) - { - // D3D10+ only allows 1 sample mask. - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return 1u; - case D3D_FEATURE_LEVEL_9_3: - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - return 0u; - default: - UNREACHABLE(); - return 0u; - } -} - -void GenerateCaps(ID3D11Device *device, ID3D11DeviceContext *deviceContext, const Renderer11DeviceCaps &renderer11DeviceCaps, gl::Caps *caps, - gl::TextureCapsMap *textureCapsMap, gl::Extensions *extensions, gl::Limitations *limitations) -{ - D3D_FEATURE_LEVEL featureLevel = renderer11DeviceCaps.featureLevel; - const gl::FormatSet &allFormats = gl::GetAllSizedInternalFormats(); - for (GLenum internalFormat : allFormats) - { - gl::TextureCaps textureCaps = GenerateTextureFormatCaps( - GetMaximumClientVersion(featureLevel), internalFormat, device, renderer11DeviceCaps); - textureCapsMap->insert(internalFormat, textureCaps); - - if (gl::GetSizedInternalFormatInfo(internalFormat).compressed) - { - caps->compressedTextureFormats.push_back(internalFormat); - } - } - - // GL core feature limits - // Reserve MAX_UINT for D3D11's primitive restart. - caps->maxElementIndex = static_cast<GLint64>(std::numeric_limits<unsigned int>::max() - 1); - caps->max3DTextureSize = static_cast<GLuint>(GetMaximum3DTextureSize(featureLevel)); - caps->max2DTextureSize = static_cast<GLuint>(GetMaximum2DTextureSize(featureLevel)); - caps->maxCubeMapTextureSize = static_cast<GLuint>(GetMaximumCubeMapTextureSize(featureLevel)); - caps->maxArrayTextureLayers = static_cast<GLuint>(GetMaximum2DTextureArraySize(featureLevel)); - - // Unimplemented, set to minimum required - caps->maxLODBias = 2.0f; - - // No specific limits on render target size, maximum 2D texture size is equivalent - caps->maxRenderbufferSize = caps->max2DTextureSize; - - // Maximum draw buffers and color attachments are the same, max color attachments could eventually be - // increased to 16 - caps->maxDrawBuffers = static_cast<GLuint>(GetMaximumSimultaneousRenderTargets(featureLevel)); - caps->maxColorAttachments = - static_cast<GLuint>(GetMaximumSimultaneousRenderTargets(featureLevel)); - - // D3D11 has the same limit for viewport width and height - caps->maxViewportWidth = static_cast<GLuint>(GetMaximumViewportSize(featureLevel)); - caps->maxViewportHeight = caps->maxViewportWidth; - - // Choose a reasonable maximum, enforced in the shader. - caps->minAliasedPointSize = 1.0f; - caps->maxAliasedPointSize = 1024.0f; - - // Wide lines not supported - caps->minAliasedLineWidth = 1.0f; - caps->maxAliasedLineWidth = 1.0f; - - // Primitive count limits - caps->maxElementsIndices = static_cast<GLuint>(GetMaximumDrawIndexedIndexCount(featureLevel)); - caps->maxElementsVertices = static_cast<GLuint>(GetMaximumDrawVertexCount(featureLevel)); - - // Program and shader binary formats (no supported shader binary formats) - caps->programBinaryFormats.push_back(GL_PROGRAM_BINARY_ANGLE); - - caps->vertexHighpFloat.setIEEEFloat(); - caps->vertexMediumpFloat.setIEEEFloat(); - caps->vertexLowpFloat.setIEEEFloat(); - caps->fragmentHighpFloat.setIEEEFloat(); - caps->fragmentMediumpFloat.setIEEEFloat(); - caps->fragmentLowpFloat.setIEEEFloat(); - - // 32-bit integers are natively supported - caps->vertexHighpInt.setTwosComplementInt(32); - caps->vertexMediumpInt.setTwosComplementInt(32); - caps->vertexLowpInt.setTwosComplementInt(32); - caps->fragmentHighpInt.setTwosComplementInt(32); - caps->fragmentMediumpInt.setTwosComplementInt(32); - caps->fragmentLowpInt.setTwosComplementInt(32); - - // We do not wait for server fence objects internally, so report a max timeout of zero. - caps->maxServerWaitTimeout = 0; - - // Vertex shader limits - caps->maxVertexAttributes = static_cast<GLuint>(GetMaximumVertexInputSlots(featureLevel)); - caps->maxVertexUniformComponents = - static_cast<GLuint>(GetMaximumVertexUniformVectors(featureLevel)) * 4; - caps->maxVertexUniformVectors = - static_cast<GLuint>(GetMaximumVertexUniformVectors(featureLevel)); - caps->maxVertexUniformBlocks = static_cast<GLuint>(GetMaximumVertexUniformBlocks(featureLevel)); - caps->maxVertexOutputComponents = - static_cast<GLuint>(GetMaximumVertexOutputVectors(featureLevel)) * 4; - caps->maxVertexTextureImageUnits = - static_cast<GLuint>(GetMaximumVertexTextureUnits(featureLevel)); - - // Vertex Attribute Bindings are emulated on D3D11. - caps->maxVertexAttribBindings = caps->maxVertexAttributes; - // Experimental testing confirmed there is no explicit limit on maximum buffer offset in D3D11. - caps->maxVertexAttribRelativeOffset = std::numeric_limits<GLint>::max(); - // Experimental testing confirmed 2048 is the maximum stride that D3D11 can support on all - // platforms. - caps->maxVertexAttribStride = 2048; - - // Fragment shader limits - caps->maxFragmentUniformComponents = - static_cast<GLuint>(GetMaximumPixelUniformVectors(featureLevel)) * 4; - caps->maxFragmentUniformVectors = - static_cast<GLuint>(GetMaximumPixelUniformVectors(featureLevel)); - caps->maxFragmentUniformBlocks = - static_cast<GLuint>(GetMaximumPixelUniformBlocks(featureLevel)); - caps->maxFragmentInputComponents = - static_cast<GLuint>(GetMaximumPixelInputVectors(featureLevel)) * 4; - caps->maxTextureImageUnits = static_cast<GLuint>(GetMaximumPixelTextureUnits(featureLevel)); - caps->minProgramTexelOffset = GetMinimumTexelOffset(featureLevel); - caps->maxProgramTexelOffset = GetMaximumTexelOffset(featureLevel); - - // Compute shader limits - caps->maxComputeWorkGroupCount = GetMaxComputeWorkGroupCount(featureLevel); - caps->maxComputeWorkGroupSize = GetMaxComputeWorkGroupSize(featureLevel); - caps->maxComputeWorkGroupInvocations = - static_cast<GLuint>(GetMaxComputeWorkGroupInvocations(featureLevel)); - caps->maxComputeUniformComponents = - static_cast<GLuint>(GetMaximumComputeUniformVectors(featureLevel)) * 4; - caps->maxComputeUniformBlocks = - static_cast<GLuint>(GetMaximumComputeUniformBlocks(featureLevel)); - caps->maxComputeTextureImageUnits = - static_cast<GLuint>(GetMaximumComputeTextureUnits(featureLevel)); - caps->maxImageUnits = static_cast<GLuint>(GetMaximumImageUnits(featureLevel)); - caps->maxComputeImageUniforms = - static_cast<GLuint>(GetMaximumComputeImageUniforms(featureLevel)); - - // Aggregate shader limits - caps->maxUniformBufferBindings = caps->maxVertexUniformBlocks + caps->maxFragmentUniformBlocks; - caps->maxUniformBlockSize = GetMaximumConstantBufferSize(featureLevel); - - // TODO(oetuaho): Get a more accurate limit. For now using the minimum requirement for GLES 3.1. - caps->maxUniformLocations = 1024; - - // With DirectX 11.1, constant buffer offset and size must be a multiple of 16 constants of 16 bytes each. - // https://msdn.microsoft.com/en-us/library/windows/desktop/hh404649%28v=vs.85%29.aspx - // With DirectX 11.0, we emulate UBO offsets using copies of ranges of the UBO however - // we still keep the same alignment as 11.1 for consistency. - caps->uniformBufferOffsetAlignment = 256; - - caps->maxCombinedUniformBlocks = caps->maxVertexUniformBlocks + caps->maxFragmentUniformBlocks; - caps->maxCombinedVertexUniformComponents = (static_cast<GLint64>(caps->maxVertexUniformBlocks) * static_cast<GLint64>(caps->maxUniformBlockSize / 4)) + - static_cast<GLint64>(caps->maxVertexUniformComponents); - caps->maxCombinedFragmentUniformComponents = (static_cast<GLint64>(caps->maxFragmentUniformBlocks) * static_cast<GLint64>(caps->maxUniformBlockSize / 4)) + - static_cast<GLint64>(caps->maxFragmentUniformComponents); - caps->maxCombinedComputeUniformComponents = - static_cast<GLuint>(caps->maxComputeUniformBlocks * (caps->maxUniformBlockSize / 4) + - caps->maxComputeUniformComponents); - caps->maxVaryingComponents = - static_cast<GLuint>(GetMaximumVertexOutputVectors(featureLevel)) * 4; - caps->maxVaryingVectors = static_cast<GLuint>(GetMaximumVertexOutputVectors(featureLevel)); - caps->maxCombinedTextureImageUnits = caps->maxVertexTextureImageUnits + caps->maxTextureImageUnits; - - // Transform feedback limits - caps->maxTransformFeedbackInterleavedComponents = - static_cast<GLuint>(GetMaximumStreamOutputInterleavedComponents(featureLevel)); - caps->maxTransformFeedbackSeparateAttributes = - static_cast<GLuint>(GetMaximumStreamOutputBuffers(featureLevel)); - caps->maxTransformFeedbackSeparateComponents = - static_cast<GLuint>(GetMaximumStreamOutputSeparateComponents(featureLevel)); - - // Defer the computation of multisample limits to Context::updateCaps() where max*Samples values - // are determined according to available sample counts for each individual format. - caps->maxSamples = std::numeric_limits<GLint>::max(); - caps->maxColorTextureSamples = std::numeric_limits<GLint>::max(); - caps->maxDepthTextureSamples = std::numeric_limits<GLint>::max(); - caps->maxIntegerSamples = std::numeric_limits<GLint>::max(); - - // Sample mask words limits - caps->maxSampleMaskWords = GetMaxSampleMaskWords(featureLevel); - - // Framebuffer limits - caps->maxFramebufferSamples = std::numeric_limits<GLint>::max(); - caps->maxFramebufferWidth = - static_cast<GLuint>(GetMaximumRenderToBufferWindowSize(featureLevel)); - caps->maxFramebufferHeight = caps->maxFramebufferWidth; - - // GL extension support - extensions->setTextureExtensionSupport(*textureCapsMap); - extensions->elementIndexUint = true; - extensions->getProgramBinary = true; - extensions->rgb8rgba8 = true; - extensions->readFormatBGRA = true; - extensions->pixelBufferObject = true; - extensions->mapBuffer = true; - extensions->mapBufferRange = true; - extensions->textureNPOT = GetNPOTTextureSupport(featureLevel); - extensions->drawBuffers = GetMaximumSimultaneousRenderTargets(featureLevel) > 1; - extensions->textureStorage = true; - extensions->textureFilterAnisotropic = true; - extensions->maxTextureAnisotropy = GetMaximumAnisotropy(featureLevel); - extensions->occlusionQueryBoolean = GetOcclusionQuerySupport(featureLevel); - extensions->fence = GetEventQuerySupport(featureLevel); - extensions->disjointTimerQuery = true; - extensions->queryCounterBitsTimeElapsed = 64; - extensions->queryCounterBitsTimestamp = - 0; // Timestamps cannot be supported due to D3D11 limitations - extensions->robustness = true; - // Direct3D guarantees to return zero for any resource that is accessed out of bounds. - // See https://msdn.microsoft.com/en-us/library/windows/desktop/ff476332(v=vs.85).aspx - // and https://msdn.microsoft.com/en-us/library/windows/desktop/ff476900(v=vs.85).aspx - extensions->robustBufferAccessBehavior = true; - extensions->blendMinMax = true; - extensions->framebufferBlit = GetFramebufferBlitSupport(featureLevel); - extensions->framebufferMultisample = GetFramebufferMultisampleSupport(featureLevel); - extensions->instancedArrays = GetInstancingSupport(featureLevel); - extensions->packReverseRowOrder = true; - extensions->standardDerivatives = GetDerivativeInstructionSupport(featureLevel); - extensions->shaderTextureLOD = GetShaderTextureLODSupport(featureLevel); - extensions->fragDepth = true; - extensions->multiview = IsMultiviewSupported(featureLevel); - if (extensions->multiview) - { - extensions->maxViews = - std::min(static_cast<GLuint>(gl::IMPLEMENTATION_ANGLE_MULTIVIEW_MAX_VIEWS), - std::min(static_cast<GLuint>(GetMaximum2DTextureArraySize(featureLevel)), - GetMaxViewportAndScissorRectanglesPerPipeline(featureLevel))); - } - extensions->textureUsage = true; // This could be false since it has no effect in D3D11 - extensions->discardFramebuffer = true; - extensions->translatedShaderSource = true; - extensions->fboRenderMipmap = false; - extensions->debugMarker = true; - extensions->eglImage = true; - extensions->eglImageExternal = true; - extensions->eglImageExternalEssl3 = true; - extensions->eglStreamConsumerExternal = true; - extensions->unpackSubimage = true; - extensions->packSubimage = true; - extensions->lossyETCDecode = true; - extensions->syncQuery = GetEventQuerySupport(featureLevel); - extensions->copyTexture = true; - extensions->copyCompressedTexture = true; - - // D3D11 Feature Level 10_0+ uses SV_IsFrontFace in HLSL to emulate gl_FrontFacing. - // D3D11 Feature Level 9_3 doesn't support SV_IsFrontFace, and has no equivalent, so can't support gl_FrontFacing. - limitations->noFrontFacingSupport = (renderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3); - - // D3D11 Feature Level 9_3 doesn't support alpha-to-coverage - limitations->noSampleAlphaToCoverageSupport = (renderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3); - - // D3D11 Feature Levels 9_3 and below do not support non-constant loop indexing and require - // additional - // pre-validation of the shader at compile time to produce a better error message. - limitations->shadersRequireIndexedLoopValidation = - (renderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3); - - // D3D11 has no concept of separate masks and refs for front and back faces in the depth stencil - // state. - limitations->noSeparateStencilRefsAndMasks = true; - - // D3D11 cannot support constant color and alpha blend funcs together - limitations->noSimultaneousConstantColorAndAlphaBlendFunc = true; - -#ifdef ANGLE_ENABLE_WINDOWS_STORE - // Setting a non-zero divisor on attribute zero doesn't work on certain Windows Phone 8-era devices. - // We should prevent developers from doing this on ALL Windows Store devices. This will maintain consistency across all Windows devices. - // We allow non-zero divisors on attribute zero if the Client Version >= 3, since devices affected by this issue don't support ES3+. - limitations->attributeZeroRequiresZeroDivisorInEXT = true; -#endif -} - -void GetSamplePosition(GLsizei sampleCount, size_t index, GLfloat *xy) -{ - size_t indexKey = static_cast<size_t>(ceil(log(sampleCount))); - ASSERT(indexKey < kSamplePositions.size() && - (2 * index + 1) < kSamplePositions[indexKey].size()); - - xy[0] = kSamplePositions[indexKey][2 * index]; - xy[1] = kSamplePositions[indexKey][2 * index + 1]; -} - -} // namespace d3d11_gl - -namespace gl_d3d11 -{ - -D3D11_BLEND ConvertBlendFunc(GLenum glBlend, bool isAlpha) -{ - D3D11_BLEND d3dBlend = D3D11_BLEND_ZERO; - - switch (glBlend) - { - case GL_ZERO: - d3dBlend = D3D11_BLEND_ZERO; - break; - case GL_ONE: - d3dBlend = D3D11_BLEND_ONE; - break; - case GL_SRC_COLOR: - d3dBlend = (isAlpha ? D3D11_BLEND_SRC_ALPHA : D3D11_BLEND_SRC_COLOR); - break; - case GL_ONE_MINUS_SRC_COLOR: - d3dBlend = (isAlpha ? D3D11_BLEND_INV_SRC_ALPHA : D3D11_BLEND_INV_SRC_COLOR); - break; - case GL_DST_COLOR: - d3dBlend = (isAlpha ? D3D11_BLEND_DEST_ALPHA : D3D11_BLEND_DEST_COLOR); - break; - case GL_ONE_MINUS_DST_COLOR: - d3dBlend = (isAlpha ? D3D11_BLEND_INV_DEST_ALPHA : D3D11_BLEND_INV_DEST_COLOR); - break; - case GL_SRC_ALPHA: - d3dBlend = D3D11_BLEND_SRC_ALPHA; - break; - case GL_ONE_MINUS_SRC_ALPHA: - d3dBlend = D3D11_BLEND_INV_SRC_ALPHA; - break; - case GL_DST_ALPHA: - d3dBlend = D3D11_BLEND_DEST_ALPHA; - break; - case GL_ONE_MINUS_DST_ALPHA: - d3dBlend = D3D11_BLEND_INV_DEST_ALPHA; - break; - case GL_CONSTANT_COLOR: - d3dBlend = D3D11_BLEND_BLEND_FACTOR; - break; - case GL_ONE_MINUS_CONSTANT_COLOR: - d3dBlend = D3D11_BLEND_INV_BLEND_FACTOR; - break; - case GL_CONSTANT_ALPHA: - d3dBlend = D3D11_BLEND_BLEND_FACTOR; - break; - case GL_ONE_MINUS_CONSTANT_ALPHA: - d3dBlend = D3D11_BLEND_INV_BLEND_FACTOR; - break; - case GL_SRC_ALPHA_SATURATE: - d3dBlend = D3D11_BLEND_SRC_ALPHA_SAT; - break; - default: - UNREACHABLE(); - } - - return d3dBlend; -} - -D3D11_BLEND_OP ConvertBlendOp(GLenum glBlendOp) -{ - D3D11_BLEND_OP d3dBlendOp = D3D11_BLEND_OP_ADD; - - switch (glBlendOp) - { - case GL_FUNC_ADD: - d3dBlendOp = D3D11_BLEND_OP_ADD; - break; - case GL_FUNC_SUBTRACT: - d3dBlendOp = D3D11_BLEND_OP_SUBTRACT; - break; - case GL_FUNC_REVERSE_SUBTRACT: - d3dBlendOp = D3D11_BLEND_OP_REV_SUBTRACT; - break; - case GL_MIN: - d3dBlendOp = D3D11_BLEND_OP_MIN; - break; - case GL_MAX: - d3dBlendOp = D3D11_BLEND_OP_MAX; - break; - default: - UNREACHABLE(); - } - - return d3dBlendOp; -} - -UINT8 ConvertColorMask(bool red, bool green, bool blue, bool alpha) -{ - UINT8 mask = 0; - if (red) - { - mask |= D3D11_COLOR_WRITE_ENABLE_RED; - } - if (green) - { - mask |= D3D11_COLOR_WRITE_ENABLE_GREEN; - } - if (blue) - { - mask |= D3D11_COLOR_WRITE_ENABLE_BLUE; - } - if (alpha) - { - mask |= D3D11_COLOR_WRITE_ENABLE_ALPHA; - } - return mask; -} - -D3D11_CULL_MODE ConvertCullMode(bool cullEnabled, gl::CullFaceMode cullMode) -{ - D3D11_CULL_MODE cull = D3D11_CULL_NONE; - - if (cullEnabled) - { - switch (cullMode) - { - case gl::CullFaceMode::Front: - cull = D3D11_CULL_FRONT; - break; - case gl::CullFaceMode::Back: - cull = D3D11_CULL_BACK; - break; - case gl::CullFaceMode::FrontAndBack: - cull = D3D11_CULL_NONE; - break; - default: - UNREACHABLE(); - } - } - else - { - cull = D3D11_CULL_NONE; - } - - return cull; -} - -D3D11_COMPARISON_FUNC ConvertComparison(GLenum comparison) -{ - D3D11_COMPARISON_FUNC d3dComp = D3D11_COMPARISON_NEVER; - switch (comparison) - { - case GL_NEVER: - d3dComp = D3D11_COMPARISON_NEVER; - break; - case GL_ALWAYS: - d3dComp = D3D11_COMPARISON_ALWAYS; - break; - case GL_LESS: - d3dComp = D3D11_COMPARISON_LESS; - break; - case GL_LEQUAL: - d3dComp = D3D11_COMPARISON_LESS_EQUAL; - break; - case GL_EQUAL: - d3dComp = D3D11_COMPARISON_EQUAL; - break; - case GL_GREATER: - d3dComp = D3D11_COMPARISON_GREATER; - break; - case GL_GEQUAL: - d3dComp = D3D11_COMPARISON_GREATER_EQUAL; - break; - case GL_NOTEQUAL: - d3dComp = D3D11_COMPARISON_NOT_EQUAL; - break; - default: - UNREACHABLE(); - } - - return d3dComp; -} - -D3D11_DEPTH_WRITE_MASK ConvertDepthMask(bool depthWriteEnabled) -{ - return depthWriteEnabled ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO; -} - -UINT8 ConvertStencilMask(GLuint stencilmask) -{ - return static_cast<UINT8>(stencilmask); -} - -D3D11_STENCIL_OP ConvertStencilOp(GLenum stencilOp) -{ - D3D11_STENCIL_OP d3dStencilOp = D3D11_STENCIL_OP_KEEP; - - switch (stencilOp) - { - case GL_ZERO: - d3dStencilOp = D3D11_STENCIL_OP_ZERO; - break; - case GL_KEEP: - d3dStencilOp = D3D11_STENCIL_OP_KEEP; - break; - case GL_REPLACE: - d3dStencilOp = D3D11_STENCIL_OP_REPLACE; - break; - case GL_INCR: - d3dStencilOp = D3D11_STENCIL_OP_INCR_SAT; - break; - case GL_DECR: - d3dStencilOp = D3D11_STENCIL_OP_DECR_SAT; - break; - case GL_INVERT: - d3dStencilOp = D3D11_STENCIL_OP_INVERT; - break; - case GL_INCR_WRAP: - d3dStencilOp = D3D11_STENCIL_OP_INCR; - break; - case GL_DECR_WRAP: - d3dStencilOp = D3D11_STENCIL_OP_DECR; - break; - default: - UNREACHABLE(); - } - - return d3dStencilOp; -} - -D3D11_FILTER ConvertFilter(GLenum minFilter, - GLenum magFilter, - float maxAnisotropy, - GLenum comparisonMode) -{ - bool comparison = comparisonMode != GL_NONE; - - if (maxAnisotropy > 1.0f) - { - return D3D11_ENCODE_ANISOTROPIC_FILTER(static_cast<D3D11_COMPARISON_FUNC>(comparison)); - } - else - { - D3D11_FILTER_TYPE dxMin = D3D11_FILTER_TYPE_POINT; - D3D11_FILTER_TYPE dxMip = D3D11_FILTER_TYPE_POINT; - switch (minFilter) - { - case GL_NEAREST: - dxMin = D3D11_FILTER_TYPE_POINT; - dxMip = D3D11_FILTER_TYPE_POINT; - break; - case GL_LINEAR: - dxMin = D3D11_FILTER_TYPE_LINEAR; - dxMip = D3D11_FILTER_TYPE_POINT; - break; - case GL_NEAREST_MIPMAP_NEAREST: - dxMin = D3D11_FILTER_TYPE_POINT; - dxMip = D3D11_FILTER_TYPE_POINT; - break; - case GL_LINEAR_MIPMAP_NEAREST: - dxMin = D3D11_FILTER_TYPE_LINEAR; - dxMip = D3D11_FILTER_TYPE_POINT; - break; - case GL_NEAREST_MIPMAP_LINEAR: - dxMin = D3D11_FILTER_TYPE_POINT; - dxMip = D3D11_FILTER_TYPE_LINEAR; - break; - case GL_LINEAR_MIPMAP_LINEAR: - dxMin = D3D11_FILTER_TYPE_LINEAR; - dxMip = D3D11_FILTER_TYPE_LINEAR; - break; - default: - UNREACHABLE(); - } - - D3D11_FILTER_TYPE dxMag = D3D11_FILTER_TYPE_POINT; - switch (magFilter) - { - case GL_NEAREST: - dxMag = D3D11_FILTER_TYPE_POINT; - break; - case GL_LINEAR: - dxMag = D3D11_FILTER_TYPE_LINEAR; - break; - default: - UNREACHABLE(); - } - - return D3D11_ENCODE_BASIC_FILTER(dxMin, dxMag, dxMip, - static_cast<D3D11_COMPARISON_FUNC>(comparison)); - } -} - -D3D11_TEXTURE_ADDRESS_MODE ConvertTextureWrap(GLenum wrap) -{ - switch (wrap) - { - case GL_REPEAT: - return D3D11_TEXTURE_ADDRESS_WRAP; - case GL_CLAMP_TO_EDGE: - return D3D11_TEXTURE_ADDRESS_CLAMP; - case GL_MIRRORED_REPEAT: - return D3D11_TEXTURE_ADDRESS_MIRROR; - default: - UNREACHABLE(); - } - - return D3D11_TEXTURE_ADDRESS_WRAP; -} - -UINT ConvertMaxAnisotropy(float maxAnisotropy, D3D_FEATURE_LEVEL featureLevel) -{ - return static_cast<UINT>(std::min(maxAnisotropy, d3d11_gl::GetMaximumAnisotropy(featureLevel))); -} - -D3D11_QUERY ConvertQueryType(GLenum queryType) -{ - switch (queryType) - { - case GL_ANY_SAMPLES_PASSED_EXT: - case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT: - return D3D11_QUERY_OCCLUSION; - case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: - return D3D11_QUERY_SO_STATISTICS; - case GL_TIME_ELAPSED_EXT: - // Two internal queries are also created for begin/end timestamps - return D3D11_QUERY_TIMESTAMP_DISJOINT; - case GL_COMMANDS_COMPLETED_CHROMIUM: - return D3D11_QUERY_EVENT; - default: - UNREACHABLE(); - return D3D11_QUERY_EVENT; - } -} - -// Get the D3D11 write mask covering all color channels of a given format -UINT8 GetColorMask(const gl::InternalFormat &format) -{ - return ConvertColorMask(format.redBits > 0, format.greenBits > 0, format.blueBits > 0, - format.alphaBits > 0); -} - -} // namespace gl_d3d11 - -namespace d3d11 -{ - -ANGLED3D11DeviceType GetDeviceType(ID3D11Device *device) -{ - // Note that this function returns an ANGLED3D11DeviceType rather than a D3D_DRIVER_TYPE value, - // since it is difficult to tell Software and Reference devices apart - - IDXGIDevice *dxgiDevice = nullptr; - IDXGIAdapter *dxgiAdapter = nullptr; - IDXGIAdapter2 *dxgiAdapter2 = nullptr; - - ANGLED3D11DeviceType retDeviceType = ANGLE_D3D11_DEVICE_TYPE_UNKNOWN; - - HRESULT hr = device->QueryInterface(__uuidof(IDXGIDevice), (void **)&dxgiDevice); - if (SUCCEEDED(hr)) - { - hr = dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void **)&dxgiAdapter); - if (SUCCEEDED(hr)) - { - std::wstring adapterString; - HRESULT adapter2hr = - dxgiAdapter->QueryInterface(__uuidof(dxgiAdapter2), (void **)&dxgiAdapter2); - if (SUCCEEDED(adapter2hr)) - { - // On D3D_FEATURE_LEVEL_9_*, IDXGIAdapter::GetDesc returns "Software Adapter" - // for the description string. Try to use IDXGIAdapter2::GetDesc2 to get the - // actual hardware values if possible. - DXGI_ADAPTER_DESC2 adapterDesc2; - dxgiAdapter2->GetDesc2(&adapterDesc2); - adapterString = std::wstring(adapterDesc2.Description); - } - else - { - DXGI_ADAPTER_DESC adapterDesc; - dxgiAdapter->GetDesc(&adapterDesc); - adapterString = std::wstring(adapterDesc.Description); - } - - // Both Reference and Software adapters will be 'Software Adapter' - const bool isSoftwareDevice = - (adapterString.find(std::wstring(L"Software Adapter")) != std::string::npos); - const bool isNullDevice = (adapterString == L""); - const bool isWARPDevice = - (adapterString.find(std::wstring(L"Basic Render")) != std::string::npos); - - if (isSoftwareDevice || isNullDevice) - { - ASSERT(!isWARPDevice); - retDeviceType = ANGLE_D3D11_DEVICE_TYPE_SOFTWARE_REF_OR_NULL; - } - else if (isWARPDevice) - { - retDeviceType = ANGLE_D3D11_DEVICE_TYPE_WARP; - } - else - { - retDeviceType = ANGLE_D3D11_DEVICE_TYPE_HARDWARE; - } - } - } - - SafeRelease(dxgiDevice); - SafeRelease(dxgiAdapter); - SafeRelease(dxgiAdapter2); - - return retDeviceType; -} - -void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset) -{ - const DXGIFormatSize &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(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++; - } - } - if (levelOffset) - { - *levelOffset = upsampleCount; - } -} - -void GenerateInitialTextureData(GLint internalFormat, - const Renderer11DeviceCaps &renderer11DeviceCaps, - GLuint width, - GLuint height, - GLuint depth, - GLuint mipLevels, - std::vector<D3D11_SUBRESOURCE_DATA> *outSubresourceData, - std::vector<std::vector<BYTE>> *outData) -{ - const d3d11::Format &d3dFormatInfo = d3d11::Format::Get(internalFormat, renderer11DeviceCaps); - ASSERT(d3dFormatInfo.dataInitializerFunction != nullptr); - - const d3d11::DXGIFormatSize &dxgiFormatInfo = - d3d11::GetDXGIFormatSizeInfo(d3dFormatInfo.texFormat); - - outSubresourceData->resize(mipLevels); - outData->resize(mipLevels); - - for (unsigned int i = 0; i < mipLevels; i++) - { - unsigned int mipWidth = std::max(width >> i, 1U); - unsigned int mipHeight = std::max(height >> i, 1U); - unsigned int mipDepth = std::max(depth >> i, 1U); - - unsigned int rowWidth = dxgiFormatInfo.pixelBytes * mipWidth; - unsigned int imageSize = rowWidth * height; - - outData->at(i).resize(rowWidth * mipHeight * mipDepth); - d3dFormatInfo.dataInitializerFunction(mipWidth, mipHeight, mipDepth, outData->at(i).data(), rowWidth, imageSize); - - outSubresourceData->at(i).pSysMem = outData->at(i).data(); - outSubresourceData->at(i).SysMemPitch = rowWidth; - outSubresourceData->at(i).SysMemSlicePitch = imageSize; - } -} - -UINT GetPrimitiveRestartIndex() -{ - return std::numeric_limits<UINT>::max(); -} - -void SetPositionTexCoordVertex(PositionTexCoordVertex* vertex, float x, float y, float u, float v) -{ - vertex->x = x; - vertex->y = y; - vertex->u = u; - vertex->v = v; -} - -void SetPositionLayerTexCoord3DVertex(PositionLayerTexCoord3DVertex* vertex, float x, float y, - unsigned int layer, float u, float v, float s) -{ - vertex->x = x; - vertex->y = y; - vertex->l = layer; - vertex->u = u; - vertex->v = v; - vertex->s = s; -} - -BlendStateKey::BlendStateKey() -{ - memset(this, 0, sizeof(BlendStateKey)); -} - -bool operator==(const BlendStateKey &a, const BlendStateKey &b) -{ - return memcmp(&a, &b, sizeof(BlendStateKey)) == 0; -} - -bool operator!=(const BlendStateKey &a, const BlendStateKey &b) -{ - return !(a == b); -} - -RasterizerStateKey::RasterizerStateKey() -{ - memset(this, 0, sizeof(RasterizerStateKey)); -} - -bool operator==(const RasterizerStateKey &a, const RasterizerStateKey &b) -{ - return memcmp(&a, &b, sizeof(RasterizerStateKey)) == 0; -} - -bool operator!=(const RasterizerStateKey &a, const RasterizerStateKey &b) -{ - return !(a == b); -} - -HRESULT SetDebugName(ID3D11DeviceChild *resource, const char *name) -{ -#if defined(_DEBUG) - UINT existingDataSize = 0; - resource->GetPrivateData(WKPDID_D3DDebugObjectName, &existingDataSize, nullptr); - // Don't check the HRESULT- if it failed then that probably just means that no private data - // exists yet - - if (existingDataSize > 0) - { - // In some cases, ANGLE will try to apply two names to one object, which causes - // a D3D SDK Layers warning. This can occur if, for example, you 'create' two objects - // (e.g.Rasterizer States) with identical DESCs on the same device. D3D11 will optimize - // these calls and return the same object both times. - static const char *multipleNamesUsed = "Multiple names set by ANGLE"; - - // Remove the existing name - HRESULT hr = resource->SetPrivateData(WKPDID_D3DDebugObjectName, 0, nullptr); - if (FAILED(hr)) - { - return hr; - } - - // Apply the new name - return resource->SetPrivateData(WKPDID_D3DDebugObjectName, - static_cast<unsigned int>(strlen(multipleNamesUsed)), - multipleNamesUsed); - } - else - { - return resource->SetPrivateData(WKPDID_D3DDebugObjectName, - static_cast<unsigned int>(strlen(name)), name); - } -#else - return S_OK; -#endif -} - -// Keep this in cpp file where it has visibility of Renderer11.h, otherwise calling -// allocateResource is only compatible with Clang and MSVS, which support calling a -// method on a forward declared class in a template. -template <ResourceType ResourceT> -gl::Error LazyResource<ResourceT>::resolveImpl(Renderer11 *renderer, - const GetDescType<ResourceT> &desc, - GetInitDataType<ResourceT> *initData, - const char *name) -{ - if (!mResource.valid()) - { - ANGLE_TRY(renderer->allocateResource(desc, initData, &mResource)); - mResource.setDebugName(name); - } - return gl::NoError(); -} - -template gl::Error LazyResource<ResourceType::BlendState>::resolveImpl(Renderer11 *renderer, - const D3D11_BLEND_DESC &desc, - void *initData, - const char *name); -template gl::Error LazyResource<ResourceType::ComputeShader>::resolveImpl(Renderer11 *renderer, - const ShaderData &desc, - void *initData, - const char *name); -template gl::Error LazyResource<ResourceType::GeometryShader>::resolveImpl( - Renderer11 *renderer, - const ShaderData &desc, - const std::vector<D3D11_SO_DECLARATION_ENTRY> *initData, - const char *name); -template gl::Error LazyResource<ResourceType::InputLayout>::resolveImpl( - Renderer11 *renderer, - const InputElementArray &desc, - const ShaderData *initData, - const char *name); -template gl::Error LazyResource<ResourceType::PixelShader>::resolveImpl(Renderer11 *renderer, - const ShaderData &desc, - void *initData, - const char *name); -template gl::Error LazyResource<ResourceType::VertexShader>::resolveImpl(Renderer11 *renderer, - const ShaderData &desc, - void *initData, - const char *name); - -LazyInputLayout::LazyInputLayout(const D3D11_INPUT_ELEMENT_DESC *inputDesc, - size_t inputDescLen, - const BYTE *byteCode, - size_t byteCodeLen, - const char *debugName) - : mInputDesc(inputDesc, inputDescLen), mByteCode(byteCode, byteCodeLen), mDebugName(debugName) -{ -} - -LazyInputLayout::~LazyInputLayout() -{ -} - -gl::Error LazyInputLayout::resolve(Renderer11 *renderer) -{ - return resolveImpl(renderer, mInputDesc, &mByteCode, mDebugName); -} - -LazyBlendState::LazyBlendState(const D3D11_BLEND_DESC &desc, const char *debugName) - : mDesc(desc), mDebugName(debugName) -{ -} - -gl::Error LazyBlendState::resolve(Renderer11 *renderer) -{ - return resolveImpl(renderer, mDesc, nullptr, mDebugName); -} - -angle::WorkaroundsD3D GenerateWorkarounds(const Renderer11DeviceCaps &deviceCaps, - const DXGI_ADAPTER_DESC &adapterDesc) -{ - bool is9_3 = (deviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3); - - angle::WorkaroundsD3D workarounds; - workarounds.mrtPerfWorkaround = true; - workarounds.setDataFasterThanImageUpload = true; - workarounds.zeroMaxLodWorkaround = is9_3; - workarounds.useInstancedPointSpriteEmulation = is9_3; - - // TODO(jmadill): Narrow problematic driver range. - if (IsNvidia(adapterDesc.VendorId)) - { - if (deviceCaps.driverVersion.valid()) - { - WORD part1 = HIWORD(deviceCaps.driverVersion.value().LowPart); - WORD part2 = LOWORD(deviceCaps.driverVersion.value().LowPart); - - // Disable the workaround to fix a second driver bug on newer NVIDIA. - workarounds.depthStencilBlitExtraCopy = (part1 <= 13u && part2 < 6881); - } - else - { - workarounds.depthStencilBlitExtraCopy = true; - } - } - - // TODO(jmadill): Disable workaround when we have a fixed compiler DLL. - workarounds.expandIntegerPowExpressions = true; - - workarounds.flushAfterEndingTransformFeedback = IsNvidia(adapterDesc.VendorId); - workarounds.getDimensionsIgnoresBaseLevel = IsNvidia(adapterDesc.VendorId); - - if (IsIntel(adapterDesc.VendorId)) - { - IntelDriverVersion capsVersion = d3d11_gl::GetIntelDriverVersion(deviceCaps.driverVersion); - - workarounds.preAddTexelFetchOffsets = true; - workarounds.useSystemMemoryForConstantBuffers = true; - workarounds.disableB5G6R5Support = capsVersion < IntelDriverVersion(4539); - workarounds.addDummyTextureNoRenderTarget = capsVersion < IntelDriverVersion(4815); - if (IsSkylake(adapterDesc.DeviceId)) - { - workarounds.callClearTwice = capsVersion < IntelDriverVersion(4771); - workarounds.emulateIsnanFloat = capsVersion < IntelDriverVersion(4542); - } - else if (IsBroadwell(adapterDesc.DeviceId) || IsHaswell(adapterDesc.DeviceId)) - { - workarounds.rewriteUnaryMinusOperator = capsVersion < IntelDriverVersion(4624); - } - } - - // TODO(jmadill): Disable when we have a fixed driver version. - workarounds.emulateTinyStencilTextures = IsAMD(adapterDesc.VendorId); - - // The tiny stencil texture workaround involves using CopySubresource or UpdateSubresource on a - // depth stencil texture. This is not allowed until feature level 10.1 but since it is not - // possible to support ES3 on these devices, there is no need for the workaround to begin with - // (anglebug.com/1572). - if (deviceCaps.featureLevel < D3D_FEATURE_LEVEL_10_1) - { - workarounds.emulateTinyStencilTextures = false; - } - - // If the VPAndRTArrayIndexFromAnyShaderFeedingRasterizer feature is not available, we have to - // select the viewport / RT array index in the geometry shader. - workarounds.selectViewInGeometryShader = - (deviceCaps.supportsVpRtIndexWriteFromVertexShader == false); - - // Call platform hooks for testing overrides. - auto *platform = ANGLEPlatformCurrent(); - platform->overrideWorkaroundsD3D(platform, &workarounds); - - return workarounds; -} - -void InitConstantBufferDesc(D3D11_BUFFER_DESC *constantBufferDescription, size_t byteWidth) -{ - constantBufferDescription->ByteWidth = static_cast<UINT>(byteWidth); - constantBufferDescription->Usage = D3D11_USAGE_DYNAMIC; - constantBufferDescription->BindFlags = D3D11_BIND_CONSTANT_BUFFER; - constantBufferDescription->CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - constantBufferDescription->MiscFlags = 0; - constantBufferDescription->StructureByteStride = 0; -} - -} // namespace d3d11 - -// TextureHelper11 implementation. -TextureHelper11::TextureHelper11() : mFormatSet(nullptr), mSampleCount(0) -{ -} - -TextureHelper11::TextureHelper11(TextureHelper11 &&toCopy) : TextureHelper11() -{ - *this = std::move(toCopy); -} - -TextureHelper11::TextureHelper11(const TextureHelper11 &other) - : mFormatSet(other.mFormatSet), mExtents(other.mExtents), mSampleCount(other.mSampleCount) -{ - mData = other.mData; -} - -TextureHelper11::~TextureHelper11() -{ -} - -void TextureHelper11::getDesc(D3D11_TEXTURE2D_DESC *desc) const -{ - static_cast<ID3D11Texture2D *>(mData->object)->GetDesc(desc); -} - -void TextureHelper11::getDesc(D3D11_TEXTURE3D_DESC *desc) const -{ - static_cast<ID3D11Texture3D *>(mData->object)->GetDesc(desc); -} - -void TextureHelper11::initDesc(const D3D11_TEXTURE2D_DESC &desc2D) -{ - mData->resourceType = ResourceType::Texture2D; - mExtents.width = static_cast<int>(desc2D.Width); - mExtents.height = static_cast<int>(desc2D.Height); - mExtents.depth = 1; - mSampleCount = desc2D.SampleDesc.Count; -} - -void TextureHelper11::initDesc(const D3D11_TEXTURE3D_DESC &desc3D) -{ - mData->resourceType = ResourceType::Texture3D; - mExtents.width = static_cast<int>(desc3D.Width); - mExtents.height = static_cast<int>(desc3D.Height); - mExtents.depth = static_cast<int>(desc3D.Depth); - mSampleCount = 1; -} - -TextureHelper11 &TextureHelper11::operator=(TextureHelper11 &&other) -{ - std::swap(mData, other.mData); - std::swap(mExtents, other.mExtents); - std::swap(mFormatSet, other.mFormatSet); - std::swap(mSampleCount, other.mSampleCount); - return *this; -} - -TextureHelper11 &TextureHelper11::operator=(const TextureHelper11 &other) -{ - mData = other.mData; - mExtents = other.mExtents; - mFormatSet = other.mFormatSet; - mSampleCount = other.mSampleCount; - return *this; -} - -bool TextureHelper11::operator==(const TextureHelper11 &other) const -{ - return mData->object == other.mData->object; -} - -bool TextureHelper11::operator!=(const TextureHelper11 &other) const -{ - return mData->object != other.mData->object; -} - -bool UsePresentPathFast(const Renderer11 *renderer, - const gl::FramebufferAttachment *framebufferAttachment) -{ - if (framebufferAttachment == nullptr) - { - return false; - } - - return (framebufferAttachment->type() == GL_FRAMEBUFFER_DEFAULT && - renderer->presentPathFastEnabled()); -} - -bool UsePrimitiveRestartWorkaround(bool primitiveRestartFixedIndexEnabled, GLenum type) -{ - // We should never have to deal with primitive restart workaround issue with GL_UNSIGNED_INT - // indices, since we restrict it via MAX_ELEMENT_INDEX. - return (!primitiveRestartFixedIndexEnabled && type == GL_UNSIGNED_SHORT); -} - -bool IsStreamingIndexData(const gl::Context *context, GLenum srcType) -{ - const auto &glState = context->getGLState(); - gl::Buffer *glBuffer = glState.getVertexArray()->getElementArrayBuffer().get(); - - // Case 1: the indices are passed by pointer, which forces the streaming of index data - if (glBuffer == nullptr) - { - return true; - } - - bool primitiveRestartWorkaround = - UsePrimitiveRestartWorkaround(glState.isPrimitiveRestartEnabled(), srcType); - - BufferD3D *buffer = GetImplAs<BufferD3D>(glBuffer); - const GLenum dstType = (srcType == GL_UNSIGNED_INT || primitiveRestartWorkaround) - ? GL_UNSIGNED_INT - : GL_UNSIGNED_SHORT; - - // Case 2a: the buffer can be used directly - if (buffer->supportsDirectBinding() && dstType == srcType) - { - return false; - } - - // Case 2b: use a static translated copy or fall back to streaming - StaticIndexBufferInterface *staticBuffer = buffer->getStaticIndexBuffer(); - if (staticBuffer == nullptr) - { - return true; - } - - if ((staticBuffer->getBufferSize() == 0) || (staticBuffer->getIndexType() != dstType)) - { - return true; - } - - return false; -} - -IndexStorageType ClassifyIndexStorage(const gl::State &glState, - const gl::Buffer *elementArrayBuffer, - GLenum elementType, - GLenum destElementType, - unsigned int offset, - bool *needsTranslation) -{ - // No buffer bound means we are streaming from a client pointer. - if (!elementArrayBuffer || !IsOffsetAligned(elementType, offset)) - { - *needsTranslation = true; - return IndexStorageType::Dynamic; - } - - // The buffer can be used directly if the storage supports it and no translation needed. - BufferD3D *bufferD3D = GetImplAs<BufferD3D>(elementArrayBuffer); - if (bufferD3D->supportsDirectBinding() && destElementType == elementType) - { - *needsTranslation = false; - return IndexStorageType::Direct; - } - - // Use a static copy when available. - StaticIndexBufferInterface *staticBuffer = bufferD3D->getStaticIndexBuffer(); - if (staticBuffer != nullptr) - { - // Need to re-translate the static data if has never been used, or changed type. - *needsTranslation = - (staticBuffer->getBufferSize() == 0 || staticBuffer->getIndexType() != destElementType); - return IndexStorageType::Static; - } - - // Static buffer not available, fall back to streaming. - *needsTranslation = true; - return IndexStorageType::Dynamic; -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/renderer11_utils.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/renderer11_utils.h deleted file mode 100644 index 3af51bb0f6..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/renderer11_utils.h +++ /dev/null @@ -1,431 +0,0 @@ -// -// Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// renderer11_utils.h: Conversion functions and other utility routines -// specific to the D3D11 renderer. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_RENDERER11_UTILS_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_RENDERER11_UTILS_H_ - -#include <array> -#include <functional> -#include <vector> - -#include "common/Color.h" - -#include "libANGLE/Caps.h" -#include "libANGLE/Error.h" -#include "libANGLE/renderer/d3d/RendererD3D.h" -#include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h" -#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h" - -namespace gl -{ -class FramebufferAttachment; -} - -namespace rx -{ -class Renderer11; -class RenderTarget11; -struct Renderer11DeviceCaps; - -using RenderTargetArray = std::array<RenderTarget11 *, gl::IMPLEMENTATION_MAX_DRAW_BUFFERS>; -using RTVArray = std::array<ID3D11RenderTargetView *, gl::IMPLEMENTATION_MAX_DRAW_BUFFERS>; - -namespace gl_d3d11 -{ - -D3D11_BLEND ConvertBlendFunc(GLenum glBlend, bool isAlpha); -D3D11_BLEND_OP ConvertBlendOp(GLenum glBlendOp); -UINT8 ConvertColorMask(bool maskRed, bool maskGreen, bool maskBlue, bool maskAlpha); - -D3D11_CULL_MODE ConvertCullMode(bool cullEnabled, gl::CullFaceMode cullMode); - -D3D11_COMPARISON_FUNC ConvertComparison(GLenum comparison); -D3D11_DEPTH_WRITE_MASK ConvertDepthMask(bool depthWriteEnabled); -UINT8 ConvertStencilMask(GLuint stencilmask); -D3D11_STENCIL_OP ConvertStencilOp(GLenum stencilOp); - -D3D11_FILTER ConvertFilter(GLenum minFilter, GLenum magFilter, float maxAnisotropy, GLenum comparisonMode); -D3D11_TEXTURE_ADDRESS_MODE ConvertTextureWrap(GLenum wrap); -UINT ConvertMaxAnisotropy(float maxAnisotropy, D3D_FEATURE_LEVEL featureLevel); - -D3D11_QUERY ConvertQueryType(GLenum queryType); - -UINT8 GetColorMask(const gl::InternalFormat &formatInfo); - -} // namespace gl_d3d11 - -namespace d3d11_gl -{ - -unsigned int GetReservedVertexUniformVectors(D3D_FEATURE_LEVEL featureLevel); - -unsigned int GetReservedFragmentUniformVectors(D3D_FEATURE_LEVEL featureLevel); - -gl::Version GetMaximumClientVersion(D3D_FEATURE_LEVEL featureLevel); -void GenerateCaps(ID3D11Device *device, ID3D11DeviceContext *deviceContext, const Renderer11DeviceCaps &renderer11DeviceCaps, gl::Caps *caps, - gl::TextureCapsMap *textureCapsMap, gl::Extensions *extensions, gl::Limitations *limitations); - -void GetSamplePosition(GLsizei sampleCount, size_t index, GLfloat *xy); - -} // namespace d3d11_gl - -namespace d3d11 -{ - -enum ANGLED3D11DeviceType -{ - ANGLE_D3D11_DEVICE_TYPE_UNKNOWN, - ANGLE_D3D11_DEVICE_TYPE_HARDWARE, - ANGLE_D3D11_DEVICE_TYPE_SOFTWARE_REF_OR_NULL, - ANGLE_D3D11_DEVICE_TYPE_WARP, -}; - -ANGLED3D11DeviceType GetDeviceType(ID3D11Device *device); - -void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset); - -void GenerateInitialTextureData(GLint internalFormat, - const Renderer11DeviceCaps &renderer11DeviceCaps, - GLuint width, - GLuint height, - GLuint depth, - GLuint mipLevels, - std::vector<D3D11_SUBRESOURCE_DATA> *outSubresourceData, - std::vector<std::vector<BYTE>> *outData); - -UINT GetPrimitiveRestartIndex(); - -struct PositionTexCoordVertex -{ - float x, y; - float u, v; -}; -void SetPositionTexCoordVertex(PositionTexCoordVertex* vertex, float x, float y, float u, float v); - -struct PositionLayerTexCoord3DVertex -{ - float x, y; - unsigned int l; - float u, v, s; -}; -void SetPositionLayerTexCoord3DVertex(PositionLayerTexCoord3DVertex* vertex, float x, float y, - unsigned int layer, float u, float v, float s); - -struct PositionVertex -{ - float x, y, z, w; -}; - -struct BlendStateKey final -{ - // This will zero-initialize the struct, including padding. - BlendStateKey(); - - gl::BlendState blendState; - - // An int so struct size rounds nicely. - uint32_t rtvMax; - - uint8_t rtvMasks[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT]; -}; - -bool operator==(const BlendStateKey &a, const BlendStateKey &b); -bool operator!=(const BlendStateKey &a, const BlendStateKey &b); - -struct RasterizerStateKey final -{ - // This will zero-initialize the struct, including padding. - RasterizerStateKey(); - - gl::RasterizerState rasterizerState; - - // Use a 32-bit int to round the struct nicely. - uint32_t scissorEnabled; -}; - -bool operator==(const RasterizerStateKey &a, const RasterizerStateKey &b); -bool operator!=(const RasterizerStateKey &a, const RasterizerStateKey &b); - -template <typename outType> -outType* DynamicCastComObject(IUnknown* object) -{ - outType *outObject = nullptr; - HRESULT result = object->QueryInterface(__uuidof(outType), reinterpret_cast<void**>(&outObject)); - if (SUCCEEDED(result)) - { - return outObject; - } - else - { - SafeRelease(outObject); - return nullptr; - } -} - -inline bool isDeviceLostError(HRESULT errorCode) -{ - switch (errorCode) - { - case DXGI_ERROR_DEVICE_HUNG: - case DXGI_ERROR_DEVICE_REMOVED: - case DXGI_ERROR_DEVICE_RESET: - case DXGI_ERROR_DRIVER_INTERNAL_ERROR: - case DXGI_ERROR_NOT_CURRENTLY_AVAILABLE: - return true; - default: - return false; - } -} - -template <ResourceType ResourceT> -class LazyResource : angle::NonCopyable -{ - public: - constexpr LazyResource() : mResource() {} - virtual ~LazyResource() {} - - virtual gl::Error resolve(Renderer11 *renderer) = 0; - void reset() { mResource.reset(); } - GetD3D11Type<ResourceT> *get() const - { - ASSERT(mResource.valid()); - return mResource.get(); - } - - const Resource11<GetD3D11Type<ResourceT>> &getObj() const { return mResource; } - - protected: - LazyResource(LazyResource &&other) : mResource(std::move(other.mResource)) {} - - // Specialized in the cpp file to avoid MSVS/Clang specific code. - gl::Error resolveImpl(Renderer11 *renderer, - const GetDescType<ResourceT> &desc, - GetInitDataType<ResourceT> *initData, - const char *name); - - Resource11<GetD3D11Type<ResourceT>> mResource; -}; - -template <typename D3D11ShaderType> -class LazyShader final : public LazyResource<GetResourceTypeFromD3D11<D3D11ShaderType>()> -{ - public: - // All parameters must be constexpr. Not supported in VS2013. - constexpr LazyShader(const BYTE *byteCode, size_t byteCodeSize, const char *name) - : mByteCode(byteCode, byteCodeSize), mName(name) - { - } - - constexpr LazyShader(LazyShader &&shader) - : LazyResource<GetResourceTypeFromD3D11<D3D11ShaderType>()>(std::move(shader)), - mByteCode(std::move(shader.mByteCode)), - mName(shader.mName) - { - } - - gl::Error resolve(Renderer11 *renderer) override - { - return this->resolveImpl(renderer, mByteCode, nullptr, mName); - } - - private: - ShaderData mByteCode; - const char *mName; -}; - -class LazyInputLayout final : public LazyResource<ResourceType::InputLayout> -{ - public: - LazyInputLayout(const D3D11_INPUT_ELEMENT_DESC *inputDesc, - size_t inputDescLen, - const BYTE *byteCode, - size_t byteCodeLen, - const char *debugName); - ~LazyInputLayout() override; - - gl::Error resolve(Renderer11 *renderer) override; - - private: - InputElementArray mInputDesc; - ShaderData mByteCode; - const char *mDebugName; -}; - -class LazyBlendState final : public LazyResource<ResourceType::BlendState> -{ - public: - LazyBlendState(const D3D11_BLEND_DESC &desc, const char *debugName); - - gl::Error resolve(Renderer11 *renderer) override; - - private: - D3D11_BLEND_DESC mDesc; - const char *mDebugName; -}; - -// Copy data to small D3D11 buffers, such as for small constant buffers, which use one struct to -// represent an entire buffer. -template <class T> -void SetBufferData(ID3D11DeviceContext *context, ID3D11Buffer *constantBuffer, const T &value) -{ - D3D11_MAPPED_SUBRESOURCE mappedResource = {}; - HRESULT result = context->Map(constantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - ASSERT(SUCCEEDED(result)); - if (SUCCEEDED(result)) - { - memcpy(mappedResource.pData, &value, sizeof(T)); - context->Unmap(constantBuffer, 0); - } -} - -angle::WorkaroundsD3D GenerateWorkarounds(const Renderer11DeviceCaps &deviceCaps, - const DXGI_ADAPTER_DESC &adapterDesc); - -enum ReservedConstantBufferSlot -{ - RESERVED_CONSTANT_BUFFER_SLOT_DEFAULT_UNIFORM_BLOCK = 0, - RESERVED_CONSTANT_BUFFER_SLOT_DRIVER = 1, - - RESERVED_CONSTANT_BUFFER_SLOT_COUNT = 2 -}; - -void InitConstantBufferDesc(D3D11_BUFFER_DESC *constantBufferDescription, size_t byteWidth); -} // namespace d3d11 - -struct GenericData -{ - GenericData() {} - ~GenericData() - { - if (object) - { - // We can have a nullptr factory when holding passed-in resources. - if (manager) - { - manager->onReleaseGeneric(resourceType, object); - manager = nullptr; - } - object->Release(); - object = nullptr; - } - } - - ResourceType resourceType = ResourceType::Last; - ID3D11Resource *object = nullptr; - ResourceManager11 *manager = nullptr; -}; - -// A helper class which wraps a 2D or 3D texture. -class TextureHelper11 : public Resource11Base<ID3D11Resource, std::shared_ptr, GenericData> -{ - public: - TextureHelper11(); - TextureHelper11(TextureHelper11 &&other); - TextureHelper11(const TextureHelper11 &other); - ~TextureHelper11() override; - TextureHelper11 &operator=(TextureHelper11 &&other); - TextureHelper11 &operator=(const TextureHelper11 &other); - - bool is2D() const { return mData->resourceType == ResourceType::Texture2D; } - bool is3D() const { return mData->resourceType == ResourceType::Texture3D; } - ResourceType getTextureType() const { return mData->resourceType; } - gl::Extents getExtents() const { return mExtents; } - DXGI_FORMAT getFormat() const { return mFormatSet->texFormat; } - const d3d11::Format &getFormatSet() const { return *mFormatSet; } - int getSampleCount() const { return mSampleCount; } - - template <typename DescT, typename ResourceT> - void init(Resource11<ResourceT> &&texture, const DescT &desc, const d3d11::Format &format) - { - std::swap(mData->manager, texture.mData->manager); - - // Can't use std::swap because texture is typed, and here we use ID3D11Resource. - ID3D11Resource *temp = mData->object; - mData->object = texture.mData->object; - texture.mData->object = static_cast<ResourceT *>(temp); - - mFormatSet = &format; - initDesc(desc); - } - - template <typename ResourceT> - void set(ResourceT *object, const d3d11::Format &format) - { - ASSERT(!valid()); - mFormatSet = &format; - mData->object = object; - mData->manager = nullptr; - - GetDescFromD3D11<ResourceT> desc; - getDesc(&desc); - initDesc(desc); - } - - bool operator==(const TextureHelper11 &other) const; - bool operator!=(const TextureHelper11 &other) const; - - void getDesc(D3D11_TEXTURE2D_DESC *desc) const; - void getDesc(D3D11_TEXTURE3D_DESC *desc) const; - - private: - void initDesc(const D3D11_TEXTURE2D_DESC &desc2D); - void initDesc(const D3D11_TEXTURE3D_DESC &desc3D); - - const d3d11::Format *mFormatSet; - gl::Extents mExtents; - int mSampleCount; -}; - -enum class StagingAccess -{ - READ, - READ_WRITE, -}; - -bool UsePresentPathFast(const Renderer11 *renderer, const gl::FramebufferAttachment *colorbuffer); -bool UsePrimitiveRestartWorkaround(bool primitiveRestartFixedIndexEnabled, GLenum type); -bool IsStreamingIndexData(const gl::Context *context, GLenum srcType); - -enum class IndexStorageType -{ - // Dynamic indexes are re-streamed every frame. They come from a client data pointer or - // from buffers that are updated frequently. - Dynamic, - - // Static indexes are translated from the original storage once, and re-used multiple times. - Static, - - // Direct indexes are never transated and are used directly from the source buffer. They are - // the fastest available path. - Direct, - - // Not a real storage type. - Invalid, -}; - -IndexStorageType ClassifyIndexStorage(const gl::State &glState, - const gl::Buffer *elementArrayBuffer, - GLenum elementType, - GLenum destElementType, - unsigned int offset, - bool *needsTranslation); - -// Used for state change notifications between buffers and vertex arrays. -using OnBufferDataDirtyBinding = angle::ChannelBinding<size_t, const gl::Context *>; -using OnBufferDataDirtyChannel = angle::BroadcastChannel<size_t, const gl::Context *>; -using OnBufferDataDirtyReceiver = angle::SignalReceiver<size_t, const gl::Context *>; - -// Used for state change notifications between RenderTarget11 and Framebuffer11. -using OnRenderTargetDirtyBinding = angle::ChannelBinding<size_t, const gl::Context *>; -using OnRenderTargetDirtyChannel = angle::BroadcastChannel<size_t, const gl::Context *>; -using OnRenderTargetDirtyReceiver = angle::SignalReceiver<size_t, const gl::Context *>; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_RENDERER11_UTILS_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/BufferToTexture11.hlsl b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/BufferToTexture11.hlsl deleted file mode 100644 index c43734f6a3..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/BufferToTexture11.hlsl +++ /dev/null @@ -1,77 +0,0 @@ -Buffer<float4> Buffer4F : register(t0); -Buffer<int4> Buffer4I : register(t0); -Buffer<uint4> Buffer4UI : register(t0); - -struct VS_OUTPUT -{ - float4 position : SV_Position; - uint index : TEXCOORD0; - uint slice : LAYER; -}; - -struct GS_OUTPUT -{ - float4 position : SV_Position; - uint index : TEXCOORD0; - uint slice : SV_RenderTargetArrayIndex; -}; - -cbuffer BufferCopyParams : register(b0) -{ - uint FirstPixelOffset; - uint PixelsPerRow; - uint RowStride; - uint RowsPerSlice; - float2 PositionOffset; - float2 PositionScale; - int2 TexLocationOffset; - int2 TexLocationScale; - uint FirstSlice; -} - -void ComputePositionAndIndex(uint vertexID, out VS_OUTPUT outVertex) -{ - uint PixelsPerSlice = PixelsPerRow * RowsPerSlice; - uint SliceStride = RowStride * RowsPerSlice; - - uint slice = vertexID / PixelsPerSlice; - uint sliceOffset = slice * PixelsPerSlice; - uint row = (vertexID - sliceOffset) / PixelsPerRow; - uint col = vertexID - sliceOffset - (row * PixelsPerRow); - - float2 coords = float2(float(col), float(row)); - - outVertex.position = float4(PositionOffset + PositionScale * coords, 0.0f, 1.0f); - outVertex.index = FirstPixelOffset + slice * SliceStride + row * RowStride + col; - outVertex.slice = FirstSlice + slice; -} - -void VS_BufferToTexture(in uint vertexID : SV_VertexID, out VS_OUTPUT outVertex) -{ - ComputePositionAndIndex(vertexID, outVertex); -} - -[maxvertexcount(1)] -void GS_BufferToTexture(point VS_OUTPUT inVertex[1], inout PointStream<GS_OUTPUT> outStream) -{ - GS_OUTPUT outVertex; - outVertex.position = inVertex[0].position; - outVertex.index = inVertex[0].index; - outVertex.slice = inVertex[0].slice; - outStream.Append(outVertex); -} - -float4 PS_BufferToTexture_4F(in float4 inPosition : SV_Position, in uint inIndex : TEXCOORD0) : SV_Target -{ - return Buffer4F.Load(inIndex); -} - -int4 PS_BufferToTexture_4I(in float4 inPosition : SV_Position, in uint inIndex : TEXCOORD0) : SV_Target -{ - return Buffer4I.Load(inIndex); -} - -uint4 PS_BufferToTexture_4UI(in float4 inPosition : SV_Position, in uint inIndex : TEXCOORD0) : SV_Target -{ - return Buffer4UI.Load(inIndex); -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/Clear11.hlsl b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/Clear11.hlsl deleted file mode 100644 index 48f5b427ec..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/Clear11.hlsl +++ /dev/null @@ -1,635 +0,0 @@ -// -// Copyright (c) 2017 The ANGLE Project. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// Clear11.hlsl: Shaders for clearing RTVs and DSVs using draw calls and -// specifying float depth values and either float, uint or sint clear colors. -// Notes: -// - UINT & SINT clears can only be compiled with FL10+ -// - VS_Clear_FL9 requires a VB to be bound with vertices to create -// a primitive covering the entire surface (in clip co-ordinates) - -// Constants -static const float2 g_Corners[6] = -{ - float2(-1.0f, 1.0f), - float2( 1.0f, -1.0f), - float2(-1.0f, -1.0f), - float2(-1.0f, 1.0f), - float2( 1.0f, 1.0f), - float2( 1.0f, -1.0f), -}; - -// Vertex Shaders -void VS_Clear(in uint id : SV_VertexID, - out float4 outPosition : SV_POSITION) -{ - float2 corner = g_Corners[id]; - outPosition = float4(corner.x, corner.y, 0.0f, 1.0f); -} - -void VS_Multiview_Clear(in uint id : SV_VertexID, - in uint instanceID : SV_InstanceID, - out float4 outPosition : SV_POSITION, - out uint outLayerID : TEXCOORD0) -{ - float2 corner = g_Corners[id]; - outPosition = float4(corner.x, corner.y, 0.0f, 1.0f); - outLayerID = instanceID; -} - -void VS_Clear_FL9( in float4 inPosition : POSITION, - out float4 outPosition : SV_POSITION) -{ - outPosition = inPosition; -} - -// Geometry shader for clearing multiview layered textures -struct GS_INPUT -{ - float4 inPosition : SV_Position; - uint inLayerID : TEXCOORD0; -}; - -struct GS_OUTPUT -{ - float4 outPosition : SV_Position; - uint outLayerID : SV_RenderTargetArrayIndex; -}; - -[maxvertexcount(3)] -void GS_Multiview_Clear(triangle GS_INPUT input[3], inout TriangleStream<GS_OUTPUT> outStream) -{ - GS_OUTPUT output = (GS_OUTPUT)0; - for (int i = 0; i < 3; i++) - { - output.outPosition = input[i].inPosition; - output.outLayerID = input[i].inLayerID; - outStream.Append(output); - } - outStream.RestartStrip(); -} - -// Pixel Shader Constant Buffers -cbuffer ColorAndDepthDataFloat : register(b0) -{ - float4 color_Float : packoffset(c0); - float zValueF_Float : packoffset(c1); -} - -cbuffer ColorAndDepthDataSint : register(b0) -{ - int4 color_Sint : packoffset(c0); - float zValueF_Sint : packoffset(c1); -} - -cbuffer ColorAndDepthDataUint : register(b0) -{ - uint4 color_Uint : packoffset(c0); - float zValueF_Uint : packoffset(c1); -} - -cbuffer DepthOnlyData : register(b0) -{ - float zValue_Depth : packoffset(c1); -} - -// Pixel Shader Output Structs -struct PS_OutputFloat_FL9 -{ - float4 color0 : SV_TARGET0; - float4 color1 : SV_TARGET1; - float4 color2 : SV_TARGET2; - float4 color3 : SV_TARGET3; - float depth : SV_DEPTH; -}; - -struct PS_OutputFloat1 -{ - float4 color0 : SV_TARGET0; - float depth : SV_DEPTH; -}; - -struct PS_OutputFloat2 -{ - float4 color0 : SV_TARGET0; - float4 color1 : SV_TARGET1; - float depth : SV_DEPTH; -}; - -struct PS_OutputFloat3 -{ - float4 color0 : SV_TARGET0; - float4 color1 : SV_TARGET1; - float4 color2 : SV_TARGET2; - float depth : SV_DEPTH; -}; - -struct PS_OutputFloat4 -{ - float4 color0 : SV_TARGET0; - float4 color1 : SV_TARGET1; - float4 color2 : SV_TARGET2; - float4 color3 : SV_TARGET3; - float depth : SV_DEPTH; -}; - -struct PS_OutputFloat5 -{ - float4 color0 : SV_TARGET0; - float4 color1 : SV_TARGET1; - float4 color2 : SV_TARGET2; - float4 color3 : SV_TARGET3; - float4 color4 : SV_TARGET4; - float depth : SV_DEPTH; -}; - -struct PS_OutputFloat6 -{ - float4 color0 : SV_TARGET0; - float4 color1 : SV_TARGET1; - float4 color2 : SV_TARGET2; - float4 color3 : SV_TARGET3; - float4 color4 : SV_TARGET4; - float4 color5 : SV_TARGET5; - float depth : SV_DEPTH; -}; - -struct PS_OutputFloat7 -{ - float4 color0 : SV_TARGET0; - float4 color1 : SV_TARGET1; - float4 color2 : SV_TARGET2; - float4 color3 : SV_TARGET3; - float4 color4 : SV_TARGET4; - float4 color5 : SV_TARGET5; - float4 color6 : SV_TARGET6; - float depth : SV_DEPTH; -}; - -struct PS_OutputFloat8 -{ - float4 color0 : SV_TARGET0; - float4 color1 : SV_TARGET1; - float4 color2 : SV_TARGET2; - float4 color3 : SV_TARGET3; - float4 color4 : SV_TARGET4; - float4 color5 : SV_TARGET5; - float4 color6 : SV_TARGET6; - float4 color7 : SV_TARGET7; - float depth : SV_DEPTH; -}; - -struct PS_OutputUint1 -{ - uint4 color0 : SV_TARGET0; - float depth : SV_DEPTH; -}; - -struct PS_OutputUint2 -{ - uint4 color0 : SV_TARGET0; - uint4 color1 : SV_TARGET1; - float depth : SV_DEPTH; -}; - -struct PS_OutputUint3 -{ - uint4 color0 : SV_TARGET0; - uint4 color1 : SV_TARGET1; - uint4 color2 : SV_TARGET2; - float depth : SV_DEPTH; -}; - -struct PS_OutputUint4 -{ - uint4 color0 : SV_TARGET0; - uint4 color1 : SV_TARGET1; - uint4 color2 : SV_TARGET2; - uint4 color3 : SV_TARGET3; - float depth : SV_DEPTH; -}; - -struct PS_OutputUint5 -{ - uint4 color0 : SV_TARGET0; - uint4 color1 : SV_TARGET1; - uint4 color2 : SV_TARGET2; - uint4 color3 : SV_TARGET3; - uint4 color4 : SV_TARGET4; - float depth : SV_DEPTH; -}; - -struct PS_OutputUint6 -{ - uint4 color0 : SV_TARGET0; - uint4 color1 : SV_TARGET1; - uint4 color2 : SV_TARGET2; - uint4 color3 : SV_TARGET3; - uint4 color4 : SV_TARGET4; - uint4 color5 : SV_TARGET5; - float depth : SV_DEPTH; -}; - -struct PS_OutputUint7 -{ - uint4 color0 : SV_TARGET0; - uint4 color1 : SV_TARGET1; - uint4 color2 : SV_TARGET2; - uint4 color3 : SV_TARGET3; - uint4 color4 : SV_TARGET4; - uint4 color5 : SV_TARGET5; - uint4 color6 : SV_TARGET6; - float depth : SV_DEPTH; -}; - -struct PS_OutputUint8 -{ - uint4 color0 : SV_TARGET0; - uint4 color1 : SV_TARGET1; - uint4 color2 : SV_TARGET2; - uint4 color3 : SV_TARGET3; - uint4 color4 : SV_TARGET4; - uint4 color5 : SV_TARGET5; - uint4 color6 : SV_TARGET6; - uint4 color7 : SV_TARGET7; - float depth : SV_DEPTH; -}; - -struct PS_OutputSint1 -{ - int4 color0 : SV_TARGET0; - float depth : SV_DEPTH; -}; - -struct PS_OutputSint2 -{ - int4 color0 : SV_TARGET0; - int4 color1 : SV_TARGET1; - float depth : SV_DEPTH; -}; - -struct PS_OutputSint3 -{ - int4 color0 : SV_TARGET0; - int4 color1 : SV_TARGET1; - int4 color2 : SV_TARGET2; - float depth : SV_DEPTH; -}; - -struct PS_OutputSint4 -{ - int4 color0 : SV_TARGET0; - int4 color1 : SV_TARGET1; - int4 color2 : SV_TARGET2; - int4 color3 : SV_TARGET3; - float depth : SV_DEPTH; -}; - -struct PS_OutputSint5 -{ - int4 color0 : SV_TARGET0; - int4 color1 : SV_TARGET1; - int4 color2 : SV_TARGET2; - int4 color3 : SV_TARGET3; - int4 color4 : SV_TARGET4; - float depth : SV_DEPTH; -}; - -struct PS_OutputSint6 -{ - int4 color0 : SV_TARGET0; - int4 color1 : SV_TARGET1; - int4 color2 : SV_TARGET2; - int4 color3 : SV_TARGET3; - int4 color4 : SV_TARGET4; - int4 color5 : SV_TARGET5; - float depth : SV_DEPTH; -}; - -struct PS_OutputSint7 -{ - int4 color0 : SV_TARGET0; - int4 color1 : SV_TARGET1; - int4 color2 : SV_TARGET2; - int4 color3 : SV_TARGET3; - int4 color4 : SV_TARGET4; - int4 color5 : SV_TARGET5; - int4 color6 : SV_TARGET6; - float depth : SV_DEPTH; -}; - -struct PS_OutputSint8 -{ - int4 color0 : SV_TARGET0; - int4 color1 : SV_TARGET1; - int4 color2 : SV_TARGET2; - int4 color3 : SV_TARGET3; - int4 color4 : SV_TARGET4; - int4 color5 : SV_TARGET5; - int4 color6 : SV_TARGET6; - int4 color7 : SV_TARGET7; - float depth : SV_DEPTH; -}; - -struct PS_OutputDepth -{ - float depth : SV_DEPTH; -}; - -// Pixel Shaders -PS_OutputFloat_FL9 PS_ClearFloat_FL9(in float4 inPosition : SV_POSITION) -{ - PS_OutputFloat_FL9 outData; - outData.color0 = color_Float; - outData.color1 = color_Float; - outData.color2 = color_Float; - outData.color3 = color_Float; - outData.depth = zValueF_Float; - return outData; -} - -PS_OutputFloat1 PS_ClearFloat1(in float4 inPosition : SV_POSITION) -{ - PS_OutputFloat1 outData; - outData.color0 = color_Float; - outData.depth = zValueF_Float; - return outData; -} - -PS_OutputFloat2 PS_ClearFloat2(in float4 inPosition : SV_POSITION) -{ - PS_OutputFloat2 outData; - outData.color0 = color_Float; - outData.color1 = color_Float; - outData.depth = zValueF_Float; - return outData; -} - -PS_OutputFloat3 PS_ClearFloat3(in float4 inPosition : SV_POSITION) -{ - PS_OutputFloat3 outData; - outData.color0 = color_Float; - outData.color1 = color_Float; - outData.color2 = color_Float; - outData.depth = zValueF_Float; - return outData; -} - -PS_OutputFloat4 PS_ClearFloat4(in float4 inPosition : SV_POSITION) -{ - PS_OutputFloat4 outData; - outData.color0 = color_Float; - outData.color1 = color_Float; - outData.color2 = color_Float; - outData.color3 = color_Float; - outData.depth = zValueF_Float; - return outData; -} - -PS_OutputFloat5 PS_ClearFloat5(in float4 inPosition : SV_POSITION) -{ - PS_OutputFloat5 outData; - outData.color0 = color_Float; - outData.color1 = color_Float; - outData.color2 = color_Float; - outData.color3 = color_Float; - outData.color4 = color_Float; - outData.depth = zValueF_Float; - return outData; -} - -PS_OutputFloat6 PS_ClearFloat6(in float4 inPosition : SV_POSITION) -{ - PS_OutputFloat6 outData; - outData.color0 = color_Float; - outData.color1 = color_Float; - outData.color2 = color_Float; - outData.color3 = color_Float; - outData.color4 = color_Float; - outData.color5 = color_Float; - outData.depth = zValueF_Float; - return outData; -} - -PS_OutputFloat7 PS_ClearFloat7(in float4 inPosition : SV_POSITION) -{ - PS_OutputFloat7 outData; - outData.color0 = color_Float; - outData.color1 = color_Float; - outData.color2 = color_Float; - outData.color3 = color_Float; - outData.color4 = color_Float; - outData.color5 = color_Float; - outData.color6 = color_Float; - outData.depth = zValueF_Float; - return outData; -} - -PS_OutputFloat8 PS_ClearFloat8(in float4 inPosition : SV_POSITION) -{ - PS_OutputFloat8 outData; - outData.color0 = color_Float; - outData.color1 = color_Float; - outData.color2 = color_Float; - outData.color3 = color_Float; - outData.color4 = color_Float; - outData.color5 = color_Float; - outData.color6 = color_Float; - outData.color7 = color_Float; - outData.depth = zValueF_Float; - return outData; -} - -PS_OutputUint1 PS_ClearUint1(in float4 inPosition : SV_POSITION) -{ - PS_OutputUint1 outData; - outData.color0 = color_Uint; - outData.depth = zValueF_Uint; - return outData; -} - -PS_OutputUint2 PS_ClearUint2(in float4 inPosition : SV_POSITION) -{ - PS_OutputUint2 outData; - outData.color0 = color_Uint; - outData.color1 = color_Uint; - outData.depth = zValueF_Uint; - return outData; -} - -PS_OutputUint3 PS_ClearUint3(in float4 inPosition : SV_POSITION) -{ - PS_OutputUint3 outData; - outData.color0 = color_Uint; - outData.color1 = color_Uint; - outData.color2 = color_Uint; - outData.depth = zValueF_Uint; - return outData; -} - -PS_OutputUint4 PS_ClearUint4(in float4 inPosition : SV_POSITION) -{ - PS_OutputUint4 outData; - outData.color0 = color_Uint; - outData.color1 = color_Uint; - outData.color2 = color_Uint; - outData.color3 = color_Uint; - outData.depth = zValueF_Uint; - return outData; -} - -PS_OutputUint5 PS_ClearUint5(in float4 inPosition : SV_POSITION) -{ - PS_OutputUint5 outData; - outData.color0 = color_Uint; - outData.color1 = color_Uint; - outData.color2 = color_Uint; - outData.color3 = color_Uint; - outData.color4 = color_Uint; - outData.depth = zValueF_Uint; - return outData; -} - -PS_OutputUint6 PS_ClearUint6(in float4 inPosition : SV_POSITION) -{ - PS_OutputUint6 outData; - outData.color0 = color_Uint; - outData.color1 = color_Uint; - outData.color2 = color_Uint; - outData.color3 = color_Uint; - outData.color4 = color_Uint; - outData.color5 = color_Uint; - outData.depth = zValueF_Uint; - return outData; -} - -PS_OutputUint7 PS_ClearUint7(in float4 inPosition : SV_POSITION) -{ - PS_OutputUint7 outData; - outData.color0 = color_Uint; - outData.color1 = color_Uint; - outData.color2 = color_Uint; - outData.color3 = color_Uint; - outData.color4 = color_Uint; - outData.color5 = color_Uint; - outData.color6 = color_Uint; - outData.depth = zValueF_Uint; - return outData; -} - -PS_OutputUint8 PS_ClearUint8(in float4 inPosition : SV_POSITION) -{ - PS_OutputUint8 outData; - outData.color0 = color_Uint; - outData.color1 = color_Uint; - outData.color2 = color_Uint; - outData.color3 = color_Uint; - outData.color4 = color_Uint; - outData.color5 = color_Uint; - outData.color6 = color_Uint; - outData.color7 = color_Uint; - outData.depth = zValueF_Uint; - return outData; -} - -PS_OutputSint1 PS_ClearSint1(in float4 inPosition : SV_POSITION) -{ - PS_OutputSint1 outData; - outData.color0 = color_Sint; - outData.depth = zValueF_Sint; - return outData; -} - -PS_OutputSint2 PS_ClearSint2(in float4 inPosition : SV_POSITION) -{ - PS_OutputSint2 outData; - outData.color0 = color_Sint; - outData.color1 = color_Sint; - outData.depth = zValueF_Sint; - return outData; -} - -PS_OutputSint3 PS_ClearSint3(in float4 inPosition : SV_POSITION) -{ - PS_OutputSint3 outData; - outData.color0 = color_Sint; - outData.color1 = color_Sint; - outData.color2 = color_Sint; - outData.depth = zValueF_Sint; - return outData; -} - -PS_OutputSint4 PS_ClearSint4(in float4 inPosition : SV_POSITION) -{ - PS_OutputSint4 outData; - outData.color0 = color_Sint; - outData.color1 = color_Sint; - outData.color2 = color_Sint; - outData.color3 = color_Sint; - outData.depth = zValueF_Sint; - return outData; -} - -PS_OutputSint5 PS_ClearSint5(in float4 inPosition : SV_POSITION) -{ - PS_OutputSint5 outData; - outData.color0 = color_Sint; - outData.color1 = color_Sint; - outData.color2 = color_Sint; - outData.color3 = color_Sint; - outData.color4 = color_Sint; - outData.depth = zValueF_Sint; - return outData; -} - -PS_OutputSint6 PS_ClearSint6(in float4 inPosition : SV_POSITION) -{ - PS_OutputSint6 outData; - outData.color0 = color_Sint; - outData.color1 = color_Sint; - outData.color2 = color_Sint; - outData.color3 = color_Sint; - outData.color4 = color_Sint; - outData.color5 = color_Sint; - outData.depth = zValueF_Sint; - return outData; -} - -PS_OutputSint7 PS_ClearSint7(in float4 inPosition : SV_POSITION) -{ - PS_OutputSint7 outData; - outData.color0 = color_Sint; - outData.color1 = color_Sint; - outData.color2 = color_Sint; - outData.color3 = color_Sint; - outData.color4 = color_Sint; - outData.color5 = color_Sint; - outData.color6 = color_Sint; - outData.depth = zValueF_Sint; - return outData; -} - -PS_OutputSint8 PS_ClearSint8(in float4 inPosition : SV_POSITION) -{ - PS_OutputSint8 outData; - outData.color0 = color_Sint; - outData.color1 = color_Sint; - outData.color2 = color_Sint; - outData.color3 = color_Sint; - outData.color4 = color_Sint; - outData.color5 = color_Sint; - outData.color6 = color_Sint; - outData.color7 = color_Sint; - outData.depth = zValueF_Sint; - return outData; -} - -PS_OutputDepth PS_ClearDepth(in float4 inPosition : SV_POSITION) -{ - PS_OutputDepth outData; - outData.depth = zValue_Depth; - return outData; -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/MultiplyAlpha.hlsl b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/MultiplyAlpha.hlsl deleted file mode 100644 index 0d10b8eafa..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/MultiplyAlpha.hlsl +++ /dev/null @@ -1,131 +0,0 @@ -Texture2D<float4> TextureF : register(t0); -Texture2D<uint4> TextureUI : register(t0); - -SamplerState Sampler : register(s0); - -// Notation: -// PM: premultiply, UM: unmulitply, PT: passthrough -// F: float, U: uint - -// Float to float LUMA -float4 PS_FtoF_PM_LUMA(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - float4 color = TextureF.Sample(Sampler, inTexCoord).rgba; - color.rgb = color.r * color.a; - color.a = 1.0f; - return color; -} -float4 PS_FtoF_UM_LUMA(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - float4 color = TextureF.Sample(Sampler, inTexCoord).rgba; - if (color.a > 0.0f) - { - color.rgb = color.r / color.a; - } - color.a = 1.0f; - return color; -} - -// Float to float LUMAALPHA -float4 PS_FtoF_PM_LUMAALPHA(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - float4 color = TextureF.Sample(Sampler, inTexCoord).rgba; - color.rgb = color.r * color.a; - return color; -} - -float4 PS_FtoF_UM_LUMAALPHA(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - float4 color = TextureF.Sample(Sampler, inTexCoord).rgba; - if (color.a > 0.0f) - { - color.rgb = color.r / color.a; - } - return color; -} - -// Float to float RGBA -float4 PS_FtoF_PM_RGBA(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - float4 color = TextureF.Sample(Sampler, inTexCoord).rgba; - color.rgb *= color.a; - return color; -} - -float4 PS_FtoF_UM_RGBA(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - float4 color = TextureF.Sample(Sampler, inTexCoord).rgba; - if (color.a > 0.0f) - { - color.rgb /= color.a; - } - return color; -} - -// Float to float RGB -float4 PS_FtoF_PM_RGB(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - float4 color = TextureF.Sample(Sampler, inTexCoord).rgba; - color.rgb *= color.a; - color.a = 1.0f; - return color; -} - -float4 PS_FtoF_UM_RGB(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - float4 color = TextureF.Sample(Sampler, inTexCoord).rgba; - if (color.a > 0.0f) - { - color.rgb /= color.a; - } - color.a = 1.0f; - return color; -} - -// Float to uint RGBA -uint4 PS_FtoU_PT_RGBA(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - float4 color = TextureF.Sample(Sampler, inTexCoord).rgba; - return uint4(color * 255); -} - -uint4 PS_FtoU_PM_RGBA(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - float4 color = TextureF.Sample(Sampler, inTexCoord).rgba; - color.rgb *= color.a; - return uint4(color * 255); -} - -uint4 PS_FtoU_UM_RGBA(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - float4 color = TextureF.Sample(Sampler, inTexCoord).rgba; - if (color.a > 0.0f) - { - color.rgb /= color.a; - } - return uint4(color * 255); -} - -// Float to uint RGB -uint4 PS_FtoU_PT_RGB(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - float4 color = TextureF.Sample(Sampler, inTexCoord).rgba; - return uint4(color.rgb * 255, 1); -} - -uint4 PS_FtoU_PM_RGB(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - float4 color = TextureF.Sample(Sampler, inTexCoord).rgba; - color.rgb *= color.a; - return uint4(color.rgb * 255, 1); -} - -uint4 PS_FtoU_UM_RGB(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - float4 color = TextureF.Sample(Sampler, inTexCoord).rgba; - if (color.a > 0.0f) - { - color.rgb /= color.a; - } - return uint4(color.rgb * 255, 1); -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/Passthrough2D11.hlsl b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/Passthrough2D11.hlsl deleted file mode 100644 index 0b1a5ad169..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/Passthrough2D11.hlsl +++ /dev/null @@ -1,122 +0,0 @@ -Texture2D<float4> TextureF : register(t0); -Texture2DMS<float4> TextureF_MS: register(t0); -Texture2D<uint4> TextureUI : register(t0); -Texture2D<int4> TextureI : register(t0); - -SamplerState Sampler : register(s0); - -void VS_Passthrough2D( in float2 inPosition : POSITION, in float2 inTexCoord : TEXCOORD0, - out float4 outPosition : SV_POSITION, out float2 outTexCoord : TEXCOORD0) -{ - outPosition = float4(inPosition, 0.0f, 1.0f); - outTexCoord = inTexCoord; -} - -float PS_PassthroughDepth2D(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_DEPTH -{ - return TextureF.Sample(Sampler, inTexCoord).r; -} - -float4 PS_PassthroughRGBA2D(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - return TextureF.Sample(Sampler, inTexCoord).rgba; -} - -float4 PS_PassthroughA2D(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - return float4(0.0f, 0.0f, 0.0f, TextureF.Sample(Sampler, inTexCoord).a); -} - -float4 PS_PassthroughRGBA2DMS(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCORD0, in uint inSampleIndex : SV_SAMPLEINDEX) : SV_TARGET0 -{ - return TextureF_MS.sample[inSampleIndex][inTexCoord].rgba; -} - -uint4 PS_PassthroughRGBA2DUI(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - uint2 size; - TextureUI.GetDimensions(size.x, size.y); - - return TextureUI.Load(int3(size * inTexCoord, 0)).rgba; -} - -int4 PS_PassthroughRGBA2DI(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - uint2 size; - TextureI.GetDimensions(size.x, size.y); - - return TextureI.Load(int3(size * inTexCoord, 0)).rgba; -} - -float4 PS_PassthroughRGB2D(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - return float4(TextureF.Sample(Sampler, inTexCoord).rgb, 1.0f); -} - -uint4 PS_PassthroughRGB2DUI(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - uint2 size; - TextureUI.GetDimensions(size.x, size.y); - - return uint4(TextureUI.Load(int3(size * inTexCoord, 0)).rgb, 0); -} - -int4 PS_PassthroughRGB2DI(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - uint2 size; - TextureI.GetDimensions(size.x, size.y); - - return int4(TextureI.Load(int3(size * inTexCoord, 0)).rgb, 0); -} - -float4 PS_PassthroughRG2D(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - return float4(TextureF.Sample(Sampler, inTexCoord).rg, 0.0f, 1.0f); -} - -uint4 PS_PassthroughRG2DUI(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - uint2 size; - TextureUI.GetDimensions(size.x, size.y); - - return uint4(TextureUI.Load(int3(size * inTexCoord, 0)).rg, 0, 0); -} - -int4 PS_PassthroughRG2DI(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - uint2 size; - TextureI.GetDimensions(size.x, size.y); - - return int4(TextureI.Load(int3(size * inTexCoord, 0)).rg, 0, 0); -} - -float4 PS_PassthroughR2D(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - return float4(TextureF.Sample(Sampler, inTexCoord).r, 0.0f, 0.0f, 1.0f); -} - -uint4 PS_PassthroughR2DUI(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - uint2 size; - TextureUI.GetDimensions(size.x, size.y); - - return uint4(TextureUI.Load(int3(size * inTexCoord, 0)).r, 0, 0, 0); -} - -int4 PS_PassthroughR2DI(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - uint2 size; - TextureI.GetDimensions(size.x, size.y); - - return int4(TextureI.Load(int3(size * inTexCoord, 0)).r, 0, 0, 0); -} - -float4 PS_PassthroughLum2D(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - return float4(TextureF.Sample(Sampler, inTexCoord).rrr, 1.0f); -} - -float4 PS_PassthroughLumAlpha2D(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - return TextureF.Sample(Sampler, inTexCoord).rrra; -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/Passthrough3D11.hlsl b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/Passthrough3D11.hlsl deleted file mode 100644 index c23c9032ec..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/Passthrough3D11.hlsl +++ /dev/null @@ -1,146 +0,0 @@ -Texture3D<float4> TextureF : register(t0); -Texture3D<uint4> TextureUI : register(t0); -Texture3D<int4> TextureI : register(t0); - -SamplerState Sampler : register(s0); - -struct VS_INPUT -{ - float2 Position : POSITION; - uint Layer : LAYER; - float3 TexCoord : TEXCOORD; -}; - -struct VS_OUTPUT -{ - float4 Position : SV_POSITION; - uint Layer : LAYER; - float3 TexCoord : TEXCOORD; -}; - -struct GS_OUTPUT -{ - float4 Position : SV_POSITION; - uint Layer : SV_RENDERTARGETARRAYINDEX; - float3 TexCoord : TEXCOORD; -}; - -VS_OUTPUT VS_Passthrough3D(VS_INPUT input) -{ - VS_OUTPUT output; - - output.Position = float4(input.Position, 0.0f, 1.0f); - output.Layer = input.Layer; - output.TexCoord = input.TexCoord; - - return output; -} - -[maxvertexcount(3)] -void GS_Passthrough3D(triangle VS_OUTPUT input[3], inout TriangleStream<GS_OUTPUT> outputStream) -{ - GS_OUTPUT output; - - for (int i = 0; i < 3; i++) - { - output.Position = input[i].Position; - output.Layer = input[i].Layer; - output.TexCoord = input[i].TexCoord; - - outputStream.Append(output); - } -} - -float4 PS_PassthroughRGBA3D(GS_OUTPUT input) : SV_TARGET0 -{ - return TextureF.Sample(Sampler, input.TexCoord).rgba; -} - -uint4 PS_PassthroughRGBA3DUI(GS_OUTPUT input) : SV_TARGET0 -{ - uint3 size; - TextureUI.GetDimensions(size.x, size.y, size.z); - - return TextureUI.Load(int4(size * input.TexCoord, 0)).rgba; -} - -int4 PS_PassthroughRGBA3DI(GS_OUTPUT input) : SV_TARGET0 -{ - uint3 size; - TextureI.GetDimensions(size.x, size.y, size.z); - - return TextureI.Load(int4(size * input.TexCoord, 0)).rgba; -} - -float4 PS_PassthroughRGB3D(GS_OUTPUT input) : SV_TARGET0 -{ - return float4(TextureF.Sample(Sampler, input.TexCoord).rgb, 1.0f); -} - -uint4 PS_PassthroughRGB3DUI(GS_OUTPUT input) : SV_TARGET0 -{ - uint3 size; - TextureUI.GetDimensions(size.x, size.y, size.z); - - return uint4(TextureUI.Load(int4(size * input.TexCoord, 0)).rgb, 0); -} - -int4 PS_PassthroughRGB3DI(GS_OUTPUT input) : SV_TARGET0 -{ - uint3 size; - TextureI.GetDimensions(size.x, size.y, size.z); - - return int4(TextureI.Load(int4(size * input.TexCoord, 0)).rgb, 0); -} - -float4 PS_PassthroughRG3D(GS_OUTPUT input) : SV_TARGET0 -{ - return float4(TextureF.Sample(Sampler, input.TexCoord).rg, 0.0f, 1.0f); -} - -uint4 PS_PassthroughRG3DUI(GS_OUTPUT input) : SV_TARGET0 -{ - uint3 size; - TextureUI.GetDimensions(size.x, size.y, size.z); - - return uint4(TextureUI.Load(int4(size * input.TexCoord, 0)).rg, 0, 0); -} - -int4 PS_PassthroughRG3DI(GS_OUTPUT input) : SV_TARGET0 -{ - uint3 size; - TextureI.GetDimensions(size.x, size.y, size.z); - - return int4(TextureI.Load(int4(size * input.TexCoord, 0)).rg, 0, 0); -} - -float4 PS_PassthroughR3D(GS_OUTPUT input) : SV_TARGET0 -{ - return float4(TextureF.Sample(Sampler, input.TexCoord).r, 0.0f, 0.0f, 1.0f); -} - -uint4 PS_PassthroughR3DUI(GS_OUTPUT input) : SV_TARGET0 -{ - uint3 size; - TextureUI.GetDimensions(size.x, size.y, size.z); - - return uint4(TextureUI.Load(int4(size * input.TexCoord, 0)).r, 0, 0, 0); -} - -int4 PS_PassthroughR3DI(GS_OUTPUT input) : SV_TARGET0 -{ - uint3 size; - TextureI.GetDimensions(size.x, size.y, size.z); - - return int4(TextureI.Load(int4(size * input.TexCoord, 0)).r, 0, 0, 0); -} - -float4 PS_PassthroughLum3D(GS_OUTPUT input) : SV_TARGET0 -{ - return float4(TextureF.Sample(Sampler, input.TexCoord).rrr, 1.0f); -} - -float4 PS_PassthroughLumAlpha3D(GS_OUTPUT input) : SV_TARGET0 -{ - return TextureF.Sample(Sampler, input.TexCoord).rrra; -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/ResolveDepthStencil.hlsl b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/ResolveDepthStencil.hlsl deleted file mode 100644 index 7dc40d4b6a..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/ResolveDepthStencil.hlsl +++ /dev/null @@ -1,56 +0,0 @@ -static const float2 g_Corners[6] = -{ - float2(-1.0f, 1.0f), - float2( 1.0f, -1.0f), - float2(-1.0f, -1.0f), - float2(-1.0f, 1.0f), - float2( 1.0f, 1.0f), - float2( 1.0f, -1.0f), -}; - -void VS_ResolveDepthStencil(in uint id : SV_VertexID, - out float4 position : SV_Position, - out float2 texCoord : TEXCOORD0) -{ - float2 corner = g_Corners[id]; - position = float4(corner.x, corner.y, 0.0f, 1.0f); - texCoord = float2((corner.x + 1.0f) * 0.5f, (-corner.y + 1.0f) * 0.5f); -} - -Texture2DMS<float> Depth : register(t0); -Texture2DMS<uint2> Stencil : register(t1); - -void PS_ResolveDepth(in float4 position : SV_Position, - in float2 texCoord : TEXCOORD0, - out float depth : SV_Depth) -{ - // MS samplers must use Load - uint width, height, samples; - Depth.GetDimensions(width, height, samples); - uint2 coord = uint2(texCoord.x * float(width), texCoord.y * float(height)); - depth = Depth.Load(coord, 0).r; -} - -void PS_ResolveDepthStencil(in float4 position : SV_Position, - in float2 texCoord : TEXCOORD0, - out float2 depthStencil : SV_Target0) -{ - // MS samplers must use Load - uint width, height, samples; - Depth.GetDimensions(width, height, samples); - uint2 coord = uint2(texCoord.x * float(width), texCoord.y * float(height)); - depthStencil.r = Depth.Load(coord, 0).r; - depthStencil.g = float(Stencil.Load(coord, 0).g); -} - -void PS_ResolveStencil(in float4 position : SV_Position, - in float2 texCoord : TEXCOORD0, - out float2 stencil : SV_Target0) -{ - // MS samplers must use Load - uint width, height, samples; - Stencil.GetDimensions(width, height, samples); - uint2 coord = uint2(texCoord.x * float(width), texCoord.y * float(height)); - stencil.r = 0.0f; - stencil.g = float(Stencil.Load(coord, 0).g); -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/Swizzle11.hlsl b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/Swizzle11.hlsl deleted file mode 100644 index 505e222137..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/Swizzle11.hlsl +++ /dev/null @@ -1,99 +0,0 @@ -Texture2D<float4> TextureF2D : register(t0); -Texture2D<uint4> TextureUI2D : register(t0); -Texture2D<int4> TextureI2D : register(t0); - -Texture3D<float4> TextureF3D : register(t0); -Texture3D<uint4> TextureUI3D : register(t0); -Texture3D<int4> TextureI3D : register(t0); - -Texture2DArray<float4> TextureF2DArray : register(t0); -Texture2DArray<uint4> TextureUI2DArray : register(t0); -Texture2DArray<int4> TextureI2DArray : register(t0); - -SamplerState Sampler : register(s0); - -cbuffer SwizzleProperties : register(b0) -{ - uint4 SwizzleIndices : packoffset(c0); -} - -float4 SwizzleLookup(in float4 sample) -{ - float lookup[6] = { sample[0], sample[1], sample[2], sample[3], 0.0f, 1.0f }; - return float4(lookup[SwizzleIndices[0]], lookup[SwizzleIndices[1]], lookup[SwizzleIndices[2]], lookup[SwizzleIndices[3]]); -} - -int4 SwizzleLookup(in int4 sample) -{ - int lookup[6] = { sample[0], sample[1], sample[2], sample[3], 0.0f, 1.0f }; - return int4(lookup[SwizzleIndices[0]], lookup[SwizzleIndices[1]], lookup[SwizzleIndices[2]], lookup[SwizzleIndices[3]]); -} - -uint4 SwizzleLookup(in uint4 sample) -{ - uint lookup[6] = { sample[0], sample[1], sample[2], sample[3], 0.0f, 1.0f }; - return uint4(lookup[SwizzleIndices[0]], lookup[SwizzleIndices[1]], lookup[SwizzleIndices[2]], lookup[SwizzleIndices[3]]); -} - -float4 PS_SwizzleF2D(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - return SwizzleLookup(TextureF2D.Sample(Sampler, inTexCoord)); -} - -int4 PS_SwizzleI2D(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - uint2 size; - TextureI2D.GetDimensions(size.x, size.y); - - return SwizzleLookup(TextureI2D.Load(int3(size * inTexCoord, 0))); -} - -uint4 PS_SwizzleUI2D(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - uint2 size; - TextureUI2D.GetDimensions(size.x, size.y); - - return SwizzleLookup(TextureUI2D.Load(int3(size * inTexCoord, 0))); -} - -float4 PS_SwizzleF3D(in float4 inPosition : SV_POSITION, in uint inLayer : SV_RENDERTARGETARRAYINDEX, in float3 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - return SwizzleLookup(TextureF3D.Sample(Sampler, inTexCoord)); -} - -int4 PS_SwizzleI3D(in float4 inPosition : SV_POSITION, in uint inLayer : SV_RENDERTARGETARRAYINDEX, in float3 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - uint3 size; - TextureI3D.GetDimensions(size.x, size.y, size.z); - - return SwizzleLookup(TextureI3D.Load(int4(size * inTexCoord, 0))); -} - -uint4 PS_SwizzleUI3D(in float4 inPosition : SV_POSITION, in uint inLayer : SV_RENDERTARGETARRAYINDEX, in float3 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - uint3 size; - TextureUI3D.GetDimensions(size.x, size.y, size.z); - - return SwizzleLookup(TextureUI3D.Load(int4(size * inTexCoord, 0))); -} - -float4 PS_SwizzleF2DArray(in float4 inPosition : SV_POSITION, in uint inLayer : SV_RENDERTARGETARRAYINDEX, in float3 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - return SwizzleLookup(TextureF2DArray.Sample(Sampler, float3(inTexCoord.xy, inLayer))); -} - -int4 PS_SwizzleI2DArray(in float4 inPosition : SV_POSITION, in uint inLayer : SV_RENDERTARGETARRAYINDEX, in float3 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - uint3 size; - TextureI2DArray.GetDimensions(size.x, size.y, size.z); - - return SwizzleLookup(TextureI2DArray.Load(int4(size.xy * inTexCoord.xy, inLayer, 0))); -} - -uint4 PS_SwizzleUI2DArray(in float4 inPosition : SV_POSITION, in uint inLayer : SV_RENDERTARGETARRAYINDEX, in float3 inTexCoord : TEXCOORD0) : SV_TARGET0 -{ - uint3 size; - TextureUI2DArray.GetDimensions(size.x, size.y, size.z); - - return SwizzleLookup(TextureUI2DArray.Load(int4(size.xy * inTexCoord.xy, inLayer, 0))); -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgba2dms11ps.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgba2dms11ps.h deleted file mode 100644 index a5cccdc98e..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/shaders/compiled/passthroughrgba2dms11ps.h +++ /dev/null @@ -1,155 +0,0 @@ -#if 0 -// -// Generated by Microsoft (R) HLSL Shader Compiler 10.1 -// -// -// Resource Bindings: -// -// Name Type Format Dim HLSL Bind Count -// ------------------------------ ---------- ------- ----------- -------------- ------ -// TextureF_MS texture float4 2dMS t0 1 -// -// -// -// Input signature: -// -// Name Index Mask Register SysValue Format Used -// -------------------- ----- ------ -------- -------- ------- ------ -// SV_POSITION 0 xyzw 0 POS float -// TEXCORD 0 xy 1 NONE float xy -// SV_SAMPLEINDEX 0 x 2 SAMPLE uint x -// -// -// Output signature: -// -// Name Index Mask Register SysValue Format Used -// -------------------- ----- ------ -------- -------- ------- ------ -// SV_TARGET 0 xyzw 0 TARGET float xyzw -// -// Pixel Shader runs at sample frequency -// -ps_4_1 -dcl_globalFlags refactoringAllowed -dcl_resource_texture2dms(0) (float,float,float,float) t0 -dcl_input_ps linear v1.xy -dcl_input_ps_sgv constant v2.x, sampleIndex -dcl_output o0.xyzw -dcl_temps 1 -ftou r0.xy, v1.xyxx -mov r0.zw, l(0,0,0,0) -ldms o0.xyzw, r0.xyzw, t0.xyzw, v2.x -ret -// Approximately 4 instruction slots used -#endif - -const BYTE g_PS_PassthroughRGBA2DMS[] = -{ - 68, 88, 66, 67, 206, 115, - 73, 27, 160, 237, 59, 223, - 179, 180, 28, 146, 74, 174, - 29, 197, 1, 0, 0, 0, - 136, 2, 0, 0, 5, 0, - 0, 0, 52, 0, 0, 0, - 172, 0, 0, 0, 40, 1, - 0, 0, 92, 1, 0, 0, - 12, 2, 0, 0, 82, 68, - 69, 70, 112, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 0, 0, - 28, 0, 0, 0, 1, 4, - 255, 255, 0, 1, 0, 0, - 72, 0, 0, 0, 60, 0, - 0, 0, 2, 0, 0, 0, - 5, 0, 0, 0, 6, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, - 0, 0, 13, 0, 0, 0, - 84, 101, 120, 116, 117, 114, - 101, 70, 95, 77, 83, 0, - 77, 105, 99, 114, 111, 115, - 111, 102, 116, 32, 40, 82, - 41, 32, 72, 76, 83, 76, - 32, 83, 104, 97, 100, 101, - 114, 32, 67, 111, 109, 112, - 105, 108, 101, 114, 32, 49, - 48, 46, 49, 0, 73, 83, - 71, 78, 116, 0, 0, 0, - 3, 0, 0, 0, 8, 0, - 0, 0, 80, 0, 0, 0, - 0, 0, 0, 0, 1, 0, - 0, 0, 3, 0, 0, 0, - 0, 0, 0, 0, 15, 0, - 0, 0, 92, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 3, 0, 0, 0, - 1, 0, 0, 0, 3, 3, - 0, 0, 100, 0, 0, 0, - 0, 0, 0, 0, 10, 0, - 0, 0, 1, 0, 0, 0, - 2, 0, 0, 0, 1, 1, - 0, 0, 83, 86, 95, 80, - 79, 83, 73, 84, 73, 79, - 78, 0, 84, 69, 88, 67, - 79, 82, 68, 0, 83, 86, - 95, 83, 65, 77, 80, 76, - 69, 73, 78, 68, 69, 88, - 0, 171, 79, 83, 71, 78, - 44, 0, 0, 0, 1, 0, - 0, 0, 8, 0, 0, 0, - 32, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 0, 0, - 0, 0, 15, 0, 0, 0, - 83, 86, 95, 84, 65, 82, - 71, 69, 84, 0, 171, 171, - 83, 72, 68, 82, 168, 0, - 0, 0, 65, 0, 0, 0, - 42, 0, 0, 0, 106, 8, - 0, 1, 88, 32, 0, 4, - 0, 112, 16, 0, 0, 0, - 0, 0, 85, 85, 0, 0, - 98, 16, 0, 3, 50, 16, - 16, 0, 1, 0, 0, 0, - 99, 8, 0, 4, 18, 16, - 16, 0, 2, 0, 0, 0, - 10, 0, 0, 0, 101, 0, - 0, 3, 242, 32, 16, 0, - 0, 0, 0, 0, 104, 0, - 0, 2, 1, 0, 0, 0, - 28, 0, 0, 5, 50, 0, - 16, 0, 0, 0, 0, 0, - 70, 16, 16, 0, 1, 0, - 0, 0, 54, 0, 0, 8, - 194, 0, 16, 0, 0, 0, - 0, 0, 2, 64, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 46, 0, - 0, 9, 242, 32, 16, 0, - 0, 0, 0, 0, 70, 14, - 16, 0, 0, 0, 0, 0, - 70, 126, 16, 0, 0, 0, - 0, 0, 10, 16, 16, 0, - 2, 0, 0, 0, 62, 0, - 0, 1, 83, 84, 65, 84, - 116, 0, 0, 0, 4, 0, - 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 3, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 0, 0 -}; diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_data.json b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_data.json deleted file mode 100644 index 61cd44a62b..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_data.json +++ /dev/null @@ -1,523 +0,0 @@ -{ - "NONE": { - }, - "A8_UNORM": { - "texFormat": "DXGI_FORMAT_A8_UNORM", - "srvFormat": "DXGI_FORMAT_A8_UNORM", - "rtvFormat": "DXGI_FORMAT_A8_UNORM", - "channels": "a", - "componentType": "unorm", - "bits": { "alpha": 8 }, - "supportTest": "OnlyFL10Plus(deviceCaps)", - "fallbackFormat": "R8G8B8A8_UNORM" - }, - "R8G8B8A8_UNORM": { - "texFormat": "DXGI_FORMAT_R8G8B8A8_UNORM", - "srvFormat": "DXGI_FORMAT_R8G8B8A8_UNORM", - "rtvFormat": "DXGI_FORMAT_R8G8B8A8_UNORM", - "channels": "rgba", - "componentType": "unorm", - "bits": { "red": 8, "green": 8, "blue": 8, "alpha": 8 }, - "glInternalFormat": "GL_RGBA8" - }, - "R16G16B16A16_UNORM": { - "texFormat": "DXGI_FORMAT_R16G16B16A16_UNORM", - "srvFormat": "DXGI_FORMAT_R16G16B16A16_UNORM", - "rtvFormat": "DXGI_FORMAT_R16G16B16A16_UNORM", - "channels": "rgba", - "componentType": "unorm", - "bits": { "red": 16, "green": 16, "blue": 16, "alpha": 16 }, - "glInternalFormat": "GL_RGBA16_EXT" - }, - "R16G16B16A16_FLOAT": { - "texFormat": "DXGI_FORMAT_R16G16B16A16_FLOAT", - "srvFormat": "DXGI_FORMAT_R16G16B16A16_FLOAT", - "rtvFormat": "DXGI_FORMAT_R16G16B16A16_FLOAT", - "channels": "rgba", - "componentType": "float", - "bits": { "red": 16, "green": 16, "blue": 16, "alpha": 16 }, - "glInternalFormat": "GL_RGBA16F" - }, - "R32G32B32A32_FLOAT": { - "texFormat": "DXGI_FORMAT_R32G32B32A32_FLOAT", - "srvFormat": "DXGI_FORMAT_R32G32B32A32_FLOAT", - "rtvFormat": "DXGI_FORMAT_R32G32B32A32_FLOAT", - "channels": "rgba", - "componentType": "float", - "bits": { "red": 32, "green": 32, "blue": 32, "alpha": 32 }, - "glInternalFormat": "GL_RGBA32F" - }, - "B8G8R8A8_UNORM": { - "texFormat": "DXGI_FORMAT_B8G8R8A8_UNORM", - "srvFormat": "DXGI_FORMAT_B8G8R8A8_UNORM", - "rtvFormat": "DXGI_FORMAT_B8G8R8A8_UNORM", - "channels": "bgra", - "componentType": "unorm", - "bits": { "red": 8, "green": 8, "blue": 8, "alpha": 8 }, - "glInternalFormat": "GL_BGRA8_EXT" - }, - "B8G8R8A8_UNORM_SRGB": { - "texFormat": "DXGI_FORMAT_B8G8R8A8_UNORM_SRGB", - "srvFormat": "DXGI_FORMAT_B8G8R8A8_UNORM_SRGB", - "rtvFormat": "DXGI_FORMAT_B8G8R8A8_UNORM_SRGB", - "channels": "bgra", - "componentType": "unorm", - "bits": {"red": 8, "green": 8, "blue": 8,"alpha": 8}, - "siwzzleFormat": "GL_RGBA8" - }, - "BC1_RGBA_UNORM_BLOCK": { - "texFormat": "DXGI_FORMAT_BC1_UNORM", - "srvFormat": "DXGI_FORMAT_BC1_UNORM", - "channels": "rgba", - "componentType": "unorm", - "swizzleFormat": "GL_RGBA8" - }, - "BC1_RGB_UNORM_BLOCK": { - "texFormat": "DXGI_FORMAT_BC1_UNORM", - "srvFormat": "DXGI_FORMAT_BC1_UNORM", - "channels": "rgba", - "componentType": "unorm", - "swizzleFormat": "GL_RGBA8" - }, - "BC2_RGBA_UNORM_BLOCK": { - "texFormat": "DXGI_FORMAT_BC2_UNORM", - "srvFormat": "DXGI_FORMAT_BC2_UNORM", - "channels": "rgba", - "componentType": "unorm", - "swizzleFormat": "GL_RGBA8" - }, - "BC3_RGBA_UNORM_BLOCK": { - "texFormat": "DXGI_FORMAT_BC3_UNORM", - "srvFormat": "DXGI_FORMAT_BC3_UNORM", - "channels": "rgba", - "componentType": "unorm", - "swizzleFormat": "GL_RGBA8" - }, - "BC1_RGBA_UNORM_SRGB_BLOCK": { - "texFormat": "DXGI_FORMAT_BC1_UNORM_SRGB", - "srvFormat": "DXGI_FORMAT_BC1_UNORM_SRGB", - "channels": "rgba", - "componentType": "unorm", - "swizzleFormat": "GL_RGBA8" - }, - "BC1_RGB_UNORM_SRGB_BLOCK": { - "texFormat": "DXGI_FORMAT_BC1_UNORM_SRGB", - "srvFormat": "DXGI_FORMAT_BC1_UNORM_SRGB", - "channels": "rgba", - "componentType": "unorm", - "swizzleFormat": "GL_RGBA8" - }, - "BC2_RGBA_UNORM_SRGB_BLOCK": { - "texFormat": "DXGI_FORMAT_BC2_UNORM_SRGB", - "srvFormat": "DXGI_FORMAT_BC2_UNORM_SRGB", - "channels": "rgba", - "componentType": "unorm", - "swizzleFormat": "GL_RGBA8" - }, - "BC3_RGBA_UNORM_SRGB_BLOCK": { - "texFormat": "DXGI_FORMAT_BC3_UNORM_SRGB", - "srvFormat": "DXGI_FORMAT_BC3_UNORM_SRGB", - "channels": "rgba", - "componentType": "unorm", - "swizzleFormat": "GL_RGBA8" - }, - "D24_UNORM_S8_UINT": { - "FL10Plus": { - "texFormat": "DXGI_FORMAT_R24G8_TYPELESS", - "srvFormat": "DXGI_FORMAT_R24_UNORM_X8_TYPELESS" - }, - "FL9_3": { - "texFormat": "DXGI_FORMAT_D24_UNORM_S8_UINT" - }, - "dsvFormat": "DXGI_FORMAT_D24_UNORM_S8_UINT", - "channels": "ds", - "bits": { "depth": 24, "stencil": 8 }, - "glInternalFormat": "GL_DEPTH24_STENCIL8_OES" - }, - "D32_FLOAT_S8X24_UINT": { - "texFormat": "DXGI_FORMAT_R32G8X24_TYPELESS", - "srvFormat": "DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS", - "dsvFormat": "DXGI_FORMAT_D32_FLOAT_S8X24_UINT", - "channels": "ds", - "bits": { "depth": 32, "stencil": 8 }, - "glInternalFormat": "GL_DEPTH32F_STENCIL8" - }, - "D16_UNORM": { - "FL10Plus": { - "texFormat": "DXGI_FORMAT_R16_TYPELESS", - "srvFormat": "DXGI_FORMAT_R16_UNORM" - }, - "FL9_3": { - "texFormat": "DXGI_FORMAT_D16_UNORM" - }, - "dsvFormat": "DXGI_FORMAT_D16_UNORM", - "channels": "d", - "componentType": "unorm", - "bits": { "depth": 16 }, - "glInternalFormat": "GL_DEPTH_COMPONENT16" - }, - "D32_FLOAT": { - "texFormat": "DXGI_FORMAT_R32_TYPELESS", - "srvFormat": "DXGI_FORMAT_R32_FLOAT", - "dsvFormat": "DXGI_FORMAT_D32_FLOAT", - "channels": "d", - "componentType": "float", - "bits": { "depth": 32 }, - "glInternalFormat": "GL_DEPTH_COMPONENT32F" - }, - "R11G11B10_FLOAT": { - "texFormat": "DXGI_FORMAT_R11G11B10_FLOAT", - "srvFormat": "DXGI_FORMAT_R11G11B10_FLOAT", - "rtvFormat": "DXGI_FORMAT_R11G11B10_FLOAT", - "channels": "rgb", - "componentType": "float", - "bits": { "red": 11, "green": 11, "blue": 10 }, - "glInternalFormat": "GL_R11F_G11F_B10F" - }, - "R16_FLOAT": { - "texFormat": "DXGI_FORMAT_R16_FLOAT", - "srvFormat": "DXGI_FORMAT_R16_FLOAT", - "rtvFormat": "DXGI_FORMAT_R16_FLOAT", - "channels": "r", - "componentType": "float", - "bits": { "red": 16 }, - "glInternalFormat": "GL_R16F" - }, - "R16_SINT": { - "texFormat": "DXGI_FORMAT_R16_SINT", - "srvFormat": "DXGI_FORMAT_R16_SINT", - "rtvFormat": "DXGI_FORMAT_R16_SINT", - "channels": "r", - "componentType": "int", - "bits": { "red": 16 }, - "glInternalFormat": "GL_R16I" - }, - "R16_UINT": { - "texFormat": "DXGI_FORMAT_R16_UINT", - "srvFormat": "DXGI_FORMAT_R16_UINT", - "rtvFormat": "DXGI_FORMAT_R16_UINT", - "channels": "r", - "componentType": "uint", - "bits": { "red": 16 }, - "glInternalFormat": "GL_R16UI" - }, - "R32_FLOAT": { - "texFormat": "DXGI_FORMAT_R32_FLOAT", - "srvFormat": "DXGI_FORMAT_R32_FLOAT", - "rtvFormat": "DXGI_FORMAT_R32_FLOAT", - "channels": "r", - "componentType": "float", - "bits": { "red": 32 }, - "glInternalFormat": "GL_R32F" - }, - "R32_SINT": { - "texFormat": "DXGI_FORMAT_R32_SINT", - "srvFormat": "DXGI_FORMAT_R32_SINT", - "rtvFormat": "DXGI_FORMAT_R32_SINT", - "channels": "r", - "componentType": "int", - "bits": { "red": 32 }, - "glInternalFormat": "GL_R32I" - }, - "R32_UINT": { - "texFormat": "DXGI_FORMAT_R32_UINT", - "srvFormat": "DXGI_FORMAT_R32_UINT", - "rtvFormat": "DXGI_FORMAT_R32_UINT", - "channels": "r", - "componentType": "uint", - "bits": { "red": 32 }, - "glInternalFormat": "GL_R32UI" - }, - "R8_UNORM": { - "texFormat": "DXGI_FORMAT_R8_UNORM", - "srvFormat": "DXGI_FORMAT_R8_UNORM", - "rtvFormat": "DXGI_FORMAT_R8_UNORM", - "channels": "r", - "componentType": "unorm", - "bits": { "red": 8 }, - "glInternalFormat": "GL_R8" - }, - "R8_SINT": { - "texFormat": "DXGI_FORMAT_R8_SINT", - "srvFormat": "DXGI_FORMAT_R8_SINT", - "rtvFormat": "DXGI_FORMAT_R8_SINT", - "channels": "r", - "componentType": "int", - "bits": { "red": 8 }, - "glInternalFormat": "GL_R8I" - }, - "R8_UINT": { - "texFormat": "DXGI_FORMAT_R8_UINT", - "srvFormat": "DXGI_FORMAT_R8_UINT", - "rtvFormat": "DXGI_FORMAT_R8_UINT", - "channels": "r", - "componentType": "uint", - "bits": { "red": 8 }, - "glInternalFormat": "GL_R8UI" - }, - "R8_SNORM": { - "texFormat": "DXGI_FORMAT_R8_SNORM", - "srvFormat": "DXGI_FORMAT_R8_SNORM", - "channels": "r", - "componentType": "snorm", - "bits": { "red": 8 }, - "glInternalFormat": "GL_R8_SNORM" - }, - "R16G16_FLOAT": { - "texFormat": "DXGI_FORMAT_R16G16_FLOAT", - "srvFormat": "DXGI_FORMAT_R16G16_FLOAT", - "rtvFormat": "DXGI_FORMAT_R16G16_FLOAT", - "channels": "rg", - "componentType": "float", - "bits": { "red": 16, "green": 16 }, - "glInternalFormat": "GL_RG16F" - }, - "R16G16_SINT": { - "texFormat": "DXGI_FORMAT_R16G16_SINT", - "srvFormat": "DXGI_FORMAT_R16G16_SINT", - "rtvFormat": "DXGI_FORMAT_R16G16_SINT", - "channels": "rg", - "componentType": "int", - "bits": { "red": 16, "green": 16 }, - "glInternalFormat": "GL_RG16I" - }, - "R16G16_UINT": { - "texFormat": "DXGI_FORMAT_R16G16_UINT", - "srvFormat": "DXGI_FORMAT_R16G16_UINT", - "rtvFormat": "DXGI_FORMAT_R16G16_UINT", - "channels": "rg", - "componentType": "uint", - "bits": { "red": 16, "green": 16 }, - "glInternalFormat": "GL_RG16UI" - }, - "R32G32_FLOAT": { - "texFormat": "DXGI_FORMAT_R32G32_FLOAT", - "srvFormat": "DXGI_FORMAT_R32G32_FLOAT", - "rtvFormat": "DXGI_FORMAT_R32G32_FLOAT", - "channels": "rg", - "componentType": "float", - "bits": { "red": 32, "green": 32 }, - "glInternalFormat": "GL_RG32F" - }, - "R32G32_SINT": { - "texFormat": "DXGI_FORMAT_R32G32_SINT", - "srvFormat": "DXGI_FORMAT_R32G32_SINT", - "rtvFormat": "DXGI_FORMAT_R32G32_SINT", - "channels": "rg", - "componentType": "int", - "bits": { "red": 32, "green": 32 }, - "glInternalFormat": "GL_RG32I" - }, - "R32G32_UINT": { - "texFormat": "DXGI_FORMAT_R32G32_UINT", - "srvFormat": "DXGI_FORMAT_R32G32_UINT", - "rtvFormat": "DXGI_FORMAT_R32G32_UINT", - "channels": "rg", - "componentType": "uint", - "bits": { "red": 32, "green": 32 }, - "glInternalFormat": "GL_RG32UI" - }, - "R8G8_UNORM": { - "texFormat": "DXGI_FORMAT_R8G8_UNORM", - "srvFormat": "DXGI_FORMAT_R8G8_UNORM", - "rtvFormat": "DXGI_FORMAT_R8G8_UNORM", - "channels": "rg", - "componentType": "unorm", - "bits": { "red": 8, "green": 8 }, - "glInternalFormat": "GL_RG8" - }, - "R8G8_SINT": { - "texFormat": "DXGI_FORMAT_R8G8_SINT", - "srvFormat": "DXGI_FORMAT_R8G8_SINT", - "rtvFormat": "DXGI_FORMAT_R8G8_SINT", - "channels": "rg", - "componentType": "int", - "bits": { "red": 8, "green": 8 }, - "glInternalFormat": "GL_RG8I" - }, - "R8G8_UINT": { - "texFormat": "DXGI_FORMAT_R8G8_UINT", - "srvFormat": "DXGI_FORMAT_R8G8_UINT", - "rtvFormat": "DXGI_FORMAT_R8G8_UINT", - "channels": "rg", - "componentType": "uint", - "bits": { "red": 8, "green": 8 }, - "glInternalFormat": "GL_RG8UI" - }, - "R8G8_SNORM": { - "texFormat": "DXGI_FORMAT_R8G8_SNORM", - "srvFormat": "DXGI_FORMAT_R8G8_SNORM", - "channels": "rg", - "componentType": "snorm", - "bits": { "red": 8, "green": 8 }, - "glInternalFormat": "GL_RG8_SNORM" - }, - "R10G10B10A2_UNORM": { - "texFormat": "DXGI_FORMAT_R10G10B10A2_UNORM", - "srvFormat": "DXGI_FORMAT_R10G10B10A2_UNORM", - "rtvFormat": "DXGI_FORMAT_R10G10B10A2_UNORM", - "channels": "rgba", - "componentType": "unorm", - "bits": { "red": 10, "green": 10, "blue": 10, "alpha": 2 }, - "glInternalFormat": "GL_RGB10_A2" - }, - "R10G10B10A2_UINT": { - "texFormat": "DXGI_FORMAT_R10G10B10A2_UINT", - "srvFormat": "DXGI_FORMAT_R10G10B10A2_UINT", - "rtvFormat": "DXGI_FORMAT_R10G10B10A2_UINT", - "channels": "rgba", - "componentType": "uint", - "bits": { "red": 10, "green": 10, "blue": 10, "alpha": 2 }, - "glInternalFormat": "GL_RGB10_A2UI" - }, - "R16G16B16A16_SINT": { - "texFormat": "DXGI_FORMAT_R16G16B16A16_SINT", - "srvFormat": "DXGI_FORMAT_R16G16B16A16_SINT", - "rtvFormat": "DXGI_FORMAT_R16G16B16A16_SINT", - "channels": "rgba", - "componentType": "int", - "bits": { "red": 16, "green": 16, "blue": 16, "alpha": 16 }, - "glInternalFormat": "GL_RGBA16I" - }, - "R16G16B16A16_UINT": { - "texFormat": "DXGI_FORMAT_R16G16B16A16_UINT", - "srvFormat": "DXGI_FORMAT_R16G16B16A16_UINT", - "rtvFormat": "DXGI_FORMAT_R16G16B16A16_UINT", - "channels": "rgba", - "componentType": "uint", - "bits": { "red": 16, "green": 16, "blue": 16, "alpha": 16 }, - "glInternalFormat": "GL_RGBA16UI" - }, - "R32G32B32A32_SINT": { - "texFormat": "DXGI_FORMAT_R32G32B32A32_SINT", - "srvFormat": "DXGI_FORMAT_R32G32B32A32_SINT", - "rtvFormat": "DXGI_FORMAT_R32G32B32A32_SINT", - "channels": "rgba", - "componentType": "int", - "bits": { "red": 32, "green": 32, "blue": 32, "alpha": 32 }, - "glInternalFormat": "GL_RGBA32I" - }, - "R32G32B32A32_UINT": { - "texFormat": "DXGI_FORMAT_R32G32B32A32_UINT", - "srvFormat": "DXGI_FORMAT_R32G32B32A32_UINT", - "rtvFormat": "DXGI_FORMAT_R32G32B32A32_UINT", - "channels": "rgba", - "componentType": "uint", - "bits": { "red": 32, "green": 32, "blue": 32, "alpha": 32 }, - "glInternalFormat": "GL_RGBA32UI" - }, - "B5G6R5_UNORM": { - "texFormat": "DXGI_FORMAT_B5G6R5_UNORM", - "srvFormat": "DXGI_FORMAT_B5G6R5_UNORM", - "rtvFormat": "DXGI_FORMAT_B5G6R5_UNORM", - "channels": "bgr", - "componentType": "unorm", - "bits": { "red": 5, "green": 6, "blue": 5 }, - "supportTest": "SupportsFormat(DXGI_FORMAT_B5G6R5_UNORM, deviceCaps)", - "fallbackFormat": "R8G8B8A8_UNORM" - }, - "B5G5R5A1_UNORM": { - "texFormat": "DXGI_FORMAT_B5G5R5A1_UNORM", - "srvFormat": "DXGI_FORMAT_B5G5R5A1_UNORM", - "rtvFormat": "DXGI_FORMAT_B5G5R5A1_UNORM", - "channels": "bgra", - "componentType": "unorm", - "bits": { "red": 5, "green": 5, "blue": 5, "alpha": 1 }, - "supportTest": "SupportsFormat(DXGI_FORMAT_B5G5R5A1_UNORM, deviceCaps)", - "fallbackFormat": "R8G8B8A8_UNORM" - }, - "R8G8B8A8_SINT": { - "texFormat": "DXGI_FORMAT_R8G8B8A8_SINT", - "srvFormat": "DXGI_FORMAT_R8G8B8A8_SINT", - "rtvFormat": "DXGI_FORMAT_R8G8B8A8_SINT", - "channels": "rgba", - "componentType": "int", - "bits": { "red": 8, "green": 8, "blue": 8, "alpha": 8 }, - "glInternalFormat": "GL_RGBA8I" - }, - "R8G8B8A8_UINT": { - "texFormat": "DXGI_FORMAT_R8G8B8A8_UINT", - "srvFormat": "DXGI_FORMAT_R8G8B8A8_UINT", - "rtvFormat": "DXGI_FORMAT_R8G8B8A8_UINT", - "channels": "rgba", - "componentType": "uint", - "bits": { "red": 8, "green": 8, "blue": 8, "alpha": 8 }, - "glInternalFormat": "GL_RGBA8UI" - }, - "R8G8B8A8_SNORM": { - "texFormat": "DXGI_FORMAT_R8G8B8A8_SNORM", - "srvFormat": "DXGI_FORMAT_R8G8B8A8_SNORM", - "channels": "rgba", - "componentType": "snorm", - "bits": { "red": 8, "green": 8, "blue": 8, "alpha": 8 }, - "glInternalFormat": "GL_RGBA8_SNORM" - }, - "R9G9B9E5_SHAREDEXP": { - "texFormat": "DXGI_FORMAT_R9G9B9E5_SHAREDEXP", - "srvFormat": "DXGI_FORMAT_R9G9B9E5_SHAREDEXP", - "channels": "rgb", - "componentType": "float", - "bits": { "red": 9, "green": 9, "blue": 9, "shared": 5 } - }, - "B4G4R4A4_UNORM": { - "texFormat": "DXGI_FORMAT_B4G4R4A4_UNORM", - "srvFormat": "DXGI_FORMAT_B4G4R4A4_UNORM", - "rtvFormat": "DXGI_FORMAT_B4G4R4A4_UNORM", - "channels": "bgra", - "componentType": "unorm", - "bits": { "red": 4, "green": 4, "blue": 4, "alpha": 4 }, - "supportTest": "SupportsFormat(DXGI_FORMAT_B4G4R4A4_UNORM, deviceCaps)", - "fallbackFormat": "R8G8B8A8_UNORM" - }, - "R8G8B8A8_UNORM_SRGB": { - "texFormat": "DXGI_FORMAT_R8G8B8A8_UNORM_SRGB", - "srvFormat": "DXGI_FORMAT_R8G8B8A8_UNORM_SRGB", - "rtvFormat": "DXGI_FORMAT_R8G8B8A8_UNORM_SRGB", - "channels": "rgba", - "componentType": "unorm", - "bits": { "red": 8, "green": 8, "blue": 8, "alpha": 8 }, - "glInternalFormat": "GL_SRGB8_ALPHA8" - }, - "R16_UNORM": { - "texFormat": "DXGI_FORMAT_R16_UNORM", - "srvFormat": "DXGI_FORMAT_R16_UNORM", - "rtvFormat": "DXGI_FORMAT_R16_UNORM", - "channels": "r", - "componentType": "unorm", - "bits": { "red": 16 }, - "glInternalFormat": "GL_R16_EXT" - }, - "R16G16_UNORM": { - "texFormat": "DXGI_FORMAT_R16G16_UNORM", - "srvFormat": "DXGI_FORMAT_R16G16_UNORM", - "rtvFormat": "DXGI_FORMAT_R16G16_UNORM", - "channels": "rg", - "componentType": "unorm", - "bits": { "red": 16, "green": 16 }, - "glInternalFormat": "GL_RG16_EXT" - }, - "R16_SNORM": { - "texFormat": "DXGI_FORMAT_R16_SNORM", - "srvFormat": "DXGI_FORMAT_R16_SNORM", - "channels": "r", - "componentType": "snorm", - "bits": { "red": 16 }, - "glInternalFormat": "GL_R16_SNORM_EXT" - }, - "R16G16_SNORM": { - "texFormat": "DXGI_FORMAT_R16G16_SNORM", - "srvFormat": "DXGI_FORMAT_R16G16_SNORM", - "channels": "rg", - "componentType": "snorm", - "bits": { "red": 16, "green": 16 }, - "glInternalFormat": "GL_RG16_SNORM_EXT" - }, - "R16G16B16A16_SNORM": { - "texFormat": "DXGI_FORMAT_R16G16B16A16_SNORM", - "srvFormat": "DXGI_FORMAT_R16G16B16A16_SNORM", - "channels": "rgba", - "componentType": "snorm", - "bits": { "red": 16, "green": 16, "blue": 16, "alpha": 16 }, - "glInternalFormat": "GL_RGBA16_SNORM_EXT" - } -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_map.json b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_map.json deleted file mode 100644 index 3ef2355645..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_map.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - "GL_ALPHA16F_EXT": "R16G16B16A16_FLOAT", - "GL_ALPHA32F_EXT": "R32G32B32A32_FLOAT", - "GL_BGR5_A1_ANGLEX": "B8G8R8A8_UNORM", - "GL_BGRA4_ANGLEX": "B8G8R8A8_UNORM", - "GL_BGRA8_SRGB_ANGLEX": "B8G8R8A8_UNORM_SRGB", - "GL_COMPRESSED_R11_EAC": "R8_UNORM", - "GL_COMPRESSED_RG11_EAC": "R8G8_UNORM", - "GL_COMPRESSED_RGB8_ETC2": "R8G8B8A8_UNORM", - "GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2": "R8G8B8A8_UNORM", - "GL_COMPRESSED_RGBA8_ETC2_EAC": "R8G8B8A8_UNORM", - "GL_COMPRESSED_RGBA_ASTC_4x4_KHR": "NONE", - "GL_COMPRESSED_RGBA_ASTC_5x4_KHR": "NONE", - "GL_COMPRESSED_RGBA_ASTC_5x5_KHR": "NONE", - "GL_COMPRESSED_RGBA_ASTC_6x5_KHR": "NONE", - "GL_COMPRESSED_RGBA_ASTC_6x6_KHR": "NONE", - "GL_COMPRESSED_RGBA_ASTC_8x5_KHR": "NONE", - "GL_COMPRESSED_RGBA_ASTC_8x6_KHR": "NONE", - "GL_COMPRESSED_RGBA_ASTC_8x8_KHR": "NONE", - "GL_COMPRESSED_RGBA_ASTC_10x5_KHR": "NONE", - "GL_COMPRESSED_RGBA_ASTC_10x6_KHR": "NONE", - "GL_COMPRESSED_RGBA_ASTC_10x8_KHR": "NONE", - "GL_COMPRESSED_RGBA_ASTC_10x10_KHR": "NONE", - "GL_COMPRESSED_RGBA_ASTC_12x10_KHR": "NONE", - "GL_COMPRESSED_RGBA_ASTC_12x12_KHR": "NONE", - "GL_COMPRESSED_SIGNED_R11_EAC": "R8_SNORM", - "GL_COMPRESSED_SIGNED_RG11_EAC": "R8G8_SNORM", - "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR": "NONE", - "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR": "NONE", - "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR": "NONE", - "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR": "NONE", - "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR": "NONE", - "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR": "NONE", - "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR": "NONE", - "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR": "NONE", - "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR": "NONE", - "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR": "NONE", - "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR": "NONE", - "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR": "NONE", - "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR": "NONE", - "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR": "NONE", - "GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC": "R8G8B8A8_UNORM_SRGB", - "GL_COMPRESSED_SRGB8_ETC2": "R8G8B8A8_UNORM_SRGB", - "GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2": "R8G8B8A8_UNORM_SRGB", - "GL_DEPTH_COMPONENT24": "D24_UNORM_S8_UINT", - "GL_DEPTH_COMPONENT32_OES": "D24_UNORM_S8_UINT", - "GL_ETC1_RGB8_OES": "R8G8B8A8_UNORM", - "GL_ETC1_RGB8_LOSSY_DECODE_ANGLE": "BC1_RGB_UNORM_BLOCK", - "GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE": "BC1_RGB_UNORM_BLOCK", - "GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE": "BC1_RGB_UNORM_SRGB_BLOCK", - "GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE": "BC1_RGBA_UNORM_BLOCK", - "GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE": "BC1_RGBA_UNORM_SRGB_BLOCK", - "GL_LUMINANCE16F_EXT": "R16G16B16A16_FLOAT", - "GL_LUMINANCE32F_EXT": "R32G32B32A32_FLOAT", - "GL_LUMINANCE8_ALPHA8_EXT": "R8G8B8A8_UNORM", - "GL_LUMINANCE8_EXT": "R8G8B8A8_UNORM", - "GL_LUMINANCE_ALPHA16F_EXT": "R16G16B16A16_FLOAT", - "GL_LUMINANCE_ALPHA32F_EXT": "R32G32B32A32_FLOAT", - "GL_RGB": "R8G8B8A8_UNORM", - "GL_RGB16F": "R16G16B16A16_FLOAT", - "GL_RGB16I": "R16G16B16A16_SINT", - "GL_RGB16UI": "R16G16B16A16_UINT", - "GL_RGB565": "B5G6R5_UNORM", - "GL_RGB5_A1": "B5G5R5A1_UNORM", - "GL_RGB8": "R8G8B8A8_UNORM", - "GL_RGB8I": "R8G8B8A8_SINT", - "GL_RGB8UI": "R8G8B8A8_UINT", - "GL_RGB8_SNORM": "R8G8B8A8_SNORM", - "GL_RGBA4": "B4G4R4A4_UNORM", - "GL_SRGB8": "R8G8B8A8_UNORM_SRGB", - "GL_STENCIL_INDEX8": "D24_UNORM_S8_UINT", - "GL_RGB16_EXT": "R16G16B16A16_UNORM", - "GL_RGBA16_EXT": "R16G16B16A16_UNORM", - "GL_RGB16_SNORM_EXT": "R16G16B16A16_SNORM", - "GL_RGB32F": "R32G32B32A32_FLOAT", - "GL_RGB32I": "R32G32B32A32_SINT", - "GL_RGB32UI": "R32G32B32A32_UINT" -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_table.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_table.cpp deleted file mode 100644 index a9dfec56b8..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_table.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright 2016 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// Helper routines for the D3D11 texture format table. - -#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h" - -#include "libANGLE/renderer/load_functions_table.h" - -namespace rx -{ - -namespace d3d11 -{ - -const Format &Format::getSwizzleFormat(const Renderer11DeviceCaps &deviceCaps) const -{ - return (swizzleFormat == internalFormat ? *this : Format::Get(swizzleFormat, deviceCaps)); -} - -LoadFunctionMap Format::getLoadFunctions() const -{ - return GetLoadFunctionsMap(internalFormat, formatID); -} - -const angle::Format &Format::format() const -{ - return angle::Format::Get(formatID); -} - -} // namespace d3d11 - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_table.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_table.h deleted file mode 100644 index 3efcb81adb..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_table.h +++ /dev/null @@ -1,105 +0,0 @@ -// -// Copyright 2015 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// texture_format_table: -// Queries for full textureFormat information based on internalFormat -// - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_TEXTUREFORMATTABLE_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_TEXTUREFORMATTABLE_H_ - -#include <map> - -#include "common/angleutils.h" -#include "common/platform.h" -#include "libANGLE/renderer/Format.h" -#include "libANGLE/renderer/renderer_utils.h" -#include "libANGLE/renderer/d3d/formatutilsD3D.h" - -namespace rx -{ - -struct Renderer11DeviceCaps; - -namespace d3d11 -{ - -// For sized GL internal formats, there are several possible corresponding D3D11 formats depending -// on device capabilities. -// This structure allows querying for the DXGI texture formats to use for textures, SRVs, RTVs and -// DSVs given a GL internal format. -struct Format final : private angle::NonCopyable -{ - constexpr Format(); - constexpr Format(GLenum internalFormat, - angle::Format::ID formatID, - DXGI_FORMAT texFormat, - DXGI_FORMAT srvFormat, - DXGI_FORMAT rtvFormat, - DXGI_FORMAT dsvFormat, - DXGI_FORMAT blitSRVFormat, - GLenum swizzleFormat, - InitializeTextureDataFunction internalFormatInitializer); - - static const Format &Get(GLenum internalFormat, const Renderer11DeviceCaps &deviceCaps); - - const Format &getSwizzleFormat(const Renderer11DeviceCaps &deviceCaps) const; - LoadFunctionMap getLoadFunctions() const; - const angle::Format &format() const; - - GLenum internalFormat; - angle::Format::ID formatID; - - DXGI_FORMAT texFormat; - DXGI_FORMAT srvFormat; - DXGI_FORMAT rtvFormat; - DXGI_FORMAT dsvFormat; - - DXGI_FORMAT blitSRVFormat; - - GLenum swizzleFormat; - - InitializeTextureDataFunction dataInitializerFunction; -}; - -constexpr Format::Format() - : internalFormat(GL_NONE), - formatID(angle::Format::ID::NONE), - texFormat(DXGI_FORMAT_UNKNOWN), - srvFormat(DXGI_FORMAT_UNKNOWN), - rtvFormat(DXGI_FORMAT_UNKNOWN), - dsvFormat(DXGI_FORMAT_UNKNOWN), - blitSRVFormat(DXGI_FORMAT_UNKNOWN), - swizzleFormat(GL_NONE), - dataInitializerFunction(nullptr) -{ -} - -constexpr Format::Format(GLenum internalFormat, - angle::Format::ID formatID, - DXGI_FORMAT texFormat, - DXGI_FORMAT srvFormat, - DXGI_FORMAT rtvFormat, - DXGI_FORMAT dsvFormat, - DXGI_FORMAT blitSRVFormat, - GLenum swizzleFormat, - InitializeTextureDataFunction internalFormatInitializer) - : internalFormat(internalFormat), - formatID(formatID), - texFormat(texFormat), - srvFormat(srvFormat), - rtvFormat(rtvFormat), - dsvFormat(dsvFormat), - blitSRVFormat(blitSRVFormat), - swizzleFormat(swizzleFormat), - dataInitializerFunction(internalFormatInitializer) -{ -} - -} // namespace d3d11 - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_TEXTUREFORMATTABLE_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_table_autogen.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_table_autogen.cpp deleted file mode 100644 index 3c1c2bcd50..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_table_autogen.cpp +++ /dev/null @@ -1,1938 +0,0 @@ -// GENERATED FILE - DO NOT EDIT. -// Generated by gen_texture_format_table.py using data from texture_format_data.json -// -// Copyright 2017 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// texture_format_table: -// Queries for full textureFormat information based in internalFormat -// - -#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h" - -#include "image_util/copyimage.h" -#include "image_util/generatemip.h" -#include "image_util/loadimage.h" - -#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/renderer/d3d/d3d11/texture_format_table_utils.h" - -using namespace angle; - -namespace rx -{ - -namespace d3d11 -{ - -// static -const Format &Format::Get(GLenum internalFormat, const Renderer11DeviceCaps &deviceCaps) -{ - // clang-format off - switch (internalFormat) - { - case GL_ALPHA16F_EXT: - { - static constexpr Format info(GL_ALPHA16F_EXT, - angle::Format::ID::R16G16B16A16_FLOAT, - DXGI_FORMAT_R16G16B16A16_FLOAT, - DXGI_FORMAT_R16G16B16A16_FLOAT, - DXGI_FORMAT_R16G16B16A16_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16B16A16_FLOAT, - GL_RGBA16F, - nullptr); - return info; - } - case GL_ALPHA32F_EXT: - { - static constexpr Format info(GL_ALPHA32F_EXT, - angle::Format::ID::R32G32B32A32_FLOAT, - DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R32G32B32A32_FLOAT, - GL_RGBA32F, - nullptr); - return info; - } - case GL_ALPHA8_EXT: - { - if (OnlyFL10Plus(deviceCaps)) - { - static constexpr Format info(GL_ALPHA8_EXT, - angle::Format::ID::A8_UNORM, - DXGI_FORMAT_A8_UNORM, - DXGI_FORMAT_A8_UNORM, - DXGI_FORMAT_A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_A8_UNORM, - GL_RGBA8, - nullptr); - return info; - } - else - { - static constexpr Format info(GL_ALPHA8_EXT, - angle::Format::ID::R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM, - GL_RGBA8, - nullptr); - return info; - } - } - case GL_BGR565_ANGLEX: - { - if (SupportsFormat(DXGI_FORMAT_B5G6R5_UNORM, deviceCaps)) - { - static constexpr Format info(GL_BGR565_ANGLEX, - angle::Format::ID::B5G6R5_UNORM, - DXGI_FORMAT_B5G6R5_UNORM, - DXGI_FORMAT_B5G6R5_UNORM, - DXGI_FORMAT_B5G6R5_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_B5G6R5_UNORM, - GL_RGBA8, - nullptr); - return info; - } - else - { - static constexpr Format info(GL_BGR565_ANGLEX, - angle::Format::ID::R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM, - GL_RGBA8, - nullptr); - return info; - } - } - case GL_BGR5_A1_ANGLEX: - { - static constexpr Format info(GL_BGR5_A1_ANGLEX, - angle::Format::ID::B8G8R8A8_UNORM, - DXGI_FORMAT_B8G8R8A8_UNORM, - DXGI_FORMAT_B8G8R8A8_UNORM, - DXGI_FORMAT_B8G8R8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_B8G8R8A8_UNORM, - GL_BGRA8_EXT, - nullptr); - return info; - } - case GL_BGRA4_ANGLEX: - { - static constexpr Format info(GL_BGRA4_ANGLEX, - angle::Format::ID::B8G8R8A8_UNORM, - DXGI_FORMAT_B8G8R8A8_UNORM, - DXGI_FORMAT_B8G8R8A8_UNORM, - DXGI_FORMAT_B8G8R8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_B8G8R8A8_UNORM, - GL_BGRA8_EXT, - nullptr); - return info; - } - case GL_BGRA8_EXT: - { - static constexpr Format info(GL_BGRA8_EXT, - angle::Format::ID::B8G8R8A8_UNORM, - DXGI_FORMAT_B8G8R8A8_UNORM, - DXGI_FORMAT_B8G8R8A8_UNORM, - DXGI_FORMAT_B8G8R8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_B8G8R8A8_UNORM, - GL_BGRA8_EXT, - nullptr); - return info; - } - case GL_BGRA8_SRGB_ANGLEX: - { - static constexpr Format info(GL_BGRA8_SRGB_ANGLEX, - angle::Format::ID::B8G8R8A8_UNORM_SRGB, - DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, - DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, - DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, - GL_BGRA8_SRGB_ANGLEX, - nullptr); - return info; - } - case GL_COMPRESSED_R11_EAC: - { - static constexpr Format info(GL_COMPRESSED_R11_EAC, - angle::Format::ID::R8_UNORM, - DXGI_FORMAT_R8_UNORM, - DXGI_FORMAT_R8_UNORM, - DXGI_FORMAT_R8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8_UNORM, - GL_RGBA8, - nullptr); - return info; - } - case GL_COMPRESSED_RG11_EAC: - { - static constexpr Format info(GL_COMPRESSED_RG11_EAC, - angle::Format::ID::R8G8_UNORM, - DXGI_FORMAT_R8G8_UNORM, - DXGI_FORMAT_R8G8_UNORM, - DXGI_FORMAT_R8G8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8_UNORM, - GL_RGBA8, - nullptr); - return info; - } - case GL_COMPRESSED_RGB8_ETC2: - { - static constexpr Format info(GL_COMPRESSED_RGB8_ETC2, - angle::Format::ID::R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM, - GL_RGBA8, - Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>); - return info; - } - case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: - { - static constexpr Format info(GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, - angle::Format::ID::BC1_RGB_UNORM_BLOCK, - DXGI_FORMAT_BC1_UNORM, - DXGI_FORMAT_BC1_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_BC1_UNORM, - GL_RGBA8, - nullptr); - return info; - } - case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: - { - static constexpr Format info(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, - angle::Format::ID::R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM, - GL_RGBA8, - Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>); - return info; - } - case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: - { - static constexpr Format info(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, - angle::Format::ID::BC1_RGBA_UNORM_BLOCK, - DXGI_FORMAT_BC1_UNORM, - DXGI_FORMAT_BC1_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_BC1_UNORM, - GL_RGBA8, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA8_ETC2_EAC: - { - static constexpr Format info(GL_COMPRESSED_RGBA8_ETC2_EAC, - angle::Format::ID::R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM, - GL_RGBA8, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_ASTC_10x10_KHR: - { - static constexpr Format info(GL_COMPRESSED_RGBA_ASTC_10x10_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_ASTC_10x5_KHR: - { - static constexpr Format info(GL_COMPRESSED_RGBA_ASTC_10x5_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_ASTC_10x6_KHR: - { - static constexpr Format info(GL_COMPRESSED_RGBA_ASTC_10x6_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_ASTC_10x8_KHR: - { - static constexpr Format info(GL_COMPRESSED_RGBA_ASTC_10x8_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_ASTC_12x10_KHR: - { - static constexpr Format info(GL_COMPRESSED_RGBA_ASTC_12x10_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_ASTC_12x12_KHR: - { - static constexpr Format info(GL_COMPRESSED_RGBA_ASTC_12x12_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_ASTC_4x4_KHR: - { - static constexpr Format info(GL_COMPRESSED_RGBA_ASTC_4x4_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_ASTC_5x4_KHR: - { - static constexpr Format info(GL_COMPRESSED_RGBA_ASTC_5x4_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_ASTC_5x5_KHR: - { - static constexpr Format info(GL_COMPRESSED_RGBA_ASTC_5x5_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_ASTC_6x5_KHR: - { - static constexpr Format info(GL_COMPRESSED_RGBA_ASTC_6x5_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_ASTC_6x6_KHR: - { - static constexpr Format info(GL_COMPRESSED_RGBA_ASTC_6x6_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_ASTC_8x5_KHR: - { - static constexpr Format info(GL_COMPRESSED_RGBA_ASTC_8x5_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_ASTC_8x6_KHR: - { - static constexpr Format info(GL_COMPRESSED_RGBA_ASTC_8x6_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_ASTC_8x8_KHR: - { - static constexpr Format info(GL_COMPRESSED_RGBA_ASTC_8x8_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - { - static constexpr Format info(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, - angle::Format::ID::BC1_RGBA_UNORM_BLOCK, - DXGI_FORMAT_BC1_UNORM, - DXGI_FORMAT_BC1_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_BC1_UNORM, - GL_RGBA8, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: - { - static constexpr Format info(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, - angle::Format::ID::BC2_RGBA_UNORM_BLOCK, - DXGI_FORMAT_BC2_UNORM, - DXGI_FORMAT_BC2_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_BC2_UNORM, - GL_RGBA8, - nullptr); - return info; - } - case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: - { - static constexpr Format info(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, - angle::Format::ID::BC3_RGBA_UNORM_BLOCK, - DXGI_FORMAT_BC3_UNORM, - DXGI_FORMAT_BC3_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_BC3_UNORM, - GL_RGBA8, - nullptr); - return info; - } - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - { - static constexpr Format info(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, - angle::Format::ID::BC1_RGB_UNORM_BLOCK, - DXGI_FORMAT_BC1_UNORM, - DXGI_FORMAT_BC1_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_BC1_UNORM, - GL_RGBA8, - nullptr); - return info; - } - case GL_COMPRESSED_SIGNED_R11_EAC: - { - static constexpr Format info(GL_COMPRESSED_SIGNED_R11_EAC, - angle::Format::ID::R8_SNORM, - DXGI_FORMAT_R8_SNORM, - DXGI_FORMAT_R8_SNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8_SNORM, - GL_RGBA8_SNORM, - nullptr); - return info; - } - case GL_COMPRESSED_SIGNED_RG11_EAC: - { - static constexpr Format info(GL_COMPRESSED_SIGNED_RG11_EAC, - angle::Format::ID::R8G8_SNORM, - DXGI_FORMAT_R8G8_SNORM, - DXGI_FORMAT_R8G8_SNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8_SNORM, - GL_RGBA8_SNORM, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, - angle::Format::ID::R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - GL_SRGB8_ALPHA8, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_ETC2: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_ETC2, - angle::Format::ID::R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - GL_SRGB8_ALPHA8, - Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>); - return info; - } - case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, - angle::Format::ID::BC1_RGB_UNORM_SRGB_BLOCK, - DXGI_FORMAT_BC1_UNORM_SRGB, - DXGI_FORMAT_BC1_UNORM_SRGB, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_BC1_UNORM_SRGB, - GL_RGBA8, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, - angle::Format::ID::R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - GL_SRGB8_ALPHA8, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: - { - static constexpr Format info(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, - angle::Format::ID::BC1_RGBA_UNORM_SRGB_BLOCK, - DXGI_FORMAT_BC1_UNORM_SRGB, - DXGI_FORMAT_BC1_UNORM_SRGB, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_BC1_UNORM_SRGB, - GL_RGBA8, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: - { - static constexpr Format info(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, - angle::Format::ID::BC1_RGBA_UNORM_SRGB_BLOCK, - DXGI_FORMAT_BC1_UNORM_SRGB, - DXGI_FORMAT_BC1_UNORM_SRGB, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_BC1_UNORM_SRGB, - GL_RGBA8, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: - { - static constexpr Format info(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, - angle::Format::ID::BC2_RGBA_UNORM_SRGB_BLOCK, - DXGI_FORMAT_BC2_UNORM_SRGB, - DXGI_FORMAT_BC2_UNORM_SRGB, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_BC2_UNORM_SRGB, - GL_RGBA8, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: - { - static constexpr Format info(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, - angle::Format::ID::BC3_RGBA_UNORM_SRGB_BLOCK, - DXGI_FORMAT_BC3_UNORM_SRGB, - DXGI_FORMAT_BC3_UNORM_SRGB, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_BC3_UNORM_SRGB, - GL_RGBA8, - nullptr); - return info; - } - case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: - { - static constexpr Format info(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, - angle::Format::ID::BC1_RGB_UNORM_SRGB_BLOCK, - DXGI_FORMAT_BC1_UNORM_SRGB, - DXGI_FORMAT_BC1_UNORM_SRGB, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_BC1_UNORM_SRGB, - GL_RGBA8, - nullptr); - return info; - } - case GL_DEPTH24_STENCIL8: - { - if (OnlyFL10Plus(deviceCaps)) - { - static constexpr Format info(GL_DEPTH24_STENCIL8, - angle::Format::ID::D24_UNORM_S8_UINT, - DXGI_FORMAT_R24G8_TYPELESS, - DXGI_FORMAT_R24_UNORM_X8_TYPELESS, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_D24_UNORM_S8_UINT, - DXGI_FORMAT_R24_UNORM_X8_TYPELESS, - GL_RGBA32F, - nullptr); - return info; - } - else - { - static constexpr Format info(GL_DEPTH24_STENCIL8, - angle::Format::ID::D24_UNORM_S8_UINT, - DXGI_FORMAT_D24_UNORM_S8_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_D24_UNORM_S8_UINT, - DXGI_FORMAT_UNKNOWN, - GL_RGBA32F, - nullptr); - return info; - } - } - case GL_DEPTH32F_STENCIL8: - { - static constexpr Format info(GL_DEPTH32F_STENCIL8, - angle::Format::ID::D32_FLOAT_S8X24_UINT, - DXGI_FORMAT_R32G8X24_TYPELESS, - DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_D32_FLOAT_S8X24_UINT, - DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, - GL_RGBA32F, - nullptr); - return info; - } - case GL_DEPTH_COMPONENT16: - { - if (OnlyFL10Plus(deviceCaps)) - { - static constexpr Format info(GL_DEPTH_COMPONENT16, - angle::Format::ID::D16_UNORM, - DXGI_FORMAT_R16_TYPELESS, - DXGI_FORMAT_R16_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_D16_UNORM, - DXGI_FORMAT_R16_UNORM, - GL_RGBA16_EXT, - nullptr); - return info; - } - else - { - static constexpr Format info(GL_DEPTH_COMPONENT16, - angle::Format::ID::D16_UNORM, - DXGI_FORMAT_D16_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_D16_UNORM, - DXGI_FORMAT_UNKNOWN, - GL_RGBA16_EXT, - nullptr); - return info; - } - } - case GL_DEPTH_COMPONENT24: - { - if (OnlyFL10Plus(deviceCaps)) - { - static constexpr Format info(GL_DEPTH_COMPONENT24, - angle::Format::ID::D24_UNORM_S8_UINT, - DXGI_FORMAT_R24G8_TYPELESS, - DXGI_FORMAT_R24_UNORM_X8_TYPELESS, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_D24_UNORM_S8_UINT, - DXGI_FORMAT_R24_UNORM_X8_TYPELESS, - GL_RGBA32F, - nullptr); - return info; - } - else - { - static constexpr Format info(GL_DEPTH_COMPONENT24, - angle::Format::ID::D24_UNORM_S8_UINT, - DXGI_FORMAT_D24_UNORM_S8_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_D24_UNORM_S8_UINT, - DXGI_FORMAT_UNKNOWN, - GL_RGBA32F, - nullptr); - return info; - } - } - case GL_DEPTH_COMPONENT32F: - { - static constexpr Format info(GL_DEPTH_COMPONENT32F, - angle::Format::ID::D32_FLOAT, - DXGI_FORMAT_R32_TYPELESS, - DXGI_FORMAT_R32_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_D32_FLOAT, - DXGI_FORMAT_R32_FLOAT, - GL_RGBA32F, - nullptr); - return info; - } - case GL_DEPTH_COMPONENT32_OES: - { - if (OnlyFL10Plus(deviceCaps)) - { - static constexpr Format info(GL_DEPTH_COMPONENT32_OES, - angle::Format::ID::D24_UNORM_S8_UINT, - DXGI_FORMAT_R24G8_TYPELESS, - DXGI_FORMAT_R24_UNORM_X8_TYPELESS, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_D24_UNORM_S8_UINT, - DXGI_FORMAT_R24_UNORM_X8_TYPELESS, - GL_RGBA32F, - nullptr); - return info; - } - else - { - static constexpr Format info(GL_DEPTH_COMPONENT32_OES, - angle::Format::ID::D24_UNORM_S8_UINT, - DXGI_FORMAT_D24_UNORM_S8_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_D24_UNORM_S8_UINT, - DXGI_FORMAT_UNKNOWN, - GL_RGBA32F, - nullptr); - return info; - } - } - case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: - { - static constexpr Format info(GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, - angle::Format::ID::BC1_RGB_UNORM_BLOCK, - DXGI_FORMAT_BC1_UNORM, - DXGI_FORMAT_BC1_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_BC1_UNORM, - GL_RGBA8, - nullptr); - return info; - } - case GL_ETC1_RGB8_OES: - { - static constexpr Format info(GL_ETC1_RGB8_OES, - angle::Format::ID::R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM, - GL_RGBA8, - Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>); - return info; - } - case GL_LUMINANCE16F_EXT: - { - static constexpr Format info(GL_LUMINANCE16F_EXT, - angle::Format::ID::R16G16B16A16_FLOAT, - DXGI_FORMAT_R16G16B16A16_FLOAT, - DXGI_FORMAT_R16G16B16A16_FLOAT, - DXGI_FORMAT_R16G16B16A16_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16B16A16_FLOAT, - GL_RGBA16F, - Initialize4ComponentData<GLhalf, 0x0000, 0x0000, 0x0000, gl::Float16One>); - return info; - } - case GL_LUMINANCE32F_EXT: - { - static constexpr Format info(GL_LUMINANCE32F_EXT, - angle::Format::ID::R32G32B32A32_FLOAT, - DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R32G32B32A32_FLOAT, - GL_RGBA32F, - Initialize4ComponentData<GLfloat, 0x00000000, 0x00000000, 0x00000000, gl::Float32One>); - return info; - } - case GL_LUMINANCE8_ALPHA8_EXT: - { - static constexpr Format info(GL_LUMINANCE8_ALPHA8_EXT, - angle::Format::ID::R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM, - GL_RGBA8, - nullptr); - return info; - } - case GL_LUMINANCE8_EXT: - { - static constexpr Format info(GL_LUMINANCE8_EXT, - angle::Format::ID::R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM, - GL_RGBA8, - Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>); - return info; - } - case GL_LUMINANCE_ALPHA16F_EXT: - { - static constexpr Format info(GL_LUMINANCE_ALPHA16F_EXT, - angle::Format::ID::R16G16B16A16_FLOAT, - DXGI_FORMAT_R16G16B16A16_FLOAT, - DXGI_FORMAT_R16G16B16A16_FLOAT, - DXGI_FORMAT_R16G16B16A16_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16B16A16_FLOAT, - GL_RGBA16F, - nullptr); - return info; - } - case GL_LUMINANCE_ALPHA32F_EXT: - { - static constexpr Format info(GL_LUMINANCE_ALPHA32F_EXT, - angle::Format::ID::R32G32B32A32_FLOAT, - DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R32G32B32A32_FLOAT, - GL_RGBA32F, - nullptr); - return info; - } - case GL_NONE: - { - static constexpr Format info(GL_NONE, - angle::Format::ID::NONE, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - GL_NONE, - nullptr); - return info; - } - case GL_R11F_G11F_B10F: - { - static constexpr Format info(GL_R11F_G11F_B10F, - angle::Format::ID::R11G11B10_FLOAT, - DXGI_FORMAT_R11G11B10_FLOAT, - DXGI_FORMAT_R11G11B10_FLOAT, - DXGI_FORMAT_R11G11B10_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R11G11B10_FLOAT, - GL_RGBA16F_EXT, - nullptr); - return info; - } - case GL_R16F: - { - static constexpr Format info(GL_R16F, - angle::Format::ID::R16_FLOAT, - DXGI_FORMAT_R16_FLOAT, - DXGI_FORMAT_R16_FLOAT, - DXGI_FORMAT_R16_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16_FLOAT, - GL_RGBA16F_EXT, - nullptr); - return info; - } - case GL_R16I: - { - static constexpr Format info(GL_R16I, - angle::Format::ID::R16_SINT, - DXGI_FORMAT_R16_SINT, - DXGI_FORMAT_R16_SINT, - DXGI_FORMAT_R16_SINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16_SINT, - GL_RGBA16I, - nullptr); - return info; - } - case GL_R16UI: - { - static constexpr Format info(GL_R16UI, - angle::Format::ID::R16_UINT, - DXGI_FORMAT_R16_UINT, - DXGI_FORMAT_R16_UINT, - DXGI_FORMAT_R16_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16_UINT, - GL_RGBA16I, - nullptr); - return info; - } - case GL_R16_EXT: - { - static constexpr Format info(GL_R16_EXT, - angle::Format::ID::R16_UNORM, - DXGI_FORMAT_R16_UNORM, - DXGI_FORMAT_R16_UNORM, - DXGI_FORMAT_R16_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16_UNORM, - GL_RGBA16_EXT, - nullptr); - return info; - } - case GL_R16_SNORM_EXT: - { - static constexpr Format info(GL_R16_SNORM_EXT, - angle::Format::ID::R16_SNORM, - DXGI_FORMAT_R16_SNORM, - DXGI_FORMAT_R16_SNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16_SNORM, - GL_RGBA16_SNORM_EXT, - nullptr); - return info; - } - case GL_R32F: - { - static constexpr Format info(GL_R32F, - angle::Format::ID::R32_FLOAT, - DXGI_FORMAT_R32_FLOAT, - DXGI_FORMAT_R32_FLOAT, - DXGI_FORMAT_R32_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R32_FLOAT, - GL_RGBA32F, - nullptr); - return info; - } - case GL_R32I: - { - static constexpr Format info(GL_R32I, - angle::Format::ID::R32_SINT, - DXGI_FORMAT_R32_SINT, - DXGI_FORMAT_R32_SINT, - DXGI_FORMAT_R32_SINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R32_SINT, - GL_RGBA32I, - nullptr); - return info; - } - case GL_R32UI: - { - static constexpr Format info(GL_R32UI, - angle::Format::ID::R32_UINT, - DXGI_FORMAT_R32_UINT, - DXGI_FORMAT_R32_UINT, - DXGI_FORMAT_R32_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R32_UINT, - GL_RGBA32I, - nullptr); - return info; - } - case GL_R8: - { - static constexpr Format info(GL_R8, - angle::Format::ID::R8_UNORM, - DXGI_FORMAT_R8_UNORM, - DXGI_FORMAT_R8_UNORM, - DXGI_FORMAT_R8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8_UNORM, - GL_RGBA8, - nullptr); - return info; - } - case GL_R8I: - { - static constexpr Format info(GL_R8I, - angle::Format::ID::R8_SINT, - DXGI_FORMAT_R8_SINT, - DXGI_FORMAT_R8_SINT, - DXGI_FORMAT_R8_SINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8_SINT, - GL_RGBA8I, - nullptr); - return info; - } - case GL_R8UI: - { - static constexpr Format info(GL_R8UI, - angle::Format::ID::R8_UINT, - DXGI_FORMAT_R8_UINT, - DXGI_FORMAT_R8_UINT, - DXGI_FORMAT_R8_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8_UINT, - GL_RGBA8I, - nullptr); - return info; - } - case GL_R8_SNORM: - { - static constexpr Format info(GL_R8_SNORM, - angle::Format::ID::R8_SNORM, - DXGI_FORMAT_R8_SNORM, - DXGI_FORMAT_R8_SNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8_SNORM, - GL_RGBA8_SNORM, - nullptr); - return info; - } - case GL_RG16F: - { - static constexpr Format info(GL_RG16F, - angle::Format::ID::R16G16_FLOAT, - DXGI_FORMAT_R16G16_FLOAT, - DXGI_FORMAT_R16G16_FLOAT, - DXGI_FORMAT_R16G16_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16_FLOAT, - GL_RGBA16F_EXT, - nullptr); - return info; - } - case GL_RG16I: - { - static constexpr Format info(GL_RG16I, - angle::Format::ID::R16G16_SINT, - DXGI_FORMAT_R16G16_SINT, - DXGI_FORMAT_R16G16_SINT, - DXGI_FORMAT_R16G16_SINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16_SINT, - GL_RGBA16I, - nullptr); - return info; - } - case GL_RG16UI: - { - static constexpr Format info(GL_RG16UI, - angle::Format::ID::R16G16_UINT, - DXGI_FORMAT_R16G16_UINT, - DXGI_FORMAT_R16G16_UINT, - DXGI_FORMAT_R16G16_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16_UINT, - GL_RGBA16I, - nullptr); - return info; - } - case GL_RG16_EXT: - { - static constexpr Format info(GL_RG16_EXT, - angle::Format::ID::R16G16_UNORM, - DXGI_FORMAT_R16G16_UNORM, - DXGI_FORMAT_R16G16_UNORM, - DXGI_FORMAT_R16G16_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16_UNORM, - GL_RGBA16_EXT, - nullptr); - return info; - } - case GL_RG16_SNORM_EXT: - { - static constexpr Format info(GL_RG16_SNORM_EXT, - angle::Format::ID::R16G16_SNORM, - DXGI_FORMAT_R16G16_SNORM, - DXGI_FORMAT_R16G16_SNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16_SNORM, - GL_RGBA16_SNORM_EXT, - nullptr); - return info; - } - case GL_RG32F: - { - static constexpr Format info(GL_RG32F, - angle::Format::ID::R32G32_FLOAT, - DXGI_FORMAT_R32G32_FLOAT, - DXGI_FORMAT_R32G32_FLOAT, - DXGI_FORMAT_R32G32_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R32G32_FLOAT, - GL_RGBA32F, - nullptr); - return info; - } - case GL_RG32I: - { - static constexpr Format info(GL_RG32I, - angle::Format::ID::R32G32_SINT, - DXGI_FORMAT_R32G32_SINT, - DXGI_FORMAT_R32G32_SINT, - DXGI_FORMAT_R32G32_SINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R32G32_SINT, - GL_RGBA32I, - nullptr); - return info; - } - case GL_RG32UI: - { - static constexpr Format info(GL_RG32UI, - angle::Format::ID::R32G32_UINT, - DXGI_FORMAT_R32G32_UINT, - DXGI_FORMAT_R32G32_UINT, - DXGI_FORMAT_R32G32_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R32G32_UINT, - GL_RGBA32I, - nullptr); - return info; - } - case GL_RG8: - { - static constexpr Format info(GL_RG8, - angle::Format::ID::R8G8_UNORM, - DXGI_FORMAT_R8G8_UNORM, - DXGI_FORMAT_R8G8_UNORM, - DXGI_FORMAT_R8G8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8_UNORM, - GL_RGBA8, - nullptr); - return info; - } - case GL_RG8I: - { - static constexpr Format info(GL_RG8I, - angle::Format::ID::R8G8_SINT, - DXGI_FORMAT_R8G8_SINT, - DXGI_FORMAT_R8G8_SINT, - DXGI_FORMAT_R8G8_SINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8_SINT, - GL_RGBA8I, - nullptr); - return info; - } - case GL_RG8UI: - { - static constexpr Format info(GL_RG8UI, - angle::Format::ID::R8G8_UINT, - DXGI_FORMAT_R8G8_UINT, - DXGI_FORMAT_R8G8_UINT, - DXGI_FORMAT_R8G8_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8_UINT, - GL_RGBA8I, - nullptr); - return info; - } - case GL_RG8_SNORM: - { - static constexpr Format info(GL_RG8_SNORM, - angle::Format::ID::R8G8_SNORM, - DXGI_FORMAT_R8G8_SNORM, - DXGI_FORMAT_R8G8_SNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8_SNORM, - GL_RGBA8_SNORM, - nullptr); - return info; - } - case GL_RGB: - { - static constexpr Format info(GL_RGB, - angle::Format::ID::R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM, - GL_RGBA8, - Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>); - return info; - } - case GL_RGB10_A2: - { - static constexpr Format info(GL_RGB10_A2, - angle::Format::ID::R10G10B10A2_UNORM, - DXGI_FORMAT_R10G10B10A2_UNORM, - DXGI_FORMAT_R10G10B10A2_UNORM, - DXGI_FORMAT_R10G10B10A2_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R10G10B10A2_UNORM, - GL_RGBA16_EXT, - nullptr); - return info; - } - case GL_RGB10_A2UI: - { - static constexpr Format info(GL_RGB10_A2UI, - angle::Format::ID::R10G10B10A2_UINT, - DXGI_FORMAT_R10G10B10A2_UINT, - DXGI_FORMAT_R10G10B10A2_UINT, - DXGI_FORMAT_R10G10B10A2_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R10G10B10A2_UINT, - GL_RGBA16I, - nullptr); - return info; - } - case GL_RGB16F: - { - static constexpr Format info(GL_RGB16F, - angle::Format::ID::R16G16B16A16_FLOAT, - DXGI_FORMAT_R16G16B16A16_FLOAT, - DXGI_FORMAT_R16G16B16A16_FLOAT, - DXGI_FORMAT_R16G16B16A16_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16B16A16_FLOAT, - GL_RGBA16F, - Initialize4ComponentData<GLhalf, 0x0000, 0x0000, 0x0000, gl::Float16One>); - return info; - } - case GL_RGB16I: - { - static constexpr Format info(GL_RGB16I, - angle::Format::ID::R16G16B16A16_SINT, - DXGI_FORMAT_R16G16B16A16_SINT, - DXGI_FORMAT_R16G16B16A16_SINT, - DXGI_FORMAT_R16G16B16A16_SINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16B16A16_SINT, - GL_RGBA16I, - Initialize4ComponentData<GLshort, 0x0000, 0x0000, 0x0000, 0x0001>); - return info; - } - case GL_RGB16UI: - { - static constexpr Format info(GL_RGB16UI, - angle::Format::ID::R16G16B16A16_UINT, - DXGI_FORMAT_R16G16B16A16_UINT, - DXGI_FORMAT_R16G16B16A16_UINT, - DXGI_FORMAT_R16G16B16A16_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16B16A16_UINT, - GL_RGBA16UI, - Initialize4ComponentData<GLushort, 0x0000, 0x0000, 0x0000, 0x0001>); - return info; - } - case GL_RGB16_EXT: - { - static constexpr Format info(GL_RGB16_EXT, - angle::Format::ID::R16G16B16A16_UNORM, - DXGI_FORMAT_R16G16B16A16_UNORM, - DXGI_FORMAT_R16G16B16A16_UNORM, - DXGI_FORMAT_R16G16B16A16_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16B16A16_UNORM, - GL_RGBA16_EXT, - Initialize4ComponentData<GLubyte, 0x0000, 0x0000, 0x0000, 0xFFFF>); - return info; - } - case GL_RGB16_SNORM_EXT: - { - static constexpr Format info(GL_RGB16_SNORM_EXT, - angle::Format::ID::R16G16B16A16_SNORM, - DXGI_FORMAT_R16G16B16A16_SNORM, - DXGI_FORMAT_R16G16B16A16_SNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16B16A16_SNORM, - GL_RGBA16_SNORM_EXT, - Initialize4ComponentData<GLushort, 0x0000, 0x0000, 0x0000, 0x7FFF>); - return info; - } - case GL_RGB32F: - { - static constexpr Format info(GL_RGB32F, - angle::Format::ID::R32G32B32A32_FLOAT, - DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R32G32B32A32_FLOAT, - GL_RGBA32F, - Initialize4ComponentData<GLfloat, 0x00000000, 0x00000000, 0x00000000, gl::Float32One>); - return info; - } - case GL_RGB32I: - { - static constexpr Format info(GL_RGB32I, - angle::Format::ID::R32G32B32A32_SINT, - DXGI_FORMAT_R32G32B32A32_SINT, - DXGI_FORMAT_R32G32B32A32_SINT, - DXGI_FORMAT_R32G32B32A32_SINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R32G32B32A32_SINT, - GL_RGBA32I, - Initialize4ComponentData<GLint, 0x00000000, 0x00000000, 0x00000000, 0x00000001>); - return info; - } - case GL_RGB32UI: - { - static constexpr Format info(GL_RGB32UI, - angle::Format::ID::R32G32B32A32_UINT, - DXGI_FORMAT_R32G32B32A32_UINT, - DXGI_FORMAT_R32G32B32A32_UINT, - DXGI_FORMAT_R32G32B32A32_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R32G32B32A32_UINT, - GL_RGBA32UI, - Initialize4ComponentData<GLuint, 0x00000000, 0x00000000, 0x00000000, 0x00000001>); - return info; - } - case GL_RGB565: - { - if (SupportsFormat(DXGI_FORMAT_B5G6R5_UNORM, deviceCaps)) - { - static constexpr Format info(GL_RGB565, - angle::Format::ID::B5G6R5_UNORM, - DXGI_FORMAT_B5G6R5_UNORM, - DXGI_FORMAT_B5G6R5_UNORM, - DXGI_FORMAT_B5G6R5_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_B5G6R5_UNORM, - GL_RGBA8, - nullptr); - return info; - } - else - { - static constexpr Format info(GL_RGB565, - angle::Format::ID::R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM, - GL_RGBA8, - Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>); - return info; - } - } - case GL_RGB5_A1: - { - if (SupportsFormat(DXGI_FORMAT_B5G5R5A1_UNORM, deviceCaps)) - { - static constexpr Format info(GL_RGB5_A1, - angle::Format::ID::B5G5R5A1_UNORM, - DXGI_FORMAT_B5G5R5A1_UNORM, - DXGI_FORMAT_B5G5R5A1_UNORM, - DXGI_FORMAT_B5G5R5A1_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_B5G5R5A1_UNORM, - GL_RGBA8, - nullptr); - return info; - } - else - { - static constexpr Format info(GL_RGB5_A1, - angle::Format::ID::R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM, - GL_RGBA8, - nullptr); - return info; - } - } - case GL_RGB8: - { - static constexpr Format info(GL_RGB8, - angle::Format::ID::R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM, - GL_RGBA8, - Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>); - return info; - } - case GL_RGB8I: - { - static constexpr Format info(GL_RGB8I, - angle::Format::ID::R8G8B8A8_SINT, - DXGI_FORMAT_R8G8B8A8_SINT, - DXGI_FORMAT_R8G8B8A8_SINT, - DXGI_FORMAT_R8G8B8A8_SINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_SINT, - GL_RGBA8I, - Initialize4ComponentData<GLbyte, 0x00, 0x00, 0x00, 0x01>); - return info; - } - case GL_RGB8UI: - { - static constexpr Format info(GL_RGB8UI, - angle::Format::ID::R8G8B8A8_UINT, - DXGI_FORMAT_R8G8B8A8_UINT, - DXGI_FORMAT_R8G8B8A8_UINT, - DXGI_FORMAT_R8G8B8A8_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UINT, - GL_RGBA8UI, - Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0x01>); - return info; - } - case GL_RGB8_SNORM: - { - static constexpr Format info(GL_RGB8_SNORM, - angle::Format::ID::R8G8B8A8_SNORM, - DXGI_FORMAT_R8G8B8A8_SNORM, - DXGI_FORMAT_R8G8B8A8_SNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_SNORM, - GL_RGBA8_SNORM, - Initialize4ComponentData<GLbyte, 0x00, 0x00, 0x00, 0x7F>); - return info; - } - case GL_RGB9_E5: - { - static constexpr Format info(GL_RGB9_E5, - angle::Format::ID::R9G9B9E5_SHAREDEXP, - DXGI_FORMAT_R9G9B9E5_SHAREDEXP, - DXGI_FORMAT_R9G9B9E5_SHAREDEXP, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R9G9B9E5_SHAREDEXP, - GL_RGBA16F_EXT, - nullptr); - return info; - } - case GL_RGBA: - { - static constexpr Format info(GL_RGBA, - angle::Format::ID::R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM, - GL_RGBA8, - nullptr); - return info; - } - case GL_RGBA16F: - { - static constexpr Format info(GL_RGBA16F, - angle::Format::ID::R16G16B16A16_FLOAT, - DXGI_FORMAT_R16G16B16A16_FLOAT, - DXGI_FORMAT_R16G16B16A16_FLOAT, - DXGI_FORMAT_R16G16B16A16_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16B16A16_FLOAT, - GL_RGBA16F, - nullptr); - return info; - } - case GL_RGBA16I: - { - static constexpr Format info(GL_RGBA16I, - angle::Format::ID::R16G16B16A16_SINT, - DXGI_FORMAT_R16G16B16A16_SINT, - DXGI_FORMAT_R16G16B16A16_SINT, - DXGI_FORMAT_R16G16B16A16_SINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16B16A16_SINT, - GL_RGBA16I, - nullptr); - return info; - } - case GL_RGBA16UI: - { - static constexpr Format info(GL_RGBA16UI, - angle::Format::ID::R16G16B16A16_UINT, - DXGI_FORMAT_R16G16B16A16_UINT, - DXGI_FORMAT_R16G16B16A16_UINT, - DXGI_FORMAT_R16G16B16A16_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16B16A16_UINT, - GL_RGBA16UI, - nullptr); - return info; - } - case GL_RGBA16_EXT: - { - static constexpr Format info(GL_RGBA16_EXT, - angle::Format::ID::R16G16B16A16_UNORM, - DXGI_FORMAT_R16G16B16A16_UNORM, - DXGI_FORMAT_R16G16B16A16_UNORM, - DXGI_FORMAT_R16G16B16A16_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16B16A16_UNORM, - GL_RGBA16_EXT, - nullptr); - return info; - } - case GL_RGBA16_SNORM_EXT: - { - static constexpr Format info(GL_RGBA16_SNORM_EXT, - angle::Format::ID::R16G16B16A16_SNORM, - DXGI_FORMAT_R16G16B16A16_SNORM, - DXGI_FORMAT_R16G16B16A16_SNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R16G16B16A16_SNORM, - GL_RGBA16_SNORM_EXT, - nullptr); - return info; - } - case GL_RGBA32F: - { - static constexpr Format info(GL_RGBA32F, - angle::Format::ID::R32G32B32A32_FLOAT, - DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R32G32B32A32_FLOAT, - GL_RGBA32F, - nullptr); - return info; - } - case GL_RGBA32I: - { - static constexpr Format info(GL_RGBA32I, - angle::Format::ID::R32G32B32A32_SINT, - DXGI_FORMAT_R32G32B32A32_SINT, - DXGI_FORMAT_R32G32B32A32_SINT, - DXGI_FORMAT_R32G32B32A32_SINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R32G32B32A32_SINT, - GL_RGBA32I, - nullptr); - return info; - } - case GL_RGBA32UI: - { - static constexpr Format info(GL_RGBA32UI, - angle::Format::ID::R32G32B32A32_UINT, - DXGI_FORMAT_R32G32B32A32_UINT, - DXGI_FORMAT_R32G32B32A32_UINT, - DXGI_FORMAT_R32G32B32A32_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R32G32B32A32_UINT, - GL_RGBA32UI, - nullptr); - return info; - } - case GL_RGBA4: - { - if (SupportsFormat(DXGI_FORMAT_B4G4R4A4_UNORM, deviceCaps)) - { - static constexpr Format info(GL_RGBA4, - angle::Format::ID::B4G4R4A4_UNORM, - DXGI_FORMAT_B4G4R4A4_UNORM, - DXGI_FORMAT_B4G4R4A4_UNORM, - DXGI_FORMAT_B4G4R4A4_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_B4G4R4A4_UNORM, - GL_RGBA4, - nullptr); - return info; - } - else - { - static constexpr Format info(GL_RGBA4, - angle::Format::ID::R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM, - GL_RGBA8, - nullptr); - return info; - } - } - case GL_RGBA8: - { - static constexpr Format info(GL_RGBA8, - angle::Format::ID::R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_R8G8B8A8_UNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM, - GL_RGBA8, - nullptr); - return info; - } - case GL_RGBA8I: - { - static constexpr Format info(GL_RGBA8I, - angle::Format::ID::R8G8B8A8_SINT, - DXGI_FORMAT_R8G8B8A8_SINT, - DXGI_FORMAT_R8G8B8A8_SINT, - DXGI_FORMAT_R8G8B8A8_SINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_SINT, - GL_RGBA8I, - nullptr); - return info; - } - case GL_RGBA8UI: - { - static constexpr Format info(GL_RGBA8UI, - angle::Format::ID::R8G8B8A8_UINT, - DXGI_FORMAT_R8G8B8A8_UINT, - DXGI_FORMAT_R8G8B8A8_UINT, - DXGI_FORMAT_R8G8B8A8_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UINT, - GL_RGBA8UI, - nullptr); - return info; - } - case GL_RGBA8_SNORM: - { - static constexpr Format info(GL_RGBA8_SNORM, - angle::Format::ID::R8G8B8A8_SNORM, - DXGI_FORMAT_R8G8B8A8_SNORM, - DXGI_FORMAT_R8G8B8A8_SNORM, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_SNORM, - GL_RGBA8_SNORM, - nullptr); - return info; - } - case GL_SRGB8: - { - static constexpr Format info(GL_SRGB8, - angle::Format::ID::R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - GL_SRGB8_ALPHA8, - Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>); - return info; - } - case GL_SRGB8_ALPHA8: - { - static constexpr Format info(GL_SRGB8_ALPHA8, - angle::Format::ID::R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - GL_SRGB8_ALPHA8, - nullptr); - return info; - } - case GL_STENCIL_INDEX8: - { - if (OnlyFL10Plus(deviceCaps)) - { - static constexpr Format info(GL_STENCIL_INDEX8, - angle::Format::ID::D24_UNORM_S8_UINT, - DXGI_FORMAT_R24G8_TYPELESS, - DXGI_FORMAT_R24_UNORM_X8_TYPELESS, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_D24_UNORM_S8_UINT, - DXGI_FORMAT_R24_UNORM_X8_TYPELESS, - GL_RGBA32F, - nullptr); - return info; - } - else - { - static constexpr Format info(GL_STENCIL_INDEX8, - angle::Format::ID::D24_UNORM_S8_UINT, - DXGI_FORMAT_D24_UNORM_S8_UINT, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_UNKNOWN, - DXGI_FORMAT_D24_UNORM_S8_UINT, - DXGI_FORMAT_UNKNOWN, - GL_RGBA32F, - nullptr); - return info; - } - } - - default: - break; - } - // clang-format on - - UNREACHABLE(); - static constexpr Format defaultInfo; - return defaultInfo; -} - -} // namespace d3d11 - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_table_utils.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_table_utils.h deleted file mode 100644 index d5351ff882..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_table_utils.h +++ /dev/null @@ -1,85 +0,0 @@ -// -// Copyright 2016 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// Helper routines for the D3D11 texture format table. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_TEXTURE_FORMAT_TABLE_UTILS_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_TEXTURE_FORMAT_TABLE_UTILS_H_ - -#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" - -namespace rx -{ - -namespace d3d11 -{ - -using FormatSupportFunction = bool (*)(const Renderer11DeviceCaps &); - -inline bool OnlyFL10Plus(const Renderer11DeviceCaps &deviceCaps) -{ - return (deviceCaps.featureLevel >= D3D_FEATURE_LEVEL_10_0); -} - -inline bool OnlyFL9_3(const Renderer11DeviceCaps &deviceCaps) -{ - return (deviceCaps.featureLevel == D3D_FEATURE_LEVEL_9_3); -} - -inline bool SupportsFormat(DXGI_FORMAT format, const Renderer11DeviceCaps &deviceCaps) -{ - // Must support texture, SRV and RTV support - UINT mustSupport = D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURECUBE | - D3D11_FORMAT_SUPPORT_SHADER_SAMPLE | D3D11_FORMAT_SUPPORT_MIP | - D3D11_FORMAT_SUPPORT_RENDER_TARGET; - UINT minimumRequiredSamples = 0; - - if (d3d11_gl::GetMaximumClientVersion(deviceCaps.featureLevel).major > 2) - { - mustSupport |= D3D11_FORMAT_SUPPORT_TEXTURE3D; - - // RGBA4, RGB5A1 and RGB565 are all required multisampled renderbuffer formats in ES3 and - // need to support a minimum of 4 samples. - minimumRequiredSamples = 4; - } - - bool fullSupport = false; - if (format == DXGI_FORMAT_B5G6R5_UNORM) - { - // All hardware that supports DXGI_FORMAT_B5G6R5_UNORM should support autogen mipmaps, but - // check anyway. - mustSupport |= D3D11_FORMAT_SUPPORT_MIP_AUTOGEN; - fullSupport = ((deviceCaps.B5G6R5support & mustSupport) == mustSupport) && - deviceCaps.B5G6R5maxSamples >= minimumRequiredSamples; - } - else if (format == DXGI_FORMAT_B4G4R4A4_UNORM) - { - fullSupport = ((deviceCaps.B4G4R4A4support & mustSupport) == mustSupport) && - deviceCaps.B4G4R4A4maxSamples >= minimumRequiredSamples; - } - else if (format == DXGI_FORMAT_B5G5R5A1_UNORM) - { - fullSupport = ((deviceCaps.B5G5R5A1support & mustSupport) == mustSupport) && - deviceCaps.B5G5R5A1maxSamples >= minimumRequiredSamples; - } - else - { - UNREACHABLE(); - return false; - } - - // This means that ANGLE would like to use the entry in the map if the inputted DXGI format - // *IS* supported. - // e.g. the entry might map GL_RGB5_A1 to DXGI_FORMAT_B5G5R5A1, which should only be used if - // DXGI_FORMAT_B5G5R5A1 is supported. - // In this case, we should only return 'true' if the format *IS* supported. - return fullSupport; -} - -} // namespace d3d11 - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_TEXTURE_FORMAT_TABLE_UTILS_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.cpp deleted file mode 100644 index f5e6c93813..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.cpp +++ /dev/null @@ -1,217 +0,0 @@ -// -// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// NativeWindow11Win32.cpp: Implementation of NativeWindow11 using win32 window APIs. - -#include "libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.h" -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" - -#include "common/debug.h" - -#include <initguid.h> -#include <dcomp.h> - -namespace rx -{ - -NativeWindow11Win32::NativeWindow11Win32(EGLNativeWindowType window, - bool hasAlpha, - bool directComposition) - : NativeWindow11(window), - mDirectComposition(directComposition), - mHasAlpha(hasAlpha), - mDevice(nullptr), - mCompositionTarget(nullptr), - mVisual(nullptr) -{ -} - -NativeWindow11Win32::~NativeWindow11Win32() -{ - SafeRelease(mCompositionTarget); - SafeRelease(mDevice); - SafeRelease(mVisual); -} - -bool NativeWindow11Win32::initialize() -{ - return true; -} - -bool NativeWindow11Win32::getClientRect(LPRECT rect) const -{ - return GetClientRect(getNativeWindow(), rect) == TRUE; -} - -bool NativeWindow11Win32::isIconic() const -{ - return IsIconic(getNativeWindow()) == TRUE; -} - -HRESULT NativeWindow11Win32::createSwapChain(ID3D11Device *device, - IDXGIFactory *factory, - DXGI_FORMAT format, - UINT width, - UINT height, - UINT samples, - IDXGISwapChain **swapChain) -{ - if (device == nullptr || factory == nullptr || swapChain == nullptr || width == 0 || - height == 0) - { - return E_INVALIDARG; - } - - if (mDirectComposition) - { - HMODULE dcomp = ::GetModuleHandle(TEXT("dcomp.dll")); - if (!dcomp) - { - return E_INVALIDARG; - } - - typedef HRESULT(WINAPI * PFN_DCOMPOSITION_CREATE_DEVICE)( - IDXGIDevice * dxgiDevice, REFIID iid, void **dcompositionDevice); - PFN_DCOMPOSITION_CREATE_DEVICE createDComp = - reinterpret_cast<PFN_DCOMPOSITION_CREATE_DEVICE>( - GetProcAddress(dcomp, "DCompositionCreateDevice")); - if (!createDComp) - { - return E_INVALIDARG; - } - - if (!mDevice) - { - IDXGIDevice *dxgiDevice = d3d11::DynamicCastComObject<IDXGIDevice>(device); - HRESULT result = createDComp(dxgiDevice, __uuidof(IDCompositionDevice), - reinterpret_cast<void **>(&mDevice)); - SafeRelease(dxgiDevice); - - if (FAILED(result)) - { - return result; - } - } - - if (!mCompositionTarget) - { - HRESULT result = - mDevice->CreateTargetForHwnd(getNativeWindow(), TRUE, &mCompositionTarget); - if (FAILED(result)) - { - return result; - } - } - - if (!mVisual) - { - HRESULT result = mDevice->CreateVisual(&mVisual); - if (FAILED(result)) - { - return result; - } - } - - IDXGIFactory2 *factory2 = d3d11::DynamicCastComObject<IDXGIFactory2>(factory); - DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0}; - swapChainDesc.Width = width; - swapChainDesc.Height = height; - swapChainDesc.Format = format; - swapChainDesc.Stereo = FALSE; - swapChainDesc.SampleDesc.Count = 1; - swapChainDesc.SampleDesc.Quality = 0; - swapChainDesc.BufferUsage = - DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_BACK_BUFFER | DXGI_USAGE_SHADER_INPUT; - swapChainDesc.BufferCount = 2; - swapChainDesc.Scaling = DXGI_SCALING_STRETCH; - swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; - swapChainDesc.AlphaMode = - mHasAlpha ? DXGI_ALPHA_MODE_PREMULTIPLIED : DXGI_ALPHA_MODE_IGNORE; - swapChainDesc.Flags = 0; - IDXGISwapChain1 *swapChain1 = nullptr; - HRESULT result = - factory2->CreateSwapChainForComposition(device, &swapChainDesc, nullptr, &swapChain1); - if (SUCCEEDED(result)) - { - *swapChain = static_cast<IDXGISwapChain *>(swapChain1); - } - mVisual->SetContent(swapChain1); - mCompositionTarget->SetRoot(mVisual); - SafeRelease(factory2); - return result; - } - - // Use IDXGIFactory2::CreateSwapChainForHwnd if DXGI 1.2 is available to create a - // DXGI_SWAP_EFFECT_SEQUENTIAL swap chain. - IDXGIFactory2 *factory2 = d3d11::DynamicCastComObject<IDXGIFactory2>(factory); - if (factory2 != nullptr) - { - DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0}; - swapChainDesc.Width = width; - swapChainDesc.Height = height; - swapChainDesc.Format = format; - swapChainDesc.Stereo = FALSE; - swapChainDesc.SampleDesc.Count = samples; - swapChainDesc.SampleDesc.Quality = 0; - swapChainDesc.BufferUsage = - DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT | DXGI_USAGE_BACK_BUFFER; - swapChainDesc.BufferCount = 1; - swapChainDesc.Scaling = DXGI_SCALING_STRETCH; - swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL; - swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED; - swapChainDesc.Flags = 0; - IDXGISwapChain1 *swapChain1 = nullptr; - HRESULT result = factory2->CreateSwapChainForHwnd(device, getNativeWindow(), &swapChainDesc, - nullptr, nullptr, &swapChain1); - if (SUCCEEDED(result)) - { - factory2->MakeWindowAssociation(getNativeWindow(), DXGI_MWA_NO_WINDOW_CHANGES); - *swapChain = static_cast<IDXGISwapChain *>(swapChain1); - } - SafeRelease(factory2); - return result; - } - - DXGI_SWAP_CHAIN_DESC swapChainDesc = {}; - swapChainDesc.BufferCount = 1; - swapChainDesc.BufferDesc.Format = format; - swapChainDesc.BufferDesc.Width = width; - swapChainDesc.BufferDesc.Height = height; - swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; - swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; - swapChainDesc.BufferDesc.RefreshRate.Numerator = 0; - swapChainDesc.BufferDesc.RefreshRate.Denominator = 1; - swapChainDesc.BufferUsage = - DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT | DXGI_USAGE_BACK_BUFFER; - swapChainDesc.Flags = 0; - swapChainDesc.OutputWindow = getNativeWindow(); - swapChainDesc.SampleDesc.Count = samples; - swapChainDesc.SampleDesc.Quality = 0; - swapChainDesc.Windowed = TRUE; - swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; - - HRESULT result = factory->CreateSwapChain(device, &swapChainDesc, swapChain); - if (SUCCEEDED(result)) - { - factory->MakeWindowAssociation(getNativeWindow(), DXGI_MWA_NO_WINDOW_CHANGES); - } - return result; -} - -void NativeWindow11Win32::commitChange() -{ - if (mDevice) - { - mDevice->Commit(); - } -} - -// static -bool NativeWindow11Win32::IsValidNativeWindow(EGLNativeWindowType window) -{ - return IsWindow(window) == TRUE; -} -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.h deleted file mode 100644 index baeba6a347..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.h +++ /dev/null @@ -1,53 +0,0 @@ -// -// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// NativeWindow11Win32.h: Implementation of NativeWindow11 using win32 window APIs. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_WIN32_NATIVEWINDOW11WIN32_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_WIN32_NATIVEWINDOW11WIN32_H_ - -#include "libANGLE/renderer/d3d/d3d11/NativeWindow11.h" - -typedef interface IDCompositionDevice IDCompositionDevice; -typedef interface IDCompositionTarget IDCompositionTarget; -typedef interface IDCompositionVisual IDCompositionVisual; - -namespace rx -{ - -class NativeWindow11Win32 : public NativeWindow11 -{ - public: - NativeWindow11Win32(EGLNativeWindowType window, bool hasAlpha, bool directComposition); - ~NativeWindow11Win32() override; - - bool initialize() override; - bool getClientRect(LPRECT rect) const override; - bool isIconic() const override; - - HRESULT createSwapChain(ID3D11Device *device, - IDXGIFactory *factory, - DXGI_FORMAT format, - UINT width, - UINT height, - UINT samples, - IDXGISwapChain **swapChain) override; - - void commitChange() override; - - static bool IsValidNativeWindow(EGLNativeWindowType window); - - private: - bool mDirectComposition; - bool mHasAlpha; - IDCompositionDevice *mDevice; - IDCompositionTarget *mCompositionTarget; - IDCompositionVisual *mVisual; -}; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_WIN32_NATIVEWINDOW11WIN32_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/CoreWindowNativeWindow.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/CoreWindowNativeWindow.cpp deleted file mode 100644 index 1ef90e7b09..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/CoreWindowNativeWindow.cpp +++ /dev/null @@ -1,208 +0,0 @@ -// -// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// CoreWindowNativeWindow.cpp: NativeWindow for managing ICoreWindow native window types. - -#include "libANGLE/renderer/d3d/d3d11/winrt/CoreWindowNativeWindow.h" - -#include <windows.graphics.display.h> - -using namespace ABI::Windows::Foundation::Collections; - -namespace rx -{ -CoreWindowNativeWindow::~CoreWindowNativeWindow() -{ - unregisterForSizeChangeEvents(); -} - -bool CoreWindowNativeWindow::initialize(EGLNativeWindowType window, IPropertySet *propertySet) -{ - ComPtr<IPropertySet> props = propertySet; - ComPtr<IInspectable> win = window; - SIZE swapChainSize = {}; - HRESULT result = S_OK; - - // IPropertySet is an optional parameter and can be null. - // If one is specified, cache as an IMap and read the properties - // used for initial host initialization. - if (propertySet) - { - result = props.As(&mPropertyMap); - if (FAILED(result)) - { - return false; - } - - // The EGLRenderSurfaceSizeProperty is optional and may be missing. The IPropertySet - // was prevalidated to contain the EGLNativeWindowType before being passed to - // this host. - result = GetOptionalSizePropertyValue(mPropertyMap, EGLRenderSurfaceSizeProperty, &swapChainSize, &mSwapChainSizeSpecified); - if (FAILED(result)) - { - return false; - } - - // The EGLRenderResolutionScaleProperty is optional and may be missing. The IPropertySet - // was prevalidated to contain the EGLNativeWindowType before being passed to - // this host. - result = GetOptionalSinglePropertyValue(mPropertyMap, EGLRenderResolutionScaleProperty, &mSwapChainScale, &mSwapChainScaleSpecified); - if (FAILED(result)) - { - return false; - } - - if (!mSwapChainScaleSpecified) - { - // Default value for the scale is 1.0f - mSwapChainScale = 1.0f; - } - - // A EGLRenderSurfaceSizeProperty and a EGLRenderResolutionScaleProperty can't both be specified - if (mSwapChainScaleSpecified && mSwapChainSizeSpecified) - { - ERR() << "It is invalid to specify both an EGLRenderSurfaceSizeProperty and a " - "EGLRenderResolutionScaleProperty."; - return false; - } - } - - if (SUCCEEDED(result)) - { - result = win.As(&mCoreWindow); - } - - if (SUCCEEDED(result)) - { - // If a swapchain size is specfied, then the automatic resize - // behaviors implemented by the host should be disabled. The swapchain - // will be still be scaled when being rendered to fit the bounds - // of the host. - // Scaling of the swapchain output occurs automatically because if - // the scaling mode setting DXGI_SCALING_STRETCH on the swapchain. - if (mSwapChainSizeSpecified) - { - mClientRect = { 0, 0, swapChainSize.cx, swapChainSize.cy }; - } - else - { - Size coreWindowSize; - result = GetCoreWindowSizeInPixels(mCoreWindow, &coreWindowSize); - - if (SUCCEEDED(result)) - { - mClientRect = clientRect(coreWindowSize); - } - } - } - - if (SUCCEEDED(result)) - { - mNewClientRect = mClientRect; - mClientRectChanged = false; - return registerForSizeChangeEvents(); - } - - return false; -} - -bool CoreWindowNativeWindow::registerForSizeChangeEvents() -{ - ComPtr<IWindowSizeChangedEventHandler> sizeChangedHandler; - HRESULT result = Microsoft::WRL::MakeAndInitialize<CoreWindowSizeChangedHandler>(sizeChangedHandler.ReleaseAndGetAddressOf(), this->shared_from_this()); - if (SUCCEEDED(result)) - { - result = mCoreWindow->add_SizeChanged(sizeChangedHandler.Get(), &mSizeChangedEventToken); - } - - if (SUCCEEDED(result)) - { - return true; - } - - return false; -} - -void CoreWindowNativeWindow::unregisterForSizeChangeEvents() -{ - if (mCoreWindow) - { - (void)mCoreWindow->remove_SizeChanged(mSizeChangedEventToken); - } - mSizeChangedEventToken.value = 0; -} - -HRESULT CoreWindowNativeWindow::createSwapChain(ID3D11Device *device, - IDXGIFactory2 *factory, - DXGI_FORMAT format, - unsigned int width, - unsigned int height, - bool containsAlpha, - IDXGISwapChain1 **swapChain) -{ - if (device == nullptr || factory == nullptr || swapChain == nullptr || width == 0 || - height == 0) - { - return E_INVALIDARG; - } - - DXGI_SWAP_CHAIN_DESC1 swapChainDesc = { 0 }; - swapChainDesc.Width = width; - swapChainDesc.Height = height; - swapChainDesc.Format = format; - swapChainDesc.Stereo = FALSE; - swapChainDesc.SampleDesc.Count = 1; - swapChainDesc.SampleDesc.Quality = 0; - swapChainDesc.BufferUsage = - DXGI_USAGE_SHADER_INPUT | DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_BACK_BUFFER; - swapChainDesc.BufferCount = 2; - swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; - swapChainDesc.Scaling = DXGI_SCALING_STRETCH; - swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED; - - *swapChain = nullptr; - - ComPtr<IDXGISwapChain1> newSwapChain; - HRESULT result = factory->CreateSwapChainForCoreWindow(device, mCoreWindow.Get(), &swapChainDesc, nullptr, newSwapChain.ReleaseAndGetAddressOf()); - if (SUCCEEDED(result)) - { - result = newSwapChain.CopyTo(swapChain); - } - - if (SUCCEEDED(result)) - { - // If automatic swapchain resize behaviors have been disabled, then - // unregister for the resize change events. - if (mSupportsSwapChainResize == false) - { - unregisterForSizeChangeEvents(); - } - } - - return result; -} - -inline HRESULT CoreWindowNativeWindow::scaleSwapChain(const Size &windowSize, - const RECT &clientRect) -{ - // We don't need to do any additional work to scale CoreWindow swapchains. - // Using DXGI_SCALING_STRETCH to create the swapchain above does all the necessary work. - return S_OK; -} - -HRESULT GetCoreWindowSizeInPixels(const ComPtr<ABI::Windows::UI::Core::ICoreWindow> &coreWindow, - Size *windowSize) -{ - ABI::Windows::Foundation::Rect bounds; - HRESULT result = coreWindow->get_Bounds(&bounds); - if (SUCCEEDED(result)) - { - *windowSize = { ConvertDipsToPixels(bounds.Width), ConvertDipsToPixels(bounds.Height) }; - } - - return result; -} -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/CoreWindowNativeWindow.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/CoreWindowNativeWindow.h deleted file mode 100644 index 21855c2c3b..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/CoreWindowNativeWindow.h +++ /dev/null @@ -1,90 +0,0 @@ -// -// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// CoreWindowNativeWindow.h: NativeWindow for managing ICoreWindow native window types. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_WINRT_COREWINDOWNATIVEWINDOW_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_WINRT_COREWINDOWNATIVEWINDOW_H_ - -#include "libANGLE/renderer/d3d/d3d11/winrt/InspectableNativeWindow.h" - -#include <memory> - -#include <EGL/eglplatform.h> - -typedef ABI::Windows::Foundation::__FITypedEventHandler_2_Windows__CUI__CCore__CCoreWindow_Windows__CUI__CCore__CWindowSizeChangedEventArgs_t IWindowSizeChangedEventHandler; - -namespace rx -{ -class CoreWindowNativeWindow : public InspectableNativeWindow, public std::enable_shared_from_this<CoreWindowNativeWindow> -{ - public: - ~CoreWindowNativeWindow(); - - bool initialize(EGLNativeWindowType window, IPropertySet *propertySet) override; - HRESULT createSwapChain(ID3D11Device *device, - IDXGIFactory2 *factory, - DXGI_FORMAT format, - unsigned int width, - unsigned int height, - bool containsAlpha, - IDXGISwapChain1 **swapChain) override; - - protected: - HRESULT scaleSwapChain(const Size &windowSize, const RECT &clientRect) override; - - bool registerForSizeChangeEvents(); - void unregisterForSizeChangeEvents(); - - private: - ComPtr<ABI::Windows::UI::Core::ICoreWindow> mCoreWindow; - ComPtr<IMap<HSTRING, IInspectable*>> mPropertyMap; -}; - -[uuid(7F924F66-EBAE-40E5-A10B-B8F35E245190)] -class CoreWindowSizeChangedHandler : - public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, IWindowSizeChangedEventHandler> -{ - public: - CoreWindowSizeChangedHandler() { } - HRESULT RuntimeClassInitialize(std::shared_ptr<InspectableNativeWindow> host) - { - if (!host) - { - return E_INVALIDARG; - } - - mHost = host; - return S_OK; - } - - // IWindowSizeChangedEventHandler - IFACEMETHOD(Invoke)(ABI::Windows::UI::Core::ICoreWindow *sender, ABI::Windows::UI::Core::IWindowSizeChangedEventArgs *sizeChangedEventArgs) - { - std::shared_ptr<InspectableNativeWindow> host = mHost.lock(); - if (host) - { - ABI::Windows::Foundation::Size windowSize; - if (SUCCEEDED(sizeChangedEventArgs->get_Size(&windowSize))) - { - Size windowSizeInPixels = {ConvertDipsToPixels(windowSize.Width), - ConvertDipsToPixels(windowSize.Height)}; - host->setNewClientSize(windowSizeInPixels); - } - } - - return S_OK; - } - - private: - std::weak_ptr<InspectableNativeWindow> mHost; -}; - -HRESULT GetCoreWindowSizeInPixels(const ComPtr<ABI::Windows::UI::Core::ICoreWindow> &coreWindow, - Size *windowSize); -} - -#endif // LIBANGLE_RENDERER_D3D_D3D11_WINRT_COREWINDOWNATIVEWINDOW_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/InspectableNativeWindow.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/InspectableNativeWindow.cpp deleted file mode 100644 index 1bd796e58f..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/InspectableNativeWindow.cpp +++ /dev/null @@ -1,297 +0,0 @@ -// -// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// InspectableNativeWindow.cpp: NativeWindow base class for managing IInspectable native window types. - -#include "libANGLE/renderer/d3d/d3d11/winrt/CoreWindowNativeWindow.h" -#include "libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.h" - -namespace rx -{ - -bool IsCoreWindow(EGLNativeWindowType window, ComPtr<ABI::Windows::UI::Core::ICoreWindow> *coreWindow) -{ - if (!window) - { - return false; - } - - ComPtr<IInspectable> win = window; - ComPtr<ABI::Windows::UI::Core::ICoreWindow> coreWin; - if (SUCCEEDED(win.As(&coreWin))) - { - if (coreWindow != nullptr) - { - *coreWindow = coreWin; - } - return true; - } - - return false; -} - -bool IsSwapChainPanel(EGLNativeWindowType window, ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> *swapChainPanel) -{ - if (!window) - { - return false; - } - - ComPtr<IInspectable> win = window; - ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> panel; - if (SUCCEEDED(win.As(&panel))) - { - if (swapChainPanel != nullptr) - { - *swapChainPanel = panel; - } - return true; - } - - return false; -} - -bool IsEGLConfiguredPropertySet(EGLNativeWindowType window, ABI::Windows::Foundation::Collections::IPropertySet **propertySet, IInspectable **eglNativeWindow) -{ - if (!window) - { - return false; - } - - ComPtr<IInspectable> props = window; - ComPtr<IPropertySet> propSet; - ComPtr<IInspectable> nativeWindow; - ComPtr<ABI::Windows::Foundation::Collections::IMap<HSTRING, IInspectable*>> propMap; - boolean hasEglNativeWindowPropertyKey = false; - - HRESULT result = props.As(&propSet); - if (SUCCEEDED(result)) - { - result = propSet.As(&propMap); - } - - // Look for the presence of the EGLNativeWindowType in the property set - if (SUCCEEDED(result)) - { - result = propMap->HasKey(HStringReference(EGLNativeWindowTypeProperty).Get(), &hasEglNativeWindowPropertyKey); - } - - // If the IPropertySet does not contain the required EglNativeWindowType key, the property set is - // considered invalid. - if (SUCCEEDED(result) && !hasEglNativeWindowPropertyKey) - { - ERR() << "Could not find EGLNativeWindowTypeProperty in IPropertySet. Valid " - "EGLNativeWindowTypeProperty values include ICoreWindow"; - return false; - } - - // The EglNativeWindowType property exists, so retreive the IInspectable that represents the EGLNativeWindowType - if (SUCCEEDED(result) && hasEglNativeWindowPropertyKey) - { - result = propMap->Lookup(HStringReference(EGLNativeWindowTypeProperty).Get(), &nativeWindow); - } - - if (SUCCEEDED(result)) - { - if (propertySet != nullptr) - { - result = propSet.CopyTo(propertySet); - } - } - - if (SUCCEEDED(result)) - { - if (eglNativeWindow != nullptr) - { - result = nativeWindow.CopyTo(eglNativeWindow); - } - } - - if (SUCCEEDED(result)) - { - return true; - } - - return false; -} - -// Retrieve an optional property from a property set -HRESULT GetOptionalPropertyValue(const ComPtr<ABI::Windows::Foundation::Collections::IMap<HSTRING, IInspectable*>> &propertyMap, - const wchar_t *propertyName, - boolean *hasKey, - ComPtr<ABI::Windows::Foundation::IPropertyValue> &propertyValue) -{ - if (!propertyMap || !hasKey) - { - return E_INVALIDARG; - } - - // Assume that the value does not exist - *hasKey = false; - - HRESULT result = propertyMap->HasKey(HStringReference(propertyName).Get(), hasKey); - if (SUCCEEDED(result) && !(*hasKey)) - { - // Value does not exist, so return S_OK and set the exists parameter to false to indicate - // that a the optional property does not exist. - return S_OK; - } - - if (SUCCEEDED(result)) - { - result = propertyMap->Lookup(HStringReference(propertyName).Get(), &propertyValue); - } - - return result; -} - -// Attempts to read an optional SIZE property value that is assumed to be in the form of -// an ABI::Windows::Foundation::Size. This function validates the Size value before returning -// it to the caller. -// -// Possible return values are: -// S_OK, valueExists == true - optional SIZE value was successfully retrieved and validated -// S_OK, valueExists == false - optional SIZE value was not found -// E_INVALIDARG, valueExists = false - optional SIZE value was malformed in the property set. -// * Incorrect property type ( must be PropertyType_Size) -// * Invalid property value (width/height must be > 0) -// Additional errors may be returned from IMap or IPropertyValue -// -HRESULT GetOptionalSizePropertyValue(const ComPtr<ABI::Windows::Foundation::Collections::IMap<HSTRING, IInspectable*>> &propertyMap, - const wchar_t *propertyName, SIZE *value, bool *valueExists) -{ - ComPtr<ABI::Windows::Foundation::IPropertyValue> propertyValue; - ABI::Windows::Foundation::PropertyType propertyType = ABI::Windows::Foundation::PropertyType::PropertyType_Empty; - Size sizeValue = { 0, 0 }; - boolean hasKey = false; - - if (!propertyMap || !value || !valueExists) - { - return E_INVALIDARG; - } - - // Assume that the value does not exist - *valueExists = false; - *value = { 0, 0 }; - - HRESULT result = GetOptionalPropertyValue(propertyMap, propertyName, &hasKey, propertyValue); - if (SUCCEEDED(result) && hasKey) - { - result = propertyValue->get_Type(&propertyType); - - // Check if the expected Size property is of PropertyType_Size type. - if (SUCCEEDED(result) && propertyType == ABI::Windows::Foundation::PropertyType::PropertyType_Size) - { - if (SUCCEEDED(propertyValue->GetSize(&sizeValue)) && (sizeValue.Width > 0 && sizeValue.Height > 0)) - { - // A valid property value exists - *value = { static_cast<long>(sizeValue.Width), static_cast<long>(sizeValue.Height) }; - *valueExists = true; - result = S_OK; - } - else - { - // An invalid Size property was detected. Width/Height values must > 0 - result = E_INVALIDARG; - } - } - else - { - // An invalid property type was detected. Size property must be of PropertyType_Size - result = E_INVALIDARG; - } - } - - return result; -} - -// Attempts to read an optional float property value that is assumed to be in the form of -// an ABI::Windows::Foundation::Single. This function validates the Single value before returning -// it to the caller. -// -// Possible return values are: -// S_OK, valueExists == true - optional Single value was successfully retrieved and validated -// S_OK, valueExists == false - optional Single value was not found -// E_INVALIDARG, valueExists = false - optional Single value was malformed in the property set. -// * Incorrect property type ( must be PropertyType_Single) -// * Invalid property value (must be > 0) -// Additional errors may be returned from IMap or IPropertyValue -// -HRESULT GetOptionalSinglePropertyValue(const ComPtr<ABI::Windows::Foundation::Collections::IMap<HSTRING, IInspectable*>> &propertyMap, - const wchar_t *propertyName, float *value, bool *valueExists) -{ - ComPtr<ABI::Windows::Foundation::IPropertyValue> propertyValue; - ABI::Windows::Foundation::PropertyType propertyType = ABI::Windows::Foundation::PropertyType::PropertyType_Empty; - float scaleValue = 0.0f; - boolean hasKey = false; - - if (!propertyMap || !value || !valueExists) - { - return E_INVALIDARG; - } - - // Assume that the value does not exist - *valueExists = false; - *value = 0.0f; - - HRESULT result = GetOptionalPropertyValue(propertyMap, propertyName, &hasKey, propertyValue); - if (SUCCEEDED(result) && hasKey) - { - result = propertyValue->get_Type(&propertyType); - - // Check if the expected Scale property is of PropertyType_Single type. - if (SUCCEEDED(result) && propertyType == ABI::Windows::Foundation::PropertyType::PropertyType_Single) - { - if (SUCCEEDED(propertyValue->GetSingle(&scaleValue)) && (scaleValue > 0.0f)) - { - // A valid property value exists - *value = scaleValue; - *valueExists = true; - result = S_OK; - } - else - { - // An invalid scale was set - result = E_INVALIDARG; - } - } - else - { - // An invalid property type was detected. Size property must be of PropertyType_Single - result = E_INVALIDARG; - } - } - - return result; -} - -RECT InspectableNativeWindow::clientRect(const Size &size) -{ - return {0, 0, static_cast<long>(ConvertDipsToPixels(size.Width)), - static_cast<long>(ConvertDipsToPixels(size.Height))}; -} - -float GetLogicalDpi() -{ - ComPtr<ABI::Windows::Graphics::Display::IDisplayPropertiesStatics> displayProperties; - float dpi = 96.0f; - - if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayProperties).Get(), displayProperties.GetAddressOf()))) - { - if (SUCCEEDED(displayProperties->get_LogicalDpi(&dpi))) - { - return dpi; - } - } - return dpi; -} - -float ConvertDipsToPixels(float dips) -{ - static const float dipsPerInch = 96.0f; - return lround((dips * GetLogicalDpi() / dipsPerInch)); -} -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/InspectableNativeWindow.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/InspectableNativeWindow.h deleted file mode 100644 index d81c3e5fb9..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/InspectableNativeWindow.h +++ /dev/null @@ -1,136 +0,0 @@ -// -// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// InspectableNativeWindow.h: Host specific implementation interface for -// managing IInspectable native window types. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_WINRT_INSPECTABLENATIVEWINDOW_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_WINRT_INSPECTABLENATIVEWINDOW_H_ - -#include "common/debug.h" -#include "common/platform.h" - -#include "angle_windowsstore.h" - -#include <EGL/eglplatform.h> - -#include <windows.applicationmodel.core.h> -#include <windows.ui.xaml.h> -#include <windows.ui.xaml.media.dxinterop.h> -#include <wrl.h> -#include <wrl/wrappers/corewrappers.h> - -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Foundation::Collections; - -namespace rx -{ -float ConvertDipsToPixels(float dips); -float GetLogicalDpi(); - -class InspectableNativeWindow -{ - public: - InspectableNativeWindow() : - mSupportsSwapChainResize(true), - mSwapChainSizeSpecified(false), - mSwapChainScaleSpecified(false), - mClientRectChanged(false), - mClientRect({0,0,0,0}), - mNewClientRect({0,0,0,0}) - { - mSizeChangedEventToken.value = 0; - mSwapChainScale = 96.0f / GetLogicalDpi(); - if (mSwapChainScale != 1.0f) - mSwapChainScaleSpecified = true; - } - virtual ~InspectableNativeWindow(){} - - virtual bool initialize(EGLNativeWindowType window, IPropertySet *propertySet) = 0; - virtual HRESULT createSwapChain(ID3D11Device *device, - IDXGIFactory2 *factory, - DXGI_FORMAT format, - unsigned int width, - unsigned int height, - bool containsAlpha, - IDXGISwapChain1 **swapChain) = 0; - - bool getClientRect(RECT *rect) - { - if (mClientRectChanged) - { - mClientRect = mNewClientRect; - } - - *rect = mClientRect; - - return true; - } - - // setNewClientSize is used by the WinRT size change handler. It isn't used by the rest of ANGLE. - void setNewClientSize(const Size &newWindowSize) - { - // If the client doesn't support swapchain resizing then we should have already unregistered from size change handler - ASSERT(mSupportsSwapChainResize); - - if (mSupportsSwapChainResize) - { - // If the swapchain size was specified then we should ignore this call too - if (!mSwapChainSizeSpecified) - { - mNewClientRect = clientRect(newWindowSize); - mClientRectChanged = true; - - // If a scale was specified, then now is the time to apply the scale matrix for the new swapchain size and window size - if (mSwapChainScaleSpecified) - { - scaleSwapChain(newWindowSize, mNewClientRect); - } - } - - // Even if the swapchain size was fixed, the window might have changed size. - // In this case, we should recalculate the scale matrix to account for the new window size - if (mSwapChainSizeSpecified) - { - scaleSwapChain(newWindowSize, mClientRect); - } - } - } - - protected: - virtual HRESULT scaleSwapChain(const Size &windowSize, const RECT &clientRect) = 0; - RECT clientRect(const Size &size); - - bool mSupportsSwapChainResize; // Support for IDXGISwapChain::ResizeBuffers method - bool mSwapChainSizeSpecified; // If an EGLRenderSurfaceSizeProperty was specified - bool mSwapChainScaleSpecified; // If an EGLRenderResolutionScaleProperty was specified - float mSwapChainScale; // The scale value specified by the EGLRenderResolutionScaleProperty property - RECT mClientRect; - RECT mNewClientRect; - bool mClientRectChanged; - - EventRegistrationToken mSizeChangedEventToken; -}; - -bool IsCoreWindow(EGLNativeWindowType window, ComPtr<ABI::Windows::UI::Core::ICoreWindow> *coreWindow = nullptr); -bool IsSwapChainPanel(EGLNativeWindowType window, ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> *swapChainPanel = nullptr); -bool IsEGLConfiguredPropertySet(EGLNativeWindowType window, ABI::Windows::Foundation::Collections::IPropertySet **propertySet = nullptr, IInspectable **inspectable = nullptr); - -HRESULT GetOptionalPropertyValue(const ComPtr<ABI::Windows::Foundation::Collections::IMap<HSTRING, IInspectable*>> &propertyMap, - const wchar_t *propertyName, - boolean *hasKey, - ComPtr<ABI::Windows::Foundation::IPropertyValue> &propertyValue); - -HRESULT GetOptionalSizePropertyValue(const ComPtr<ABI::Windows::Foundation::Collections::IMap<HSTRING, IInspectable*>> &propertyMap, - const wchar_t *propertyName, SIZE *value, bool *valueExists); - -HRESULT GetOptionalSinglePropertyValue(const ComPtr<ABI::Windows::Foundation::Collections::IMap<HSTRING, IInspectable*>> &propertyMap, - const wchar_t *propertyName, float *value, bool *valueExists); -} - -#endif // LIBANGLE_RENDERER_D3D_D3D11_WINRT_INSPECTABLENATIVEWINDOW_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/NativeWindow11WinRT.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/NativeWindow11WinRT.cpp deleted file mode 100644 index 655b23be83..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/NativeWindow11WinRT.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// -// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// NativeWindow11WinRT.cpp: NativeWindow base class for managing IInspectable native window types. - -#include "libANGLE/renderer/d3d/d3d11/winrt/NativeWindow11WinRT.h" - -#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" -#include "libANGLE/renderer/d3d/d3d11/winrt/CoreWindowNativeWindow.h" -#include "libANGLE/renderer/d3d/d3d11/winrt/InspectableNativeWindow.h" -#include "libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.h" - -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; - -namespace rx -{ -NativeWindow11WinRT::NativeWindow11WinRT(EGLNativeWindowType window, bool hasAlpha) - : NativeWindow11(window), mHasAlpha(hasAlpha) -{ -} - -bool NativeWindow11WinRT::initialize() -{ - EGLNativeWindowType window = getNativeWindow(); - - // If the native window type is a IPropertySet, extract the - // EGLNativeWindowType (IInspectable) and initialize the - // proper host with this IPropertySet. - ComPtr<ABI::Windows::Foundation::Collections::IPropertySet> propertySet; - ComPtr<IInspectable> eglNativeWindow; - if (IsEGLConfiguredPropertySet(window, &propertySet, &eglNativeWindow)) - { - // A property set was found and the EGLNativeWindowType was - // retrieved. The mWindow member of the host to must be updated - // to use the EGLNativeWindowType specified in the property set. - // mWindow is treated as a raw pointer not an AddRef'd interface, so - // the old mWindow does not need a Release() before this assignment. - window = eglNativeWindow.Get(); - } - - ComPtr<ABI::Windows::UI::Core::ICoreWindow> coreWindow; - ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> swapChainPanel; - if (IsCoreWindow(window, &coreWindow)) - { - mImpl = std::make_shared<CoreWindowNativeWindow>(); - if (mImpl) - { - return mImpl->initialize(window, propertySet.Get()); - } - } - else if (IsSwapChainPanel(window, &swapChainPanel)) - { - mImpl = std::make_shared<SwapChainPanelNativeWindow>(); - if (mImpl) - { - return mImpl->initialize(window, propertySet.Get()); - } - } - else - { - ERR() << "Invalid IInspectable EGLNativeWindowType detected. Valid IInspectables include " - "ICoreWindow, ISwapChainPanel and IPropertySet"; - } - - return false; -} - -bool NativeWindow11WinRT::getClientRect(LPRECT rect) const -{ - if (mImpl) - { - return mImpl->getClientRect(rect); - } - - return false; -} - -bool NativeWindow11WinRT::isIconic() const -{ - return false; -} - -HRESULT NativeWindow11WinRT::createSwapChain(ID3D11Device *device, - IDXGIFactory *factory, - DXGI_FORMAT format, - UINT width, - UINT height, - UINT samples, - IDXGISwapChain **swapChain) -{ - if (mImpl) - { - IDXGIFactory2 *factory2 = d3d11::DynamicCastComObject<IDXGIFactory2>(factory); - IDXGISwapChain1 *swapChain1 = nullptr; - HRESULT result = - mImpl->createSwapChain(device, factory2, format, width, height, mHasAlpha, &swapChain1); - SafeRelease(factory2); - *swapChain = static_cast<IDXGISwapChain *>(swapChain1); - return result; - } - - return E_UNEXPECTED; -} - -void NativeWindow11WinRT::commitChange() -{ -} - -// static -bool NativeWindow11WinRT::IsValidNativeWindow(EGLNativeWindowType window) -{ - // A Valid EGLNativeWindowType IInspectable can only be: - // - // ICoreWindow - // ISwapChainPanel - // IPropertySet - // - // Anything else will be rejected as an invalid IInspectable. - return IsCoreWindow(window) || IsSwapChainPanel(window) || IsEGLConfiguredPropertySet(window); -} - -} // namespace rx diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/NativeWindow11WinRT.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/NativeWindow11WinRT.h deleted file mode 100644 index c4ac997a55..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/NativeWindow11WinRT.h +++ /dev/null @@ -1,51 +0,0 @@ -// -// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// NativeWindow11WinRT.h: NativeWindow base class for managing IInspectable native window types. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_WINRT_NATIVEWINDOW11WINRT_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_WINRT_NATIVEWINDOW11WINRT_H_ - -#include "libANGLE/renderer/d3d/d3d11/NativeWindow11.h" - -#include <memory> -#include <windows.applicationmodel.core.h> -#include <wrl.h> -#include <wrl/wrappers/corewrappers.h> - -namespace rx -{ -class InspectableNativeWindow; - -class NativeWindow11WinRT : public NativeWindow11 -{ - public: - NativeWindow11WinRT(EGLNativeWindowType window, bool hasAlpha); - - bool initialize() override; - bool getClientRect(LPRECT rect) const override; - bool isIconic() const override; - - HRESULT createSwapChain(ID3D11Device *device, - IDXGIFactory *factory, - DXGI_FORMAT format, - UINT width, - UINT height, - UINT samples, - IDXGISwapChain **swapChain) override; - - void commitChange() override; - - static bool IsValidNativeWindow(EGLNativeWindowType window); - - private: - bool mHasAlpha; - std::shared_ptr<InspectableNativeWindow> mImpl; -}; - -} // namespace rx - -#endif // LIBANGLE_RENDERER_D3D_D3D11_WINRT_NATIVEWINDOW11WINRT_H_ diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.cpp deleted file mode 100644 index 3425fad95d..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.cpp +++ /dev/null @@ -1,359 +0,0 @@ -// -// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// SwapChainPanelNativeWindow.cpp: NativeWindow for managing ISwapChainPanel native window types. - -#include "libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.h" - -#include <algorithm> -#include <math.h> - -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Foundation::Collections; -using namespace ABI::Windows::UI::Core; -using namespace ABI::Windows::UI::Xaml; -using namespace Microsoft::WRL; - -namespace rx -{ -SwapChainPanelNativeWindow::~SwapChainPanelNativeWindow() -{ - unregisterForSizeChangeEvents(); -} - -template <typename T> -struct AddFtmBase -{ - typedef Implements<RuntimeClassFlags<ClassicCom>, T, FtmBase> Type; -}; - -template <typename CODE> -HRESULT RunOnUIThread(CODE &&code, const ComPtr<ICoreDispatcher> &dispatcher) -{ - ComPtr<IAsyncAction> asyncAction; - HRESULT result = S_OK; - - boolean hasThreadAccess; - result = dispatcher->get_HasThreadAccess(&hasThreadAccess); - if (FAILED(result)) - { - return result; - } - - if (hasThreadAccess) - { - return code(); - } - else - { - Event waitEvent( - CreateEventEx(nullptr, nullptr, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS)); - if (!waitEvent.IsValid()) - { - return E_FAIL; - } - - HRESULT codeResult = E_FAIL; - auto handler = - Callback<AddFtmBase<IDispatchedHandler>::Type>([&codeResult, &code, &waitEvent] - { - codeResult = code(); - SetEvent(waitEvent.Get()); - return S_OK; - }); - - result = dispatcher->RunAsync(CoreDispatcherPriority_Normal, handler.Get(), - asyncAction.GetAddressOf()); - if (FAILED(result)) - { - return result; - } - - auto waitResult = WaitForSingleObjectEx(waitEvent.Get(), 10 * 1000, true); - if (waitResult != WAIT_OBJECT_0) - { - // Wait 10 seconds before giving up. At this point, the application is in an - // unrecoverable state (probably deadlocked). We therefore terminate the application - // entirely. This also prevents stack corruption if the async operation is eventually - // run. - ERR() - << "Timeout waiting for async action on UI thread. The UI thread might be blocked."; - std::terminate(); - return E_FAIL; - } - - return codeResult; - } -} - -bool SwapChainPanelNativeWindow::initialize(EGLNativeWindowType window, IPropertySet *propertySet) -{ - ComPtr<IPropertySet> props = propertySet; - ComPtr<IInspectable> win = window; - SIZE swapChainSize = {}; - HRESULT result = S_OK; - - // IPropertySet is an optional parameter and can be null. - // If one is specified, cache as an IMap and read the properties - // used for initial host initialization. - if (propertySet) - { - result = props.As(&mPropertyMap); - if (FAILED(result)) - { - return false; - } - - // The EGLRenderSurfaceSizeProperty is optional and may be missing. The IPropertySet - // was prevalidated to contain the EGLNativeWindowType before being passed to - // this host. - result = GetOptionalSizePropertyValue(mPropertyMap, EGLRenderSurfaceSizeProperty, &swapChainSize, &mSwapChainSizeSpecified); - if (FAILED(result)) - { - return false; - } - - // The EGLRenderResolutionScaleProperty is optional and may be missing. The IPropertySet - // was prevalidated to contain the EGLNativeWindowType before being passed to - // this host. - result = GetOptionalSinglePropertyValue(mPropertyMap, EGLRenderResolutionScaleProperty, &mSwapChainScale, &mSwapChainScaleSpecified); - if (FAILED(result)) - { - return false; - } - - if (!mSwapChainScaleSpecified) - { - // Default value for the scale is 1.0f - mSwapChainScale = 1.0f; - } - - // A EGLRenderSurfaceSizeProperty and a EGLRenderResolutionScaleProperty can't both be specified - if (mSwapChainScaleSpecified && mSwapChainSizeSpecified) - { - ERR() << "It is invalid to specify both an EGLRenderSurfaceSizeProperty and a " - "EGLRenderResolutionScaleProperty."; - return false; - } - } - - if (SUCCEEDED(result)) - { - result = win.As(&mSwapChainPanel); - } - - ComPtr<IDependencyObject> swapChainPanelDependencyObject; - if (SUCCEEDED(result)) - { - result = mSwapChainPanel.As(&swapChainPanelDependencyObject); - } - - if (SUCCEEDED(result)) - { - result = swapChainPanelDependencyObject->get_Dispatcher( - mSwapChainPanelDispatcher.GetAddressOf()); - } - - if (SUCCEEDED(result)) - { - // If a swapchain size is specfied, then the automatic resize - // behaviors implemented by the host should be disabled. The swapchain - // will be still be scaled when being rendered to fit the bounds - // of the host. - // Scaling of the swapchain output needs to be handled by the - // host for swapchain panels even though the scaling mode setting - // DXGI_SCALING_STRETCH is configured on the swapchain. - if (mSwapChainSizeSpecified) - { - mClientRect = { 0, 0, swapChainSize.cx, swapChainSize.cy }; - } - else - { - Size swapChainPanelSize; - result = GetSwapChainPanelSize(mSwapChainPanel, mSwapChainPanelDispatcher, - &swapChainPanelSize); - - if (SUCCEEDED(result)) - { - // Update the client rect to account for any swapchain scale factor - mClientRect = clientRect(swapChainPanelSize); - } - } - } - - if (SUCCEEDED(result)) - { - mNewClientRect = mClientRect; - mClientRectChanged = false; - return registerForSizeChangeEvents(); - } - - return false; -} - -bool SwapChainPanelNativeWindow::registerForSizeChangeEvents() -{ - ComPtr<ISizeChangedEventHandler> sizeChangedHandler; - ComPtr<IFrameworkElement> frameworkElement; - HRESULT result = Microsoft::WRL::MakeAndInitialize<SwapChainPanelSizeChangedHandler>(sizeChangedHandler.ReleaseAndGetAddressOf(), this->shared_from_this()); - - if (SUCCEEDED(result)) - { - result = mSwapChainPanel.As(&frameworkElement); - } - - if (SUCCEEDED(result)) - { - result = RunOnUIThread( - [this, frameworkElement, sizeChangedHandler] - { - return frameworkElement->add_SizeChanged(sizeChangedHandler.Get(), - &mSizeChangedEventToken); - }, - mSwapChainPanelDispatcher); - } - - if (SUCCEEDED(result)) - { - return true; - } - - return false; -} - -void SwapChainPanelNativeWindow::unregisterForSizeChangeEvents() -{ - ComPtr<IFrameworkElement> frameworkElement; - if (mSwapChainPanel && SUCCEEDED(mSwapChainPanel.As(&frameworkElement))) - { - RunOnUIThread( - [this, frameworkElement] - { - return frameworkElement->remove_SizeChanged(mSizeChangedEventToken); - }, - mSwapChainPanelDispatcher); - } - - mSizeChangedEventToken.value = 0; -} - -HRESULT SwapChainPanelNativeWindow::createSwapChain(ID3D11Device *device, - IDXGIFactory2 *factory, - DXGI_FORMAT format, - unsigned int width, - unsigned int height, - bool containsAlpha, - IDXGISwapChain1 **swapChain) -{ - if (device == nullptr || factory == nullptr || swapChain == nullptr || width == 0 || - height == 0) - { - return E_INVALIDARG; - } - - DXGI_SWAP_CHAIN_DESC1 swapChainDesc = { 0 }; - swapChainDesc.Width = width; - swapChainDesc.Height = height; - swapChainDesc.Format = format; - swapChainDesc.Stereo = FALSE; - swapChainDesc.SampleDesc.Count = 1; - swapChainDesc.SampleDesc.Quality = 0; - swapChainDesc.BufferUsage = - DXGI_USAGE_SHADER_INPUT | DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_BACK_BUFFER; - swapChainDesc.BufferCount = 2; - swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; - swapChainDesc.Scaling = DXGI_SCALING_STRETCH; - swapChainDesc.AlphaMode = - containsAlpha ? DXGI_ALPHA_MODE_PREMULTIPLIED : DXGI_ALPHA_MODE_IGNORE; - - *swapChain = nullptr; - - ComPtr<IDXGISwapChain1> newSwapChain; - ComPtr<ISwapChainPanelNative> swapChainPanelNative; - Size currentPanelSize = {}; - - HRESULT result = factory->CreateSwapChainForComposition(device, &swapChainDesc, nullptr, newSwapChain.ReleaseAndGetAddressOf()); - - if (SUCCEEDED(result)) - { - result = mSwapChainPanel.As(&swapChainPanelNative); - } - - if (SUCCEEDED(result)) - { - result = RunOnUIThread( - [swapChainPanelNative, newSwapChain] - { - return swapChainPanelNative->SetSwapChain(newSwapChain.Get()); - }, - mSwapChainPanelDispatcher); - } - - if (SUCCEEDED(result)) - { - // The swapchain panel host requires an instance of the swapchain set on the SwapChainPanel - // to perform the runtime-scale behavior. This swapchain is cached here because there are - // no methods for retreiving the currently configured on from ISwapChainPanelNative. - mSwapChain = newSwapChain; - result = newSwapChain.CopyTo(swapChain); - } - - // If the host is responsible for scaling the output of the swapchain, then - // scale it now before returning an instance to the caller. This is done by - // first reading the current size of the swapchain panel, then scaling - if (SUCCEEDED(result)) - { - if (mSwapChainSizeSpecified || mSwapChainScaleSpecified) - { - result = GetSwapChainPanelSize(mSwapChainPanel, mSwapChainPanelDispatcher, - ¤tPanelSize); - - // Scale the swapchain to fit inside the contents of the panel. - if (SUCCEEDED(result)) - { - result = scaleSwapChain(currentPanelSize, mClientRect); - } - } - } - - return result; -} - -HRESULT SwapChainPanelNativeWindow::scaleSwapChain(const Size &windowSize, const RECT &clientRect) -{ - Size renderScale = {windowSize.Width / std::max(LONG(1), clientRect.right), - windowSize.Height / std::max(LONG(1), clientRect.bottom)}; - // Setup a scale matrix for the swap chain - DXGI_MATRIX_3X2_F scaleMatrix = {}; - scaleMatrix._11 = renderScale.Width; - scaleMatrix._22 = renderScale.Height; - - ComPtr<IDXGISwapChain2> swapChain2; - HRESULT result = mSwapChain.As(&swapChain2); - if (SUCCEEDED(result)) - { - result = swapChain2->SetMatrixTransform(&scaleMatrix); - } - - return result; -} - -HRESULT GetSwapChainPanelSize( - const ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> &swapChainPanel, - const ComPtr<ICoreDispatcher> &dispatcher, - Size *windowSize) -{ - ComPtr<IUIElement> uiElement; - HRESULT result = swapChainPanel.As(&uiElement); - if (SUCCEEDED(result)) - { - result = RunOnUIThread( - [uiElement, windowSize] { return uiElement->get_RenderSize(windowSize); }, dispatcher); - } - - return result; -} -} diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.h deleted file mode 100644 index f9a2fc0e4b..0000000000 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.h +++ /dev/null @@ -1,93 +0,0 @@ -// -// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// - -// SwapChainPanelNativeWindow.h: NativeWindow for managing ISwapChainPanel native window types. - -#ifndef LIBANGLE_RENDERER_D3D_D3D11_WINRT_SWAPCHAINPANELNATIVEWINDOW_H_ -#define LIBANGLE_RENDERER_D3D_D3D11_WINRT_SWAPCHAINPANELNATIVEWINDOW_H_ - -#include "libANGLE/renderer/d3d/d3d11/winrt/InspectableNativeWindow.h" - -#include <memory> - -namespace rx -{ -class SwapChainPanelNativeWindow : public InspectableNativeWindow, public std::enable_shared_from_this<SwapChainPanelNativeWindow> -{ - public: - ~SwapChainPanelNativeWindow(); - - bool initialize(EGLNativeWindowType window, IPropertySet *propertySet) override; - HRESULT createSwapChain(ID3D11Device *device, - IDXGIFactory2 *factory, - DXGI_FORMAT format, - unsigned int width, - unsigned int height, - bool containsAlpha, - IDXGISwapChain1 **swapChain) override; - - protected: - HRESULT scaleSwapChain(const Size &windowSize, const RECT &clientRect) override; - - bool registerForSizeChangeEvents(); - void unregisterForSizeChangeEvents(); - - private: - ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> mSwapChainPanel; - ComPtr<ABI::Windows::UI::Core::ICoreDispatcher> mSwapChainPanelDispatcher; - ComPtr<IMap<HSTRING, IInspectable*>> mPropertyMap; - ComPtr<IDXGISwapChain1> mSwapChain; -}; - -[uuid(8ACBD974-8187-4508-AD80-AEC77F93CF36)] -class SwapChainPanelSizeChangedHandler : - public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, ABI::Windows::UI::Xaml::ISizeChangedEventHandler> -{ - public: - SwapChainPanelSizeChangedHandler() { } - HRESULT RuntimeClassInitialize(std::shared_ptr<InspectableNativeWindow> host) - { - if (!host) - { - return E_INVALIDARG; - } - - mHost = host; - return S_OK; - } - - // ISizeChangedEventHandler - IFACEMETHOD(Invoke)(IInspectable *sender, ABI::Windows::UI::Xaml::ISizeChangedEventArgs *sizeChangedEventArgs) - { - std::shared_ptr<InspectableNativeWindow> host = mHost.lock(); - if (host) - { - // The size of the ISwapChainPanel control is returned in DIPs. - // We are keeping these in dips because the swapchain created for composition - // also uses dip units. This keeps dimensions, viewports, etc in the same unit. - // XAML Clients of the ISwapChainPanel are required to use dips to define their - // layout sizes as well. - ABI::Windows::Foundation::Size newSize; - HRESULT result = sizeChangedEventArgs->get_NewSize(&newSize); - if (SUCCEEDED(result)) - { - host->setNewClientSize(newSize); - } - } - - return S_OK; - } - - private: - std::weak_ptr<InspectableNativeWindow> mHost; -}; - -HRESULT GetSwapChainPanelSize( - const ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> &swapChainPanel, - const ComPtr<ABI::Windows::UI::Core::ICoreDispatcher> &dispatcher, - Size *windowSize); -} -#endif // LIBANGLE_RENDERER_D3D_D3D11_WINRT_SWAPCHAINPANELNATIVEWINDOW_H_ |