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