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