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