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