diff options
author | Andrew Knight <andrew.knight@digia.com> | 2013-04-03 19:57:09 +0300 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-08 11:35:44 +0200 |
commit | 710ad8ce1bd5d01ce048851d210ac3831ca17dde (patch) | |
tree | bb3f645e57a7887341113275c9caa2583f7e2dfa /src/3rdparty/angle/src/libEGL/Display.cpp | |
parent | 8307ab784eb4d8d22441ee61f02cb381684ca3a2 (diff) |
Upgrade ANGLE to DX11 Proto
Upgrades ANGLE to dx11proto (dx11-MRT-support tag), which splits out support
for DirectX9 & DirectX11. The DX9 codepath is used by default;
CONFIG+=angle_d3d11 must be passed to the ANGLE project to build for DX11.
Existing patches to ANGLE have been updated (or removed if no longer
needed), and a patch has been added to make DX9/DX11 codepaths mutually
exclusive.
Change-Id: Ibe13befadb94f04883eca449d0ee1f0da955ff92
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Axel Waggershauser <awagger@gmail.com>
Diffstat (limited to 'src/3rdparty/angle/src/libEGL/Display.cpp')
-rw-r--r-- | src/3rdparty/angle/src/libEGL/Display.cpp | 874 |
1 files changed, 57 insertions, 817 deletions
diff --git a/src/3rdparty/angle/src/libEGL/Display.cpp b/src/3rdparty/angle/src/libEGL/Display.cpp index a2dee6d964..d5d0f0f831 100644 --- a/src/3rdparty/angle/src/libEGL/Display.cpp +++ b/src/3rdparty/angle/src/libEGL/Display.cpp @@ -16,20 +16,12 @@ #include "common/debug.h" #include "libGLESv2/mathutil.h" -#include "libGLESv2/utilities.h" +#include "libGLESv2/main.h" +#include "libGLESv2/Context.h" +#include "libGLESv2/renderer/SwapChain.h" #include "libEGL/main.h" - -// Can also be enabled by defining FORCE_REF_RAST in the project's predefined macros -#define REF_RAST 0 - -// The "Debug This Pixel..." feature in PIX often fails when using the -// D3D9Ex interfaces. In order to get debug pixel to work on a Vista/Win 7 -// machine, define "ANGLE_ENABLE_D3D9EX=0" in your project file. -#if !defined(ANGLE_ENABLE_D3D9EX) -// Enables use of the IDirect3D9Ex interface, when available -#define ANGLE_ENABLE_D3D9EX 1 -#endif // !defined(ANGLE_ENABLE_D3D9EX) +#include "libEGL/Surface.h" namespace egl { @@ -69,27 +61,10 @@ egl::Display *Display::getDisplay(EGLNativeDisplayType displayId) Display::Display(EGLNativeDisplayType displayId, HDC deviceContext, bool software) : mDc(deviceContext) { - mD3d9Module = NULL; - - mD3d9 = NULL; - mD3d9Ex = NULL; - mDevice = NULL; - mDeviceEx = NULL; - mDeviceWindow = NULL; - - mAdapter = D3DADAPTER_DEFAULT; - - #if REF_RAST == 1 || defined(FORCE_REF_RAST) - mDeviceType = D3DDEVTYPE_REF; - #else - mDeviceType = D3DDEVTYPE_HAL; - #endif - - mMinSwapInterval = 1; - mMaxSwapInterval = 1; + mSoftwareDevice = software; mDisplayId = displayId; - mDeviceLost = false; + mRenderer = NULL; } Display::~Display() @@ -100,7 +75,7 @@ Display::~Display() if (thisDisplay != displays.end()) { - displays.erase(thisDisplay); + displays.erase(thisDisplay); } } @@ -111,197 +86,48 @@ bool Display::initialize() return true; } - if (mSoftwareDevice) - { - mD3d9Module = GetModuleHandle(TEXT("swiftshader_d3d9.dll")); - } - else - { - mD3d9Module = GetModuleHandle(TEXT("d3d9.dll")); - } - if (mD3d9Module == NULL) + mRenderer = glCreateRenderer(this, mDc, mSoftwareDevice); + + if (!mRenderer) { terminate(); - return false; - } - - typedef HRESULT (WINAPI *Direct3DCreate9ExFunc)(UINT, IDirect3D9Ex**); - Direct3DCreate9ExFunc Direct3DCreate9ExPtr = reinterpret_cast<Direct3DCreate9ExFunc>(GetProcAddress(mD3d9Module, "Direct3DCreate9Ex")); - - // Use Direct3D9Ex if available. Among other things, this version is less - // inclined to report a lost context, for example when the user switches - // desktop. Direct3D9Ex is available in Windows Vista and later if suitable drivers are available. - if (ANGLE_ENABLE_D3D9EX && Direct3DCreate9ExPtr && SUCCEEDED(Direct3DCreate9ExPtr(D3D_SDK_VERSION, &mD3d9Ex))) - { - ASSERT(mD3d9Ex); - mD3d9Ex->QueryInterface(IID_IDirect3D9, reinterpret_cast<void**>(&mD3d9)); - ASSERT(mD3d9); - } - else - { - mD3d9 = Direct3DCreate9(D3D_SDK_VERSION); + return error(EGL_NOT_INITIALIZED, false); } - if (mD3d9) - { - if (mDc != NULL) - { - // UNIMPLEMENTED(); // FIXME: Determine which adapter index the device context corresponds to - } - - HRESULT result; - - // Give up on getting device caps after about one second. - for (int i = 0; i < 10; ++i) - { - result = mD3d9->GetDeviceCaps(mAdapter, mDeviceType, &mDeviceCaps); - - if (SUCCEEDED(result)) - { - break; - } - else if (result == D3DERR_NOTAVAILABLE) - { - Sleep(100); // Give the driver some time to initialize/recover - } - else if (FAILED(result)) // D3DERR_OUTOFVIDEOMEMORY, E_OUTOFMEMORY, D3DERR_INVALIDDEVICE, or another error we can't recover from - { - terminate(); - return error(EGL_BAD_ALLOC, false); - } - } - - if (mDeviceCaps.PixelShaderVersion < D3DPS_VERSION(2, 0)) - { - terminate(); - return error(EGL_NOT_INITIALIZED, false); - } - - // When DirectX9 is running with an older DirectX8 driver, a StretchRect from a regular texture to a render target texture is not supported. - // This is required by Texture2D::convertToRenderTarget. - if ((mDeviceCaps.DevCaps2 & D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES) == 0) - { - terminate(); - return error(EGL_NOT_INITIALIZED, false); - } - - mMinSwapInterval = 4; - mMaxSwapInterval = 0; - - if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) {mMinSwapInterval = std::min(mMinSwapInterval, 0); mMaxSwapInterval = std::max(mMaxSwapInterval, 0);} - if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) {mMinSwapInterval = std::min(mMinSwapInterval, 1); mMaxSwapInterval = std::max(mMaxSwapInterval, 1);} - if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_TWO) {mMinSwapInterval = std::min(mMinSwapInterval, 2); mMaxSwapInterval = std::max(mMaxSwapInterval, 2);} - if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_THREE) {mMinSwapInterval = std::min(mMinSwapInterval, 3); mMaxSwapInterval = std::max(mMaxSwapInterval, 3);} - if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_FOUR) {mMinSwapInterval = std::min(mMinSwapInterval, 4); mMaxSwapInterval = std::max(mMaxSwapInterval, 4);} - - mD3d9->GetAdapterIdentifier(mAdapter, 0, &mAdapterIdentifier); + EGLint minSwapInterval = mRenderer->getMinSwapInterval(); + EGLint maxSwapInterval = mRenderer->getMaxSwapInterval(); + EGLint maxTextureWidth = mRenderer->getMaxTextureWidth(); + EGLint maxTextureHeight = mRenderer->getMaxTextureHeight(); - // ATI cards on XP have problems with non-power-of-two textures. - mSupportsNonPower2Textures = !(mDeviceCaps.TextureCaps & D3DPTEXTURECAPS_POW2) && - !(mDeviceCaps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2) && - !(mDeviceCaps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL) && - !(getComparableOSVersion() < versionWindowsVista && mAdapterIdentifier.VendorId == VENDOR_ID_AMD); - - const D3DFORMAT renderTargetFormats[] = - { - D3DFMT_A1R5G5B5, - // D3DFMT_A2R10G10B10, // The color_ramp conformance test uses ReadPixels with UNSIGNED_BYTE causing it to think that rendering skipped a colour value. - D3DFMT_A8R8G8B8, - D3DFMT_R5G6B5, - // D3DFMT_X1R5G5B5, // Has no compatible OpenGL ES renderbuffer format - D3DFMT_X8R8G8B8 - }; - - const D3DFORMAT depthStencilFormats[] = - { - D3DFMT_UNKNOWN, - // D3DFMT_D16_LOCKABLE, - D3DFMT_D32, - // D3DFMT_D15S1, - D3DFMT_D24S8, - D3DFMT_D24X8, - // D3DFMT_D24X4S4, - D3DFMT_D16, - // D3DFMT_D32F_LOCKABLE, - // D3DFMT_D24FS8 - }; - - D3DDISPLAYMODE currentDisplayMode; - mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); - - ConfigSet configSet; - - for (int formatIndex = 0; formatIndex < sizeof(renderTargetFormats) / sizeof(D3DFORMAT); formatIndex++) - { - D3DFORMAT renderTargetFormat = renderTargetFormats[formatIndex]; + rx::ConfigDesc *descList; + int numConfigs = mRenderer->generateConfigs(&descList); + ConfigSet configSet; - HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, renderTargetFormat); + for (int i = 0; i < numConfigs; ++i) + configSet.add(descList[i], minSwapInterval, maxSwapInterval, + maxTextureWidth, maxTextureHeight); - if (SUCCEEDED(result)) - { - for (int depthStencilIndex = 0; depthStencilIndex < sizeof(depthStencilFormats) / sizeof(D3DFORMAT); depthStencilIndex++) - { - D3DFORMAT depthStencilFormat = depthStencilFormats[depthStencilIndex]; - HRESULT result = D3D_OK; - - if(depthStencilFormat != D3DFMT_UNKNOWN) - { - result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthStencilFormat); - } - - if (SUCCEEDED(result)) - { - if(depthStencilFormat != D3DFMT_UNKNOWN) - { - result = mD3d9->CheckDepthStencilMatch(mAdapter, mDeviceType, currentDisplayMode.Format, renderTargetFormat, depthStencilFormat); - } - - if (SUCCEEDED(result)) - { - // FIXME: enumerate multi-sampling - - configSet.add(currentDisplayMode, mMinSwapInterval, mMaxSwapInterval, renderTargetFormat, depthStencilFormat, 0, - mDeviceCaps.MaxTextureWidth, mDeviceCaps.MaxTextureHeight); - } - } - } - } - } - - // Give the sorted configs a unique ID and store them internally - EGLint index = 1; - for (ConfigSet::Iterator config = configSet.mSet.begin(); config != configSet.mSet.end(); config++) - { - Config configuration = *config; - configuration.mConfigID = index; - index++; - - mConfigSet.mSet.insert(configuration); - } - } - - if (!isInitialized()) + // Give the sorted configs a unique ID and store them internally + EGLint index = 1; + for (ConfigSet::Iterator config = configSet.mSet.begin(); config != configSet.mSet.end(); config++) { - terminate(); + Config configuration = *config; + configuration.mConfigID = index; + index++; - return false; + mConfigSet.mSet.insert(configuration); } - initExtensionString(); - - static const TCHAR windowName[] = TEXT("AngleHiddenWindow"); - static const TCHAR className[] = TEXT("STATIC"); - - mDeviceWindow = CreateWindowEx(WS_EX_NOACTIVATE, className, windowName, WS_DISABLED | WS_POPUP, 0, 0, 1, 1, HWND_MESSAGE, NULL, GetModuleHandle(NULL), NULL); + mRenderer->deleteConfigs(descList); + descList = NULL; - if (!createDevice()) + if (!isInitialized()) { terminate(); return false; } - mVertexShaderCache.initialize(mDevice); - mPixelShaderCache.initialize(mDevice); + initExtensionString(); return true; } @@ -318,79 +144,8 @@ void Display::terminate() destroyContext(*mContextSet.begin()); } - while (!mEventQueryPool.empty()) - { - mEventQueryPool.back()->Release(); - mEventQueryPool.pop_back(); - } - - mVertexShaderCache.clear(); - mPixelShaderCache.clear(); - - if (mDevice) - { - // If the device is lost, reset it first to prevent leaving the driver in an unstable state - if (testDeviceLost()) - { - resetDevice(); - } - - mDevice->Release(); - mDevice = NULL; - } - - if (mDeviceEx) - { - mDeviceEx->Release(); - mDeviceEx = NULL; - } - - if (mD3d9) - { - mD3d9->Release(); - mD3d9 = NULL; - } - - if (mDeviceWindow) - { - DestroyWindow(mDeviceWindow); - mDeviceWindow = NULL; - } - - if (mD3d9Ex) - { - mD3d9Ex->Release(); - mD3d9Ex = NULL; - } - - if (mD3d9Module) - { - mD3d9Module = NULL; - } -} - -void Display::startScene() -{ - if (!mSceneStarted) - { - long result = mDevice->BeginScene(); - if (SUCCEEDED(result)) { - // This is defensive checking against the device being - // lost at unexpected times. - mSceneStarted = true; - } - } -} - -void Display::endScene() -{ - if (mSceneStarted) - { - // EndScene can fail if the device was lost, for example due - // to a TDR during a draw call. - mDevice->EndScene(); - mSceneStarted = false; - } + glDestroyRenderer(mRenderer); + mRenderer = NULL; } bool Display::getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig) @@ -443,107 +198,7 @@ bool Display::getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value) return true; } -bool Display::createDevice() -{ - D3DPRESENT_PARAMETERS presentParameters = getDefaultPresentParameters(); - DWORD behaviorFlags = D3DCREATE_FPU_PRESERVE | D3DCREATE_NOWINDOWCHANGES; - - HRESULT result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &presentParameters, &mDevice); - - if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_DEVICELOST) - { - return error(EGL_BAD_ALLOC, false); - } - - if (FAILED(result)) - { - result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParameters, &mDevice); - - if (FAILED(result)) - { - ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_NOTAVAILABLE || result == D3DERR_DEVICELOST); - return error(EGL_BAD_ALLOC, false); - } - } - - if (mD3d9Ex) - { - result = mDevice->QueryInterface(IID_IDirect3DDevice9Ex, (void**) &mDeviceEx); - ASSERT(SUCCEEDED(result)); - } - - initializeDevice(); - - return true; -} - -// 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. -void Display::initializeDevice() -{ - // Permanent non-default states - mDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE); - mDevice->SetRenderState(D3DRS_LASTPIXEL, FALSE); - - if (mDeviceCaps.PixelShaderVersion >= D3DPS_VERSION(3, 0)) - { - mDevice->SetRenderState(D3DRS_POINTSIZE_MAX, (DWORD&)mDeviceCaps.MaxPointSize); - } - else - { - mDevice->SetRenderState(D3DRS_POINTSIZE_MAX, 0x3F800000); // 1.0f - } - - mSceneStarted = false; -} - -bool Display::resetDevice() -{ - D3DPRESENT_PARAMETERS presentParameters = getDefaultPresentParameters(); - - HRESULT result = D3D_OK; - bool lost = testDeviceLost(); - int attempts = 3; - - while (lost && attempts > 0) - { - if (mDeviceEx) - { - Sleep(500); // Give the graphics driver some CPU time - result = mDeviceEx->ResetEx(&presentParameters, NULL); - } - else - { - result = mDevice->TestCooperativeLevel(); - - while (result == D3DERR_DEVICELOST) - { - Sleep(100); // Give the graphics driver some CPU time - result = mDevice->TestCooperativeLevel(); - } - - if (result == D3DERR_DEVICENOTRESET) - { - result = mDevice->Reset(&presentParameters); - } - } - - lost = testDeviceLost(); - attempts --; - } - - if (FAILED(result)) - { - ERR("Reset/ResetEx failed multiple times: 0x%08X", result); - return error(EGL_BAD_ALLOC, false); - } - - // reset device defaults - initializeDevice(); - return true; -} EGLSurface Display::createWindowSurface(HWND window, EGLConfig config, const EGLint *attribList) { @@ -587,7 +242,7 @@ EGLSurface Display::createWindowSurface(HWND window, EGLConfig config, const EGL return error(EGL_BAD_ALLOC, EGL_NO_SURFACE); } - if (testDeviceLost()) + if (mRenderer->testDeviceLost(false)) { if (!restoreLostDevice()) return EGL_NO_SURFACE; @@ -678,7 +333,7 @@ EGLSurface Display::createOffscreenSurface(EGLConfig config, HANDLE shareHandle, return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); } - if (textureFormat != EGL_NO_TEXTURE && !getNonPower2TextureSupport() && (!gl::isPow2(width) || !gl::isPow2(height))) + if (textureFormat != EGL_NO_TEXTURE && !mRenderer->getNonPower2TextureSupport() && (!gl::isPow2(width) || !gl::isPow2(height))) { return error(EGL_BAD_MATCH, EGL_NO_SURFACE); } @@ -700,7 +355,7 @@ EGLSurface Display::createOffscreenSurface(EGLConfig config, HANDLE shareHandle, return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); } - if (testDeviceLost()) + if (mRenderer->testDeviceLost(false)) { if (!restoreLostDevice()) return EGL_NO_SURFACE; @@ -721,24 +376,18 @@ EGLSurface Display::createOffscreenSurface(EGLConfig config, HANDLE shareHandle, EGLContext Display::createContext(EGLConfig configHandle, const gl::Context *shareContext, bool notifyResets, bool robustAccess) { - if (!mDevice) + if (!mRenderer) { - if (!createDevice()) - { - return NULL; - } + return NULL; } - else if (testDeviceLost()) // Lost device + else if (mRenderer->testDeviceLost(false)) // Lost device { if (!restoreLostDevice()) return NULL; } - const egl::Config *config = mConfigSet.get(configHandle); - - gl::Context *context = glCreateContext(config, shareContext, notifyResets, robustAccess); + gl::Context *context = glCreateContext(shareContext, mRenderer, notifyResets, robustAccess); mContextSet.insert(context); - mDeviceLost = false; return context; } @@ -757,18 +406,9 @@ bool Display::restoreLostDevice() (*surface)->release(); } - while (!mEventQueryPool.empty()) - { - mEventQueryPool.back()->Release(); - mEventQueryPool.pop_back(); - } - - mVertexShaderCache.clear(); - mPixelShaderCache.clear(); - - if (!resetDevice()) + if (!mRenderer->resetDevice()) { - return false; + return error(EGL_BAD_ALLOC, false); } // Restore any surfaces that may have been lost @@ -799,18 +439,20 @@ void Display::notifyDeviceLost() { (*context)->markContextLost(); } - mDeviceLost = true; - error(EGL_CONTEXT_LOST); + egl::error(EGL_CONTEXT_LOST); } -bool Display::isDeviceLost() +void Display::recreateSwapChains() { - return mDeviceLost; + for (SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++) + { + (*surface)->getSwapChain()->recreate(); + } } bool Display::isInitialized() const { - return mD3d9 != NULL && mConfigSet.size() > 0; + return mRenderer != NULL && mConfigSet.size() > 0; } bool Display::isValidConfig(EGLConfig config) @@ -841,352 +483,10 @@ bool Display::hasExistingWindowSurface(HWND window) return false; } -EGLint Display::getMinSwapInterval() -{ - return mMinSwapInterval; -} - -EGLint Display::getMaxSwapInterval() -{ - return mMaxSwapInterval; -} - -IDirect3DDevice9 *Display::getDevice() -{ - if (!mDevice) - { - if (!createDevice()) - { - return NULL; - } - } - - return mDevice; -} - -D3DCAPS9 Display::getDeviceCaps() -{ - return mDeviceCaps; -} - -D3DADAPTER_IDENTIFIER9 *Display::getAdapterIdentifier() -{ - return &mAdapterIdentifier; -} - -bool Display::testDeviceLost() -{ - if (mDeviceEx) - { - return FAILED(mDeviceEx->CheckDeviceState(NULL)); - } - else if (mDevice) - { - return FAILED(mDevice->TestCooperativeLevel()); - } - - return false; // No device yet, so no reset required -} - -bool Display::testDeviceResettable() -{ - HRESULT status = D3D_OK; - - if (mDeviceEx) - { - status = mDeviceEx->CheckDeviceState(NULL); - } - else if (mDevice) - { - status = mDevice->TestCooperativeLevel(); - } - - switch (status) - { - case D3DERR_DEVICENOTRESET: - case D3DERR_DEVICEHUNG: - return true; - default: - return false; - } -} - -void Display::sync(bool block) -{ - HRESULT result; - - IDirect3DQuery9* query = allocateEventQuery(); - if (!query) - { - return; - } - - result = query->Issue(D3DISSUE_END); - ASSERT(SUCCEEDED(result)); - - do - { - result = query->GetData(NULL, 0, D3DGETDATA_FLUSH); - - if(block && result == S_FALSE) - { - // Keep polling, but allow other threads to do something useful first - Sleep(0); - // explicitly check for device loss - // some drivers seem to return S_FALSE even if the device is lost - // instead of D3DERR_DEVICELOST like they should - if (testDeviceLost()) - { - result = D3DERR_DEVICELOST; - } - } - } - while(block && result == S_FALSE); - - freeEventQuery(query); - - if (isDeviceLostError(result)) - { - notifyDeviceLost(); - } -} - -IDirect3DQuery9* Display::allocateEventQuery() -{ - IDirect3DQuery9 *query = NULL; - - if (mEventQueryPool.empty()) - { - HRESULT result = mDevice->CreateQuery(D3DQUERYTYPE_EVENT, &query); - ASSERT(SUCCEEDED(result)); - } - else - { - query = mEventQueryPool.back(); - mEventQueryPool.pop_back(); - } - - return query; -} - -void Display::freeEventQuery(IDirect3DQuery9* query) -{ - if (mEventQueryPool.size() > 1000) - { - query->Release(); - } - else - { - mEventQueryPool.push_back(query); - } -} - -void Display::getMultiSampleSupport(D3DFORMAT format, bool *multiSampleArray) -{ - for (int multiSampleIndex = 0; multiSampleIndex <= D3DMULTISAMPLE_16_SAMPLES; multiSampleIndex++) - { - HRESULT result = mD3d9->CheckDeviceMultiSampleType(mAdapter, mDeviceType, format, - TRUE, (D3DMULTISAMPLE_TYPE)multiSampleIndex, NULL); - - multiSampleArray[multiSampleIndex] = SUCCEEDED(result); - } -} - -bool Display::getDXT1TextureSupport() -{ - D3DDISPLAYMODE currentDisplayMode; - mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); - - return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT1)); -} - -bool Display::getDXT3TextureSupport() -{ - D3DDISPLAYMODE currentDisplayMode; - mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); - - return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT3)); -} - -bool Display::getDXT5TextureSupport() -{ - D3DDISPLAYMODE currentDisplayMode; - mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); - - return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT5)); -} - -// we use INTZ for depth textures in Direct3D9 -// we also want NULL texture support to ensure the we can make depth-only FBOs -// see http://aras-p.info/texts/D3D9GPUHacks.html -bool Display::getDepthTextureSupport() const -{ - D3DDISPLAYMODE currentDisplayMode; - mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); - - bool intz = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, - D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, D3DFMT_INTZ)); - bool null = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, - D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, D3DFMT_NULL)); - - return intz && null; -} - -bool Display::getFloat32TextureSupport(bool *filtering, bool *renderable) -{ - D3DDISPLAYMODE currentDisplayMode; - mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); - - *filtering = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER, - D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)) && - SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER, - D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F)); - - *renderable = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, - D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F))&& - SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, - D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F)); - - if (!*filtering && !*renderable) - { - return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, - D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)) && - SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, - D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F)); - } - else - { - return true; - } -} - -bool Display::getFloat16TextureSupport(bool *filtering, bool *renderable) -{ - D3DDISPLAYMODE currentDisplayMode; - mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); - - *filtering = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER, - D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) && - SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER, - D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F)); - - *renderable = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, - D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) && - SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, - D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F)); - - if (!*filtering && !*renderable) - { - return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, - D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) && - SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, - D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F)); - } - else - { - return true; - } -} - -bool Display::getLuminanceTextureSupport() -{ - D3DDISPLAYMODE currentDisplayMode; - mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); - - return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_L8)); -} - -bool Display::getLuminanceAlphaTextureSupport() -{ - D3DDISPLAYMODE currentDisplayMode; - mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); - - return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8L8)); -} - -float Display::getTextureFilterAnisotropySupport() const -{ - // Must support a minimum of 2:1 anisotropy for max anisotropy to be considered supported, per the spec - if ((mDeviceCaps.RasterCaps & D3DPRASTERCAPS_ANISOTROPY) && (mDeviceCaps.MaxAnisotropy >= 2)) - { - return mDeviceCaps.MaxAnisotropy; - } - return 1.0f; -} - -D3DPOOL Display::getBufferPool(DWORD usage) const -{ - if (mD3d9Ex != NULL) - { - return D3DPOOL_DEFAULT; - } - else - { - if (!(usage & D3DUSAGE_DYNAMIC)) - { - return D3DPOOL_MANAGED; - } - } - - return D3DPOOL_DEFAULT; -} - -D3DPOOL Display::getTexturePool(DWORD usage) const -{ - if (mD3d9Ex != NULL) - { - return D3DPOOL_DEFAULT; - } - else - { - if (!(usage & (D3DUSAGE_DEPTHSTENCIL | D3DUSAGE_RENDERTARGET))) - { - return D3DPOOL_MANAGED; - } - } - - return D3DPOOL_DEFAULT; -} - -bool Display::getEventQuerySupport() -{ - IDirect3DQuery9 *query = allocateEventQuery(); - if (query) - { - freeEventQuery(query); - return true; - } - else - { - return false; - } -} - -D3DPRESENT_PARAMETERS Display::getDefaultPresentParameters() -{ - D3DPRESENT_PARAMETERS presentParameters = {0}; - - // The default swap chain is never actually used. Surface will create a new swap chain with the proper parameters. - presentParameters.AutoDepthStencilFormat = D3DFMT_UNKNOWN; - presentParameters.BackBufferCount = 1; - presentParameters.BackBufferFormat = D3DFMT_UNKNOWN; - presentParameters.BackBufferWidth = 1; - presentParameters.BackBufferHeight = 1; - presentParameters.EnableAutoDepthStencil = FALSE; - presentParameters.Flags = 0; - presentParameters.hDeviceWindow = mDeviceWindow; - presentParameters.MultiSampleQuality = 0; - presentParameters.MultiSampleType = D3DMULTISAMPLE_NONE; - presentParameters.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; - presentParameters.Windowed = TRUE; - - return presentParameters; -} - void Display::initExtensionString() { HMODULE swiftShader = GetModuleHandle(TEXT("swiftshader_d3d9.dll")); + bool shareHandleSupported = mRenderer->getShareHandleSupport(); mExtensionString = ""; @@ -1194,7 +494,7 @@ void Display::initExtensionString() mExtensionString += "EGL_EXT_create_context_robustness "; // ANGLE-specific extensions - if (shareHandleSupported()) + if (shareHandleSupported) { mExtensionString += "EGL_ANGLE_d3d_share_handle_client_buffer "; } @@ -1206,12 +506,15 @@ void Display::initExtensionString() mExtensionString += "EGL_ANGLE_software_display "; } - if (shareHandleSupported()) + if (shareHandleSupported) { mExtensionString += "EGL_ANGLE_surface_d3d_texture_2d_share_handle "; } - mExtensionString += "EGL_NV_post_sub_buffer"; + if (mRenderer->getPostSubBufferSupport()) + { + mExtensionString += "EGL_NV_post_sub_buffer"; + } std::string::size_type end = mExtensionString.find_last_not_of(' '); if (end != std::string::npos) @@ -1225,68 +528,5 @@ const char *Display::getExtensionString() const return mExtensionString.c_str(); } -bool Display::shareHandleSupported() const -{ - // PIX doesn't seem to support using share handles, so disable them. - return isD3d9ExDevice() && !gl::perfActive(); -} - -IDirect3DVertexShader9 *Display::createVertexShader(const DWORD *function, size_t length) -{ - return mVertexShaderCache.create(function, length); -} - -IDirect3DPixelShader9 *Display::createPixelShader(const DWORD *function, size_t length) -{ - return mPixelShaderCache.create(function, length); -} - -// Only Direct3D 10 ready devices support all the necessary vertex texture formats. -// We test this using D3D9 by checking support for the R16F format. -bool Display::getVertexTextureSupport() const -{ - if (!isInitialized() || mDeviceCaps.PixelShaderVersion < D3DPS_VERSION(3, 0)) - { - return false; - } - - D3DDISPLAYMODE currentDisplayMode; - mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); - - HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_R16F); - - return SUCCEEDED(result); -} - -bool Display::getNonPower2TextureSupport() const -{ - return mSupportsNonPower2Textures; -} - -bool Display::getOcclusionQuerySupport() const -{ - if (!isInitialized()) - { - return false; - } - - IDirect3DQuery9 *query = NULL; - HRESULT result = mDevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, &query); - - if (SUCCEEDED(result) && query) - { - query->Release(); - return true; - } - else - { - return false; - } -} - -bool Display::getInstancingSupport() const -{ - return mDeviceCaps.PixelShaderVersion >= D3DPS_VERSION(3, 0); -} } |