shannon.woods@transgaming.com | bdf2d80 | 2013-02-28 23:16:20 +0000 | [diff] [blame] | 1 | #include "precompiled.h" |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 2 | // |
Nicolas Capens | 673e680 | 2014-05-28 10:28:33 -0400 | [diff] [blame] | 3 | // Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | // |
| 7 | |
| 8 | // SwapChain11.cpp: Implements a back-end specific class for the D3D11 swap chain. |
| 9 | |
Brandon Jones | c7a4104 | 2014-06-23 12:03:25 -0700 | [diff] [blame] | 10 | #include "libGLESv2/renderer/d3d/d3d11/SwapChain11.h" |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 11 | |
Brandon Jones | c7a4104 | 2014-06-23 12:03:25 -0700 | [diff] [blame] | 12 | #include "libGLESv2/renderer/d3d/d3d11/renderer11_utils.h" |
| 13 | #include "libGLESv2/renderer/d3d/d3d11/formatutils11.h" |
| 14 | #include "libGLESv2/renderer/d3d/d3d11/Renderer11.h" |
| 15 | #include "libGLESv2/renderer/d3d/d3d11/shaders/compiled/passthrough2d11vs.h" |
| 16 | #include "libGLESv2/renderer/d3d/d3d11/shaders/compiled/passthroughrgba2d11ps.h" |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 17 | |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 18 | namespace rx |
| 19 | { |
| 20 | |
| 21 | SwapChain11::SwapChain11(Renderer11 *renderer, HWND window, HANDLE shareHandle, |
| 22 | GLenum backBufferFormat, GLenum depthBufferFormat) |
| 23 | : mRenderer(renderer), SwapChain(window, shareHandle, backBufferFormat, depthBufferFormat) |
| 24 | { |
| 25 | mSwapChain = NULL; |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 26 | mBackBufferTexture = NULL; |
| 27 | mBackBufferRTView = NULL; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 28 | mOffscreenTexture = NULL; |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 29 | mOffscreenRTView = NULL; |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 30 | mOffscreenSRView = NULL; |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 31 | mDepthStencilTexture = NULL; |
| 32 | mDepthStencilDSView = NULL; |
Geoff Lang | 88f9cbf | 2013-10-18 14:33:37 -0400 | [diff] [blame] | 33 | mDepthStencilSRView = NULL; |
daniel@transgaming.com | f06e539 | 2013-01-11 21:15:50 +0000 | [diff] [blame] | 34 | mQuadVB = NULL; |
| 35 | mPassThroughSampler = NULL; |
| 36 | mPassThroughIL = NULL; |
| 37 | mPassThroughVS = NULL; |
| 38 | mPassThroughPS = NULL; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 39 | mWidth = -1; |
| 40 | mHeight = -1; |
shannon.woods@transgaming.com | ad74a4b | 2013-02-28 23:04:09 +0000 | [diff] [blame] | 41 | mSwapInterval = 0; |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 42 | mAppCreatedShareHandle = mShareHandle != NULL; |
shannon.woods@transgaming.com | 211fa2e | 2013-02-28 23:05:23 +0000 | [diff] [blame] | 43 | mPassThroughResourcesInit = false; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | SwapChain11::~SwapChain11() |
| 47 | { |
| 48 | release(); |
| 49 | } |
| 50 | |
| 51 | void SwapChain11::release() |
| 52 | { |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 53 | SafeRelease(mSwapChain); |
| 54 | SafeRelease(mBackBufferTexture); |
| 55 | SafeRelease(mBackBufferRTView); |
| 56 | SafeRelease(mOffscreenTexture); |
| 57 | SafeRelease(mOffscreenRTView); |
| 58 | SafeRelease(mOffscreenSRView); |
| 59 | SafeRelease(mDepthStencilTexture); |
| 60 | SafeRelease(mDepthStencilDSView); |
Geoff Lang | 88f9cbf | 2013-10-18 14:33:37 -0400 | [diff] [blame] | 61 | SafeRelease(mDepthStencilSRView); |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 62 | SafeRelease(mQuadVB); |
| 63 | SafeRelease(mPassThroughSampler); |
| 64 | SafeRelease(mPassThroughIL); |
| 65 | SafeRelease(mPassThroughVS); |
| 66 | SafeRelease(mPassThroughPS); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 67 | |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 68 | if (!mAppCreatedShareHandle) |
| 69 | { |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 70 | mShareHandle = NULL; |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 71 | } |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 72 | } |
| 73 | |
shannon.woods@transgaming.com | 30f52c6 | 2013-02-28 23:05:34 +0000 | [diff] [blame] | 74 | void SwapChain11::releaseOffscreenTexture() |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 75 | { |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 76 | SafeRelease(mOffscreenTexture); |
| 77 | SafeRelease(mOffscreenRTView); |
| 78 | SafeRelease(mOffscreenSRView); |
| 79 | SafeRelease(mDepthStencilTexture); |
| 80 | SafeRelease(mDepthStencilDSView); |
Jamie Madill | 8b4f8f8 | 2014-03-26 14:01:58 -0400 | [diff] [blame] | 81 | SafeRelease(mDepthStencilSRView); |
shannon.woods@transgaming.com | 30f52c6 | 2013-02-28 23:05:34 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHeight) |
| 85 | { |
| 86 | ID3D11Device *device = mRenderer->getDevice(); |
| 87 | |
| 88 | ASSERT(device != NULL); |
| 89 | |
| 90 | // D3D11 does not allow zero size textures |
| 91 | ASSERT(backbufferWidth >= 1); |
| 92 | ASSERT(backbufferHeight >= 1); |
| 93 | |
| 94 | // Preserve the render target content |
| 95 | ID3D11Texture2D *previousOffscreenTexture = mOffscreenTexture; |
| 96 | if (previousOffscreenTexture) |
| 97 | { |
| 98 | previousOffscreenTexture->AddRef(); |
| 99 | } |
| 100 | const int previousWidth = mWidth; |
| 101 | const int previousHeight = mHeight; |
| 102 | |
| 103 | releaseOffscreenTexture(); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 104 | |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 105 | // If the app passed in a share handle, open the resource |
| 106 | // See EGL_ANGLE_d3d_share_handle_client_buffer |
| 107 | if (mAppCreatedShareHandle) |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 108 | { |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 109 | ID3D11Resource *tempResource11; |
| 110 | HRESULT result = device->OpenSharedResource(mShareHandle, __uuidof(ID3D11Resource), (void**)&tempResource11); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 111 | |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 112 | if (FAILED(result)) |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 113 | { |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 114 | ERR("Failed to open the swap chain pbuffer share handle: %08lX", result); |
| 115 | release(); |
| 116 | return EGL_BAD_PARAMETER; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 117 | } |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 118 | |
| 119 | result = tempResource11->QueryInterface(__uuidof(ID3D11Texture2D), (void**)&mOffscreenTexture); |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 120 | SafeRelease(tempResource11); |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 121 | |
| 122 | if (FAILED(result)) |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 123 | { |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 124 | ERR("Failed to query texture2d interface in pbuffer share handle: %08lX", result); |
| 125 | release(); |
| 126 | return EGL_BAD_PARAMETER; |
| 127 | } |
| 128 | |
| 129 | // Validate offscreen texture parameters |
| 130 | D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0}; |
| 131 | mOffscreenTexture->GetDesc(&offscreenTextureDesc); |
| 132 | |
| 133 | if (offscreenTextureDesc.Width != (UINT)backbufferWidth |
| 134 | || offscreenTextureDesc.Height != (UINT)backbufferHeight |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 135 | || offscreenTextureDesc.Format != gl_d3d11::GetTexFormat(mBackBufferFormat) |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 136 | || offscreenTextureDesc.MipLevels != 1 |
| 137 | || offscreenTextureDesc.ArraySize != 1) |
| 138 | { |
| 139 | ERR("Invalid texture parameters in the shared offscreen texture pbuffer"); |
| 140 | release(); |
| 141 | return EGL_BAD_PARAMETER; |
| 142 | } |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | const bool useSharedResource = !mWindow && mRenderer->getShareHandleSupport(); |
| 147 | |
| 148 | D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0}; |
| 149 | offscreenTextureDesc.Width = backbufferWidth; |
| 150 | offscreenTextureDesc.Height = backbufferHeight; |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 151 | offscreenTextureDesc.Format = gl_d3d11::GetTexFormat(mBackBufferFormat); |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 152 | offscreenTextureDesc.MipLevels = 1; |
| 153 | offscreenTextureDesc.ArraySize = 1; |
| 154 | offscreenTextureDesc.SampleDesc.Count = 1; |
| 155 | offscreenTextureDesc.SampleDesc.Quality = 0; |
| 156 | offscreenTextureDesc.Usage = D3D11_USAGE_DEFAULT; |
| 157 | offscreenTextureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; |
| 158 | offscreenTextureDesc.CPUAccessFlags = 0; |
| 159 | offscreenTextureDesc.MiscFlags = useSharedResource ? D3D11_RESOURCE_MISC_SHARED : 0; |
| 160 | |
| 161 | HRESULT result = device->CreateTexture2D(&offscreenTextureDesc, NULL, &mOffscreenTexture); |
| 162 | |
| 163 | if (FAILED(result)) |
| 164 | { |
| 165 | ERR("Could not create offscreen texture: %08lX", result); |
| 166 | release(); |
| 167 | |
shannon.woods@transgaming.com | f5f5949 | 2013-02-28 23:04:40 +0000 | [diff] [blame] | 168 | if (d3d11::isDeviceLostError(result)) |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 169 | { |
| 170 | return EGL_CONTEXT_LOST; |
| 171 | } |
| 172 | else |
| 173 | { |
| 174 | return EGL_BAD_ALLOC; |
| 175 | } |
| 176 | } |
| 177 | |
Geoff Lang | 88f9cbf | 2013-10-18 14:33:37 -0400 | [diff] [blame] | 178 | d3d11::SetDebugName(mOffscreenTexture, "Offscreen back buffer texture"); |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 179 | |
| 180 | // EGL_ANGLE_surface_d3d_texture_2d_share_handle requires that we store a share handle for the client |
| 181 | if (useSharedResource) |
| 182 | { |
| 183 | IDXGIResource *offscreenTextureResource = NULL; |
| 184 | result = mOffscreenTexture->QueryInterface(__uuidof(IDXGIResource), (void**)&offscreenTextureResource); |
| 185 | |
| 186 | // Fall back to no share handle on failure |
| 187 | if (FAILED(result)) |
| 188 | { |
| 189 | ERR("Could not query offscreen texture resource: %08lX", result); |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | result = offscreenTextureResource->GetSharedHandle(&mShareHandle); |
Shannon Woods | 78568ba | 2013-08-08 14:15:08 -0400 | [diff] [blame] | 194 | SafeRelease(offscreenTextureResource); |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 195 | |
| 196 | if (FAILED(result)) |
| 197 | { |
| 198 | mShareHandle = NULL; |
| 199 | ERR("Could not get offscreen texture shared handle: %08lX", result); |
| 200 | } |
| 201 | } |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 202 | } |
| 203 | } |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 204 | |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 205 | |
| 206 | D3D11_RENDER_TARGET_VIEW_DESC offscreenRTVDesc; |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 207 | offscreenRTVDesc.Format = gl_d3d11::GetRTVFormat(mBackBufferFormat); |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 208 | offscreenRTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; |
| 209 | offscreenRTVDesc.Texture2D.MipSlice = 0; |
| 210 | |
| 211 | HRESULT result = device->CreateRenderTargetView(mOffscreenTexture, &offscreenRTVDesc, &mOffscreenRTView); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 212 | ASSERT(SUCCEEDED(result)); |
Geoff Lang | 88f9cbf | 2013-10-18 14:33:37 -0400 | [diff] [blame] | 213 | d3d11::SetDebugName(mOffscreenRTView, "Offscreen back buffer render target"); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 214 | |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 215 | D3D11_SHADER_RESOURCE_VIEW_DESC offscreenSRVDesc; |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 216 | offscreenSRVDesc.Format = gl_d3d11::GetSRVFormat(mBackBufferFormat); |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 217 | offscreenSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; |
| 218 | offscreenSRVDesc.Texture2D.MostDetailedMip = 0; |
| 219 | offscreenSRVDesc.Texture2D.MipLevels = -1; |
| 220 | |
| 221 | result = device->CreateShaderResourceView(mOffscreenTexture, &offscreenSRVDesc, &mOffscreenSRView); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 222 | ASSERT(SUCCEEDED(result)); |
Geoff Lang | 88f9cbf | 2013-10-18 14:33:37 -0400 | [diff] [blame] | 223 | d3d11::SetDebugName(mOffscreenSRView, "Offscreen back buffer shader resource"); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 224 | |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 225 | if (mDepthBufferFormat != GL_NONE) |
| 226 | { |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 227 | D3D11_TEXTURE2D_DESC depthStencilTextureDesc; |
| 228 | depthStencilTextureDesc.Width = backbufferWidth; |
| 229 | depthStencilTextureDesc.Height = backbufferHeight; |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 230 | depthStencilTextureDesc.Format = gl_d3d11::GetTexFormat(mDepthBufferFormat); |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 231 | depthStencilTextureDesc.MipLevels = 1; |
| 232 | depthStencilTextureDesc.ArraySize = 1; |
| 233 | depthStencilTextureDesc.SampleDesc.Count = 1; |
| 234 | depthStencilTextureDesc.SampleDesc.Quality = 0; |
| 235 | depthStencilTextureDesc.Usage = D3D11_USAGE_DEFAULT; |
Geoff Lang | 88f9cbf | 2013-10-18 14:33:37 -0400 | [diff] [blame] | 236 | depthStencilTextureDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE; |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 237 | depthStencilTextureDesc.CPUAccessFlags = 0; |
| 238 | depthStencilTextureDesc.MiscFlags = 0; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 239 | |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 240 | result = device->CreateTexture2D(&depthStencilTextureDesc, NULL, &mDepthStencilTexture); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 241 | if (FAILED(result)) |
| 242 | { |
| 243 | ERR("Could not create depthstencil surface for new swap chain: 0x%08X", result); |
| 244 | release(); |
| 245 | |
shannon.woods@transgaming.com | f5f5949 | 2013-02-28 23:04:40 +0000 | [diff] [blame] | 246 | if (d3d11::isDeviceLostError(result)) |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 247 | { |
| 248 | return EGL_CONTEXT_LOST; |
| 249 | } |
| 250 | else |
| 251 | { |
| 252 | return EGL_BAD_ALLOC; |
| 253 | } |
| 254 | } |
Geoff Lang | 88f9cbf | 2013-10-18 14:33:37 -0400 | [diff] [blame] | 255 | d3d11::SetDebugName(mDepthStencilTexture, "Offscreen depth stencil texture"); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 256 | |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 257 | D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilDesc; |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 258 | depthStencilDesc.Format = gl_d3d11::GetDSVFormat(mDepthBufferFormat); |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 259 | depthStencilDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; |
| 260 | depthStencilDesc.Flags = 0; |
| 261 | depthStencilDesc.Texture2D.MipSlice = 0; |
| 262 | |
| 263 | result = device->CreateDepthStencilView(mDepthStencilTexture, &depthStencilDesc, &mDepthStencilDSView); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 264 | ASSERT(SUCCEEDED(result)); |
Geoff Lang | 88f9cbf | 2013-10-18 14:33:37 -0400 | [diff] [blame] | 265 | d3d11::SetDebugName(mDepthStencilDSView, "Offscreen depth stencil view"); |
| 266 | |
| 267 | D3D11_SHADER_RESOURCE_VIEW_DESC depthStencilSRVDesc; |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 268 | depthStencilSRVDesc.Format = gl_d3d11::GetSRVFormat(mDepthBufferFormat); |
Geoff Lang | 88f9cbf | 2013-10-18 14:33:37 -0400 | [diff] [blame] | 269 | depthStencilSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; |
| 270 | depthStencilSRVDesc.Texture2D.MostDetailedMip = 0; |
| 271 | depthStencilSRVDesc.Texture2D.MipLevels = -1; |
| 272 | |
| 273 | result = device->CreateShaderResourceView(mDepthStencilTexture, &depthStencilSRVDesc, &mDepthStencilSRView); |
| 274 | ASSERT(SUCCEEDED(result)); |
| 275 | d3d11::SetDebugName(mDepthStencilSRView, "Offscreen depth stencil shader resource"); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 276 | } |
| 277 | |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 278 | mWidth = backbufferWidth; |
| 279 | mHeight = backbufferHeight; |
| 280 | |
shannon.woods@transgaming.com | 30f52c6 | 2013-02-28 23:05:34 +0000 | [diff] [blame] | 281 | if (previousOffscreenTexture != NULL) |
| 282 | { |
| 283 | D3D11_BOX sourceBox = {0}; |
| 284 | sourceBox.left = 0; |
| 285 | sourceBox.right = std::min(previousWidth, mWidth); |
| 286 | sourceBox.top = std::max(previousHeight - mHeight, 0); |
| 287 | sourceBox.bottom = previousHeight; |
| 288 | sourceBox.front = 0; |
| 289 | sourceBox.back = 1; |
| 290 | |
| 291 | ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); |
| 292 | const int yoffset = std::max(mHeight - previousHeight, 0); |
| 293 | deviceContext->CopySubresourceRegion(mOffscreenTexture, 0, 0, yoffset, 0, previousOffscreenTexture, 0, &sourceBox); |
| 294 | |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 295 | SafeRelease(previousOffscreenTexture); |
shannon.woods@transgaming.com | 30f52c6 | 2013-02-28 23:05:34 +0000 | [diff] [blame] | 296 | |
| 297 | if (mSwapChain) |
| 298 | { |
| 299 | swapRect(0, 0, mWidth, mHeight); |
| 300 | } |
| 301 | } |
| 302 | |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 303 | return EGL_SUCCESS; |
| 304 | } |
| 305 | |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 306 | EGLint SwapChain11::resize(EGLint backbufferWidth, EGLint backbufferHeight) |
| 307 | { |
| 308 | ID3D11Device *device = mRenderer->getDevice(); |
| 309 | |
| 310 | if (device == NULL) |
| 311 | { |
| 312 | return EGL_BAD_ACCESS; |
| 313 | } |
| 314 | |
Jamie Madill | fa3d9f3 | 2013-12-03 16:58:17 -0500 | [diff] [blame] | 315 | // EGL allows creating a surface with 0x0 dimension, however, DXGI does not like 0x0 swapchains |
| 316 | if (backbufferWidth < 1 || backbufferHeight < 1) |
| 317 | { |
| 318 | return EGL_SUCCESS; |
| 319 | } |
| 320 | |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 321 | // Can only call resize if we have already created our swap buffer and resources |
| 322 | ASSERT(mSwapChain && mBackBufferTexture && mBackBufferRTView); |
| 323 | |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 324 | SafeRelease(mBackBufferTexture); |
| 325 | SafeRelease(mBackBufferRTView); |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 326 | |
| 327 | // Resize swap chain |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 328 | DXGI_FORMAT backbufferDXGIFormat = gl_d3d11::GetTexFormat(mBackBufferFormat); |
Nicolas Capens | 673e680 | 2014-05-28 10:28:33 -0400 | [diff] [blame] | 329 | HRESULT result = mSwapChain->ResizeBuffers(1, backbufferWidth, backbufferHeight, backbufferDXGIFormat, 0); |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 330 | |
| 331 | if (FAILED(result)) |
| 332 | { |
| 333 | ERR("Error resizing swap chain buffers: 0x%08X", result); |
| 334 | release(); |
| 335 | |
| 336 | if (d3d11::isDeviceLostError(result)) |
| 337 | { |
| 338 | return EGL_CONTEXT_LOST; |
| 339 | } |
| 340 | else |
| 341 | { |
| 342 | return EGL_BAD_ALLOC; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBufferTexture); |
| 347 | ASSERT(SUCCEEDED(result)); |
| 348 | if (SUCCEEDED(result)) |
| 349 | { |
| 350 | d3d11::SetDebugName(mBackBufferTexture, "Back buffer texture"); |
| 351 | } |
| 352 | |
| 353 | result = device->CreateRenderTargetView(mBackBufferTexture, NULL, &mBackBufferRTView); |
| 354 | ASSERT(SUCCEEDED(result)); |
| 355 | if (SUCCEEDED(result)) |
| 356 | { |
| 357 | d3d11::SetDebugName(mBackBufferRTView, "Back buffer render target"); |
| 358 | } |
| 359 | |
| 360 | return resetOffscreenTexture(backbufferWidth, backbufferHeight); |
| 361 | } |
| 362 | |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 363 | EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swapInterval) |
| 364 | { |
| 365 | ID3D11Device *device = mRenderer->getDevice(); |
| 366 | |
| 367 | if (device == NULL) |
| 368 | { |
| 369 | return EGL_BAD_ACCESS; |
| 370 | } |
| 371 | |
| 372 | // Release specific resources to free up memory for the new render target, while the |
| 373 | // old render target still exists for the purpose of preserving its contents. |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 374 | SafeRelease(mSwapChain); |
| 375 | SafeRelease(mBackBufferTexture); |
| 376 | SafeRelease(mBackBufferRTView); |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 377 | |
| 378 | mSwapInterval = static_cast<unsigned int>(swapInterval); |
| 379 | if (mSwapInterval > 4) |
| 380 | { |
| 381 | // IDXGISwapChain::Present documentation states that valid sync intervals are in the [0,4] range |
| 382 | return EGL_BAD_PARAMETER; |
| 383 | } |
| 384 | |
shannon.woods@transgaming.com | 8c6d9df | 2013-02-28 23:08:57 +0000 | [diff] [blame] | 385 | // EGL allows creating a surface with 0x0 dimension, however, DXGI does not like 0x0 swapchains |
| 386 | if (backbufferWidth < 1 || backbufferHeight < 1) |
| 387 | { |
| 388 | releaseOffscreenTexture(); |
| 389 | return EGL_SUCCESS; |
| 390 | } |
| 391 | |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 392 | if (mWindow) |
| 393 | { |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 394 | IDXGIFactory *factory = mRenderer->getDxgiFactory(); |
| 395 | |
| 396 | DXGI_SWAP_CHAIN_DESC swapChainDesc = {0}; |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 397 | swapChainDesc.BufferDesc.Width = backbufferWidth; |
| 398 | swapChainDesc.BufferDesc.Height = backbufferHeight; |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 399 | swapChainDesc.BufferDesc.RefreshRate.Numerator = 0; |
| 400 | swapChainDesc.BufferDesc.RefreshRate.Denominator = 1; |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 401 | swapChainDesc.BufferDesc.Format = gl_d3d11::GetTexFormat(mBackBufferFormat); |
Nicolas Capens | 0e3efa5 | 2014-05-16 16:54:23 -0400 | [diff] [blame] | 402 | swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; |
| 403 | swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 404 | swapChainDesc.SampleDesc.Count = 1; |
| 405 | swapChainDesc.SampleDesc.Quality = 0; |
Nicolas Capens | 0e3efa5 | 2014-05-16 16:54:23 -0400 | [diff] [blame] | 406 | swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; |
Nicolas Capens | 673e680 | 2014-05-28 10:28:33 -0400 | [diff] [blame] | 407 | swapChainDesc.BufferCount = 1; |
Nicolas Capens | 0e3efa5 | 2014-05-16 16:54:23 -0400 | [diff] [blame] | 408 | swapChainDesc.OutputWindow = mWindow; |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 409 | swapChainDesc.Windowed = TRUE; |
Nicolas Capens | 0e3efa5 | 2014-05-16 16:54:23 -0400 | [diff] [blame] | 410 | swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; |
| 411 | swapChainDesc.Flags = 0; |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 412 | |
| 413 | HRESULT result = factory->CreateSwapChain(device, &swapChainDesc, &mSwapChain); |
| 414 | |
| 415 | if (FAILED(result)) |
| 416 | { |
| 417 | ERR("Could not create additional swap chains or offscreen surfaces: %08lX", result); |
| 418 | release(); |
| 419 | |
| 420 | if (d3d11::isDeviceLostError(result)) |
| 421 | { |
| 422 | return EGL_CONTEXT_LOST; |
| 423 | } |
| 424 | else |
| 425 | { |
Geoff Lang | 94a9089 | 2014-02-18 17:14:19 -0500 | [diff] [blame] | 426 | return EGL_BAD_ALLOC; |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
| 430 | result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBufferTexture); |
| 431 | ASSERT(SUCCEEDED(result)); |
| 432 | d3d11::SetDebugName(mBackBufferTexture, "Back buffer texture"); |
| 433 | |
| 434 | result = device->CreateRenderTargetView(mBackBufferTexture, NULL, &mBackBufferRTView); |
| 435 | ASSERT(SUCCEEDED(result)); |
| 436 | d3d11::SetDebugName(mBackBufferRTView, "Back buffer render target"); |
| 437 | } |
| 438 | |
shannon.woods@transgaming.com | 211fa2e | 2013-02-28 23:05:23 +0000 | [diff] [blame] | 439 | // If we are resizing the swap chain, we don't wish to recreate all the static resources |
| 440 | if (!mPassThroughResourcesInit) |
| 441 | { |
| 442 | mPassThroughResourcesInit = true; |
| 443 | initPassThroughResources(); |
| 444 | } |
| 445 | |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 446 | return resetOffscreenTexture(backbufferWidth, backbufferHeight); |
shannon.woods@transgaming.com | 211fa2e | 2013-02-28 23:05:23 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | void SwapChain11::initPassThroughResources() |
| 450 | { |
| 451 | ID3D11Device *device = mRenderer->getDevice(); |
| 452 | |
| 453 | ASSERT(device != NULL); |
| 454 | |
| 455 | // Make sure our resources are all not allocated, when we create |
| 456 | ASSERT(mQuadVB == NULL && mPassThroughSampler == NULL); |
| 457 | ASSERT(mPassThroughIL == NULL && mPassThroughVS == NULL && mPassThroughPS == NULL); |
| 458 | |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 459 | D3D11_BUFFER_DESC vbDesc; |
shannon.woods@transgaming.com | f3d8207 | 2013-01-25 21:50:43 +0000 | [diff] [blame] | 460 | vbDesc.ByteWidth = sizeof(d3d11::PositionTexCoordVertex) * 4; |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 461 | vbDesc.Usage = D3D11_USAGE_DYNAMIC; |
| 462 | vbDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; |
| 463 | vbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; |
| 464 | vbDesc.MiscFlags = 0; |
| 465 | vbDesc.StructureByteStride = 0; |
| 466 | |
shannon.woods@transgaming.com | 211fa2e | 2013-02-28 23:05:23 +0000 | [diff] [blame] | 467 | HRESULT result = device->CreateBuffer(&vbDesc, NULL, &mQuadVB); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 468 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | ad3d827 | 2013-01-11 04:11:14 +0000 | [diff] [blame] | 469 | d3d11::SetDebugName(mQuadVB, "Swap chain quad vertex buffer"); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 470 | |
| 471 | D3D11_SAMPLER_DESC samplerDesc; |
| 472 | samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; |
| 473 | samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; |
| 474 | samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; |
| 475 | samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; |
| 476 | samplerDesc.MipLODBias = 0.0f; |
| 477 | samplerDesc.MaxAnisotropy = 0; |
| 478 | samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; |
| 479 | samplerDesc.BorderColor[0] = 0.0f; |
| 480 | samplerDesc.BorderColor[1] = 0.0f; |
| 481 | samplerDesc.BorderColor[2] = 0.0f; |
| 482 | samplerDesc.BorderColor[3] = 0.0f; |
| 483 | samplerDesc.MinLOD = 0; |
| 484 | samplerDesc.MaxLOD = D3D11_FLOAT32_MAX; |
| 485 | |
| 486 | result = device->CreateSamplerState(&samplerDesc, &mPassThroughSampler); |
| 487 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | ad3d827 | 2013-01-11 04:11:14 +0000 | [diff] [blame] | 488 | d3d11::SetDebugName(mPassThroughSampler, "Swap chain pass through sampler"); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 489 | |
| 490 | D3D11_INPUT_ELEMENT_DESC quadLayout[] = |
| 491 | { |
| 492 | { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, |
| 493 | { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0 }, |
| 494 | }; |
| 495 | |
shannonwoods@chromium.org | ad8a0d3 | 2013-05-30 00:03:28 +0000 | [diff] [blame] | 496 | result = device->CreateInputLayout(quadLayout, 2, g_VS_Passthrough2D, sizeof(g_VS_Passthrough2D), &mPassThroughIL); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 497 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | ad3d827 | 2013-01-11 04:11:14 +0000 | [diff] [blame] | 498 | d3d11::SetDebugName(mPassThroughIL, "Swap chain pass through layout"); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 499 | |
shannonwoods@chromium.org | ad8a0d3 | 2013-05-30 00:03:28 +0000 | [diff] [blame] | 500 | result = device->CreateVertexShader(g_VS_Passthrough2D, sizeof(g_VS_Passthrough2D), NULL, &mPassThroughVS); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 501 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | ad3d827 | 2013-01-11 04:11:14 +0000 | [diff] [blame] | 502 | d3d11::SetDebugName(mPassThroughVS, "Swap chain pass through vertex shader"); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 503 | |
shannonwoods@chromium.org | ad8a0d3 | 2013-05-30 00:03:28 +0000 | [diff] [blame] | 504 | result = device->CreatePixelShader(g_PS_PassthroughRGBA2D, sizeof(g_PS_PassthroughRGBA2D), NULL, &mPassThroughPS); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 505 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | ad3d827 | 2013-01-11 04:11:14 +0000 | [diff] [blame] | 506 | d3d11::SetDebugName(mPassThroughPS, "Swap chain pass through pixel shader"); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | // parameters should be validated/clamped by caller |
| 510 | EGLint SwapChain11::swapRect(EGLint x, EGLint y, EGLint width, EGLint height) |
| 511 | { |
| 512 | if (!mSwapChain) |
| 513 | { |
| 514 | return EGL_SUCCESS; |
| 515 | } |
| 516 | |
| 517 | ID3D11Device *device = mRenderer->getDevice(); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 518 | ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 519 | |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 520 | // Set vertices |
| 521 | D3D11_MAPPED_SUBRESOURCE mappedResource; |
| 522 | HRESULT result = deviceContext->Map(mQuadVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); |
| 523 | if (FAILED(result)) |
| 524 | { |
| 525 | return EGL_BAD_ACCESS; |
| 526 | } |
| 527 | |
shannon.woods@transgaming.com | f3d8207 | 2013-01-25 21:50:43 +0000 | [diff] [blame] | 528 | d3d11::PositionTexCoordVertex *vertices = static_cast<d3d11::PositionTexCoordVertex*>(mappedResource.pData); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 529 | |
| 530 | // Create a quad in homogeneous coordinates |
shannon.woods@transgaming.com | 2ac02d5 | 2013-01-25 21:56:54 +0000 | [diff] [blame] | 531 | float x1 = (x / float(mWidth)) * 2.0f - 1.0f; |
shannon.woods@transgaming.com | 0bbb08d | 2013-02-28 23:09:11 +0000 | [diff] [blame] | 532 | float y1 = (y / float(mHeight)) * 2.0f - 1.0f; |
shannon.woods@transgaming.com | 2ac02d5 | 2013-01-25 21:56:54 +0000 | [diff] [blame] | 533 | float x2 = ((x + width) / float(mWidth)) * 2.0f - 1.0f; |
shannon.woods@transgaming.com | 0bbb08d | 2013-02-28 23:09:11 +0000 | [diff] [blame] | 534 | float y2 = ((y + height) / float(mHeight)) * 2.0f - 1.0f; |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 535 | |
| 536 | float u1 = x / float(mWidth); |
| 537 | float v1 = y / float(mHeight); |
| 538 | float u2 = (x + width) / float(mWidth); |
| 539 | float v2 = (y + height) / float(mHeight); |
| 540 | |
shannon.woods@transgaming.com | f3d8207 | 2013-01-25 21:50:43 +0000 | [diff] [blame] | 541 | d3d11::SetPositionTexCoordVertex(&vertices[0], x1, y1, u1, v1); |
| 542 | d3d11::SetPositionTexCoordVertex(&vertices[1], x1, y2, u1, v2); |
| 543 | d3d11::SetPositionTexCoordVertex(&vertices[2], x2, y1, u2, v1); |
| 544 | d3d11::SetPositionTexCoordVertex(&vertices[3], x2, y2, u2, v2); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 545 | |
| 546 | deviceContext->Unmap(mQuadVB, 0); |
| 547 | |
shannon.woods@transgaming.com | f3d8207 | 2013-01-25 21:50:43 +0000 | [diff] [blame] | 548 | static UINT stride = sizeof(d3d11::PositionTexCoordVertex); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 549 | static UINT startIdx = 0; |
| 550 | deviceContext->IASetVertexBuffers(0, 1, &mQuadVB, &stride, &startIdx); |
| 551 | |
| 552 | // Apply state |
| 553 | deviceContext->OMSetDepthStencilState(NULL, 0xFFFFFFFF); |
| 554 | |
| 555 | static const float blendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; |
| 556 | deviceContext->OMSetBlendState(NULL, blendFactor, 0xFFFFFFF); |
| 557 | |
| 558 | deviceContext->RSSetState(NULL); |
| 559 | |
| 560 | // Apply shaders |
| 561 | deviceContext->IASetInputLayout(mPassThroughIL); |
| 562 | deviceContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); |
| 563 | deviceContext->VSSetShader(mPassThroughVS, NULL, 0); |
| 564 | deviceContext->PSSetShader(mPassThroughPS, NULL, 0); |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 565 | deviceContext->GSSetShader(NULL, NULL, 0); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 566 | |
| 567 | // Apply render targets |
shannon.woods%transgaming.com@gtempaccount.com | ba2744f | 2013-04-13 03:33:38 +0000 | [diff] [blame] | 568 | mRenderer->setOneTimeRenderTarget(mBackBufferRTView); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 569 | |
daniel@transgaming.com | 9799a2f | 2013-01-11 04:09:27 +0000 | [diff] [blame] | 570 | // Set the viewport |
| 571 | D3D11_VIEWPORT viewport; |
| 572 | viewport.TopLeftX = 0; |
| 573 | viewport.TopLeftY = 0; |
| 574 | viewport.Width = mWidth; |
| 575 | viewport.Height = mHeight; |
| 576 | viewport.MinDepth = 0.0f; |
| 577 | viewport.MaxDepth = 1.0f; |
| 578 | deviceContext->RSSetViewports(1, &viewport); |
| 579 | |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 580 | // Apply textures |
| 581 | deviceContext->PSSetShaderResources(0, 1, &mOffscreenSRView); |
| 582 | deviceContext->PSSetSamplers(0, 1, &mPassThroughSampler); |
| 583 | |
| 584 | // Draw |
| 585 | deviceContext->Draw(4, 0); |
Geoff Lang | f5ef21c | 2013-10-03 11:20:48 -0400 | [diff] [blame] | 586 | |
Shannon Woods | fb83947 | 2014-06-16 13:21:41 -0400 | [diff] [blame] | 587 | #ifdef ANGLE_FORCE_VSYNC_OFF |
Geoff Lang | f5ef21c | 2013-10-03 11:20:48 -0400 | [diff] [blame] | 588 | result = mSwapChain->Present(0, 0); |
| 589 | #else |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 590 | result = mSwapChain->Present(mSwapInterval, 0); |
Geoff Lang | f5ef21c | 2013-10-03 11:20:48 -0400 | [diff] [blame] | 591 | #endif |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 592 | |
| 593 | if (result == DXGI_ERROR_DEVICE_REMOVED) |
| 594 | { |
| 595 | HRESULT removedReason = device->GetDeviceRemovedReason(); |
Jamie Madill | bae30a0 | 2014-06-17 10:45:02 -0400 | [diff] [blame] | 596 | UNUSED_TRACE_VARIABLE(removedReason); |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 597 | ERR("Present failed: the D3D11 device was removed: 0x%08X", removedReason); |
| 598 | return EGL_CONTEXT_LOST; |
| 599 | } |
| 600 | else if (result == DXGI_ERROR_DEVICE_RESET) |
| 601 | { |
| 602 | ERR("Present failed: the D3D11 device was reset from a bad command."); |
| 603 | return EGL_CONTEXT_LOST; |
| 604 | } |
| 605 | else if (FAILED(result)) |
| 606 | { |
| 607 | ERR("Present failed with error code 0x%08X", result); |
| 608 | } |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 609 | |
| 610 | // Unbind |
| 611 | static ID3D11ShaderResourceView *const nullSRV = NULL; |
| 612 | deviceContext->PSSetShaderResources(0, 1, &nullSRV); |
| 613 | |
shannon.woods%transgaming.com@gtempaccount.com | ba2744f | 2013-04-13 03:33:38 +0000 | [diff] [blame] | 614 | mRenderer->unapplyRenderTargets(); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 615 | mRenderer->markAllStateDirty(); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 616 | |
| 617 | return EGL_SUCCESS; |
| 618 | } |
| 619 | |
shannon.woods@transgaming.com | 5c25ed2 | 2013-01-25 21:49:51 +0000 | [diff] [blame] | 620 | ID3D11Texture2D *SwapChain11::getOffscreenTexture() |
| 621 | { |
shannon.woods@transgaming.com | 5c25ed2 | 2013-01-25 21:49:51 +0000 | [diff] [blame] | 622 | return mOffscreenTexture; |
| 623 | } |
| 624 | |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 625 | ID3D11RenderTargetView *SwapChain11::getRenderTarget() |
| 626 | { |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 627 | return mOffscreenRTView; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 628 | } |
| 629 | |
shannon.woods@transgaming.com | 5c25ed2 | 2013-01-25 21:49:51 +0000 | [diff] [blame] | 630 | ID3D11ShaderResourceView *SwapChain11::getRenderTargetShaderResource() |
| 631 | { |
shannon.woods@transgaming.com | 5c25ed2 | 2013-01-25 21:49:51 +0000 | [diff] [blame] | 632 | return mOffscreenSRView; |
| 633 | } |
| 634 | |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 635 | ID3D11DepthStencilView *SwapChain11::getDepthStencil() |
| 636 | { |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 637 | return mDepthStencilDSView; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 638 | } |
| 639 | |
Geoff Lang | 88f9cbf | 2013-10-18 14:33:37 -0400 | [diff] [blame] | 640 | ID3D11ShaderResourceView * SwapChain11::getDepthStencilShaderResource() |
| 641 | { |
Geoff Lang | 88f9cbf | 2013-10-18 14:33:37 -0400 | [diff] [blame] | 642 | return mDepthStencilSRView; |
| 643 | } |
| 644 | |
shannon.woods@transgaming.com | 7e23285 | 2013-02-28 23:06:15 +0000 | [diff] [blame] | 645 | ID3D11Texture2D *SwapChain11::getDepthStencilTexture() |
| 646 | { |
shannon.woods@transgaming.com | 7e23285 | 2013-02-28 23:06:15 +0000 | [diff] [blame] | 647 | return mDepthStencilTexture; |
| 648 | } |
| 649 | |
daniel@transgaming.com | d733bb8 | 2012-11-28 20:53:40 +0000 | [diff] [blame] | 650 | SwapChain11 *SwapChain11::makeSwapChain11(SwapChain *swapChain) |
| 651 | { |
apatrick@chromium.org | 8b400b1 | 2013-01-30 21:53:40 +0000 | [diff] [blame] | 652 | ASSERT(HAS_DYNAMIC_TYPE(rx::SwapChain11*, swapChain)); |
daniel@transgaming.com | d733bb8 | 2012-11-28 20:53:40 +0000 | [diff] [blame] | 653 | return static_cast<rx::SwapChain11*>(swapChain); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 654 | } |
daniel@transgaming.com | d733bb8 | 2012-11-28 20:53:40 +0000 | [diff] [blame] | 655 | |
shannon.woods%transgaming.com@gtempaccount.com | 8bce3f5 | 2013-04-13 03:35:32 +0000 | [diff] [blame] | 656 | void SwapChain11::recreate() |
| 657 | { |
| 658 | // possibly should use this method instead of reset |
| 659 | } |
| 660 | |
daniel@transgaming.com | d733bb8 | 2012-11-28 20:53:40 +0000 | [diff] [blame] | 661 | } |