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