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