| 2177 | } |
| 2178 | |
| 2179 | static Pipeline* GetOrCreatePipeline(VkDevice vk_device, VkPipelineCache vk_pipeline_cache, VkSampleCountFlagBits vk_sample_count, |
| 2180 | const PipelineState pipelineState, PipelineCache& pipelineCache, |
| 2181 | VulkanProgram* program, VulkanRenderTarget* rt, VertexDeclaration** vertexDeclaration, uint32_t vertexDeclarationCount) |
| 2182 | { |
| 2183 | HashState64 pipeline_hash_state; |
| 2184 | dmHashInit64(&pipeline_hash_state, false); |
| 2185 | dmHashUpdateBuffer64(&pipeline_hash_state, &program->m_Hash, sizeof(program->m_Hash)); |
| 2186 | dmHashUpdateBuffer64(&pipeline_hash_state, &pipelineState, sizeof(pipelineState)); |
| 2187 | dmHashUpdateBuffer64(&pipeline_hash_state, &rt->m_Base.m_Id, sizeof(rt->m_Base.m_Id)); |
| 2188 | dmHashUpdateBuffer64(&pipeline_hash_state, &vk_sample_count, sizeof(vk_sample_count)); |
| 2189 | |
| 2190 | for (int i = 0; i < vertexDeclarationCount; ++i) |
| 2191 | { |
| 2192 | dmHashUpdateBuffer64(&pipeline_hash_state, &vertexDeclaration[i]->m_PipelineHash, sizeof(vertexDeclaration[i]->m_PipelineHash)); |
| 2193 | dmHashUpdateBuffer64(&pipeline_hash_state, &vertexDeclaration[i]->m_StepFunction, sizeof(vertexDeclaration[i]->m_StepFunction)); |
| 2194 | } |
| 2195 | |
| 2196 | uint64_t pipeline_hash = dmHashFinal64(&pipeline_hash_state); |
| 2197 | |
| 2198 | Pipeline* cached_pipeline = pipelineCache.Get(pipeline_hash); |
| 2199 | |
| 2200 | if (!cached_pipeline) |
| 2201 | { |
| 2202 | Pipeline new_pipeline; |
| 2203 | memset(&new_pipeline, 0, sizeof(new_pipeline)); |
| 2204 | |
| 2205 | VkRect2D vk_scissor; |
| 2206 | vk_scissor.extent = rt->m_Extent; |
| 2207 | vk_scissor.offset.x = 0; |
| 2208 | vk_scissor.offset.y = 0; |
| 2209 | |
| 2210 | VkResult res = CreateGraphicsPipeline(vk_device, vk_pipeline_cache, vk_scissor, vk_sample_count, pipelineState, program, vertexDeclaration, vertexDeclarationCount, rt, &new_pipeline); |
| 2211 | if (res == VK_ERROR_INITIALIZATION_FAILED) |
| 2212 | { |
| 2213 | dmLogError("Failed to create VkPipeline"); |
| 2214 | return 0; |
| 2215 | } |
| 2216 | CHECK_VK_ERROR(res); |
| 2217 | |
| 2218 | if (pipelineCache.Full()) |
| 2219 | { |
| 2220 | pipelineCache.SetCapacity(32, pipelineCache.Capacity() + 4); |
| 2221 | } |
| 2222 | |
| 2223 | pipelineCache.Put(pipeline_hash, new_pipeline); |
| 2224 | cached_pipeline = pipelineCache.Get(pipeline_hash); |
| 2225 | |
| 2226 | dmLogDebug("Created new VK Pipeline with hash %llu", (unsigned long long) pipeline_hash); |
| 2227 | } |
| 2228 | |
| 2229 | return cached_pipeline; |
| 2230 | } |
| 2231 | |
| 2232 | static void SetDeviceBuffer(VulkanContext* context, DeviceBuffer* buffer, uint32_t size, uint32_t offset, const void* data) |
| 2233 | { |
no test coverage detected