anv_pipeline.c revision e10dc002e9544500a2247e49a132e18f994f34ee
1769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg/* 2769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * Copyright © 2015 Intel Corporation 3769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * 4769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * Permission is hereby granted, free of charge, to any person obtaining a 5769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * copy of this software and associated documentation files (the "Software"), 6769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * to deal in the Software without restriction, including without limitation 7769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * and/or sell copies of the Software, and to permit persons to whom the 9769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * Software is furnished to do so, subject to the following conditions: 10769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * 11769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * The above copyright notice and this permission notice (including the next 12769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * paragraph) shall be included in all copies or substantial portions of the 13769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * Software. 14769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * 15769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg * IN THE SOFTWARE. 22769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg */ 23769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg 24769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg#include <assert.h> 25769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg#include <stdbool.h> 26769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg#include <string.h> 27769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg#include <unistd.h> 28769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg#include <fcntl.h> 29769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg 302c2233e328341700b7bc5c574f9de21ab4e4116aChad Versace#include "anv_private.h" 31a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand#include "brw_nir.h" 32a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand#include "anv_nir.h" 33a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand#include "glsl/nir/nir_spirv.h" 34a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 35a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand/* Needed for SWIZZLE macros */ 36a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand#include "program/prog_instruction.h" 37769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg 38769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg// Shader functions 39769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg 405a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason EkstrandVkResult anv_CreateShaderModule( 415a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand VkDevice _device, 425a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand const VkShaderModuleCreateInfo* pCreateInfo, 43fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand const VkAllocationCallbacks* pAllocator, 447529e7ce860fc5dd64b93b53e5676136e0af3e4eChad Versace VkShaderModule* pShaderModule) 455a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand{ 465a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand ANV_FROM_HANDLE(anv_device, device, _device); 475a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand struct anv_shader_module *module; 485a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand 495a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO); 505a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand assert(pCreateInfo->flags == 0); 515a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand 52fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand module = anv_alloc2(&device->alloc, pAllocator, 53fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand sizeof(*module) + pCreateInfo->codeSize, 8, 54fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); 555a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand if (module == NULL) 565a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); 575a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand 58add99c4beb3fc08e21bae4cd2e288deb8a2c26b9Jason Ekstrand module->nir = NULL; 595a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand module->size = pCreateInfo->codeSize; 605a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand memcpy(module->data, pCreateInfo->pCode, module->size); 615a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand 626eb221c884a28786b68904faf950cf6f7881d9d9Jason Ekstrand *pShaderModule = anv_shader_module_to_handle(module); 635a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand 645a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand return VK_SUCCESS; 655a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand} 665a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand 6705a26a60c831f1dafc60a9f88b0d5cb2ca303d01Jason Ekstrandvoid anv_DestroyShaderModule( 688ae8e14ba7e5628f4bf3e396fe48f3b46649107bChad Versace VkDevice _device, 69fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand VkShaderModule _module, 70fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand const VkAllocationCallbacks* pAllocator) 718ae8e14ba7e5628f4bf3e396fe48f3b46649107bChad Versace{ 728ae8e14ba7e5628f4bf3e396fe48f3b46649107bChad Versace ANV_FROM_HANDLE(anv_device, device, _device); 738ae8e14ba7e5628f4bf3e396fe48f3b46649107bChad Versace ANV_FROM_HANDLE(anv_shader_module, module, _module); 748ae8e14ba7e5628f4bf3e396fe48f3b46649107bChad Versace 75fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand anv_free2(&device->alloc, pAllocator, module); 768ae8e14ba7e5628f4bf3e396fe48f3b46649107bChad Versace} 778ae8e14ba7e5628f4bf3e396fe48f3b46649107bChad Versace 78a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand#define SPIR_V_MAGIC_NUMBER 0x07230203 79a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 80a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandstatic const gl_shader_stage vk_shader_stage_to_mesa_stage[] = { 81a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand [VK_SHADER_STAGE_VERTEX] = MESA_SHADER_VERTEX, 82a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand [VK_SHADER_STAGE_TESS_CONTROL] = -1, 83a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand [VK_SHADER_STAGE_TESS_EVALUATION] = -1, 84a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand [VK_SHADER_STAGE_GEOMETRY] = MESA_SHADER_GEOMETRY, 85a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand [VK_SHADER_STAGE_FRAGMENT] = MESA_SHADER_FRAGMENT, 86a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand [VK_SHADER_STAGE_COMPUTE] = MESA_SHADER_COMPUTE, 87a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand}; 88a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 891b5c7e7ecd43d3526c0a6831ff6c1edfab4529afJason Ekstrandbool 901b5c7e7ecd43d3526c0a6831ff6c1edfab4529afJason Ekstrandanv_is_scalar_shader_stage(const struct brw_compiler *compiler, 911b5c7e7ecd43d3526c0a6831ff6c1edfab4529afJason Ekstrand VkShaderStage stage) 92a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand{ 93179fc4aae8f782453f0488e8dd508f9a01117376Jason Ekstrand return compiler->scalar_stage[vk_shader_stage_to_mesa_stage[stage]]; 94a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand} 95a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 96a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand/* Eventually, this will become part of anv_CreateShader. Unfortunately, 97a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * we can't do that yet because we don't have the ability to copy nir. 98a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 99a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandstatic nir_shader * 100a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandanv_shader_compile_to_nir(struct anv_device *device, 101e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand struct anv_shader_module *module, 102e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand const char *entrypoint_name, VkShaderStage vk_stage) 103a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand{ 104e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand if (strcmp(entrypoint_name, "main") != 0) { 105a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand anv_finishme("Multiple shaders per module not really supported"); 106a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 107a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 108a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand gl_shader_stage stage = vk_shader_stage_to_mesa_stage[vk_stage]; 109a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const struct brw_compiler *compiler = 110a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand device->instance->physicalDevice.compiler; 111a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const nir_shader_compiler_options *nir_options = 112a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand compiler->glsl_compiler_options[stage].NirOptions; 113a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 114a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand nir_shader *nir; 115e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand if (module->nir) { 116a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Some things such as our meta clear/blit code will give us a NIR 117a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * shader directly. In that case, we just ignore the SPIR-V entirely 118a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * and just use the NIR shader */ 119e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand nir = module->nir; 120a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand nir->options = nir_options; 121a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } else { 122e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand uint32_t *spirv = (uint32_t *) module->data; 123a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand assert(spirv[0] == SPIR_V_MAGIC_NUMBER); 124e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand assert(module->size % 4 == 0); 125a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 126e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand nir = spirv_to_nir(spirv, module->size / 4, stage, nir_options); 127a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 128a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand nir_validate_shader(nir); 129a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 1308aba8cf513a0856415e2389b729b76417cd89584Jason Ekstrand /* Vulkan uses the separate-shader linking model */ 1318aba8cf513a0856415e2389b729b76417cd89584Jason Ekstrand nir->info.separate_shader = true; 1328aba8cf513a0856415e2389b729b76417cd89584Jason Ekstrand 133a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Make sure the provided shader has exactly one entrypoint and that the 134a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * name matches the name that came in from the VkShader. 135a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 136a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand nir_function_impl *entrypoint = NULL; 137a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand nir_foreach_overload(nir, overload) { 138e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand if (strcmp(entrypoint_name, overload->function->name) == 0 && 139a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand overload->impl) { 140a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand assert(entrypoint == NULL); 141a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand entrypoint = overload->impl; 142a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 143a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 144a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand assert(entrypoint != NULL); 145a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 146179fc4aae8f782453f0488e8dd508f9a01117376Jason Ekstrand nir = brw_preprocess_nir(nir, compiler->scalar_stage[stage]); 147a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 148a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand nir_shader_gather_info(nir, entrypoint); 149a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 150a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand return nir; 151a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand} 152cb57bff36c5b8f449f4f9738e71d5359d9090fc8Chad Versace 1535a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason EkstrandVkResult anv_CreatePipelineCache( 1545a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand VkDevice device, 1555a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand const VkPipelineCacheCreateInfo* pCreateInfo, 156fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand const VkAllocationCallbacks* pAllocator, 1575a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand VkPipelineCache* pPipelineCache) 1585a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand{ 1593db43e8f3e60f8dc746eb4ab2e86f6b1b32d248aJason Ekstrand *pPipelineCache = (VkPipelineCache)1; 1605a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand 1615a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand stub_return(VK_SUCCESS); 1625a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand} 1635a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand 16405a26a60c831f1dafc60a9f88b0d5cb2ca303d01Jason Ekstrandvoid anv_DestroyPipelineCache( 165114015321eb3998e2814687e3584994bc061a33bChad Versace VkDevice _device, 166fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand VkPipelineCache _cache, 167fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand const VkAllocationCallbacks* pAllocator) 168114015321eb3998e2814687e3584994bc061a33bChad Versace{ 169114015321eb3998e2814687e3584994bc061a33bChad Versace} 170114015321eb3998e2814687e3584994bc061a33bChad Versace 1715a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason EkstrandVkResult anv_GetPipelineCacheData( 1725a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand VkDevice device, 1735a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand VkPipelineCache pipelineCache, 174c30a0218202d65f4ceaa8d9c0d2afc8b2d0c0621Jason Ekstrand size_t* pDataSize, 1755a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand void* pData) 1765a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand{ 1775a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand stub_return(VK_UNSUPPORTED); 1785a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand} 1795a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand 1805a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason EkstrandVkResult anv_MergePipelineCaches( 1815a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand VkDevice device, 1825a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand VkPipelineCache destCache, 1835a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand uint32_t srcCacheCount, 1845a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand const VkPipelineCache* pSrcCaches) 1855a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand{ 1865a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand stub_return(VK_UNSUPPORTED); 1875a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand} 1885a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand 18905a26a60c831f1dafc60a9f88b0d5cb2ca303d01Jason Ekstrandvoid anv_DestroyPipeline( 1906e5ab5cf1bdac9292b512bbbe10da44558fe1bc0Chad Versace VkDevice _device, 191fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand VkPipeline _pipeline, 192fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand const VkAllocationCallbacks* pAllocator) 1936e5ab5cf1bdac9292b512bbbe10da44558fe1bc0Chad Versace{ 1946e5ab5cf1bdac9292b512bbbe10da44558fe1bc0Chad Versace ANV_FROM_HANDLE(anv_device, device, _device); 1956e5ab5cf1bdac9292b512bbbe10da44558fe1bc0Chad Versace ANV_FROM_HANDLE(anv_pipeline, pipeline, _pipeline); 1966e5ab5cf1bdac9292b512bbbe10da44558fe1bc0Chad Versace 197fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand anv_reloc_list_finish(&pipeline->batch_relocs, 198fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand pAllocator ? pAllocator : &device->alloc); 1996e5ab5cf1bdac9292b512bbbe10da44558fe1bc0Chad Versace anv_state_stream_finish(&pipeline->program_stream); 20091bc4e7cec4098000f3d9a265e7db7907a686e5aJason Ekstrand if (pipeline->blend_state.map) 20191bc4e7cec4098000f3d9a265e7db7907a686e5aJason Ekstrand anv_state_pool_free(&device->dynamic_state_pool, pipeline->blend_state); 202fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand anv_free2(&device->alloc, pAllocator, pipeline); 2036e5ab5cf1bdac9292b512bbbe10da44558fe1bc0Chad Versace} 2046e5ab5cf1bdac9292b512bbbe10da44558fe1bc0Chad Versace 2059c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsbergstatic const uint32_t vk_to_gen_primitive_type[] = { 2066a8a542610243f32ee20989778af06d66d7b5b1aJason Ekstrand [VK_PRIMITIVE_TOPOLOGY_POINT_LIST] = _3DPRIM_POINTLIST, 2076a8a542610243f32ee20989778af06d66d7b5b1aJason Ekstrand [VK_PRIMITIVE_TOPOLOGY_LINE_LIST] = _3DPRIM_LINELIST, 2086a8a542610243f32ee20989778af06d66d7b5b1aJason Ekstrand [VK_PRIMITIVE_TOPOLOGY_LINE_STRIP] = _3DPRIM_LINESTRIP, 2096a8a542610243f32ee20989778af06d66d7b5b1aJason Ekstrand [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST] = _3DPRIM_TRILIST, 2106a8a542610243f32ee20989778af06d66d7b5b1aJason Ekstrand [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP] = _3DPRIM_TRISTRIP, 2116a8a542610243f32ee20989778af06d66d7b5b1aJason Ekstrand [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN] = _3DPRIM_TRIFAN, 2126a8a542610243f32ee20989778af06d66d7b5b1aJason Ekstrand [VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY] = _3DPRIM_LINELIST_ADJ, 2136a8a542610243f32ee20989778af06d66d7b5b1aJason Ekstrand [VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY] = _3DPRIM_LINESTRIP_ADJ, 2146a8a542610243f32ee20989778af06d66d7b5b1aJason Ekstrand [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY] = _3DPRIM_TRILIST_ADJ, 2156a8a542610243f32ee20989778af06d66d7b5b1aJason Ekstrand [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY] = _3DPRIM_TRISTRIP_ADJ, 2166a8a542610243f32ee20989778af06d66d7b5b1aJason Ekstrand/* [VK_PRIMITIVE_TOPOLOGY_PATCH_LIST] = _3DPRIM_PATCHLIST_1 */ 2179c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg}; 2189c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg 2191a52bc30390d56493ea2d0a950d8b9f01519ed24Jason Ekstrandstatic void 220a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandpopulate_sampler_prog_key(const struct brw_device_info *devinfo, 221a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand struct brw_sampler_prog_key_data *key) 222a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand{ 223a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* XXX: Handle texture swizzle on HSW- */ 224a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand for (int i = 0; i < MAX_SAMPLERS; i++) { 225a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Assume color sampler, no swizzling. (Works for BDW+) */ 226a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand key->swizzles[i] = SWIZZLE_XYZW; 227a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 228a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand} 229a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 230a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandstatic void 231a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandpopulate_vs_prog_key(const struct brw_device_info *devinfo, 232a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand struct brw_vs_prog_key *key) 233a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand{ 234a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand memset(key, 0, sizeof(*key)); 235a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 236a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand populate_sampler_prog_key(devinfo, &key->tex); 237a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 238a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* XXX: Handle vertex input work-arounds */ 239a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 240a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* XXX: Handle sampler_prog_key */ 241a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand} 242a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 243a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandstatic void 244d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrandpopulate_gs_prog_key(const struct brw_device_info *devinfo, 245d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand struct brw_gs_prog_key *key) 246d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand{ 247d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand memset(key, 0, sizeof(*key)); 248d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand 249d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand populate_sampler_prog_key(devinfo, &key->tex); 250d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand} 251d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand 252d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrandstatic void 253a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandpopulate_wm_prog_key(const struct brw_device_info *devinfo, 254a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const VkGraphicsPipelineCreateInfo *info, 255a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand struct brw_wm_prog_key *key) 256a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand{ 257a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand ANV_FROM_HANDLE(anv_render_pass, render_pass, info->renderPass); 258a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 259a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand memset(key, 0, sizeof(*key)); 260a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 261a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand populate_sampler_prog_key(devinfo, &key->tex); 262a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 26337b6afb3d96a7bc68129a312c77dfaf94121a70fJason Ekstrand /* TODO: Fill out key->input_slots_valid */ 26437b6afb3d96a7bc68129a312c77dfaf94121a70fJason Ekstrand 265a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Vulkan doesn't specify a default */ 266a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand key->high_quality_derivatives = false; 267a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 268a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* XXX Vulkan doesn't appear to specify */ 269a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand key->clamp_fragment_color = false; 270a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 27172d99f8a40b4c00983952265323b96e61ce45c6bJason Ekstrand /* Vulkan always specifies upper-left coordinates */ 272a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand key->drawable_height = 0; 27327d868500aba43e88ef86f9f68aa729289569e75Jason Ekstrand key->render_to_fbo = false; 274a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 275a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand key->nr_color_regions = render_pass->subpasses[info->subpass].color_count; 276a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 277a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand key->replicate_alpha = key->nr_color_regions > 1 && 2789fa6e328ebac4616148a23a7a4fbe7ed25ec315fJason Ekstrand info->pMultisampleState && 2799fa6e328ebac4616148a23a7a4fbe7ed25ec315fJason Ekstrand info->pMultisampleState->alphaToCoverageEnable; 280a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 2817f2284063df569df40f68074833f1518005d348dJason Ekstrand if (info->pMultisampleState && info->pMultisampleState->rasterizationSamples > 1) { 282a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* We should probably pull this out of the shader, but it's fairly 283a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * harmless to compute it and then let dead-code take care of it. 284a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 285a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand key->persample_shading = info->pMultisampleState->sampleShadingEnable; 286a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (key->persample_shading) 2877f2284063df569df40f68074833f1518005d348dJason Ekstrand key->persample_2x = info->pMultisampleState->rasterizationSamples == 2; 288a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 289a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand key->compute_pos_offset = info->pMultisampleState->sampleShadingEnable; 290a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand key->compute_sample_id = info->pMultisampleState->sampleShadingEnable; 291a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 292a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand} 293a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 294a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandstatic void 295a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandpopulate_cs_prog_key(const struct brw_device_info *devinfo, 296a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand struct brw_cs_prog_key *key) 297a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand{ 298a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand memset(key, 0, sizeof(*key)); 299a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 300a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand populate_sampler_prog_key(devinfo, &key->tex); 301a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand} 302a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 303a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandstatic nir_shader * 304a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandanv_pipeline_compile(struct anv_pipeline *pipeline, 305e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand struct anv_shader_module *module, 306e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand const char *entrypoint, 307a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand VkShaderStage stage, 308a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand struct brw_stage_prog_data *prog_data) 309a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand{ 310a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const struct brw_compiler *compiler = 311a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->device->instance->physicalDevice.compiler; 312a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 313e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand nir_shader *nir = anv_shader_compile_to_nir(pipeline->device, 314e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand module, entrypoint, stage); 315a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (nir == NULL) 316a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand return NULL; 317a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 3181b5c7e7ecd43d3526c0a6831ff6c1edfab4529afJason Ekstrand anv_nir_lower_push_constants(nir, anv_is_scalar_shader_stage(compiler, stage)); 319a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 320a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Figure out the number of parameters */ 321a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand prog_data->nr_params = 0; 322a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 3233883728730f293b763a5641560375b18d4f97782Jason Ekstrand if (nir->num_uniforms > 0) { 324a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* If the shader uses any push constants at all, we'll just give 325a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * them the maximum possible number 326a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 327a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand prog_data->nr_params += MAX_PUSH_CONSTANTS_SIZE / sizeof(float); 328a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 329a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 330a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (pipeline->layout && pipeline->layout->stage[stage].has_dynamic_offsets) 331612e35b2c65c99773b73e53d0e6fd112b1a7431fJason Ekstrand prog_data->nr_params += MAX_DYNAMIC_BUFFERS * 2; 332a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 333a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (prog_data->nr_params > 0) { 334fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand /* XXX: I think we're leaking this */ 335a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand prog_data->param = (const gl_constant_value **) 336fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand malloc(prog_data->nr_params * sizeof(gl_constant_value *)); 337a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 338a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* We now set the param values to be offsets into a 339a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * anv_push_constant_data structure. Since the compiler doesn't 340a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * actually dereference any of the gl_constant_value pointers in the 341a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * params array, it doesn't really matter what we put here. 342a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 343a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand struct anv_push_constants *null_data = NULL; 3443883728730f293b763a5641560375b18d4f97782Jason Ekstrand if (nir->num_uniforms > 0) { 345a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Fill out the push constants section of the param array */ 346a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand for (unsigned i = 0; i < MAX_PUSH_CONSTANTS_SIZE / sizeof(float); i++) 347a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand prog_data->param[i] = (const gl_constant_value *) 348a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand &null_data->client_data[i * sizeof(float)]; 349a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 350a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 351a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 352a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Set up dynamic offsets */ 353a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand anv_nir_apply_dynamic_offsets(pipeline, nir, prog_data); 354a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 355a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Apply the actual pipeline layout to UBOs, SSBOs, and textures */ 356a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand anv_nir_apply_pipeline_layout(nir, pipeline->layout); 357a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 358a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* All binding table offsets provided by apply_pipeline_layout() are 359a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * relative to the start of the bindint table (plus MAX_RTS for VS). 360a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 361a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned bias = stage == VK_SHADER_STAGE_FRAGMENT ? MAX_RTS : 0; 362a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand prog_data->binding_table.size_bytes = 0; 363a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand prog_data->binding_table.texture_start = bias; 364a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand prog_data->binding_table.ubo_start = bias; 365104525c33b154ed31cfedea2100b275abbc7a739Jason Ekstrand prog_data->binding_table.ssbo_start = bias; 366a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand prog_data->binding_table.image_start = bias; 367a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 368a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Finish the optimization and compilation process */ 369179fc4aae8f782453f0488e8dd508f9a01117376Jason Ekstrand nir = brw_lower_nir(nir, &pipeline->device->info, NULL, 3701b5c7e7ecd43d3526c0a6831ff6c1edfab4529afJason Ekstrand anv_is_scalar_shader_stage(compiler, stage)); 371a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 372a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* nir_lower_io will only handle the push constants; we need to set this 373a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * to the full number of possible uniforms. 374a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 375a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand nir->num_uniforms = prog_data->nr_params; 376a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 377a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand return nir; 378a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand} 379a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 380a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandstatic uint32_t 381a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandanv_pipeline_upload_kernel(struct anv_pipeline *pipeline, 382a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const void *data, size_t size) 383a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand{ 384a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand struct anv_state state = 385a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand anv_state_stream_alloc(&pipeline->program_stream, size, 64); 386a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 387a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand assert(size < pipeline->program_stream.block_pool->block_size); 388a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 389a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand memcpy(state.map, data, size); 390a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 391a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand return state.offset; 392a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand} 393a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandstatic void 394a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandanv_pipeline_add_compiled_stage(struct anv_pipeline *pipeline, 395a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand VkShaderStage stage, 396a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand struct brw_stage_prog_data *prog_data) 397a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand{ 398a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand struct brw_device_info *devinfo = &pipeline->device->info; 399a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand uint32_t max_threads[] = { 400a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand [VK_SHADER_STAGE_VERTEX] = devinfo->max_vs_threads, 401a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand [VK_SHADER_STAGE_TESS_CONTROL] = 0, 402a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand [VK_SHADER_STAGE_TESS_EVALUATION] = 0, 403a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand [VK_SHADER_STAGE_GEOMETRY] = devinfo->max_gs_threads, 404a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand [VK_SHADER_STAGE_FRAGMENT] = devinfo->max_wm_threads, 405a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand [VK_SHADER_STAGE_COMPUTE] = devinfo->max_cs_threads, 406a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand }; 407a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 408a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->prog_data[stage] = prog_data; 409a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->active_stages |= 1 << stage; 410a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->scratch_start[stage] = pipeline->total_scratch; 411a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->total_scratch = 412a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand align_u32(pipeline->total_scratch, 1024) + 413a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand prog_data->total_scratch * max_threads[stage]; 414a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand} 415a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 416a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandstatic VkResult 417a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandanv_pipeline_compile_vs(struct anv_pipeline *pipeline, 418a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const VkGraphicsPipelineCreateInfo *info, 419e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand struct anv_shader_module *module, 420e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand const char *entrypoint) 421a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand{ 422a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const struct brw_compiler *compiler = 423a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->device->instance->physicalDevice.compiler; 424a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand struct brw_vs_prog_data *prog_data = &pipeline->vs_prog_data; 425a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand struct brw_vs_prog_key key; 426a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 427a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand populate_vs_prog_key(&pipeline->device->info, &key); 428a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 429a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* TODO: Look up shader in cache */ 430a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 431a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand memset(prog_data, 0, sizeof(*prog_data)); 432a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 433e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand nir_shader *nir = anv_pipeline_compile(pipeline, module, entrypoint, 434a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand VK_SHADER_STAGE_VERTEX, 435a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand &prog_data->base.base); 436a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (nir == NULL) 437a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); 438a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 439a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand void *mem_ctx = ralloc_context(NULL); 440a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 441e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand if (module->nir == NULL) 442a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand ralloc_steal(mem_ctx, nir); 443a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 444a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand prog_data->inputs_read = nir->info.inputs_read; 445a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->writes_point_size = nir->info.outputs_written & VARYING_SLOT_PSIZ; 446a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 447a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand brw_compute_vue_map(&pipeline->device->info, 448a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand &prog_data->base.vue_map, 449a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand nir->info.outputs_written, 450760c4b894db983c42e0aca60af252594af808b2aJason Ekstrand nir->info.separate_shader); 451a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 452a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned code_size; 453a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const unsigned *shader_code = 454a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand brw_compile_vs(compiler, NULL, mem_ctx, &key, prog_data, nir, 455a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand NULL, false, -1, &code_size, NULL); 456a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (shader_code == NULL) { 457a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand ralloc_free(mem_ctx); 458a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); 459a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 460a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 461a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const uint32_t offset = 462a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand anv_pipeline_upload_kernel(pipeline, shader_code, code_size); 463a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (prog_data->base.dispatch_mode == DISPATCH_MODE_SIMD8) { 464a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->vs_simd8 = offset; 465a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->vs_vec4 = NO_KERNEL; 466a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } else { 467a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->vs_simd8 = NO_KERNEL; 468a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->vs_vec4 = offset; 469a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 470a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 471a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand ralloc_free(mem_ctx); 472a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 473a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand anv_pipeline_add_compiled_stage(pipeline, VK_SHADER_STAGE_VERTEX, 474a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand &prog_data->base.base); 475a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 476a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand return VK_SUCCESS; 477a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand} 478a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 479a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandstatic VkResult 480d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrandanv_pipeline_compile_gs(struct anv_pipeline *pipeline, 481d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand const VkGraphicsPipelineCreateInfo *info, 482e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand struct anv_shader_module *module, 483e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand const char *entrypoint) 484d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand{ 485d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand const struct brw_compiler *compiler = 486d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand pipeline->device->instance->physicalDevice.compiler; 487d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand struct brw_gs_prog_data *prog_data = &pipeline->gs_prog_data; 488d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand struct brw_gs_prog_key key; 489d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand 490d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand populate_gs_prog_key(&pipeline->device->info, &key); 491d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand 492d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand /* TODO: Look up shader in cache */ 493d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand 494d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand memset(prog_data, 0, sizeof(*prog_data)); 495d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand 496e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand nir_shader *nir = anv_pipeline_compile(pipeline, module, entrypoint, 497d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand VK_SHADER_STAGE_GEOMETRY, 498d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand &prog_data->base.base); 499d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand if (nir == NULL) 500d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); 501d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand 502d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand void *mem_ctx = ralloc_context(NULL); 503d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand 504e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand if (module->nir == NULL) 505d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand ralloc_steal(mem_ctx, nir); 506d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand 507d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand brw_compute_vue_map(&pipeline->device->info, 508d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand &prog_data->base.vue_map, 509d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand nir->info.outputs_written, 510760c4b894db983c42e0aca60af252594af808b2aJason Ekstrand nir->info.separate_shader); 511d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand 512d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand unsigned code_size; 513d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand const unsigned *shader_code = 514d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand brw_compile_gs(compiler, NULL, mem_ctx, &key, prog_data, nir, 515d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand NULL, -1, &code_size, NULL); 516d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand if (shader_code == NULL) { 517d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand ralloc_free(mem_ctx); 518d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); 519d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand } 520d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand 521d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand /* TODO: SIMD8 GS */ 522d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand pipeline->gs_vec4 = 523d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand anv_pipeline_upload_kernel(pipeline, shader_code, code_size); 524d0e8c78407c9b259da55c8b203b96deadab6187eJason Ekstrand pipeline->gs_vertex_count = nir->info.gs.vertices_in; 525d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand 526d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand ralloc_free(mem_ctx); 527d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand 528d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand anv_pipeline_add_compiled_stage(pipeline, VK_SHADER_STAGE_GEOMETRY, 529d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand &prog_data->base.base); 530d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand 531d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand return VK_SUCCESS; 532d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand} 533d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand 534d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrandstatic VkResult 535a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandanv_pipeline_compile_fs(struct anv_pipeline *pipeline, 536a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const VkGraphicsPipelineCreateInfo *info, 537e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand struct anv_shader_module *module, 538e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand const char *entrypoint) 539a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand{ 540a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const struct brw_compiler *compiler = 541a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->device->instance->physicalDevice.compiler; 542a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand struct brw_wm_prog_data *prog_data = &pipeline->wm_prog_data; 543a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand struct brw_wm_prog_key key; 544a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 545a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand populate_wm_prog_key(&pipeline->device->info, info, &key); 546a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 547a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (pipeline->use_repclear) 548a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand key.nr_color_regions = 1; 549a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 550a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* TODO: Look up shader in cache */ 551a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 552a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand memset(prog_data, 0, sizeof(*prog_data)); 553a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 554a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand prog_data->binding_table.render_target_start = 0; 555a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 556e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand nir_shader *nir = anv_pipeline_compile(pipeline, module, entrypoint, 557a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand VK_SHADER_STAGE_FRAGMENT, 558a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand &prog_data->base); 559a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (nir == NULL) 560a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); 561a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 562a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand void *mem_ctx = ralloc_context(NULL); 563a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 564e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand if (module->nir == NULL) 565a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand ralloc_steal(mem_ctx, nir); 566a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 567a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned code_size; 568a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const unsigned *shader_code = 569a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand brw_compile_fs(compiler, NULL, mem_ctx, &key, prog_data, nir, 570a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand NULL, -1, -1, pipeline->use_repclear, &code_size, NULL); 571a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (shader_code == NULL) { 572a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand ralloc_free(mem_ctx); 573a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); 574a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 575a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 576a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand uint32_t offset = anv_pipeline_upload_kernel(pipeline, 577a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand shader_code, code_size); 578a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (prog_data->no_8) 579a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->ps_simd8 = NO_KERNEL; 580a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand else 581a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->ps_simd8 = offset; 582a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 583a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (prog_data->no_8 || prog_data->prog_offset_16) { 584a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->ps_simd16 = offset + prog_data->prog_offset_16; 585a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } else { 586a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->ps_simd16 = NO_KERNEL; 587a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 588a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 589a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->ps_ksp2 = 0; 590a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->ps_grf_start2 = 0; 591a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (pipeline->ps_simd8 != NO_KERNEL) { 592a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->ps_ksp0 = pipeline->ps_simd8; 593a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->ps_grf_start0 = prog_data->base.dispatch_grf_start_reg; 594a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (pipeline->ps_simd16 != NO_KERNEL) { 595a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->ps_ksp2 = pipeline->ps_simd16; 596a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->ps_grf_start2 = prog_data->dispatch_grf_start_reg_16; 597a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 598a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } else if (pipeline->ps_simd16 != NO_KERNEL) { 599a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->ps_ksp0 = pipeline->ps_simd16; 600a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->ps_grf_start0 = prog_data->dispatch_grf_start_reg_16; 601a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 602a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 603a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand ralloc_free(mem_ctx); 604a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 605a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand anv_pipeline_add_compiled_stage(pipeline, VK_SHADER_STAGE_FRAGMENT, 606a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand &prog_data->base); 607a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 608a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand return VK_SUCCESS; 609a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand} 610a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 611a71e614d33e8d869bbaced8948349a7180783ab7Jason EkstrandVkResult 612a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandanv_pipeline_compile_cs(struct anv_pipeline *pipeline, 613a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const VkComputePipelineCreateInfo *info, 614e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand struct anv_shader_module *module, 615e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand const char *entrypoint) 616a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand{ 617a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const struct brw_compiler *compiler = 618a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->device->instance->physicalDevice.compiler; 619a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand struct brw_cs_prog_data *prog_data = &pipeline->cs_prog_data; 620a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand struct brw_cs_prog_key key; 621a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 622a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand populate_cs_prog_key(&pipeline->device->info, &key); 623a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 624a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* TODO: Look up shader in cache */ 625a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 626a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand memset(prog_data, 0, sizeof(*prog_data)); 627a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 628e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand nir_shader *nir = anv_pipeline_compile(pipeline, module, entrypoint, 629a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand VK_SHADER_STAGE_COMPUTE, 630a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand &prog_data->base); 631a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (nir == NULL) 632a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); 633a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 634a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand void *mem_ctx = ralloc_context(NULL); 635a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 636e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand if (module->nir == NULL) 637a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand ralloc_steal(mem_ctx, nir); 638a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 639a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned code_size; 640a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const unsigned *shader_code = 641a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand brw_compile_cs(compiler, NULL, mem_ctx, &key, prog_data, nir, 642a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand -1, &code_size, NULL); 643a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (shader_code == NULL) { 644a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand ralloc_free(mem_ctx); 645a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); 646a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 647a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 648a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->cs_simd = anv_pipeline_upload_kernel(pipeline, 649a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand shader_code, code_size); 650a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand ralloc_free(mem_ctx); 651a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 652a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand anv_pipeline_add_compiled_stage(pipeline, VK_SHADER_STAGE_COMPUTE, 653a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand &prog_data->base); 654a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 655a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand return VK_SUCCESS; 656a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand} 657a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 658a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandstatic const int gen8_push_size = 32 * 1024; 659a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 660a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandstatic void 661a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandgen7_compute_urb_partition(struct anv_pipeline *pipeline) 662a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand{ 663a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand const struct brw_device_info *devinfo = &pipeline->device->info; 664a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand bool vs_present = pipeline->active_stages & VK_SHADER_STAGE_VERTEX_BIT; 665a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned vs_size = vs_present ? pipeline->vs_prog_data.base.urb_entry_size : 1; 666a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned vs_entry_size_bytes = vs_size * 64; 667a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand bool gs_present = pipeline->active_stages & VK_SHADER_STAGE_GEOMETRY_BIT; 668a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned gs_size = gs_present ? pipeline->gs_prog_data.base.urb_entry_size : 1; 669a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned gs_entry_size_bytes = gs_size * 64; 670a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 671a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* From p35 of the Ivy Bridge PRM (section 1.7.1: 3DSTATE_URB_GS): 672a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * 673a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * VS Number of URB Entries must be divisible by 8 if the VS URB Entry 674a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * Allocation Size is less than 9 512-bit URB entries. 675a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * 676a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * Similar text exists for GS. 677a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 678a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned vs_granularity = (vs_size < 9) ? 8 : 1; 679a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned gs_granularity = (gs_size < 9) ? 8 : 1; 680a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 681a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* URB allocations must be done in 8k chunks. */ 682a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned chunk_size_bytes = 8192; 683a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 684a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Determine the size of the URB in chunks. */ 685a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned urb_chunks = devinfo->urb.size * 1024 / chunk_size_bytes; 686a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 687a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Reserve space for push constants */ 688a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned push_constant_bytes = gen8_push_size; 689a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned push_constant_chunks = 690a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand push_constant_bytes / chunk_size_bytes; 691a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 692a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Initially, assign each stage the minimum amount of URB space it needs, 693a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * and make a note of how much additional space it "wants" (the amount of 694a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * additional space it could actually make use of). 695a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 696a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 697a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* VS has a lower limit on the number of URB entries */ 698a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned vs_chunks = 699a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand ALIGN(devinfo->urb.min_vs_entries * vs_entry_size_bytes, 700a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand chunk_size_bytes) / chunk_size_bytes; 701a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned vs_wants = 702a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand ALIGN(devinfo->urb.max_vs_entries * vs_entry_size_bytes, 703a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand chunk_size_bytes) / chunk_size_bytes - vs_chunks; 704a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 705a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned gs_chunks = 0; 706a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned gs_wants = 0; 707a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (gs_present) { 708a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* There are two constraints on the minimum amount of URB space we can 709a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * allocate: 710a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * 711a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * (1) We need room for at least 2 URB entries, since we always operate 712a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * the GS in DUAL_OBJECT mode. 713a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * 714a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * (2) We can't allocate less than nr_gs_entries_granularity. 715a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 716a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand gs_chunks = ALIGN(MAX2(gs_granularity, 2) * gs_entry_size_bytes, 717a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand chunk_size_bytes) / chunk_size_bytes; 718a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand gs_wants = 719a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand ALIGN(devinfo->urb.max_gs_entries * gs_entry_size_bytes, 720a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand chunk_size_bytes) / chunk_size_bytes - gs_chunks; 721a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 722a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 723a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* There should always be enough URB space to satisfy the minimum 724a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * requirements of each stage. 725a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 726a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned total_needs = push_constant_chunks + vs_chunks + gs_chunks; 727a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand assert(total_needs <= urb_chunks); 728a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 729a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Mete out remaining space (if any) in proportion to "wants". */ 730a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned total_wants = vs_wants + gs_wants; 731a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned remaining_space = urb_chunks - total_needs; 732a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (remaining_space > total_wants) 733a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand remaining_space = total_wants; 734a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (remaining_space > 0) { 735a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned vs_additional = (unsigned) 736a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand round(vs_wants * (((double) remaining_space) / total_wants)); 737a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand vs_chunks += vs_additional; 738a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand remaining_space -= vs_additional; 739a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand gs_chunks += remaining_space; 740a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 741a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 742a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Sanity check that we haven't over-allocated. */ 743a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand assert(push_constant_chunks + vs_chunks + gs_chunks <= urb_chunks); 744a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 745a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Finally, compute the number of entries that can fit in the space 746a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * allocated to each stage. 747a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 748a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned nr_vs_entries = vs_chunks * chunk_size_bytes / vs_entry_size_bytes; 749a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand unsigned nr_gs_entries = gs_chunks * chunk_size_bytes / gs_entry_size_bytes; 750a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 751a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Since we rounded up when computing *_wants, this may be slightly more 752a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * than the maximum allowed amount, so correct for that. 753a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 754a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand nr_vs_entries = MIN2(nr_vs_entries, devinfo->urb.max_vs_entries); 755a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand nr_gs_entries = MIN2(nr_gs_entries, devinfo->urb.max_gs_entries); 756a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 757a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Ensure that we program a multiple of the granularity. */ 758a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand nr_vs_entries = ROUND_DOWN_TO(nr_vs_entries, vs_granularity); 759a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand nr_gs_entries = ROUND_DOWN_TO(nr_gs_entries, gs_granularity); 760a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 761a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Finally, sanity check to make sure we have at least the minimum number 762a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * of entries needed for each stage. 763a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 764a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand assert(nr_vs_entries >= devinfo->urb.min_vs_entries); 765a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (gs_present) 766a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand assert(nr_gs_entries >= 2); 767a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 768a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Lay out the URB in the following order: 769a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * - push constants 770a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * - VS 771a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * - GS 772a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 773a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->urb.vs_start = push_constant_chunks; 774a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->urb.vs_size = vs_size; 775a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->urb.nr_vs_entries = nr_vs_entries; 776a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 777a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->urb.gs_start = push_constant_chunks + vs_chunks; 778a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->urb.gs_size = gs_size; 779a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->urb.nr_gs_entries = nr_gs_entries; 780a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand} 781a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 782a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrandstatic void 7831a52bc30390d56493ea2d0a950d8b9f01519ed24Jason Ekstrandanv_pipeline_init_dynamic_state(struct anv_pipeline *pipeline, 7841a52bc30390d56493ea2d0a950d8b9f01519ed24Jason Ekstrand const VkGraphicsPipelineCreateInfo *pCreateInfo) 7851a52bc30390d56493ea2d0a950d8b9f01519ed24Jason Ekstrand{ 7864d4e559b6a26d2942c2a24cc81588adc2482f415Chad Versace anv_cmd_dirty_mask_t states = ANV_CMD_DIRTY_DYNAMIC_ALL; 7872484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace ANV_FROM_HANDLE(anv_render_pass, pass, pCreateInfo->renderPass); 7882484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace struct anv_subpass *subpass = &pass->subpasses[pCreateInfo->subpass]; 7892484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace 7902484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace pipeline->dynamic_state = default_dynamic_state; 7911a52bc30390d56493ea2d0a950d8b9f01519ed24Jason Ekstrand 792368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand if (pCreateInfo->pDynamicState) { 793368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand /* Remove all of the states that are marked as dynamic */ 794368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand uint32_t count = pCreateInfo->pDynamicState->dynamicStateCount; 795368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand for (uint32_t s = 0; s < count; s++) 796368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand states &= ~(1 << pCreateInfo->pDynamicState->pDynamicStates[s]); 797368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand } 7981a52bc30390d56493ea2d0a950d8b9f01519ed24Jason Ekstrand 7991a52bc30390d56493ea2d0a950d8b9f01519ed24Jason Ekstrand struct anv_dynamic_state *dynamic = &pipeline->dynamic_state; 8001a52bc30390d56493ea2d0a950d8b9f01519ed24Jason Ekstrand 801368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand dynamic->viewport.count = pCreateInfo->pViewportState->viewportCount; 802368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand if (states & (1 << VK_DYNAMIC_STATE_VIEWPORT)) { 803368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand typed_memcpy(dynamic->viewport.viewports, 804368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand pCreateInfo->pViewportState->pViewports, 805368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand pCreateInfo->pViewportState->viewportCount); 806368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand } 807368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand 808368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand dynamic->scissor.count = pCreateInfo->pViewportState->scissorCount; 809368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand if (states & (1 << VK_DYNAMIC_STATE_SCISSOR)) { 810368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand typed_memcpy(dynamic->scissor.scissors, 811368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand pCreateInfo->pViewportState->pScissors, 812368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand pCreateInfo->pViewportState->scissorCount); 813368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand } 814368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand 815368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand if (states & (1 << VK_DYNAMIC_STATE_LINE_WIDTH)) { 8167f2284063df569df40f68074833f1518005d348dJason Ekstrand assert(pCreateInfo->pRasterizationState); 8177f2284063df569df40f68074833f1518005d348dJason Ekstrand dynamic->line_width = pCreateInfo->pRasterizationState->lineWidth; 818368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand } 819368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand 820368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand if (states & (1 << VK_DYNAMIC_STATE_DEPTH_BIAS)) { 8217f2284063df569df40f68074833f1518005d348dJason Ekstrand assert(pCreateInfo->pRasterizationState); 8224ab9391fbb35e627f2033494f0440536bb3341a8Jason Ekstrand dynamic->depth_bias.bias = 8237f2284063df569df40f68074833f1518005d348dJason Ekstrand pCreateInfo->pRasterizationState->depthBiasConstantFactor; 8247f2284063df569df40f68074833f1518005d348dJason Ekstrand dynamic->depth_bias.clamp = 8257f2284063df569df40f68074833f1518005d348dJason Ekstrand pCreateInfo->pRasterizationState->depthBiasClamp; 8264ab9391fbb35e627f2033494f0440536bb3341a8Jason Ekstrand dynamic->depth_bias.slope = 8277f2284063df569df40f68074833f1518005d348dJason Ekstrand pCreateInfo->pRasterizationState->depthBiasSlopeFactor; 828368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand } 829368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand 830368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand if (states & (1 << VK_DYNAMIC_STATE_BLEND_CONSTANTS)) { 831368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand assert(pCreateInfo->pColorBlendState); 832368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand typed_memcpy(dynamic->blend_constants, 8334ab9391fbb35e627f2033494f0440536bb3341a8Jason Ekstrand pCreateInfo->pColorBlendState->blendConstants, 4); 8341a52bc30390d56493ea2d0a950d8b9f01519ed24Jason Ekstrand } 835368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand 8362484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace /* If there is no depthstencil attachment, then don't read 8372484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace * pDepthStencilState. The Vulkan spec states that pDepthStencilState may 8382484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace * be NULL in this case. Even if pDepthStencilState is non-NULL, there is 8392484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace * no need to override the depthstencil defaults in 8402484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace * anv_pipeline::dynamic_state when there is no depthstencil attachment. 8412484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace * 8422484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace * From the Vulkan spec (20 Oct 2015, git-aa308cb): 8432484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace * 8442484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace * pDepthStencilState [...] may only be NULL if renderPass and subpass 8452484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace * specify a subpass that has no depth/stencil attachment. 8462484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace */ 8472484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace if (subpass->depth_stencil_attachment != VK_ATTACHMENT_UNUSED) { 8482484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace if (states & (1 << VK_DYNAMIC_STATE_DEPTH_BOUNDS)) { 8492484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace assert(pCreateInfo->pDepthStencilState); 8502484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace dynamic->depth_bounds.min = 8512484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace pCreateInfo->pDepthStencilState->minDepthBounds; 8522484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace dynamic->depth_bounds.max = 8532484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace pCreateInfo->pDepthStencilState->maxDepthBounds; 8542484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace } 8552484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace 8562484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace if (states & (1 << VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK)) { 8572484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace assert(pCreateInfo->pDepthStencilState); 8582484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace dynamic->stencil_compare_mask.front = 8594ab9391fbb35e627f2033494f0440536bb3341a8Jason Ekstrand pCreateInfo->pDepthStencilState->front.compareMask; 8602484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace dynamic->stencil_compare_mask.back = 8614ab9391fbb35e627f2033494f0440536bb3341a8Jason Ekstrand pCreateInfo->pDepthStencilState->back.compareMask; 8622484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace } 8632484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace 8642484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace if (states & (1 << VK_DYNAMIC_STATE_STENCIL_WRITE_MASK)) { 8652484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace assert(pCreateInfo->pDepthStencilState); 8662484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace dynamic->stencil_write_mask.front = 8674ab9391fbb35e627f2033494f0440536bb3341a8Jason Ekstrand pCreateInfo->pDepthStencilState->front.writeMask; 8682484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace dynamic->stencil_write_mask.back = 8694ab9391fbb35e627f2033494f0440536bb3341a8Jason Ekstrand pCreateInfo->pDepthStencilState->back.writeMask; 8702484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace } 8712484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace 8722484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace if (states & (1 << VK_DYNAMIC_STATE_STENCIL_REFERENCE)) { 8732484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace assert(pCreateInfo->pDepthStencilState); 8742484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace dynamic->stencil_reference.front = 8754ab9391fbb35e627f2033494f0440536bb3341a8Jason Ekstrand pCreateInfo->pDepthStencilState->front.reference; 8762484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace dynamic->stencil_reference.back = 8774ab9391fbb35e627f2033494f0440536bb3341a8Jason Ekstrand pCreateInfo->pDepthStencilState->back.reference; 8782484d1a01fff6127b45280ee9bfbd1bbfaa425dbChad Versace } 879368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand } 880368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand 881368e703a01c631f04f2a2a1f5f62f61c06838faeJason Ekstrand pipeline->dynamic_state_mask = states; 8821a52bc30390d56493ea2d0a950d8b9f01519ed24Jason Ekstrand} 8831a52bc30390d56493ea2d0a950d8b9f01519ed24Jason Ekstrand 884b51468b519f447c8e0afd492ce09d7c9485e222bChad Versacestatic void 885b51468b519f447c8e0afd492ce09d7c9485e222bChad Versaceanv_pipeline_validate_create_info(const VkGraphicsPipelineCreateInfo *info) 886b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace{ 887b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace struct anv_render_pass *renderpass = NULL; 888b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace struct anv_subpass *subpass = NULL; 889b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace 890b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace /* Assert that all required members of VkGraphicsPipelineCreateInfo are 891b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace * present, as explained by the Vulkan (20 Oct 2015, git-aa308cb), Section 892b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace * 4.2 Graphics Pipeline. 893b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace */ 894b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace assert(info->sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO); 895b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace 896b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace renderpass = anv_render_pass_from_handle(info->renderPass); 897b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace assert(renderpass); 898b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace 899b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace if (renderpass != &anv_meta_dummy_renderpass) { 900b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace assert(info->subpass < renderpass->subpass_count); 901b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace subpass = &renderpass->subpasses[info->subpass]; 902b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace } 903b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace 904b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace assert(info->stageCount >= 1); 905b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace assert(info->pVertexInputState); 906b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace assert(info->pInputAssemblyState); 907b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace assert(info->pViewportState); 9087f2284063df569df40f68074833f1518005d348dJason Ekstrand assert(info->pRasterizationState); 909b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace assert(info->pMultisampleState); 910b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace 911b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace if (subpass && subpass->depth_stencil_attachment != VK_ATTACHMENT_UNUSED) 912b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace assert(info->pDepthStencilState); 913b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace 914b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace if (subpass && subpass->color_count > 0) 915b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace assert(info->pColorBlendState); 916b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace 917b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace for (uint32_t i = 0; i < info->stageCount; ++i) { 918b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace switch (info->pStages[i].stage) { 919b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace case VK_SHADER_STAGE_TESS_CONTROL: 920b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace case VK_SHADER_STAGE_TESS_EVALUATION: 921b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace assert(info->pTessellationState); 922b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace break; 923b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace default: 924b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace break; 925b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace } 926b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace } 927b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace} 928b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace 9299c752b5b38305acaf863fc0165565fcf6f8f390aKristian HøgsbergVkResult 9309c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberganv_pipeline_init(struct anv_pipeline *pipeline, struct anv_device *device, 9319c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg const VkGraphicsPipelineCreateInfo *pCreateInfo, 932fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand const struct anv_graphics_pipeline_create_info *extra, 933fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand const VkAllocationCallbacks *alloc) 9349c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg{ 935b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace anv_validate { 936b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace anv_pipeline_validate_create_info(pCreateInfo); 937b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace } 938b51468b519f447c8e0afd492ce09d7c9485e222bChad Versace 939fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand if (alloc == NULL) 940fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand alloc = &device->alloc; 941fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand 9429c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg pipeline->device = device; 9439c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg pipeline->layout = anv_pipeline_layout_from_handle(pCreateInfo->layout); 9449c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg 945fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand anv_reloc_list_init(&pipeline->batch_relocs, alloc); 946fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand /* TODO: Handle allocation fail */ 947fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand 948fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand pipeline->batch.alloc = alloc; 9499c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg pipeline->batch.next = pipeline->batch.start = pipeline->batch_data; 9509c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg pipeline->batch.end = pipeline->batch.start + sizeof(pipeline->batch_data); 9519c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg pipeline->batch.relocs = &pipeline->batch_relocs; 9529c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg 9539c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg anv_state_stream_init(&pipeline->program_stream, 9549c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg &device->instruction_block_pool); 9559c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg 9561a52bc30390d56493ea2d0a950d8b9f01519ed24Jason Ekstrand anv_pipeline_init_dynamic_state(pipeline, pCreateInfo); 9571a52bc30390d56493ea2d0a950d8b9f01519ed24Jason Ekstrand 9589c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg if (pCreateInfo->pTessellationState) 9599c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg anv_finishme("VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO"); 96037bf120930aa9e3ccf455efc633f2edbdec9dfc1Chad Versace if (pCreateInfo->pMultisampleState && 9617f2284063df569df40f68074833f1518005d348dJason Ekstrand pCreateInfo->pMultisampleState->rasterizationSamples > 1) 9629c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg anv_finishme("VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO"); 9639c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg 9649c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg pipeline->use_repclear = extra && extra->use_repclear; 965a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->writes_point_size = false; 9669c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg 967a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* When we free the pipeline, we detect stages based on the NULL status 968a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand * of various prog_data pointers. Make them NULL by default. 969a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand */ 970a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand memset(pipeline->prog_data, 0, sizeof(pipeline->prog_data)); 971a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand memset(pipeline->scratch_start, 0, sizeof(pipeline->scratch_start)); 9729c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg 973a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->vs_simd8 = NO_KERNEL; 974a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->vs_vec4 = NO_KERNEL; 975a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->gs_vec4 = NO_KERNEL; 9769c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg 977a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->active_stages = 0; 978a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand pipeline->total_scratch = 0; 979a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 980a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) { 981e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand ANV_FROM_HANDLE(anv_shader_module, module, 982e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand pCreateInfo->pStages[i].module); 983e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand const char *entrypoint = pCreateInfo->pStages[i].pName; 984a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 985a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand switch (pCreateInfo->pStages[i].stage) { 986a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand case VK_SHADER_STAGE_VERTEX: 987e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand anv_pipeline_compile_vs(pipeline, pCreateInfo, module, entrypoint); 988a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand break; 989d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand case VK_SHADER_STAGE_GEOMETRY: 990e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand anv_pipeline_compile_gs(pipeline, pCreateInfo, module, entrypoint); 991d538fe849df0c3f80fea2765ff36dd2db5eab72bJason Ekstrand break; 992a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand case VK_SHADER_STAGE_FRAGMENT: 993e10dc002e9544500a2247e49a132e18f994f34eeJason Ekstrand anv_pipeline_compile_fs(pipeline, pCreateInfo, module, entrypoint); 994a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand break; 995a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand default: 996a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand anv_finishme("Unsupported shader stage"); 9979c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg } 9989c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg } 9999c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg 1000a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand if (!(pipeline->active_stages & VK_SHADER_STAGE_VERTEX_BIT)) { 1001a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand /* Vertex is only optional if disable_vs is set */ 1002a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand assert(extra->disable_vs); 1003a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand memset(&pipeline->vs_prog_data, 0, sizeof(pipeline->vs_prog_data)); 1004a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand } 1005a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 1006a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand gen7_compute_urb_partition(pipeline); 1007a71e614d33e8d869bbaced8948349a7180783ab7Jason Ekstrand 10089c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg const VkPipelineVertexInputStateCreateInfo *vi_info = 10099c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg pCreateInfo->pVertexInputState; 10109c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg pipeline->vb_used = 0; 1011e673d642090e6a6fe339570726e52b9191b89d3eJason Ekstrand for (uint32_t i = 0; i < vi_info->vertexBindingDescriptionCount; i++) { 10129c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg const VkVertexInputBindingDescription *desc = 10139c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg &vi_info->pVertexBindingDescriptions[i]; 10149c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg 10159c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg pipeline->vb_used |= 1 << desc->binding; 1016e673d642090e6a6fe339570726e52b9191b89d3eJason Ekstrand pipeline->binding_stride[desc->binding] = desc->stride; 10179c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg 10189c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg /* Step rate is programmed per vertex element (attribute), not 10199c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg * binding. Set up a map of which bindings step per instance, for 10209c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg * reference by vertex element setup. */ 10219b1cb8fdbc7e3c2fb9b950a9844ef653761b7480Jason Ekstrand switch (desc->inputRate) { 10229c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg default: 10239b1cb8fdbc7e3c2fb9b950a9844ef653761b7480Jason Ekstrand case VK_VERTEX_INPUT_RATE_VERTEX: 10249c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg pipeline->instancing_enable[desc->binding] = false; 10259c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg break; 10269b1cb8fdbc7e3c2fb9b950a9844ef653761b7480Jason Ekstrand case VK_VERTEX_INPUT_RATE_INSTANCE: 10279c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg pipeline->instancing_enable[desc->binding] = true; 10289c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg break; 10299c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg } 10309c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg } 10319c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg 10329c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg const VkPipelineInputAssemblyStateCreateInfo *ia_info = 10339c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg pCreateInfo->pInputAssemblyState; 10349c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg pipeline->primitive_restart = ia_info->primitiveRestartEnable; 10359c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg pipeline->topology = vk_to_gen_primitive_type[ia_info->topology]; 10369c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg 10379c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg if (extra && extra->use_rectlist) 10389c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg pipeline->topology = _3DPRIM_RECTLIST; 10399c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg 10409c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg return VK_SUCCESS; 10419c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg} 10429c752b5b38305acaf863fc0165565fcf6f8f390aKristian Høgsberg 10430bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian HøgsbergVkResult 10440bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberganv_graphics_pipeline_create( 10450bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg VkDevice _device, 10460bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg const VkGraphicsPipelineCreateInfo *pCreateInfo, 10470bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg const struct anv_graphics_pipeline_create_info *extra, 1048fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand const VkAllocationCallbacks *pAllocator, 10490bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg VkPipeline *pPipeline) 10500bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg{ 10510bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg ANV_FROM_HANDLE(anv_device, device, _device); 10520bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg 10530bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg switch (device->info.gen) { 1054f1455ffac78b1369d9c4187b7f1d36c2d96e0babKristian Høgsberg case 7: 1055f0390bcad6b5e1f1e94bbf762ccc98bf499c022bJason Ekstrand if (device->info.is_haswell) 1056fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand return gen75_graphics_pipeline_create(_device, pCreateInfo, extra, pAllocator, pPipeline); 1057f0390bcad6b5e1f1e94bbf762ccc98bf499c022bJason Ekstrand else 1058fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand return gen7_graphics_pipeline_create(_device, pCreateInfo, extra, pAllocator, pPipeline); 10590bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg case 8: 1060fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand return gen8_graphics_pipeline_create(_device, pCreateInfo, extra, pAllocator, pPipeline); 1061cd4721c062a300739b107925f801c9b9ced5f9faKristian Høgsberg case 9: 1062fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand return gen9_graphics_pipeline_create(_device, pCreateInfo, extra, pAllocator, pPipeline); 10630bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg default: 10640bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg unreachable("unsupported gen\n"); 10650bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg } 10660bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg} 10670bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg 10685a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason EkstrandVkResult anv_CreateGraphicsPipelines( 10695a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand VkDevice _device, 10705a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand VkPipelineCache pipelineCache, 10715a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand uint32_t count, 10725a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand const VkGraphicsPipelineCreateInfo* pCreateInfos, 1073fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand const VkAllocationCallbacks* pAllocator, 10745a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand VkPipeline* pPipelines) 1075769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg{ 10765a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand VkResult result = VK_SUCCESS; 10775a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand 10785a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand unsigned i = 0; 10795a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand for (; i < count; i++) { 10800bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg result = anv_graphics_pipeline_create(_device, &pCreateInfos[i], 1081fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand NULL, pAllocator, &pPipelines[i]); 10825a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand if (result != VK_SUCCESS) { 10835a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand for (unsigned j = 0; j < i; j++) { 1084fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand anv_DestroyPipeline(_device, pPipelines[j], pAllocator); 10855a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand } 10865a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand 10875a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand return result; 10885a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand } 10895a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand } 10905a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand 10915a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand return VK_SUCCESS; 1092769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg} 1093769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg 10945a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrandstatic VkResult anv_compute_pipeline_create( 1095765175f5d195df727ed9d171720f4e843809744eKristian Høgsberg VkDevice _device, 1096769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg const VkComputePipelineCreateInfo* pCreateInfo, 1097fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand const VkAllocationCallbacks* pAllocator, 1098769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg VkPipeline* pPipeline) 1099769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg{ 11006eb221c884a28786b68904faf950cf6f7881d9d9Jason Ekstrand ANV_FROM_HANDLE(anv_device, device, _device); 1101765175f5d195df727ed9d171720f4e843809744eKristian Høgsberg 11020bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg switch (device->info.gen) { 1103f1455ffac78b1369d9c4187b7f1d36c2d96e0babKristian Høgsberg case 7: 1104f0390bcad6b5e1f1e94bbf762ccc98bf499c022bJason Ekstrand if (device->info.is_haswell) 1105fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand return gen75_compute_pipeline_create(_device, pCreateInfo, pAllocator, pPipeline); 1106f0390bcad6b5e1f1e94bbf762ccc98bf499c022bJason Ekstrand else 1107fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand return gen7_compute_pipeline_create(_device, pCreateInfo, pAllocator, pPipeline); 11080bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg case 8: 1109fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand return gen8_compute_pipeline_create(_device, pCreateInfo, pAllocator, pPipeline); 1110cd4721c062a300739b107925f801c9b9ced5f9faKristian Høgsberg case 9: 1111fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand return gen9_compute_pipeline_create(_device, pCreateInfo, pAllocator, pPipeline); 11120bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg default: 11130bcf85d79f39242daa648fb88fcded9fba6fd3b4Kristian Høgsberg unreachable("unsupported gen\n"); 1114765175f5d195df727ed9d171720f4e843809744eKristian Høgsberg } 1115769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg} 1116769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg 11175a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason EkstrandVkResult anv_CreateComputePipelines( 11185a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand VkDevice _device, 11195a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand VkPipelineCache pipelineCache, 11205a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand uint32_t count, 11215a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand const VkComputePipelineCreateInfo* pCreateInfos, 1122fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand const VkAllocationCallbacks* pAllocator, 11235a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand VkPipeline* pPipelines) 1124769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg{ 11255a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand VkResult result = VK_SUCCESS; 11265a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand 11275a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand unsigned i = 0; 11285a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand for (; i < count; i++) { 11295a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand result = anv_compute_pipeline_create(_device, &pCreateInfos[i], 1130fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand pAllocator, &pPipelines[i]); 11315a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand if (result != VK_SUCCESS) { 11325a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand for (unsigned j = 0; j < i; j++) { 1133fcfb404a5860c67129e3672768cc557c0e4a1f12Jason Ekstrand anv_DestroyPipeline(_device, pPipelines[j], pAllocator); 11345a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand } 11355a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand 11365a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand return result; 11375a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand } 11385a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand } 1139769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg 11405a4ebf6bc12b01fdecdb04c1e4a1df573d75ce8aJason Ekstrand return VK_SUCCESS; 1141769785c497aaa60c629e0299e3ebfff53a8e393eKristian Høgsberg} 1142