Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | #include "precompiled.h" |
michael@0 | 2 | // |
michael@0 | 3 | // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. |
michael@0 | 4 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | // found in the LICENSE file. |
michael@0 | 6 | // |
michael@0 | 7 | |
michael@0 | 8 | // InputLayoutCache.cpp: Defines InputLayoutCache, a class that builds and caches |
michael@0 | 9 | // D3D11 input layouts. |
michael@0 | 10 | |
michael@0 | 11 | #include "libGLESv2/renderer/InputLayoutCache.h" |
michael@0 | 12 | #include "libGLESv2/renderer/VertexBuffer11.h" |
michael@0 | 13 | #include "libGLESv2/renderer/BufferStorage11.h" |
michael@0 | 14 | #include "libGLESv2/renderer/ShaderExecutable11.h" |
michael@0 | 15 | #include "libGLESv2/ProgramBinary.h" |
michael@0 | 16 | #include "libGLESv2/Context.h" |
michael@0 | 17 | #include "libGLESv2/renderer/VertexDataManager.h" |
michael@0 | 18 | |
michael@0 | 19 | #include "third_party/murmurhash/MurmurHash3.h" |
michael@0 | 20 | |
michael@0 | 21 | namespace rx |
michael@0 | 22 | { |
michael@0 | 23 | |
michael@0 | 24 | const unsigned int InputLayoutCache::kMaxInputLayouts = 1024; |
michael@0 | 25 | |
michael@0 | 26 | InputLayoutCache::InputLayoutCache() : mInputLayoutMap(kMaxInputLayouts, hashInputLayout, compareInputLayouts) |
michael@0 | 27 | { |
michael@0 | 28 | mCounter = 0; |
michael@0 | 29 | mDevice = NULL; |
michael@0 | 30 | mDeviceContext = NULL; |
michael@0 | 31 | mCurrentIL = NULL; |
michael@0 | 32 | for (unsigned int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
michael@0 | 33 | { |
michael@0 | 34 | mCurrentBuffers[i] = -1; |
michael@0 | 35 | mCurrentVertexStrides[i] = -1; |
michael@0 | 36 | mCurrentVertexOffsets[i] = -1; |
michael@0 | 37 | } |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | InputLayoutCache::~InputLayoutCache() |
michael@0 | 41 | { |
michael@0 | 42 | clear(); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | void InputLayoutCache::initialize(ID3D11Device *device, ID3D11DeviceContext *context) |
michael@0 | 46 | { |
michael@0 | 47 | clear(); |
michael@0 | 48 | mDevice = device; |
michael@0 | 49 | mDeviceContext = context; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | void InputLayoutCache::clear() |
michael@0 | 53 | { |
michael@0 | 54 | for (InputLayoutMap::iterator i = mInputLayoutMap.begin(); i != mInputLayoutMap.end(); i++) |
michael@0 | 55 | { |
michael@0 | 56 | i->second.inputLayout->Release(); |
michael@0 | 57 | } |
michael@0 | 58 | mInputLayoutMap.clear(); |
michael@0 | 59 | markDirty(); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | void InputLayoutCache::markDirty() |
michael@0 | 63 | { |
michael@0 | 64 | mCurrentIL = NULL; |
michael@0 | 65 | for (unsigned int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
michael@0 | 66 | { |
michael@0 | 67 | mCurrentBuffers[i] = -1; |
michael@0 | 68 | mCurrentVertexStrides[i] = -1; |
michael@0 | 69 | mCurrentVertexOffsets[i] = -1; |
michael@0 | 70 | } |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS], |
michael@0 | 74 | gl::ProgramBinary *programBinary) |
michael@0 | 75 | { |
michael@0 | 76 | int sortedSemanticIndices[gl::MAX_VERTEX_ATTRIBS]; |
michael@0 | 77 | programBinary->sortAttributesByLayout(attributes, sortedSemanticIndices); |
michael@0 | 78 | |
michael@0 | 79 | if (!mDevice || !mDeviceContext) |
michael@0 | 80 | { |
michael@0 | 81 | ERR("InputLayoutCache is not initialized."); |
michael@0 | 82 | return GL_INVALID_OPERATION; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | InputLayoutKey ilKey = { 0 }; |
michael@0 | 86 | |
michael@0 | 87 | ID3D11Buffer *vertexBuffers[gl::MAX_VERTEX_ATTRIBS] = { NULL }; |
michael@0 | 88 | unsigned int vertexBufferSerials[gl::MAX_VERTEX_ATTRIBS] = { 0 }; |
michael@0 | 89 | UINT vertexStrides[gl::MAX_VERTEX_ATTRIBS] = { 0 }; |
michael@0 | 90 | UINT vertexOffsets[gl::MAX_VERTEX_ATTRIBS] = { 0 }; |
michael@0 | 91 | |
michael@0 | 92 | static const char* semanticName = "TEXCOORD"; |
michael@0 | 93 | |
michael@0 | 94 | for (unsigned int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
michael@0 | 95 | { |
michael@0 | 96 | if (attributes[i].active) |
michael@0 | 97 | { |
michael@0 | 98 | VertexBuffer11 *vertexBuffer = VertexBuffer11::makeVertexBuffer11(attributes[i].vertexBuffer); |
michael@0 | 99 | BufferStorage11 *bufferStorage = attributes[i].storage ? BufferStorage11::makeBufferStorage11(attributes[i].storage) : NULL; |
michael@0 | 100 | |
michael@0 | 101 | D3D11_INPUT_CLASSIFICATION inputClass = attributes[i].divisor > 0 ? D3D11_INPUT_PER_INSTANCE_DATA : D3D11_INPUT_PER_VERTEX_DATA; |
michael@0 | 102 | |
michael@0 | 103 | // Record the type of the associated vertex shader vector in our key |
michael@0 | 104 | // This will prevent mismatched vertex shaders from using the same input layout |
michael@0 | 105 | GLint attributeSize; |
michael@0 | 106 | programBinary->getActiveAttribute(ilKey.elementCount, 0, NULL, &attributeSize, &ilKey.glslElementType[ilKey.elementCount], NULL); |
michael@0 | 107 | |
michael@0 | 108 | ilKey.elements[ilKey.elementCount].SemanticName = semanticName; |
michael@0 | 109 | ilKey.elements[ilKey.elementCount].SemanticIndex = sortedSemanticIndices[i]; |
michael@0 | 110 | ilKey.elements[ilKey.elementCount].Format = attributes[i].attribute->mArrayEnabled ? vertexBuffer->getDXGIFormat(*attributes[i].attribute) : DXGI_FORMAT_R32G32B32A32_FLOAT; |
michael@0 | 111 | ilKey.elements[ilKey.elementCount].InputSlot = i; |
michael@0 | 112 | ilKey.elements[ilKey.elementCount].AlignedByteOffset = 0; |
michael@0 | 113 | ilKey.elements[ilKey.elementCount].InputSlotClass = inputClass; |
michael@0 | 114 | ilKey.elements[ilKey.elementCount].InstanceDataStepRate = attributes[i].divisor; |
michael@0 | 115 | ilKey.elementCount++; |
michael@0 | 116 | |
michael@0 | 117 | vertexBuffers[i] = bufferStorage ? bufferStorage->getBuffer() : vertexBuffer->getBuffer(); |
michael@0 | 118 | vertexBufferSerials[i] = bufferStorage ? bufferStorage->getSerial() : vertexBuffer->getSerial(); |
michael@0 | 119 | vertexStrides[i] = attributes[i].stride; |
michael@0 | 120 | vertexOffsets[i] = attributes[i].offset; |
michael@0 | 121 | } |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | ID3D11InputLayout *inputLayout = NULL; |
michael@0 | 125 | |
michael@0 | 126 | InputLayoutMap::iterator i = mInputLayoutMap.find(ilKey); |
michael@0 | 127 | if (i != mInputLayoutMap.end()) |
michael@0 | 128 | { |
michael@0 | 129 | inputLayout = i->second.inputLayout; |
michael@0 | 130 | i->second.lastUsedTime = mCounter++; |
michael@0 | 131 | } |
michael@0 | 132 | else |
michael@0 | 133 | { |
michael@0 | 134 | ShaderExecutable11 *shader = ShaderExecutable11::makeShaderExecutable11(programBinary->getVertexExecutable()); |
michael@0 | 135 | |
michael@0 | 136 | HRESULT result = mDevice->CreateInputLayout(ilKey.elements, ilKey.elementCount, shader->getFunction(), shader->getLength(), &inputLayout); |
michael@0 | 137 | if (FAILED(result)) |
michael@0 | 138 | { |
michael@0 | 139 | ERR("Failed to crate input layout, result: 0x%08x", result); |
michael@0 | 140 | return GL_INVALID_OPERATION; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | if (mInputLayoutMap.size() >= kMaxInputLayouts) |
michael@0 | 144 | { |
michael@0 | 145 | TRACE("Overflowed the limit of %u input layouts, removing the least recently used " |
michael@0 | 146 | "to make room.", kMaxInputLayouts); |
michael@0 | 147 | |
michael@0 | 148 | InputLayoutMap::iterator leastRecentlyUsed = mInputLayoutMap.begin(); |
michael@0 | 149 | for (InputLayoutMap::iterator i = mInputLayoutMap.begin(); i != mInputLayoutMap.end(); i++) |
michael@0 | 150 | { |
michael@0 | 151 | if (i->second.lastUsedTime < leastRecentlyUsed->second.lastUsedTime) |
michael@0 | 152 | { |
michael@0 | 153 | leastRecentlyUsed = i; |
michael@0 | 154 | } |
michael@0 | 155 | } |
michael@0 | 156 | leastRecentlyUsed->second.inputLayout->Release(); |
michael@0 | 157 | mInputLayoutMap.erase(leastRecentlyUsed); |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | InputLayoutCounterPair inputCounterPair; |
michael@0 | 161 | inputCounterPair.inputLayout = inputLayout; |
michael@0 | 162 | inputCounterPair.lastUsedTime = mCounter++; |
michael@0 | 163 | |
michael@0 | 164 | mInputLayoutMap.insert(std::make_pair(ilKey, inputCounterPair)); |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | if (inputLayout != mCurrentIL) |
michael@0 | 168 | { |
michael@0 | 169 | mDeviceContext->IASetInputLayout(inputLayout); |
michael@0 | 170 | mCurrentIL = inputLayout; |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | for (unsigned int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
michael@0 | 174 | { |
michael@0 | 175 | if (vertexBufferSerials[i] != mCurrentBuffers[i] || vertexStrides[i] != mCurrentVertexStrides[i] || |
michael@0 | 176 | vertexOffsets[i] != mCurrentVertexOffsets[i]) |
michael@0 | 177 | { |
michael@0 | 178 | mDeviceContext->IASetVertexBuffers(i, 1, &vertexBuffers[i], &vertexStrides[i], &vertexOffsets[i]); |
michael@0 | 179 | mCurrentBuffers[i] = vertexBufferSerials[i]; |
michael@0 | 180 | mCurrentVertexStrides[i] = vertexStrides[i]; |
michael@0 | 181 | mCurrentVertexOffsets[i] = vertexOffsets[i]; |
michael@0 | 182 | } |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | return GL_NO_ERROR; |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | std::size_t InputLayoutCache::hashInputLayout(const InputLayoutKey &inputLayout) |
michael@0 | 189 | { |
michael@0 | 190 | static const unsigned int seed = 0xDEADBEEF; |
michael@0 | 191 | |
michael@0 | 192 | std::size_t hash = 0; |
michael@0 | 193 | MurmurHash3_x86_32(&inputLayout, sizeof(InputLayoutKey), seed, &hash); |
michael@0 | 194 | return hash; |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | bool InputLayoutCache::compareInputLayouts(const InputLayoutKey &a, const InputLayoutKey &b) |
michael@0 | 198 | { |
michael@0 | 199 | return memcmp(&a, &b, sizeof(InputLayoutKey)) == 0; |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | } |