X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Famd%2Fvulkan%2Fradv_meta.c;h=5e619c2f181644e936b0a0a7e100cfa87f81dde3;hb=2141e6fc73eec854759f74c38df09975c544ced6;hp=00a20d155e72d20209a3dbcf7439f2f6e0c40636;hpb=43af92edc5ca6ac8408bb694f187d93ccfd62fb1;p=mesa.git diff --git a/src/amd/vulkan/radv_meta.c b/src/amd/vulkan/radv_meta.c index 00a20d155e7..5e619c2f181 100644 --- a/src/amd/vulkan/radv_meta.c +++ b/src/amd/vulkan/radv_meta.c @@ -73,6 +73,11 @@ radv_meta_save(struct radv_meta_saved_state *state, 1 << VK_DYNAMIC_STATE_SCISSOR; } + if (state->flags & RADV_META_SAVE_SAMPLE_LOCATIONS) { + typed_memcpy(&state->sample_location, + &cmd_buffer->state.dynamic.sample_location, 1); + } + if (state->flags & RADV_META_SAVE_COMPUTE_PIPELINE) { assert(!(state->flags & RADV_META_SAVE_GRAPHICS_PIPELINE)); @@ -80,10 +85,9 @@ radv_meta_save(struct radv_meta_saved_state *state, } if (state->flags & RADV_META_SAVE_DESCRIPTORS) { - if (descriptors_state->valid & (1 << 0)) - state->old_descriptor_set0 = descriptors_state->sets[0]; - else - state->old_descriptor_set0 = NULL; + state->old_descriptor_set0 = descriptors_state->sets[0]; + if (!state->old_descriptor_set0) + state->flags &= ~RADV_META_SAVE_DESCRIPTORS; } if (state->flags & RADV_META_SAVE_CONSTANTS) { @@ -128,8 +132,15 @@ radv_meta_restore(const struct radv_meta_saved_state *state, state->scissor.scissors, MAX_SCISSORS); - cmd_buffer->state.dirty |= 1 << VK_DYNAMIC_STATE_VIEWPORT | - 1 << VK_DYNAMIC_STATE_SCISSOR; + cmd_buffer->state.dirty |= RADV_CMD_DIRTY_DYNAMIC_VIEWPORT | + RADV_CMD_DIRTY_DYNAMIC_SCISSOR; + } + + if (state->flags & RADV_META_SAVE_SAMPLE_LOCATIONS) { + typed_memcpy(&cmd_buffer->state.dynamic.sample_location.locations, + &state->sample_location.locations, 1); + + cmd_buffer->state.dirty |= RADV_CMD_DIRTY_DYNAMIC_SAMPLE_LOCATIONS; } if (state->flags & RADV_META_SAVE_COMPUTE_PIPELINE) { @@ -144,13 +155,15 @@ radv_meta_restore(const struct radv_meta_saved_state *state, } if (state->flags & RADV_META_SAVE_CONSTANTS) { - memcpy(cmd_buffer->push_constants, state->push_constants, - MAX_PUSH_CONSTANTS_SIZE); - cmd_buffer->push_constant_stages |= VK_SHADER_STAGE_COMPUTE_BIT; + VkShaderStageFlags stages = VK_SHADER_STAGE_COMPUTE_BIT; - if (state->flags & RADV_META_SAVE_GRAPHICS_PIPELINE) { - cmd_buffer->push_constant_stages |= VK_SHADER_STAGE_ALL_GRAPHICS; - } + if (state->flags & RADV_META_SAVE_GRAPHICS_PIPELINE) + stages |= VK_SHADER_STAGE_ALL_GRAPHICS; + + radv_CmdPushConstants(radv_cmd_buffer_to_handle(cmd_buffer), + VK_NULL_HANDLE, stages, 0, + MAX_PUSH_CONSTANTS_SIZE, + state->push_constants); } if (state->flags & RADV_META_SAVE_PASS) { @@ -235,15 +248,12 @@ radv_builtin_cache_path(char *path) const char *suffix2 = "/.cache/radv_builtin_shaders"; struct passwd pwd, *result; char path2[PATH_MAX + 1]; /* PATH_MAX is not a real max,but suffices here. */ + int ret; if (xdg_cache_home) { - - if (strlen(xdg_cache_home) + strlen(suffix) > PATH_MAX) - return false; - - strcpy(path, xdg_cache_home); - strcat(path, suffix); - return true; + ret = snprintf(path, PATH_MAX + 1, "%s%s%zd", + xdg_cache_home, suffix, sizeof(void *) * 8); + return ret > 0 && ret < PATH_MAX + 1; } getpwuid_r(getuid(), &pwd, path2, PATH_MAX - strlen(suffix2), &result); @@ -254,23 +264,25 @@ radv_builtin_cache_path(char *path) strcat(path, "/.cache"); mkdir(path, 0755); - strcat(path, suffix); - return true; + ret = snprintf(path, PATH_MAX + 1, "%s%s%zd", + pwd.pw_dir, suffix2, sizeof(void *) * 8); + return ret > 0 && ret < PATH_MAX + 1; } -static void +static bool radv_load_meta_pipeline(struct radv_device *device) { char path[PATH_MAX + 1]; struct stat st; void *data = NULL; + bool ret = false; if (!radv_builtin_cache_path(path)) - return; + return false; int fd = open(path, O_RDONLY); if (fd < 0) - return; + return false; if (fstat(fd, &st)) goto fail; data = malloc(st.st_size); @@ -279,10 +291,11 @@ radv_load_meta_pipeline(struct radv_device *device) if(read(fd, data, st.st_size) == -1) goto fail; - radv_pipeline_cache_load(&device->meta_state.cache, data, st.st_size); + ret = radv_pipeline_cache_load(&device->meta_state.cache, data, st.st_size); fail: free(data); close(fd); + return ret; } static void @@ -331,6 +344,8 @@ radv_device_init_meta(struct radv_device *device) { VkResult result; + memset(&device->meta_state, 0, sizeof(device->meta_state)); + device->meta_state.alloc = (VkAllocationCallbacks) { .pUserData = device, .pfnAllocation = meta_alloc, @@ -340,21 +355,24 @@ radv_device_init_meta(struct radv_device *device) device->meta_state.cache.alloc = device->meta_state.alloc; radv_pipeline_cache_init(&device->meta_state.cache, device); - radv_load_meta_pipeline(device); + bool loaded_cache = radv_load_meta_pipeline(device); + bool on_demand = !loaded_cache; + + mtx_init(&device->meta_state.mtx, mtx_plain); - result = radv_device_init_meta_clear_state(device); + result = radv_device_init_meta_clear_state(device, on_demand); if (result != VK_SUCCESS) goto fail_clear; - result = radv_device_init_meta_resolve_state(device); + result = radv_device_init_meta_resolve_state(device, on_demand); if (result != VK_SUCCESS) goto fail_resolve; - result = radv_device_init_meta_blit_state(device); + result = radv_device_init_meta_blit_state(device, on_demand); if (result != VK_SUCCESS) goto fail_blit; - result = radv_device_init_meta_blit2d_state(device); + result = radv_device_init_meta_blit2d_state(device, on_demand); if (result != VK_SUCCESS) goto fail_blit2d; @@ -362,7 +380,7 @@ radv_device_init_meta(struct radv_device *device) if (result != VK_SUCCESS) goto fail_bufimage; - result = radv_device_init_meta_depth_decomp_state(device); + result = radv_device_init_meta_depth_decomp_state(device, on_demand); if (result != VK_SUCCESS) goto fail_depth_decomp; @@ -370,23 +388,30 @@ radv_device_init_meta(struct radv_device *device) if (result != VK_SUCCESS) goto fail_buffer; - result = radv_device_init_meta_query_state(device); + result = radv_device_init_meta_query_state(device, on_demand); if (result != VK_SUCCESS) goto fail_query; - result = radv_device_init_meta_fast_clear_flush_state(device); + result = radv_device_init_meta_fast_clear_flush_state(device, on_demand); if (result != VK_SUCCESS) goto fail_fast_clear; - result = radv_device_init_meta_resolve_compute_state(device); + result = radv_device_init_meta_resolve_compute_state(device, on_demand); if (result != VK_SUCCESS) goto fail_resolve_compute; - result = radv_device_init_meta_resolve_fragment_state(device); + result = radv_device_init_meta_resolve_fragment_state(device, on_demand); if (result != VK_SUCCESS) goto fail_resolve_fragment; + + result = radv_device_init_meta_fmask_expand_state(device); + if (result != VK_SUCCESS) + goto fail_fmask_expand; + return VK_SUCCESS; +fail_fmask_expand: + radv_device_finish_meta_resolve_fragment_state(device); fail_resolve_fragment: radv_device_finish_meta_resolve_compute_state(device); fail_resolve_compute: @@ -408,6 +433,7 @@ fail_blit: fail_resolve: radv_device_finish_meta_clear_state(device); fail_clear: + mtx_destroy(&device->meta_state.mtx); radv_pipeline_cache_finish(&device->meta_state.cache); return result; } @@ -426,9 +452,11 @@ radv_device_finish_meta(struct radv_device *device) radv_device_finish_meta_fast_clear_flush_state(device); radv_device_finish_meta_resolve_compute_state(device); radv_device_finish_meta_resolve_fragment_state(device); + radv_device_finish_meta_fmask_expand_state(device); radv_store_meta_pipeline(device); radv_pipeline_cache_finish(&device->meta_state.cache); + mtx_destroy(&device->meta_state.mtx); } nir_ssa_def *radv_meta_gen_rect_vertices_comp2(nir_builder *vs_b, nir_ssa_def *comp2)