radv: enable the trap handler and configure the shader exceptions
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 18 Aug 2020 06:49:11 +0000 (08:49 +0200)
committerMarge Bot <eric+marge@anholt.net>
Mon, 24 Aug 2020 11:08:24 +0000 (11:08 +0000)
When TRAP_PRESENT is not enabled, all traps and exceptions are ignored.
Only EXCP_EN.mem_viol is currently supported because the other
exceptions have to be tested/validated first.

EXCP_EN.mem_viol is used to detect any sort of invalid memory
access like VM fault. When a memory violation is reported, the
hw jumps to the trap handler.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6384>

src/amd/vulkan/radv_shader.c

index 8d0cd9d4feb7d60a32361d68dc3c97f94439751c..5ca57e045e42ff05b5813a0fc8d2eed4cae600e8 100644 (file)
@@ -805,12 +805,13 @@ radv_get_shader_binary_size(size_t code_size)
        return code_size + DEBUGGER_NUM_MARKERS * 4;
 }
 
-static void radv_postprocess_config(const struct radv_physical_device *pdevice,
+static void radv_postprocess_config(const struct radv_device *device,
                                    const struct ac_shader_config *config_in,
                                    const struct radv_shader_info *info,
                                    gl_shader_stage stage,
                                    struct ac_shader_config *config_out)
 {
+       const struct radv_physical_device *pdevice = device->physical_device;
        bool scratch_enabled = config_in->scratch_bytes_per_wave > 0;
        unsigned vgpr_comp_cnt = 0;
        unsigned num_input_vgprs = info->num_input_vgprs;
@@ -836,6 +837,15 @@ static void radv_postprocess_config(const struct radv_physical_device *pdevice,
        config_out->rsrc2 = S_00B12C_USER_SGPR(info->num_user_sgprs) |
                            S_00B12C_SCRATCH_EN(scratch_enabled);
 
+       if (device->trap_handler_shader) {
+               /* Enable the trap handler if requested and configure the
+                * shader exceptions like memory violation, etc.
+                * TODO: Enable (and validate) more exceptions.
+                */
+               config_out->rsrc2 |= S_00B12C_TRAP_PRESENT(1) |
+                                    S_00B12C_EXCP_EN(1 << 8); /* mem_viol */
+       }
+
        if (!pdevice->use_ngg_streamout) {
                config_out->rsrc2 |= S_00B12C_SO_BASE0_EN(!!info->so.strides[0]) |
                                     S_00B12C_SO_BASE1_EN(!!info->so.strides[1]) |
@@ -1108,7 +1118,7 @@ radv_shader_variant_create(struct radv_device *device,
        }
 
        variant->info = binary->info;
-       radv_postprocess_config(device->physical_device, &config, &binary->info,
+       radv_postprocess_config(device, &config, &binary->info,
                                binary->stage, &variant->config);
 
        void *dest_ptr = radv_alloc_shader_memory(device, variant);