shannon.woods@transgaming.com | bdf2d80 | 2013-02-28 23:16:20 +0000 | [diff] [blame] | 1 | #include "precompiled.h" |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2 | // |
Geoff Lang | eeba6e1 | 2014-02-03 13:12:30 -0500 | [diff] [blame] | 3 | // Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +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 | // Renderer11.cpp: Implements a back-end specific class for the D3D11 renderer. |
| 9 | |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 10 | #include "libGLESv2/main.h" |
shannonwoods@chromium.org | a2ecfcc | 2013-05-30 00:11:59 +0000 | [diff] [blame] | 11 | #include "common/utilities.h" |
daniel@transgaming.com | 18adad0 | 2012-11-28 21:04:03 +0000 | [diff] [blame] | 12 | #include "libGLESv2/Buffer.h" |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 13 | #include "libGLESv2/ProgramBinary.h" |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 14 | #include "libGLESv2/Framebuffer.h" |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 15 | #include "libGLESv2/RenderBuffer.h" |
Geoff Lang | d47e0fc | 2013-08-29 11:40:43 -0400 | [diff] [blame] | 16 | #include "libGLESv2/renderer/d3d11/Renderer11.h" |
| 17 | #include "libGLESv2/renderer/d3d11/RenderTarget11.h" |
| 18 | #include "libGLESv2/renderer/d3d11/renderer11_utils.h" |
| 19 | #include "libGLESv2/renderer/d3d11/formatutils11.h" |
| 20 | #include "libGLESv2/renderer/d3d11/ShaderExecutable11.h" |
| 21 | #include "libGLESv2/renderer/d3d11/SwapChain11.h" |
| 22 | #include "libGLESv2/renderer/d3d11/Image11.h" |
| 23 | #include "libGLESv2/renderer/d3d11/VertexBuffer11.h" |
| 24 | #include "libGLESv2/renderer/d3d11/IndexBuffer11.h" |
| 25 | #include "libGLESv2/renderer/d3d11/BufferStorage11.h" |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 26 | #include "libGLESv2/renderer/VertexDataManager.h" |
| 27 | #include "libGLESv2/renderer/IndexDataManager.h" |
Geoff Lang | d47e0fc | 2013-08-29 11:40:43 -0400 | [diff] [blame] | 28 | #include "libGLESv2/renderer/d3d11/TextureStorage11.h" |
| 29 | #include "libGLESv2/renderer/d3d11/Query11.h" |
| 30 | #include "libGLESv2/renderer/d3d11/Fence11.h" |
| 31 | #include "libGLESv2/renderer/d3d11/Blit11.h" |
| 32 | #include "libGLESv2/renderer/d3d11/Clear11.h" |
| 33 | #include "libGLESv2/renderer/d3d11/PixelTransfer11.h" |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 34 | #include "libGLESv2/renderer/d3d11/VertexArray11.h" |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 35 | #include "libEGL/Display.h" |
| 36 | |
Geoff Lang | 94a9089 | 2014-02-18 17:14:19 -0500 | [diff] [blame] | 37 | // Enable ANGLE_SKIP_DXGI_1_2_CHECK if there is not a possibility of using cross-process |
| 38 | // HWNDs or the Windows 7 Platform Update (KB2670838) is expected to be installed. |
| 39 | #ifndef ANGLE_SKIP_DXGI_1_2_CHECK |
| 40 | #define ANGLE_SKIP_DXGI_1_2_CHECK 0 |
| 41 | #endif |
| 42 | |
shannon.woods@transgaming.com | 236be77 | 2013-02-28 23:18:15 +0000 | [diff] [blame] | 43 | #ifdef _DEBUG |
| 44 | // this flag enables suppressing some spurious warnings that pop up in certain WebGL samples |
| 45 | // and conformance tests. to enable all warnings, remove this define. |
| 46 | #define ANGLE_SUPPRESS_D3D11_HAZARD_WARNINGS 1 |
| 47 | #endif |
| 48 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 49 | namespace rx |
| 50 | { |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 51 | static const DXGI_FORMAT RenderTargetFormats[] = |
| 52 | { |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 53 | DXGI_FORMAT_B8G8R8A8_UNORM, |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 54 | DXGI_FORMAT_R8G8B8A8_UNORM |
| 55 | }; |
| 56 | |
| 57 | static const DXGI_FORMAT DepthStencilFormats[] = |
| 58 | { |
shannon.woods@transgaming.com | eec5c63 | 2013-02-28 23:04:21 +0000 | [diff] [blame] | 59 | DXGI_FORMAT_UNKNOWN, |
| 60 | DXGI_FORMAT_D24_UNORM_S8_UINT, |
| 61 | DXGI_FORMAT_D16_UNORM |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 62 | }; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 63 | |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 64 | enum |
| 65 | { |
| 66 | MAX_TEXTURE_IMAGE_UNITS_VTF_SM4 = 16 |
| 67 | }; |
| 68 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 69 | Renderer11::Renderer11(egl::Display *display, HDC hDc) : Renderer(display), mDc(hDc) |
| 70 | { |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 71 | mVertexDataManager = NULL; |
| 72 | mIndexDataManager = NULL; |
| 73 | |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 74 | mLineLoopIB = NULL; |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 75 | mTriangleFanIB = NULL; |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 76 | |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 77 | mBlit = NULL; |
Jamie Madill | a21eea3 | 2013-09-18 14:36:25 -0400 | [diff] [blame] | 78 | mPixelTransfer = NULL; |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 79 | |
Geoff Lang | da507fe | 2013-08-20 12:01:42 -0400 | [diff] [blame] | 80 | mClear = NULL; |
shannon.woods@transgaming.com | 34f507c | 2013-01-25 21:52:15 +0000 | [diff] [blame] | 81 | |
daniel@transgaming.com | bdf787f | 2013-02-01 03:20:36 +0000 | [diff] [blame] | 82 | mSyncQuery = NULL; |
| 83 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 84 | mD3d11Module = NULL; |
| 85 | mDxgiModule = NULL; |
| 86 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 87 | mDeviceLost = false; |
| 88 | |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 89 | mMaxSupportedSamples = 0; |
| 90 | |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 91 | mDevice = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 92 | mDeviceContext = NULL; |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 93 | mDxgiAdapter = NULL; |
| 94 | mDxgiFactory = NULL; |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 95 | |
| 96 | mDriverConstantBufferVS = NULL; |
| 97 | mDriverConstantBufferPS = NULL; |
shannon.woods@transgaming.com | bec04bf | 2013-01-25 21:53:52 +0000 | [diff] [blame] | 98 | |
Jamie Madill | 6246dc8 | 2014-01-29 09:26:47 -0500 | [diff] [blame] | 99 | mAppliedVertexShader = NULL; |
| 100 | mAppliedGeometryShader = NULL; |
Geoff Lang | 4c5c6bb | 2014-02-05 16:32:46 -0500 | [diff] [blame] | 101 | mCurPointGeometryShader = NULL; |
Jamie Madill | 6246dc8 | 2014-01-29 09:26:47 -0500 | [diff] [blame] | 102 | mAppliedPixelShader = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | Renderer11::~Renderer11() |
| 106 | { |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 107 | release(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 108 | } |
| 109 | |
daniel@transgaming.com | b64ed28 | 2012-11-28 20:54:02 +0000 | [diff] [blame] | 110 | Renderer11 *Renderer11::makeRenderer11(Renderer *renderer) |
| 111 | { |
apatrick@chromium.org | 8b400b1 | 2013-01-30 21:53:40 +0000 | [diff] [blame] | 112 | ASSERT(HAS_DYNAMIC_TYPE(rx::Renderer11*, renderer)); |
daniel@transgaming.com | b64ed28 | 2012-11-28 20:54:02 +0000 | [diff] [blame] | 113 | return static_cast<rx::Renderer11*>(renderer); |
| 114 | } |
| 115 | |
shannon.woods%transgaming.com@gtempaccount.com | f9686c2 | 2013-04-13 03:33:45 +0000 | [diff] [blame] | 116 | #ifndef __d3d11_1_h__ |
| 117 | #define D3D11_MESSAGE_ID_DEVICE_DRAW_RENDERTARGETVIEW_NOT_SET ((D3D11_MESSAGE_ID)3146081) |
| 118 | #endif |
| 119 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 120 | EGLint Renderer11::initialize() |
| 121 | { |
Geoff Lang | dad5ed3 | 2014-02-10 12:59:17 -0500 | [diff] [blame] | 122 | if (!mCompiler.initialize()) |
daniel@transgaming.com | 25e16af | 2012-11-28 21:05:57 +0000 | [diff] [blame] | 123 | { |
| 124 | return EGL_NOT_INITIALIZED; |
| 125 | } |
| 126 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 127 | mDxgiModule = LoadLibrary(TEXT("dxgi.dll")); |
| 128 | mD3d11Module = LoadLibrary(TEXT("d3d11.dll")); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 129 | |
| 130 | if (mD3d11Module == NULL || mDxgiModule == NULL) |
| 131 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 132 | ERR("Could not load D3D11 or DXGI library - aborting!\n"); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 133 | return EGL_NOT_INITIALIZED; |
| 134 | } |
| 135 | |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 136 | // create the D3D11 device |
| 137 | ASSERT(mDevice == NULL); |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 138 | PFN_D3D11_CREATE_DEVICE D3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(mD3d11Module, "D3D11CreateDevice"); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 139 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 140 | if (D3D11CreateDevice == NULL) |
| 141 | { |
| 142 | ERR("Could not retrieve D3D11CreateDevice address - aborting!\n"); |
| 143 | return EGL_NOT_INITIALIZED; |
| 144 | } |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 145 | |
shannon.woods@transgaming.com | d438fd4 | 2013-02-28 23:17:45 +0000 | [diff] [blame] | 146 | D3D_FEATURE_LEVEL featureLevels[] = |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 147 | { |
| 148 | D3D_FEATURE_LEVEL_11_0, |
| 149 | D3D_FEATURE_LEVEL_10_1, |
| 150 | D3D_FEATURE_LEVEL_10_0, |
| 151 | }; |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 152 | |
shannonwoods@chromium.org | c3419c1 | 2013-05-30 00:02:01 +0000 | [diff] [blame] | 153 | HRESULT result = S_OK; |
| 154 | |
| 155 | #ifdef _DEBUG |
| 156 | result = D3D11CreateDevice(NULL, |
| 157 | D3D_DRIVER_TYPE_HARDWARE, |
| 158 | NULL, |
| 159 | D3D11_CREATE_DEVICE_DEBUG, |
| 160 | featureLevels, |
| 161 | ArraySize(featureLevels), |
| 162 | D3D11_SDK_VERSION, |
| 163 | &mDevice, |
| 164 | &mFeatureLevel, |
| 165 | &mDeviceContext); |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 166 | |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 167 | if (!mDevice || FAILED(result)) |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 168 | { |
shannonwoods@chromium.org | c3419c1 | 2013-05-30 00:02:01 +0000 | [diff] [blame] | 169 | ERR("Failed creating Debug D3D11 device - falling back to release runtime.\n"); |
| 170 | } |
| 171 | |
| 172 | if (!mDevice || FAILED(result)) |
| 173 | #endif |
| 174 | { |
| 175 | result = D3D11CreateDevice(NULL, |
| 176 | D3D_DRIVER_TYPE_HARDWARE, |
| 177 | NULL, |
| 178 | 0, |
| 179 | featureLevels, |
| 180 | ArraySize(featureLevels), |
| 181 | D3D11_SDK_VERSION, |
| 182 | &mDevice, |
| 183 | &mFeatureLevel, |
| 184 | &mDeviceContext); |
| 185 | |
| 186 | if (!mDevice || FAILED(result)) |
| 187 | { |
| 188 | ERR("Could not create D3D11 device - aborting!\n"); |
| 189 | return EGL_NOT_INITIALIZED; // Cleanup done by destructor through glDestroyRenderer |
| 190 | } |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 191 | } |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 192 | |
Geoff Lang | 94a9089 | 2014-02-18 17:14:19 -0500 | [diff] [blame] | 193 | #if !ANGLE_SKIP_DXGI_1_2_CHECK |
| 194 | // In order to create a swap chain for an HWND owned by another process, DXGI 1.2 is required. |
| 195 | // The easiest way to check is to query for a IDXGIDevice2. |
| 196 | bool requireDXGI1_2 = false; |
| 197 | HWND hwnd = WindowFromDC(mDc); |
| 198 | if (hwnd) |
| 199 | { |
| 200 | DWORD currentProcessId = GetCurrentProcessId(); |
| 201 | DWORD wndProcessId; |
| 202 | GetWindowThreadProcessId(hwnd, &wndProcessId); |
| 203 | requireDXGI1_2 = (currentProcessId != wndProcessId); |
| 204 | } |
| 205 | else |
| 206 | { |
| 207 | requireDXGI1_2 = true; |
| 208 | } |
| 209 | |
| 210 | if (requireDXGI1_2) |
| 211 | { |
| 212 | IDXGIDevice2 *dxgiDevice2 = NULL; |
| 213 | result = mDevice->QueryInterface(__uuidof(IDXGIDevice2), (void**)&dxgiDevice2); |
| 214 | if (FAILED(result)) |
| 215 | { |
| 216 | ERR("DXGI 1.2 required to present to HWNDs owned by another process.\n"); |
| 217 | return EGL_NOT_INITIALIZED; |
| 218 | } |
| 219 | SafeRelease(dxgiDevice2); |
| 220 | } |
| 221 | #endif |
| 222 | |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 223 | IDXGIDevice *dxgiDevice = NULL; |
| 224 | result = mDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice); |
| 225 | |
| 226 | if (FAILED(result)) |
| 227 | { |
| 228 | ERR("Could not query DXGI device - aborting!\n"); |
| 229 | return EGL_NOT_INITIALIZED; |
| 230 | } |
| 231 | |
| 232 | result = dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&mDxgiAdapter); |
| 233 | |
| 234 | if (FAILED(result)) |
| 235 | { |
| 236 | ERR("Could not retrieve DXGI adapter - aborting!\n"); |
| 237 | return EGL_NOT_INITIALIZED; |
| 238 | } |
| 239 | |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 240 | SafeRelease(dxgiDevice); |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 241 | |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 242 | mDxgiAdapter->GetDesc(&mAdapterDescription); |
| 243 | memset(mDescription, 0, sizeof(mDescription)); |
| 244 | wcstombs(mDescription, mAdapterDescription.Description, sizeof(mDescription) - 1); |
| 245 | |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 246 | result = mDxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&mDxgiFactory); |
| 247 | |
| 248 | if (!mDxgiFactory || FAILED(result)) |
| 249 | { |
| 250 | ERR("Could not create DXGI factory - aborting!\n"); |
| 251 | return EGL_NOT_INITIALIZED; |
| 252 | } |
| 253 | |
shannon.woods@transgaming.com | 236be77 | 2013-02-28 23:18:15 +0000 | [diff] [blame] | 254 | // Disable some spurious D3D11 debug warnings to prevent them from flooding the output log |
| 255 | #if defined(ANGLE_SUPPRESS_D3D11_HAZARD_WARNINGS) && defined(_DEBUG) |
| 256 | ID3D11InfoQueue *infoQueue; |
| 257 | result = mDevice->QueryInterface(__uuidof(ID3D11InfoQueue), (void **)&infoQueue); |
| 258 | |
| 259 | if (SUCCEEDED(result)) |
| 260 | { |
| 261 | D3D11_MESSAGE_ID hideMessages[] = |
| 262 | { |
shannon.woods%transgaming.com@gtempaccount.com | f9686c2 | 2013-04-13 03:33:45 +0000 | [diff] [blame] | 263 | D3D11_MESSAGE_ID_DEVICE_DRAW_RENDERTARGETVIEW_NOT_SET |
shannon.woods@transgaming.com | 236be77 | 2013-02-28 23:18:15 +0000 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | D3D11_INFO_QUEUE_FILTER filter = {0}; |
| 267 | filter.DenyList.NumIDs = ArraySize(hideMessages); |
| 268 | filter.DenyList.pIDList = hideMessages; |
| 269 | |
| 270 | infoQueue->AddStorageFilterEntries(&filter); |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 271 | SafeRelease(infoQueue); |
shannon.woods@transgaming.com | 236be77 | 2013-02-28 23:18:15 +0000 | [diff] [blame] | 272 | } |
| 273 | #endif |
| 274 | |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 275 | mMaxSupportedSamples = 0; |
| 276 | |
| 277 | const d3d11::DXGIFormatSet &dxgiFormats = d3d11::GetAllUsedDXGIFormats(); |
| 278 | for (d3d11::DXGIFormatSet::const_iterator i = dxgiFormats.begin(); i != dxgiFormats.end(); ++i) |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 279 | { |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 280 | MultisampleSupportInfo support = getMultisampleSupportInfo(*i); |
| 281 | mMultisampleSupportMap.insert(std::make_pair(*i, support)); |
| 282 | mMaxSupportedSamples = std::max(mMaxSupportedSamples, support.maxSupportedSamples); |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 283 | } |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 284 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 285 | initializeDevice(); |
| 286 | |
| 287 | return EGL_SUCCESS; |
| 288 | } |
| 289 | |
| 290 | // do any one-time device initialization |
| 291 | // NOTE: this is also needed after a device lost/reset |
| 292 | // to reset the scene status and ensure the default states are reset. |
| 293 | void Renderer11::initializeDevice() |
| 294 | { |
Jamie Madill | 1e3fa74 | 2014-06-16 10:34:00 -0400 | [diff] [blame] | 295 | mStateCache.initialize(this); |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 296 | mInputLayoutCache.initialize(mDevice, mDeviceContext); |
| 297 | |
| 298 | ASSERT(!mVertexDataManager && !mIndexDataManager); |
| 299 | mVertexDataManager = new VertexDataManager(this); |
| 300 | mIndexDataManager = new IndexDataManager(this); |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 301 | |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 302 | ASSERT(!mBlit); |
| 303 | mBlit = new Blit11(this); |
| 304 | |
Geoff Lang | da507fe | 2013-08-20 12:01:42 -0400 | [diff] [blame] | 305 | ASSERT(!mClear); |
| 306 | mClear = new Clear11(this); |
| 307 | |
Jamie Madill | a21eea3 | 2013-09-18 14:36:25 -0400 | [diff] [blame] | 308 | ASSERT(!mPixelTransfer); |
| 309 | mPixelTransfer = new PixelTransfer11(this); |
| 310 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 311 | markAllStateDirty(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 312 | } |
| 313 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 314 | int Renderer11::generateConfigs(ConfigDesc **configDescList) |
| 315 | { |
shannon.woods@transgaming.com | d438fd4 | 2013-02-28 23:17:45 +0000 | [diff] [blame] | 316 | unsigned int numRenderFormats = ArraySize(RenderTargetFormats); |
| 317 | unsigned int numDepthFormats = ArraySize(DepthStencilFormats); |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 318 | (*configDescList) = new ConfigDesc[numRenderFormats * numDepthFormats]; |
| 319 | int numConfigs = 0; |
| 320 | |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 321 | for (unsigned int formatIndex = 0; formatIndex < numRenderFormats; formatIndex++) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 322 | { |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 323 | for (unsigned int depthStencilIndex = 0; depthStencilIndex < numDepthFormats; depthStencilIndex++) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 324 | { |
| 325 | DXGI_FORMAT renderTargetFormat = RenderTargetFormats[formatIndex]; |
| 326 | |
| 327 | UINT formatSupport = 0; |
| 328 | HRESULT result = mDevice->CheckFormatSupport(renderTargetFormat, &formatSupport); |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 329 | |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 330 | if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET)) |
| 331 | { |
| 332 | DXGI_FORMAT depthStencilFormat = DepthStencilFormats[depthStencilIndex]; |
| 333 | |
shannon.woods@transgaming.com | eec5c63 | 2013-02-28 23:04:21 +0000 | [diff] [blame] | 334 | bool depthStencilFormatOK = true; |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 335 | |
shannon.woods@transgaming.com | eec5c63 | 2013-02-28 23:04:21 +0000 | [diff] [blame] | 336 | if (depthStencilFormat != DXGI_FORMAT_UNKNOWN) |
| 337 | { |
Geoff Lang | 5c9a29a | 2014-02-11 10:26:24 -0500 | [diff] [blame] | 338 | UINT depthStencilSupport = 0; |
| 339 | result = mDevice->CheckFormatSupport(depthStencilFormat, &depthStencilSupport); |
| 340 | depthStencilFormatOK = SUCCEEDED(result) && (depthStencilSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL); |
shannon.woods@transgaming.com | eec5c63 | 2013-02-28 23:04:21 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | if (depthStencilFormatOK) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 344 | { |
Jamie Madill | d6cb244 | 2013-07-10 15:13:38 -0400 | [diff] [blame] | 345 | // FIXME: parse types from context version |
| 346 | ASSERT(d3d11_gl::GetInternalFormat(renderTargetFormat, 2) == d3d11_gl::GetInternalFormat(renderTargetFormat, 3)); |
| 347 | ASSERT(d3d11_gl::GetInternalFormat(depthStencilFormat, 2) == d3d11_gl::GetInternalFormat(depthStencilFormat, 3)); |
| 348 | |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 349 | ConfigDesc newConfig; |
Jamie Madill | d6cb244 | 2013-07-10 15:13:38 -0400 | [diff] [blame] | 350 | newConfig.renderTargetFormat = d3d11_gl::GetInternalFormat(renderTargetFormat, getCurrentClientVersion()); |
| 351 | newConfig.depthStencilFormat = d3d11_gl::GetInternalFormat(depthStencilFormat, getCurrentClientVersion()); |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 352 | newConfig.multiSample = 0; // FIXME: enumerate multi-sampling |
| 353 | newConfig.fastConfig = true; // Assume all DX11 format conversions to be fast |
shannon.woods%transgaming.com@gtempaccount.com | dcf33d5 | 2013-04-13 03:33:11 +0000 | [diff] [blame] | 354 | newConfig.es3Capable = true; |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 355 | |
| 356 | (*configDescList)[numConfigs++] = newConfig; |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | return numConfigs; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void Renderer11::deleteConfigs(ConfigDesc *configDescList) |
| 366 | { |
| 367 | delete [] (configDescList); |
| 368 | } |
| 369 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 370 | void Renderer11::sync(bool block) |
| 371 | { |
daniel@transgaming.com | bdf787f | 2013-02-01 03:20:36 +0000 | [diff] [blame] | 372 | if (block) |
| 373 | { |
| 374 | HRESULT result; |
| 375 | |
| 376 | if (!mSyncQuery) |
| 377 | { |
| 378 | D3D11_QUERY_DESC queryDesc; |
| 379 | queryDesc.Query = D3D11_QUERY_EVENT; |
| 380 | queryDesc.MiscFlags = 0; |
| 381 | |
| 382 | result = mDevice->CreateQuery(&queryDesc, &mSyncQuery); |
| 383 | ASSERT(SUCCEEDED(result)); |
| 384 | } |
| 385 | |
| 386 | mDeviceContext->End(mSyncQuery); |
| 387 | mDeviceContext->Flush(); |
| 388 | |
| 389 | do |
| 390 | { |
| 391 | result = mDeviceContext->GetData(mSyncQuery, NULL, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH); |
| 392 | |
| 393 | // Keep polling, but allow other threads to do something useful first |
| 394 | Sleep(0); |
| 395 | |
| 396 | if (testDeviceLost(true)) |
| 397 | { |
| 398 | return; |
| 399 | } |
| 400 | } |
| 401 | while (result == S_FALSE); |
| 402 | } |
| 403 | else |
| 404 | { |
| 405 | mDeviceContext->Flush(); |
| 406 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 407 | } |
| 408 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 409 | SwapChain *Renderer11::createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) |
| 410 | { |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 411 | return new rx::SwapChain11(this, window, shareHandle, backBufferFormat, depthBufferFormat); |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Geoff Lang | e2e0ce0 | 2013-09-17 17:05:08 -0400 | [diff] [blame] | 414 | void Renderer11::generateSwizzle(gl::Texture *texture) |
| 415 | { |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 416 | if (texture) |
| 417 | { |
| 418 | TextureStorageInterface *texStorage = texture->getNativeTexture(); |
| 419 | if (texStorage) |
| 420 | { |
| 421 | TextureStorage11 *storage11 = TextureStorage11::makeTextureStorage11(texStorage->getStorageInstance()); |
| 422 | |
| 423 | storage11->generateSwizzles(texture->getSwizzleRed(), texture->getSwizzleGreen(), texture->getSwizzleBlue(), |
| 424 | texture->getSwizzleAlpha()); |
| 425 | } |
| 426 | } |
Geoff Lang | e2e0ce0 | 2013-09-17 17:05:08 -0400 | [diff] [blame] | 427 | } |
| 428 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 429 | void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState) |
| 430 | { |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame] | 431 | if (type == gl::SAMPLER_PIXEL) |
| 432 | { |
| 433 | if (index < 0 || index >= gl::MAX_TEXTURE_IMAGE_UNITS) |
| 434 | { |
| 435 | ERR("Pixel shader sampler index %i is not valid.", index); |
| 436 | return; |
| 437 | } |
| 438 | |
| 439 | if (mForceSetPixelSamplerStates[index] || memcmp(&samplerState, &mCurPixelSamplerStates[index], sizeof(gl::SamplerState)) != 0) |
| 440 | { |
| 441 | ID3D11SamplerState *dxSamplerState = mStateCache.getSamplerState(samplerState); |
| 442 | |
| 443 | if (!dxSamplerState) |
| 444 | { |
| 445 | ERR("NULL sampler state returned by RenderStateCache::getSamplerState, setting the default" |
| 446 | "sampler state for pixel shaders at slot %i.", index); |
| 447 | } |
| 448 | |
| 449 | mDeviceContext->PSSetSamplers(index, 1, &dxSamplerState); |
| 450 | |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame] | 451 | mCurPixelSamplerStates[index] = samplerState; |
| 452 | } |
| 453 | |
| 454 | mForceSetPixelSamplerStates[index] = false; |
| 455 | } |
| 456 | else if (type == gl::SAMPLER_VERTEX) |
| 457 | { |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 458 | if (index < 0 || index >= (int)getMaxVertexTextureImageUnits()) |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame] | 459 | { |
| 460 | ERR("Vertex shader sampler index %i is not valid.", index); |
| 461 | return; |
| 462 | } |
| 463 | |
| 464 | if (mForceSetVertexSamplerStates[index] || memcmp(&samplerState, &mCurVertexSamplerStates[index], sizeof(gl::SamplerState)) != 0) |
| 465 | { |
| 466 | ID3D11SamplerState *dxSamplerState = mStateCache.getSamplerState(samplerState); |
| 467 | |
| 468 | if (!dxSamplerState) |
| 469 | { |
| 470 | ERR("NULL sampler state returned by RenderStateCache::getSamplerState, setting the default" |
| 471 | "sampler state for vertex shaders at slot %i.", index); |
| 472 | } |
| 473 | |
| 474 | mDeviceContext->VSSetSamplers(index, 1, &dxSamplerState); |
| 475 | |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame] | 476 | mCurVertexSamplerStates[index] = samplerState; |
| 477 | } |
| 478 | |
| 479 | mForceSetVertexSamplerStates[index] = false; |
| 480 | } |
| 481 | else UNREACHABLE(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *texture) |
| 485 | { |
daniel@transgaming.com | 0785fad | 2013-01-11 04:08:10 +0000 | [diff] [blame] | 486 | ID3D11ShaderResourceView *textureSRV = NULL; |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 487 | bool forceSetTexture = false; |
daniel@transgaming.com | 0785fad | 2013-01-11 04:08:10 +0000 | [diff] [blame] | 488 | |
| 489 | if (texture) |
| 490 | { |
| 491 | TextureStorageInterface *texStorage = texture->getNativeTexture(); |
| 492 | if (texStorage) |
| 493 | { |
| 494 | TextureStorage11 *storage11 = TextureStorage11::makeTextureStorage11(texStorage->getStorageInstance()); |
Nicolas Capens | a10c1c7 | 2014-03-27 11:20:52 -0400 | [diff] [blame] | 495 | gl::SamplerState samplerState; |
| 496 | texture->getSamplerState(&samplerState); |
| 497 | textureSRV = storage11->getSRV(samplerState); |
daniel@transgaming.com | 0785fad | 2013-01-11 04:08:10 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | // If we get NULL back from getSRV here, something went wrong in the texture class and we're unexpectedly |
| 501 | // missing the shader resource view |
| 502 | ASSERT(textureSRV != NULL); |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 503 | |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 504 | forceSetTexture = texture->hasDirtyImages(); |
daniel@transgaming.com | 0785fad | 2013-01-11 04:08:10 +0000 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | if (type == gl::SAMPLER_PIXEL) |
| 508 | { |
| 509 | if (index < 0 || index >= gl::MAX_TEXTURE_IMAGE_UNITS) |
| 510 | { |
| 511 | ERR("Pixel shader sampler index %i is not valid.", index); |
| 512 | return; |
| 513 | } |
| 514 | |
Geoff Lang | 91382e5 | 2014-01-07 16:16:30 -0500 | [diff] [blame] | 515 | if (forceSetTexture || mCurPixelSRVs[index] != textureSRV) |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 516 | { |
| 517 | mDeviceContext->PSSetShaderResources(index, 1, &textureSRV); |
| 518 | } |
| 519 | |
Geoff Lang | 91382e5 | 2014-01-07 16:16:30 -0500 | [diff] [blame] | 520 | mCurPixelSRVs[index] = textureSRV; |
daniel@transgaming.com | 0785fad | 2013-01-11 04:08:10 +0000 | [diff] [blame] | 521 | } |
| 522 | else if (type == gl::SAMPLER_VERTEX) |
| 523 | { |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 524 | if (index < 0 || index >= (int)getMaxVertexTextureImageUnits()) |
daniel@transgaming.com | 0785fad | 2013-01-11 04:08:10 +0000 | [diff] [blame] | 525 | { |
| 526 | ERR("Vertex shader sampler index %i is not valid.", index); |
| 527 | return; |
| 528 | } |
| 529 | |
Geoff Lang | 91382e5 | 2014-01-07 16:16:30 -0500 | [diff] [blame] | 530 | if (forceSetTexture || mCurVertexSRVs[index] != textureSRV) |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 531 | { |
| 532 | mDeviceContext->VSSetShaderResources(index, 1, &textureSRV); |
| 533 | } |
| 534 | |
Geoff Lang | 91382e5 | 2014-01-07 16:16:30 -0500 | [diff] [blame] | 535 | mCurVertexSRVs[index] = textureSRV; |
daniel@transgaming.com | 0785fad | 2013-01-11 04:08:10 +0000 | [diff] [blame] | 536 | } |
| 537 | else UNREACHABLE(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 538 | } |
| 539 | |
shannonwoods@chromium.org | 1bddfb9 | 2013-05-30 00:11:29 +0000 | [diff] [blame] | 540 | bool Renderer11::setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]) |
| 541 | { |
shannonwoods@chromium.org | 1bddfb9 | 2013-05-30 00:11:29 +0000 | [diff] [blame] | 542 | for (unsigned int uniformBufferIndex = 0; uniformBufferIndex < gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS; uniformBufferIndex++) |
| 543 | { |
| 544 | const gl::Buffer *uniformBuffer = vertexUniformBuffers[uniformBufferIndex]; |
| 545 | if (uniformBuffer) |
| 546 | { |
| 547 | BufferStorage11 *bufferStorage = BufferStorage11::makeBufferStorage11(uniformBuffer->getStorage()); |
Geoff Lang | 9c53f1e | 2014-01-08 13:41:47 -0500 | [diff] [blame] | 548 | ID3D11Buffer *constantBuffer = bufferStorage->getBuffer(BUFFER_USAGE_UNIFORM); |
shannonwoods@chromium.org | 1bddfb9 | 2013-05-30 00:11:29 +0000 | [diff] [blame] | 549 | |
| 550 | if (!constantBuffer) |
| 551 | { |
| 552 | return false; |
| 553 | } |
| 554 | |
Geoff Lang | c6354ee | 2013-07-22 10:40:07 -0400 | [diff] [blame] | 555 | if (mCurrentConstantBufferVS[uniformBufferIndex] != bufferStorage->getSerial()) |
| 556 | { |
| 557 | mDeviceContext->VSSetConstantBuffers(getReservedVertexUniformBuffers() + uniformBufferIndex, |
| 558 | 1, &constantBuffer); |
| 559 | mCurrentConstantBufferVS[uniformBufferIndex] = bufferStorage->getSerial(); |
| 560 | } |
shannonwoods@chromium.org | 1bddfb9 | 2013-05-30 00:11:29 +0000 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
| 564 | for (unsigned int uniformBufferIndex = 0; uniformBufferIndex < gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS; uniformBufferIndex++) |
| 565 | { |
| 566 | const gl::Buffer *uniformBuffer = fragmentUniformBuffers[uniformBufferIndex]; |
| 567 | if (uniformBuffer) |
| 568 | { |
| 569 | BufferStorage11 *bufferStorage = BufferStorage11::makeBufferStorage11(uniformBuffer->getStorage()); |
Geoff Lang | 9c53f1e | 2014-01-08 13:41:47 -0500 | [diff] [blame] | 570 | ID3D11Buffer *constantBuffer = bufferStorage->getBuffer(BUFFER_USAGE_UNIFORM); |
shannonwoods@chromium.org | 1bddfb9 | 2013-05-30 00:11:29 +0000 | [diff] [blame] | 571 | |
| 572 | if (!constantBuffer) |
| 573 | { |
| 574 | return false; |
| 575 | } |
| 576 | |
Geoff Lang | c6354ee | 2013-07-22 10:40:07 -0400 | [diff] [blame] | 577 | if (mCurrentConstantBufferPS[uniformBufferIndex] != bufferStorage->getSerial()) |
| 578 | { |
| 579 | mDeviceContext->PSSetConstantBuffers(getReservedFragmentUniformBuffers() + uniformBufferIndex, |
| 580 | 1, &constantBuffer); |
| 581 | mCurrentConstantBufferPS[uniformBufferIndex] = bufferStorage->getSerial(); |
| 582 | } |
shannonwoods@chromium.org | 1bddfb9 | 2013-05-30 00:11:29 +0000 | [diff] [blame] | 583 | } |
| 584 | } |
| 585 | |
shannonwoods@chromium.org | 1bddfb9 | 2013-05-30 00:11:29 +0000 | [diff] [blame] | 586 | return true; |
| 587 | } |
| 588 | |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 589 | void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 590 | { |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 591 | if (mForceSetRasterState || memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0) |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 592 | { |
Nicolas Capens | aea8e94 | 2014-05-09 19:14:08 -0400 | [diff] [blame] | 593 | ID3D11RasterizerState *dxRasterState = mStateCache.getRasterizerState(rasterState, mScissorEnabled); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 594 | if (!dxRasterState) |
| 595 | { |
daniel@transgaming.com | 0f9b320 | 2013-01-11 04:08:05 +0000 | [diff] [blame] | 596 | ERR("NULL rasterizer state returned by RenderStateCache::getRasterizerState, setting the default" |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 597 | "rasterizer state."); |
| 598 | } |
| 599 | |
| 600 | mDeviceContext->RSSetState(dxRasterState); |
| 601 | |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 602 | mCurRasterState = rasterState; |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | mForceSetRasterState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Geoff Lang | c142e9d | 2013-09-30 15:19:47 -0400 | [diff] [blame] | 608 | void Renderer11::setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor, |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 609 | unsigned int sampleMask) |
| 610 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 611 | if (mForceSetBlendState || |
| 612 | memcmp(&blendState, &mCurBlendState, sizeof(gl::BlendState)) != 0 || |
Geoff Lang | 2a64ee4 | 2013-05-31 11:22:40 -0400 | [diff] [blame] | 613 | memcmp(&blendColor, &mCurBlendColor, sizeof(gl::ColorF)) != 0 || |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 614 | sampleMask != mCurSampleMask) |
| 615 | { |
Geoff Lang | c142e9d | 2013-09-30 15:19:47 -0400 | [diff] [blame] | 616 | ID3D11BlendState *dxBlendState = mStateCache.getBlendState(framebuffer, blendState); |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 617 | if (!dxBlendState) |
| 618 | { |
| 619 | ERR("NULL blend state returned by RenderStateCache::getBlendState, setting the default " |
| 620 | "blend state."); |
| 621 | } |
| 622 | |
shannonwoods@chromium.org | 568c82e | 2013-05-30 00:13:15 +0000 | [diff] [blame] | 623 | float blendColors[4] = {0.0f}; |
| 624 | if (blendState.sourceBlendRGB != GL_CONSTANT_ALPHA && blendState.sourceBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA && |
| 625 | blendState.destBlendRGB != GL_CONSTANT_ALPHA && blendState.destBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA) |
| 626 | { |
| 627 | blendColors[0] = blendColor.red; |
| 628 | blendColors[1] = blendColor.green; |
| 629 | blendColors[2] = blendColor.blue; |
| 630 | blendColors[3] = blendColor.alpha; |
| 631 | } |
| 632 | else |
| 633 | { |
| 634 | blendColors[0] = blendColor.alpha; |
| 635 | blendColors[1] = blendColor.alpha; |
| 636 | blendColors[2] = blendColor.alpha; |
| 637 | blendColors[3] = blendColor.alpha; |
| 638 | } |
| 639 | |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 640 | mDeviceContext->OMSetBlendState(dxBlendState, blendColors, sampleMask); |
| 641 | |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 642 | mCurBlendState = blendState; |
| 643 | mCurBlendColor = blendColor; |
| 644 | mCurSampleMask = sampleMask; |
| 645 | } |
| 646 | |
| 647 | mForceSetBlendState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 648 | } |
| 649 | |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 650 | void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, |
daniel@transgaming.com | 3a0ef48 | 2012-11-28 21:01:20 +0000 | [diff] [blame] | 651 | int stencilBackRef, bool frontFaceCCW) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 652 | { |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 653 | if (mForceSetDepthStencilState || |
| 654 | memcmp(&depthStencilState, &mCurDepthStencilState, sizeof(gl::DepthStencilState)) != 0 || |
| 655 | stencilRef != mCurStencilRef || stencilBackRef != mCurStencilBackRef) |
| 656 | { |
| 657 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
| 658 | stencilRef != stencilBackRef || |
| 659 | depthStencilState.stencilMask != depthStencilState.stencilBackMask) |
| 660 | { |
| 661 | ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are " |
| 662 | "invalid under WebGL."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 663 | return gl::error(GL_INVALID_OPERATION); |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | ID3D11DepthStencilState *dxDepthStencilState = mStateCache.getDepthStencilState(depthStencilState); |
| 667 | if (!dxDepthStencilState) |
| 668 | { |
| 669 | ERR("NULL depth stencil state returned by RenderStateCache::getDepthStencilState, " |
| 670 | "setting the default depth stencil state."); |
| 671 | } |
| 672 | |
Jamie Madill | ec91cd3 | 2014-01-21 16:38:12 -0500 | [diff] [blame] | 673 | // Max D3D11 stencil reference value is 0xFF, corresponding to the max 8 bits in a stencil buffer |
| 674 | // GL specifies we should clamp the ref value to the nearest bit depth when doing stencil ops |
| 675 | META_ASSERT(D3D11_DEFAULT_STENCIL_READ_MASK == 0xFF); |
| 676 | META_ASSERT(D3D11_DEFAULT_STENCIL_WRITE_MASK == 0xFF); |
Geoff Lang | 0bf3a98 | 2014-02-11 09:40:48 -0500 | [diff] [blame] | 677 | UINT dxStencilRef = std::min<UINT>(stencilRef, 0xFFu); |
Jamie Madill | ec91cd3 | 2014-01-21 16:38:12 -0500 | [diff] [blame] | 678 | |
Geoff Lang | 0bf3a98 | 2014-02-11 09:40:48 -0500 | [diff] [blame] | 679 | mDeviceContext->OMSetDepthStencilState(dxDepthStencilState, dxStencilRef); |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 680 | |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 681 | mCurDepthStencilState = depthStencilState; |
| 682 | mCurStencilRef = stencilRef; |
| 683 | mCurStencilBackRef = stencilBackRef; |
| 684 | } |
| 685 | |
| 686 | mForceSetDepthStencilState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 687 | } |
| 688 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 689 | void Renderer11::setScissorRectangle(const gl::Rectangle &scissor, bool enabled) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 690 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 691 | if (mForceSetScissor || memcmp(&scissor, &mCurScissor, sizeof(gl::Rectangle)) != 0 || |
| 692 | enabled != mScissorEnabled) |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 693 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 694 | if (enabled) |
| 695 | { |
| 696 | D3D11_RECT rect; |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 697 | rect.left = std::max(0, scissor.x); |
| 698 | rect.top = std::max(0, scissor.y); |
| 699 | rect.right = scissor.x + std::max(0, scissor.width); |
| 700 | rect.bottom = scissor.y + std::max(0, scissor.height); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 701 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 702 | mDeviceContext->RSSetScissorRects(1, &rect); |
| 703 | } |
| 704 | |
| 705 | if (enabled != mScissorEnabled) |
| 706 | { |
| 707 | mForceSetRasterState = true; |
| 708 | } |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 709 | |
| 710 | mCurScissor = scissor; |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 711 | mScissorEnabled = enabled; |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | mForceSetScissor = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 715 | } |
| 716 | |
daniel@transgaming.com | 1298518 | 2012-12-20 20:56:31 +0000 | [diff] [blame] | 717 | bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace, |
shannon.woods@transgaming.com | 0b236e2 | 2013-01-25 21:57:07 +0000 | [diff] [blame] | 718 | bool ignoreViewport) |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 719 | { |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 720 | gl::Rectangle actualViewport = viewport; |
| 721 | float actualZNear = gl::clamp01(zNear); |
| 722 | float actualZFar = gl::clamp01(zFar); |
| 723 | if (ignoreViewport) |
| 724 | { |
| 725 | actualViewport.x = 0; |
| 726 | actualViewport.y = 0; |
| 727 | actualViewport.width = mRenderTargetDesc.width; |
| 728 | actualViewport.height = mRenderTargetDesc.height; |
| 729 | actualZNear = 0.0f; |
| 730 | actualZFar = 1.0f; |
| 731 | } |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 732 | |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 733 | // Get D3D viewport bounds, which depends on the feature level |
| 734 | const Range& viewportBounds = getViewportBounds(); |
| 735 | |
| 736 | // Clamp width and height first to the gl maximum, then clamp further if we extend past the D3D maximum bounds |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 737 | D3D11_VIEWPORT dxViewport; |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 738 | dxViewport.TopLeftX = gl::clamp(actualViewport.x, viewportBounds.start, viewportBounds.end); |
| 739 | dxViewport.TopLeftY = gl::clamp(actualViewport.y, viewportBounds.start, viewportBounds.end); |
| 740 | dxViewport.Width = gl::clamp(actualViewport.width, 0, getMaxViewportDimension()); |
| 741 | dxViewport.Height = gl::clamp(actualViewport.height, 0, getMaxViewportDimension()); |
| 742 | dxViewport.Width = std::min((int)dxViewport.Width, viewportBounds.end - static_cast<int>(dxViewport.TopLeftX)); |
| 743 | dxViewport.Height = std::min((int)dxViewport.Height, viewportBounds.end - static_cast<int>(dxViewport.TopLeftY)); |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 744 | dxViewport.MinDepth = actualZNear; |
| 745 | dxViewport.MaxDepth = actualZFar; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 746 | |
| 747 | if (dxViewport.Width <= 0 || dxViewport.Height <= 0) |
| 748 | { |
| 749 | return false; // Nothing to render |
| 750 | } |
| 751 | |
daniel@transgaming.com | ed36abd | 2013-01-11 21:15:58 +0000 | [diff] [blame] | 752 | bool viewportChanged = mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 || |
| 753 | actualZNear != mCurNear || actualZFar != mCurFar; |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 754 | |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 755 | if (viewportChanged) |
| 756 | { |
| 757 | mDeviceContext->RSSetViewports(1, &dxViewport); |
| 758 | |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 759 | mCurViewport = actualViewport; |
| 760 | mCurNear = actualZNear; |
| 761 | mCurFar = actualZFar; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 762 | |
shannon.woods@transgaming.com | a14ecf3 | 2013-02-28 23:09:42 +0000 | [diff] [blame] | 763 | mPixelConstants.viewCoords[0] = actualViewport.width * 0.5f; |
| 764 | mPixelConstants.viewCoords[1] = actualViewport.height * 0.5f; |
| 765 | mPixelConstants.viewCoords[2] = actualViewport.x + (actualViewport.width * 0.5f); |
| 766 | mPixelConstants.viewCoords[3] = actualViewport.y + (actualViewport.height * 0.5f); |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 767 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 768 | mPixelConstants.depthFront[0] = (actualZFar - actualZNear) * 0.5f; |
| 769 | mPixelConstants.depthFront[1] = (actualZNear + actualZFar) * 0.5f; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 770 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 771 | mVertexConstants.depthRange[0] = actualZNear; |
| 772 | mVertexConstants.depthRange[1] = actualZFar; |
| 773 | mVertexConstants.depthRange[2] = actualZFar - actualZNear; |
daniel@transgaming.com | ed36abd | 2013-01-11 21:15:58 +0000 | [diff] [blame] | 774 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 775 | mPixelConstants.depthRange[0] = actualZNear; |
| 776 | mPixelConstants.depthRange[1] = actualZFar; |
| 777 | mPixelConstants.depthRange[2] = actualZFar - actualZNear; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | mForceSetViewport = false; |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 781 | return true; |
| 782 | } |
| 783 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 784 | bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count) |
| 785 | { |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 786 | D3D11_PRIMITIVE_TOPOLOGY primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 787 | |
Geoff Lang | 57e713e | 2013-07-31 17:01:58 -0400 | [diff] [blame] | 788 | GLsizei minCount = 0; |
| 789 | |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 790 | switch (mode) |
| 791 | { |
Geoff Lang | 57e713e | 2013-07-31 17:01:58 -0400 | [diff] [blame] | 792 | case GL_POINTS: primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_POINTLIST; minCount = 1; break; |
| 793 | case GL_LINES: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINELIST; minCount = 2; break; |
| 794 | case GL_LINE_LOOP: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP; minCount = 2; break; |
| 795 | case GL_LINE_STRIP: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP; minCount = 2; break; |
| 796 | case GL_TRIANGLES: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; minCount = 3; break; |
| 797 | case GL_TRIANGLE_STRIP: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; minCount = 3; break; |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 798 | // emulate fans via rewriting index buffer |
Geoff Lang | 57e713e | 2013-07-31 17:01:58 -0400 | [diff] [blame] | 799 | case GL_TRIANGLE_FAN: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; minCount = 3; break; |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 800 | default: |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 801 | return gl::error(GL_INVALID_ENUM, false); |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 802 | } |
| 803 | |
Geoff Lang | 4c09586 | 2013-07-22 10:43:36 -0400 | [diff] [blame] | 804 | if (primitiveTopology != mCurrentPrimitiveTopology) |
| 805 | { |
| 806 | mDeviceContext->IASetPrimitiveTopology(primitiveTopology); |
| 807 | mCurrentPrimitiveTopology = primitiveTopology; |
| 808 | } |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 809 | |
Geoff Lang | 57e713e | 2013-07-31 17:01:58 -0400 | [diff] [blame] | 810 | return count >= minCount; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 814 | { |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 815 | // Get the color render buffer and serial |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 816 | // Also extract the render target dimensions and view |
| 817 | unsigned int renderTargetWidth = 0; |
| 818 | unsigned int renderTargetHeight = 0; |
| 819 | GLenum renderTargetFormat = 0; |
| 820 | unsigned int renderTargetSerials[gl::IMPLEMENTATION_MAX_DRAW_BUFFERS] = {0}; |
| 821 | ID3D11RenderTargetView* framebufferRTVs[gl::IMPLEMENTATION_MAX_DRAW_BUFFERS] = {NULL}; |
| 822 | bool missingColorRenderTarget = true; |
| 823 | |
| 824 | for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 825 | { |
shannon.woods%transgaming.com@gtempaccount.com | 4059a38 | 2013-04-13 03:31:16 +0000 | [diff] [blame] | 826 | const GLenum drawBufferState = framebuffer->getDrawBufferState(colorAttachment); |
| 827 | |
| 828 | if (framebuffer->getColorbufferType(colorAttachment) != GL_NONE && drawBufferState != GL_NONE) |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 829 | { |
shannon.woods%transgaming.com@gtempaccount.com | 4059a38 | 2013-04-13 03:31:16 +0000 | [diff] [blame] | 830 | // the draw buffer must be either "none", "back" for the default buffer or the same index as this color (in order) |
| 831 | ASSERT(drawBufferState == GL_BACK || drawBufferState == (GL_COLOR_ATTACHMENT0_EXT + colorAttachment)); |
| 832 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 833 | gl::FramebufferAttachment *colorbuffer = framebuffer->getColorbuffer(colorAttachment); |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 834 | |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 835 | if (!colorbuffer) |
| 836 | { |
| 837 | ERR("render target pointer unexpectedly null."); |
| 838 | return false; |
| 839 | } |
shannon.woods@transgaming.com | 3e3da58 | 2013-02-28 23:09:03 +0000 | [diff] [blame] | 840 | |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 841 | // check for zero-sized default framebuffer, which is a special case. |
| 842 | // in this case we do not wish to modify any state and just silently return false. |
| 843 | // this will not report any gl error but will cause the calling method to return. |
| 844 | if (colorbuffer->getWidth() == 0 || colorbuffer->getHeight() == 0) |
| 845 | { |
| 846 | return false; |
| 847 | } |
| 848 | |
| 849 | renderTargetSerials[colorAttachment] = colorbuffer->getSerial(); |
| 850 | |
| 851 | // Extract the render target dimensions and view |
| 852 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(colorbuffer->getRenderTarget()); |
| 853 | if (!renderTarget) |
| 854 | { |
| 855 | ERR("render target pointer unexpectedly null."); |
| 856 | return false; |
| 857 | } |
| 858 | |
| 859 | framebufferRTVs[colorAttachment] = renderTarget->getRenderTargetView(); |
| 860 | if (!framebufferRTVs[colorAttachment]) |
| 861 | { |
| 862 | ERR("render target view pointer unexpectedly null."); |
| 863 | return false; |
| 864 | } |
| 865 | |
| 866 | if (missingColorRenderTarget) |
| 867 | { |
| 868 | renderTargetWidth = colorbuffer->getWidth(); |
| 869 | renderTargetHeight = colorbuffer->getHeight(); |
| 870 | renderTargetFormat = colorbuffer->getActualFormat(); |
| 871 | missingColorRenderTarget = false; |
| 872 | } |
Jamie Madill | ba597af | 2013-10-22 13:12:15 -0400 | [diff] [blame] | 873 | |
Geoff Lang | 91382e5 | 2014-01-07 16:16:30 -0500 | [diff] [blame] | 874 | // TODO: Detect if this color buffer is already bound as a texture and unbind it first to prevent |
| 875 | // D3D11 warnings. |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 876 | } |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | // Get the depth stencil render buffer and serials |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 880 | gl::FramebufferAttachment *depthStencil = NULL; |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 881 | unsigned int depthbufferSerial = 0; |
| 882 | unsigned int stencilbufferSerial = 0; |
| 883 | if (framebuffer->getDepthbufferType() != GL_NONE) |
| 884 | { |
| 885 | depthStencil = framebuffer->getDepthbuffer(); |
| 886 | if (!depthStencil) |
| 887 | { |
| 888 | ERR("Depth stencil pointer unexpectedly null."); |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 889 | SafeRelease(framebufferRTVs); |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 890 | return false; |
| 891 | } |
| 892 | |
| 893 | depthbufferSerial = depthStencil->getSerial(); |
| 894 | } |
| 895 | else if (framebuffer->getStencilbufferType() != GL_NONE) |
| 896 | { |
| 897 | depthStencil = framebuffer->getStencilbuffer(); |
| 898 | if (!depthStencil) |
| 899 | { |
| 900 | ERR("Depth stencil pointer unexpectedly null."); |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 901 | SafeRelease(framebufferRTVs); |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 902 | return false; |
| 903 | } |
| 904 | |
| 905 | stencilbufferSerial = depthStencil->getSerial(); |
| 906 | } |
| 907 | |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 908 | ID3D11DepthStencilView* framebufferDSV = NULL; |
| 909 | if (depthStencil) |
| 910 | { |
| 911 | RenderTarget11 *depthStencilRenderTarget = RenderTarget11::makeRenderTarget11(depthStencil->getDepthStencil()); |
| 912 | if (!depthStencilRenderTarget) |
| 913 | { |
| 914 | ERR("render target pointer unexpectedly null."); |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 915 | SafeRelease(framebufferRTVs); |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 916 | return false; |
| 917 | } |
| 918 | |
| 919 | framebufferDSV = depthStencilRenderTarget->getDepthStencilView(); |
| 920 | if (!framebufferDSV) |
| 921 | { |
| 922 | ERR("depth stencil view pointer unexpectedly null."); |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 923 | SafeRelease(framebufferRTVs); |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 924 | return false; |
| 925 | } |
| 926 | |
| 927 | // If there is no render buffer, the width, height and format values come from |
| 928 | // the depth stencil |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 929 | if (missingColorRenderTarget) |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 930 | { |
| 931 | renderTargetWidth = depthStencil->getWidth(); |
| 932 | renderTargetHeight = depthStencil->getHeight(); |
| 933 | renderTargetFormat = depthStencil->getActualFormat(); |
| 934 | } |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | // Apply the render target and depth stencil |
| 938 | if (!mRenderTargetDescInitialized || !mDepthStencilInitialized || |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 939 | memcmp(renderTargetSerials, mAppliedRenderTargetSerials, sizeof(renderTargetSerials)) != 0 || |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 940 | depthbufferSerial != mAppliedDepthbufferSerial || |
| 941 | stencilbufferSerial != mAppliedStencilbufferSerial) |
| 942 | { |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 943 | mDeviceContext->OMSetRenderTargets(getMaxRenderTargets(), framebufferRTVs, framebufferDSV); |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 944 | |
| 945 | mRenderTargetDesc.width = renderTargetWidth; |
| 946 | mRenderTargetDesc.height = renderTargetHeight; |
| 947 | mRenderTargetDesc.format = renderTargetFormat; |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 948 | mForceSetViewport = true; |
| 949 | mForceSetScissor = true; |
Geoff Lang | c142e9d | 2013-09-30 15:19:47 -0400 | [diff] [blame] | 950 | mForceSetBlendState = true; |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 951 | |
Nicolas Capens | aea8e94 | 2014-05-09 19:14:08 -0400 | [diff] [blame] | 952 | if (!mDepthStencilInitialized) |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 953 | { |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 954 | mForceSetRasterState = true; |
| 955 | } |
| 956 | |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 957 | for (unsigned int rtIndex = 0; rtIndex < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; rtIndex++) |
| 958 | { |
| 959 | mAppliedRenderTargetSerials[rtIndex] = renderTargetSerials[rtIndex]; |
| 960 | } |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 961 | mAppliedDepthbufferSerial = depthbufferSerial; |
| 962 | mAppliedStencilbufferSerial = stencilbufferSerial; |
| 963 | mRenderTargetDescInitialized = true; |
| 964 | mDepthStencilInitialized = true; |
| 965 | } |
| 966 | |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 967 | invalidateFramebufferSwizzles(framebuffer); |
| 968 | |
daniel@transgaming.com | ae39ee2 | 2012-11-28 19:42:02 +0000 | [diff] [blame] | 969 | return true; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 970 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 971 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 972 | GLenum Renderer11::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[], |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 973 | GLint first, GLsizei count, GLsizei instances) |
daniel@transgaming.com | def9f0f | 2012-11-28 20:53:20 +0000 | [diff] [blame] | 974 | { |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 975 | TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS]; |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 976 | GLenum err = mVertexDataManager->prepareVertexData(vertexAttributes, currentValues, programBinary, first, count, attributes, instances); |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 977 | if (err != GL_NO_ERROR) |
daniel@transgaming.com | da495a1 | 2012-11-28 21:03:56 +0000 | [diff] [blame] | 978 | { |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 979 | return err; |
| 980 | } |
daniel@transgaming.com | da495a1 | 2012-11-28 21:03:56 +0000 | [diff] [blame] | 981 | |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 982 | return mInputLayoutCache.applyVertexBuffers(attributes, programBinary); |
daniel@transgaming.com | def9f0f | 2012-11-28 20:53:20 +0000 | [diff] [blame] | 983 | } |
| 984 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 985 | GLenum Renderer11::applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 986 | { |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 987 | GLenum err = mIndexDataManager->prepareIndexData(type, count, elementArrayBuffer, indices, indexInfo); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 988 | |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 989 | if (err == GL_NO_ERROR) |
| 990 | { |
Geoff Lang | 7840b17 | 2014-03-13 11:20:44 -0400 | [diff] [blame] | 991 | IndexBuffer11* indexBuffer = IndexBuffer11::makeIndexBuffer11(indexInfo->indexBuffer); |
| 992 | |
| 993 | ID3D11Buffer *buffer = NULL; |
| 994 | DXGI_FORMAT bufferFormat = indexBuffer->getIndexFormat(); |
| 995 | |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 996 | if (indexInfo->storage) |
| 997 | { |
Geoff Lang | 7840b17 | 2014-03-13 11:20:44 -0400 | [diff] [blame] | 998 | BufferStorage11 *storage = BufferStorage11::makeBufferStorage11(indexInfo->storage); |
| 999 | buffer = storage->getBuffer(BUFFER_USAGE_INDEX); |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 1000 | } |
Geoff Lang | 7840b17 | 2014-03-13 11:20:44 -0400 | [diff] [blame] | 1001 | else |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 1002 | { |
Geoff Lang | 7840b17 | 2014-03-13 11:20:44 -0400 | [diff] [blame] | 1003 | buffer = indexBuffer->getBuffer(); |
| 1004 | } |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 1005 | |
Geoff Lang | 7840b17 | 2014-03-13 11:20:44 -0400 | [diff] [blame] | 1006 | if (buffer != mAppliedIB || bufferFormat != mAppliedIBFormat || indexInfo->startOffset != mAppliedIBOffset) |
| 1007 | { |
| 1008 | mDeviceContext->IASetIndexBuffer(buffer, bufferFormat, indexInfo->startOffset); |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 1009 | |
Geoff Lang | 7840b17 | 2014-03-13 11:20:44 -0400 | [diff] [blame] | 1010 | mAppliedIB = buffer; |
| 1011 | mAppliedIBFormat = bufferFormat; |
daniel@transgaming.com | 7fbf486 | 2013-01-11 04:09:22 +0000 | [diff] [blame] | 1012 | mAppliedIBOffset = indexInfo->startOffset; |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | return err; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
Geoff Lang | eeba6e1 | 2014-02-03 13:12:30 -0500 | [diff] [blame] | 1019 | void Renderer11::applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]) |
| 1020 | { |
| 1021 | ID3D11Buffer* d3dBuffers[gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS]; |
| 1022 | UINT d3dOffsets[gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS]; |
| 1023 | bool requiresUpdate = false; |
| 1024 | for (size_t i = 0; i < gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS; i++) |
| 1025 | { |
| 1026 | if (transformFeedbackBuffers[i]) |
| 1027 | { |
| 1028 | BufferStorage11 *storage = BufferStorage11::makeBufferStorage11(transformFeedbackBuffers[i]->getStorage()); |
| 1029 | ID3D11Buffer *buffer = storage->getBuffer(BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK); |
| 1030 | |
| 1031 | d3dBuffers[i] = buffer; |
| 1032 | d3dOffsets[i] = (mAppliedTFBuffers[i] != buffer) ? static_cast<UINT>(offsets[i]) : -1; |
| 1033 | } |
| 1034 | else |
| 1035 | { |
| 1036 | d3dBuffers[i] = NULL; |
| 1037 | d3dOffsets[i] = 0; |
| 1038 | } |
| 1039 | |
| 1040 | if (d3dBuffers[i] != mAppliedTFBuffers[i] || offsets[i] != mAppliedTFOffsets[i]) |
| 1041 | { |
| 1042 | requiresUpdate = true; |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | if (requiresUpdate) |
| 1047 | { |
| 1048 | mDeviceContext->SOSetTargets(ArraySize(d3dBuffers), d3dBuffers, d3dOffsets); |
| 1049 | for (size_t i = 0; i < gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS; i++) |
| 1050 | { |
| 1051 | mAppliedTFBuffers[i] = d3dBuffers[i]; |
| 1052 | mAppliedTFOffsets[i] = offsets[i]; |
| 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | |
Geoff Lang | 4c5c6bb | 2014-02-05 16:32:46 -0500 | [diff] [blame] | 1057 | void Renderer11::drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1058 | { |
Geoff Lang | 4c5c6bb | 2014-02-05 16:32:46 -0500 | [diff] [blame] | 1059 | if (mode == GL_POINTS && transformFeedbackActive) |
| 1060 | { |
| 1061 | // Since point sprites are generated with a geometry shader, too many vertices will |
| 1062 | // be written if transform feedback is active. To work around this, draw only the points |
| 1063 | // with the stream out shader and no pixel shader to feed the stream out buffers and then |
| 1064 | // draw again with the point sprite geometry shader to rasterize the point sprites. |
| 1065 | |
| 1066 | mDeviceContext->PSSetShader(NULL, NULL, 0); |
| 1067 | |
| 1068 | if (instances > 0) |
| 1069 | { |
| 1070 | mDeviceContext->DrawInstanced(count, instances, 0, 0); |
| 1071 | } |
| 1072 | else |
| 1073 | { |
| 1074 | mDeviceContext->Draw(count, 0); |
| 1075 | } |
| 1076 | |
| 1077 | mDeviceContext->GSSetShader(mCurPointGeometryShader, NULL, 0); |
| 1078 | mDeviceContext->PSSetShader(mAppliedPixelShader, NULL, 0); |
| 1079 | |
| 1080 | if (instances > 0) |
| 1081 | { |
| 1082 | mDeviceContext->DrawInstanced(count, instances, 0, 0); |
| 1083 | } |
| 1084 | else |
| 1085 | { |
| 1086 | mDeviceContext->Draw(count, 0); |
| 1087 | } |
| 1088 | |
| 1089 | mDeviceContext->GSSetShader(mAppliedGeometryShader, NULL, 0); |
| 1090 | } |
| 1091 | else if (mode == GL_LINE_LOOP) |
daniel@transgaming.com | 1ef0967 | 2013-01-11 04:10:37 +0000 | [diff] [blame] | 1092 | { |
| 1093 | drawLineLoop(count, GL_NONE, NULL, 0, NULL); |
| 1094 | } |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1095 | else if (mode == GL_TRIANGLE_FAN) |
| 1096 | { |
shannon.woods@transgaming.com | 00032cb | 2013-01-25 21:56:30 +0000 | [diff] [blame] | 1097 | drawTriangleFan(count, GL_NONE, NULL, 0, NULL, instances); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1098 | } |
daniel@transgaming.com | 1ef0967 | 2013-01-11 04:10:37 +0000 | [diff] [blame] | 1099 | else if (instances > 0) |
| 1100 | { |
shannon.woods@transgaming.com | 00032cb | 2013-01-25 21:56:30 +0000 | [diff] [blame] | 1101 | mDeviceContext->DrawInstanced(count, instances, 0, 0); |
daniel@transgaming.com | 1ef0967 | 2013-01-11 04:10:37 +0000 | [diff] [blame] | 1102 | } |
| 1103 | else |
| 1104 | { |
| 1105 | mDeviceContext->Draw(count, 0); |
| 1106 | } |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
Geoff Lang | 4c5c6bb | 2014-02-05 16:32:46 -0500 | [diff] [blame] | 1109 | void Renderer11::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, |
| 1110 | gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1111 | { |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1112 | if (mode == GL_LINE_LOOP) |
| 1113 | { |
| 1114 | drawLineLoop(count, type, indices, indexInfo.minIndex, elementArrayBuffer); |
| 1115 | } |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1116 | else if (mode == GL_TRIANGLE_FAN) |
| 1117 | { |
shannon.woods@transgaming.com | 00032cb | 2013-01-25 21:56:30 +0000 | [diff] [blame] | 1118 | drawTriangleFan(count, type, indices, indexInfo.minIndex, elementArrayBuffer, instances); |
| 1119 | } |
| 1120 | else if (instances > 0) |
| 1121 | { |
| 1122 | mDeviceContext->DrawIndexedInstanced(count, instances, 0, -static_cast<int>(indexInfo.minIndex), 0); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1123 | } |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1124 | else |
| 1125 | { |
daniel@transgaming.com | 9f7ede6 | 2013-01-11 04:07:06 +0000 | [diff] [blame] | 1126 | mDeviceContext->DrawIndexed(count, 0, -static_cast<int>(indexInfo.minIndex)); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer) |
| 1131 | { |
| 1132 | // Get the raw indices for an indexed draw |
| 1133 | if (type != GL_NONE && elementArrayBuffer) |
| 1134 | { |
| 1135 | gl::Buffer *indexBuffer = elementArrayBuffer; |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 1136 | BufferStorage *storage = indexBuffer->getStorage(); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1137 | intptr_t offset = reinterpret_cast<intptr_t>(indices); |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 1138 | indices = static_cast<const GLubyte*>(storage->getData()) + offset; |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | if (!mLineLoopIB) |
| 1142 | { |
| 1143 | mLineLoopIB = new StreamingIndexBufferInterface(this); |
| 1144 | if (!mLineLoopIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT)) |
| 1145 | { |
| 1146 | delete mLineLoopIB; |
| 1147 | mLineLoopIB = NULL; |
| 1148 | |
| 1149 | ERR("Could not create a 32-bit looping index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1150 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1151 | } |
| 1152 | } |
| 1153 | |
Geoff Lang | 57e713e | 2013-07-31 17:01:58 -0400 | [diff] [blame] | 1154 | // Checked by Renderer11::applyPrimitiveType |
| 1155 | ASSERT(count >= 0); |
| 1156 | |
| 1157 | if (static_cast<unsigned int>(count) + 1 > (std::numeric_limits<unsigned int>::max() / sizeof(unsigned int))) |
Geoff Lang | eadfd57 | 2013-07-09 15:55:07 -0400 | [diff] [blame] | 1158 | { |
| 1159 | ERR("Could not create a 32-bit looping index buffer for GL_LINE_LOOP, too many indices required."); |
| 1160 | return gl::error(GL_OUT_OF_MEMORY); |
| 1161 | } |
| 1162 | |
Geoff Lang | 57e713e | 2013-07-31 17:01:58 -0400 | [diff] [blame] | 1163 | const unsigned int spaceNeeded = (static_cast<unsigned int>(count) + 1) * sizeof(unsigned int); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1164 | if (!mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT)) |
| 1165 | { |
| 1166 | ERR("Could not reserve enough space in looping index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1167 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | void* mappedMemory = NULL; |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 1171 | unsigned int offset; |
| 1172 | if (!mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory, &offset)) |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1173 | { |
| 1174 | ERR("Could not map index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1175 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1178 | unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory); |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 1179 | unsigned int indexBufferOffset = offset; |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1180 | |
| 1181 | switch (type) |
| 1182 | { |
| 1183 | case GL_NONE: // Non-indexed draw |
| 1184 | for (int i = 0; i < count; i++) |
| 1185 | { |
| 1186 | data[i] = i; |
| 1187 | } |
| 1188 | data[count] = 0; |
| 1189 | break; |
| 1190 | case GL_UNSIGNED_BYTE: |
| 1191 | for (int i = 0; i < count; i++) |
| 1192 | { |
| 1193 | data[i] = static_cast<const GLubyte*>(indices)[i]; |
| 1194 | } |
| 1195 | data[count] = static_cast<const GLubyte*>(indices)[0]; |
| 1196 | break; |
| 1197 | case GL_UNSIGNED_SHORT: |
| 1198 | for (int i = 0; i < count; i++) |
| 1199 | { |
| 1200 | data[i] = static_cast<const GLushort*>(indices)[i]; |
| 1201 | } |
| 1202 | data[count] = static_cast<const GLushort*>(indices)[0]; |
| 1203 | break; |
| 1204 | case GL_UNSIGNED_INT: |
| 1205 | for (int i = 0; i < count; i++) |
| 1206 | { |
| 1207 | data[i] = static_cast<const GLuint*>(indices)[i]; |
| 1208 | } |
| 1209 | data[count] = static_cast<const GLuint*>(indices)[0]; |
| 1210 | break; |
| 1211 | default: UNREACHABLE(); |
| 1212 | } |
| 1213 | |
| 1214 | if (!mLineLoopIB->unmapBuffer()) |
| 1215 | { |
| 1216 | ERR("Could not unmap index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1217 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
Geoff Lang | 7840b17 | 2014-03-13 11:20:44 -0400 | [diff] [blame] | 1220 | IndexBuffer11 *indexBuffer = IndexBuffer11::makeIndexBuffer11(mLineLoopIB->getIndexBuffer()); |
| 1221 | ID3D11Buffer *d3dIndexBuffer = indexBuffer->getBuffer(); |
| 1222 | DXGI_FORMAT indexFormat = indexBuffer->getIndexFormat(); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1223 | |
Geoff Lang | 7840b17 | 2014-03-13 11:20:44 -0400 | [diff] [blame] | 1224 | if (mAppliedIB != d3dIndexBuffer || mAppliedIBFormat != indexFormat || mAppliedIBOffset != indexBufferOffset) |
| 1225 | { |
daniel@transgaming.com | 7fbf486 | 2013-01-11 04:09:22 +0000 | [diff] [blame] | 1226 | mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), indexBufferOffset); |
Geoff Lang | 7840b17 | 2014-03-13 11:20:44 -0400 | [diff] [blame] | 1227 | mAppliedIB = d3dIndexBuffer; |
| 1228 | mAppliedIBFormat = indexFormat; |
daniel@transgaming.com | 7fbf486 | 2013-01-11 04:09:22 +0000 | [diff] [blame] | 1229 | mAppliedIBOffset = indexBufferOffset; |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1230 | } |
| 1231 | |
daniel@transgaming.com | 1ef0967 | 2013-01-11 04:10:37 +0000 | [diff] [blame] | 1232 | mDeviceContext->DrawIndexed(count + 1, 0, -minIndex); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
shannon.woods@transgaming.com | 00032cb | 2013-01-25 21:56:30 +0000 | [diff] [blame] | 1235 | void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer, int instances) |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1236 | { |
| 1237 | // Get the raw indices for an indexed draw |
| 1238 | if (type != GL_NONE && elementArrayBuffer) |
| 1239 | { |
| 1240 | gl::Buffer *indexBuffer = elementArrayBuffer; |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 1241 | BufferStorage *storage = indexBuffer->getStorage(); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1242 | intptr_t offset = reinterpret_cast<intptr_t>(indices); |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 1243 | indices = static_cast<const GLubyte*>(storage->getData()) + offset; |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | if (!mTriangleFanIB) |
| 1247 | { |
| 1248 | mTriangleFanIB = new StreamingIndexBufferInterface(this); |
| 1249 | if (!mTriangleFanIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT)) |
| 1250 | { |
| 1251 | delete mTriangleFanIB; |
| 1252 | mTriangleFanIB = NULL; |
| 1253 | |
| 1254 | ERR("Could not create a scratch index buffer for GL_TRIANGLE_FAN."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1255 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1256 | } |
| 1257 | } |
| 1258 | |
Geoff Lang | 57e713e | 2013-07-31 17:01:58 -0400 | [diff] [blame] | 1259 | // Checked by Renderer11::applyPrimitiveType |
| 1260 | ASSERT(count >= 3); |
| 1261 | |
Geoff Lang | eadfd57 | 2013-07-09 15:55:07 -0400 | [diff] [blame] | 1262 | const unsigned int numTris = count - 2; |
| 1263 | |
Geoff Lang | 57e713e | 2013-07-31 17:01:58 -0400 | [diff] [blame] | 1264 | if (numTris > (std::numeric_limits<unsigned int>::max() / (sizeof(unsigned int) * 3))) |
Geoff Lang | eadfd57 | 2013-07-09 15:55:07 -0400 | [diff] [blame] | 1265 | { |
| 1266 | ERR("Could not create a scratch index buffer for GL_TRIANGLE_FAN, too many indices required."); |
| 1267 | return gl::error(GL_OUT_OF_MEMORY); |
| 1268 | } |
| 1269 | |
| 1270 | const unsigned int spaceNeeded = (numTris * 3) * sizeof(unsigned int); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1271 | if (!mTriangleFanIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT)) |
| 1272 | { |
| 1273 | ERR("Could not reserve enough space in scratch index buffer for GL_TRIANGLE_FAN."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1274 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | void* mappedMemory = NULL; |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 1278 | unsigned int offset; |
| 1279 | if (!mTriangleFanIB->mapBuffer(spaceNeeded, &mappedMemory, &offset)) |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1280 | { |
| 1281 | ERR("Could not map scratch index buffer for GL_TRIANGLE_FAN."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1282 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory); |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 1286 | unsigned int indexBufferOffset = offset; |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1287 | |
| 1288 | switch (type) |
| 1289 | { |
| 1290 | case GL_NONE: // Non-indexed draw |
Geoff Lang | eadfd57 | 2013-07-09 15:55:07 -0400 | [diff] [blame] | 1291 | for (unsigned int i = 0; i < numTris; i++) |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1292 | { |
| 1293 | data[i*3 + 0] = 0; |
| 1294 | data[i*3 + 1] = i + 1; |
| 1295 | data[i*3 + 2] = i + 2; |
| 1296 | } |
| 1297 | break; |
| 1298 | case GL_UNSIGNED_BYTE: |
Geoff Lang | eadfd57 | 2013-07-09 15:55:07 -0400 | [diff] [blame] | 1299 | for (unsigned int i = 0; i < numTris; i++) |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1300 | { |
| 1301 | data[i*3 + 0] = static_cast<const GLubyte*>(indices)[0]; |
| 1302 | data[i*3 + 1] = static_cast<const GLubyte*>(indices)[i + 1]; |
| 1303 | data[i*3 + 2] = static_cast<const GLubyte*>(indices)[i + 2]; |
| 1304 | } |
| 1305 | break; |
| 1306 | case GL_UNSIGNED_SHORT: |
Geoff Lang | eadfd57 | 2013-07-09 15:55:07 -0400 | [diff] [blame] | 1307 | for (unsigned int i = 0; i < numTris; i++) |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1308 | { |
| 1309 | data[i*3 + 0] = static_cast<const GLushort*>(indices)[0]; |
| 1310 | data[i*3 + 1] = static_cast<const GLushort*>(indices)[i + 1]; |
| 1311 | data[i*3 + 2] = static_cast<const GLushort*>(indices)[i + 2]; |
| 1312 | } |
| 1313 | break; |
| 1314 | case GL_UNSIGNED_INT: |
Geoff Lang | eadfd57 | 2013-07-09 15:55:07 -0400 | [diff] [blame] | 1315 | for (unsigned int i = 0; i < numTris; i++) |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1316 | { |
| 1317 | data[i*3 + 0] = static_cast<const GLuint*>(indices)[0]; |
| 1318 | data[i*3 + 1] = static_cast<const GLuint*>(indices)[i + 1]; |
| 1319 | data[i*3 + 2] = static_cast<const GLuint*>(indices)[i + 2]; |
| 1320 | } |
| 1321 | break; |
| 1322 | default: UNREACHABLE(); |
| 1323 | } |
| 1324 | |
| 1325 | if (!mTriangleFanIB->unmapBuffer()) |
| 1326 | { |
| 1327 | ERR("Could not unmap scratch index buffer for GL_TRIANGLE_FAN."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1328 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
Geoff Lang | 7840b17 | 2014-03-13 11:20:44 -0400 | [diff] [blame] | 1331 | IndexBuffer11 *indexBuffer = IndexBuffer11::makeIndexBuffer11(mTriangleFanIB->getIndexBuffer()); |
| 1332 | ID3D11Buffer *d3dIndexBuffer = indexBuffer->getBuffer(); |
| 1333 | DXGI_FORMAT indexFormat = indexBuffer->getIndexFormat(); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1334 | |
Geoff Lang | 7840b17 | 2014-03-13 11:20:44 -0400 | [diff] [blame] | 1335 | if (mAppliedIB != d3dIndexBuffer || mAppliedIBFormat != indexFormat || mAppliedIBOffset != indexBufferOffset) |
| 1336 | { |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1337 | mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), indexBufferOffset); |
Geoff Lang | 7840b17 | 2014-03-13 11:20:44 -0400 | [diff] [blame] | 1338 | mAppliedIB = d3dIndexBuffer; |
| 1339 | mAppliedIBFormat = indexFormat; |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1340 | mAppliedIBOffset = indexBufferOffset; |
| 1341 | } |
| 1342 | |
shannon.woods@transgaming.com | 00032cb | 2013-01-25 21:56:30 +0000 | [diff] [blame] | 1343 | if (instances > 0) |
| 1344 | { |
| 1345 | mDeviceContext->DrawIndexedInstanced(numTris * 3, instances, 0, -minIndex, 0); |
| 1346 | } |
| 1347 | else |
| 1348 | { |
| 1349 | mDeviceContext->DrawIndexed(numTris * 3, 0, -minIndex); |
| 1350 | } |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1351 | } |
| 1352 | |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 1353 | void Renderer11::applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer, |
| 1354 | bool rasterizerDiscard, bool transformFeedbackActive) |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 1355 | { |
Jamie Madill | c5a8300 | 2014-02-14 16:41:25 -0500 | [diff] [blame] | 1356 | ShaderExecutable *vertexExe = programBinary->getVertexExecutableForInputLayout(inputLayout); |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 1357 | ShaderExecutable *pixelExe = programBinary->getPixelExecutableForFramebuffer(framebuffer); |
Jamie Madill | 6246dc8 | 2014-01-29 09:26:47 -0500 | [diff] [blame] | 1358 | ShaderExecutable *geometryExe = programBinary->getGeometryExecutable(); |
shannon.woods@transgaming.com | 43ccf3f | 2013-02-28 23:07:19 +0000 | [diff] [blame] | 1359 | |
Jamie Madill | 6246dc8 | 2014-01-29 09:26:47 -0500 | [diff] [blame] | 1360 | ID3D11VertexShader *vertexShader = (vertexExe ? ShaderExecutable11::makeShaderExecutable11(vertexExe)->getVertexShader() : NULL); |
Jamie Madill | 6246dc8 | 2014-01-29 09:26:47 -0500 | [diff] [blame] | 1361 | |
Geoff Lang | 4c5c6bb | 2014-02-05 16:32:46 -0500 | [diff] [blame] | 1362 | ID3D11PixelShader *pixelShader = NULL; |
| 1363 | // Skip pixel shader if we're doing rasterizer discard. |
| 1364 | if (!rasterizerDiscard) |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1365 | { |
Geoff Lang | 4c5c6bb | 2014-02-05 16:32:46 -0500 | [diff] [blame] | 1366 | pixelShader = (pixelExe ? ShaderExecutable11::makeShaderExecutable11(pixelExe)->getPixelShader() : NULL); |
shannon.woods@transgaming.com | dd2524c | 2013-02-28 23:04:33 +0000 | [diff] [blame] | 1367 | } |
| 1368 | |
Geoff Lang | 4c5c6bb | 2014-02-05 16:32:46 -0500 | [diff] [blame] | 1369 | ID3D11GeometryShader *geometryShader = NULL; |
| 1370 | if (transformFeedbackActive) |
Geoff Lang | 0550d03 | 2014-01-30 11:29:07 -0500 | [diff] [blame] | 1371 | { |
Geoff Lang | 4c5c6bb | 2014-02-05 16:32:46 -0500 | [diff] [blame] | 1372 | geometryShader = (vertexExe ? ShaderExecutable11::makeShaderExecutable11(vertexExe)->getStreamOutShader() : NULL); |
| 1373 | } |
| 1374 | else if (mCurRasterState.pointDrawMode) |
| 1375 | { |
| 1376 | geometryShader = (geometryExe ? ShaderExecutable11::makeShaderExecutable11(geometryExe)->getGeometryShader() : NULL); |
Geoff Lang | 0550d03 | 2014-01-30 11:29:07 -0500 | [diff] [blame] | 1377 | } |
| 1378 | |
Jamie Madill | 6246dc8 | 2014-01-29 09:26:47 -0500 | [diff] [blame] | 1379 | bool dirtyUniforms = false; |
shannon.woods@transgaming.com | dd2524c | 2013-02-28 23:04:33 +0000 | [diff] [blame] | 1380 | |
Jamie Madill | 6246dc8 | 2014-01-29 09:26:47 -0500 | [diff] [blame] | 1381 | if (vertexShader != mAppliedVertexShader) |
shannon.woods@transgaming.com | dd2524c | 2013-02-28 23:04:33 +0000 | [diff] [blame] | 1382 | { |
Jamie Madill | 6246dc8 | 2014-01-29 09:26:47 -0500 | [diff] [blame] | 1383 | mDeviceContext->VSSetShader(vertexShader, NULL, 0); |
| 1384 | mAppliedVertexShader = vertexShader; |
| 1385 | dirtyUniforms = true; |
| 1386 | } |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 1387 | |
Jamie Madill | 6246dc8 | 2014-01-29 09:26:47 -0500 | [diff] [blame] | 1388 | if (geometryShader != mAppliedGeometryShader) |
| 1389 | { |
| 1390 | mDeviceContext->GSSetShader(geometryShader, NULL, 0); |
| 1391 | mAppliedGeometryShader = geometryShader; |
| 1392 | dirtyUniforms = true; |
| 1393 | } |
| 1394 | |
Geoff Lang | 4c5c6bb | 2014-02-05 16:32:46 -0500 | [diff] [blame] | 1395 | if (geometryExe && mCurRasterState.pointDrawMode) |
| 1396 | { |
| 1397 | mCurPointGeometryShader = ShaderExecutable11::makeShaderExecutable11(geometryExe)->getGeometryShader(); |
| 1398 | } |
| 1399 | else |
| 1400 | { |
| 1401 | mCurPointGeometryShader = NULL; |
| 1402 | } |
| 1403 | |
Jamie Madill | 6246dc8 | 2014-01-29 09:26:47 -0500 | [diff] [blame] | 1404 | if (pixelShader != mAppliedPixelShader) |
| 1405 | { |
| 1406 | mDeviceContext->PSSetShader(pixelShader, NULL, 0); |
| 1407 | mAppliedPixelShader = pixelShader; |
| 1408 | dirtyUniforms = true; |
| 1409 | } |
| 1410 | |
| 1411 | if (dirtyUniforms) |
| 1412 | { |
| 1413 | programBinary->dirtyAllUniforms(); |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1414 | } |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
Jamie Madill | 8ff21ae | 2014-02-04 16:04:05 -0500 | [diff] [blame] | 1417 | void Renderer11::applyUniforms(const gl::ProgramBinary &programBinary) |
daniel@transgaming.com | ab1c146 | 2012-12-20 21:08:30 +0000 | [diff] [blame] | 1418 | { |
Jamie Madill | 834e8b7 | 2014-04-11 13:33:58 -0400 | [diff] [blame] | 1419 | const std::vector<gl::LinkedUniform*> &uniformArray = programBinary.getUniforms(); |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1420 | |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1421 | unsigned int totalRegisterCountVS = 0; |
| 1422 | unsigned int totalRegisterCountPS = 0; |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1423 | |
shannon.woods@transgaming.com | 21ba647 | 2013-01-25 21:53:32 +0000 | [diff] [blame] | 1424 | bool vertexUniformsDirty = false; |
| 1425 | bool pixelUniformsDirty = false; |
| 1426 | |
Jamie Madill | 8ff21ae | 2014-02-04 16:04:05 -0500 | [diff] [blame] | 1427 | for (size_t uniformIndex = 0; uniformIndex < uniformArray.size(); uniformIndex++) |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1428 | { |
Jamie Madill | 834e8b7 | 2014-04-11 13:33:58 -0400 | [diff] [blame] | 1429 | const gl::LinkedUniform &uniform = *uniformArray[uniformIndex]; |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 1430 | |
Jamie Madill | 8ff21ae | 2014-02-04 16:04:05 -0500 | [diff] [blame] | 1431 | if (uniform.isReferencedByVertexShader() && !uniform.isSampler()) |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1432 | { |
Jamie Madill | 8ff21ae | 2014-02-04 16:04:05 -0500 | [diff] [blame] | 1433 | totalRegisterCountVS += uniform.registerCount; |
| 1434 | vertexUniformsDirty = (vertexUniformsDirty || uniform.dirty); |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1435 | } |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1436 | |
Jamie Madill | 8ff21ae | 2014-02-04 16:04:05 -0500 | [diff] [blame] | 1437 | if (uniform.isReferencedByFragmentShader() && !uniform.isSampler()) |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1438 | { |
Jamie Madill | 8ff21ae | 2014-02-04 16:04:05 -0500 | [diff] [blame] | 1439 | totalRegisterCountPS += uniform.registerCount; |
| 1440 | pixelUniformsDirty = (pixelUniformsDirty || uniform.dirty); |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1441 | } |
| 1442 | } |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1443 | |
Jamie Madill | 8ff21ae | 2014-02-04 16:04:05 -0500 | [diff] [blame] | 1444 | const UniformStorage11 *vertexUniformStorage = UniformStorage11::makeUniformStorage11(&programBinary.getVertexUniformStorage()); |
| 1445 | const UniformStorage11 *fragmentUniformStorage = UniformStorage11::makeUniformStorage11(&programBinary.getFragmentUniformStorage()); |
| 1446 | ASSERT(vertexUniformStorage); |
| 1447 | ASSERT(fragmentUniformStorage); |
| 1448 | |
| 1449 | ID3D11Buffer *vertexConstantBuffer = vertexUniformStorage->getConstantBuffer(); |
| 1450 | ID3D11Buffer *pixelConstantBuffer = fragmentUniformStorage->getConstantBuffer(); |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1451 | |
shannon.woods@transgaming.com | 09bf2a7 | 2013-02-28 23:12:54 +0000 | [diff] [blame] | 1452 | float (*mapVS)[4] = NULL; |
| 1453 | float (*mapPS)[4] = NULL; |
| 1454 | |
Shannon Woods | 5ab33c8 | 2013-06-26 15:31:09 -0400 | [diff] [blame] | 1455 | if (totalRegisterCountVS > 0 && vertexUniformsDirty) |
| 1456 | { |
| 1457 | D3D11_MAPPED_SUBRESOURCE map = {0}; |
| 1458 | HRESULT result = mDeviceContext->Map(vertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); |
Geoff Lang | 9cd1915 | 2014-05-28 15:54:34 -0400 | [diff] [blame] | 1459 | UNUSED_ASSERTION_VARIABLE(result); |
Shannon Woods | 5ab33c8 | 2013-06-26 15:31:09 -0400 | [diff] [blame] | 1460 | ASSERT(SUCCEEDED(result)); |
| 1461 | mapVS = (float(*)[4])map.pData; |
| 1462 | } |
shannon.woods@transgaming.com | 09bf2a7 | 2013-02-28 23:12:54 +0000 | [diff] [blame] | 1463 | |
Shannon Woods | 5ab33c8 | 2013-06-26 15:31:09 -0400 | [diff] [blame] | 1464 | if (totalRegisterCountPS > 0 && pixelUniformsDirty) |
| 1465 | { |
| 1466 | D3D11_MAPPED_SUBRESOURCE map = {0}; |
| 1467 | HRESULT result = mDeviceContext->Map(pixelConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); |
Geoff Lang | 9cd1915 | 2014-05-28 15:54:34 -0400 | [diff] [blame] | 1468 | UNUSED_ASSERTION_VARIABLE(result); |
Shannon Woods | 5ab33c8 | 2013-06-26 15:31:09 -0400 | [diff] [blame] | 1469 | ASSERT(SUCCEEDED(result)); |
| 1470 | mapPS = (float(*)[4])map.pData; |
| 1471 | } |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1472 | |
Jamie Madill | 8ff21ae | 2014-02-04 16:04:05 -0500 | [diff] [blame] | 1473 | for (size_t uniformIndex = 0; uniformIndex < uniformArray.size(); uniformIndex++) |
daniel@transgaming.com | ab1c146 | 2012-12-20 21:08:30 +0000 | [diff] [blame] | 1474 | { |
Jamie Madill | 834e8b7 | 2014-04-11 13:33:58 -0400 | [diff] [blame] | 1475 | gl::LinkedUniform *uniform = uniformArray[uniformIndex]; |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1476 | |
Jamie Madill | 8ff21ae | 2014-02-04 16:04:05 -0500 | [diff] [blame] | 1477 | if (!uniform->isSampler()) |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1478 | { |
Jamie Madill | 5b085dc | 2013-08-30 13:21:11 -0400 | [diff] [blame] | 1479 | unsigned int componentCount = (4 - uniform->registerElement); |
| 1480 | |
Jamie Madill | 71cc91f | 2013-09-18 12:51:22 -0400 | [diff] [blame] | 1481 | // we assume that uniforms from structs are arranged in struct order in our uniforms list. otherwise we would |
Jamie Madill | 5b085dc | 2013-08-30 13:21:11 -0400 | [diff] [blame] | 1482 | // overwrite previously written regions of memory. |
Jamie Madill | 5b085dc | 2013-08-30 13:21:11 -0400 | [diff] [blame] | 1483 | |
shannonwoods@chromium.org | 38676dc | 2013-05-30 00:06:52 +0000 | [diff] [blame] | 1484 | if (uniform->isReferencedByVertexShader() && mapVS) |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1485 | { |
Jamie Madill | 5b085dc | 2013-08-30 13:21:11 -0400 | [diff] [blame] | 1486 | memcpy(&mapVS[uniform->vsRegisterIndex][uniform->registerElement], uniform->data, uniform->registerCount * sizeof(float) * componentCount); |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1487 | } |
shannon.woods@transgaming.com | 13979a6 | 2013-02-28 23:10:18 +0000 | [diff] [blame] | 1488 | |
shannonwoods@chromium.org | 38676dc | 2013-05-30 00:06:52 +0000 | [diff] [blame] | 1489 | if (uniform->isReferencedByFragmentShader() && mapPS) |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1490 | { |
Jamie Madill | 5b085dc | 2013-08-30 13:21:11 -0400 | [diff] [blame] | 1491 | memcpy(&mapPS[uniform->psRegisterIndex][uniform->registerElement], uniform->data, uniform->registerCount * sizeof(float) * componentCount); |
daniel@transgaming.com | e76b64b | 2013-01-11 04:10:08 +0000 | [diff] [blame] | 1492 | } |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1493 | } |
daniel@transgaming.com | ab1c146 | 2012-12-20 21:08:30 +0000 | [diff] [blame] | 1494 | } |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1495 | |
shannon.woods@transgaming.com | 09bf2a7 | 2013-02-28 23:12:54 +0000 | [diff] [blame] | 1496 | if (mapVS) |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1497 | { |
shannon.woods@transgaming.com | 09bf2a7 | 2013-02-28 23:12:54 +0000 | [diff] [blame] | 1498 | mDeviceContext->Unmap(vertexConstantBuffer, 0); |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
shannon.woods@transgaming.com | 09bf2a7 | 2013-02-28 23:12:54 +0000 | [diff] [blame] | 1501 | if (mapPS) |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1502 | { |
shannon.woods@transgaming.com | 09bf2a7 | 2013-02-28 23:12:54 +0000 | [diff] [blame] | 1503 | mDeviceContext->Unmap(pixelConstantBuffer, 0); |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1504 | } |
Geoff Lang | c6354ee | 2013-07-22 10:40:07 -0400 | [diff] [blame] | 1505 | |
| 1506 | if (mCurrentVertexConstantBuffer != vertexConstantBuffer) |
| 1507 | { |
| 1508 | mDeviceContext->VSSetConstantBuffers(0, 1, &vertexConstantBuffer); |
| 1509 | mCurrentVertexConstantBuffer = vertexConstantBuffer; |
| 1510 | } |
| 1511 | |
| 1512 | if (mCurrentPixelConstantBuffer != pixelConstantBuffer) |
| 1513 | { |
| 1514 | mDeviceContext->PSSetConstantBuffers(0, 1, &pixelConstantBuffer); |
| 1515 | mCurrentPixelConstantBuffer = pixelConstantBuffer; |
| 1516 | } |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 1517 | |
daniel@transgaming.com | a390e1e | 2013-01-11 04:09:39 +0000 | [diff] [blame] | 1518 | // Driver uniforms |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1519 | if (!mDriverConstantBufferVS) |
| 1520 | { |
| 1521 | D3D11_BUFFER_DESC constantBufferDescription = {0}; |
| 1522 | constantBufferDescription.ByteWidth = sizeof(dx_VertexConstants); |
| 1523 | constantBufferDescription.Usage = D3D11_USAGE_DEFAULT; |
| 1524 | constantBufferDescription.BindFlags = D3D11_BIND_CONSTANT_BUFFER; |
| 1525 | constantBufferDescription.CPUAccessFlags = 0; |
| 1526 | constantBufferDescription.MiscFlags = 0; |
| 1527 | constantBufferDescription.StructureByteStride = 0; |
daniel@transgaming.com | a390e1e | 2013-01-11 04:09:39 +0000 | [diff] [blame] | 1528 | |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1529 | HRESULT result = mDevice->CreateBuffer(&constantBufferDescription, NULL, &mDriverConstantBufferVS); |
Geoff Lang | 9cd1915 | 2014-05-28 15:54:34 -0400 | [diff] [blame] | 1530 | UNUSED_ASSERTION_VARIABLE(result); |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1531 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1532 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1533 | mDeviceContext->VSSetConstantBuffers(1, 1, &mDriverConstantBufferVS); |
| 1534 | } |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 1535 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1536 | if (!mDriverConstantBufferPS) |
| 1537 | { |
| 1538 | D3D11_BUFFER_DESC constantBufferDescription = {0}; |
| 1539 | constantBufferDescription.ByteWidth = sizeof(dx_PixelConstants); |
| 1540 | constantBufferDescription.Usage = D3D11_USAGE_DEFAULT; |
| 1541 | constantBufferDescription.BindFlags = D3D11_BIND_CONSTANT_BUFFER; |
| 1542 | constantBufferDescription.CPUAccessFlags = 0; |
| 1543 | constantBufferDescription.MiscFlags = 0; |
| 1544 | constantBufferDescription.StructureByteStride = 0; |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 1545 | |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1546 | HRESULT result = mDevice->CreateBuffer(&constantBufferDescription, NULL, &mDriverConstantBufferPS); |
Geoff Lang | 9cd1915 | 2014-05-28 15:54:34 -0400 | [diff] [blame] | 1547 | UNUSED_ASSERTION_VARIABLE(result); |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1548 | ASSERT(SUCCEEDED(result)); |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 1549 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1550 | mDeviceContext->PSSetConstantBuffers(1, 1, &mDriverConstantBufferPS); |
| 1551 | } |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 1552 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1553 | if (memcmp(&mVertexConstants, &mAppliedVertexConstants, sizeof(dx_VertexConstants)) != 0) |
| 1554 | { |
| 1555 | mDeviceContext->UpdateSubresource(mDriverConstantBufferVS, 0, NULL, &mVertexConstants, 16, 0); |
| 1556 | memcpy(&mAppliedVertexConstants, &mVertexConstants, sizeof(dx_VertexConstants)); |
| 1557 | } |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 1558 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1559 | if (memcmp(&mPixelConstants, &mAppliedPixelConstants, sizeof(dx_PixelConstants)) != 0) |
| 1560 | { |
| 1561 | mDeviceContext->UpdateSubresource(mDriverConstantBufferPS, 0, NULL, &mPixelConstants, 16, 0); |
| 1562 | memcpy(&mAppliedPixelConstants, &mPixelConstants, sizeof(dx_PixelConstants)); |
| 1563 | } |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 1564 | |
| 1565 | // needed for the point sprite geometry shader |
Geoff Lang | c6354ee | 2013-07-22 10:40:07 -0400 | [diff] [blame] | 1566 | if (mCurrentGeometryConstantBuffer != mDriverConstantBufferPS) |
| 1567 | { |
| 1568 | mDeviceContext->GSSetConstantBuffers(0, 1, &mDriverConstantBufferPS); |
| 1569 | mCurrentGeometryConstantBuffer = mDriverConstantBufferPS; |
| 1570 | } |
daniel@transgaming.com | ab1c146 | 2012-12-20 21:08:30 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
daniel@transgaming.com | 084a257 | 2012-11-28 20:55:17 +0000 | [diff] [blame] | 1573 | void Renderer11::clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 1574 | { |
Geoff Lang | da507fe | 2013-08-20 12:01:42 -0400 | [diff] [blame] | 1575 | mClear->clearFramebuffer(clearParams, frameBuffer); |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 1576 | invalidateFramebufferSwizzles(frameBuffer); |
shannon.woods@transgaming.com | 34f507c | 2013-01-25 21:52:15 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1579 | void Renderer11::markAllStateDirty() |
| 1580 | { |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 1581 | for (unsigned int rtIndex = 0; rtIndex < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; rtIndex++) |
| 1582 | { |
| 1583 | mAppliedRenderTargetSerials[rtIndex] = 0; |
| 1584 | } |
daniel@transgaming.com | 9a06737 | 2012-12-20 20:55:24 +0000 | [diff] [blame] | 1585 | mAppliedDepthbufferSerial = 0; |
| 1586 | mAppliedStencilbufferSerial = 0; |
daniel@transgaming.com | 7b6b83e | 2012-11-28 21:00:30 +0000 | [diff] [blame] | 1587 | mDepthStencilInitialized = false; |
| 1588 | mRenderTargetDescInitialized = false; |
| 1589 | |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 1590 | for (int i = 0; i < gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS; i++) |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame] | 1591 | { |
| 1592 | mForceSetVertexSamplerStates[i] = true; |
Geoff Lang | 91382e5 | 2014-01-07 16:16:30 -0500 | [diff] [blame] | 1593 | mCurVertexSRVs[i] = NULL; |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame] | 1594 | } |
| 1595 | for (int i = 0; i < gl::MAX_TEXTURE_IMAGE_UNITS; i++) |
| 1596 | { |
| 1597 | mForceSetPixelSamplerStates[i] = true; |
Geoff Lang | 91382e5 | 2014-01-07 16:16:30 -0500 | [diff] [blame] | 1598 | mCurPixelSRVs[i] = NULL; |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1601 | mForceSetBlendState = true; |
| 1602 | mForceSetRasterState = true; |
| 1603 | mForceSetDepthStencilState = true; |
| 1604 | mForceSetScissor = true; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 1605 | mForceSetViewport = true; |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1606 | |
Geoff Lang | 7840b17 | 2014-03-13 11:20:44 -0400 | [diff] [blame] | 1607 | mAppliedIB = NULL; |
| 1608 | mAppliedIBFormat = DXGI_FORMAT_UNKNOWN; |
daniel@transgaming.com | 7fbf486 | 2013-01-11 04:09:22 +0000 | [diff] [blame] | 1609 | mAppliedIBOffset = 0; |
| 1610 | |
Jamie Madill | 6246dc8 | 2014-01-29 09:26:47 -0500 | [diff] [blame] | 1611 | mAppliedVertexShader = NULL; |
| 1612 | mAppliedGeometryShader = NULL; |
Geoff Lang | 4c5c6bb | 2014-02-05 16:32:46 -0500 | [diff] [blame] | 1613 | mCurPointGeometryShader = NULL; |
Jamie Madill | 6246dc8 | 2014-01-29 09:26:47 -0500 | [diff] [blame] | 1614 | mAppliedPixelShader = NULL; |
Geoff Lang | eeba6e1 | 2014-02-03 13:12:30 -0500 | [diff] [blame] | 1615 | |
| 1616 | for (size_t i = 0; i < gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS; i++) |
| 1617 | { |
| 1618 | mAppliedTFBuffers[i] = NULL; |
| 1619 | mAppliedTFOffsets[i] = 0; |
| 1620 | } |
| 1621 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1622 | memset(&mAppliedVertexConstants, 0, sizeof(dx_VertexConstants)); |
| 1623 | memset(&mAppliedPixelConstants, 0, sizeof(dx_PixelConstants)); |
Geoff Lang | 1f53cab | 2013-07-22 10:37:22 -0400 | [diff] [blame] | 1624 | |
| 1625 | mInputLayoutCache.markDirty(); |
Geoff Lang | c6354ee | 2013-07-22 10:40:07 -0400 | [diff] [blame] | 1626 | |
| 1627 | for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS; i++) |
| 1628 | { |
| 1629 | mCurrentConstantBufferVS[i] = -1; |
| 1630 | mCurrentConstantBufferPS[i] = -1; |
| 1631 | } |
| 1632 | |
| 1633 | mCurrentVertexConstantBuffer = NULL; |
| 1634 | mCurrentPixelConstantBuffer = NULL; |
| 1635 | mCurrentGeometryConstantBuffer = NULL; |
Geoff Lang | 4c09586 | 2013-07-22 10:43:36 -0400 | [diff] [blame] | 1636 | |
| 1637 | mCurrentPrimitiveTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1640 | void Renderer11::releaseDeviceResources() |
| 1641 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 1642 | mStateCache.clear(); |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 1643 | mInputLayoutCache.clear(); |
| 1644 | |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 1645 | SafeDelete(mVertexDataManager); |
| 1646 | SafeDelete(mIndexDataManager); |
| 1647 | SafeDelete(mLineLoopIB); |
| 1648 | SafeDelete(mTriangleFanIB); |
| 1649 | SafeDelete(mBlit); |
Geoff Lang | da507fe | 2013-08-20 12:01:42 -0400 | [diff] [blame] | 1650 | SafeDelete(mClear); |
Jamie Madill | a21eea3 | 2013-09-18 14:36:25 -0400 | [diff] [blame] | 1651 | SafeDelete(mPixelTransfer); |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1652 | |
shannonwoods@chromium.org | 894b324 | 2013-05-30 00:01:44 +0000 | [diff] [blame] | 1653 | SafeRelease(mDriverConstantBufferVS); |
| 1654 | SafeRelease(mDriverConstantBufferPS); |
| 1655 | SafeRelease(mSyncQuery); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1656 | } |
| 1657 | |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 1658 | void Renderer11::notifyDeviceLost() |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1659 | { |
| 1660 | mDeviceLost = true; |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 1661 | mDisplay->notifyDeviceLost(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
| 1664 | bool Renderer11::isDeviceLost() |
| 1665 | { |
| 1666 | return mDeviceLost; |
| 1667 | } |
| 1668 | |
| 1669 | // set notify to true to broadcast a message to all contexts of the device loss |
| 1670 | bool Renderer11::testDeviceLost(bool notify) |
| 1671 | { |
| 1672 | bool isLost = false; |
| 1673 | |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1674 | // GetRemovedReason is used to test if the device is removed |
| 1675 | HRESULT result = mDevice->GetDeviceRemovedReason(); |
| 1676 | isLost = d3d11::isDeviceLostError(result); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1677 | |
| 1678 | if (isLost) |
| 1679 | { |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1680 | // Log error if this is a new device lost event |
| 1681 | if (mDeviceLost == false) |
| 1682 | { |
| 1683 | ERR("The D3D11 device was removed: 0x%08X", result); |
| 1684 | } |
| 1685 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1686 | // ensure we note the device loss -- |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1687 | // we'll probably get this done again by notifyDeviceLost |
| 1688 | // but best to remember it! |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1689 | // Note that we don't want to clear the device loss status here |
| 1690 | // -- this needs to be done by resetDevice |
| 1691 | mDeviceLost = true; |
| 1692 | if (notify) |
| 1693 | { |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 1694 | notifyDeviceLost(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1695 | } |
| 1696 | } |
| 1697 | |
| 1698 | return isLost; |
| 1699 | } |
| 1700 | |
| 1701 | bool Renderer11::testDeviceResettable() |
| 1702 | { |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1703 | // determine if the device is resettable by creating a dummy device |
| 1704 | PFN_D3D11_CREATE_DEVICE D3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(mD3d11Module, "D3D11CreateDevice"); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1705 | |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1706 | if (D3D11CreateDevice == NULL) |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1707 | { |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1708 | return false; |
| 1709 | } |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1710 | |
shannon.woods@transgaming.com | d438fd4 | 2013-02-28 23:17:45 +0000 | [diff] [blame] | 1711 | D3D_FEATURE_LEVEL featureLevels[] = |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1712 | { |
| 1713 | D3D_FEATURE_LEVEL_11_0, |
| 1714 | D3D_FEATURE_LEVEL_10_1, |
| 1715 | D3D_FEATURE_LEVEL_10_0, |
| 1716 | }; |
| 1717 | |
| 1718 | ID3D11Device* dummyDevice; |
| 1719 | D3D_FEATURE_LEVEL dummyFeatureLevel; |
| 1720 | ID3D11DeviceContext* dummyContext; |
| 1721 | |
| 1722 | HRESULT result = D3D11CreateDevice(NULL, |
| 1723 | D3D_DRIVER_TYPE_HARDWARE, |
| 1724 | NULL, |
| 1725 | #if defined(_DEBUG) |
| 1726 | D3D11_CREATE_DEVICE_DEBUG, |
| 1727 | #else |
| 1728 | 0, |
| 1729 | #endif |
shannon.woods@transgaming.com | d438fd4 | 2013-02-28 23:17:45 +0000 | [diff] [blame] | 1730 | featureLevels, |
| 1731 | ArraySize(featureLevels), |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1732 | D3D11_SDK_VERSION, |
| 1733 | &dummyDevice, |
| 1734 | &dummyFeatureLevel, |
| 1735 | &dummyContext); |
| 1736 | |
| 1737 | if (!mDevice || FAILED(result)) |
| 1738 | { |
| 1739 | return false; |
| 1740 | } |
| 1741 | |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 1742 | SafeRelease(dummyContext); |
| 1743 | SafeRelease(dummyDevice); |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1744 | |
| 1745 | return true; |
| 1746 | } |
| 1747 | |
| 1748 | void Renderer11::release() |
| 1749 | { |
| 1750 | releaseDeviceResources(); |
| 1751 | |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 1752 | SafeRelease(mDxgiFactory); |
| 1753 | SafeRelease(mDxgiAdapter); |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1754 | |
| 1755 | if (mDeviceContext) |
| 1756 | { |
| 1757 | mDeviceContext->ClearState(); |
| 1758 | mDeviceContext->Flush(); |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 1759 | SafeRelease(mDeviceContext); |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 1762 | SafeRelease(mDevice); |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1763 | |
| 1764 | if (mD3d11Module) |
| 1765 | { |
| 1766 | FreeLibrary(mD3d11Module); |
| 1767 | mD3d11Module = NULL; |
| 1768 | } |
| 1769 | |
| 1770 | if (mDxgiModule) |
| 1771 | { |
| 1772 | FreeLibrary(mDxgiModule); |
| 1773 | mDxgiModule = NULL; |
| 1774 | } |
Geoff Lang | dad5ed3 | 2014-02-10 12:59:17 -0500 | [diff] [blame] | 1775 | |
| 1776 | mCompiler.release(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | bool Renderer11::resetDevice() |
| 1780 | { |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1781 | // recreate everything |
| 1782 | release(); |
| 1783 | EGLint result = initialize(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1784 | |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1785 | if (result != EGL_SUCCESS) |
| 1786 | { |
| 1787 | ERR("Could not reinitialize D3D11 device: %08X", result); |
| 1788 | return false; |
| 1789 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1790 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1791 | mDeviceLost = false; |
| 1792 | |
| 1793 | return true; |
| 1794 | } |
| 1795 | |
| 1796 | DWORD Renderer11::getAdapterVendor() const |
| 1797 | { |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1798 | return mAdapterDescription.VendorId; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1799 | } |
| 1800 | |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 1801 | std::string Renderer11::getRendererDescription() const |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1802 | { |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 1803 | std::ostringstream rendererString; |
| 1804 | |
| 1805 | rendererString << mDescription; |
| 1806 | rendererString << " Direct3D11"; |
| 1807 | |
| 1808 | rendererString << " vs_" << getMajorShaderModel() << "_" << getMinorShaderModel(); |
| 1809 | rendererString << " ps_" << getMajorShaderModel() << "_" << getMinorShaderModel(); |
| 1810 | |
| 1811 | return rendererString.str(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | GUID Renderer11::getAdapterIdentifier() const |
| 1815 | { |
shannon.woods@transgaming.com | 43db795 | 2013-02-28 23:04:28 +0000 | [diff] [blame] | 1816 | // Use the adapter LUID as our adapter ID |
| 1817 | // This number is local to a machine is only guaranteed to be unique between restarts |
| 1818 | META_ASSERT(sizeof(LUID) <= sizeof(GUID)); |
| 1819 | GUID adapterId = {0}; |
| 1820 | memcpy(&adapterId, &mAdapterDescription.AdapterLuid, sizeof(LUID)); |
| 1821 | return adapterId; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1822 | } |
| 1823 | |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 1824 | Range Renderer11::getViewportBounds() const |
| 1825 | { |
| 1826 | switch (mFeatureLevel) |
| 1827 | { |
| 1828 | case D3D_FEATURE_LEVEL_11_0: |
| 1829 | return Range(D3D11_VIEWPORT_BOUNDS_MIN, D3D11_VIEWPORT_BOUNDS_MAX); |
| 1830 | case D3D_FEATURE_LEVEL_10_1: |
| 1831 | case D3D_FEATURE_LEVEL_10_0: |
| 1832 | return Range(D3D10_VIEWPORT_BOUNDS_MIN, D3D10_VIEWPORT_BOUNDS_MAX); |
| 1833 | default: UNREACHABLE(); |
| 1834 | return Range(0, 0); |
| 1835 | } |
| 1836 | } |
| 1837 | |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 1838 | unsigned int Renderer11::getMaxVertexTextureImageUnits() const |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1839 | { |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 1840 | META_ASSERT(MAX_TEXTURE_IMAGE_UNITS_VTF_SM4 <= gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS); |
| 1841 | switch (mFeatureLevel) |
| 1842 | { |
| 1843 | case D3D_FEATURE_LEVEL_11_0: |
| 1844 | case D3D_FEATURE_LEVEL_10_1: |
| 1845 | case D3D_FEATURE_LEVEL_10_0: |
| 1846 | return MAX_TEXTURE_IMAGE_UNITS_VTF_SM4; |
| 1847 | default: UNREACHABLE(); |
| 1848 | return 0; |
| 1849 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
shannon.woods@transgaming.com | 76cd88c | 2013-01-25 21:54:36 +0000 | [diff] [blame] | 1852 | unsigned int Renderer11::getMaxCombinedTextureImageUnits() const |
| 1853 | { |
| 1854 | return gl::MAX_TEXTURE_IMAGE_UNITS + getMaxVertexTextureImageUnits(); |
| 1855 | } |
| 1856 | |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 1857 | unsigned int Renderer11::getReservedVertexUniformVectors() const |
| 1858 | { |
Shannon Woods | 5ab33c8 | 2013-06-26 15:31:09 -0400 | [diff] [blame] | 1859 | return 0; // Driver uniforms are stored in a separate constant buffer |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | unsigned int Renderer11::getReservedFragmentUniformVectors() const |
| 1863 | { |
Shannon Woods | 5ab33c8 | 2013-06-26 15:31:09 -0400 | [diff] [blame] | 1864 | return 0; // Driver uniforms are stored in a separate constant buffer |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | unsigned int Renderer11::getMaxVertexUniformVectors() const |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 1868 | { |
shannon.woods@transgaming.com | 4e48204 | 2013-01-25 21:54:18 +0000 | [diff] [blame] | 1869 | META_ASSERT(MAX_VERTEX_UNIFORM_VECTORS_D3D11 <= D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT); |
| 1870 | ASSERT(mFeatureLevel >= D3D_FEATURE_LEVEL_10_0); |
| 1871 | return MAX_VERTEX_UNIFORM_VECTORS_D3D11; |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 1874 | unsigned int Renderer11::getMaxFragmentUniformVectors() const |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 1875 | { |
shannon.woods@transgaming.com | 4e48204 | 2013-01-25 21:54:18 +0000 | [diff] [blame] | 1876 | META_ASSERT(MAX_FRAGMENT_UNIFORM_VECTORS_D3D11 <= D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT); |
| 1877 | ASSERT(mFeatureLevel >= D3D_FEATURE_LEVEL_10_0); |
| 1878 | return MAX_FRAGMENT_UNIFORM_VECTORS_D3D11; |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 1881 | unsigned int Renderer11::getMaxVaryingVectors() const |
shannon.woods@transgaming.com | 28d268e | 2013-01-25 21:54:26 +0000 | [diff] [blame] | 1882 | { |
| 1883 | META_ASSERT(gl::IMPLEMENTATION_MAX_VARYING_VECTORS == D3D11_VS_OUTPUT_REGISTER_COUNT); |
shannonwoods@chromium.org | 74b86cf | 2013-05-30 00:02:58 +0000 | [diff] [blame] | 1884 | META_ASSERT(D3D11_VS_OUTPUT_REGISTER_COUNT <= D3D11_PS_INPUT_REGISTER_COUNT); |
| 1885 | META_ASSERT(D3D10_VS_OUTPUT_REGISTER_COUNT <= D3D10_PS_INPUT_REGISTER_COUNT); |
shannon.woods@transgaming.com | 28d268e | 2013-01-25 21:54:26 +0000 | [diff] [blame] | 1886 | switch (mFeatureLevel) |
| 1887 | { |
| 1888 | case D3D_FEATURE_LEVEL_11_0: |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 1889 | return D3D11_VS_OUTPUT_REGISTER_COUNT - getReservedVaryings(); |
shannon.woods@transgaming.com | 28d268e | 2013-01-25 21:54:26 +0000 | [diff] [blame] | 1890 | case D3D_FEATURE_LEVEL_10_1: |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 1891 | return D3D10_1_VS_OUTPUT_REGISTER_COUNT - getReservedVaryings(); |
shannon.woods@transgaming.com | 28d268e | 2013-01-25 21:54:26 +0000 | [diff] [blame] | 1892 | case D3D_FEATURE_LEVEL_10_0: |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 1893 | return D3D10_VS_OUTPUT_REGISTER_COUNT - getReservedVaryings(); |
shannon.woods@transgaming.com | 28d268e | 2013-01-25 21:54:26 +0000 | [diff] [blame] | 1894 | default: UNREACHABLE(); |
| 1895 | return 0; |
| 1896 | } |
| 1897 | } |
| 1898 | |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 1899 | unsigned int Renderer11::getMaxVertexShaderUniformBuffers() const |
| 1900 | { |
shannon.woods%transgaming.com@gtempaccount.com | 3408935 | 2013-04-13 03:36:57 +0000 | [diff] [blame] | 1901 | META_ASSERT(gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS >= D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT && |
| 1902 | gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS >= D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT); |
| 1903 | |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 1904 | switch (mFeatureLevel) |
| 1905 | { |
| 1906 | case D3D_FEATURE_LEVEL_11_0: |
shannonwoods@chromium.org | 2b54422 | 2013-05-30 00:11:12 +0000 | [diff] [blame] | 1907 | return D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - getReservedVertexUniformBuffers(); |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 1908 | case D3D_FEATURE_LEVEL_10_1: |
| 1909 | case D3D_FEATURE_LEVEL_10_0: |
shannonwoods@chromium.org | 2b54422 | 2013-05-30 00:11:12 +0000 | [diff] [blame] | 1910 | return D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - getReservedVertexUniformBuffers(); |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 1911 | default: UNREACHABLE(); |
| 1912 | return 0; |
| 1913 | } |
| 1914 | } |
| 1915 | |
| 1916 | unsigned int Renderer11::getMaxFragmentShaderUniformBuffers() const |
| 1917 | { |
shannon.woods%transgaming.com@gtempaccount.com | 3408935 | 2013-04-13 03:36:57 +0000 | [diff] [blame] | 1918 | META_ASSERT(gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS >= D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT && |
| 1919 | gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS >= D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT); |
| 1920 | |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 1921 | switch (mFeatureLevel) |
| 1922 | { |
| 1923 | case D3D_FEATURE_LEVEL_11_0: |
shannonwoods@chromium.org | 2b54422 | 2013-05-30 00:11:12 +0000 | [diff] [blame] | 1924 | return D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - getReservedFragmentUniformBuffers(); |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 1925 | case D3D_FEATURE_LEVEL_10_1: |
| 1926 | case D3D_FEATURE_LEVEL_10_0: |
shannonwoods@chromium.org | 2b54422 | 2013-05-30 00:11:12 +0000 | [diff] [blame] | 1927 | return D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - getReservedFragmentUniformBuffers(); |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 1928 | default: UNREACHABLE(); |
| 1929 | return 0; |
| 1930 | } |
| 1931 | } |
| 1932 | |
shannonwoods@chromium.org | 2b54422 | 2013-05-30 00:11:12 +0000 | [diff] [blame] | 1933 | unsigned int Renderer11::getReservedVertexUniformBuffers() const |
| 1934 | { |
| 1935 | // we reserve one buffer for the application uniforms, and one for driver uniforms |
| 1936 | return 2; |
| 1937 | } |
| 1938 | |
| 1939 | unsigned int Renderer11::getReservedFragmentUniformBuffers() const |
| 1940 | { |
| 1941 | // we reserve one buffer for the application uniforms, and one for driver uniforms |
| 1942 | return 2; |
| 1943 | } |
| 1944 | |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 1945 | unsigned int Renderer11::getReservedVaryings() const |
| 1946 | { |
Jamie Madill | 2bf8b37 | 2014-06-16 17:18:51 -0400 | [diff] [blame] | 1947 | // We potentially reserve varyings for gl_Position, dx_Position, gl_FragCoord and gl_PointSize |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 1948 | return 4; |
| 1949 | } |
| 1950 | |
| 1951 | |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 1952 | unsigned int Renderer11::getMaxTransformFeedbackBuffers() const |
| 1953 | { |
shannon.woods%transgaming.com@gtempaccount.com | 3408935 | 2013-04-13 03:36:57 +0000 | [diff] [blame] | 1954 | META_ASSERT(gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS >= D3D11_SO_BUFFER_SLOT_COUNT && |
| 1955 | gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS >= D3D10_SO_BUFFER_SLOT_COUNT); |
| 1956 | |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 1957 | switch (mFeatureLevel) |
| 1958 | { |
| 1959 | case D3D_FEATURE_LEVEL_11_0: |
| 1960 | return D3D11_SO_BUFFER_SLOT_COUNT; |
| 1961 | case D3D_FEATURE_LEVEL_10_1: |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 1962 | return D3D10_1_SO_BUFFER_SLOT_COUNT; |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 1963 | case D3D_FEATURE_LEVEL_10_0: |
| 1964 | return D3D10_SO_BUFFER_SLOT_COUNT; |
| 1965 | default: UNREACHABLE(); |
| 1966 | return 0; |
| 1967 | } |
| 1968 | } |
| 1969 | |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 1970 | unsigned int Renderer11::getMaxTransformFeedbackSeparateComponents() const |
| 1971 | { |
| 1972 | switch (mFeatureLevel) |
| 1973 | { |
| 1974 | case D3D_FEATURE_LEVEL_11_0: |
| 1975 | return getMaxTransformFeedbackInterleavedComponents() / getMaxTransformFeedbackBuffers(); |
| 1976 | case D3D_FEATURE_LEVEL_10_1: |
| 1977 | case D3D_FEATURE_LEVEL_10_0: |
| 1978 | // D3D 10 and 10.1 only allow one output per output slot if an output slot other than zero |
| 1979 | // is used. |
| 1980 | return 4; |
| 1981 | default: UNREACHABLE(); |
| 1982 | return 0; |
| 1983 | } |
| 1984 | } |
| 1985 | |
| 1986 | unsigned int Renderer11::getMaxTransformFeedbackInterleavedComponents() const |
| 1987 | { |
| 1988 | return (getMaxVaryingVectors() * 4); |
| 1989 | } |
| 1990 | |
shannonwoods@chromium.org | 33e798f | 2013-05-30 00:05:05 +0000 | [diff] [blame] | 1991 | unsigned int Renderer11::getMaxUniformBufferSize() const |
| 1992 | { |
| 1993 | // Each component is a 4-element vector of 4-byte units (floats) |
| 1994 | const unsigned int bytesPerComponent = 4 * sizeof(float); |
| 1995 | |
| 1996 | switch (mFeatureLevel) |
| 1997 | { |
| 1998 | case D3D_FEATURE_LEVEL_11_0: |
| 1999 | return D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * bytesPerComponent; |
| 2000 | case D3D_FEATURE_LEVEL_10_1: |
| 2001 | case D3D_FEATURE_LEVEL_10_0: |
| 2002 | return D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * bytesPerComponent; |
| 2003 | default: UNREACHABLE(); |
| 2004 | return 0; |
| 2005 | } |
| 2006 | } |
| 2007 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2008 | bool Renderer11::getShareHandleSupport() const |
| 2009 | { |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 2010 | // We only currently support share handles with BGRA surfaces, because |
| 2011 | // chrome needs BGRA. Once chrome fixes this, we should always support them. |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2012 | // PIX doesn't seem to support using share handles, so disable them. |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2013 | return getCaps().extensions.textureFormatBGRA8888 && !gl::perfActive(); |
daniel@transgaming.com | 7629bb6 | 2013-01-11 04:12:28 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
shannon.woods@transgaming.com | 8d2f086 | 2013-02-28 23:09:19 +0000 | [diff] [blame] | 2016 | bool Renderer11::getPostSubBufferSupport() const |
| 2017 | { |
| 2018 | // D3D11 does not support present with dirty rectangles until D3D11.1 and DXGI 1.2. |
| 2019 | return false; |
| 2020 | } |
| 2021 | |
Jamie Madill | 13a2f85 | 2013-12-11 16:35:08 -0500 | [diff] [blame] | 2022 | int Renderer11::getMaxRecommendedElementsIndices() const |
| 2023 | { |
| 2024 | META_ASSERT(D3D11_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP == 32); |
| 2025 | META_ASSERT(D3D10_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP == 32); |
| 2026 | |
| 2027 | // D3D11 allows up to 2^32 elements, but we report max signed int for convenience. |
| 2028 | return std::numeric_limits<GLint>::max(); |
| 2029 | } |
| 2030 | |
| 2031 | int Renderer11::getMaxRecommendedElementsVertices() const |
| 2032 | { |
| 2033 | META_ASSERT(D3D11_REQ_DRAW_VERTEX_COUNT_2_TO_EXP == 32); |
| 2034 | META_ASSERT(D3D10_REQ_DRAW_VERTEX_COUNT_2_TO_EXP == 32); |
| 2035 | |
| 2036 | // D3D11 allows up to 2^32 elements, but we report max signed int for convenience. |
| 2037 | return std::numeric_limits<GLint>::max(); |
| 2038 | } |
| 2039 | |
Geoff Lang | 05b0502 | 2014-06-11 15:31:45 -0400 | [diff] [blame] | 2040 | bool Renderer11::getSRGBTextureSupport() const |
| 2041 | { |
| 2042 | return true; |
| 2043 | } |
| 2044 | |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 2045 | int Renderer11::getMajorShaderModel() const |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2046 | { |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 2047 | switch (mFeatureLevel) |
| 2048 | { |
| 2049 | case D3D_FEATURE_LEVEL_11_0: return D3D11_SHADER_MAJOR_VERSION; // 5 |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2050 | case D3D_FEATURE_LEVEL_10_1: return D3D10_1_SHADER_MAJOR_VERSION; // 4 |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 2051 | case D3D_FEATURE_LEVEL_10_0: return D3D10_SHADER_MAJOR_VERSION; // 4 |
| 2052 | default: UNREACHABLE(); return 0; |
| 2053 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2054 | } |
| 2055 | |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2056 | int Renderer11::getMinorShaderModel() const |
| 2057 | { |
| 2058 | switch (mFeatureLevel) |
| 2059 | { |
| 2060 | case D3D_FEATURE_LEVEL_11_0: return D3D11_SHADER_MINOR_VERSION; // 0 |
| 2061 | case D3D_FEATURE_LEVEL_10_1: return D3D10_1_SHADER_MINOR_VERSION; // 1 |
| 2062 | case D3D_FEATURE_LEVEL_10_0: return D3D10_SHADER_MINOR_VERSION; // 0 |
| 2063 | default: UNREACHABLE(); return 0; |
| 2064 | } |
| 2065 | } |
| 2066 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2067 | float Renderer11::getMaxPointSize() const |
| 2068 | { |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 2069 | // choose a reasonable maximum. we enforce this in the shader. |
| 2070 | // (nb: on a Radeon 2600xt, DX9 reports a 256 max point size) |
| 2071 | return 1024.0f; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2072 | } |
| 2073 | |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 2074 | int Renderer11::getMaxViewportDimension() const |
| 2075 | { |
shannon.woods@transgaming.com | fd86c2c | 2013-02-28 23:13:07 +0000 | [diff] [blame] | 2076 | // Maximum viewport size must be at least as large as the largest render buffer (or larger). |
| 2077 | // In our case return the maximum texture size, which is the maximum render buffer size. |
| 2078 | META_ASSERT(D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION * 2 - 1 <= D3D11_VIEWPORT_BOUNDS_MAX); |
| 2079 | META_ASSERT(D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION * 2 - 1 <= D3D10_VIEWPORT_BOUNDS_MAX); |
| 2080 | |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 2081 | switch (mFeatureLevel) |
| 2082 | { |
| 2083 | case D3D_FEATURE_LEVEL_11_0: |
shannon.woods@transgaming.com | fd86c2c | 2013-02-28 23:13:07 +0000 | [diff] [blame] | 2084 | return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 2085 | case D3D_FEATURE_LEVEL_10_1: |
| 2086 | case D3D_FEATURE_LEVEL_10_0: |
shannon.woods@transgaming.com | fd86c2c | 2013-02-28 23:13:07 +0000 | [diff] [blame] | 2087 | return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 2088 | default: UNREACHABLE(); |
| 2089 | return 0; |
| 2090 | } |
| 2091 | } |
| 2092 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2093 | int Renderer11::getMaxTextureWidth() const |
| 2094 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 2095 | switch (mFeatureLevel) |
| 2096 | { |
| 2097 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 2098 | case D3D_FEATURE_LEVEL_10_1: |
| 2099 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 2100 | default: UNREACHABLE(); return 0; |
| 2101 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | int Renderer11::getMaxTextureHeight() const |
| 2105 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 2106 | switch (mFeatureLevel) |
| 2107 | { |
| 2108 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 2109 | case D3D_FEATURE_LEVEL_10_1: |
| 2110 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 2111 | default: UNREACHABLE(); return 0; |
| 2112 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2113 | } |
| 2114 | |
shannon.woods%transgaming.com@gtempaccount.com | c1fdf6b | 2013-04-13 03:44:41 +0000 | [diff] [blame] | 2115 | int Renderer11::getMaxTextureDepth() const |
| 2116 | { |
| 2117 | switch (mFeatureLevel) |
| 2118 | { |
| 2119 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION; // 2048 |
| 2120 | case D3D_FEATURE_LEVEL_10_1: |
| 2121 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE3D_U_V_OR_W_DIMENSION; // 2048 |
| 2122 | default: UNREACHABLE(); return 0; |
| 2123 | } |
| 2124 | } |
| 2125 | |
shannon.woods%transgaming.com@gtempaccount.com | a98a811 | 2013-04-13 03:45:57 +0000 | [diff] [blame] | 2126 | int Renderer11::getMaxTextureArrayLayers() const |
| 2127 | { |
| 2128 | switch (mFeatureLevel) |
| 2129 | { |
| 2130 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION; // 2048 |
| 2131 | case D3D_FEATURE_LEVEL_10_1: |
| 2132 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION; // 512 |
| 2133 | default: UNREACHABLE(); return 0; |
| 2134 | } |
| 2135 | } |
| 2136 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2137 | int Renderer11::getMinSwapInterval() const |
| 2138 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 2139 | return 0; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | int Renderer11::getMaxSwapInterval() const |
| 2143 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 2144 | return 4; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | int Renderer11::getMaxSupportedSamples() const |
| 2148 | { |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 2149 | return mMaxSupportedSamples; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 2152 | GLsizei Renderer11::getMaxSupportedFormatSamples(GLenum internalFormat) const |
Geoff Lang | 0e120e3 | 2013-05-29 10:23:55 -0400 | [diff] [blame] | 2153 | { |
Shannon Woods | dd4674f | 2013-07-08 10:32:15 -0400 | [diff] [blame] | 2154 | DXGI_FORMAT format = gl_d3d11::GetRenderableFormat(internalFormat, getCurrentClientVersion()); |
Geoff Lang | 0e120e3 | 2013-05-29 10:23:55 -0400 | [diff] [blame] | 2155 | MultisampleSupportMap::const_iterator iter = mMultisampleSupportMap.find(format); |
| 2156 | return (iter != mMultisampleSupportMap.end()) ? iter->second.maxSupportedSamples : 0; |
| 2157 | } |
| 2158 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 2159 | GLsizei Renderer11::getNumSampleCounts(GLenum internalFormat) const |
Shannon Woods | 52f1e7e | 2013-07-08 10:32:17 -0400 | [diff] [blame] | 2160 | { |
| 2161 | unsigned int numCounts = 0; |
| 2162 | |
| 2163 | // D3D11 supports multisampling for signed and unsigned format, but ES 3.0 does not |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 2164 | GLenum componentType = gl::GetComponentType(internalFormat, getCurrentClientVersion()); |
| 2165 | if (componentType != GL_INT && componentType != GL_UNSIGNED_INT) |
Shannon Woods | 52f1e7e | 2013-07-08 10:32:17 -0400 | [diff] [blame] | 2166 | { |
| 2167 | DXGI_FORMAT format = gl_d3d11::GetRenderableFormat(internalFormat, getCurrentClientVersion()); |
| 2168 | MultisampleSupportMap::const_iterator iter = mMultisampleSupportMap.find(format); |
| 2169 | |
| 2170 | if (iter != mMultisampleSupportMap.end()) |
| 2171 | { |
| 2172 | const MultisampleSupportInfo& info = iter->second; |
| 2173 | for (int i = 0; i < D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; i++) |
| 2174 | { |
| 2175 | if (info.qualityLevels[i] > 0) |
| 2176 | { |
| 2177 | numCounts++; |
| 2178 | } |
| 2179 | } |
| 2180 | } |
| 2181 | } |
| 2182 | |
| 2183 | return numCounts; |
| 2184 | } |
| 2185 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 2186 | void Renderer11::getSampleCounts(GLenum internalFormat, GLsizei bufSize, GLint *params) const |
Shannon Woods | 52f1e7e | 2013-07-08 10:32:17 -0400 | [diff] [blame] | 2187 | { |
| 2188 | // D3D11 supports multisampling for signed and unsigned format, but ES 3.0 does not |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 2189 | GLenum componentType = gl::GetComponentType(internalFormat, getCurrentClientVersion()); |
| 2190 | if (componentType == GL_INT || componentType == GL_UNSIGNED_INT) |
| 2191 | { |
Shannon Woods | 52f1e7e | 2013-07-08 10:32:17 -0400 | [diff] [blame] | 2192 | return; |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 2193 | } |
Shannon Woods | 52f1e7e | 2013-07-08 10:32:17 -0400 | [diff] [blame] | 2194 | |
| 2195 | DXGI_FORMAT format = gl_d3d11::GetRenderableFormat(internalFormat, getCurrentClientVersion()); |
| 2196 | MultisampleSupportMap::const_iterator iter = mMultisampleSupportMap.find(format); |
| 2197 | |
| 2198 | if (iter != mMultisampleSupportMap.end()) |
| 2199 | { |
| 2200 | const MultisampleSupportInfo& info = iter->second; |
| 2201 | int bufPos = 0; |
| 2202 | for (int i = D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT - 1; i >= 0 && bufPos < bufSize; i--) |
| 2203 | { |
| 2204 | if (info.qualityLevels[i] > 0) |
| 2205 | { |
| 2206 | params[bufPos++] = i + 1; |
| 2207 | } |
| 2208 | } |
| 2209 | } |
| 2210 | } |
| 2211 | |
shannon.woods@transgaming.com | 88fbd0f | 2013-02-28 23:05:46 +0000 | [diff] [blame] | 2212 | int Renderer11::getNearestSupportedSamples(DXGI_FORMAT format, unsigned int requested) const |
| 2213 | { |
| 2214 | if (requested == 0) |
| 2215 | { |
| 2216 | return 0; |
| 2217 | } |
| 2218 | |
| 2219 | MultisampleSupportMap::const_iterator iter = mMultisampleSupportMap.find(format); |
| 2220 | if (iter != mMultisampleSupportMap.end()) |
| 2221 | { |
| 2222 | const MultisampleSupportInfo& info = iter->second; |
| 2223 | for (unsigned int i = requested - 1; i < D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; i++) |
| 2224 | { |
| 2225 | if (info.qualityLevels[i] > 0) |
| 2226 | { |
| 2227 | return i + 1; |
| 2228 | } |
| 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 | return -1; |
| 2233 | } |
| 2234 | |
shannon.woods%transgaming.com@gtempaccount.com | b290ac1 | 2013-04-13 03:28:15 +0000 | [diff] [blame] | 2235 | unsigned int Renderer11::getMaxRenderTargets() const |
| 2236 | { |
Geoff Lang | 4ace423 | 2014-06-18 19:12:48 -0400 | [diff] [blame^] | 2237 | return d3d11::GetMaximumSimultaneousRenderTargets(mFeatureLevel); |
shannon.woods%transgaming.com@gtempaccount.com | b290ac1 | 2013-04-13 03:28:15 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2240 | bool Renderer11::copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 2241 | { |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 2242 | if (source && dest) |
| 2243 | { |
| 2244 | TextureStorage11_2D *source11 = TextureStorage11_2D::makeTextureStorage11_2D(source->getStorageInstance()); |
| 2245 | TextureStorage11_2D *dest11 = TextureStorage11_2D::makeTextureStorage11_2D(dest->getStorageInstance()); |
| 2246 | |
Nicolas Capens | 76b258f | 2014-04-03 10:59:42 -0400 | [diff] [blame] | 2247 | mDeviceContext->CopyResource(dest11->getResource(), source11->getResource()); |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 2248 | |
| 2249 | dest11->invalidateSwizzleCache(); |
| 2250 | |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 2251 | return true; |
| 2252 | } |
| 2253 | |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 2254 | return false; |
| 2255 | } |
| 2256 | |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2257 | bool Renderer11::copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 2258 | { |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 2259 | if (source && dest) |
| 2260 | { |
daniel@transgaming.com | e9cf5e7 | 2013-01-11 04:06:55 +0000 | [diff] [blame] | 2261 | TextureStorage11_Cube *source11 = TextureStorage11_Cube::makeTextureStorage11_Cube(source->getStorageInstance()); |
| 2262 | TextureStorage11_Cube *dest11 = TextureStorage11_Cube::makeTextureStorage11_Cube(dest->getStorageInstance()); |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 2263 | |
Nicolas Capens | 76b258f | 2014-04-03 10:59:42 -0400 | [diff] [blame] | 2264 | mDeviceContext->CopyResource(dest11->getResource(), source11->getResource()); |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 2265 | |
| 2266 | dest11->invalidateSwizzleCache(); |
| 2267 | |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 2268 | return true; |
| 2269 | } |
| 2270 | |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 2271 | return false; |
| 2272 | } |
| 2273 | |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2274 | bool Renderer11::copyToRenderTarget(TextureStorageInterface3D *dest, TextureStorageInterface3D *source) |
| 2275 | { |
| 2276 | if (source && dest) |
| 2277 | { |
| 2278 | TextureStorage11_3D *source11 = TextureStorage11_3D::makeTextureStorage11_3D(source->getStorageInstance()); |
| 2279 | TextureStorage11_3D *dest11 = TextureStorage11_3D::makeTextureStorage11_3D(dest->getStorageInstance()); |
| 2280 | |
Nicolas Capens | 76b258f | 2014-04-03 10:59:42 -0400 | [diff] [blame] | 2281 | mDeviceContext->CopyResource(dest11->getResource(), source11->getResource()); |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 2282 | |
| 2283 | dest11->invalidateSwizzleCache(); |
| 2284 | |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2285 | return true; |
| 2286 | } |
| 2287 | |
| 2288 | return false; |
| 2289 | } |
| 2290 | |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 2291 | bool Renderer11::copyToRenderTarget(TextureStorageInterface2DArray *dest, TextureStorageInterface2DArray *source) |
| 2292 | { |
| 2293 | if (source && dest) |
| 2294 | { |
| 2295 | TextureStorage11_2DArray *source11 = TextureStorage11_2DArray::makeTextureStorage11_2DArray(source->getStorageInstance()); |
| 2296 | TextureStorage11_2DArray *dest11 = TextureStorage11_2DArray::makeTextureStorage11_2DArray(dest->getStorageInstance()); |
| 2297 | |
Nicolas Capens | 76b258f | 2014-04-03 10:59:42 -0400 | [diff] [blame] | 2298 | mDeviceContext->CopyResource(dest11->getResource(), source11->getResource()); |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 2299 | |
| 2300 | dest11->invalidateSwizzleCache(); |
| 2301 | |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 2302 | return true; |
| 2303 | } |
| 2304 | |
| 2305 | return false; |
| 2306 | } |
| 2307 | |
shannon.woods@transgaming.com | 664916b | 2013-01-25 21:50:32 +0000 | [diff] [blame] | 2308 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2309 | GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level) |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 2310 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2311 | gl::FramebufferAttachment *colorbuffer = framebuffer->getReadColorbuffer(); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2312 | if (!colorbuffer) |
| 2313 | { |
| 2314 | ERR("Failed to retrieve the color buffer from the frame buffer."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2315 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2316 | } |
| 2317 | |
| 2318 | RenderTarget11 *sourceRenderTarget = RenderTarget11::makeRenderTarget11(colorbuffer->getRenderTarget()); |
| 2319 | if (!sourceRenderTarget) |
| 2320 | { |
| 2321 | ERR("Failed to retrieve the render target from the frame buffer."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2322 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | ID3D11ShaderResourceView *source = sourceRenderTarget->getShaderResourceView(); |
| 2326 | if (!source) |
| 2327 | { |
| 2328 | ERR("Failed to retrieve the render target view from the render target."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2329 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | TextureStorage11_2D *storage11 = TextureStorage11_2D::makeTextureStorage11_2D(storage->getStorageInstance()); |
| 2333 | if (!storage11) |
| 2334 | { |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2335 | ERR("Failed to retrieve the texture storage from the destination."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2336 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2337 | } |
| 2338 | |
| 2339 | RenderTarget11 *destRenderTarget = RenderTarget11::makeRenderTarget11(storage11->getRenderTarget(level)); |
| 2340 | if (!destRenderTarget) |
| 2341 | { |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2342 | ERR("Failed to retrieve the render target from the destination storage."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2343 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | ID3D11RenderTargetView *dest = destRenderTarget->getRenderTargetView(); |
| 2347 | if (!dest) |
| 2348 | { |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2349 | ERR("Failed to retrieve the render target view from the destination render target."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2350 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2351 | } |
| 2352 | |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2353 | gl::Box sourceArea(sourceRect.x, sourceRect.y, 0, sourceRect.width, sourceRect.height, 1); |
| 2354 | gl::Extents sourceSize(sourceRenderTarget->getWidth(), sourceRenderTarget->getHeight(), 1); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2355 | |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2356 | gl::Box destArea(xoffset, yoffset, 0, sourceRect.width, sourceRect.height, 1); |
| 2357 | gl::Extents destSize(destRenderTarget->getWidth(), destRenderTarget->getHeight(), 1); |
shannonwoods@chromium.org | 7b61d5c | 2013-05-30 00:04:12 +0000 | [diff] [blame] | 2358 | |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2359 | // Use nearest filtering because source and destination are the same size for the direct |
| 2360 | // copy |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 2361 | bool ret = mBlit->copyTexture(source, sourceArea, sourceSize, dest, destArea, destSize, NULL, |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2362 | destFormat, GL_NEAREST); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2363 | |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 2364 | storage11->invalidateSwizzleCacheLevel(level); |
| 2365 | |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2366 | return ret; |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 2367 | } |
| 2368 | |
shannon.woods@transgaming.com | 664916b | 2013-01-25 21:50:32 +0000 | [diff] [blame] | 2369 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2370 | GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level) |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 2371 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2372 | gl::FramebufferAttachment *colorbuffer = framebuffer->getReadColorbuffer(); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2373 | if (!colorbuffer) |
| 2374 | { |
| 2375 | ERR("Failed to retrieve the color buffer from the frame buffer."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2376 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | RenderTarget11 *sourceRenderTarget = RenderTarget11::makeRenderTarget11(colorbuffer->getRenderTarget()); |
| 2380 | if (!sourceRenderTarget) |
| 2381 | { |
| 2382 | ERR("Failed to retrieve the render target from the frame buffer."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2383 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | ID3D11ShaderResourceView *source = sourceRenderTarget->getShaderResourceView(); |
| 2387 | if (!source) |
| 2388 | { |
| 2389 | ERR("Failed to retrieve the render target view from the render target."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2390 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | TextureStorage11_Cube *storage11 = TextureStorage11_Cube::makeTextureStorage11_Cube(storage->getStorageInstance()); |
| 2394 | if (!storage11) |
| 2395 | { |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2396 | ERR("Failed to retrieve the texture storage from the destination."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2397 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2398 | } |
| 2399 | |
Nicolas Capens | b13f866 | 2013-06-04 13:30:19 -0400 | [diff] [blame] | 2400 | RenderTarget11 *destRenderTarget = RenderTarget11::makeRenderTarget11(storage11->getRenderTargetFace(target, level)); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2401 | if (!destRenderTarget) |
| 2402 | { |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2403 | ERR("Failed to retrieve the render target from the destination storage."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2404 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | ID3D11RenderTargetView *dest = destRenderTarget->getRenderTargetView(); |
| 2408 | if (!dest) |
| 2409 | { |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2410 | ERR("Failed to retrieve the render target view from the destination render target."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2411 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2412 | } |
| 2413 | |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2414 | gl::Box sourceArea(sourceRect.x, sourceRect.y, 0, sourceRect.width, sourceRect.height, 1); |
| 2415 | gl::Extents sourceSize(sourceRenderTarget->getWidth(), sourceRenderTarget->getHeight(), 1); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2416 | |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2417 | gl::Box destArea(xoffset, yoffset, 0, sourceRect.width, sourceRect.height, 1); |
| 2418 | gl::Extents destSize(destRenderTarget->getWidth(), destRenderTarget->getHeight(), 1); |
shannonwoods@chromium.org | 7b61d5c | 2013-05-30 00:04:12 +0000 | [diff] [blame] | 2419 | |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2420 | // Use nearest filtering because source and destination are the same size for the direct |
| 2421 | // copy |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 2422 | bool ret = mBlit->copyTexture(source, sourceArea, sourceSize, dest, destArea, destSize, NULL, |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2423 | destFormat, GL_NEAREST); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2424 | |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 2425 | storage11->invalidateSwizzleCacheLevel(level); |
| 2426 | |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2427 | return ret; |
| 2428 | } |
| 2429 | |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2430 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, |
| 2431 | GLint xoffset, GLint yoffset, GLint zOffset, TextureStorageInterface3D *storage, GLint level) |
| 2432 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2433 | gl::FramebufferAttachment *colorbuffer = framebuffer->getReadColorbuffer(); |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2434 | if (!colorbuffer) |
| 2435 | { |
| 2436 | ERR("Failed to retrieve the color buffer from the frame buffer."); |
| 2437 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2438 | } |
| 2439 | |
| 2440 | RenderTarget11 *sourceRenderTarget = RenderTarget11::makeRenderTarget11(colorbuffer->getRenderTarget()); |
| 2441 | if (!sourceRenderTarget) |
| 2442 | { |
| 2443 | ERR("Failed to retrieve the render target from the frame buffer."); |
| 2444 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2445 | } |
| 2446 | |
| 2447 | ID3D11ShaderResourceView *source = sourceRenderTarget->getShaderResourceView(); |
| 2448 | if (!source) |
| 2449 | { |
| 2450 | ERR("Failed to retrieve the render target view from the render target."); |
| 2451 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2452 | } |
| 2453 | |
| 2454 | TextureStorage11_3D *storage11 = TextureStorage11_3D::makeTextureStorage11_3D(storage->getStorageInstance()); |
| 2455 | if (!storage11) |
| 2456 | { |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2457 | ERR("Failed to retrieve the texture storage from the destination."); |
| 2458 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2459 | } |
| 2460 | |
| 2461 | RenderTarget11 *destRenderTarget = RenderTarget11::makeRenderTarget11(storage11->getRenderTargetLayer(level, zOffset)); |
| 2462 | if (!destRenderTarget) |
| 2463 | { |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2464 | ERR("Failed to retrieve the render target from the destination storage."); |
| 2465 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2466 | } |
| 2467 | |
| 2468 | ID3D11RenderTargetView *dest = destRenderTarget->getRenderTargetView(); |
| 2469 | if (!dest) |
| 2470 | { |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2471 | ERR("Failed to retrieve the render target view from the destination render target."); |
| 2472 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2473 | } |
| 2474 | |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2475 | gl::Box sourceArea(sourceRect.x, sourceRect.y, 0, sourceRect.width, sourceRect.height, 1); |
| 2476 | gl::Extents sourceSize(sourceRenderTarget->getWidth(), sourceRenderTarget->getHeight(), 1); |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2477 | |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2478 | gl::Box destArea(xoffset, yoffset, 0, sourceRect.width, sourceRect.height, 1); |
| 2479 | gl::Extents destSize(destRenderTarget->getWidth(), destRenderTarget->getHeight(), 1); |
shannonwoods@chromium.org | 7b61d5c | 2013-05-30 00:04:12 +0000 | [diff] [blame] | 2480 | |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2481 | // Use nearest filtering because source and destination are the same size for the direct |
| 2482 | // copy |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 2483 | bool ret = mBlit->copyTexture(source, sourceArea, sourceSize, dest, destArea, destSize, NULL, |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2484 | destFormat, GL_NEAREST); |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2485 | |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 2486 | storage11->invalidateSwizzleCacheLevel(level); |
| 2487 | |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2488 | return ret; |
| 2489 | } |
| 2490 | |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 2491 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, |
| 2492 | GLint xoffset, GLint yoffset, GLint zOffset, TextureStorageInterface2DArray *storage, GLint level) |
| 2493 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2494 | gl::FramebufferAttachment *colorbuffer = framebuffer->getReadColorbuffer(); |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 2495 | if (!colorbuffer) |
| 2496 | { |
| 2497 | ERR("Failed to retrieve the color buffer from the frame buffer."); |
| 2498 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2499 | } |
| 2500 | |
| 2501 | RenderTarget11 *sourceRenderTarget = RenderTarget11::makeRenderTarget11(colorbuffer->getRenderTarget()); |
| 2502 | if (!sourceRenderTarget) |
| 2503 | { |
| 2504 | ERR("Failed to retrieve the render target from the frame buffer."); |
| 2505 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2506 | } |
| 2507 | |
| 2508 | ID3D11ShaderResourceView *source = sourceRenderTarget->getShaderResourceView(); |
| 2509 | if (!source) |
| 2510 | { |
| 2511 | ERR("Failed to retrieve the render target view from the render target."); |
| 2512 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2513 | } |
| 2514 | |
| 2515 | TextureStorage11_2DArray *storage11 = TextureStorage11_2DArray::makeTextureStorage11_2DArray(storage->getStorageInstance()); |
| 2516 | if (!storage11) |
| 2517 | { |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 2518 | SafeRelease(source); |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 2519 | ERR("Failed to retrieve the texture storage from the destination."); |
| 2520 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2521 | } |
| 2522 | |
| 2523 | RenderTarget11 *destRenderTarget = RenderTarget11::makeRenderTarget11(storage11->getRenderTargetLayer(level, zOffset)); |
| 2524 | if (!destRenderTarget) |
| 2525 | { |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 2526 | SafeRelease(source); |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 2527 | ERR("Failed to retrieve the render target from the destination storage."); |
| 2528 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2529 | } |
| 2530 | |
| 2531 | ID3D11RenderTargetView *dest = destRenderTarget->getRenderTargetView(); |
| 2532 | if (!dest) |
| 2533 | { |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 2534 | ERR("Failed to retrieve the render target view from the destination render target."); |
| 2535 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2536 | } |
| 2537 | |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2538 | gl::Box sourceArea(sourceRect.x, sourceRect.y, 0, sourceRect.width, sourceRect.height, 1); |
| 2539 | gl::Extents sourceSize(sourceRenderTarget->getWidth(), sourceRenderTarget->getHeight(), 1); |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 2540 | |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2541 | gl::Box destArea(xoffset, yoffset, 0, sourceRect.width, sourceRect.height, 1); |
| 2542 | gl::Extents destSize(destRenderTarget->getWidth(), destRenderTarget->getHeight(), 1); |
shannonwoods@chromium.org | 7b61d5c | 2013-05-30 00:04:12 +0000 | [diff] [blame] | 2543 | |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2544 | // Use nearest filtering because source and destination are the same size for the direct |
| 2545 | // copy |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 2546 | bool ret = mBlit->copyTexture(source, sourceArea, sourceSize, dest, destArea, destSize, NULL, |
Geoff Lang | b86b979 | 2013-06-04 16:32:05 -0400 | [diff] [blame] | 2547 | destFormat, GL_NEAREST); |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 2548 | |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 2549 | storage11->invalidateSwizzleCacheLevel(level); |
| 2550 | |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 2551 | return ret; |
| 2552 | } |
| 2553 | |
shannon.woods%transgaming.com@gtempaccount.com | ba2744f | 2013-04-13 03:33:38 +0000 | [diff] [blame] | 2554 | void Renderer11::unapplyRenderTargets() |
| 2555 | { |
| 2556 | setOneTimeRenderTarget(NULL); |
| 2557 | } |
| 2558 | |
| 2559 | void Renderer11::setOneTimeRenderTarget(ID3D11RenderTargetView *renderTargetView) |
| 2560 | { |
| 2561 | ID3D11RenderTargetView *rtvArray[gl::IMPLEMENTATION_MAX_DRAW_BUFFERS] = {NULL}; |
| 2562 | |
| 2563 | rtvArray[0] = renderTargetView; |
| 2564 | |
| 2565 | mDeviceContext->OMSetRenderTargets(getMaxRenderTargets(), rtvArray, NULL); |
| 2566 | |
| 2567 | // Do not preserve the serial for this one-time-use render target |
| 2568 | for (unsigned int rtIndex = 0; rtIndex < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; rtIndex++) |
| 2569 | { |
| 2570 | mAppliedRenderTargetSerials[rtIndex] = 0; |
| 2571 | } |
| 2572 | } |
| 2573 | |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 2574 | RenderTarget *Renderer11::createRenderTarget(SwapChain *swapChain, bool depth) |
| 2575 | { |
shannon.woods@transgaming.com | 183408d | 2013-01-25 21:50:07 +0000 | [diff] [blame] | 2576 | SwapChain11 *swapChain11 = SwapChain11::makeSwapChain11(swapChain); |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 2577 | RenderTarget11 *renderTarget = NULL; |
shannon.woods@transgaming.com | 8c6d9df | 2013-02-28 23:08:57 +0000 | [diff] [blame] | 2578 | |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 2579 | if (depth) |
| 2580 | { |
shannon.woods@transgaming.com | 8c6d9df | 2013-02-28 23:08:57 +0000 | [diff] [blame] | 2581 | // Note: depth stencil may be NULL for 0 sized surfaces |
shannon.woods@transgaming.com | 7e23285 | 2013-02-28 23:06:15 +0000 | [diff] [blame] | 2582 | renderTarget = new RenderTarget11(this, swapChain11->getDepthStencil(), |
Geoff Lang | 88f9cbf | 2013-10-18 14:33:37 -0400 | [diff] [blame] | 2583 | swapChain11->getDepthStencilTexture(), |
| 2584 | swapChain11->getDepthStencilShaderResource(), |
shannonwoods@chromium.org | 7faf3ec | 2013-05-30 00:03:45 +0000 | [diff] [blame] | 2585 | swapChain11->getWidth(), swapChain11->getHeight(), 1); |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 2586 | } |
| 2587 | else |
| 2588 | { |
shannon.woods@transgaming.com | 8c6d9df | 2013-02-28 23:08:57 +0000 | [diff] [blame] | 2589 | // Note: render target may be NULL for 0 sized surfaces |
shannon.woods@transgaming.com | 183408d | 2013-01-25 21:50:07 +0000 | [diff] [blame] | 2590 | renderTarget = new RenderTarget11(this, swapChain11->getRenderTarget(), |
shannon.woods@transgaming.com | 7e23285 | 2013-02-28 23:06:15 +0000 | [diff] [blame] | 2591 | swapChain11->getOffscreenTexture(), |
shannon.woods@transgaming.com | 183408d | 2013-01-25 21:50:07 +0000 | [diff] [blame] | 2592 | swapChain11->getRenderTargetShaderResource(), |
shannonwoods@chromium.org | 7faf3ec | 2013-05-30 00:03:45 +0000 | [diff] [blame] | 2593 | swapChain11->getWidth(), swapChain11->getHeight(), 1); |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 2594 | } |
| 2595 | return renderTarget; |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 2596 | } |
| 2597 | |
Geoff Lang | a2d97f1 | 2013-06-11 11:44:02 -0400 | [diff] [blame] | 2598 | RenderTarget *Renderer11::createRenderTarget(int width, int height, GLenum format, GLsizei samples) |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 2599 | { |
Geoff Lang | a2d97f1 | 2013-06-11 11:44:02 -0400 | [diff] [blame] | 2600 | RenderTarget11 *renderTarget = new RenderTarget11(this, width, height, format, samples); |
daniel@transgaming.com | c9a501d | 2013-01-11 04:08:46 +0000 | [diff] [blame] | 2601 | return renderTarget; |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 2602 | } |
| 2603 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2604 | ShaderExecutable *Renderer11::loadExecutable(const void *function, size_t length, rx::ShaderType type, |
| 2605 | const std::vector<gl::LinkedVarying> &transformFeedbackVaryings, |
| 2606 | bool separatedOutputBuffers) |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 2607 | { |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2608 | ShaderExecutable11 *executable = NULL; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2609 | HRESULT result; |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2610 | |
| 2611 | switch (type) |
| 2612 | { |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 2613 | case rx::SHADER_VERTEX: |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2614 | { |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2615 | ID3D11VertexShader *vertexShader = NULL; |
| 2616 | ID3D11GeometryShader *streamOutShader = NULL; |
| 2617 | |
| 2618 | result = mDevice->CreateVertexShader(function, length, NULL, &vertexShader); |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2619 | ASSERT(SUCCEEDED(result)); |
| 2620 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2621 | if (transformFeedbackVaryings.size() > 0) |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2622 | { |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2623 | std::vector<D3D11_SO_DECLARATION_ENTRY> soDeclaration; |
| 2624 | for (size_t i = 0; i < transformFeedbackVaryings.size(); i++) |
| 2625 | { |
| 2626 | const gl::LinkedVarying &varying = transformFeedbackVaryings[i]; |
Jamie Madill | 6195ef8 | 2014-06-18 10:09:43 -0400 | [diff] [blame] | 2627 | GLenum transposedType = gl::TransposeMatrixType(varying.type); |
| 2628 | |
Geoff Lang | cebb5aa | 2014-04-07 14:13:40 -0400 | [diff] [blame] | 2629 | for (size_t j = 0; j < varying.semanticIndexCount; j++) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2630 | { |
| 2631 | D3D11_SO_DECLARATION_ENTRY entry = { 0 }; |
| 2632 | entry.Stream = 0; |
Geoff Lang | cebb5aa | 2014-04-07 14:13:40 -0400 | [diff] [blame] | 2633 | entry.SemanticName = varying.semanticName.c_str(); |
| 2634 | entry.SemanticIndex = varying.semanticIndex + j; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2635 | entry.StartComponent = 0; |
Jamie Madill | 6195ef8 | 2014-06-18 10:09:43 -0400 | [diff] [blame] | 2636 | entry.ComponentCount = gl::VariableColumnCount(transposedType); |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2637 | entry.OutputSlot = (separatedOutputBuffers ? i : 0); |
| 2638 | soDeclaration.push_back(entry); |
| 2639 | } |
| 2640 | } |
| 2641 | |
| 2642 | result = mDevice->CreateGeometryShaderWithStreamOutput(function, length, soDeclaration.data(), soDeclaration.size(), |
| 2643 | NULL, 0, 0, NULL, &streamOutShader); |
| 2644 | ASSERT(SUCCEEDED(result)); |
| 2645 | } |
| 2646 | |
| 2647 | if (vertexShader) |
| 2648 | { |
| 2649 | executable = new ShaderExecutable11(function, length, vertexShader, streamOutShader); |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2650 | } |
| 2651 | } |
| 2652 | break; |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 2653 | case rx::SHADER_PIXEL: |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2654 | { |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2655 | ID3D11PixelShader *pixelShader = NULL; |
| 2656 | |
| 2657 | result = mDevice->CreatePixelShader(function, length, NULL, &pixelShader); |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2658 | ASSERT(SUCCEEDED(result)); |
| 2659 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2660 | if (pixelShader) |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2661 | { |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2662 | executable = new ShaderExecutable11(function, length, pixelShader); |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2663 | } |
| 2664 | } |
| 2665 | break; |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 2666 | case rx::SHADER_GEOMETRY: |
| 2667 | { |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2668 | ID3D11GeometryShader *geometryShader = NULL; |
| 2669 | |
| 2670 | result = mDevice->CreateGeometryShader(function, length, NULL, &geometryShader); |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 2671 | ASSERT(SUCCEEDED(result)); |
| 2672 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2673 | if (geometryShader) |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 2674 | { |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2675 | executable = new ShaderExecutable11(function, length, geometryShader); |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 2676 | } |
| 2677 | } |
| 2678 | break; |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2679 | default: |
| 2680 | UNREACHABLE(); |
| 2681 | break; |
| 2682 | } |
| 2683 | |
| 2684 | return executable; |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 2685 | } |
| 2686 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2687 | ShaderExecutable *Renderer11::compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, rx::ShaderType type, |
| 2688 | const std::vector<gl::LinkedVarying> &transformFeedbackVaryings, |
| 2689 | bool separatedOutputBuffers, D3DWorkaroundType workaround) |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 2690 | { |
Geoff Lang | 6e05c27 | 2014-03-17 10:46:54 -0700 | [diff] [blame] | 2691 | const char *profileType = NULL; |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 2692 | switch (type) |
| 2693 | { |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 2694 | case rx::SHADER_VERTEX: |
Geoff Lang | 6e05c27 | 2014-03-17 10:46:54 -0700 | [diff] [blame] | 2695 | profileType = "vs"; |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 2696 | break; |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 2697 | case rx::SHADER_PIXEL: |
Geoff Lang | 6e05c27 | 2014-03-17 10:46:54 -0700 | [diff] [blame] | 2698 | profileType = "ps"; |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 2699 | break; |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 2700 | case rx::SHADER_GEOMETRY: |
Geoff Lang | 6e05c27 | 2014-03-17 10:46:54 -0700 | [diff] [blame] | 2701 | profileType = "gs"; |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 2702 | break; |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 2703 | default: |
| 2704 | UNREACHABLE(); |
| 2705 | return NULL; |
| 2706 | } |
| 2707 | |
Geoff Lang | 6e05c27 | 2014-03-17 10:46:54 -0700 | [diff] [blame] | 2708 | const char *profileVersion = NULL; |
| 2709 | switch (mFeatureLevel) |
| 2710 | { |
| 2711 | case D3D_FEATURE_LEVEL_11_0: |
| 2712 | profileVersion = "5_0"; |
| 2713 | break; |
| 2714 | case D3D_FEATURE_LEVEL_10_1: |
| 2715 | profileVersion = "4_1"; |
| 2716 | break; |
| 2717 | case D3D_FEATURE_LEVEL_10_0: |
| 2718 | profileVersion = "4_0"; |
| 2719 | break; |
| 2720 | default: |
| 2721 | UNREACHABLE(); |
| 2722 | return NULL; |
| 2723 | } |
| 2724 | |
| 2725 | char profile[32]; |
| 2726 | snprintf(profile, ArraySize(profile), "%s_%s", profileType, profileVersion); |
| 2727 | |
Nicolas Capens | 93faad9 | 2014-05-10 12:14:13 -0400 | [diff] [blame] | 2728 | UINT flags = D3DCOMPILE_OPTIMIZATION_LEVEL0; |
| 2729 | |
| 2730 | if (gl::perfActive()) |
| 2731 | { |
| 2732 | #ifndef NDEBUG |
| 2733 | flags = D3DCOMPILE_SKIP_OPTIMIZATION; |
| 2734 | #endif |
| 2735 | |
| 2736 | flags |= D3DCOMPILE_DEBUG; |
| 2737 | |
| 2738 | std::string sourcePath = getTempPath(); |
| 2739 | std::string sourceText = std::string("#line 2 \"") + sourcePath + std::string("\"\n\n") + std::string(shaderHLSL); |
| 2740 | writeFile(sourcePath.c_str(), sourceText.c_str(), sourceText.size()); |
| 2741 | } |
| 2742 | |
| 2743 | // Sometimes D3DCompile will fail with the default compilation flags for complicated shaders when it would otherwise pass with alternative options. |
| 2744 | // Try the default flags first and if compilation fails, try some alternatives. |
| 2745 | const UINT extraFlags[] = |
| 2746 | { |
Nicolas Capens | 1408bae | 2014-05-10 12:18:42 -0400 | [diff] [blame] | 2747 | flags, |
Nicolas Capens | 2c27db6 | 2014-05-10 12:21:11 -0400 | [diff] [blame] | 2748 | flags | D3DCOMPILE_SKIP_VALIDATION, |
| 2749 | flags | D3DCOMPILE_SKIP_OPTIMIZATION |
Nicolas Capens | 93faad9 | 2014-05-10 12:14:13 -0400 | [diff] [blame] | 2750 | }; |
| 2751 | |
| 2752 | const static char *extraFlagNames[] = |
| 2753 | { |
Nicolas Capens | 1408bae | 2014-05-10 12:18:42 -0400 | [diff] [blame] | 2754 | "default", |
Nicolas Capens | 2c27db6 | 2014-05-10 12:21:11 -0400 | [diff] [blame] | 2755 | "skip validation", |
| 2756 | "skip optimization" |
Nicolas Capens | 93faad9 | 2014-05-10 12:14:13 -0400 | [diff] [blame] | 2757 | }; |
| 2758 | |
| 2759 | int attempts = ArraySize(extraFlags); |
| 2760 | |
| 2761 | ID3DBlob *binary = (ID3DBlob*)mCompiler.compileToBinary(infoLog, shaderHLSL, profile, extraFlags, extraFlagNames, attempts); |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 2762 | if (!binary) |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 2763 | { |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 2764 | return NULL; |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 2765 | } |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 2766 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 2767 | ShaderExecutable *executable = loadExecutable((DWORD *)binary->GetBufferPointer(), binary->GetBufferSize(), type, |
| 2768 | transformFeedbackVaryings, separatedOutputBuffers); |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 2769 | SafeRelease(binary); |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 2770 | |
| 2771 | return executable; |
| 2772 | } |
| 2773 | |
Jamie Madill | 8ff21ae | 2014-02-04 16:04:05 -0500 | [diff] [blame] | 2774 | rx::UniformStorage *Renderer11::createUniformStorage(size_t storageSize) |
| 2775 | { |
| 2776 | return new UniformStorage11(this, storageSize); |
| 2777 | } |
| 2778 | |
daniel@transgaming.com | 3f255b4 | 2012-12-20 21:07:35 +0000 | [diff] [blame] | 2779 | VertexBuffer *Renderer11::createVertexBuffer() |
| 2780 | { |
daniel@transgaming.com | 2c4d070 | 2012-12-20 21:08:51 +0000 | [diff] [blame] | 2781 | return new VertexBuffer11(this); |
daniel@transgaming.com | 3f255b4 | 2012-12-20 21:07:35 +0000 | [diff] [blame] | 2782 | } |
| 2783 | |
daniel@transgaming.com | 0b6d774 | 2012-12-20 21:09:47 +0000 | [diff] [blame] | 2784 | IndexBuffer *Renderer11::createIndexBuffer() |
| 2785 | { |
daniel@transgaming.com | 11c2af5 | 2012-12-20 21:10:01 +0000 | [diff] [blame] | 2786 | return new IndexBuffer11(this); |
shannon.woods@transgaming.com | cfe787e | 2013-02-28 23:03:35 +0000 | [diff] [blame] | 2787 | } |
| 2788 | |
shannon.woods@transgaming.com | 4e52b63 | 2013-02-28 23:08:01 +0000 | [diff] [blame] | 2789 | BufferStorage *Renderer11::createBufferStorage() |
| 2790 | { |
| 2791 | return new BufferStorage11(this); |
| 2792 | } |
| 2793 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 2794 | VertexArrayImpl *Renderer11::createVertexArray() |
| 2795 | { |
| 2796 | return new VertexArray11(this); |
| 2797 | } |
| 2798 | |
shannon.woods@transgaming.com | cfe787e | 2013-02-28 23:03:35 +0000 | [diff] [blame] | 2799 | QueryImpl *Renderer11::createQuery(GLenum type) |
| 2800 | { |
shannon.woods@transgaming.com | 8b7606a | 2013-02-28 23:03:47 +0000 | [diff] [blame] | 2801 | return new Query11(this, type); |
shannon.woods@transgaming.com | cfe787e | 2013-02-28 23:03:35 +0000 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | FenceImpl *Renderer11::createFence() |
| 2805 | { |
shannon.woods@transgaming.com | be58aa0 | 2013-02-28 23:03:55 +0000 | [diff] [blame] | 2806 | return new Fence11(this); |
daniel@transgaming.com | 0b6d774 | 2012-12-20 21:09:47 +0000 | [diff] [blame] | 2807 | } |
| 2808 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 2809 | bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const |
Jamie Madill | 0e0510f | 2013-10-10 15:46:23 -0400 | [diff] [blame] | 2810 | { |
Jamie Madill | 4461f09 | 2013-10-10 15:10:39 -0400 | [diff] [blame] | 2811 | int clientVersion = getCurrentClientVersion(); |
| 2812 | |
| 2813 | // We only support buffer to texture copies in ES3 |
| 2814 | if (clientVersion <= 2) |
| 2815 | { |
| 2816 | return false; |
| 2817 | } |
| 2818 | |
| 2819 | // sRGB formats do not work with D3D11 buffer SRVs |
| 2820 | if (gl::GetColorEncoding(internalFormat, clientVersion) == GL_SRGB) |
| 2821 | { |
| 2822 | return false; |
| 2823 | } |
| 2824 | |
| 2825 | // We cannot support direct copies to non-color-renderable formats |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2826 | if (!getCaps().textureCaps.get(internalFormat).colorRendering) |
Jamie Madill | 4461f09 | 2013-10-10 15:10:39 -0400 | [diff] [blame] | 2827 | { |
| 2828 | return false; |
| 2829 | } |
| 2830 | |
| 2831 | // We skip all 3-channel formats since sometimes format support is missing |
| 2832 | if (gl::GetComponentCount(internalFormat, clientVersion) == 3) |
| 2833 | { |
| 2834 | return false; |
| 2835 | } |
| 2836 | |
| 2837 | // We don't support formats which we can't represent without conversion |
| 2838 | if (getNativeTextureFormat(internalFormat) != internalFormat) |
| 2839 | { |
| 2840 | return false; |
| 2841 | } |
| 2842 | |
| 2843 | return true; |
Jamie Madill | 0e0510f | 2013-10-10 15:46:23 -0400 | [diff] [blame] | 2844 | } |
| 2845 | |
Jamie Madill | a21eea3 | 2013-09-18 14:36:25 -0400 | [diff] [blame] | 2846 | bool Renderer11::fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget, |
| 2847 | GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea) |
| 2848 | { |
Jamie Madill | 0e0510f | 2013-10-10 15:46:23 -0400 | [diff] [blame] | 2849 | ASSERT(supportsFastCopyBufferToTexture(destinationFormat)); |
Jamie Madill | a21eea3 | 2013-09-18 14:36:25 -0400 | [diff] [blame] | 2850 | return mPixelTransfer->copyBufferToTexture(unpack, offset, destRenderTarget, destinationFormat, sourcePixelsType, destArea); |
| 2851 | } |
| 2852 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2853 | bool Renderer11::getRenderTargetResource(gl::FramebufferAttachment *colorbuffer, unsigned int *subresourceIndex, ID3D11Texture2D **resource) |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 2854 | { |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 2855 | ASSERT(colorbuffer != NULL); |
| 2856 | |
| 2857 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(colorbuffer->getRenderTarget()); |
| 2858 | if (renderTarget) |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 2859 | { |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 2860 | *subresourceIndex = renderTarget->getSubresourceIndex(); |
| 2861 | |
| 2862 | ID3D11RenderTargetView *colorBufferRTV = renderTarget->getRenderTargetView(); |
| 2863 | if (colorBufferRTV) |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 2864 | { |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 2865 | ID3D11Resource *textureResource = NULL; |
| 2866 | colorBufferRTV->GetResource(&textureResource); |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 2867 | |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 2868 | if (textureResource) |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 2869 | { |
Geoff Lang | 8e32884 | 2014-02-10 13:11:20 -0500 | [diff] [blame] | 2870 | HRESULT result = textureResource->QueryInterface(__uuidof(ID3D11Texture2D), (void**)resource); |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 2871 | SafeRelease(textureResource); |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 2872 | |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 2873 | if (SUCCEEDED(result)) |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 2874 | { |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 2875 | return true; |
| 2876 | } |
| 2877 | else |
| 2878 | { |
| 2879 | ERR("Failed to extract the ID3D11Texture2D from the render target resource, " |
| 2880 | "HRESULT: 0x%X.", result); |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 2881 | } |
| 2882 | } |
| 2883 | } |
| 2884 | } |
| 2885 | |
| 2886 | return false; |
| 2887 | } |
| 2888 | |
shannon.woods@transgaming.com | ea4a0c6 | 2013-02-28 23:06:29 +0000 | [diff] [blame] | 2889 | bool Renderer11::blitRect(gl::Framebuffer *readTarget, const gl::Rectangle &readRect, gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect, |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 2890 | const gl::Rectangle *scissor, bool blitRenderTarget, bool blitDepth, bool blitStencil, GLenum filter) |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2891 | { |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 2892 | if (blitRenderTarget) |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 2893 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2894 | gl::FramebufferAttachment *readBuffer = readTarget->getReadColorbuffer(); |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 2895 | |
| 2896 | if (!readBuffer) |
| 2897 | { |
| 2898 | ERR("Failed to retrieve the read buffer from the read framebuffer."); |
| 2899 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2900 | } |
| 2901 | |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 2902 | RenderTarget *readRenderTarget = readBuffer->getRenderTarget(); |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 2903 | |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 2904 | for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 2905 | { |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 2906 | if (drawTarget->isEnabledColorAttachment(colorAttachment)) |
| 2907 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2908 | gl::FramebufferAttachment *drawBuffer = drawTarget->getColorbuffer(colorAttachment); |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 2909 | |
| 2910 | if (!drawBuffer) |
| 2911 | { |
| 2912 | ERR("Failed to retrieve the draw buffer from the draw framebuffer."); |
| 2913 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2914 | } |
| 2915 | |
| 2916 | RenderTarget *drawRenderTarget = drawBuffer->getRenderTarget(); |
| 2917 | |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 2918 | if (!blitRenderbufferRect(readRect, drawRect, readRenderTarget, drawRenderTarget, filter, scissor, |
Geoff Lang | 685806d | 2013-06-12 11:16:36 -0400 | [diff] [blame] | 2919 | blitRenderTarget, false, false)) |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 2920 | { |
| 2921 | return false; |
| 2922 | } |
| 2923 | } |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 2924 | } |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 2925 | } |
| 2926 | |
Geoff Lang | 685806d | 2013-06-12 11:16:36 -0400 | [diff] [blame] | 2927 | if (blitDepth || blitStencil) |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 2928 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2929 | gl::FramebufferAttachment *readBuffer = readTarget->getDepthOrStencilbuffer(); |
| 2930 | gl::FramebufferAttachment *drawBuffer = drawTarget->getDepthOrStencilbuffer(); |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 2931 | |
| 2932 | if (!readBuffer) |
| 2933 | { |
| 2934 | ERR("Failed to retrieve the read depth-stencil buffer from the read framebuffer."); |
| 2935 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2936 | } |
| 2937 | |
| 2938 | if (!drawBuffer) |
| 2939 | { |
| 2940 | ERR("Failed to retrieve the draw depth-stencil buffer from the draw framebuffer."); |
| 2941 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2942 | } |
| 2943 | |
| 2944 | RenderTarget *readRenderTarget = readBuffer->getDepthStencil(); |
| 2945 | RenderTarget *drawRenderTarget = drawBuffer->getDepthStencil(); |
| 2946 | |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 2947 | if (!blitRenderbufferRect(readRect, drawRect, readRenderTarget, drawRenderTarget, filter, scissor, |
Geoff Lang | 685806d | 2013-06-12 11:16:36 -0400 | [diff] [blame] | 2948 | false, blitDepth, blitStencil)) |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 2949 | { |
| 2950 | return false; |
| 2951 | } |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 2952 | } |
| 2953 | |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 2954 | invalidateFramebufferSwizzles(drawTarget); |
| 2955 | |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 2956 | return true; |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2957 | } |
| 2958 | |
Jamie Madill | eb9baab | 2014-03-24 13:19:43 -0400 | [diff] [blame] | 2959 | void Renderer11::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, |
| 2960 | GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, void* pixels) |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2961 | { |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 2962 | ID3D11Texture2D *colorBufferTexture = NULL; |
daniel@transgaming.com | 2eb7ab7 | 2013-01-11 04:10:21 +0000 | [diff] [blame] | 2963 | unsigned int subresourceIndex = 0; |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 2964 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2965 | gl::FramebufferAttachment *colorbuffer = framebuffer->getReadColorbuffer(); |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 2966 | |
| 2967 | if (colorbuffer && getRenderTargetResource(colorbuffer, &subresourceIndex, &colorBufferTexture)) |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 2968 | { |
| 2969 | gl::Rectangle area; |
| 2970 | area.x = x; |
| 2971 | area.y = y; |
| 2972 | area.width = width; |
| 2973 | area.height = height; |
| 2974 | |
Jamie Madill | 1ef6fe7 | 2014-05-01 14:51:05 -0400 | [diff] [blame] | 2975 | if (pack.pixelBuffer.get() != NULL) |
| 2976 | { |
| 2977 | rx::BufferStorage11 *packBufferStorage = BufferStorage11::makeBufferStorage11(pack.pixelBuffer.get()->getStorage()); |
| 2978 | PackPixelsParams packParams(area, format, type, outputPitch, pack, reinterpret_cast<ptrdiff_t>(pixels)); |
| 2979 | packBufferStorage->packPixels(colorBufferTexture, subresourceIndex, packParams); |
| 2980 | } |
| 2981 | else |
| 2982 | { |
| 2983 | readTextureData(colorBufferTexture, subresourceIndex, area, format, type, outputPitch, pack, pixels); |
| 2984 | } |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 2985 | |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 2986 | SafeRelease(colorBufferTexture); |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 2987 | } |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2988 | } |
| 2989 | |
daniel@transgaming.com | 244e183 | 2012-12-20 20:52:35 +0000 | [diff] [blame] | 2990 | Image *Renderer11::createImage() |
| 2991 | { |
daniel@transgaming.com | a8aac67 | 2012-12-20 21:08:00 +0000 | [diff] [blame] | 2992 | return new Image11(); |
daniel@transgaming.com | 244e183 | 2012-12-20 20:52:35 +0000 | [diff] [blame] | 2993 | } |
| 2994 | |
daniel@transgaming.com | f721fdb | 2012-12-20 20:53:11 +0000 | [diff] [blame] | 2995 | void Renderer11::generateMipmap(Image *dest, Image *src) |
| 2996 | { |
shannon.woods@transgaming.com | 2b132f4 | 2013-01-25 21:52:47 +0000 | [diff] [blame] | 2997 | Image11 *dest11 = Image11::makeImage11(dest); |
| 2998 | Image11 *src11 = Image11::makeImage11(src); |
Jamie Madill | d6cb244 | 2013-07-10 15:13:38 -0400 | [diff] [blame] | 2999 | Image11::generateMipmap(getCurrentClientVersion(), dest11, src11); |
daniel@transgaming.com | f721fdb | 2012-12-20 20:53:11 +0000 | [diff] [blame] | 3000 | } |
| 3001 | |
daniel@transgaming.com | 413d271 | 2012-12-20 21:11:04 +0000 | [diff] [blame] | 3002 | TextureStorage *Renderer11::createTextureStorage2D(SwapChain *swapChain) |
| 3003 | { |
daniel@transgaming.com | 36670db | 2013-01-11 04:08:22 +0000 | [diff] [blame] | 3004 | SwapChain11 *swapChain11 = SwapChain11::makeSwapChain11(swapChain); |
| 3005 | return new TextureStorage11_2D(this, swapChain11); |
daniel@transgaming.com | 413d271 | 2012-12-20 21:11:04 +0000 | [diff] [blame] | 3006 | } |
| 3007 | |
Nicolas Capens | bf712d0 | 2014-03-31 14:23:35 -0400 | [diff] [blame] | 3008 | TextureStorage *Renderer11::createTextureStorage2D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, int levels) |
daniel@transgaming.com | 413d271 | 2012-12-20 21:11:04 +0000 | [diff] [blame] | 3009 | { |
Nicolas Capens | bf712d0 | 2014-03-31 14:23:35 -0400 | [diff] [blame] | 3010 | return new TextureStorage11_2D(this, internalformat, renderTarget, width, height, levels); |
daniel@transgaming.com | 413d271 | 2012-12-20 21:11:04 +0000 | [diff] [blame] | 3011 | } |
| 3012 | |
Nicolas Capens | bf712d0 | 2014-03-31 14:23:35 -0400 | [diff] [blame] | 3013 | TextureStorage *Renderer11::createTextureStorageCube(GLenum internalformat, bool renderTarget, int size, int levels) |
daniel@transgaming.com | 413d271 | 2012-12-20 21:11:04 +0000 | [diff] [blame] | 3014 | { |
Nicolas Capens | bf712d0 | 2014-03-31 14:23:35 -0400 | [diff] [blame] | 3015 | return new TextureStorage11_Cube(this, internalformat, renderTarget, size, levels); |
daniel@transgaming.com | 413d271 | 2012-12-20 21:11:04 +0000 | [diff] [blame] | 3016 | } |
| 3017 | |
Nicolas Capens | bf712d0 | 2014-03-31 14:23:35 -0400 | [diff] [blame] | 3018 | TextureStorage *Renderer11::createTextureStorage3D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, GLsizei depth, int levels) |
shannon.woods%transgaming.com@gtempaccount.com | 2058d64 | 2013-04-13 03:42:50 +0000 | [diff] [blame] | 3019 | { |
Nicolas Capens | bf712d0 | 2014-03-31 14:23:35 -0400 | [diff] [blame] | 3020 | return new TextureStorage11_3D(this, internalformat, renderTarget, width, height, depth, levels); |
shannon.woods%transgaming.com@gtempaccount.com | 2058d64 | 2013-04-13 03:42:50 +0000 | [diff] [blame] | 3021 | } |
| 3022 | |
Nicolas Capens | bf712d0 | 2014-03-31 14:23:35 -0400 | [diff] [blame] | 3023 | TextureStorage *Renderer11::createTextureStorage2DArray(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, GLsizei depth, int levels) |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 3024 | { |
Nicolas Capens | bf712d0 | 2014-03-31 14:23:35 -0400 | [diff] [blame] | 3025 | return new TextureStorage11_2DArray(this, internalformat, renderTarget, width, height, depth, levels); |
shannon.woods%transgaming.com@gtempaccount.com | 6c86bd5 | 2013-04-13 03:45:45 +0000 | [diff] [blame] | 3026 | } |
| 3027 | |
Jamie Madill | eb9baab | 2014-03-24 13:19:43 -0400 | [diff] [blame] | 3028 | void Renderer11::readTextureData(ID3D11Texture2D *texture, unsigned int subResource, const gl::Rectangle &area, GLenum format, |
| 3029 | GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, void *pixels) |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3030 | { |
Jamie Madill | 1eb5bd7 | 2014-03-28 10:43:39 -0400 | [diff] [blame] | 3031 | ASSERT(area.width >= 0); |
| 3032 | ASSERT(area.height >= 0); |
| 3033 | |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3034 | D3D11_TEXTURE2D_DESC textureDesc; |
| 3035 | texture->GetDesc(&textureDesc); |
| 3036 | |
Jamie Madill | 1eb5bd7 | 2014-03-28 10:43:39 -0400 | [diff] [blame] | 3037 | // Clamp read region to the defined texture boundaries, preventing out of bounds reads |
| 3038 | // and reads of uninitialized data. |
| 3039 | gl::Rectangle safeArea; |
| 3040 | safeArea.x = gl::clamp(area.x, 0, static_cast<int>(textureDesc.Width)); |
| 3041 | safeArea.y = gl::clamp(area.y, 0, static_cast<int>(textureDesc.Height)); |
| 3042 | safeArea.width = gl::clamp(area.width + std::min(area.x, 0), 0, |
| 3043 | static_cast<int>(textureDesc.Width) - safeArea.x); |
| 3044 | safeArea.height = gl::clamp(area.height + std::min(area.y, 0), 0, |
| 3045 | static_cast<int>(textureDesc.Height) - safeArea.y); |
| 3046 | |
| 3047 | ASSERT(safeArea.x >= 0 && safeArea.y >= 0); |
| 3048 | ASSERT(safeArea.x + safeArea.width <= static_cast<int>(textureDesc.Width)); |
| 3049 | ASSERT(safeArea.y + safeArea.height <= static_cast<int>(textureDesc.Height)); |
| 3050 | |
| 3051 | if (safeArea.width == 0 || safeArea.height == 0) |
| 3052 | { |
| 3053 | // no work to do |
| 3054 | return; |
| 3055 | } |
| 3056 | |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3057 | D3D11_TEXTURE2D_DESC stagingDesc; |
Jamie Madill | 1eb5bd7 | 2014-03-28 10:43:39 -0400 | [diff] [blame] | 3058 | stagingDesc.Width = safeArea.width; |
| 3059 | stagingDesc.Height = safeArea.height; |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3060 | stagingDesc.MipLevels = 1; |
| 3061 | stagingDesc.ArraySize = 1; |
| 3062 | stagingDesc.Format = textureDesc.Format; |
| 3063 | stagingDesc.SampleDesc.Count = 1; |
| 3064 | stagingDesc.SampleDesc.Quality = 0; |
| 3065 | stagingDesc.Usage = D3D11_USAGE_STAGING; |
| 3066 | stagingDesc.BindFlags = 0; |
| 3067 | stagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; |
| 3068 | stagingDesc.MiscFlags = 0; |
| 3069 | |
| 3070 | ID3D11Texture2D* stagingTex = NULL; |
| 3071 | HRESULT result = mDevice->CreateTexture2D(&stagingDesc, NULL, &stagingTex); |
| 3072 | if (FAILED(result)) |
| 3073 | { |
| 3074 | ERR("Failed to create staging texture for readPixels, HRESULT: 0x%X.", result); |
| 3075 | return; |
| 3076 | } |
| 3077 | |
| 3078 | ID3D11Texture2D* srcTex = NULL; |
| 3079 | if (textureDesc.SampleDesc.Count > 1) |
| 3080 | { |
| 3081 | D3D11_TEXTURE2D_DESC resolveDesc; |
| 3082 | resolveDesc.Width = textureDesc.Width; |
| 3083 | resolveDesc.Height = textureDesc.Height; |
| 3084 | resolveDesc.MipLevels = 1; |
| 3085 | resolveDesc.ArraySize = 1; |
| 3086 | resolveDesc.Format = textureDesc.Format; |
| 3087 | resolveDesc.SampleDesc.Count = 1; |
| 3088 | resolveDesc.SampleDesc.Quality = 0; |
| 3089 | resolveDesc.Usage = D3D11_USAGE_DEFAULT; |
| 3090 | resolveDesc.BindFlags = 0; |
| 3091 | resolveDesc.CPUAccessFlags = 0; |
| 3092 | resolveDesc.MiscFlags = 0; |
| 3093 | |
| 3094 | result = mDevice->CreateTexture2D(&resolveDesc, NULL, &srcTex); |
| 3095 | if (FAILED(result)) |
| 3096 | { |
| 3097 | ERR("Failed to create resolve texture for readPixels, HRESULT: 0x%X.", result); |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 3098 | SafeRelease(stagingTex); |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3099 | return; |
| 3100 | } |
| 3101 | |
| 3102 | mDeviceContext->ResolveSubresource(srcTex, 0, texture, subResource, textureDesc.Format); |
| 3103 | subResource = 0; |
| 3104 | } |
| 3105 | else |
| 3106 | { |
| 3107 | srcTex = texture; |
| 3108 | srcTex->AddRef(); |
| 3109 | } |
| 3110 | |
| 3111 | D3D11_BOX srcBox; |
Jamie Madill | 1eb5bd7 | 2014-03-28 10:43:39 -0400 | [diff] [blame] | 3112 | srcBox.left = static_cast<UINT>(safeArea.x); |
| 3113 | srcBox.right = static_cast<UINT>(safeArea.x + safeArea.width); |
| 3114 | srcBox.top = static_cast<UINT>(safeArea.y); |
| 3115 | srcBox.bottom = static_cast<UINT>(safeArea.y + safeArea.height); |
| 3116 | srcBox.front = 0; |
| 3117 | srcBox.back = 1; |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3118 | |
| 3119 | mDeviceContext->CopySubresourceRegion(stagingTex, 0, 0, 0, 0, srcTex, subResource, &srcBox); |
| 3120 | |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 3121 | SafeRelease(srcTex); |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3122 | |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3123 | PackPixelsParams packParams(safeArea, format, type, outputPitch, pack, 0); |
| 3124 | packPixels(stagingTex, packParams, pixels); |
| 3125 | |
| 3126 | SafeRelease(stagingTex); |
| 3127 | } |
| 3128 | |
| 3129 | void Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams ¶ms, void *pixelsOut) |
| 3130 | { |
| 3131 | D3D11_TEXTURE2D_DESC textureDesc; |
| 3132 | readTexture->GetDesc(&textureDesc); |
| 3133 | |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3134 | D3D11_MAPPED_SUBRESOURCE mapping; |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3135 | HRESULT hr = mDeviceContext->Map(readTexture, 0, D3D11_MAP_READ, 0, &mapping); |
Geoff Lang | 9cd1915 | 2014-05-28 15:54:34 -0400 | [diff] [blame] | 3136 | UNUSED_ASSERTION_VARIABLE(hr); |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3137 | ASSERT(SUCCEEDED(hr)); |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3138 | |
| 3139 | unsigned char *source; |
| 3140 | int inputPitch; |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3141 | if (params.pack.reverseRowOrder) |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3142 | { |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3143 | source = static_cast<unsigned char*>(mapping.pData) + mapping.RowPitch * (params.area.height - 1); |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3144 | inputPitch = -static_cast<int>(mapping.RowPitch); |
| 3145 | } |
| 3146 | else |
| 3147 | { |
| 3148 | source = static_cast<unsigned char*>(mapping.pData); |
| 3149 | inputPitch = static_cast<int>(mapping.RowPitch); |
| 3150 | } |
| 3151 | |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 3152 | GLuint clientVersion = getCurrentClientVersion(); |
shannon.woods%transgaming.com@gtempaccount.com | 676dc8f | 2013-04-13 03:35:13 +0000 | [diff] [blame] | 3153 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 3154 | GLenum sourceInternalFormat = d3d11_gl::GetInternalFormat(textureDesc.Format, clientVersion); |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 3155 | GLenum sourceFormat = gl::GetFormat(sourceInternalFormat, clientVersion); |
| 3156 | GLenum sourceType = gl::GetType(sourceInternalFormat, clientVersion); |
| 3157 | |
| 3158 | GLuint sourcePixelSize = gl::GetPixelBytes(sourceInternalFormat, clientVersion); |
| 3159 | |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3160 | if (sourceFormat == params.format && sourceType == params.type) |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 3161 | { |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3162 | unsigned char *dest = static_cast<unsigned char*>(pixelsOut) + params.offset; |
| 3163 | for (int y = 0; y < params.area.height; y++) |
shannon.woods%transgaming.com@gtempaccount.com | 676dc8f | 2013-04-13 03:35:13 +0000 | [diff] [blame] | 3164 | { |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3165 | memcpy(dest + y * params.outputPitch, source + y * inputPitch, params.area.width * sourcePixelSize); |
shannon.woods%transgaming.com@gtempaccount.com | 676dc8f | 2013-04-13 03:35:13 +0000 | [diff] [blame] | 3166 | } |
| 3167 | } |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3168 | else |
| 3169 | { |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3170 | GLenum destInternalFormat = gl::GetSizedInternalFormat(params.format, params.type, clientVersion); |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 3171 | GLuint destPixelSize = gl::GetPixelBytes(destInternalFormat, clientVersion); |
| 3172 | |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3173 | ColorCopyFunction fastCopyFunc = d3d11::GetFastCopyFunction(textureDesc.Format, params.format, params.type); |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 3174 | if (fastCopyFunc) |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3175 | { |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 3176 | // Fast copy is possible through some special function |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3177 | for (int y = 0; y < params.area.height; y++) |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3178 | { |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3179 | for (int x = 0; x < params.area.width; x++) |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 3180 | { |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3181 | void *dest = static_cast<unsigned char*>(pixelsOut) + params.offset + y * params.outputPitch + x * destPixelSize; |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 3182 | void *src = static_cast<unsigned char*>(source) + y * inputPitch + x * sourcePixelSize; |
| 3183 | |
| 3184 | fastCopyFunc(src, dest); |
| 3185 | } |
| 3186 | } |
| 3187 | } |
| 3188 | else |
| 3189 | { |
Jamie Madill | 9eeecfc | 2014-01-29 09:26:48 -0500 | [diff] [blame] | 3190 | ColorReadFunction readFunc = d3d11::GetColorReadFunction(textureDesc.Format); |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3191 | ColorWriteFunction writeFunc = gl::GetColorWriteFunction(params.format, params.type, clientVersion); |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 3192 | |
| 3193 | unsigned char temp[16]; // Maximum size of any Color<T> type used. |
| 3194 | META_ASSERT(sizeof(temp) >= sizeof(gl::ColorF) && |
| 3195 | sizeof(temp) >= sizeof(gl::ColorUI) && |
| 3196 | sizeof(temp) >= sizeof(gl::ColorI)); |
| 3197 | |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3198 | for (int y = 0; y < params.area.height; y++) |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 3199 | { |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3200 | for (int x = 0; x < params.area.width; x++) |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 3201 | { |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3202 | void *dest = static_cast<unsigned char*>(pixelsOut) + params.offset + y * params.outputPitch + x * destPixelSize; |
Geoff Lang | 697ad3e | 2013-06-04 10:11:28 -0400 | [diff] [blame] | 3203 | void *src = static_cast<unsigned char*>(source) + y * inputPitch + x * sourcePixelSize; |
| 3204 | |
| 3205 | // readFunc and writeFunc will be using the same type of color, CopyTexImage |
| 3206 | // will not allow the copy otherwise. |
| 3207 | readFunc(src, temp); |
| 3208 | writeFunc(temp, dest); |
| 3209 | } |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3210 | } |
| 3211 | } |
| 3212 | } |
| 3213 | |
Jamie Madill | 7538f7f | 2014-04-17 11:53:39 -0400 | [diff] [blame] | 3214 | mDeviceContext->Unmap(readTexture, 0); |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3215 | } |
| 3216 | |
Geoff Lang | 758d5b2 | 2013-06-11 11:42:50 -0400 | [diff] [blame] | 3217 | bool Renderer11::blitRenderbufferRect(const gl::Rectangle &readRect, const gl::Rectangle &drawRect, RenderTarget *readRenderTarget, |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 3218 | RenderTarget *drawRenderTarget, GLenum filter, const gl::Rectangle *scissor, |
| 3219 | bool colorBlit, bool depthBlit, bool stencilBlit) |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3220 | { |
Geoff Lang | 975af37 | 2013-06-12 11:19:22 -0400 | [diff] [blame] | 3221 | // Since blitRenderbufferRect is called for each render buffer that needs to be blitted, |
| 3222 | // it should never be the case that both color and depth/stencil need to be blitted at |
| 3223 | // at the same time. |
| 3224 | ASSERT(colorBlit != (depthBlit || stencilBlit)); |
| 3225 | |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3226 | bool result = true; |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3227 | |
Geoff Lang | 4d78273 | 2013-07-22 10:44:18 -0400 | [diff] [blame] | 3228 | RenderTarget11 *drawRenderTarget11 = RenderTarget11::makeRenderTarget11(drawRenderTarget); |
| 3229 | if (!drawRenderTarget) |
| 3230 | { |
| 3231 | ERR("Failed to retrieve the draw render target from the draw framebuffer."); |
| 3232 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 3233 | } |
| 3234 | |
| 3235 | ID3D11Resource *drawTexture = drawRenderTarget11->getTexture(); |
| 3236 | unsigned int drawSubresource = drawRenderTarget11->getSubresourceIndex(); |
| 3237 | ID3D11RenderTargetView *drawRTV = drawRenderTarget11->getRenderTargetView(); |
| 3238 | ID3D11DepthStencilView *drawDSV = drawRenderTarget11->getDepthStencilView(); |
| 3239 | |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3240 | RenderTarget11 *readRenderTarget11 = RenderTarget11::makeRenderTarget11(readRenderTarget); |
| 3241 | if (!readRenderTarget) |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3242 | { |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3243 | ERR("Failed to retrieve the read render target from the read framebuffer."); |
shannon.woods@transgaming.com | ea4a0c6 | 2013-02-28 23:06:29 +0000 | [diff] [blame] | 3244 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3245 | } |
| 3246 | |
shannon.woods%transgaming.com@gtempaccount.com | 27ac40e | 2013-04-13 03:43:17 +0000 | [diff] [blame] | 3247 | ID3D11Resource *readTexture = NULL; |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3248 | ID3D11ShaderResourceView *readSRV = NULL; |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3249 | unsigned int readSubresource = 0; |
| 3250 | if (readRenderTarget->getSamples() > 0) |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3251 | { |
shannon.woods%transgaming.com@gtempaccount.com | 27ac40e | 2013-04-13 03:43:17 +0000 | [diff] [blame] | 3252 | ID3D11Resource *unresolvedResource = readRenderTarget11->getTexture(); |
| 3253 | ID3D11Texture2D *unresolvedTexture = d3d11::DynamicCastComObject<ID3D11Texture2D>(unresolvedResource); |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3254 | |
shannon.woods%transgaming.com@gtempaccount.com | 27ac40e | 2013-04-13 03:43:17 +0000 | [diff] [blame] | 3255 | if (unresolvedTexture) |
| 3256 | { |
| 3257 | readTexture = resolveMultisampledTexture(unresolvedTexture, readRenderTarget11->getSubresourceIndex()); |
| 3258 | readSubresource = 0; |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3259 | |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 3260 | SafeRelease(unresolvedTexture); |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3261 | |
Geoff Lang | 5c9a29a | 2014-02-11 10:26:24 -0500 | [diff] [blame] | 3262 | HRESULT hresult = mDevice->CreateShaderResourceView(readTexture, NULL, &readSRV); |
| 3263 | if (FAILED(hresult)) |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3264 | { |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame] | 3265 | SafeRelease(readTexture); |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3266 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 3267 | } |
shannon.woods%transgaming.com@gtempaccount.com | 27ac40e | 2013-04-13 03:43:17 +0000 | [diff] [blame] | 3268 | } |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3269 | } |
| 3270 | else |
| 3271 | { |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3272 | readTexture = readRenderTarget11->getTexture(); |
Geoff Lang | 4d78273 | 2013-07-22 10:44:18 -0400 | [diff] [blame] | 3273 | readTexture->AddRef(); |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3274 | readSubresource = readRenderTarget11->getSubresourceIndex(); |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3275 | readSRV = readRenderTarget11->getShaderResourceView(); |
Geoff Lang | 4d78273 | 2013-07-22 10:44:18 -0400 | [diff] [blame] | 3276 | readSRV->AddRef(); |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3277 | } |
| 3278 | |
Geoff Lang | 4d78273 | 2013-07-22 10:44:18 -0400 | [diff] [blame] | 3279 | if (!readTexture || !readSRV) |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3280 | { |
Geoff Lang | 4d78273 | 2013-07-22 10:44:18 -0400 | [diff] [blame] | 3281 | SafeRelease(readTexture); |
| 3282 | SafeRelease(readSRV); |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3283 | ERR("Failed to retrieve the read render target view from the read render target."); |
shannon.woods@transgaming.com | ea4a0c6 | 2013-02-28 23:06:29 +0000 | [diff] [blame] | 3284 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3285 | } |
| 3286 | |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 3287 | gl::Extents readSize(readRenderTarget->getWidth(), readRenderTarget->getHeight(), 1); |
| 3288 | gl::Extents drawSize(drawRenderTarget->getWidth(), drawRenderTarget->getHeight(), 1); |
| 3289 | |
| 3290 | bool scissorNeeded = scissor && gl::ClipRectangle(drawRect, *scissor, NULL); |
| 3291 | |
| 3292 | bool wholeBufferCopy = !scissorNeeded && |
| 3293 | readRect.x == 0 && readRect.width == readSize.width && |
| 3294 | readRect.y == 0 && readRect.height == readSize.height && |
| 3295 | drawRect.x == 0 && drawRect.width == drawSize.width && |
| 3296 | drawRect.y == 0 && drawRect.height == drawSize.height; |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3297 | |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3298 | bool stretchRequired = readRect.width != drawRect.width || readRect.height != drawRect.height; |
Geoff Lang | 758d5b2 | 2013-06-11 11:42:50 -0400 | [diff] [blame] | 3299 | |
Geoff Lang | 1cd1b21 | 2014-02-11 09:42:27 -0500 | [diff] [blame] | 3300 | bool flipRequired = readRect.width < 0 || readRect.height < 0 || drawRect.width < 0 || drawRect.height < 0; |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 3301 | |
| 3302 | bool outOfBounds = readRect.x < 0 || readRect.x + readRect.width > readSize.width || |
| 3303 | readRect.y < 0 || readRect.y + readRect.height > readSize.height || |
| 3304 | drawRect.x < 0 || drawRect.x + drawRect.width > drawSize.width || |
| 3305 | drawRect.y < 0 || drawRect.y + drawRect.height > drawSize.height; |
| 3306 | |
| 3307 | bool hasDepth = gl::GetDepthBits(drawRenderTarget11->getActualFormat(), getCurrentClientVersion()) > 0; |
| 3308 | bool hasStencil = gl::GetStencilBits(drawRenderTarget11->getActualFormat(), getCurrentClientVersion()) > 0; |
| 3309 | bool partialDSBlit = (hasDepth && depthBlit) != (hasStencil && stencilBlit); |
| 3310 | |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3311 | if (readRenderTarget11->getActualFormat() == drawRenderTarget->getActualFormat() && |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 3312 | !stretchRequired && !outOfBounds && !flipRequired && !partialDSBlit && |
| 3313 | (!(depthBlit || stencilBlit) || wholeBufferCopy)) |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3314 | { |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 3315 | UINT dstX = drawRect.x; |
| 3316 | UINT dstY = drawRect.y; |
| 3317 | |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3318 | D3D11_BOX readBox; |
| 3319 | readBox.left = readRect.x; |
| 3320 | readBox.right = readRect.x + readRect.width; |
| 3321 | readBox.top = readRect.y; |
| 3322 | readBox.bottom = readRect.y + readRect.height; |
| 3323 | readBox.front = 0; |
| 3324 | readBox.back = 1; |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3325 | |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 3326 | if (scissorNeeded) |
| 3327 | { |
| 3328 | // drawRect is guaranteed to have positive width and height because stretchRequired is false. |
| 3329 | ASSERT(drawRect.width >= 0 || drawRect.height >= 0); |
| 3330 | |
| 3331 | if (drawRect.x < scissor->x) |
| 3332 | { |
| 3333 | dstX = scissor->x; |
| 3334 | readBox.left += (scissor->x - drawRect.x); |
| 3335 | } |
| 3336 | if (drawRect.y < scissor->y) |
| 3337 | { |
| 3338 | dstY = scissor->y; |
| 3339 | readBox.top += (scissor->y - drawRect.y); |
| 3340 | } |
| 3341 | if (drawRect.x + drawRect.width > scissor->x + scissor->width) |
| 3342 | { |
| 3343 | readBox.right -= ((drawRect.x + drawRect.width) - (scissor->x + scissor->width)); |
| 3344 | } |
| 3345 | if (drawRect.y + drawRect.height > scissor->y + scissor->height) |
| 3346 | { |
| 3347 | readBox.bottom -= ((drawRect.y + drawRect.height) - (scissor->y + scissor->height)); |
| 3348 | } |
| 3349 | } |
| 3350 | |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3351 | // D3D11 needs depth-stencil CopySubresourceRegions to have a NULL pSrcBox |
| 3352 | // We also require complete framebuffer copies for depth-stencil blit. |
| 3353 | D3D11_BOX *pSrcBox = wholeBufferCopy ? NULL : &readBox; |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3354 | |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 3355 | mDeviceContext->CopySubresourceRegion(drawTexture, drawSubresource, dstX, dstY, 0, |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3356 | readTexture, readSubresource, pSrcBox); |
| 3357 | result = true; |
| 3358 | } |
| 3359 | else |
| 3360 | { |
| 3361 | gl::Box readArea(readRect.x, readRect.y, 0, readRect.width, readRect.height, 1); |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3362 | gl::Box drawArea(drawRect.x, drawRect.y, 0, drawRect.width, drawRect.height, 1); |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3363 | |
Geoff Lang | 975af37 | 2013-06-12 11:19:22 -0400 | [diff] [blame] | 3364 | if (depthBlit && stencilBlit) |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3365 | { |
Geoff Lang | 975af37 | 2013-06-12 11:19:22 -0400 | [diff] [blame] | 3366 | result = mBlit->copyDepthStencil(readTexture, readSubresource, readArea, readSize, |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 3367 | drawTexture, drawSubresource, drawArea, drawSize, |
| 3368 | scissor); |
Geoff Lang | 975af37 | 2013-06-12 11:19:22 -0400 | [diff] [blame] | 3369 | } |
| 3370 | else if (depthBlit) |
| 3371 | { |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 3372 | result = mBlit->copyDepth(readSRV, readArea, readSize, drawDSV, drawArea, drawSize, |
| 3373 | scissor); |
Geoff Lang | 975af37 | 2013-06-12 11:19:22 -0400 | [diff] [blame] | 3374 | } |
| 3375 | else if (stencilBlit) |
| 3376 | { |
| 3377 | result = mBlit->copyStencil(readTexture, readSubresource, readArea, readSize, |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 3378 | drawTexture, drawSubresource, drawArea, drawSize, |
| 3379 | scissor); |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3380 | } |
| 3381 | else |
| 3382 | { |
Geoff Lang | 685806d | 2013-06-12 11:16:36 -0400 | [diff] [blame] | 3383 | GLenum format = gl::GetFormat(drawRenderTarget->getInternalFormat(), getCurrentClientVersion()); |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 3384 | result = mBlit->copyTexture(readSRV, readArea, readSize, drawRTV, drawArea, drawSize, |
| 3385 | scissor, format, filter); |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3386 | } |
| 3387 | } |
| 3388 | |
| 3389 | SafeRelease(readTexture); |
| 3390 | SafeRelease(readSRV); |
Geoff Lang | c1f51be | 2013-06-11 11:49:14 -0400 | [diff] [blame] | 3391 | |
| 3392 | return result; |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3393 | } |
| 3394 | |
shannon.woods@transgaming.com | d67f9ce | 2013-02-28 23:06:09 +0000 | [diff] [blame] | 3395 | ID3D11Texture2D *Renderer11::resolveMultisampledTexture(ID3D11Texture2D *source, unsigned int subresource) |
| 3396 | { |
| 3397 | D3D11_TEXTURE2D_DESC textureDesc; |
| 3398 | source->GetDesc(&textureDesc); |
| 3399 | |
| 3400 | if (textureDesc.SampleDesc.Count > 1) |
| 3401 | { |
| 3402 | D3D11_TEXTURE2D_DESC resolveDesc; |
| 3403 | resolveDesc.Width = textureDesc.Width; |
| 3404 | resolveDesc.Height = textureDesc.Height; |
| 3405 | resolveDesc.MipLevels = 1; |
| 3406 | resolveDesc.ArraySize = 1; |
| 3407 | resolveDesc.Format = textureDesc.Format; |
| 3408 | resolveDesc.SampleDesc.Count = 1; |
| 3409 | resolveDesc.SampleDesc.Quality = 0; |
| 3410 | resolveDesc.Usage = textureDesc.Usage; |
| 3411 | resolveDesc.BindFlags = textureDesc.BindFlags; |
| 3412 | resolveDesc.CPUAccessFlags = 0; |
| 3413 | resolveDesc.MiscFlags = 0; |
| 3414 | |
| 3415 | ID3D11Texture2D *resolveTexture = NULL; |
| 3416 | HRESULT result = mDevice->CreateTexture2D(&resolveDesc, NULL, &resolveTexture); |
| 3417 | if (FAILED(result)) |
| 3418 | { |
| 3419 | ERR("Failed to create a multisample resolve texture, HRESULT: 0x%X.", result); |
| 3420 | return NULL; |
| 3421 | } |
| 3422 | |
| 3423 | mDeviceContext->ResolveSubresource(resolveTexture, 0, source, subresource, textureDesc.Format); |
| 3424 | return resolveTexture; |
| 3425 | } |
| 3426 | else |
| 3427 | { |
| 3428 | source->AddRef(); |
| 3429 | return source; |
| 3430 | } |
| 3431 | } |
| 3432 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 3433 | void Renderer11::invalidateFBOAttachmentSwizzles(gl::FramebufferAttachment *attachment, int mipLevel) |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 3434 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 3435 | ASSERT(attachment->isTexture()); |
| 3436 | TextureStorage *texStorage = attachment->getTextureStorage(); |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 3437 | if (texStorage) |
| 3438 | { |
| 3439 | TextureStorage11 *texStorage11 = TextureStorage11::makeTextureStorage11(texStorage); |
| 3440 | if (!texStorage11) |
| 3441 | { |
| 3442 | ERR("texture storage pointer unexpectedly null."); |
| 3443 | return; |
| 3444 | } |
| 3445 | |
| 3446 | texStorage11->invalidateSwizzleCacheLevel(mipLevel); |
| 3447 | } |
| 3448 | } |
| 3449 | |
| 3450 | void Renderer11::invalidateFramebufferSwizzles(gl::Framebuffer *framebuffer) |
| 3451 | { |
| 3452 | for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
| 3453 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 3454 | gl::FramebufferAttachment *attachment = framebuffer->getColorbuffer(colorAttachment); |
| 3455 | if (attachment && attachment->isTexture()) |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 3456 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 3457 | invalidateFBOAttachmentSwizzles(attachment, framebuffer->getColorbufferMipLevel(colorAttachment)); |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 3458 | } |
| 3459 | } |
| 3460 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 3461 | gl::FramebufferAttachment *depthAttachment = framebuffer->getDepthbuffer(); |
| 3462 | if (depthAttachment && depthAttachment->isTexture()) |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 3463 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 3464 | invalidateFBOAttachmentSwizzles(depthAttachment, framebuffer->getDepthbufferMipLevel()); |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 3465 | } |
| 3466 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 3467 | gl::FramebufferAttachment *stencilAttachment = framebuffer->getStencilbuffer(); |
| 3468 | if (stencilAttachment && stencilAttachment->isTexture()) |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 3469 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 3470 | invalidateFBOAttachmentSwizzles(stencilAttachment, framebuffer->getStencilbufferMipLevel()); |
Geoff Lang | 42477a4 | 2013-09-17 17:07:02 -0400 | [diff] [blame] | 3471 | } |
| 3472 | } |
| 3473 | |
shannonwoods@chromium.org | 6e4f2a6 | 2013-05-30 00:15:19 +0000 | [diff] [blame] | 3474 | bool Renderer11::getLUID(LUID *adapterLuid) const |
| 3475 | { |
| 3476 | adapterLuid->HighPart = 0; |
| 3477 | adapterLuid->LowPart = 0; |
| 3478 | |
| 3479 | if (!mDxgiAdapter) |
| 3480 | { |
| 3481 | return false; |
| 3482 | } |
| 3483 | |
| 3484 | DXGI_ADAPTER_DESC adapterDesc; |
| 3485 | if (FAILED(mDxgiAdapter->GetDesc(&adapterDesc))) |
| 3486 | { |
| 3487 | return false; |
| 3488 | } |
| 3489 | |
| 3490 | *adapterLuid = adapterDesc.AdapterLuid; |
| 3491 | return true; |
| 3492 | } |
| 3493 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 3494 | GLenum Renderer11::getNativeTextureFormat(GLenum internalFormat) const |
Jamie Madill | c8c102b | 2013-10-10 15:10:24 -0400 | [diff] [blame] | 3495 | { |
| 3496 | int clientVersion = getCurrentClientVersion(); |
| 3497 | return d3d11_gl::GetInternalFormat(gl_d3d11::GetTexFormat(internalFormat, clientVersion), clientVersion); |
| 3498 | } |
| 3499 | |
Jamie Madill | 95ffb86 | 2014-01-29 09:26:59 -0500 | [diff] [blame] | 3500 | rx::VertexConversionType Renderer11::getVertexConversionType(const gl::VertexFormat &vertexFormat) const |
| 3501 | { |
| 3502 | return gl_d3d11::GetVertexConversionType(vertexFormat); |
| 3503 | } |
| 3504 | |
| 3505 | GLenum Renderer11::getVertexComponentType(const gl::VertexFormat &vertexFormat) const |
| 3506 | { |
| 3507 | return d3d11::GetComponentType(gl_d3d11::GetNativeVertexFormat(vertexFormat)); |
| 3508 | } |
| 3509 | |
Geoff Lang | 61e49a5 | 2013-05-29 10:22:58 -0400 | [diff] [blame] | 3510 | Renderer11::MultisampleSupportInfo Renderer11::getMultisampleSupportInfo(DXGI_FORMAT format) |
| 3511 | { |
| 3512 | MultisampleSupportInfo supportInfo = { 0 }; |
| 3513 | |
| 3514 | UINT formatSupport; |
| 3515 | HRESULT result; |
| 3516 | |
| 3517 | result = mDevice->CheckFormatSupport(format, &formatSupport); |
| 3518 | if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET)) |
| 3519 | { |
| 3520 | for (unsigned int i = 1; i <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; i++) |
| 3521 | { |
| 3522 | result = mDevice->CheckMultisampleQualityLevels(format, i, &supportInfo.qualityLevels[i - 1]); |
| 3523 | if (SUCCEEDED(result) && supportInfo.qualityLevels[i - 1] > 0) |
| 3524 | { |
| 3525 | supportInfo.maxSupportedSamples = std::max(supportInfo.maxSupportedSamples, i); |
| 3526 | } |
| 3527 | else |
| 3528 | { |
| 3529 | supportInfo.qualityLevels[i - 1] = 0; |
| 3530 | } |
| 3531 | } |
| 3532 | } |
| 3533 | |
| 3534 | return supportInfo; |
| 3535 | } |
| 3536 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 3537 | gl::Caps Renderer11::generateCaps() const |
| 3538 | { |
| 3539 | return d3d11_gl::GenerateCaps(mDevice); |
| 3540 | } |
| 3541 | |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 3542 | } |