Path: blob/main_old/src/tests/gl_tests/D3D11FormatTablesTest.cpp
1693 views
//1// Copyright 2015 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// D3D11FormatTablesTest:6// Tests to validate our D3D11 support tables match hardware support.7//89#include "common/debug.h"10#include "libANGLE/Context.h"11#include "libANGLE/angletypes.h"12#include "libANGLE/formatutils.h"13#include "libANGLE/renderer/d3d/d3d11/Context11.h"14#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"15#include "libANGLE/renderer/d3d/d3d11/formatutils11.h"16#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"17#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h"18#include "libANGLE/renderer/dxgi_support_table.h"19#include "test_utils/ANGLETest.h"20#include "test_utils/angle_test_instantiate.h"21#include "util/EGLWindow.h"2223using namespace angle;2425namespace26{2728class D3D11FormatTablesTest : public ANGLETest29{};3031// This test enumerates all GL formats - for each, it queries the D3D support for32// using it as a texture, a render target, and sampling from it in the shader. It33// checks this against our speed-optimized baked tables, and validates they would34// give the same result.35// TODO(jmadill): Find out why in 9_3, some format queries return an error.36// The error seems to appear for formats that are not supported on 9_3.37TEST_P(D3D11FormatTablesTest, TestFormatSupport)38{39ASSERT_EQ(EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, GetParam().getRenderer());4041// Hack the angle!42gl::Context *context = static_cast<gl::Context *>(getEGLWindow()->getContext());43rx::Context11 *context11 = rx::GetImplAs<rx::Context11>(context);44rx::Renderer11 *renderer = context11->getRenderer();45const auto &textureCaps = renderer->getNativeTextureCaps();4647ID3D11Device *device = renderer->getDevice();4849const gl::FormatSet &allFormats = gl::GetAllSizedInternalFormats();50for (GLenum internalFormat : allFormats)51{52const rx::d3d11::Format &formatInfo =53rx::d3d11::Format::Get(internalFormat, renderer->getRenderer11DeviceCaps());54const auto &textureInfo = textureCaps.get(internalFormat);5556// Bits for texturing57const gl::InternalFormat &internalFormatInfo =58gl::GetSizedInternalFormatInfo(internalFormat);5960UINT texSupportMask = D3D11_FORMAT_SUPPORT_TEXTURE2D;61if (internalFormatInfo.depthBits == 0 && internalFormatInfo.stencilBits == 0)62{63texSupportMask |= D3D11_FORMAT_SUPPORT_TEXTURECUBE;64if (GetParam().majorVersion > 2)65{66texSupportMask |= D3D11_FORMAT_SUPPORT_TEXTURE3D;67}68}6970UINT texSupport = 0;71bool texSuccess = SUCCEEDED(device->CheckFormatSupport(formatInfo.texFormat, &texSupport));72bool textureable = texSuccess && ((texSupport & texSupportMask) == texSupportMask);73EXPECT_EQ(textureable, textureInfo.texturable) << " for " << gl::FmtHex(internalFormat);7475// Bits for mipmap auto-gen.76bool expectedMipGen = texSuccess && ((texSupport & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN) != 0);77auto featureLevel = renderer->getRenderer11DeviceCaps().featureLevel;78const auto &dxgiSupport = rx::d3d11::GetDXGISupport(formatInfo.texFormat, featureLevel);79bool actualMipGen =80((dxgiSupport.alwaysSupportedFlags & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN) != 0);81EXPECT_EQ(0u, dxgiSupport.optionallySupportedFlags & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN)82<< " for " << gl::FmtHex(internalFormat);83EXPECT_EQ(expectedMipGen, actualMipGen) << " for " << gl::FmtHex(internalFormat);8485// Bits for filtering86UINT filterSupport = 0;87bool filterSuccess =88SUCCEEDED(device->CheckFormatSupport(formatInfo.srvFormat, &filterSupport));89bool filterable =90filterSuccess && ((filterSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE) != 0);91EXPECT_EQ(filterable, textureInfo.filterable) << " for " << gl::FmtHex(internalFormat);9293// Bits for renderable94bool renderable = false;95UINT renderSupport = 0u;96DXGI_FORMAT renderFormat = DXGI_FORMAT_UNKNOWN;97if (internalFormatInfo.depthBits > 0 || internalFormatInfo.stencilBits > 0)98{99renderFormat = formatInfo.dsvFormat;100bool depthSuccess =101SUCCEEDED(device->CheckFormatSupport(formatInfo.dsvFormat, &renderSupport));102renderable =103depthSuccess && ((renderSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL) != 0);104if (renderable)105{106EXPECT_NE(DXGI_FORMAT_UNKNOWN, formatInfo.dsvFormat)107<< " for " << gl::FmtHex(internalFormat);108}109}110else111{112renderFormat = formatInfo.rtvFormat;113bool rtSuccess =114SUCCEEDED(device->CheckFormatSupport(formatInfo.rtvFormat, &renderSupport));115renderable = rtSuccess && ((renderSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET) != 0);116if (renderable)117{118EXPECT_NE(DXGI_FORMAT_UNKNOWN, formatInfo.rtvFormat)119<< " for " << gl::FmtHex(internalFormat);120}121}122EXPECT_EQ(renderable, textureInfo.textureAttachment)123<< " for " << gl::FmtHex(internalFormat);124EXPECT_EQ(renderable, textureInfo.renderbuffer) << " for " << gl::FmtHex(internalFormat);125if (!textureInfo.sampleCounts.empty())126{127EXPECT_TRUE(renderable) << " for " << gl::FmtHex(internalFormat);128}129130// Multisample counts131if (renderable)132{133if ((renderSupport & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET) != 0)134{135EXPECT_TRUE(!textureInfo.sampleCounts.empty());136for (unsigned int sampleCount = 1;137sampleCount <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; sampleCount *= 2)138{139UINT qualityCount = 0;140bool sampleSuccess = SUCCEEDED(device->CheckMultisampleQualityLevels(141renderFormat, sampleCount, &qualityCount));142GLuint expectedCount = (!sampleSuccess || qualityCount == 0) ? 0 : 1;143EXPECT_EQ(expectedCount, textureInfo.sampleCounts.count(sampleCount))144<< " for " << gl::FmtHex(internalFormat);145}146}147else148{149EXPECT_TRUE(textureInfo.sampleCounts.empty())150<< " for " << gl::FmtHex(internalFormat);151}152}153}154}155156// This test validates that all DXGI_FORMATs can be potentially resized without crashes.157TEST_P(D3D11FormatTablesTest, TestFormatMakeValidSize)158{159gl::Context *context = static_cast<gl::Context *>(getEGLWindow()->getContext());160rx::Context11 *context11 = rx::GetImplAs<rx::Context11>(context);161rx::Renderer11 *renderer = context11->getRenderer();162163const gl::FormatSet &allFormats = gl::GetAllSizedInternalFormats();164for (GLenum internalFormat : allFormats)165{166const rx::d3d11::Format &formatInfo =167rx::d3d11::Format::Get(internalFormat, renderer->getRenderer11DeviceCaps());168169std::array<bool, 2> isImages = {false, true};170for (auto &image : isImages)171{172int reqWidth = 32;173int reqHeight = 32;174int level = 0;175176rx::d3d11::MakeValidSize(image, formatInfo.texFormat, &reqWidth, &reqHeight, &level);177}178}179}180181ANGLE_INSTANTIATE_TEST(D3D11FormatTablesTest,182ES2_D3D11_FL9_3(),183ES2_D3D11_FL10_0(),184ES2_D3D11_FL10_1(),185ES2_D3D11_FL11_0());186187} // anonymous namespace188189190