diff --git a/src/nouveau/vulkan/nvk_physical_device.c b/src/nouveau/vulkan/nvk_physical_device.c index ff9f693021f..0b564b50b30 100644 --- a/src/nouveau/vulkan/nvk_physical_device.c +++ b/src/nouveau/vulkan/nvk_physical_device.c @@ -12,6 +12,7 @@ #include "nvk_shader.h" #include "nvk_wsi.h" #include "git_sha1.h" +#include "util/disk_cache.h" #include "util/mesa-sha1.h" #include "vulkan/runtime/vk_device.h" @@ -627,6 +628,24 @@ nvk_get_device_properties(const struct nvk_instance *instance, "Mesa " PACKAGE_VERSION MESA_GIT_SHA1); } +static void +nvk_physical_device_init_disk_cache(struct nvk_physical_device *pdev) +{ +#ifdef ENABLE_SHADER_CACHE + char renderer[10]; + ASSERTED int len = snprintf(renderer, sizeof(renderer), "nvk_%04x", + pdev->info.chipset); + assert(len == sizeof(renderer) - 2); + + char timestamp[41]; + struct nvk_instance *instance = nvk_physical_device_instance(pdev); + _mesa_sha1_format(timestamp, instance->driver_build_sha); + + const uint64_t driver_flags = nvk_physical_device_compiler_flags(pdev); + pdev->vk.disk_cache = disk_cache_create(renderer, timestamp, driver_flags); +#endif +} + VkResult nvk_create_drm_physical_device(struct vk_instance *_instance, drmDevicePtr drm_device, @@ -752,6 +771,8 @@ nvk_create_drm_physical_device(struct vk_instance *_instance, pdev->render_dev = render_dev; pdev->info = info; + nvk_physical_device_init_disk_cache(pdev); + pdev->mem_heaps[0].flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT; pdev->mem_types[0].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; pdev->mem_types[0].heapIndex = 0; diff --git a/src/nouveau/vulkan/nvk_shader.c b/src/nouveau/vulkan/nvk_shader.c index cbe6571f098..ff61cbcc112 100644 --- a/src/nouveau/vulkan/nvk_shader.c +++ b/src/nouveau/vulkan/nvk_shader.c @@ -61,6 +61,29 @@ pipe_shader_type_from_mesa(gl_shader_stage stage) } } +static uint64_t +get_prog_debug(void) +{ + return debug_get_num_option("NV50_PROG_DEBUG", 0); +} + +static uint64_t +get_prog_optimize(void) +{ + return debug_get_num_option("NV50_PROG_OPTIMIZE", 0); +} + +uint64_t +nvk_physical_device_compiler_flags(const struct nvk_physical_device *pdev) +{ + uint64_t prog_debug = get_prog_debug(); + uint64_t prog_optimize = get_prog_optimize(); + + assert(prog_debug <= UINT8_MAX); + assert(prog_optimize <= UINT8_MAX); + return prog_debug | (prog_optimize << 8); +} + const nir_shader_compiler_options * nvk_physical_device_nir_options(const struct nvk_physical_device *pdev, gl_shader_stage stage) @@ -1108,8 +1131,8 @@ nvk_compile_nir(struct nvk_physical_device *pdev, nir_shader *nir, shader->cp.block_size[i] = nir->info.workgroup_size[i]; info->bin.smemSize = shader->cp.smem_size; - info->dbgFlags = debug_get_num_option("NV50_PROG_DEBUG", 0); - info->optLevel = debug_get_num_option("NV50_PROG_OPTIMIZE", 3); + info->dbgFlags = get_prog_debug(); + info->optLevel = get_prog_optimize(); info->io.auxCBSlot = 1; info->io.uboInfoBase = 0; info->io.drawInfoBase = nvk_root_descriptor_offset(draw.base_vertex); diff --git a/src/nouveau/vulkan/nvk_shader.h b/src/nouveau/vulkan/nvk_shader.h index 11c9ed7f86f..9c961adb22f 100644 --- a/src/nouveau/vulkan/nvk_shader.h +++ b/src/nouveau/vulkan/nvk_shader.h @@ -95,6 +95,9 @@ nvk_shader_address(const struct nvk_shader *shader) return shader->upload_addr + shader->upload_padding; } +uint64_t +nvk_physical_device_compiler_flags(const struct nvk_physical_device *pdev); + const nir_shader_compiler_options * nvk_physical_device_nir_options(const struct nvk_physical_device *pdev, gl_shader_stage stage);