| 150 | } |
| 151 | |
| 152 | GPUVertexLayout* GPUVertexLayout::Get(const Elements& elements, bool explicitOffsets) |
| 153 | { |
| 154 | // Hash input layout |
| 155 | uint32 hash = explicitOffsets ? 131 : 0; |
| 156 | for (const VertexElement& element : elements) |
| 157 | { |
| 158 | CombineHash(hash, GetHash(element)); |
| 159 | } |
| 160 | |
| 161 | // Lookup existing cache |
| 162 | GPUVertexLayout* result; |
| 163 | if (!LayoutCache.TryGet(hash, result)) |
| 164 | { |
| 165 | result = GPUDevice::Instance->CreateVertexLayout(elements, explicitOffsets); |
| 166 | if (!result) |
| 167 | { |
| 168 | #if GPU_ENABLE_ASSERTION_LOW_LAYERS |
| 169 | for (auto& e : elements) |
| 170 | LOG(Error, " {}", e.ToString()); |
| 171 | #endif |
| 172 | LOG(Error, "Failed to create vertex layout"); |
| 173 | return nullptr; |
| 174 | } |
| 175 | if (!LayoutCache.Add(hash, result)) |
| 176 | { |
| 177 | // Other thread added the value |
| 178 | Delete(result); |
| 179 | bool found = LayoutCache.TryGet(hash, result); |
| 180 | ASSERT(found); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | return result; |
| 185 | } |
| 186 | |
| 187 | GPUVertexLayout* GPUVertexLayout::Get(const Span<GPUBuffer*>& vertexBuffers) |
| 188 | { |
no test coverage detected