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