Lines Matching +full:stale +full:- +full:pr +full:- +full:message
78 * Since virgl_caps_v2 is growable and no backward-incompatible change is
545 unsigned size; /**< size of the accessible sub-range in bytes */
620 #define VREND_PROGRAM_NQUEUE_MASK (VREND_PROGRAM_NQUEUES - 1)
632 /* Using an array of lists only adds VREND_PROGRAM_NQUEUES - 1 list_head
840 if (!gbm || !gbm->device || !gbm_format) in vrend_format_can_sample()
844 return gbm_device_is_format_supported(gbm->device, gbm_format, gbm_usage); in vrend_format_can_sample()
877 if (!gbm || !gbm->device || !gbm_format) in vrend_format_can_scanout()
880 return gbm_device_is_format_supported(gbm->device, gbm_format, GBM_BO_USE_SCANOUT); in vrend_format_can_scanout()
897 return &ctx->sub->tweaks; in vrend_get_context_tweaks()
918 return (has_bit(res->storage_bits, VREND_STORAGE_EGL_IMAGE) && in vrend_resource_has_24bpp_internal_format()
919 (res->base.format == VIRGL_FORMAT_B8G8R8X8_UNORM || in vrend_resource_has_24bpp_internal_format()
920 res->base.format == VIRGL_FORMAT_R8G8B8X8_UNORM)); in vrend_resource_has_24bpp_internal_format()
926 /* Texture views on eglimage-backed bgr* resources are not supported and in vrend_resource_supports_view()
928 * bgr* resources use GL_RGBA8 internal format, while eglimage-backed in vrend_resource_supports_view()
934 return !(vrend_format_is_bgra(res->base.format) && in vrend_resource_supports_view()
935 has_bit(res->storage_bits, VREND_STORAGE_EGL_IMAGE)) && in vrend_resource_supports_view()
944 vrend_format_is_bgra(res->base.format) ^ vrend_format_is_bgra(view_format); in vrend_resource_needs_redblue_swizzle()
952 util_format_is_srgb(res->base.format) && in vrend_resource_needs_srgb_decode()
961 !util_format_is_srgb(res->base.format) && in vrend_resource_needs_srgb_encode()
1035 ctx->in_error = true; in vrend_report_context_error_internal()
1036 ctx->last_error = error; in vrend_report_context_error_internal()
1038 ctx->ctx_id, ctx->debug_name, vrend_ctx_error_strings[error], in vrend_report_context_error_internal()
1062 ctx->ctx_id, ctx->debug_name, in __report_core_warn()
1110 VREND_DEBUG(dbg_gles, ctx, "%s: GLES violation - %s\n", fname, vrend_gles_warn_strings[error]); in __report_gles_warn()
1150 if (surf->id != surf->texture->id) in vrend_destroy_surface()
1151 glDeleteTextures(1, &surf->id); in vrend_destroy_surface()
1152 vrend_resource_reference(&surf->texture, NULL); in vrend_destroy_surface()
1161 if (pipe_reference(&(*ptr)->reference, &surf->reference)) in vrend_surface_reference()
1168 if (samp->texture->id != samp->id) in vrend_destroy_sampler_view()
1169 glDeleteTextures(1, &samp->id); in vrend_destroy_sampler_view()
1170 vrend_resource_reference(&samp->texture, NULL); in vrend_destroy_sampler_view()
1179 if (pipe_reference(&(*ptr)->reference, &view->reference)) in vrend_sampler_view_reference()
1186 vrend_resource_reference(&target->buffer, NULL); in vrend_destroy_so_target()
1195 if (pipe_reference(&(*ptr)->reference, &target->reference)) in vrend_so_target_reference()
1202 const char *prefix = pipe_shader_to_prefix(shader->sel->type); in vrend_shader_dump()
1203 if (shader->sel->tmp_buf) in vrend_shader_dump()
1204 vrend_printf("%s: %d TGSI:\n%s\n", prefix, shader->id, shader->sel->tmp_buf); in vrend_shader_dump()
1206 vrend_printf("%s: %d GLSL:\n", prefix, shader->id); in vrend_shader_dump()
1207 strarray_dump_with_line_numbers(&shader->glsl_strings); in vrend_shader_dump()
1215 LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, &shader->programs, sl[shader->sel->type]) { in vrend_shader_destroy()
1219 if (shader->sel->sinfo.separable_program) in vrend_shader_destroy()
1220 glDeleteProgram(shader->program_id); in vrend_shader_destroy()
1221 glDeleteShader(shader->id); in vrend_shader_destroy()
1222 strarray_free(&shader->glsl_strings, true); in vrend_shader_destroy()
1228 struct vrend_shader *p = sel->current, *c; in vrend_destroy_shader_selector()
1231 c = p->next_variant; in vrend_destroy_shader_selector()
1235 if (sel->sinfo.so_names) in vrend_destroy_shader_selector()
1236 for (i = 0; i < sel->sinfo.so_info.num_outputs; i++) in vrend_destroy_shader_selector()
1237 free(sel->sinfo.so_names[i]); in vrend_destroy_shader_selector()
1238 free(sel->tmp_buf); in vrend_destroy_shader_selector()
1239 free(sel->sinfo.so_names); in vrend_destroy_shader_selector()
1240 free(sel->sinfo.sampler_arrays); in vrend_destroy_shader_selector()
1241 free(sel->sinfo.image_arrays); in vrend_destroy_shader_selector()
1242 free(sel->tokens); in vrend_destroy_shader_selector()
1266 for (int i = 0; i < shader->glsl_strings.num_strings; i++) in vrend_compile_shader()
1267 shader_parts[i] = shader->glsl_strings.strings[i].buf; in vrend_compile_shader()
1269 shader->id = glCreateShader(conv_shader_type(shader->sel->type)); in vrend_compile_shader()
1270 glShaderSource(shader->id, shader->glsl_strings.num_strings, shader_parts, NULL); in vrend_compile_shader()
1271 glCompileShader(shader->id); in vrend_compile_shader()
1272 glGetShaderiv(shader->id, GL_COMPILE_STATUS, ¶m); in vrend_compile_shader()
1276 glGetShaderInfoLog(shader->id, 65536, &len, infolog); in vrend_compile_shader()
1277 vrend_report_context_error(sub_ctx->parent, VIRGL_ERROR_CTX_ILLEGAL_SHADER, 0); in vrend_compile_shader()
1283 if (shader->sel->sinfo.separable_program) { in vrend_compile_shader()
1284 shader->program_id = glCreateProgram(); in vrend_compile_shader()
1285 shader->last_pipeline_id = 0xffffffff; in vrend_compile_shader()
1286 glProgramParameteri(shader->program_id, GL_PROGRAM_SEPARABLE, GL_TRUE); in vrend_compile_shader()
1287 glAttachShader(shader->program_id, shader->id); in vrend_compile_shader()
1290 shader->is_compiled = true; in vrend_compile_shader()
1299 if (pipe_reference(&(*ptr)->reference, &shader->reference)) in vrend_shader_state_reference()
1307 tex_conv_table[entry->format] = *entry; in vrend_insert_format()
1308 tex_conv_table[entry->format].bindings = bindings; in vrend_insert_format()
1309 tex_conv_table[entry->format].flags = flags; in vrend_insert_format()
1338 if (sub_ctx->current_program_id != id) { in use_program()
1339 sub_ctx->current_program_id = id; in use_program()
1346 if (sub_ctx->current_pipeline_id != id) { in bind_pipeline()
1347 sub_ctx->current_pipeline_id = id; in bind_pipeline()
1356 program->is_pipeline ? program->id.pipeline : in vrend_use_program()
1357 program->id.program; in vrend_use_program()
1358 if (program && program->is_pipeline) { in vrend_use_program()
1370 if (ctx->sub->depth_test_enabled != depth_test_enable) { in vrend_depth_test_enable()
1371 ctx->sub->depth_test_enabled = depth_test_enable; in vrend_depth_test_enable()
1385 if (ctx->sub->alpha_test_enabled != alpha_test_enable) { in vrend_alpha_test_enable()
1386 ctx->sub->alpha_test_enabled = alpha_test_enable; in vrend_alpha_test_enable()
1396 if (sub_ctx->stencil_test_enabled != stencil_test_enable) { in vrend_stencil_test_enable()
1397 sub_ctx->stencil_test_enabled = stencil_test_enable; in vrend_stencil_test_enable()
1411 vrend_printf("streamout: %d\n", so->num_outputs); in dump_stream_out()
1414 vrend_printf("%d ", so->stride[i]); in dump_stream_out()
1417 for (i = 0; i < so->num_outputs; i++) { in dump_stream_out()
1420 so->output[i].register_index, in dump_stream_out()
1421 so->output[i].start_component, in dump_stream_out()
1422 so->output[i].num_components, in dump_stream_out()
1423 so->output[i].output_buffer, in dump_stream_out()
1424 so->output[i].dst_offset, in dump_stream_out()
1425 so->output[i].stream); in dump_stream_out()
1439 *skip_val -= 1; in get_skip_str()
1442 *skip_val -= 2; in get_skip_str()
1445 *skip_val -= 3; in get_skip_str()
1448 *skip_val -= 4; in get_skip_str()
1457 struct pipe_stream_output_info *so = &sinfo->so_info; in set_stream_out_varyings()
1465 if (!so->num_outputs) in set_stream_out_varyings()
1468 VREND_DEBUG_EXT(dbg_shader_streamout, sub_ctx->parent, dump_stream_out(so)); in set_stream_out_varyings()
1470 for (i = 0; i < so->num_outputs; i++) { in set_stream_out_varyings()
1471 if (last_buffer != so->output[i].output_buffer) { in set_stream_out_varyings()
1473 skip = so->stride[last_buffer] - buf_offset; in set_stream_out_varyings()
1479 for (j = last_buffer; j < so->output[i].output_buffer; j++) in set_stream_out_varyings()
1481 last_buffer = so->output[i].output_buffer; in set_stream_out_varyings()
1485 skip = so->output[i].dst_offset - buf_offset; in set_stream_out_varyings()
1491 buf_offset = so->output[i].dst_offset; in set_stream_out_varyings()
1493 buf_offset += so->output[i].num_components; in set_stream_out_varyings()
1494 if (sinfo->so_names[i]) in set_stream_out_varyings()
1495 varyings[n_outputs++] = strdup(sinfo->so_names[i]); in set_stream_out_varyings()
1498 skip = so->stride[last_buffer] - buf_offset; in set_stream_out_varyings()
1517 assert(!sprog->is_pipeline || sprog->ss[shader_type]->sel->sinfo.separable_program); in vrend_get_uniform_location()
1519 GLint id = sprog->is_pipeline ? in vrend_get_uniform_location()
1520 sprog->ss[shader_type]->program_id : in vrend_get_uniform_location()
1521 sprog->id.program; in vrend_get_uniform_location()
1529 if (sprog->is_pipeline && sprog->ss[shader_type]) in vrend_set_active_pipeline_stage()
1530 glActiveShaderProgram(sprog->id.pipeline, sprog->ss[shader_type]->program_id); in vrend_set_active_pipeline_stage()
1536 const struct vrend_shader_info *sinfo = &sprog->ss[shader_type]->sel->sinfo; in bind_sampler_locs()
1538 if (sinfo->samplers_used_mask) { in bind_sampler_locs()
1539 uint32_t mask = sinfo->samplers_used_mask; in bind_sampler_locs()
1540 sprog->shadow_samp_mask[shader_type] = sinfo->shadow_samp_mask; in bind_sampler_locs()
1541 if (sinfo->shadow_samp_mask) { in bind_sampler_locs()
1542 unsigned nsamp = util_bitcount(sinfo->samplers_used_mask); in bind_sampler_locs()
1543 sprog->shadow_samp_mask_locs[shader_type] = calloc(nsamp, sizeof(uint32_t)); in bind_sampler_locs()
1544 sprog->shadow_samp_add_locs[shader_type] = calloc(nsamp, sizeof(uint32_t)); in bind_sampler_locs()
1546 … sprog->shadow_samp_mask_locs[shader_type] = sprog->shadow_samp_add_locs[shader_type] = NULL; in bind_sampler_locs()
1553 if (sinfo->num_sampler_arrays) { in bind_sampler_locs()
1555 snprintf(name, 32, "%ssamp%d[%d]", prefix, arr_idx, i - arr_idx); in bind_sampler_locs()
1563 if (sinfo->shadow_samp_mask & (1 << i)) { in bind_sampler_locs()
1565 sprog->shadow_samp_mask_locs[shader_type][sampler_index] = in bind_sampler_locs()
1568 sprog->shadow_samp_add_locs[shader_type][sampler_index] = in bind_sampler_locs()
1574 sprog->shadow_samp_mask_locs[shader_type] = NULL; in bind_sampler_locs()
1575 sprog->shadow_samp_add_locs[shader_type] = NULL; in bind_sampler_locs()
1576 sprog->shadow_samp_mask[shader_type] = 0; in bind_sampler_locs()
1578 sprog->samplers_used_mask[shader_type] = sinfo->samplers_used_mask; in bind_sampler_locs()
1586 if (sprog->ss[shader_type]->sel->sinfo.num_consts) { in bind_const_locs()
1589 sprog->const_location[shader_type] = vrend_get_uniform_location(sprog, name, in bind_const_locs()
1592 sprog->const_location[shader_type] = -1; in bind_const_locs()
1599 assert(!sprog->is_pipeline || sprog->ss[shader_type]->sel->sinfo.separable_program); in vrend_get_uniform_block_index()
1601 GLuint id = sprog->is_pipeline ? in vrend_get_uniform_block_index()
1602 sprog->ss[shader_type]->program_id : in vrend_get_uniform_block_index()
1603 sprog->id.program; in vrend_get_uniform_block_index()
1612 assert(!sprog->is_pipeline || sprog->ss[shader_type]->sel->sinfo.separable_program); in vrend_uniform_block_binding()
1614 GLint id = sprog->is_pipeline ? in vrend_uniform_block_binding()
1615 sprog->ss[shader_type]->program_id : in vrend_uniform_block_binding()
1616 sprog->id.program; in vrend_uniform_block_binding()
1624 const struct vrend_shader_info *sinfo = &sprog->ss[shader_type]->sel->sinfo; in bind_ubo_locs()
1625 if (sinfo->ubo_used_mask) { in bind_ubo_locs()
1628 unsigned mask = sinfo->ubo_used_mask; in bind_ubo_locs()
1632 if (sinfo->ubo_indirect) in bind_ubo_locs()
1633 snprintf(name, 32, "%subo[%d]", prefix, ubo_idx - 1); in bind_ubo_locs()
1642 sprog->ubo_used_mask[shader_type] = sinfo->ubo_used_mask; in bind_ubo_locs()
1651 sprog->separate_virgl_block_id[shader_type] = in bind_virgl_block_loc()
1654 if (sprog->separate_virgl_block_id[shader_type] != GL_INVALID_INDEX) { in bind_virgl_block_loc()
1657 if (sprog->virgl_block_bind == -1) { in bind_virgl_block_loc()
1658 sprog->virgl_block_bind = virgl_block_ubo_id; in bind_virgl_block_loc()
1659 if (sprog->ubo_sysval_buffer_id == -1) { in bind_virgl_block_loc()
1660 glGenBuffers(1, (GLuint *) &sprog->ubo_sysval_buffer_id); in bind_virgl_block_loc()
1667 sprog->separate_virgl_block_id[shader_type], in bind_virgl_block_loc()
1668 sprog->virgl_block_bind); in bind_virgl_block_loc()
1671 int prog_id = sprog->is_pipeline ? sprog->ss[shader_type]->program_id : in bind_virgl_block_loc()
1672 sprog->id.program; in bind_virgl_block_loc()
1673 glGetActiveUniformBlockiv(prog_id, sprog->separate_virgl_block_id[shader_type], in bind_virgl_block_loc()
1678 glBindBuffer(GL_UNIFORM_BUFFER, sprog->ubo_sysval_buffer_id); in bind_virgl_block_loc()
1694 if (!sprog->ss[shader_type]) in rebind_ubo_and_sampler_locs()
1700 if (sprog->is_pipeline) in rebind_ubo_and_sampler_locs()
1701 sprog->ss[shader_type]->last_pipeline_id = sprog->id.pipeline; in rebind_ubo_and_sampler_locs()
1705 sprog->virgl_block_bind = -1; in rebind_ubo_and_sampler_locs()
1709 if (!sprog->ss[shader_type]) in rebind_ubo_and_sampler_locs()
1721 sprog->ssbo_used_mask[shader_type] = sprog->ss[shader_type]->sel->sinfo.ssbo_used_mask; in bind_ssbo_locs()
1730 const struct vrend_shader_info *sinfo = &sprog->ss[shader_type]->sel->sinfo; in bind_image_locs()
1732 uint32_t mask = sinfo->images_used_mask; in bind_image_locs()
1733 if (!mask && !sinfo->num_image_arrays) in bind_image_locs()
1741 sprog->img_locs[shader_type] = calloc(nsamp, sizeof(GLint)); in bind_image_locs()
1742 if (!sprog->img_locs[shader_type]) in bind_image_locs()
1745 sprog->img_locs[shader_type] = NULL; in bind_image_locs()
1747 if (sinfo->num_image_arrays) { in bind_image_locs()
1748 for (i = 0; i < sinfo->num_image_arrays; i++) { in bind_image_locs()
1749 struct vrend_array *img_array = &sinfo->image_arrays[i]; in bind_image_locs()
1750 for (int j = 0; j < img_array->array_size; j++) { in bind_image_locs()
1751 snprintf(name, 32, "%simg%d[%d]", prefix, img_array->first, j); in bind_image_locs()
1752 sprog->img_locs[shader_type][img_array->first + j] = in bind_image_locs()
1754 if (sprog->img_locs[shader_type][img_array->first + j] == -1) in bind_image_locs()
1762 sprog->img_locs[shader_type][i] = in bind_image_locs()
1764 if (sprog->img_locs[shader_type][i] == -1) in bind_image_locs()
1767 sprog->img_locs[shader_type][i] = -1; in bind_image_locs()
1771 sprog->images_used_mask[shader_type] = mask; in bind_image_locs()
1797 set_stream_out_varyings(sub_ctx, shader->program_id, &shader->sel->sinfo); in vrend_link_separable_shader()
1799 if (type == PIPE_SHADER_FRAGMENT && shader->sel->sinfo.num_outputs > 1) { in vrend_link_separable_shader()
1800 bool dual_src_linked = util_blend_state_is_dual(&sub_ctx->blend_state, 0); in vrend_link_separable_shader()
1804 glBindFragDataLocationIndexed(shader->program_id, 0, 0, "fsout_c0"); in vrend_link_separable_shader()
1805 glBindFragDataLocationIndexed(shader->program_id, 0, 1, "fsout_c1"); in vrend_link_separable_shader()
1807 glBindFragDataLocationIndexedEXT(shader->program_id, 0, 0, "fsout_c0"); in vrend_link_separable_shader()
1808 glBindFragDataLocationIndexedEXT(shader->program_id, 0, 1, "fsout_c1"); in vrend_link_separable_shader()
1811 vrend_report_context_error(sub_ctx->parent, VIRGL_ERROR_CTX_ILLEGAL_DUAL_SRC_BLEND, 0); in vrend_link_separable_shader()
1816 for (int i = 0; i < shader->sel->sinfo.num_outputs; ++i) { in vrend_link_separable_shader()
1817 if (shader->sel->sinfo.fs_output_layout[i] >= 0) { in vrend_link_separable_shader()
1820 shader->sel->sinfo.fs_output_layout[i]); in vrend_link_separable_shader()
1821 glBindFragDataLocationIndexed(shader->program_id, in vrend_link_separable_shader()
1822 shader->sel->sinfo.fs_output_layout[i], in vrend_link_separable_shader()
1830 uint32_t mask = shader->sel->sinfo.attrib_input_mask; in vrend_link_separable_shader()
1834 glBindAttribLocation(shader->program_id, i, name); in vrend_link_separable_shader()
1838 shader->is_linked = vrend_link(shader->program_id); in vrend_link_separable_shader()
1840 if (!shader->is_linked) { in vrend_link_separable_shader()
1842 vrend_report_context_error(sub_ctx->parent, VIRGL_ERROR_CTX_ILLEGAL_SHADER, 0); in vrend_link_separable_shader()
1846 return shader->is_linked; in vrend_link_separable_shader()
1855 glAttachShader(prog_id, cs->id); in add_cs_shader_program()
1865 sprog->ss[PIPE_SHADER_COMPUTE] = cs; in add_cs_shader_program()
1867 list_add(&sprog->sl[PIPE_SHADER_COMPUTE], &cs->programs); in add_cs_shader_program()
1868 sprog->id.program = prog_id; in add_cs_shader_program()
1869 list_addtail(&sprog->head, &ctx->sub->cs_programs); in add_cs_shader_program()
1871 vrend_use_program(ctx->sub, sprog); in add_cs_shader_program()
1883 if (!stage->is_linked) in vrend_link_stage()
1884 stage->is_linked = vrend_link(stage->program_id); in vrend_link_stage()
1885 return stage->is_linked; in vrend_link_stage()
1909 vs_id = vs->program_id; in add_shader_program()
1910 fs_id = fs->program_id; in add_shader_program()
1912 gs_id = gs->program_id; in add_shader_program()
1914 tes_id = tes->program_id; in add_shader_program()
1917 glAttachShader(prog_id, vs->id); in add_shader_program()
1918 if (tcs && tcs->id > 0) in add_shader_program()
1919 glAttachShader(prog_id, tcs->id); in add_shader_program()
1920 if (tes && tes->id > 0) in add_shader_program()
1921 glAttachShader(prog_id, tes->id); in add_shader_program()
1922 if (gs && gs->id > 0) in add_shader_program()
1923 glAttachShader(prog_id, gs->id); in add_shader_program()
1924 glAttachShader(prog_id, fs->id); in add_shader_program()
1926 /* For the non-separable codepath (the usual path), all these shader stages are in add_shader_program()
1937 set_stream_out_varyings(sub_ctx, gs_id, &gs->sel->sinfo); in add_shader_program()
1939 set_stream_out_varyings(sub_ctx, tes_id, &tes->sel->sinfo); in add_shader_program()
1941 set_stream_out_varyings(sub_ctx, vs_id, &vs->sel->sinfo); in add_shader_program()
1943 if (fs->sel->sinfo.num_outputs > 1) { in add_shader_program()
1944 sprog->dual_src_linked = util_blend_state_is_dual(&sub_ctx->blend_state, 0); in add_shader_program()
1945 if (sprog->dual_src_linked) { in add_shader_program()
1955 vrend_report_context_error(sub_ctx->parent, VIRGL_ERROR_CTX_ILLEGAL_DUAL_SRC_BLEND, 0); in add_shader_program()
1960 for (int i = 0; i < fs->sel->sinfo.num_outputs; ++i) { in add_shader_program()
1961 if (fs->sel->sinfo.fs_output_layout[i] >= 0) { in add_shader_program()
1963 snprintf(buf, sizeof(buf), "fsout_c%d", fs->sel->sinfo.fs_output_layout[i]); in add_shader_program()
1964 glBindFragDataLocationIndexed(fs_id, fs->sel->sinfo.fs_output_layout[i], 0, buf); in add_shader_program()
1969 sprog->dual_src_linked = false; in add_shader_program()
1972 uint32_t mask = vs->sel->sinfo.attrib_input_mask; in add_shader_program()
1987 } else { /* non-separable programs */ in add_shader_program()
2001 vrend_report_context_error(sub_ctx->parent, VIRGL_ERROR_CTX_ILLEGAL_SHADER, 0); in add_shader_program()
2014 glUseProgramStages(pipeline_id, GL_VERTEX_SHADER_BIT, vs->program_id); in add_shader_program()
2015 if (tcs) glUseProgramStages(pipeline_id, GL_TESS_CONTROL_SHADER_BIT, tcs->program_id); in add_shader_program()
2016 if (tes) glUseProgramStages(pipeline_id, GL_TESS_EVALUATION_SHADER_BIT, tes->program_id); in add_shader_program()
2017 if (gs) glUseProgramStages(pipeline_id, GL_GEOMETRY_SHADER_BIT, gs->program_id); in add_shader_program()
2018 glUseProgramStages(pipeline_id, GL_FRAGMENT_SHADER_BIT, fs->program_id); in add_shader_program()
2024 vrend_report_context_error(sub_ctx->parent, VIRGL_ERROR_CTX_ILLEGAL_PROGRAM_PIPELINE, 0); in add_shader_program()
2028 sprog->ss[PIPE_SHADER_VERTEX] = vs; in add_shader_program()
2029 sprog->ss[PIPE_SHADER_FRAGMENT] = fs; in add_shader_program()
2030 sprog->vs_fs_key = (((uint64_t)fs->id) << 32) | (vs->id & ~VREND_PROGRAM_NQUEUE_MASK) | in add_shader_program()
2031 (sprog->dual_src_linked ? 1 : 0); in add_shader_program()
2033 sprog->ss[PIPE_SHADER_GEOMETRY] = gs; in add_shader_program()
2034 sprog->ss[PIPE_SHADER_TESS_CTRL] = tcs; in add_shader_program()
2035 sprog->ss[PIPE_SHADER_TESS_EVAL] = tes; in add_shader_program()
2037 list_add(&sprog->sl[PIPE_SHADER_VERTEX], &vs->programs); in add_shader_program()
2038 list_add(&sprog->sl[PIPE_SHADER_FRAGMENT], &fs->programs); in add_shader_program()
2040 list_add(&sprog->sl[PIPE_SHADER_GEOMETRY], &gs->programs); in add_shader_program()
2042 list_add(&sprog->sl[PIPE_SHADER_TESS_CTRL], &tcs->programs); in add_shader_program()
2044 list_add(&sprog->sl[PIPE_SHADER_TESS_EVAL], &tes->programs); in add_shader_program()
2048 sprog->is_pipeline = separable; in add_shader_program()
2049 if (sprog->is_pipeline) in add_shader_program()
2050 sprog->id.pipeline = pipeline_id; in add_shader_program()
2052 sprog->id.program = prog_id; in add_shader_program()
2054 list_addtail(&sprog->head, &sub_ctx->gl_programs[vs->id & VREND_PROGRAM_NQUEUE_MASK]); in add_shader_program()
2056 sprog->virgl_block_bind = -1; in add_shader_program()
2057 sprog->ubo_sysval_buffer_id = -1; in add_shader_program()
2064 if (!sprog->ss[shader_type]) in add_shader_program()
2074 if (vs->sel->sinfo.num_inputs) { in add_shader_program()
2075 sprog->attrib_locs = calloc(vs->sel->sinfo.num_inputs, sizeof(uint32_t)); in add_shader_program()
2076 if (sprog->attrib_locs) { in add_shader_program()
2077 for (i = 0; i < vs->sel->sinfo.num_inputs; i++) { in add_shader_program()
2079 sprog->attrib_locs[i] = glGetAttribLocation(vs_id, name); in add_shader_program()
2083 sprog->attrib_locs = NULL; in add_shader_program()
2093 LIST_FOR_EACH_ENTRY(ent, &ctx->sub->cs_programs, head) { in lookup_cs_shader_program()
2094 if (ent->ss[PIPE_SHADER_COMPUTE]->id == cs_id) { in lookup_cs_shader_program()
2095 list_del(&ent->head); in lookup_cs_shader_program()
2096 list_add(&ent->head, &ctx->sub->cs_programs); in lookup_cs_shader_program()
2116 struct list_head *programs = &sub_ctx->gl_programs[vs_id & VREND_PROGRAM_NQUEUE_MASK]; in lookup_shader_program()
2118 if (likely(ent->vs_fs_key != vs_fs_key)) in lookup_shader_program()
2120 if (ent->ss[PIPE_SHADER_GEOMETRY] && in lookup_shader_program()
2121 ent->ss[PIPE_SHADER_GEOMETRY]->id != gs_id) in lookup_shader_program()
2123 if (ent->ss[PIPE_SHADER_TESS_CTRL] && in lookup_shader_program()
2124 ent->ss[PIPE_SHADER_TESS_CTRL]->id != tcs_id) in lookup_shader_program()
2126 if (ent->ss[PIPE_SHADER_TESS_EVAL] && in lookup_shader_program()
2127 ent->ss[PIPE_SHADER_TESS_EVAL]->id != tes_id) in lookup_shader_program()
2130 if (programs->next != &ent->head) { in lookup_shader_program()
2131 list_del(&ent->head); in lookup_shader_program()
2132 list_add(&ent->head, programs); in lookup_shader_program()
2143 if (ent->ref_context && ent->ref_context->prog == ent) in vrend_destroy_program()
2144 ent->ref_context->prog = NULL; in vrend_destroy_program()
2146 if (ent->ubo_sysval_buffer_id != -1) { in vrend_destroy_program()
2147 glDeleteBuffers(1, (GLuint *) &ent->ubo_sysval_buffer_id); in vrend_destroy_program()
2150 if (ent->is_pipeline) in vrend_destroy_program()
2151 glDeleteProgramPipelines(1, &ent->id.pipeline); in vrend_destroy_program()
2153 glDeleteProgram(ent->id.program); in vrend_destroy_program()
2155 list_del(&ent->head); in vrend_destroy_program()
2158 if (ent->ss[i]) in vrend_destroy_program()
2159 list_del(&ent->sl[i]); in vrend_destroy_program()
2160 free(ent->shadow_samp_mask_locs[i]); in vrend_destroy_program()
2161 free(ent->shadow_samp_add_locs[i]); in vrend_destroy_program()
2162 free(ent->img_locs[i]); in vrend_destroy_program()
2164 free(ent->attrib_locs); in vrend_destroy_program()
2172 if (!LIST_IS_EMPTY(&sub->cs_programs)) { in vrend_free_programs()
2173 LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, &sub->cs_programs, head) in vrend_free_programs()
2178 if (!LIST_IS_EMPTY(&sub->gl_programs[i])) { in vrend_free_programs()
2179 LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, &sub->gl_programs[i], head) in vrend_free_programs()
2188 list_del(&obj->head); in vrend_destroy_streamout_object()
2189 for (i = 0; i < obj->num_targets; i++) in vrend_destroy_streamout_object()
2190 vrend_so_target_reference(&obj->so_targets[i], NULL); in vrend_destroy_streamout_object()
2192 glDeleteTransformFeedbacks(1, &obj->id); in vrend_destroy_streamout_object()
2198 vrend_clicbs->make_current(gl_cxt); in vrend_sync_make_current()
2227 surf->res_handle = res_handle; in vrend_create_surface()
2228 surf->format = format; in vrend_create_surface()
2230 surf->val0 = val0; in vrend_create_surface()
2231 surf->val1 = val1; in vrend_create_surface()
2232 surf->id = res->id; in vrend_create_surface()
2233 surf->nr_samples = nr_samples; in vrend_create_surface()
2235 if (!has_bit(res->storage_bits, VREND_STORAGE_GL_BUFFER) && in vrend_create_surface()
2236 has_bit(res->storage_bits, VREND_STORAGE_GL_IMMUTABLE) && in vrend_create_surface()
2246 int first_layer = surf->val1 & 0xffff; in vrend_create_surface()
2247 int last_layer = (surf->val1 >> 16) & 0xffff; in vrend_create_surface()
2250 (first_layer != 0 || (last_layer != (int)util_max_layer(&res->base, surf->val0))); in vrend_create_surface()
2251 if (!needs_view && surf->format != res->base.format) in vrend_create_surface()
2254 if (needs_view && vrend_resource_supports_view(res, surf->format)) { in vrend_create_surface()
2255 GLenum target = res->target; in vrend_create_surface()
2264 util_format_name(res->base.format), in vrend_create_surface()
2265 util_format_name(surf->format)); in vrend_create_surface()
2267 glGenTextures(1, &surf->id); in vrend_create_surface()
2280 glTextureView(surf->id, target, res->id, internalformat, in vrend_create_surface()
2281 0, res->base.last_level + 1, in vrend_create_surface()
2282 first_layer, last_layer - first_layer + 1); in vrend_create_surface()
2286 pipe_reference_init(&surf->reference, 1); in vrend_create_surface()
2288 vrend_resource_reference(&surf->texture, res); in vrend_create_surface()
2315 struct vrend_sub_context *sub_ctx = target->sub_ctx; in vrend_destroy_so_target_object()
2320 LIST_FOR_EACH_ENTRY_SAFE(obj, tmp, &sub_ctx->streamout_list, head) { in vrend_destroy_so_target_object()
2322 for (i = 0; i < obj->num_targets; i++) { in vrend_destroy_so_target_object()
2323 if (obj->so_targets[i] == target) { in vrend_destroy_so_target_object()
2329 if (obj == sub_ctx->current_so) in vrend_destroy_so_target_object()
2330 sub_ctx->current_so = NULL; in vrend_destroy_so_target_object()
2331 if (obj->xfb_state == XFB_STATE_PAUSED) { in vrend_destroy_so_target_object()
2333 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, obj->id); in vrend_destroy_so_target_object()
2335 if (sub_ctx->current_so && has_feature(feat_transform_feedback2)) in vrend_destroy_so_target_object()
2336 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, sub_ctx->current_so->id); in vrend_destroy_so_target_object()
2349 if (v == v->owning_sub->ve) in vrend_destroy_vertex_elements_object()
2350 v->owning_sub->ve = NULL; in vrend_destroy_vertex_elements_object()
2353 glDeleteVertexArrays(1, &v->id); in vrend_destroy_vertex_elements_object()
2363 glDeleteSamplers(2, state->ids); in vrend_destroy_sampler_state_object()
2382 return -1; in convert_wrap()
2432 state->base = *templ; in vrend_create_sampler_state()
2435 glGenSamplers(2, state->ids); in vrend_create_sampler_state()
2438 glSamplerParameteri(state->ids[i], GL_TEXTURE_WRAP_S, convert_wrap(templ->wrap_s)); in vrend_create_sampler_state()
2439 glSamplerParameteri(state->ids[i], GL_TEXTURE_WRAP_T, convert_wrap(templ->wrap_t)); in vrend_create_sampler_state()
2440 glSamplerParameteri(state->ids[i], GL_TEXTURE_WRAP_R, convert_wrap(templ->wrap_r)); in vrend_create_sampler_state()
2441 …glSamplerParameterf(state->ids[i], GL_TEXTURE_MIN_FILTER, convert_min_filter(templ->min_img_filter… in vrend_create_sampler_state()
2442 …glSamplerParameterf(state->ids[i], GL_TEXTURE_MAG_FILTER, convert_mag_filter(templ->mag_img_filter… in vrend_create_sampler_state()
2443 glSamplerParameterf(state->ids[i], GL_TEXTURE_MIN_LOD, templ->min_lod); in vrend_create_sampler_state()
2444 glSamplerParameterf(state->ids[i], GL_TEXTURE_MAX_LOD, templ->max_lod); in vrend_create_sampler_state()
2445 …glSamplerParameteri(state->ids[i], GL_TEXTURE_COMPARE_MODE, templ->compare_mode ? GL_COMPARE_R_TO_… in vrend_create_sampler_state()
2446 … glSamplerParameteri(state->ids[i], GL_TEXTURE_COMPARE_FUNC, GL_NEVER + templ->compare_func); in vrend_create_sampler_state()
2448 if (templ->lod_bias) in vrend_create_sampler_state()
2451 glSamplerParameterf(state->ids[i], GL_TEXTURE_LOD_BIAS, templ->lod_bias); in vrend_create_sampler_state()
2454 if (templ->seamless_cube_map != 0) { in vrend_create_sampler_state()
2458 … glSamplerParameteri(state->ids[i], GL_TEXTURE_CUBE_MAP_SEAMLESS, templ->seamless_cube_map); in vrend_create_sampler_state()
2462 apply_sampler_border_color(state->ids[i], templ->border_color.ui); in vrend_create_sampler_state()
2464 glSamplerParameteri(state->ids[i], GL_TEXTURE_SRGB_DECODE_EXT, in vrend_create_sampler_state()
2472 glDeleteSamplers(2, state->ids); in vrend_create_sampler_state()
2529 pipe_reference_init(&view->reference, 1); in vrend_create_sampler_view()
2530 view->format = format & 0xffffff; in vrend_create_sampler_view()
2532 if (!view->format || view->format >= VIRGL_FORMAT_MAX) { in vrend_create_sampler_view()
2533 vrend_report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_FORMAT, view->format); in vrend_create_sampler_view()
2541 view->format); in vrend_create_sampler_view()
2546 view->target = tgsitargettogltarget(pipe_target, res->base.nr_samples); in vrend_create_sampler_view()
2550 if (view->target == GL_TEXTURE_1D) in vrend_create_sampler_view()
2551 view->target = GL_TEXTURE_2D; in vrend_create_sampler_view()
2552 else if (view->target == GL_TEXTURE_1D_ARRAY) in vrend_create_sampler_view()
2553 view->target = GL_TEXTURE_2D_ARRAY; in vrend_create_sampler_view()
2556 if (view->target == GL_TEXTURE_RECTANGLE_NV && in vrend_create_sampler_view()
2557 !(tex_conv_table[view->format].flags & VIRGL_TEXTURE_CAN_TARGET_RECTANGLE)) { in vrend_create_sampler_view()
2558 view->emulated_rect = true; in vrend_create_sampler_view()
2559 view->target = GL_TEXTURE_2D; in vrend_create_sampler_view()
2562 view->val0 = val0; in vrend_create_sampler_view()
2563 view->val1 = val1; in vrend_create_sampler_view()
2570 vrend_resource_reference(&view->texture, res); in vrend_create_sampler_view()
2572 view->id = view->texture->id; in vrend_create_sampler_view()
2573 if (view->target == PIPE_BUFFER) in vrend_create_sampler_view()
2574 view->target = view->texture->target; in vrend_create_sampler_view()
2576 view->srgb_decode = GL_DECODE_EXT; in vrend_create_sampler_view()
2577 if (view->format != view->texture->base.format) { in vrend_create_sampler_view()
2578 if (util_format_is_srgb(view->texture->base.format) && in vrend_create_sampler_view()
2579 !util_format_is_srgb(view->format)) in vrend_create_sampler_view()
2580 view->srgb_decode = GL_SKIP_DECODE_EXT; in vrend_create_sampler_view()
2583 if (!(util_format_has_alpha(view->format) || util_format_is_depth_or_stencil(view->format))) { in vrend_create_sampler_view()
2594 if (tex_conv_table[view->format].flags & VIRGL_TEXTURE_NEED_SWIZZLE) { in vrend_create_sampler_view()
2596 swizzle[0] = tex_conv_table[view->format].swizzle[swizzle[0]]; in vrend_create_sampler_view()
2598 swizzle[1] = tex_conv_table[view->format].swizzle[swizzle[1]]; in vrend_create_sampler_view()
2600 swizzle[2] = tex_conv_table[view->format].swizzle[swizzle[2]]; in vrend_create_sampler_view()
2602 swizzle[3] = tex_conv_table[view->format].swizzle[swizzle[3]]; in vrend_create_sampler_view()
2606 view->gl_swizzle[i] = to_gl_swizzle(swizzle[i]); in vrend_create_sampler_view()
2608 if (!has_bit(view->texture->storage_bits, VREND_STORAGE_GL_BUFFER)) { in vrend_create_sampler_view()
2617 if (view->target != view->texture->target) in vrend_create_sampler_view()
2630 format = view->format; in vrend_create_sampler_view()
2631 if (util_format_is_depth_or_stencil(view->texture->base.format)) in vrend_create_sampler_view()
2632 format = view->texture->base.format; in vrend_create_sampler_view()
2633 else if (view->format != view->texture->base.format) in vrend_create_sampler_view()
2637 has_bit(view->texture->storage_bits, VREND_STORAGE_GL_IMMUTABLE) && in vrend_create_sampler_view()
2639 glGenTextures(1, &view->id); in vrend_create_sampler_view()
2641 unsigned base_layer = view->val0 & 0xffff; in vrend_create_sampler_view()
2642 unsigned max_layer = (view->val0 >> 16) & 0xffff; in vrend_create_sampler_view()
2643 int base_level = view->val1 & 0xff; in vrend_create_sampler_view()
2644 int max_level = (view->val1 >> 8) & 0xff; in vrend_create_sampler_view()
2645 view->levels = (max_level - base_level) + 1; in vrend_create_sampler_view()
2647 /* texture views for eglimage-backed bgr* resources are usually not in vrend_create_sampler_view()
2648 * supported since they cause unintended red/blue channel-swapping. in vrend_create_sampler_view()
2654 if (!vrend_resource_supports_view(view->texture, view->format) && in vrend_create_sampler_view()
2655 vrend_format_is_bgra(view->format)) { in vrend_create_sampler_view()
2656 …VREND_DEBUG(dbg_tex, ctx, "texture view with red/blue swizzle created for EGL-backed texture sampl… in vrend_create_sampler_view()
2658 util_format_name(view->texture->base.format), in vrend_create_sampler_view()
2659 util_format_name(view->format)); in vrend_create_sampler_view()
2660 GLint temp = view->gl_swizzle[0]; in vrend_create_sampler_view()
2661 view->gl_swizzle[0] = view->gl_swizzle[2]; in vrend_create_sampler_view()
2662 view->gl_swizzle[2] = temp; in vrend_create_sampler_view()
2665 glTextureView(view->id, view->target, view->texture->id, internalformat, in vrend_create_sampler_view()
2666 base_level, view->levels, in vrend_create_sampler_view()
2667 base_layer, max_layer - base_layer + 1); in vrend_create_sampler_view()
2669 glBindTexture(view->target, view->id); in vrend_create_sampler_view()
2671 if (util_format_is_depth_or_stencil(view->format)) { in vrend_create_sampler_view()
2674 glTexParameteri(view->target, GL_DEPTH_TEXTURE_MODE, GL_RED); in vrend_create_sampler_view()
2677 const struct util_format_description *desc = util_format_description(view->format); in vrend_create_sampler_view()
2679 glTexParameteri(view->target, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_INDEX); in vrend_create_sampler_view()
2681 glTexParameteri(view->target, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_DEPTH_COMPONENT); in vrend_create_sampler_view()
2686 glTexParameteri(view->target, GL_TEXTURE_BASE_LEVEL, base_level); in vrend_create_sampler_view()
2687 glTexParameteri(view->target, GL_TEXTURE_MAX_LEVEL, max_level); in vrend_create_sampler_view()
2690 glTexParameteri(view->target, GL_TEXTURE_SWIZZLE_R + i, view->gl_swizzle[i]); in vrend_create_sampler_view()
2693 glTexParameteriv(view->target, GL_TEXTURE_SWIZZLE_RGBA, view->gl_swizzle); in vrend_create_sampler_view()
2694 if (util_format_is_srgb(view->format) && in vrend_create_sampler_view()
2696 glTexParameteri(view->target, GL_TEXTURE_SRGB_DECODE_EXT, in vrend_create_sampler_view()
2697 view->srgb_decode); in vrend_create_sampler_view()
2699 glBindTexture(view->target, 0); in vrend_create_sampler_view()
2700 } else if (needs_view && view->val0 < ARRAY_SIZE(res->aux_plane_egl_image) && in vrend_create_sampler_view()
2701 res->aux_plane_egl_image[view->val0]) { in vrend_create_sampler_view()
2702 void *image = res->aux_plane_egl_image[view->val0]; in vrend_create_sampler_view()
2703 glGenTextures(1, &view->id); in vrend_create_sampler_view()
2704 glBindTexture(view->target, view->id); in vrend_create_sampler_view()
2705 glEGLImageTargetTexture2DOES(view->target, (GLeglImageOES) image); in vrend_create_sampler_view()
2706 glBindTexture(view->target, 0); in vrend_create_sampler_view()
2726 /* fallback to non-msaa */ in vrend_framebuffer_texture_2d()
2736 glGenRenderbuffers(1, &res->rbo_id); in vrend_framebuffer_texture_2d()
2737 glBindRenderbuffer(GL_RENDERBUFFER, res->rbo_id); in vrend_framebuffer_texture_2d()
2739 internalformat, res->base.width0, in vrend_framebuffer_texture_2d()
2740 res->base.height0); in vrend_framebuffer_texture_2d()
2742 GL_RENDERBUFFER, res->rbo_id); in vrend_framebuffer_texture_2d()
2745 /* unsupported attachment for EXT_multisampled_render_to_texture, fallback to non-msaa */ in vrend_framebuffer_texture_2d()
2754 ASSERTED const struct pipe_resource *pr = >->base; in debug_texture() local
2758 switch (tgsitargettogltarget(pr->target, pr->nr_samples)) { in debug_texture()
2772 gt->id, pr->target, pr->nr_samples, util_format_name(pr->format), in debug_texture()
2773 pr->width0, pr->height0, pr->depth0, pr->last_level); in debug_texture()
2782 const struct util_format_description *desc = util_format_description(res->base.format); in vrend_fb_bind_texture_id()
2787 if (vrend_format_is_ds(res->base.format)) { in vrend_fb_bind_texture_id()
2797 switch (res->target) { in vrend_fb_bind_texture_id()
2815 res->target, id, level, layer); in vrend_fb_bind_texture_id()
2818 res->target, id, level, layer); in vrend_fb_bind_texture_id()
2831 res->target, id, level); in vrend_fb_bind_texture_id()
2836 res->target, id, level, samples); in vrend_fb_bind_texture_id()
2841 switch (res->target) { in vrend_fb_bind_texture_id()
2859 vrend_fb_bind_texture_id(res, res->id, idx, level, layer, 0); in vrend_fb_bind_texture()
2864 struct vrend_surface *surf = ctx->sub->zsurf; in vrend_hw_set_zsurf_texture()
2870 uint32_t first_layer = surf->val1 & 0xffff; in vrend_hw_set_zsurf_texture()
2871 uint32_t last_layer = (surf->val1 >> 16) & 0xffff; in vrend_hw_set_zsurf_texture()
2873 if (!surf->texture) in vrend_hw_set_zsurf_texture()
2876 vrend_fb_bind_texture_id(surf->texture, surf->id, 0, surf->val0, in vrend_hw_set_zsurf_texture()
2878 surf->nr_samples); in vrend_hw_set_zsurf_texture()
2884 struct vrend_surface *surf = sub_ctx->surf[index]; in vrend_hw_set_color_surface()
2892 uint32_t first_layer = sub_ctx->surf[index]->val1 & 0xffff; in vrend_hw_set_color_surface()
2893 uint32_t last_layer = (sub_ctx->surf[index]->val1 >> 16) & 0xffff; in vrend_hw_set_color_surface()
2895 vrend_fb_bind_texture_id(surf->texture, surf->id, index, surf->val0, in vrend_hw_set_color_surface()
2897 surf->nr_samples); in vrend_hw_set_color_surface()
2914 if (sub_ctx->nr_cbufs == 0) { in vrend_hw_emit_framebuffer_state()
2918 sub_ctx->framebuffer_srgb_enabled = false; in vrend_hw_emit_framebuffer_state()
2924 for (i = 0; i < sub_ctx->nr_cbufs; i++) { in vrend_hw_emit_framebuffer_state()
2925 if (sub_ctx->surf[i]) { in vrend_hw_emit_framebuffer_state()
2926 surf = sub_ctx->surf[i]; in vrend_hw_emit_framebuffer_state()
2927 if (util_format_is_srgb(surf->format)) { in vrend_hw_emit_framebuffer_state()
2938 sub_ctx->framebuffer_srgb_enabled = use_srgb; in vrend_hw_emit_framebuffer_state()
2941 sub_ctx->swizzle_output_rgb_to_bgr = 0; in vrend_hw_emit_framebuffer_state()
2942 sub_ctx->needs_manual_srgb_encode_bitmask = 0; in vrend_hw_emit_framebuffer_state()
2943 for (int i = 0; i < sub_ctx->nr_cbufs; i++) { in vrend_hw_emit_framebuffer_state()
2944 struct vrend_surface *surf = sub_ctx->surf[i]; in vrend_hw_emit_framebuffer_state()
2948 /* glTextureView() is not applied to eglimage-backed surfaces, because it in vrend_hw_emit_framebuffer_state()
2953 if (vrend_resource_needs_redblue_swizzle(surf->texture, surf->format)) in vrend_hw_emit_framebuffer_state()
2954 sub_ctx->swizzle_output_rgb_to_bgr |= 1 << i; in vrend_hw_emit_framebuffer_state()
2956 /* glTextureView() on eglimage-backed bgr* textures for is not supported. in vrend_hw_emit_framebuffer_state()
2960 if (util_format_is_srgb(surf->format) && in vrend_hw_emit_framebuffer_state()
2961 !vrend_resource_supports_view(surf->texture, surf->format)) { in vrend_hw_emit_framebuffer_state()
2962 VREND_DEBUG(dbg_tex, sub_ctx->parent, in vrend_hw_emit_framebuffer_state()
2963 … "manually converting linear->srgb for EGL-backed framebuffer color attachment 0x%x" in vrend_hw_emit_framebuffer_state()
2965 … i, util_format_name(surf->format), util_format_name(surf->texture->base.format)); in vrend_hw_emit_framebuffer_state()
2966 sub_ctx->needs_manual_srgb_encode_bitmask |= 1 << i; in vrend_hw_emit_framebuffer_state()
2970 glDrawBuffers(sub_ctx->nr_cbufs, buffers); in vrend_hw_emit_framebuffer_state()
2981 GLint new_height = -1; in vrend_set_framebuffer_state()
2984 struct vrend_sub_context *sub_ctx = ctx->sub; in vrend_set_framebuffer_state()
2986 glBindFramebuffer(GL_FRAMEBUFFER, sub_ctx->fb_id); in vrend_set_framebuffer_state()
2989 zsurf = vrend_object_lookup(sub_ctx->object_hash, zsurf_handle, VIRGL_OBJECT_SURFACE); in vrend_set_framebuffer_state()
2997 if (sub_ctx->zsurf != zsurf) { in vrend_set_framebuffer_state()
2998 vrend_surface_reference(&sub_ctx->zsurf, zsurf); in vrend_set_framebuffer_state()
3002 old_num = sub_ctx->nr_cbufs; in vrend_set_framebuffer_state()
3003 sub_ctx->nr_cbufs = nr_cbufs; in vrend_set_framebuffer_state()
3007 surf = vrend_object_lookup(sub_ctx->object_hash, surf_handle[i], VIRGL_OBJECT_SURFACE); in vrend_set_framebuffer_state()
3015 if (sub_ctx->surf[i] != surf) { in vrend_set_framebuffer_state()
3016 vrend_surface_reference(&sub_ctx->surf[i], surf); in vrend_set_framebuffer_state()
3021 if (old_num > sub_ctx->nr_cbufs) { in vrend_set_framebuffer_state()
3022 for (i = sub_ctx->nr_cbufs; i < old_num; i++) { in vrend_set_framebuffer_state()
3023 vrend_surface_reference(&sub_ctx->surf[i], NULL); in vrend_set_framebuffer_state()
3029 if (sub_ctx->nr_cbufs == 0 && !sub_ctx->zsurf) { in vrend_set_framebuffer_state()
3032 } else if (sub_ctx->nr_cbufs == 0) { in vrend_set_framebuffer_state()
3033 new_height = u_minify(sub_ctx->zsurf->texture->base.height0, sub_ctx->zsurf->val0); in vrend_set_framebuffer_state()
3034 new_fbo_origin_upper_left = sub_ctx->zsurf->texture->y_0_top ? true : false; in vrend_set_framebuffer_state()
3038 for (i = 0; i < sub_ctx->nr_cbufs; i++) { in vrend_set_framebuffer_state()
3039 if (sub_ctx->surf[i]) { in vrend_set_framebuffer_state()
3040 surf = sub_ctx->surf[i]; in vrend_set_framebuffer_state()
3048 new_height = u_minify(surf->texture->base.height0, surf->val0); in vrend_set_framebuffer_state()
3049 new_fbo_origin_upper_left = surf->texture->y_0_top ? true : false; in vrend_set_framebuffer_state()
3052 if (new_height != -1) { in vrend_set_framebuffer_state()
3053 if (sub_ctx->fb_height != (uint32_t)new_height || in vrend_set_framebuffer_state()
3054 sub_ctx->fbo_origin_upper_left != new_fbo_origin_upper_left) { in vrend_set_framebuffer_state()
3055 sub_ctx->fb_height = new_height; in vrend_set_framebuffer_state()
3056 sub_ctx->fbo_origin_upper_left = new_fbo_origin_upper_left; in vrend_set_framebuffer_state()
3057 sub_ctx->viewport_state_dirty = (1 << 0); in vrend_set_framebuffer_state()
3063 if (sub_ctx->nr_cbufs > 0 || sub_ctx->zsurf) { in vrend_set_framebuffer_state()
3066 vrend_printf("failed to complete framebuffer 0x%x %s\n", status, ctx->debug_name); in vrend_set_framebuffer_state()
3069 sub_ctx->shader_dirty = true; in vrend_set_framebuffer_state()
3070 sub_ctx->blend_state_dirty = true; in vrend_set_framebuffer_state()
3109 start_slot > (PIPE_MAX_VIEWPORTS - num_viewports)) { in vrend_set_viewport_states()
3120 x = state[i].translate[0] - state[i].scale[0]; in vrend_set_viewport_states()
3121 y = state[i].translate[1] - state[i].scale[1]; in vrend_set_viewport_states()
3123 if (!ctx->sub->rs_state.clip_halfz) { in vrend_set_viewport_states()
3124 near_val = state[i].translate[2] - state[i].scale[2]; in vrend_set_viewport_states()
3131 if (ctx->sub->vps[idx].cur_x != x || in vrend_set_viewport_states()
3132 ctx->sub->vps[idx].cur_y != y || in vrend_set_viewport_states()
3133 ctx->sub->vps[idx].width != width || in vrend_set_viewport_states()
3134 ctx->sub->vps[idx].height != height || in vrend_set_viewport_states()
3135 ctx->sub->vps[idx].near_val != near_val || in vrend_set_viewport_states()
3136 ctx->sub->vps[idx].far_val != far_val || in vrend_set_viewport_states()
3137 (!(ctx->sub->viewport_state_initialized &= (1 << idx)))) { in vrend_set_viewport_states()
3138 ctx->sub->vps[idx].cur_x = x; in vrend_set_viewport_states()
3139 ctx->sub->vps[idx].cur_y = y; in vrend_set_viewport_states()
3140 ctx->sub->vps[idx].width = width; in vrend_set_viewport_states()
3141 ctx->sub->vps[idx].height = height; in vrend_set_viewport_states()
3142 ctx->sub->vps[idx].near_val = near_val; in vrend_set_viewport_states()
3143 ctx->sub->vps[idx].far_val = far_val; in vrend_set_viewport_states()
3144 ctx->sub->viewport_state_dirty |= (1 << idx); in vrend_set_viewport_states()
3148 if (ctx->sub->viewport_is_negative != viewport_is_negative) { in vrend_set_viewport_states()
3149 ctx->sub->viewport_is_negative = viewport_is_negative; in vrend_set_viewport_states()
3150 ctx->sub->sysvalue_data.winsys_adjust_y = in vrend_set_viewport_states()
3151 viewport_is_negative ? -1.f : 1.f; in vrend_set_viewport_states()
3152 ctx->sub->sysvalue_data_cookie++; in vrend_set_viewport_states()
3185 v->count = num_elements; in vrend_create_vertex_elements_state()
3187 memcpy(&v->elements[i].base, &elements[i], sizeof(struct pipe_vertex_element)); in vrend_create_vertex_elements_state()
3196 switch (desc->channel[0].type) { in vrend_create_vertex_elements_state()
3198 switch (desc->channel[0].size) { in vrend_create_vertex_elements_state()
3205 switch (desc->channel[0].size) { in vrend_create_vertex_elements_state()
3212 switch (desc->channel[0].size) { in vrend_create_vertex_elements_state()
3245 v->elements[i].type = type; in vrend_create_vertex_elements_state()
3246 if (desc->channel[0].normalized) in vrend_create_vertex_elements_state()
3247 v->elements[i].norm = GL_TRUE; in vrend_create_vertex_elements_state()
3249 v->elements[i].nr_chan = 3; in vrend_create_vertex_elements_state()
3251 v->elements[i].nr_chan = desc->nr_channels; in vrend_create_vertex_elements_state()
3253 if (desc->nr_channels == 4 && desc->swizzle[0] == UTIL_FORMAT_SWIZZLE_Z) in vrend_create_vertex_elements_state()
3254 v->zyxw_bitmask |= 1 << i; in vrend_create_vertex_elements_state()
3258 glGenVertexArrays(1, &v->id); in vrend_create_vertex_elements_state()
3259 glBindVertexArray(v->id); in vrend_create_vertex_elements_state()
3261 struct vrend_vertex_element *ve = &v->elements[i]; in vrend_create_vertex_elements_state()
3262 GLint size = !vrend_state.use_gles && (v->zyxw_bitmask & (1 << i)) ? GL_BGRA : ve->nr_chan; in vrend_create_vertex_elements_state()
3264 if (util_format_is_pure_integer(ve->base.src_format)) { in vrend_create_vertex_elements_state()
3265 UPDATE_INT_SIGN_MASK(ve->base.src_format, i, in vrend_create_vertex_elements_state()
3266 v->signed_int_bitmask, in vrend_create_vertex_elements_state()
3267 v->unsigned_int_bitmask); in vrend_create_vertex_elements_state()
3268 glVertexAttribIFormat(i, size, ve->type, ve->base.src_offset); in vrend_create_vertex_elements_state()
3271 glVertexAttribFormat(i, size, ve->type, ve->norm, ve->base.src_offset); in vrend_create_vertex_elements_state()
3272 glVertexAttribBinding(i, ve->base.vertex_buffer_index); in vrend_create_vertex_elements_state()
3273 glVertexBindingDivisor(i, ve->base.instance_divisor); in vrend_create_vertex_elements_state()
3283 v->owning_sub = ctx->sub; in vrend_create_vertex_elements_state()
3293 ctx->sub->ve = NULL; in vrend_bind_vertex_elements_state()
3296 v = vrend_object_lookup(ctx->sub->object_hash, handle, VIRGL_OBJECT_VERTEX_ELEMENTS); in vrend_bind_vertex_elements_state()
3302 if (ctx->sub->ve != v) in vrend_bind_vertex_elements_state()
3303 ctx->sub->vbo_dirty = true; in vrend_bind_vertex_elements_state()
3304 ctx->sub->ve = v; in vrend_bind_vertex_elements_state()
3314 consts = &ctx->sub->consts[shader]; in vrend_set_constants()
3315 ctx->sub->const_dirty[shader] = true; in vrend_set_constants()
3318 if (consts->num_allocated_consts < num_constant) { in vrend_set_constants()
3319 free(consts->consts); in vrend_set_constants()
3320 consts->consts = malloc(num_constant * sizeof(float)); in vrend_set_constants()
3321 if (!consts->consts) in vrend_set_constants()
3323 consts->num_allocated_consts = num_constant; in vrend_set_constants()
3326 memcpy(consts->consts, data, num_constant * sizeof(unsigned int)); in vrend_set_constants()
3327 consts->num_consts = num_constant; in vrend_set_constants()
3339 struct pipe_constant_buffer *cbs = &ctx->sub->cbs[shader][index]; in vrend_set_uniform_buffer()
3349 cbs->buffer = (struct pipe_resource *)res; in vrend_set_uniform_buffer()
3350 cbs->buffer_offset = offset; in vrend_set_uniform_buffer()
3351 cbs->buffer_size = length; in vrend_set_uniform_buffer()
3352 ctx->sub->const_bufs_used_mask[shader] |= mask; in vrend_set_uniform_buffer()
3354 cbs->buffer = NULL; in vrend_set_uniform_buffer()
3355 cbs->buffer_offset = 0; in vrend_set_uniform_buffer()
3356 cbs->buffer_size = 0; in vrend_set_uniform_buffer()
3357 ctx->sub->const_bufs_used_mask[shader] &= ~mask; in vrend_set_uniform_buffer()
3359 ctx->sub->const_bufs_dirty[shader] |= mask; in vrend_set_uniform_buffer()
3369 ctx->sub->ib.index_size = index_size; in vrend_set_index_buffer()
3370 ctx->sub->ib.offset = offset; in vrend_set_index_buffer()
3372 if (ctx->sub->index_buffer_res_id != res_handle) { in vrend_set_index_buffer()
3375 vrend_resource_reference((struct vrend_resource **)&ctx->sub->ib.buffer, NULL); in vrend_set_index_buffer()
3376 ctx->sub->index_buffer_res_id = 0; in vrend_set_index_buffer()
3380 vrend_resource_reference((struct vrend_resource **)&ctx->sub->ib.buffer, res); in vrend_set_index_buffer()
3381 ctx->sub->index_buffer_res_id = res_handle; in vrend_set_index_buffer()
3384 vrend_resource_reference((struct vrend_resource **)&ctx->sub->ib.buffer, NULL); in vrend_set_index_buffer()
3385 ctx->sub->index_buffer_res_id = 0; in vrend_set_index_buffer()
3396 struct vrend_vertex_buffer *vbo = &ctx->sub->vbo[index]; in vrend_set_single_vbo()
3398 if (vbo->base.stride != stride || in vrend_set_single_vbo()
3399 vbo->base.buffer_offset != buffer_offset || in vrend_set_single_vbo()
3400 vbo->res_id != res_handle) in vrend_set_single_vbo()
3401 ctx->sub->vbo_dirty = true; in vrend_set_single_vbo()
3403 vbo->base.stride = stride; in vrend_set_single_vbo()
3404 vbo->base.buffer_offset = buffer_offset; in vrend_set_single_vbo()
3407 vrend_resource_reference((struct vrend_resource **)&vbo->base.buffer, NULL); in vrend_set_single_vbo()
3408 vbo->res_id = 0; in vrend_set_single_vbo()
3409 } else if (vbo->res_id != res_handle) { in vrend_set_single_vbo()
3413 vbo->res_id = 0; in vrend_set_single_vbo()
3416 vrend_resource_reference((struct vrend_resource **)&vbo->base.buffer, res); in vrend_set_single_vbo()
3417 vbo->res_id = res_handle; in vrend_set_single_vbo()
3424 int old_num = sub->num_vbos; in vrend_set_num_vbo_sub()
3427 sub->num_vbos = num_vbo; in vrend_set_num_vbo_sub()
3428 sub->old_num_vbos = old_num; in vrend_set_num_vbo_sub()
3431 sub->vbo_dirty = true; in vrend_set_num_vbo_sub()
3434 vrend_resource_reference((struct vrend_resource **)&sub->vbo[i].base.buffer, NULL); in vrend_set_num_vbo_sub()
3435 sub->vbo[i].res_id = 0; in vrend_set_num_vbo_sub()
3443 vrend_set_num_vbo_sub(ctx->sub, num_vbo); in vrend_set_num_vbo()
3497 view = vrend_object_lookup(ctx->sub->object_hash, handle, VIRGL_OBJECT_SAMPLER_VIEW); in vrend_set_single_sampler_view()
3499 ctx->sub->views[shader_type].views[index] = NULL; in vrend_set_single_sampler_view()
3503 if (ctx->sub->views[shader_type].views[index] == view) { in vrend_set_single_sampler_view()
3507 tex = (struct vrend_texture *)view->texture; in vrend_set_single_sampler_view()
3512 ctx->sub->sampler_views_dirty[shader_type] |= 1u << index; in vrend_set_single_sampler_view()
3514 if (!has_bit(view->texture->storage_bits, VREND_STORAGE_GL_BUFFER)) { in vrend_set_single_sampler_view()
3515 if (view->texture->id == view->id) { in vrend_set_single_sampler_view()
3516 glBindTexture(view->target, view->id); in vrend_set_single_sampler_view()
3518 if (util_format_is_depth_or_stencil(view->format)) { in vrend_set_single_sampler_view()
3521 glTexParameteri(view->texture->target, GL_DEPTH_TEXTURE_MODE, GL_RED); in vrend_set_single_sampler_view()
3524 … const struct util_format_description *desc = util_format_description(view->format); in vrend_set_single_sampler_view()
3526 … glTexParameteri(view->texture->target, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_INDEX); in vrend_set_single_sampler_view()
3528 … glTexParameteri(view->texture->target, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_DEPTH_COMPONENT); in vrend_set_single_sampler_view()
3533 GLuint base_level = view->val1 & 0xff; in vrend_set_single_sampler_view()
3534 GLuint max_level = (view->val1 >> 8) & 0xff; in vrend_set_single_sampler_view()
3535 view->levels = max_level - base_level + 1; in vrend_set_single_sampler_view()
3537 if (tex->cur_base != base_level) { in vrend_set_single_sampler_view()
3538 glTexParameteri(view->texture->target, GL_TEXTURE_BASE_LEVEL, base_level); in vrend_set_single_sampler_view()
3539 tex->cur_base = base_level; in vrend_set_single_sampler_view()
3541 if (tex->cur_max != max_level) { in vrend_set_single_sampler_view()
3542 glTexParameteri(view->texture->target, GL_TEXTURE_MAX_LEVEL, max_level); in vrend_set_single_sampler_view()
3543 tex->cur_max = max_level; in vrend_set_single_sampler_view()
3545 if (memcmp(tex->cur_swizzle, view->gl_swizzle, 4 * sizeof(GLint))) { in vrend_set_single_sampler_view()
3548 if (tex->cur_swizzle[i] != view->gl_swizzle[i]) { in vrend_set_single_sampler_view()
3549 … glTexParameteri(view->texture->target, GL_TEXTURE_SWIZZLE_R + i, view->gl_swizzle[i]); in vrend_set_single_sampler_view()
3553 … glTexParameteriv(view->texture->target, GL_TEXTURE_SWIZZLE_RGBA, view->gl_swizzle); in vrend_set_single_sampler_view()
3554 memcpy(tex->cur_swizzle, view->gl_swizzle, 4 * sizeof(GLint)); in vrend_set_single_sampler_view()
3557 … if (tex->cur_srgb_decode != view->srgb_decode && util_format_is_srgb(tex->base.base.format)) { in vrend_set_single_sampler_view()
3559 ctx->sub->sampler_views_dirty[shader_type] |= (1u << index); in vrend_set_single_sampler_view()
3561 glTexParameteri(view->texture->target, GL_TEXTURE_SRGB_DECODE_EXT, in vrend_set_single_sampler_view()
3562 view->srgb_decode); in vrend_set_single_sampler_view()
3563 tex->cur_srgb_decode = view->srgb_decode; in vrend_set_single_sampler_view()
3570 if (!view->texture->tbo_tex_id) in vrend_set_single_sampler_view()
3571 glGenTextures(1, &view->texture->tbo_tex_id); in vrend_set_single_sampler_view()
3573 glBindTexture(GL_TEXTURE_BUFFER, view->texture->tbo_tex_id); in vrend_set_single_sampler_view()
3574 internalformat = tex_conv_table[view->format].internalformat; in vrend_set_single_sampler_view()
3578 internalformat = vrend_get_arb_format(view->format); in vrend_set_single_sampler_view()
3582 unsigned offset = view->val0; in vrend_set_single_sampler_view()
3583 unsigned size = view->val1 - view->val0 + 1; in vrend_set_single_sampler_view()
3584 int blsize = util_format_get_blocksize(view->format); in vrend_set_single_sampler_view()
3587 size = vrend_state.max_texture_buffer_size - offset; in vrend_set_single_sampler_view()
3590 glTexBufferRange(GL_TEXTURE_BUFFER, internalformat, view->texture->id, offset, size); in vrend_set_single_sampler_view()
3592 glTexBuffer(GL_TEXTURE_BUFFER, internalformat, view->texture->id); in vrend_set_single_sampler_view()
3596 vrend_sampler_view_reference(&ctx->sub->views[shader_type].views[index], view); in vrend_set_single_sampler_view()
3607 for (i = last_slot; i < ctx->sub->views[shader_type].num_views; i++) in vrend_set_num_sampler_views()
3608 vrend_sampler_view_reference(&ctx->sub->views[shader_type].views[i], NULL); in vrend_set_num_sampler_views()
3610 ctx->sub->views[shader_type].num_views = last_slot; in vrend_set_num_sampler_views()
3620 struct vrend_image_view *iview = &ctx->sub->image_views[shader_type][index]; in vrend_set_single_image_view()
3632 iview->texture = res; in vrend_set_single_image_view()
3633 iview->vformat = format; in vrend_set_single_image_view()
3634 iview->format = tex_conv_table[format].internalformat; in vrend_set_single_image_view()
3635 iview->access = access; in vrend_set_single_image_view()
3636 iview->u.buf.offset = layer_offset; in vrend_set_single_image_view()
3637 iview->u.buf.size = level_size; in vrend_set_single_image_view()
3638 ctx->sub->images_used_mask[shader_type] |= (1u << index); in vrend_set_single_image_view()
3640 iview->texture = NULL; in vrend_set_single_image_view()
3641 iview->format = 0; in vrend_set_single_image_view()
3642 ctx->sub->images_used_mask[shader_type] &= ~(1u << index); in vrend_set_single_image_view()
3652 struct vrend_ssbo *ssbo = &ctx->sub->ssbo[shader_type][index]; in vrend_set_single_ssbo()
3664 ssbo->res = res; in vrend_set_single_ssbo()
3665 ssbo->buffer_offset = offset; in vrend_set_single_ssbo()
3666 ssbo->buffer_size = length; in vrend_set_single_ssbo()
3667 ctx->sub->ssbo_used_mask[shader_type] |= (1u << index); in vrend_set_single_ssbo()
3669 ssbo->res = 0; in vrend_set_single_ssbo()
3670 ssbo->buffer_offset = 0; in vrend_set_single_ssbo()
3671 ssbo->buffer_size = 0; in vrend_set_single_ssbo()
3672 ctx->sub->ssbo_used_mask[shader_type] &= ~(1u << index); in vrend_set_single_ssbo()
3681 struct vrend_abo *abo = &ctx->sub->abo[index]; in vrend_set_single_abo()
3693 abo->res = res; in vrend_set_single_abo()
3694 abo->buffer_offset = offset; in vrend_set_single_abo()
3695 abo->buffer_size = length; in vrend_set_single_abo()
3696 ctx->sub->abo_used_mask |= (1u << index); in vrend_set_single_abo()
3698 abo->res = 0; in vrend_set_single_abo()
3699 abo->buffer_offset = 0; in vrend_set_single_abo()
3700 abo->buffer_size = 0; in vrend_set_single_abo()
3701 ctx->sub->abo_used_mask &= ~(1u << index); in vrend_set_single_abo()
3783 enum pipe_shader_type type = sel->type; in vrend_sync_shader_io()
3792 if (sub_ctx->shaders[type] == sel) { in vrend_sync_shader_io()
3795 if (key->tcs_present || key->tes_present) in vrend_sync_shader_io()
3799 if (key->gs_present) in vrend_sync_shader_io()
3801 else if (key->tcs_present || key->tes_present) in vrend_sync_shader_io()
3805 if (key->tcs_present) in vrend_sync_shader_io()
3814 …struct vrend_shader_selector *prev = prev_type != PIPE_SHADER_INVALID ? sub_ctx->shaders[prev_type… in vrend_sync_shader_io()
3817 if (!prev->sinfo.separable_program || !sel->sinfo.separable_program) { in vrend_sync_shader_io()
3818 key->require_input_arrays = prev->sinfo.has_output_arrays; in vrend_sync_shader_io()
3819 key->in_generic_expected_mask = prev->sinfo.out_generic_emitted_mask; in vrend_sync_shader_io()
3820 key->in_texcoord_expected_mask = prev->sinfo.out_texcoord_emitted_mask; in vrend_sync_shader_io()
3821 key->in_patch_expected_mask = prev->sinfo.out_patch_emitted_mask; in vrend_sync_shader_io()
3822 key->in_arrays = prev->sinfo.output_arrays; in vrend_sync_shader_io()
3824 memcpy(key->force_invariant_inputs, prev->sinfo.invariant_outputs, 4 * sizeof(uint32_t)); in vrend_sync_shader_io()
3827 key->num_in_clip = sub_ctx->shaders[prev_type]->current->var_sinfo.num_out_clip; in vrend_sync_shader_io()
3828 key->num_in_cull = sub_ctx->shaders[prev_type]->current->var_sinfo.num_out_cull; in vrend_sync_shader_io()
3831 …key->fs.available_color_in_bits = sub_ctx->shaders[prev_type]->current->var_sinfo.legacy_color_bit… in vrend_sync_shader_io()
3837 key->fs.lower_left_origin = !sub_ctx->fbo_origin_upper_left; in vrend_sync_shader_io()
3838 key->fs.swizzle_output_rgb_to_bgr = sub_ctx->swizzle_output_rgb_to_bgr; in vrend_sync_shader_io()
3839 key->fs.needs_manual_srgb_encode_bitmask = sub_ctx->needs_manual_srgb_encode_bitmask; in vrend_sync_shader_io()
3840 if (vrend_state.use_gles && can_emulate_logicop(sub_ctx->blend_state.logicop_func)) { in vrend_sync_shader_io()
3841 key->fs.logicop_enabled = sub_ctx->blend_state.logicop_enable; in vrend_sync_shader_io()
3842 key->fs.logicop_func = sub_ctx->blend_state.logicop_func; in vrend_sync_shader_io()
3844 int fs_prim_mode = sub_ctx->prim_mode; // inherit draw-call's mode in vrend_sync_shader_io()
3848 switch (prev->type) { in vrend_sync_shader_io()
3850 if (prev->sinfo.tes_point_mode) in vrend_sync_shader_io()
3854 fs_prim_mode = prev->sinfo.gs_out_prim; in vrend_sync_shader_io()
3861 key->fs.prim_is_points = (fs_prim_mode == PIPE_PRIM_POINTS); in vrend_sync_shader_io()
3862 key->fs.coord_replace = sub_ctx->rs_state.point_quad_rasterization in vrend_sync_shader_io()
3863 && key->fs.prim_is_points in vrend_sync_shader_io()
3864 ? sub_ctx->rs_state.sprite_coord_enable in vrend_sync_shader_io()
3868 if (sub_ctx->shaders[PIPE_SHADER_FRAGMENT]) in vrend_sync_shader_io()
3874 if (key->tcs_present) in vrend_sync_shader_io()
3876 else if (key->gs_present) in vrend_sync_shader_io()
3878 else if (key->tes_present) { in vrend_sync_shader_io()
3889 if (key->gs_present) in vrend_sync_shader_io()
3895 if (next_type != PIPE_SHADER_INVALID && sub_ctx->shaders[next_type]) { in vrend_sync_shader_io()
3896 if (!sub_ctx->shaders[next_type]->sinfo.separable_program || in vrend_sync_shader_io()
3897 !sel->sinfo.separable_program) { in vrend_sync_shader_io()
3898 struct vrend_shader_selector *next = sub_ctx->shaders[next_type]; in vrend_sync_shader_io()
3900 key->use_pervertex_in = next->sinfo.use_pervertex_in; in vrend_sync_shader_io()
3901 key->require_output_arrays = next->sinfo.has_input_arrays; in vrend_sync_shader_io()
3902 key->out_generic_expected_mask = next->sinfo.in_generic_emitted_mask; in vrend_sync_shader_io()
3903 key->out_texcoord_expected_mask = next->sinfo.in_texcoord_emitted_mask; in vrend_sync_shader_io()
3906 * we can avoid re-translating this shader by not updating the in vrend_sync_shader_io()
3909 key->num_out_clip = sub_ctx->shaders[next_type]->current->var_sinfo.num_in_clip; in vrend_sync_shader_io()
3910 key->num_out_cull = sub_ctx->shaders[next_type]->current->var_sinfo.num_in_cull; in vrend_sync_shader_io()
3915 sub_ctx->shaders[PIPE_SHADER_FRAGMENT]->current; in vrend_sync_shader_io()
3916 key->fs_info = fs->var_sinfo.fs_info; in vrend_sync_shader_io()
3917 if (type == PIPE_SHADER_VERTEX && sub_ctx->shaders[type]) { in vrend_sync_shader_io()
3918 uint32_t fog_input = sub_ctx->shaders[next_type]->sinfo.fog_input_mask; in vrend_sync_shader_io()
3919 uint32_t fog_output = sub_ctx->shaders[type]->sinfo.fog_output_mask; in vrend_sync_shader_io()
3923 key->vs.fog_fixup_mask = (fog_input ^ fog_output) & fog_input; in vrend_sync_shader_io()
3938 switch (view->format) { in vrend_get_swizzle()
3988 if (tex_conv_table[view->format].flags & VIRGL_TEXTURE_NEED_SWIZZLE) { in vrend_get_swizzle()
3989 swizzle[0] = tex_conv_table[view->format].swizzle[0]; in vrend_get_swizzle()
3990 swizzle[1] = tex_conv_table[view->format].swizzle[1]; in vrend_get_swizzle()
3991 swizzle[2] = tex_conv_table[view->format].swizzle[2]; in vrend_get_swizzle()
3992 swizzle[3] = tex_conv_table[view->format].swizzle[3]; in vrend_get_swizzle()
4005 enum pipe_shader_type type = sel->type; in vrend_fill_shader_key()
4011 /* Only use integer info when drawing to avoid stale info. in vrend_fill_shader_key()
4014 if (vrend_state.use_integer && sub_ctx->drawing && sub_ctx->ve && in vrend_fill_shader_key()
4016 key->vs.attrib_signed_int_bitmask = sub_ctx->ve->signed_int_bitmask; in vrend_fill_shader_key()
4017 key->vs.attrib_unsigned_int_bitmask = sub_ctx->ve->unsigned_int_bitmask; in vrend_fill_shader_key()
4020 for (i = 0; i < sub_ctx->nr_cbufs; i++) { in vrend_fill_shader_key()
4021 if (!sub_ctx->surf[i]) in vrend_fill_shader_key()
4023 if (vrend_format_is_emulated_alpha(sub_ctx->surf[i]->format)) in vrend_fill_shader_key()
4024 key->fs.cbufs_are_a8_bitmask |= (1 << i); in vrend_fill_shader_key()
4025 if (util_format_is_pure_integer(sub_ctx->surf[i]->format)) { in vrend_fill_shader_key()
4027 UPDATE_INT_SIGN_MASK(sub_ctx->surf[i]->format, i, in vrend_fill_shader_key()
4028 key->fs.cbufs_signed_int_bitmask, in vrend_fill_shader_key()
4029 key->fs.cbufs_unsigned_int_bitmask); in vrend_fill_shader_key()
4032 if (sub_ctx->blend_state.logicop_enable) { in vrend_fill_shader_key()
4033 …key->fs.surface_component_bits[i] = util_format_get_component_bits(sub_ctx->surf[i]->format, UTIL_… in vrend_fill_shader_key()
4037 key->add_alpha_test = sub_ctx->dsa_state.alpha.enabled; in vrend_fill_shader_key()
4038 key->alpha_test = sub_ctx->dsa_state.alpha.func; in vrend_fill_shader_key()
4042 key->pstipple_enabled = sub_ctx->rs_state.poly_stipple_enable; in vrend_fill_shader_key()
4043 key->color_two_side = sub_ctx->rs_state.light_twoside; in vrend_fill_shader_key()
4045 key->flatshade = sub_ctx->rs_state.flatshade ? true : false; in vrend_fill_shader_key()
4048 if (vrend_state.use_gles && sub_ctx->ve && type == PIPE_SHADER_VERTEX) { in vrend_fill_shader_key()
4049 key->vs.attrib_zyxw_bitmask = sub_ctx->ve->zyxw_bitmask; in vrend_fill_shader_key()
4052 key->gs_present = !!sub_ctx->shaders[PIPE_SHADER_GEOMETRY] || type == PIPE_SHADER_GEOMETRY; in vrend_fill_shader_key()
4053 key->tcs_present = !!sub_ctx->shaders[PIPE_SHADER_TESS_CTRL] || type == PIPE_SHADER_TESS_CTRL; in vrend_fill_shader_key()
4054 key->tes_present = !!sub_ctx->shaders[PIPE_SHADER_TESS_EVAL] || type == PIPE_SHADER_TESS_EVAL; in vrend_fill_shader_key()
4060 key->gs.emit_clip_distance = sub_ctx->rs_state.clip_plane_enable != 0; in vrend_fill_shader_key()
4062 for (int i = 0; i < sub_ctx->views[type].num_views; i++) { in vrend_fill_shader_key()
4063 struct vrend_sampler_view *view = sub_ctx->views[type].views[i]; in vrend_fill_shader_key()
4067 if (view->emulated_rect) { in vrend_fill_shader_key()
4068 vrend_shader_sampler_views_mask_set(key->sampler_views_emulated_rect_mask, i); in vrend_fill_shader_key()
4071 if (view->texture->target == GL_TEXTURE_BUFFER) { in vrend_fill_shader_key()
4074 vrend_shader_sampler_views_mask_set(key->sampler_views_lower_swizzle_mask, i); in vrend_fill_shader_key()
4075 key->tex_swizzle[i] = to_pipe_swizzle(swizzle[0]) | in vrend_fill_shader_key()
4090 shader->uid = ++uid; in vrend_shader_create()
4092 if (shader->sel->tokens) { in vrend_shader_create()
4094 VREND_DEBUG(dbg_shader_tgsi, ctx, "shader\n%s\n", shader->sel->tmp_buf); in vrend_shader_create()
4096 bool ret = vrend_convert_shader(ctx, &ctx->shader_cfg, shader->sel->tokens, in vrend_shader_create()
4097 shader->sel->req_local_mem, key, &shader->sel->sinfo, in vrend_shader_create()
4098 &shader->var_sinfo, &shader->glsl_strings); in vrend_shader_create()
4100 vrend_report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_SHADER, shader->sel->type); in vrend_shader_create()
4101 return -1; in vrend_shader_create()
4103 } else if (!ctx->shader_cfg.use_gles && shader->sel->type != PIPE_SHADER_TESS_CTRL) { in vrend_shader_create()
4104 vrend_report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_SHADER, shader->sel->type); in vrend_shader_create()
4105 return -1; in vrend_shader_create()
4108 shader->key = *key; in vrend_shader_create()
4123 if (sel->current) { in vrend_shader_select()
4124 if (!memcmp(&sel->current->key, &key, sizeof(key))) in vrend_shader_select()
4127 struct vrend_shader *p = sel->current; in vrend_shader_select()
4128 struct vrend_shader *c = p->next_variant; in vrend_shader_select()
4130 while (c && memcmp(&c->key, &key, sizeof(key)) != 0) { in vrend_shader_select()
4132 c = c->next_variant; in vrend_shader_select()
4135 p->next_variant = c->next_variant; in vrend_shader_select()
4142 shader->sel = sel; in vrend_shader_select()
4143 list_inithead(&shader->programs); in vrend_shader_select()
4144 strarray_alloc(&shader->glsl_strings, SHADER_MAX_STRINGS); in vrend_shader_select()
4146 r = vrend_shader_create(sub_ctx->parent, shader, &key); in vrend_shader_select()
4148 sel->current = NULL; in vrend_shader_select()
4149 strarray_free(&shader->glsl_strings, true); in vrend_shader_select()
4157 shader->next_variant = sel->current; in vrend_shader_select()
4158 sel->current = shader; in vrend_shader_select()
4171 sel->req_local_mem = req_local_mem; in vrend_create_shader_state()
4172 sel->type = pipe_shader_type; in vrend_create_shader_state()
4173 sel->sinfo.so_info = *so_info; in vrend_create_shader_state()
4174 pipe_reference_init(&sel->reference, 1); in vrend_create_shader_state()
4183 sel->tokens = tgsi_dup_tokens(tokens); in vrend_finish_shader()
4185 if (!ctx->shader_cfg.use_gles && sel->type != PIPE_SHADER_COMPUTE) in vrend_finish_shader()
4186 sel->sinfo.separable_program = in vrend_finish_shader()
4187 vrend_shader_query_separable_program(sel->tokens, &ctx->shader_cfg); in vrend_finish_shader()
4189 return vrend_shader_select(ctx->sub, sel, NULL) ? EINVAL : 0; in vrend_finish_shader()
4227 struct vrend_sub_context *sub_ctx = ctx->sub; in vrend_create_shader()
4229 /* if we have an in progress one - don't allow a new shader in vrend_create_shader()
4231 if (sub_ctx->long_shader_in_progress_handle[type]) { in vrend_create_shader()
4234 if (handle != sub_ctx->long_shader_in_progress_handle[type]) in vrend_create_shader()
4249 sel->buf_len = expected_token_count * 4; in vrend_create_shader()
4250 sel->tmp_buf = malloc(sel->buf_len); in vrend_create_shader()
4251 if (!sel->tmp_buf) { in vrend_create_shader()
4256 memcpy(sel->tmp_buf, shd_text, pkt_length_bytes); in vrend_create_shader()
4258 sel->buf_offset = pkt_length_bytes; in vrend_create_shader()
4259 sub_ctx->long_shader_in_progress_handle[type] = handle; in vrend_create_shader()
4263 sel = vrend_object_lookup(sub_ctx->object_hash, handle, VIRGL_OBJECT_SHADER); in vrend_create_shader()
4271 if (offlen != sel->buf_offset) { in vrend_create_shader()
4273 offlen, sel->buf_offset); in vrend_create_shader()
4280 pkt_length_bytes + sel->buf_offset < pkt_length_bytes || in vrend_create_shader()
4281 pkt_length_bytes + sel->buf_offset < sel->buf_offset) { in vrend_create_shader()
4286 if ((pkt_length_bytes + sel->buf_offset) > sel->buf_len) { in vrend_create_shader()
4288 pkt_length_bytes + sel->buf_offset, sel->buf_len); in vrend_create_shader()
4293 memcpy(sel->tmp_buf + sel->buf_offset, shd_text, pkt_length_bytes); in vrend_create_shader()
4295 sel->buf_offset += pkt_length_bytes; in vrend_create_shader()
4296 if (sel->buf_offset >= sel->buf_len) { in vrend_create_shader()
4298 shd_text = sel->tmp_buf; in vrend_create_shader()
4306 uint32_t last_chunk_offset = sel->buf_offset ? sel->buf_offset : pkt_length_bytes; in vrend_create_shader()
4307 if (last_chunk_offset < 4 || !memchr(shd_text + last_chunk_offset - 4, '\0', 4)) { in vrend_create_shader()
4329 free(sel->tmp_buf); in vrend_create_shader()
4330 sel->tmp_buf = NULL; in vrend_create_shader()
4333 sub_ctx->long_shader_in_progress_handle[type] = 0; in vrend_create_shader()
4363 struct vrend_sub_context *sub_ctx = ctx->sub; in vrend_bind_shader()
4367 sub_ctx->cs_shader_dirty = true; in vrend_bind_shader()
4369 sub_ctx->shader_dirty = true; in vrend_bind_shader()
4370 vrend_shader_state_reference(&sub_ctx->shaders[type], NULL); in vrend_bind_shader()
4374 sel = vrend_object_lookup(sub_ctx->object_hash, handle, VIRGL_OBJECT_SHADER); in vrend_bind_shader()
4378 if (sel->type != type) in vrend_bind_shader()
4381 if (sub_ctx->shaders[sel->type] != sel) { in vrend_bind_shader()
4383 sub_ctx->cs_shader_dirty = true; in vrend_bind_shader()
4385 sub_ctx->shader_dirty = true; in vrend_bind_shader()
4386 sub_ctx->prog_ids[sel->type] = 0; in vrend_bind_shader()
4389 vrend_shader_state_reference(&sub_ctx->shaders[sel->type], sel); in vrend_bind_shader()
4396 : 1.055f * powf(color, (1.f / 2.4f)) - 0.055f; in vrend_color_encode_as_srgb()
4405 struct vrend_sub_context *sub_ctx = ctx->sub; in vrend_clear()
4407 if (ctx->in_error) in vrend_clear()
4410 if (ctx->ctx_switch_pending) in vrend_clear()
4414 if (sub_ctx->stencil_state_dirty) in vrend_clear()
4416 if (sub_ctx->scissor_state_dirty) in vrend_clear()
4418 if (sub_ctx->viewport_state_dirty) in vrend_clear()
4421 vrend_use_program(ctx->sub, NULL); in vrend_clear()
4426 memcpy(colorf, color->f, sizeof(colorf)); in vrend_clear()
4429 struct vrend_surface *surf = sub_ctx->surf[0]; in vrend_clear()
4430 if (sub_ctx->nr_cbufs && surf && in vrend_clear()
4431 util_format_is_srgb(surf->format) && in vrend_clear()
4432 !vrend_resource_supports_view(surf->texture, surf->format)) { in vrend_clear()
4434 …"manually converting glClearColor from linear->srgb colorspace for EGL-backed framebuffer color at… in vrend_clear()
4436 util_format_name(surf->format), in vrend_clear()
4437 util_format_name(surf->texture->base.format)); in vrend_clear()
4444 …if (sub_ctx->nr_cbufs && sub_ctx->surf[0] && vrend_format_is_emulated_alpha(sub_ctx->surf[0]->form… in vrend_clear()
4446 } else if (sub_ctx->nr_cbufs && sub_ctx->surf[0] && in vrend_clear()
4447 … vrend_resource_needs_redblue_swizzle(sub_ctx->surf[0]->texture, sub_ctx->surf[0]->format)) { in vrend_clear()
4448 …gra, ctx, "swizzling glClearColor() since rendering surface is an externally-stored BGR* resource\… in vrend_clear()
4454 /* This function implements Gallium's full clear callback (st->pipe->clear) on the host. This in vrend_clear()
4457 if (sub_ctx->hw_blend_state.independent_blend_enable && in vrend_clear()
4485 if (sub_ctx->hw_rs_state.rasterizer_discard) in vrend_clear()
4491 for (i = 0; i < sub_ctx->nr_cbufs; i++) { in vrend_clear()
4492 if (sub_ctx->surf[i]) in vrend_clear()
4499 …if (i < PIPE_MAX_COLOR_BUFS && sub_ctx->surf[i] && util_format_is_pure_uint(sub_ctx->surf[i] && su… in vrend_clear()
4502 … if (i < PIPE_MAX_COLOR_BUFS && sub_ctx->surf[i] && util_format_is_pure_sint(sub_ctx->surf[i] && s… in vrend_clear()
4525 if (sub_ctx->hw_rs_state.rasterizer_discard) in vrend_clear()
4529 if (!sub_ctx->dsa_state.depth.writemask) in vrend_clear()
4535 glStencilMaskSeparate(GL_FRONT, sub_ctx->dsa_state.stencil[0].writemask); in vrend_clear()
4536 glStencilMaskSeparate(GL_BACK, sub_ctx->dsa_state.stencil[1].writemask); in vrend_clear()
4541 if (sub_ctx->hw_blend_state.independent_blend_enable && in vrend_clear()
4545 struct pipe_blend_state *blend = &sub_ctx->hw_blend_state; in vrend_clear()
4546 glColorMaskIndexedEXT(i, blend->rt[i].colormask & PIPE_MASK_R ? GL_TRUE : GL_FALSE, in vrend_clear()
4547 blend->rt[i].colormask & PIPE_MASK_G ? GL_TRUE : GL_FALSE, in vrend_clear()
4548 blend->rt[i].colormask & PIPE_MASK_B ? GL_TRUE : GL_FALSE, in vrend_clear()
4549 blend->rt[i].colormask & PIPE_MASK_A ? GL_TRUE : GL_FALSE); in vrend_clear()
4552 glColorMask(sub_ctx->hw_blend_state.rt[0].colormask & PIPE_MASK_R ? GL_TRUE : GL_FALSE, in vrend_clear()
4553 sub_ctx->hw_blend_state.rt[0].colormask & PIPE_MASK_G ? GL_TRUE : GL_FALSE, in vrend_clear()
4554 sub_ctx->hw_blend_state.rt[0].colormask & PIPE_MASK_B ? GL_TRUE : GL_FALSE, in vrend_clear()
4555 sub_ctx->hw_blend_state.rt[0].colormask & PIPE_MASK_A ? GL_TRUE : GL_FALSE); in vrend_clear()
4558 if (sub_ctx->hw_rs_state.scissor) in vrend_clear()
4578 enum virgl_formats fmt = res->base.format; in vrend_clear_texture()
4582 /* 32-bit BGRA resources are always reordered to RGBA ordering before in vrend_clear_texture()
4594 glClearTexSubImageEXT(res->id, level, in vrend_clear_texture()
4595 box->x, box->y, box->z, in vrend_clear_texture()
4596 box->width, box->height, box->depth, in vrend_clear_texture()
4599 glClearTexSubImage(res->id, level, in vrend_clear_texture()
4600 box->x, box->y, box->z, in vrend_clear_texture()
4601 box->width, box->height, box->depth, in vrend_clear_texture()
4612 unsigned mask = sub_ctx->scissor_state_dirty; in vrend_update_scissor_state()
4617 vrend_report_buffer_error(sub_ctx->parent, 0); in vrend_update_scissor_state()
4620 ss = &sub_ctx->ss[idx]; in vrend_update_scissor_state()
4621 y = ss->miny; in vrend_update_scissor_state()
4624 glScissorIndexed(idx, ss->minx, y, ss->maxx - ss->minx, ss->maxy - ss->miny); in vrend_update_scissor_state()
4626 glScissor(ss->minx, y, ss->maxx - ss->minx, ss->maxy - ss->miny); in vrend_update_scissor_state()
4628 sub_ctx->scissor_state_dirty = 0; in vrend_update_scissor_state()
4634 unsigned mask = sub_ctx->viewport_state_dirty; in vrend_update_viewport_state()
4639 if (sub_ctx->viewport_is_negative) in vrend_update_viewport_state()
4640 cy = sub_ctx->vps[idx].cur_y - sub_ctx->vps[idx].height; in vrend_update_viewport_state()
4642 cy = sub_ctx->vps[idx].cur_y; in vrend_update_viewport_state()
4644 …glViewportIndexedf(idx, sub_ctx->vps[idx].cur_x, cy, sub_ctx->vps[idx].width, sub_ctx->vps[idx].he… in vrend_update_viewport_state()
4646 glViewport(sub_ctx->vps[idx].cur_x, cy, sub_ctx->vps[idx].width, sub_ctx->vps[idx].height); in vrend_update_viewport_state()
4650 glDepthRangeIndexedfOES(idx, sub_ctx->vps[idx].near_val, sub_ctx->vps[idx].far_val); in vrend_update_viewport_state()
4652 glDepthRangeIndexed(idx, sub_ctx->vps[idx].near_val, sub_ctx->vps[idx].far_val); in vrend_update_viewport_state()
4655 glDepthRangefOES(sub_ctx->vps[idx].near_val, sub_ctx->vps[idx].far_val); in vrend_update_viewport_state()
4657 glDepthRange(sub_ctx->vps[idx].near_val, sub_ctx->vps[idx].far_val); in vrend_update_viewport_state()
4660 sub_ctx->viewport_state_dirty = 0; in vrend_update_viewport_state()
4724 disable_bitmask = ~((1ull << va->count) - 1); in vrend_draw_bind_vertex_legacy()
4725 for (i = 0; i < (int)va->count; i++) { in vrend_draw_bind_vertex_legacy()
4726 struct vrend_vertex_element *ve = &va->elements[i]; in vrend_draw_bind_vertex_legacy()
4727 int vbo_index = ve->base.vertex_buffer_index; in vrend_draw_bind_vertex_legacy()
4731 if (i >= ctx->sub->prog->ss[PIPE_SHADER_VERTEX]->sel->sinfo.num_inputs) { in vrend_draw_bind_vertex_legacy()
4735 res = (struct vrend_resource *)ctx->sub->vbo[vbo_index].base.buffer; in vrend_draw_bind_vertex_legacy()
4738 …end_printf("cannot find vbo buf %d %d %d\n", i, va->count, ctx->sub->prog->ss[PIPE_SHADER_VERTEX]-… in vrend_draw_bind_vertex_legacy()
4745 if (ctx->sub->prog->attrib_locs) { in vrend_draw_bind_vertex_legacy()
4746 loc = ctx->sub->prog->attrib_locs[i]; in vrend_draw_bind_vertex_legacy()
4747 } else loc = -1; in vrend_draw_bind_vertex_legacy()
4749 if (loc == -1) { in vrend_draw_bind_vertex_legacy()
4750 …tf("%s: cannot find loc %d %d %d\n", ctx->debug_name, i, va->count, ctx->sub->prog->ss[PIPE_SHADER… in vrend_draw_bind_vertex_legacy()
4752 … vrend_printf("%s: shader probably didn't compile - skipping rendering\n", ctx->debug_name); in vrend_draw_bind_vertex_legacy()
4759 if (ve->type == GL_FALSE) { in vrend_draw_bind_vertex_legacy()
4760 vrend_printf("failed to translate vertex type - skipping render\n"); in vrend_draw_bind_vertex_legacy()
4764 glBindBuffer(GL_ARRAY_BUFFER, res->id); in vrend_draw_bind_vertex_legacy()
4766 struct vrend_vertex_buffer *vbo = &ctx->sub->vbo[vbo_index]; in vrend_draw_bind_vertex_legacy()
4768 if (vbo->base.stride == 0) { in vrend_draw_bind_vertex_legacy()
4771 …data = glMapBufferRange(GL_ARRAY_BUFFER, vbo->base.buffer_offset, ve->nr_chan * sizeof(GLfloat), G… in vrend_draw_bind_vertex_legacy()
4773 switch (ve->nr_chan) { in vrend_draw_bind_vertex_legacy()
4790 … GLint size = !vrend_state.use_gles && (va->zyxw_bitmask & (1 << i)) ? GL_BGRA : ve->nr_chan; in vrend_draw_bind_vertex_legacy()
4793 if (util_format_is_pure_integer(ve->base.src_format)) { in vrend_draw_bind_vertex_legacy()
4794 …glVertexAttribIPointer(loc, size, ve->type, vbo->base.stride, (void *)(uintptr_t)(ve->base.src_off… in vrend_draw_bind_vertex_legacy()
4796 …glVertexAttribPointer(loc, size, ve->type, ve->norm, vbo->base.stride, (void *)(uintptr_t)(ve->bas… in vrend_draw_bind_vertex_legacy()
4798 glVertexAttribDivisorARB(loc, ve->base.instance_divisor); in vrend_draw_bind_vertex_legacy()
4801 if (ctx->sub->enabled_attribs_bitmask != enable_bitmask) { in vrend_draw_bind_vertex_legacy()
4802 uint32_t mask = ctx->sub->enabled_attribs_bitmask & disable_bitmask; in vrend_draw_bind_vertex_legacy()
4808 ctx->sub->enabled_attribs_bitmask &= ~disable_bitmask; in vrend_draw_bind_vertex_legacy()
4810 mask = ctx->sub->enabled_attribs_bitmask ^ enable_bitmask; in vrend_draw_bind_vertex_legacy()
4816 ctx->sub->enabled_attribs_bitmask = enable_bitmask; in vrend_draw_bind_vertex_legacy()
4825 glBindVertexArray(va->id); in vrend_draw_bind_vertex_binding()
4827 if (ctx->sub->vbo_dirty) { in vrend_draw_bind_vertex_binding()
4828 struct vrend_vertex_buffer *vbo = &ctx->sub->vbo[0]; in vrend_draw_bind_vertex_binding()
4831 GLsizei count = MAX2(ctx->sub->num_vbos, ctx->sub->old_num_vbos); in vrend_draw_bind_vertex_binding()
4837 for (i = 0; i < ctx->sub->num_vbos; i++) { in vrend_draw_bind_vertex_binding()
4840 buffers[i] = res->id; in vrend_draw_bind_vertex_binding()
4850 for (i = ctx->sub->num_vbos; i < ctx->sub->old_num_vbos; i++) { in vrend_draw_bind_vertex_binding()
4858 for (i = 0; i < ctx->sub->num_vbos; i++) { in vrend_draw_bind_vertex_binding()
4861 glBindVertexBuffer(i, res->id, vbo[i].base.buffer_offset, vbo[i].base.stride); in vrend_draw_bind_vertex_binding()
4865 for (i = ctx->sub->num_vbos; i < ctx->sub->old_num_vbos; i++) in vrend_draw_bind_vertex_binding()
4869 ctx->sub->vbo_dirty = false; in vrend_draw_bind_vertex_binding()
4879 uint32_t dirty = sub_ctx->sampler_views_dirty[shader_type]; in vrend_draw_bind_samplers_shader()
4880 uint32_t mask = sub_ctx->prog->samplers_used_mask[shader_type]; in vrend_draw_bind_samplers_shader()
4881 struct vrend_shader_view *sviews = &sub_ctx->views[shader_type]; in vrend_draw_bind_samplers_shader()
4886 struct vrend_sampler_view *tview = sviews->views[i]; in vrend_draw_bind_samplers_shader()
4888 if (sub_ctx->prog->shadow_samp_mask[shader_type] & (1 << i)) { in vrend_draw_bind_samplers_shader()
4889 struct vrend_texture *tex = (struct vrend_texture *)tview->texture; in vrend_draw_bind_samplers_shader()
4896 if (memcmp(tex->cur_swizzle, swizzle, 4 * sizeof(GLint))) { in vrend_draw_bind_samplers_shader()
4899 glTexParameteri(tview->texture->target, GL_TEXTURE_SWIZZLE_R + i, swizzle[i]); in vrend_draw_bind_samplers_shader()
4902 glTexParameteriv(tview->texture->target, GL_TEXTURE_SWIZZLE_RGBA, swizzle); in vrend_draw_bind_samplers_shader()
4904 memcpy(tex->cur_swizzle, swizzle, 4 * sizeof(GLint)); in vrend_draw_bind_samplers_shader()
4907 glUniform4f(sub_ctx->prog->shadow_samp_mask_locs[shader_type][sampler_index], in vrend_draw_bind_samplers_shader()
4908 … (tview->gl_swizzle[0] == GL_ZERO || tview->gl_swizzle[0] == GL_ONE) ? 0.0 : 1.0, in vrend_draw_bind_samplers_shader()
4909 … (tview->gl_swizzle[1] == GL_ZERO || tview->gl_swizzle[1] == GL_ONE) ? 0.0 : 1.0, in vrend_draw_bind_samplers_shader()
4910 … (tview->gl_swizzle[2] == GL_ZERO || tview->gl_swizzle[2] == GL_ONE) ? 0.0 : 1.0, in vrend_draw_bind_samplers_shader()
4911 … (tview->gl_swizzle[3] == GL_ZERO || tview->gl_swizzle[3] == GL_ONE) ? 0.0 : 1.0); in vrend_draw_bind_samplers_shader()
4912 glUniform4f(sub_ctx->prog->shadow_samp_add_locs[shader_type][sampler_index], in vrend_draw_bind_samplers_shader()
4913 tview->gl_swizzle[0] == GL_ONE ? 1.0 : 0.0, in vrend_draw_bind_samplers_shader()
4914 tview->gl_swizzle[1] == GL_ONE ? 1.0 : 0.0, in vrend_draw_bind_samplers_shader()
4915 tview->gl_swizzle[2] == GL_ONE ? 1.0 : 0.0, in vrend_draw_bind_samplers_shader()
4916 tview->gl_swizzle[3] == GL_ONE ? 1.0 : 0.0); in vrend_draw_bind_samplers_shader()
4919 if (tview->texture) { in vrend_draw_bind_samplers_shader()
4920 GLuint id = tview->id; in vrend_draw_bind_samplers_shader()
4921 struct vrend_resource *texture = tview->texture; in vrend_draw_bind_samplers_shader()
4922 GLenum target = tview->target; in vrend_draw_bind_samplers_shader()
4924 debug_texture(__func__, tview->texture); in vrend_draw_bind_samplers_shader()
4926 if (has_bit(tview->texture->storage_bits, VREND_STORAGE_GL_BUFFER)) { in vrend_draw_bind_samplers_shader()
4927 id = texture->tbo_tex_id; in vrend_draw_bind_samplers_shader()
4935 … const unsigned levels = tview->levels ? tview->levels : tview->texture->base.last_level + 1u; in vrend_draw_bind_samplers_shader()
4936 sub_ctx->texture_levels[shader_type][n_samplers++] = levels; in vrend_draw_bind_samplers_shader()
4939 if (sub_ctx->views[shader_type].old_ids[i] != id || in vrend_draw_bind_samplers_shader()
4940 sub_ctx->sampler_views_dirty[shader_type] & (1 << i)) { in vrend_draw_bind_samplers_shader()
4943 sviews->old_ids[i] = id; in vrend_draw_bind_samplers_shader()
4952 sub_ctx->n_samplers[shader_type] = n_samplers; in vrend_draw_bind_samplers_shader()
4953 sub_ctx->sampler_views_dirty[shader_type] = dirty; in vrend_draw_bind_samplers_shader()
4965 mask = sub_ctx->prog->ubo_used_mask[shader_type]; in vrend_draw_bind_ubo_shader()
4966 dirty = sub_ctx->const_bufs_dirty[shader_type]; in vrend_draw_bind_ubo_shader()
4967 update = dirty & sub_ctx->const_bufs_used_mask[shader_type]; in vrend_draw_bind_ubo_shader()
4978 cb = &sub_ctx->cbs[shader_type][i]; in vrend_draw_bind_ubo_shader()
4979 res = (struct vrend_resource *)cb->buffer; in vrend_draw_bind_ubo_shader()
4981 glBindBufferRange(GL_UNIFORM_BUFFER, next_ubo_id, res->id, in vrend_draw_bind_ubo_shader()
4982 cb->buffer_offset, cb->buffer_size); in vrend_draw_bind_ubo_shader()
4987 sub_ctx->const_bufs_dirty[shader_type] = dirty; in vrend_draw_bind_ubo_shader()
4995 if (sub_ctx->consts[shader_type].consts && in vrend_draw_bind_const_shader()
4996 sub_ctx->shaders[shader_type] && in vrend_draw_bind_const_shader()
4997 (sub_ctx->prog->const_location[shader_type] != -1) && in vrend_draw_bind_const_shader()
4998 (sub_ctx->const_dirty[shader_type] || new_program)) { in vrend_draw_bind_const_shader()
4999 glUniform4uiv(sub_ctx->prog->const_location[shader_type], in vrend_draw_bind_const_shader()
5000 sub_ctx->shaders[shader_type]->sinfo.num_consts, in vrend_draw_bind_const_shader()
5001 sub_ctx->consts[shader_type].consts); in vrend_draw_bind_const_shader()
5002 sub_ctx->const_dirty[shader_type] = false; in vrend_draw_bind_const_shader()
5017 if (!sub_ctx->prog->ssbo_used_mask[shader_type]) in vrend_draw_bind_ssbo_shader()
5020 if (!sub_ctx->ssbo_used_mask[shader_type]) in vrend_draw_bind_ssbo_shader()
5023 mask = sub_ctx->ssbo_used_mask[shader_type]; in vrend_draw_bind_ssbo_shader()
5027 ssbo = &sub_ctx->ssbo[shader_type][i]; in vrend_draw_bind_ssbo_shader()
5028 res = (struct vrend_resource *)ssbo->res; in vrend_draw_bind_ssbo_shader()
5029 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, i, res->id, in vrend_draw_bind_ssbo_shader()
5030 ssbo->buffer_offset, ssbo->buffer_size); in vrend_draw_bind_ssbo_shader()
5044 mask = sub_ctx->abo_used_mask; in vrend_draw_bind_abo_shader()
5048 abo = &sub_ctx->abo[i]; in vrend_draw_bind_abo_shader()
5049 res = (struct vrend_resource *)abo->res; in vrend_draw_bind_abo_shader()
5050 glBindBufferRange(GL_ATOMIC_COUNTER_BUFFER, i, res->id, in vrend_draw_bind_abo_shader()
5051 abo->buffer_offset, abo->buffer_size); in vrend_draw_bind_abo_shader()
5063 if (!sub_ctx->images_used_mask[shader_type]) in vrend_draw_bind_images_shader()
5066 if (!sub_ctx->prog->img_locs[shader_type]) in vrend_draw_bind_images_shader()
5072 mask = sub_ctx->images_used_mask[shader_type]; in vrend_draw_bind_images_shader()
5076 if (!(sub_ctx->prog->images_used_mask[shader_type] & (1 << i))) in vrend_draw_bind_images_shader()
5078 iview = &sub_ctx->image_views[shader_type][i]; in vrend_draw_bind_images_shader()
5079 tex_id = iview->texture->id; in vrend_draw_bind_images_shader()
5080 if (has_bit(iview->texture->storage_bits, VREND_STORAGE_GL_BUFFER)) { in vrend_draw_bind_images_shader()
5081 if (!iview->texture->tbo_tex_id) in vrend_draw_bind_images_shader()
5082 glGenTextures(1, &iview->texture->tbo_tex_id); in vrend_draw_bind_images_shader()
5085 uint32_t format = (iview->format == GL_RGBA8_SNORM) ? GL_RGBA8UI : iview->format; in vrend_draw_bind_images_shader()
5089 format = vrend_get_arb_format(iview->vformat); in vrend_draw_bind_images_shader()
5092 glBindBufferARB(GL_TEXTURE_BUFFER, iview->texture->id); in vrend_draw_bind_images_shader()
5093 glBindTexture(GL_TEXTURE_BUFFER, iview->texture->tbo_tex_id); in vrend_draw_bind_images_shader()
5101 int blsize = util_format_get_blocksize(iview->vformat); in vrend_draw_bind_images_shader()
5102 unsigned offset = iview->u.buf.offset / blsize; in vrend_draw_bind_images_shader()
5103 unsigned size = iview->u.buf.size / blsize; in vrend_draw_bind_images_shader()
5105 size = vrend_state.max_texture_buffer_size - offset; in vrend_draw_bind_images_shader()
5106 glTexBufferRange(GL_TEXTURE_BUFFER, format, iview->texture->id, iview->u.buf.offset, in vrend_draw_bind_images_shader()
5109 glTexBuffer(GL_TEXTURE_BUFFER, format, iview->texture->id); in vrend_draw_bind_images_shader()
5113 tex_id = iview->texture->tbo_tex_id; in vrend_draw_bind_images_shader()
5117 level = iview->u.tex.level; in vrend_draw_bind_images_shader()
5118 first_layer = iview->u.tex.first_layer; in vrend_draw_bind_images_shader()
5119 layered = !((iview->texture->base.array_size > 1 || in vrend_draw_bind_images_shader()
5120 … iview->texture->base.depth0 > 1) && (iview->u.tex.first_layer == iview->u.tex.last_layer)); in vrend_draw_bind_images_shader()
5124 glUniform1i(sub_ctx->prog->img_locs[shader_type][i], i); in vrend_draw_bind_images_shader()
5126 switch (iview->access) { in vrend_draw_bind_images_shader()
5141 glBindImageTexture(i, tex_id, level, layered, first_layer, access, iview->format); in vrend_draw_bind_images_shader()
5148 if (sub_ctx->prog->virgl_block_bind == -1) in vrend_fill_sysval_uniform_block()
5151 if (sub_ctx->sysvalue_data_cookie != sub_ctx->prog->sysvalue_data_cookie) { in vrend_fill_sysval_uniform_block()
5152 glBindBuffer(GL_UNIFORM_BUFFER, sub_ctx->prog->ubo_sysval_buffer_id); in vrend_fill_sysval_uniform_block()
5154 &sub_ctx->sysvalue_data); in vrend_fill_sysval_uniform_block()
5156 sub_ctx->prog->sysvalue_data_cookie = sub_ctx->sysvalue_data_cookie; in vrend_fill_sysval_uniform_block()
5163 …for (int shader_type = PIPE_SHADER_VERTEX; shader_type <= sub_ctx->last_shader_idx; shader_type++)… in vrend_draw_bind_objects()
5164 vrend_set_active_pipeline_stage(sub_ctx->prog, shader_type); in vrend_draw_bind_objects()
5174 if (sub_ctx->prog->tex_levels_uniform_id[shader_type] != -1) { in vrend_draw_bind_objects()
5175 vrend_set_active_pipeline_stage(sub_ctx->prog, shader_type); in vrend_draw_bind_objects()
5176 glUniform1iv(sub_ctx->prog->tex_levels_uniform_id[shader_type], in vrend_draw_bind_objects()
5177 sub_ctx->n_samplers[shader_type], in vrend_draw_bind_objects()
5178 sub_ctx->texture_levels[shader_type]); in vrend_draw_bind_objects()
5183 if (sub_ctx->prog->virgl_block_bind != -1) in vrend_draw_bind_objects()
5184 glBindBufferRange(GL_UNIFORM_BUFFER, sub_ctx->prog->virgl_block_bind, in vrend_draw_bind_objects()
5185 sub_ctx->prog->ubo_sysval_buffer_id, in vrend_draw_bind_objects()
5190 vrend_set_active_pipeline_stage(sub_ctx->prog, PIPE_SHADER_FRAGMENT); in vrend_draw_bind_objects()
5203 vrend_fill_shader_key(sub_ctx, sel, &shader->key); in vrend_inject_tcs()
5205 shader->sel = sel; in vrend_inject_tcs()
5206 list_inithead(&shader->programs); in vrend_inject_tcs()
5207 strarray_alloc(&shader->glsl_strings, SHADER_MAX_STRINGS); in vrend_inject_tcs()
5209 if (!vrend_shader_create_passthrough_tcs(sub_ctx->parent, &sub_ctx->parent->shader_cfg, in vrend_inject_tcs()
5210 sub_ctx->shaders[PIPE_SHADER_VERTEX]->tokens, in vrend_inject_tcs()
5211 &shader->key, vrend_state.tess_factors, &sel->sinfo, in vrend_inject_tcs()
5212 &shader->glsl_strings, vertices_per_patch)) { in vrend_inject_tcs()
5213 strarray_free(&shader->glsl_strings, true); in vrend_inject_tcs()
5215 vrend_report_context_error(sub_ctx->parent, VIRGL_ERROR_CTX_ILLEGAL_SHADER, sel->type); in vrend_inject_tcs()
5221 sel->tokens = NULL; in vrend_inject_tcs()
5222 sel->current = shader; in vrend_inject_tcs()
5223 sub_ctx->shaders[PIPE_SHADER_TESS_CTRL] = sel; in vrend_inject_tcs()
5234 bool dual_src = util_blend_state_is_dual(&sub_ctx->blend_state, 0); in vrend_select_program()
5237 struct vrend_shader_selector **shaders = sub_ctx->shaders; in vrend_select_program()
5239 sub_ctx->shader_dirty = false; in vrend_select_program()
5251 sub_ctx->drawing = true; in vrend_select_program()
5253 sub_ctx->drawing = false; in vrend_select_program()
5255 if (shaders[PIPE_SHADER_TESS_CTRL] && shaders[PIPE_SHADER_TESS_CTRL]->tokens) in vrend_select_program()
5258 VREND_DEBUG(dbg_shader, sub_ctx->parent, "Need to inject a TCS\n"); in vrend_select_program()
5272 // NOTE: run shader selection again as a workaround to #180 - "duplicated shader compilation" in vrend_select_program()
5277 if (shaders[PIPE_SHADER_TESS_CTRL] && shaders[PIPE_SHADER_TESS_CTRL]->tokens) in vrend_select_program()
5280 VREND_DEBUG(dbg_shader, sub_ctx->parent, "Need to inject a TCS\n"); in vrend_select_program()
5283 sub_ctx->drawing = true; in vrend_select_program()
5285 sub_ctx->drawing = false; in vrend_select_program()
5294 struct vrend_shader *shader = sel->current; in vrend_select_program()
5295 if (shader && !shader->is_compiled) { in vrend_select_program()
5299 if (vrend_state.use_gles && sel->sinfo.gles_use_tex_query_level) in vrend_select_program()
5303 if (!shaders[PIPE_SHADER_VERTEX]->current || in vrend_select_program()
5304 !shaders[PIPE_SHADER_FRAGMENT]->current || in vrend_select_program()
5305 (shaders[PIPE_SHADER_GEOMETRY] && !shaders[PIPE_SHADER_GEOMETRY]->current) || in vrend_select_program()
5306 (shaders[PIPE_SHADER_TESS_CTRL] && !shaders[PIPE_SHADER_TESS_CTRL]->current) || in vrend_select_program()
5307 (shaders[PIPE_SHADER_TESS_EVAL] && !shaders[PIPE_SHADER_TESS_EVAL]->current)) in vrend_select_program()
5310 struct vrend_shader *vs = shaders[PIPE_SHADER_VERTEX]->current; in vrend_select_program()
5311 struct vrend_shader *fs = shaders[PIPE_SHADER_FRAGMENT]->current; in vrend_select_program()
5312 …struct vrend_shader *gs = shaders[PIPE_SHADER_GEOMETRY] ? shaders[PIPE_SHADER_GEOMETRY]->current :… in vrend_select_program()
5313 …struct vrend_shader *tcs = shaders[PIPE_SHADER_TESS_CTRL] ? shaders[PIPE_SHADER_TESS_CTRL]->curren… in vrend_select_program()
5314 …struct vrend_shader *tes = shaders[PIPE_SHADER_TESS_EVAL] ? shaders[PIPE_SHADER_TESS_EVAL]->curren… in vrend_select_program()
5316 GLuint vs_id = vs->id; in vrend_select_program()
5317 GLuint fs_id = fs->id; in vrend_select_program()
5318 GLuint gs_id = !gs ? 0 : gs->id; in vrend_select_program()
5319 GLuint tcs_id = !tcs ? 0 : tcs->id; in vrend_select_program()
5320 GLuint tes_id = !tes ? 0 : tes->id; in vrend_select_program()
5322 if (shaders[PIPE_SHADER_FRAGMENT]->current->sel->sinfo.num_outputs <= 1) in vrend_select_program()
5325 bool same_prog = sub_ctx->prog && in vrend_select_program()
5326 vs_id == sub_ctx->prog_ids[PIPE_SHADER_VERTEX] && in vrend_select_program()
5327 fs_id == sub_ctx->prog_ids[PIPE_SHADER_FRAGMENT] && in vrend_select_program()
5328 gs_id == sub_ctx->prog_ids[PIPE_SHADER_GEOMETRY] && in vrend_select_program()
5329 tcs_id == sub_ctx->prog_ids[PIPE_SHADER_TESS_CTRL] && in vrend_select_program()
5330 tes_id == sub_ctx->prog_ids[PIPE_SHADER_TESS_EVAL] && in vrend_select_program()
5331 sub_ctx->prog->dual_src_linked == dual_src; in vrend_select_program()
5333 bool separable = vs->sel->sinfo.separable_program && in vrend_select_program()
5334 fs->sel->sinfo.separable_program && in vrend_select_program()
5335 (!gs || gs->sel->sinfo.separable_program) && in vrend_select_program()
5336 (!tcs || tcs->sel->sinfo.separable_program) && in vrend_select_program()
5337 (!tes || tes->sel->sinfo.separable_program); in vrend_select_program()
5343 sub_ctx->shaders[PIPE_SHADER_VERTEX]->current, in vrend_select_program()
5344 sub_ctx->shaders[PIPE_SHADER_FRAGMENT]->current, in vrend_select_program()
5345 gs_id ? sub_ctx->shaders[PIPE_SHADER_GEOMETRY]->current : NULL, in vrend_select_program()
5346 tcs_id ? sub_ctx->shaders[PIPE_SHADER_TESS_CTRL]->current : NULL, in vrend_select_program()
5347 tes_id ? sub_ctx->shaders[PIPE_SHADER_TESS_EVAL]->current : NULL, in vrend_select_program()
5351 prog->gles_use_query_texturelevel_mask = gles_emulate_query_texture_levels_mask; in vrend_select_program()
5354 * re-linked. With separable shaders, the program can be relinked in vrend_select_program()
5366 if (!prog->ss[shader_type]) in vrend_select_program()
5368 need_rebind |= prog->ss[shader_type]->last_pipeline_id != prog->id.pipeline; in vrend_select_program()
5377 …sub_ctx->last_shader_idx = sub_ctx->shaders[PIPE_SHADER_TESS_EVAL] ? PIPE_SHADER_TESS_EVAL : (sub_… in vrend_select_program()
5379 prog = sub_ctx->prog; in vrend_select_program()
5380 if (sub_ctx->prog != prog) { in vrend_select_program()
5382 sub_ctx->prog_ids[PIPE_SHADER_VERTEX] = vs_id; in vrend_select_program()
5383 sub_ctx->prog_ids[PIPE_SHADER_FRAGMENT] = fs_id; in vrend_select_program()
5384 sub_ctx->prog_ids[PIPE_SHADER_GEOMETRY] = gs_id; in vrend_select_program()
5385 sub_ctx->prog_ids[PIPE_SHADER_TESS_CTRL] = tcs_id; in vrend_select_program()
5386 sub_ctx->prog_ids[PIPE_SHADER_TESS_EVAL] = tes_id; in vrend_select_program()
5387 sub_ctx->prog_ids[PIPE_SHADER_COMPUTE] = 0; in vrend_select_program()
5388 sub_ctx->prog = prog; in vrend_select_program()
5392 sub_ctx->const_bufs_dirty[stage] = ~0; in vrend_select_program()
5393 sub_ctx->sampler_views_dirty[stage] = ~0; in vrend_select_program()
5396 prog->ref_context = sub_ctx; in vrend_select_program()
5398 sub_ctx->cs_shader_dirty = true; in vrend_select_program()
5402 vrend_printf( "failure to compile shader variants: %s\n", sub_ctx->parent->debug_name); in vrend_select_program()
5408 /* Pre-compiling compute shaders needs some additional work */ in vrend_link_program_hook()
5412 struct vrend_shader_selector *vs = vrend_object_lookup(ctx->sub->object_hash, in vrend_link_program_hook()
5415 struct vrend_shader_selector *fs = vrend_object_lookup(ctx->sub->object_hash, in vrend_link_program_hook()
5421 (!vs || !vs->sinfo.separable_program) && (!fs || !fs->sinfo.separable_program)) in vrend_link_program_hook()
5424 /* We can't link a pre-link a TCS without a TES, exit early */ in vrend_link_program_hook()
5431 memcpy(prev_shader_ids, ctx->sub->prog_ids, PIPE_SHADER_TYPES * sizeof(uint32_t)); in vrend_link_program_hook()
5432 struct vrend_linked_shader_program *prev_prog = ctx->sub->prog; in vrend_link_program_hook()
5435 vrend_shader_state_reference(&prev_handles[type], ctx->sub->shaders[type]); in vrend_link_program_hook()
5439 /* Force early-linking for separable shaders, since they don't depend on other stages */ in vrend_link_program_hook()
5441 if (ctx->sub->shaders[type] && ctx->sub->shaders[type]->sinfo.separable_program) { in vrend_link_program_hook()
5442 if (!ctx->sub->shaders[type]->current->is_compiled) in vrend_link_program_hook()
5443 vrend_compile_shader(ctx->sub, ctx->sub->shaders[type]->current); in vrend_link_program_hook()
5444 if (!ctx->sub->shaders[type]->current->is_linked) in vrend_link_program_hook()
5445 vrend_link_separable_shader(ctx->sub, ctx->sub->shaders[type]->current, type); in vrend_link_program_hook()
5449 /* Force early-link of the whole shader program. */ in vrend_link_program_hook()
5450 vrend_select_program(ctx->sub, 1); in vrend_link_program_hook()
5452 ctx->sub->shader_dirty = true; in vrend_link_program_hook()
5453 ctx->sub->cs_shader_dirty = true; in vrend_link_program_hook()
5457 vrend_shader_state_reference(&ctx->sub->shaders[type], prev_handles[type]); in vrend_link_program_hook()
5460 memcpy(ctx->sub->prog_ids, prev_shader_ids, PIPE_SHADER_TYPES * sizeof(uint32_t)); in vrend_link_program_hook()
5461 ctx->sub->prog = prev_prog; in vrend_link_program_hook()
5472 struct vrend_sub_context *sub_ctx = ctx->sub; in vrend_draw_vbo()
5474 if (ctx->in_error) in vrend_draw_vbo()
5477 if (info->instance_count && !has_feature(feat_draw_instance)) in vrend_draw_vbo()
5480 if (info->start_instance && !has_feature(feat_base_instance)) in vrend_draw_vbo()
5483 if (info->indirect.draw_count > 1 && !has_feature(feat_multi_draw_indirect)) in vrend_draw_vbo()
5508 if (ctx->ctx_switch_pending) in vrend_draw_vbo()
5512 if (ctx->sub->stencil_state_dirty) in vrend_draw_vbo()
5514 if (ctx->sub->scissor_state_dirty) in vrend_draw_vbo()
5517 if (ctx->sub->viewport_state_dirty) in vrend_draw_vbo()
5520 if (ctx->sub->blend_state_dirty) in vrend_draw_vbo()
5523 // enable primitive-mode-dependent shader variants in vrend_draw_vbo()
5524 if (sub_ctx->prim_mode != (int)info->mode) { in vrend_draw_vbo()
5526 if (sub_ctx->prim_mode == PIPE_PRIM_POINTS in vrend_draw_vbo()
5527 || (int)info->mode == PIPE_PRIM_POINTS) in vrend_draw_vbo()
5528 sub_ctx->shader_dirty = true; in vrend_draw_vbo()
5530 sub_ctx->prim_mode = (int)info->mode; in vrend_draw_vbo()
5533 if (!sub_ctx->ve) { in vrend_draw_vbo()
5534 vrend_printf("illegal VE setup - skipping renderering\n"); in vrend_draw_vbo()
5538 if (sub_ctx->shader_dirty || sub_ctx->swizzle_output_rgb_to_bgr || in vrend_draw_vbo()
5539 sub_ctx->needs_manual_srgb_encode_bitmask || sub_ctx->vbo_dirty) in vrend_draw_vbo()
5540 new_program = vrend_select_program(sub_ctx, info->vertices_per_patch); in vrend_draw_vbo()
5542 if (!sub_ctx->prog) { in vrend_draw_vbo()
5543 vrend_printf("dropping rendering due to missing shaders: %s\n", ctx->debug_name); in vrend_draw_vbo()
5547 vrend_use_program(sub_ctx, sub_ctx->prog); in vrend_draw_vbo()
5553 if (sub_ctx->prog->gles_use_query_texturelevel_mask & (1 << i)) { in vrend_draw_vbo()
5556 sub_ctx->prog->tex_levels_uniform_id[i] = in vrend_draw_vbo()
5557 vrend_get_uniform_location(sub_ctx->prog, loc_name, i); in vrend_draw_vbo()
5559 sub_ctx->prog->tex_levels_uniform_id[i] = -1; in vrend_draw_vbo()
5569 vrend_draw_bind_vertex_binding(ctx, sub_ctx->ve); in vrend_draw_vbo()
5571 vrend_draw_bind_vertex_legacy(ctx, sub_ctx->ve); in vrend_draw_vbo()
5573 if (info->indexed) { in vrend_draw_vbo()
5574 struct vrend_resource *res = (struct vrend_resource *)sub_ctx->ib.buffer; in vrend_draw_vbo()
5579 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, res->id); in vrend_draw_vbo()
5583 if (sub_ctx->current_so) { in vrend_draw_vbo()
5584 if (sub_ctx->current_so->xfb_state == XFB_STATE_STARTED_NEED_BEGIN) { in vrend_draw_vbo()
5585 if (sub_ctx->shaders[PIPE_SHADER_GEOMETRY]) in vrend_draw_vbo()
5586 …glBeginTransformFeedback(get_gs_xfb_mode(sub_ctx->shaders[PIPE_SHADER_GEOMETRY]->sinfo.gs_out_prim… in vrend_draw_vbo()
5587 else if (sub_ctx->shaders[PIPE_SHADER_TESS_EVAL]) in vrend_draw_vbo()
5588 …glBeginTransformFeedback(get_tess_xfb_mode(sub_ctx->shaders[PIPE_SHADER_TESS_EVAL]->sinfo.tes_prim, in vrend_draw_vbo()
5589 sub_ctx->shaders[PIPE_SHADER_TESS_EVAL]->sinfo.tes_point_mode)); in vrend_draw_vbo()
5591 glBeginTransformFeedback(get_xfb_mode(info->mode)); in vrend_draw_vbo()
5592 sub_ctx->current_so->xfb_state = XFB_STATE_STARTED; in vrend_draw_vbo()
5593 } else if (sub_ctx->current_so->xfb_state == XFB_STATE_PAUSED) { in vrend_draw_vbo()
5595 sub_ctx->current_so->xfb_state = XFB_STATE_STARTED; in vrend_draw_vbo()
5599 if (info->primitive_restart) { in vrend_draw_vbo()
5604 glPrimitiveRestartIndexNV(info->restart_index); in vrend_draw_vbo()
5607 glPrimitiveRestartIndex(info->restart_index); in vrend_draw_vbo()
5612 GLint buf = indirect_res ? indirect_res->id : 0; in vrend_draw_vbo()
5613 if (sub_ctx->draw_indirect_buffer != buf) { in vrend_draw_vbo()
5615 sub_ctx->draw_indirect_buffer = buf; in vrend_draw_vbo()
5619 GLint buf = indirect_params_res ? indirect_params_res->id : 0; in vrend_draw_vbo()
5620 if (sub_ctx->draw_indirect_params_buffer != buf) { in vrend_draw_vbo()
5622 sub_ctx->draw_indirect_params_buffer = buf; in vrend_draw_vbo()
5627 if (info->vertices_per_patch && has_feature(feat_tessellation)) in vrend_draw_vbo()
5628 glPatchParameteri(GL_PATCH_VERTICES, info->vertices_per_patch); in vrend_draw_vbo()
5635 …uint32_t blend_mask_shader = sub_ctx->shaders[PIPE_SHADER_FRAGMENT]->sinfo.fs_blend_equation_advan… in vrend_draw_vbo()
5636 uint32_t blend_mode = sub_ctx->blend_state.rt[0].alpha_src_factor; in vrend_draw_vbo()
5637 uint32_t alpha_dst_factor = sub_ctx->blend_state.rt[0].alpha_dst_factor; in vrend_draw_vbo()
5650 if (!info->indexed) { in vrend_draw_vbo()
5651 GLenum mode = info->mode; in vrend_draw_vbo()
5652 int count = cso ? cso : info->count; in vrend_draw_vbo()
5653 int start = cso ? 0 : info->start; in vrend_draw_vbo()
5657 … glMultiDrawArraysIndirectCountARB(mode, (GLvoid const *)(uintptr_t)info->indirect.offset, in vrend_draw_vbo()
5658 … info->indirect.indirect_draw_count_offset, info->indirect.draw_count, info->indirect.stride); in vrend_draw_vbo()
5659 else if (info->indirect.draw_count > 1) in vrend_draw_vbo()
5660 …rraysIndirect(mode, (GLvoid const *)(uintptr_t)info->indirect.offset, info->indirect.draw_count, i… in vrend_draw_vbo()
5662 glDrawArraysIndirect(mode, (GLvoid const *)(uintptr_t)info->indirect.offset); in vrend_draw_vbo()
5663 } else if (info->instance_count > 0) { in vrend_draw_vbo()
5664 if (info->start_instance > 0) in vrend_draw_vbo()
5665 … glDrawArraysInstancedBaseInstance(mode, start, count, info->instance_count, info->start_instance); in vrend_draw_vbo()
5667 glDrawArraysInstancedARB(mode, start, count, info->instance_count); in vrend_draw_vbo()
5672 GLenum mode = info->mode; in vrend_draw_vbo()
5673 switch (sub_ctx->ib.index_size) { in vrend_draw_vbo()
5688 … glMultiDrawElementsIndirectCountARB(mode, elsz, (GLvoid const *)(uintptr_t)info->indirect.offset, in vrend_draw_vbo()
5689 … info->indirect.indirect_draw_count_offset, info->indirect.draw_count, info->indirect.stride); in vrend_draw_vbo()
5690 else if (info->indirect.draw_count > 1) in vrend_draw_vbo()
5691 …ndirect(mode, elsz, (GLvoid const *)(uintptr_t)info->indirect.offset, info->indirect.draw_count, i… in vrend_draw_vbo()
5693 glDrawElementsIndirect(mode, elsz, (GLvoid const *)(uintptr_t)info->indirect.offset); in vrend_draw_vbo()
5694 } else if (info->index_bias) { in vrend_draw_vbo()
5695 if (info->instance_count > 0) { in vrend_draw_vbo()
5696 if (info->start_instance > 0) in vrend_draw_vbo()
5697 …lDrawElementsInstancedBaseVertexBaseInstance(mode, info->count, elsz, (void *)(uintptr_t)sub_ctx->… in vrend_draw_vbo()
5698 … info->instance_count, info->index_bias, info->start_instance); in vrend_draw_vbo()
5700 …ementsInstancedBaseVertex(mode, info->count, elsz, (void *)(uintptr_t)sub_ctx->ib.offset, info->in… in vrend_draw_vbo()
5703 } else if (info->min_index != 0 || info->max_index != (unsigned)-1) in vrend_draw_vbo()
5704 …eElementsBaseVertex(mode, info->min_index, info->max_index, info->count, elsz, (void *)(uintptr_t)… in vrend_draw_vbo()
5706 …glDrawElementsBaseVertex(mode, info->count, elsz, (void *)(uintptr_t)sub_ctx->ib.offset, info->ind… in vrend_draw_vbo()
5707 } else if (info->instance_count > 0) { in vrend_draw_vbo()
5708 if (info->start_instance > 0) { in vrend_draw_vbo()
5709 …entsInstancedBaseInstance(mode, info->count, elsz, (void *)(uintptr_t)sub_ctx->ib.offset, info->in… in vrend_draw_vbo()
5711 …glDrawElementsInstancedARB(mode, info->count, elsz, (void *)(uintptr_t)sub_ctx->ib.offset, info->i… in vrend_draw_vbo()
5712 } else if (info->min_index != 0 || info->max_index != (unsigned)-1) in vrend_draw_vbo()
5713 …glDrawRangeElements(mode, info->min_index, info->max_index, info->count, elsz, (void *)(uintptr_t)… in vrend_draw_vbo()
5715 glDrawElements(mode, info->count, elsz, (void *)(uintptr_t)sub_ctx->ib.offset); in vrend_draw_vbo()
5718 if (info->primitive_restart) { in vrend_draw_vbo()
5728 if (sub_ctx->current_so && has_feature(feat_transform_feedback2)) { in vrend_draw_vbo()
5729 if (sub_ctx->current_so->xfb_state == XFB_STATE_STARTED) { in vrend_draw_vbo()
5731 sub_ctx->current_so->xfb_state = XFB_STATE_PAUSED; in vrend_draw_vbo()
5752 struct vrend_sub_context *sub_ctx = ctx->sub; in vrend_launch_grid()
5754 if (sub_ctx->cs_shader_dirty) { in vrend_launch_grid()
5758 sub_ctx->cs_shader_dirty = false; in vrend_launch_grid()
5760 if (!sub_ctx->shaders[PIPE_SHADER_COMPUTE]) { in vrend_launch_grid()
5761 vrend_printf("dropping rendering due to missing shaders: %s\n", ctx->debug_name); in vrend_launch_grid()
5765 vrend_shader_select(sub_ctx, sub_ctx->shaders[PIPE_SHADER_COMPUTE], &cs_dirty); in vrend_launch_grid()
5766 if (!sub_ctx->shaders[PIPE_SHADER_COMPUTE]->current) { in vrend_launch_grid()
5767 vrend_printf( "failure to select compute shader variant: %s\n", ctx->debug_name); in vrend_launch_grid()
5770 if (!sub_ctx->shaders[PIPE_SHADER_COMPUTE]->current->is_compiled) { in vrend_launch_grid()
5771 if(!vrend_compile_shader(sub_ctx, sub_ctx->shaders[PIPE_SHADER_COMPUTE]->current)) { in vrend_launch_grid()
5772 vrend_printf( "failure to compile compute shader variant: %s\n", ctx->debug_name); in vrend_launch_grid()
5776 …if (sub_ctx->shaders[PIPE_SHADER_COMPUTE]->current->id != (GLuint)sub_ctx->prog_ids[PIPE_SHADER_CO… in vrend_launch_grid()
5777 prog = lookup_cs_shader_program(ctx, sub_ctx->shaders[PIPE_SHADER_COMPUTE]->current->id); in vrend_launch_grid()
5779 prog = add_cs_shader_program(ctx, sub_ctx->shaders[PIPE_SHADER_COMPUTE]->current); in vrend_launch_grid()
5784 prog = sub_ctx->prog; in vrend_launch_grid()
5786 if (sub_ctx->prog != prog) { in vrend_launch_grid()
5788 sub_ctx->prog_ids[PIPE_SHADER_VERTEX] = 0; in vrend_launch_grid()
5789 … sub_ctx->prog_ids[PIPE_SHADER_COMPUTE] = sub_ctx->shaders[PIPE_SHADER_COMPUTE]->current->id; in vrend_launch_grid()
5790 sub_ctx->prog = prog; in vrend_launch_grid()
5791 prog->ref_context = sub_ctx; in vrend_launch_grid()
5793 sub_ctx->shader_dirty = true; in vrend_launch_grid()
5796 if (!sub_ctx->prog) { in vrend_launch_grid()
5798 __func__, ctx->debug_name); in vrend_launch_grid()
5802 vrend_use_program(sub_ctx, sub_ctx->prog); in vrend_launch_grid()
5804 vrend_set_active_pipeline_stage(sub_ctx->prog, PIPE_SHADER_COMPUTE); in vrend_launch_grid()
5821 glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, indirect_res->id); in vrend_launch_grid()
5965 if (state->logicop_enable != sub_ctx->hw_blend_state.logicop_enable) { in vrend_hw_emit_blend()
5966 sub_ctx->hw_blend_state.logicop_enable = state->logicop_enable; in vrend_hw_emit_blend()
5968 if (can_emulate_logicop(state->logicop_func)) in vrend_hw_emit_blend()
5969 sub_ctx->shader_dirty = true; in vrend_hw_emit_blend()
5971 report_gles_warn(sub_ctx->parent, GLES_WARN_LOGIC_OP); in vrend_hw_emit_blend()
5972 } else if (state->logicop_enable) { in vrend_hw_emit_blend()
5974 glLogicOp(translate_logicop(state->logicop_func)); in vrend_hw_emit_blend()
5980 if (state->independent_blend_enable && in vrend_hw_emit_blend()
5988 if (state->rt[i].blend_enable) { in vrend_hw_emit_blend()
5989 bool dual_src = util_blend_state_is_dual(&sub_ctx->blend_state, i); in vrend_hw_emit_blend()
5995 glBlendFuncSeparateiARB(i, translate_blend_factor(state->rt[i].rgb_src_factor), in vrend_hw_emit_blend()
5996 translate_blend_factor(state->rt[i].rgb_dst_factor), in vrend_hw_emit_blend()
5997 translate_blend_factor(state->rt[i].alpha_src_factor), in vrend_hw_emit_blend()
5998 translate_blend_factor(state->rt[i].alpha_dst_factor)); in vrend_hw_emit_blend()
5999 glBlendEquationSeparateiARB(i, translate_blend_func(state->rt[i].rgb_func), in vrend_hw_emit_blend()
6000 translate_blend_func(state->rt[i].alpha_func)); in vrend_hw_emit_blend()
6005 if (state->rt[i].colormask != sub_ctx->hw_blend_state.rt[i].colormask) { in vrend_hw_emit_blend()
6006 sub_ctx->hw_blend_state.rt[i].colormask = state->rt[i].colormask; in vrend_hw_emit_blend()
6007 glColorMaskIndexedEXT(i, state->rt[i].colormask & PIPE_MASK_R ? GL_TRUE : GL_FALSE, in vrend_hw_emit_blend()
6008 state->rt[i].colormask & PIPE_MASK_G ? GL_TRUE : GL_FALSE, in vrend_hw_emit_blend()
6009 state->rt[i].colormask & PIPE_MASK_B ? GL_TRUE : GL_FALSE, in vrend_hw_emit_blend()
6010 state->rt[i].colormask & PIPE_MASK_A ? GL_TRUE : GL_FALSE); in vrend_hw_emit_blend()
6014 if (state->rt[0].blend_enable) { in vrend_hw_emit_blend()
6015 bool dual_src = util_blend_state_is_dual(&sub_ctx->blend_state, 0); in vrend_hw_emit_blend()
6019 glBlendFuncSeparate(translate_blend_factor(state->rt[0].rgb_src_factor), in vrend_hw_emit_blend()
6020 translate_blend_factor(state->rt[0].rgb_dst_factor), in vrend_hw_emit_blend()
6021 translate_blend_factor(state->rt[0].alpha_src_factor), in vrend_hw_emit_blend()
6022 translate_blend_factor(state->rt[0].alpha_dst_factor)); in vrend_hw_emit_blend()
6023 glBlendEquationSeparate(translate_blend_func(state->rt[0].rgb_func), in vrend_hw_emit_blend()
6024 translate_blend_func(state->rt[0].alpha_func)); in vrend_hw_emit_blend()
6030 if (state->rt[0].colormask != sub_ctx->hw_blend_state.rt[0].colormask || in vrend_hw_emit_blend()
6031 (sub_ctx->hw_blend_state.independent_blend_enable && in vrend_hw_emit_blend()
6032 !state->independent_blend_enable)) { in vrend_hw_emit_blend()
6033 glColorMask(state->rt[0].colormask & PIPE_MASK_R ? GL_TRUE : GL_FALSE, in vrend_hw_emit_blend()
6034 state->rt[0].colormask & PIPE_MASK_G ? GL_TRUE : GL_FALSE, in vrend_hw_emit_blend()
6035 state->rt[0].colormask & PIPE_MASK_B ? GL_TRUE : GL_FALSE, in vrend_hw_emit_blend()
6036 state->rt[0].colormask & PIPE_MASK_A ? GL_TRUE : GL_FALSE); in vrend_hw_emit_blend()
6038 sub_ctx->hw_blend_state.rt[i].colormask = state->rt[0].colormask; in vrend_hw_emit_blend()
6041 sub_ctx->hw_blend_state.independent_blend_enable = state->independent_blend_enable; in vrend_hw_emit_blend()
6044 if (state->alpha_to_coverage) in vrend_hw_emit_blend()
6050 if (state->alpha_to_one) in vrend_hw_emit_blend()
6057 if (state->dither) in vrend_hw_emit_blend()
6070 struct pipe_blend_state new_state = sub_ctx->blend_state; in vrend_patch_blend_state()
6071 struct pipe_blend_state *state = &sub_ctx->blend_state; in vrend_patch_blend_state()
6073 struct pipe_blend_color blend_color = sub_ctx->blend_color; in vrend_patch_blend_state()
6076 if (sub_ctx->nr_cbufs == 0) { in vrend_patch_blend_state()
6077 sub_ctx->blend_state_dirty = false; in vrend_patch_blend_state()
6081 for (i = 0; i < (state->independent_blend_enable ? PIPE_MAX_COLOR_BUFS : 1); i++) { in vrend_patch_blend_state()
6082 if (i < sub_ctx->nr_cbufs && sub_ctx->surf[i]) { in vrend_patch_blend_state()
6083 if (vrend_format_is_emulated_alpha(sub_ctx->surf[i]->format)) { in vrend_patch_blend_state()
6084 if (state->rt[i].blend_enable) { in vrend_patch_blend_state()
6085 new_state.rt[i].rgb_src_factor = conv_a8_blend(state->rt[i].alpha_src_factor); in vrend_patch_blend_state()
6086 new_state.rt[i].rgb_dst_factor = conv_a8_blend(state->rt[i].alpha_dst_factor); in vrend_patch_blend_state()
6091 if (state->rt[i].colormask & PIPE_MASK_A) in vrend_patch_blend_state()
6097 } else if (!util_format_has_alpha(sub_ctx->surf[i]->format)) { in vrend_patch_blend_state()
6098 if (!(is_dst_blend(state->rt[i].rgb_src_factor) || in vrend_patch_blend_state()
6099 is_dst_blend(state->rt[i].rgb_dst_factor) || in vrend_patch_blend_state()
6100 is_dst_blend(state->rt[i].alpha_src_factor) || in vrend_patch_blend_state()
6101 is_dst_blend(state->rt[i].alpha_dst_factor))) in vrend_patch_blend_state()
6103 new_state.rt[i].rgb_src_factor = conv_dst_blend(state->rt[i].rgb_src_factor); in vrend_patch_blend_state()
6104 new_state.rt[i].rgb_dst_factor = conv_dst_blend(state->rt[i].rgb_dst_factor); in vrend_patch_blend_state()
6105 new_state.rt[i].alpha_src_factor = conv_dst_blend(state->rt[i].alpha_src_factor); in vrend_patch_blend_state()
6106 new_state.rt[i].alpha_dst_factor = conv_dst_blend(state->rt[i].alpha_dst_factor); in vrend_patch_blend_state()
6125 sub_ctx->blend_state_dirty = false; in vrend_patch_blend_state()
6134 memset(&ctx->sub->blend_state, 0, sizeof(ctx->sub->blend_state)); in vrend_object_bind_blend()
6138 state = vrend_object_lookup(ctx->sub->object_hash, handle, VIRGL_OBJECT_BLEND); in vrend_object_bind_blend()
6144 ctx->sub->shader_dirty = true; in vrend_object_bind_blend()
6145 ctx->sub->blend_state = *state; in vrend_object_bind_blend()
6147 ctx->sub->blend_state_dirty = true; in vrend_object_bind_blend()
6152 struct pipe_depth_stencil_alpha_state *state = &ctx->sub->dsa_state; in vrend_hw_emit_dsa()
6154 if (state->depth.enabled) { in vrend_hw_emit_dsa()
6156 glDepthFunc(GL_NEVER + state->depth.func); in vrend_hw_emit_dsa()
6157 if (state->depth.writemask) in vrend_hw_emit_dsa()
6164 if (state->alpha.enabled) { in vrend_hw_emit_dsa()
6167 glAlphaFunc(GL_NEVER + state->alpha.func, state->alpha.ref_value); in vrend_hw_emit_dsa()
6179 memset(&ctx->sub->dsa_state, 0, sizeof(ctx->sub->dsa_state)); in vrend_object_bind_dsa()
6180 ctx->sub->dsa = NULL; in vrend_object_bind_dsa()
6181 ctx->sub->stencil_state_dirty = true; in vrend_object_bind_dsa()
6182 ctx->sub->shader_dirty = true; in vrend_object_bind_dsa()
6187 state = vrend_object_lookup(ctx->sub->object_hash, handle, VIRGL_OBJECT_DSA); in vrend_object_bind_dsa()
6193 if (ctx->sub->dsa != state) { in vrend_object_bind_dsa()
6194 ctx->sub->stencil_state_dirty = true; in vrend_object_bind_dsa()
6195 ctx->sub->shader_dirty = true; in vrend_object_bind_dsa()
6197 ctx->sub->dsa_state = *state; in vrend_object_bind_dsa()
6198 ctx->sub->dsa = state; in vrend_object_bind_dsa()
6200 if (ctx->sub->sysvalue_data.alpha_ref_val != state->alpha.ref_value) { in vrend_object_bind_dsa()
6201 ctx->sub->sysvalue_data.alpha_ref_val = state->alpha.ref_value; in vrend_object_bind_dsa()
6202 ctx->sub->sysvalue_data_cookie++; in vrend_object_bind_dsa()
6210 struct pipe_rasterizer_state *state = &sub_ctx->rs_state; in vrend_update_frontface_state()
6211 int front_ccw = state->front_ccw; in vrend_update_frontface_state()
6213 front_ccw ^= (sub_ctx->fbo_origin_upper_left ? 0 : 1); in vrend_update_frontface_state()
6222 struct pipe_depth_stencil_alpha_state *state = sub_ctx->dsa; in vrend_update_stencil_state()
6227 if (!state->stencil[1].enabled) { in vrend_update_stencil_state()
6228 if (state->stencil[0].enabled) { in vrend_update_stencil_state()
6231 glStencilOp(translate_stencil_op(state->stencil[0].fail_op), in vrend_update_stencil_state()
6232 translate_stencil_op(state->stencil[0].zfail_op), in vrend_update_stencil_state()
6233 translate_stencil_op(state->stencil[0].zpass_op)); in vrend_update_stencil_state()
6235 glStencilFunc(GL_NEVER + state->stencil[0].func, in vrend_update_stencil_state()
6236 sub_ctx->stencil_refs[0], in vrend_update_stencil_state()
6237 state->stencil[0].valuemask); in vrend_update_stencil_state()
6238 glStencilMask(state->stencil[0].writemask); in vrend_update_stencil_state()
6247 translate_stencil_op(state->stencil[i].fail_op), in vrend_update_stencil_state()
6248 translate_stencil_op(state->stencil[i].zfail_op), in vrend_update_stencil_state()
6249 translate_stencil_op(state->stencil[i].zpass_op)); in vrend_update_stencil_state()
6251 glStencilFuncSeparate(face, GL_NEVER + state->stencil[i].func, in vrend_update_stencil_state()
6252 sub_ctx->stencil_refs[i], in vrend_update_stencil_state()
6253 state->stencil[i].valuemask); in vrend_update_stencil_state()
6254 glStencilMaskSeparate(face, state->stencil[i].writemask); in vrend_update_stencil_state()
6257 sub_ctx->stencil_state_dirty = false; in vrend_update_stencil_state()
6277 struct pipe_rasterizer_state *state = &ctx->sub->rs_state; in vrend_hw_emit_rs()
6281 if (state->depth_clip) in vrend_hw_emit_rs()
6289 if (!state->point_size_per_vertex && in vrend_hw_emit_rs()
6290 state->point_size != 1.0f && in vrend_hw_emit_rs()
6291 state->point_size != 0.0f) { in vrend_hw_emit_rs()
6294 } else if (state->point_size_per_vertex) { in vrend_hw_emit_rs()
6298 if (state->point_size) { in vrend_hw_emit_rs()
6299 glPointSize(state->point_size); in vrend_hw_emit_rs()
6304 glLineWidth(state->line_width <= 0 ? 1.0f : state->line_width); in vrend_hw_emit_rs()
6306 if (state->rasterizer_discard != ctx->sub->hw_rs_state.rasterizer_discard) { in vrend_hw_emit_rs()
6307 ctx->sub->hw_rs_state.rasterizer_discard = state->rasterizer_discard; in vrend_hw_emit_rs()
6308 if (state->rasterizer_discard) in vrend_hw_emit_rs()
6315 if (translate_fill(state->fill_front) != GL_FILL) { in vrend_hw_emit_rs()
6318 if (translate_fill(state->fill_back) != GL_FILL) { in vrend_hw_emit_rs()
6322 glPolygonMode(GL_FRONT, translate_fill(state->fill_front)); in vrend_hw_emit_rs()
6323 glPolygonMode(GL_BACK, translate_fill(state->fill_back)); in vrend_hw_emit_rs()
6324 } else if (state->fill_front == state->fill_back) { in vrend_hw_emit_rs()
6325 glPolygonMode(GL_FRONT_AND_BACK, translate_fill(state->fill_front)); in vrend_hw_emit_rs()
6329 if (state->offset_tri) { in vrend_hw_emit_rs()
6336 if (state->offset_line) { in vrend_hw_emit_rs()
6339 } else if (state->offset_line) { in vrend_hw_emit_rs()
6346 if (state->offset_point) { in vrend_hw_emit_rs()
6349 } else if (state->offset_point) { in vrend_hw_emit_rs()
6356 if (state->flatshade != ctx->sub->hw_rs_state.flatshade) { in vrend_hw_emit_rs()
6357 ctx->sub->hw_rs_state.flatshade = state->flatshade; in vrend_hw_emit_rs()
6359 if (state->flatshade) { in vrend_hw_emit_rs()
6367 if (state->clip_halfz != ctx->sub->hw_rs_state.clip_halfz) { in vrend_hw_emit_rs()
6371 GLenum depthrule = state->clip_halfz ? GL_ZERO_TO_ONE : GL_NEGATIVE_ONE_TO_ONE; in vrend_hw_emit_rs()
6373 ctx->sub->hw_rs_state.clip_halfz = state->clip_halfz; in vrend_hw_emit_rs()
6378 if (state->flatshade_first != ctx->sub->hw_rs_state.flatshade_first) { in vrend_hw_emit_rs()
6379 ctx->sub->hw_rs_state.flatshade_first = state->flatshade_first; in vrend_hw_emit_rs()
6381 if (state->flatshade_first) { in vrend_hw_emit_rs()
6384 } else if (state->flatshade_first) { in vrend_hw_emit_rs()
6392 glPolygonOffsetClampEXT(state->offset_scale, state->offset_units, state->offset_clamp); in vrend_hw_emit_rs()
6394 glPolygonOffset(state->offset_scale, state->offset_units); in vrend_hw_emit_rs()
6397 if (state->poly_stipple_enable) in vrend_hw_emit_rs()
6403 if (state->point_quad_rasterization) { in vrend_hw_emit_rs()
6410 …glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, state->sprite_coord_mode ? GL_UPPER_LEFT : GL_LOWE… in vrend_hw_emit_rs()
6419 if (state->cull_face != PIPE_FACE_NONE) { in vrend_hw_emit_rs()
6420 switch (state->cull_face) { in vrend_hw_emit_rs()
6431 vrend_printf( "unhandled cull-face: %x\n", state->cull_face); in vrend_hw_emit_rs()
6439 if (state->light_twoside) in vrend_hw_emit_rs()
6445 if (state->clip_plane_enable != ctx->sub->hw_rs_state.clip_plane_enable) { in vrend_hw_emit_rs()
6446 ctx->sub->hw_rs_state.clip_plane_enable = state->clip_plane_enable; in vrend_hw_emit_rs()
6448 if (state->clip_plane_enable & (1 << i)) in vrend_hw_emit_rs()
6454 ctx->sub->sysvalue_data_cookie++; in vrend_hw_emit_rs()
6455 if (ctx->sub->rs_state.clip_plane_enable) { in vrend_hw_emit_rs()
6456 ctx->sub->sysvalue_data.clip_plane_enabled = 1.f; in vrend_hw_emit_rs()
6458 ctx->sub->sysvalue_data.clip_plane_enabled = 0.f; in vrend_hw_emit_rs()
6462 glLineStipple(state->line_stipple_factor, state->line_stipple_pattern); in vrend_hw_emit_rs()
6463 if (state->line_stipple_enable) in vrend_hw_emit_rs()
6467 } else if (state->line_stipple_enable) { in vrend_hw_emit_rs()
6476 if (state->line_smooth) { in vrend_hw_emit_rs()
6479 } else if (state->line_smooth) { in vrend_hw_emit_rs()
6486 if (state->poly_smooth) { in vrend_hw_emit_rs()
6489 } else if (state->poly_smooth) { in vrend_hw_emit_rs()
6496 if (state->clamp_vertex_color) in vrend_hw_emit_rs()
6501 if (state->clamp_fragment_color) in vrend_hw_emit_rs()
6506 if (state->clamp_vertex_color || state->clamp_fragment_color) in vrend_hw_emit_rs()
6512 if (state->multisample) in vrend_hw_emit_rs()
6520 if (state->multisample) in vrend_hw_emit_rs()
6527 if (state->force_persample_interp) in vrend_hw_emit_rs()
6534 if (state->scissor) in vrend_hw_emit_rs()
6538 ctx->sub->hw_rs_state.scissor = state->scissor; in vrend_hw_emit_rs()
6548 memset(&ctx->sub->rs_state, 0, sizeof(ctx->sub->rs_state)); in vrend_object_bind_rasterizer()
6552 state = vrend_object_lookup(ctx->sub->object_hash, handle, VIRGL_OBJECT_RASTERIZER); in vrend_object_bind_rasterizer()
6559 ctx->sub->rs_state = *state; in vrend_object_bind_rasterizer()
6560 ctx->sub->shader_dirty = true; in vrend_object_bind_rasterizer()
6579 start_slot > (PIPE_MAX_SAMPLERS - num_states)) { in vrend_bind_sampler_states()
6584 ctx->sub->num_sampler_states[shader_type] = num_states; in vrend_bind_sampler_states()
6590 state = vrend_object_lookup(ctx->sub->object_hash, handles[i], VIRGL_OBJECT_SAMPLER_STATE); in vrend_bind_sampler_states()
6595 ctx->sub->sampler_state[shader_type][start_slot + i] = state; in vrend_bind_sampler_states()
6596 ctx->sub->sampler_views_dirty[shader_type] |= (1 << (start_slot + i)); in vrend_bind_sampler_states()
6608 struct vrend_sampler_state *vstate = sub_ctx->sampler_state[shader_type][id]; in vrend_apply_sampler_state()
6609 struct pipe_sampler_state *state = &vstate->base; in vrend_apply_sampler_state()
6611 GLenum target = tex->base.target; in vrend_apply_sampler_state()
6617 if (res->base.nr_samples > 0) { in vrend_apply_sampler_state()
6618 tex->state = *state; in vrend_apply_sampler_state()
6622 if (has_bit(tex->base.storage_bits, VREND_STORAGE_GL_BUFFER)) { in vrend_apply_sampler_state()
6623 tex->state = *state; in vrend_apply_sampler_state()
6632 bool is_emulated_alpha = vrend_format_is_emulated_alpha(tview->format); in vrend_apply_sampler_state()
6634 int sampler = vstate->ids[tview->srgb_decode == GL_SKIP_DECODE_EXT ? 0 : 1]; in vrend_apply_sampler_state()
6637 border_color = state->border_color; in vrend_apply_sampler_state()
6647 if (tex->state.max_lod == -1) in vrend_apply_sampler_state()
6650 if (tex->state.wrap_s != state->wrap_s || set_all) in vrend_apply_sampler_state()
6651 glTexParameteri(target, GL_TEXTURE_WRAP_S, convert_wrap(state->wrap_s)); in vrend_apply_sampler_state()
6652 if (tex->state.wrap_t != state->wrap_t || set_all) in vrend_apply_sampler_state()
6653 glTexParameteri(target, GL_TEXTURE_WRAP_T, convert_wrap(state->wrap_t)); in vrend_apply_sampler_state()
6654 if (tex->state.wrap_r != state->wrap_r || set_all) in vrend_apply_sampler_state()
6655 glTexParameteri(target, GL_TEXTURE_WRAP_R, convert_wrap(state->wrap_r)); in vrend_apply_sampler_state()
6656 if (tex->state.min_img_filter != state->min_img_filter || in vrend_apply_sampler_state()
6657 tex->state.min_mip_filter != state->min_mip_filter || set_all) in vrend_apply_sampler_state()
6658 …rameterf(target, GL_TEXTURE_MIN_FILTER, convert_min_filter(state->min_img_filter, state->min_mip_f… in vrend_apply_sampler_state()
6659 if (tex->state.mag_img_filter != state->mag_img_filter || set_all) in vrend_apply_sampler_state()
6660 glTexParameterf(target, GL_TEXTURE_MAG_FILTER, convert_mag_filter(state->mag_img_filter)); in vrend_apply_sampler_state()
6661 if (res->target != GL_TEXTURE_RECTANGLE) { in vrend_apply_sampler_state()
6662 if (tex->state.min_lod != state->min_lod || set_all) in vrend_apply_sampler_state()
6663 glTexParameterf(target, GL_TEXTURE_MIN_LOD, state->min_lod); in vrend_apply_sampler_state()
6664 if (tex->state.max_lod != state->max_lod || set_all) in vrend_apply_sampler_state()
6665 glTexParameterf(target, GL_TEXTURE_MAX_LOD, state->max_lod); in vrend_apply_sampler_state()
6666 if (tex->state.lod_bias != state->lod_bias || set_all) { in vrend_apply_sampler_state()
6668 if (state->lod_bias) in vrend_apply_sampler_state()
6669 report_gles_warn(sub_ctx->parent, GLES_WARN_LOD_BIAS); in vrend_apply_sampler_state()
6671 glTexParameterf(target, GL_TEXTURE_LOD_BIAS, state->lod_bias); in vrend_apply_sampler_state()
6676 if (tex->state.compare_mode != state->compare_mode || set_all) in vrend_apply_sampler_state()
6677 …glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, state->compare_mode ? GL_COMPARE_R_TO_TEXTURE : G… in vrend_apply_sampler_state()
6678 if (tex->state.compare_func != state->compare_func || set_all) in vrend_apply_sampler_state()
6679 glTexParameteri(target, GL_TEXTURE_COMPARE_FUNC, GL_NEVER + state->compare_func); in vrend_apply_sampler_state()
6680 …if (has_feature(feat_anisotropic_filter) && (tex->state.max_anisotropy != state->max_anisotropy ||… in vrend_apply_sampler_state()
6681 glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY, state->max_anisotropy); in vrend_apply_sampler_state()
6690 if (state->seamless_cube_map) { in vrend_apply_sampler_state()
6697 if (memcmp(&tex->state.border_color, &state->border_color, 16) || set_all || in vrend_apply_sampler_state()
6701 border_color = state->border_color; in vrend_apply_sampler_state()
6706 glTexParameterIuiv(target, GL_TEXTURE_BORDER_COLOR, state->border_color.ui); in vrend_apply_sampler_state()
6710 tex->state = *state; in vrend_apply_sampler_state()
6761 list_del(&fence->fences); in free_fence_locked()
6764 virgl_egl_fence_destroy(egl, fence->eglsyncobj); in free_fence_locked()
6768 glDeleteSync(fence->glsyncobj); in free_fence_locked()
6793 if (fence->ctx == ctx) in vrend_free_fences_for_context()
6797 if (fence->ctx == ctx) in vrend_free_fences_for_context()
6802 vrend_state.fence_waiting->ctx = NULL; in vrend_free_fences_for_context()
6807 if (fence->ctx == ctx) in vrend_free_fences_for_context()
6817 return virgl_egl_client_wait_fence(egl, fence->eglsyncobj, can_block); in do_wait()
6823 GLenum glret = glClientWaitSync(fence->glsyncobj, 0, timeout); in do_wait()
6825 vrend_printf( "wait sync failed: illegal fence object %p\n", fence->glsyncobj); in do_wait()
6854 struct vrend_context *ctx = fence->ctx; in wait_sync()
6862 list_inithead(&fence->fences); in wait_sync()
6864 list_addtail(&fence->fences, &vrend_state.fence_list); in wait_sync()
6900 * by setting fence->ctx to NULL in wait_sync()
6903 ctx->fence_retire(fence->fence_id, ctx->fence_retire_data); in wait_sync()
6917 u_thread_setname("vrend-sync"); in thread_sync()
6920 vrend_clicbs->make_current(gl_context); in thread_sync()
6932 list_del(&fence->fences); in thread_sync()
6940 vrend_clicbs->make_current(0); in thread_sync()
6941 vrend_clicbs->destroy_gl_context(vrend_state.sync_context); in thread_sync()
6956 vrend_state.sync_context = vrend_clicbs->create_gl_context(0, &ctx_params); in vrend_renderer_use_threaded_sync()
6963 if (vrend_state.eventfd == -1) { in vrend_renderer_use_threaded_sync()
6965 vrend_clicbs->destroy_gl_context(vrend_state.sync_context); in vrend_renderer_use_threaded_sync()
6978 vrend_state.eventfd = -1; in vrend_renderer_use_threaded_sync()
6979 vrend_clicbs->destroy_gl_context(vrend_state.sync_context); in vrend_renderer_use_threaded_sync()
6989 UNUSED const GLchar* message, UNUSED const void* userParam) in vrend_debug_cb() argument
6995 vrend_printf( "ERROR: %s\n", message); in vrend_debug_cb()
7003 if (vrend_state.finishing || pipe_reference(&res->base.reference, NULL)) in vrend_pipe_resource_unref()
7014 res->iov = iov; in vrend_pipe_resource_attach_iov()
7015 res->num_iovs = iov_count; in vrend_pipe_resource_attach_iov()
7017 if (has_bit(res->storage_bits, VREND_STORAGE_HOST_SYSTEM_MEMORY)) { in vrend_pipe_resource_attach_iov()
7018 vrend_write_to_iovec(res->iov, res->num_iovs, 0, in vrend_pipe_resource_attach_iov()
7019 res->ptr, res->base.width0); in vrend_pipe_resource_attach_iov()
7028 if (has_bit(res->storage_bits, VREND_STORAGE_HOST_SYSTEM_MEMORY)) { in vrend_pipe_resource_detach_iov()
7029 vrend_read_from_iovec(res->iov, res->num_iovs, 0, in vrend_pipe_resource_detach_iov()
7030 res->ptr, res->base.width0); in vrend_pipe_resource_detach_iov()
7033 res->iov = NULL; in vrend_pipe_resource_detach_iov()
7034 res->num_iovs = 0; in vrend_pipe_resource_detach_iov()
7044 if (res->storage_bits & VREND_STORAGE_GBM_BUFFER) { in vrend_pipe_resource_export_fd()
7045 int ret = virgl_gbm_export_fd(gbm->device, in vrend_pipe_resource_export_fd()
7046 gbm_bo_get_handle(res->gbm_bo).u32, fd); in vrend_pipe_resource_export_fd()
7060 return res->size; in vrend_pipe_resource_get_size()
7075 vrend_printf("GL error reported (%d) for context %d\n", err, ctx->ctx_id); in vrend_check_no_error()
7136 gl_context = vrend_clicbs->create_gl_context(0, &ctx_params); in vrend_renderer_init()
7141 vrend_clicbs->make_current(gl_context); in vrend_renderer_init()
7159 vrend_printf( "gl_version %d - es profile enabled\n", gl_ver); in vrend_renderer_init()
7164 vrend_printf( "gl_version %d - core profile enabled\n", gl_ver); in vrend_renderer_init()
7167 vrend_printf( "gl_version %d - compat profile\n", gl_ver); in vrend_renderer_init()
7181 * doesn't exceed the number to be on the save side when using 8-bit masks in vrend_renderer_init()
7225 vrend_clicbs->destroy_gl_context(gl_context); in vrend_renderer_init()
7234 vrend_state.eventfd = -1; in vrend_renderer_init()
7255 if (vrend_clicbs->get_drm_fd) in vrend_renderer_init()
7256 vrend_video_init(vrend_clicbs->get_drm_fd()); in vrend_renderer_init()
7270 if (vrend_state.eventfd != -1) { in vrend_renderer_fini()
7272 vrend_state.eventfd = -1; in vrend_renderer_fini()
7294 vrend_clicbs->make_current(sub->gl_context); in vrend_destroy_sub_context()
7296 if (sub->fb_id) in vrend_destroy_sub_context()
7297 glDeleteFramebuffers(1, &sub->fb_id); in vrend_destroy_sub_context()
7299 if (sub->blit_fb_ids[0]) in vrend_destroy_sub_context()
7300 glDeleteFramebuffers(2, sub->blit_fb_ids); in vrend_destroy_sub_context()
7305 while (sub->enabled_attribs_bitmask) { in vrend_destroy_sub_context()
7306 uint32_t i = u_bit_scan(&sub->enabled_attribs_bitmask); in vrend_destroy_sub_context()
7310 glDeleteVertexArrays(1, &sub->vaoid); in vrend_destroy_sub_context()
7315 if (sub->current_so) in vrend_destroy_sub_context()
7318 LIST_FOR_EACH_ENTRY_SAFE(obj, tmp, &sub->streamout_list, head) { in vrend_destroy_sub_context()
7322 vrend_shader_state_reference(&sub->shaders[PIPE_SHADER_VERTEX], NULL); in vrend_destroy_sub_context()
7323 vrend_shader_state_reference(&sub->shaders[PIPE_SHADER_FRAGMENT], NULL); in vrend_destroy_sub_context()
7324 vrend_shader_state_reference(&sub->shaders[PIPE_SHADER_GEOMETRY], NULL); in vrend_destroy_sub_context()
7325 vrend_shader_state_reference(&sub->shaders[PIPE_SHADER_TESS_CTRL], NULL); in vrend_destroy_sub_context()
7326 vrend_shader_state_reference(&sub->shaders[PIPE_SHADER_TESS_EVAL], NULL); in vrend_destroy_sub_context()
7327 vrend_shader_state_reference(&sub->shaders[PIPE_SHADER_COMPUTE], NULL); in vrend_destroy_sub_context()
7329 if (sub->prog) in vrend_destroy_sub_context()
7330 sub->prog->ref_context = NULL; in vrend_destroy_sub_context()
7334 free(sub->consts[type].consts); in vrend_destroy_sub_context()
7335 sub->consts[type].consts = NULL; in vrend_destroy_sub_context()
7338 vrend_sampler_view_reference(&sub->views[type].views[i], NULL); in vrend_destroy_sub_context()
7342 if (sub->zsurf) in vrend_destroy_sub_context()
7343 vrend_surface_reference(&sub->zsurf, NULL); in vrend_destroy_sub_context()
7345 for (int i = 0; i < sub->nr_cbufs; i++) { in vrend_destroy_sub_context()
7346 if (!sub->surf[i]) in vrend_destroy_sub_context()
7348 vrend_surface_reference(&sub->surf[i], NULL); in vrend_destroy_sub_context()
7352 vrend_resource_reference((struct vrend_resource **)&sub->ib.buffer, NULL); in vrend_destroy_sub_context()
7354 vrend_object_fini_ctx_table(sub->object_hash); in vrend_destroy_sub_context()
7355 vrend_clicbs->destroy_gl_context(sub->gl_context); in vrend_destroy_sub_context()
7357 list_del(&sub->head); in vrend_destroy_sub_context()
7373 vrend_clicbs->make_current(ctx->sub->gl_context); in vrend_destroy_context()
7388 LIST_FOR_EACH_ENTRY_SAFE(sub, tmp, &ctx->sub_ctxs, head) in vrend_destroy_context()
7390 if(ctx->ctx_id) in vrend_destroy_context()
7396 vrend_video_destroy_context(ctx->video); in vrend_destroy_context()
7399 LIST_FOR_EACH_ENTRY_SAFE(untyped_res, untyped_res_tmp, &ctx->untyped_resources, head) in vrend_destroy_context()
7401 vrend_ctx_resource_fini_table(ctx->res_hash); in vrend_destroy_context()
7417 strncpy(grctx->debug_name, debug_name, in vrend_create_context()
7418 nlen < sizeof(grctx->debug_name) - 1 ? in vrend_create_context()
7419 nlen : sizeof(grctx->debug_name) - 1); in vrend_create_context()
7420 grctx->debug_name[sizeof(grctx->debug_name) - 1] = 0; in vrend_create_context()
7425 grctx->ctx_id = id; in vrend_create_context()
7427 list_inithead(&grctx->sub_ctxs); in vrend_create_context()
7428 list_inithead(&grctx->vrend_resources); in vrend_create_context()
7431 grctx->video = vrend_video_create_context(grctx); in vrend_create_context()
7434 grctx->res_hash = vrend_ctx_resource_init_table(); in vrend_create_context()
7435 list_inithead(&grctx->untyped_resources); in vrend_create_context()
7437 grctx->shader_cfg.max_shader_patch_varyings = vrend_state.max_shader_patch_varyings; in vrend_create_context()
7438 grctx->shader_cfg.use_gles = vrend_state.use_gles; in vrend_create_context()
7439 grctx->shader_cfg.use_core_profile = vrend_state.use_core_profile; in vrend_create_context()
7440 grctx->shader_cfg.use_explicit_locations = vrend_state.use_explicit_locations; in vrend_create_context()
7441 grctx->shader_cfg.max_draw_buffers = vrend_state.max_draw_buffers; in vrend_create_context()
7442 grctx->shader_cfg.has_arrays_of_arrays = has_feature(feat_arrays_of_arrays); in vrend_create_context()
7443 grctx->shader_cfg.has_gpu_shader5 = has_feature(feat_gpu_shader5); in vrend_create_context()
7444 grctx->shader_cfg.has_es31_compat = has_feature(feat_gles31_compatibility); in vrend_create_context()
7445 grctx->shader_cfg.has_conservative_depth = has_feature(feat_conservative_depth); in vrend_create_context()
7446 grctx->shader_cfg.use_integer = vrend_state.use_integer; in vrend_create_context()
7447 grctx->shader_cfg.has_dual_src_blend = has_feature(feat_dual_src_blend); in vrend_create_context()
7448 grctx->shader_cfg.has_fbfetch_coherent = has_feature(feat_framebuffer_fetch); in vrend_create_context()
7449 grctx->shader_cfg.has_cull_distance = has_feature(feat_cull_distance); in vrend_create_context()
7450 grctx->shader_cfg.has_nopersective = has_feature(feat_shader_noperspective_interpolation); in vrend_create_context()
7451 grctx->shader_cfg.has_texture_shadow_lod = has_feature(feat_texture_shadow_lod); in vrend_create_context()
7456 grctx->shader_cfg.glsl_version = vrender_get_glsl_version(); in vrend_create_context()
7458 if (!grctx->ctx_id) in vrend_create_context()
7459 grctx->fence_retire = vrend_clicbs->ctx0_fence_retire; in vrend_create_context()
7468 if (args->target >= PIPE_MAX_TEXTURE_TYPES) { in check_resource_valid()
7470 args->target, PIPE_MAX_TEXTURE_TYPES); in check_resource_valid()
7471 return -1; in check_resource_valid()
7474 if (args->format >= VIRGL_FORMAT_MAX) { in check_resource_valid()
7476 args->format, VIRGL_FORMAT_MAX); in check_resource_valid()
7477 return -1; in check_resource_valid()
7481 (tex_conv_table[args->format].flags & VIRGL_TEXTURE_CAN_TEXTURE_STORAGE); in check_resource_valid()
7484 if (args->nr_samples > 0) { in check_resource_valid()
7485 if (!vrend_format_can_multisample(args->format)) { in check_resource_valid()
7487 util_format_name(args->format)); in check_resource_valid()
7488 return -1; in check_resource_valid()
7491 if (args->target != PIPE_TEXTURE_2D && args->target != PIPE_TEXTURE_2D_ARRAY) { in check_resource_valid()
7492 snprintf(errmsg, 256, "Multisample textures not 2D (target:%d)", args->target); in check_resource_valid()
7493 return -1; in check_resource_valid()
7496 if (args->last_level > 0) { in check_resource_valid()
7498 return -1; in check_resource_valid()
7502 if (args->last_level > 0) { in check_resource_valid()
7504 if (args->target == PIPE_BUFFER) { in check_resource_valid()
7506 return -1; in check_resource_valid()
7509 if (args->target == PIPE_TEXTURE_RECT) { in check_resource_valid()
7511 return -1; in check_resource_valid()
7514 if (args->last_level > (floor(log2(MAX2(args->width, args->height))) + 1)) { in check_resource_valid()
7516 args->last_level, args->width, args->height); in check_resource_valid()
7517 return -1; in check_resource_valid()
7521 if (args->flags != 0) { in check_resource_valid()
7525 if (args->flags & ~supported_mask) { in check_resource_valid()
7526 snprintf(errmsg, 256, "Resource flags 0x%x not supported", args->flags); in check_resource_valid()
7527 return -1; in check_resource_valid()
7531 if (args->flags & VIRGL_RESOURCE_Y_0_TOP) { in check_resource_valid()
7532 if (args->target != PIPE_TEXTURE_2D && args->target != PIPE_TEXTURE_RECT) { in check_resource_valid()
7534 return -1; in check_resource_valid()
7539 if (args->target == PIPE_TEXTURE_CUBE) { in check_resource_valid()
7540 if (args->array_size != 6) { in check_resource_valid()
7541 snprintf(errmsg, 256, "Cube map: unexpected array size %d", args->array_size); in check_resource_valid()
7542 return -1; in check_resource_valid()
7544 } else if (args->target == PIPE_TEXTURE_CUBE_ARRAY) { in check_resource_valid()
7547 return -1; in check_resource_valid()
7549 if (args->array_size % 6) { in check_resource_valid()
7550 snprintf(errmsg, 256, "Cube map array: unexpected array size %d", args->array_size); in check_resource_valid()
7551 return -1; in check_resource_valid()
7553 } else if (args->array_size > 1) { in check_resource_valid()
7554 if (args->target != PIPE_TEXTURE_2D_ARRAY && in check_resource_valid()
7555 args->target != PIPE_TEXTURE_1D_ARRAY) { in check_resource_valid()
7556 snprintf(errmsg, 256, "Texture target %d can't be an array ", args->target); in check_resource_valid()
7557 return -1; in check_resource_valid()
7562 return -1; in check_resource_valid()
7566 if (args->target != PIPE_BUFFER && !args->width) { in check_resource_valid()
7568 return -1; in check_resource_valid()
7571 if (args->bind == 0 || in check_resource_valid()
7572 args->bind == VIRGL_BIND_CUSTOM || in check_resource_valid()
7573 args->bind == VIRGL_BIND_STAGING || in check_resource_valid()
7574 args->bind == VIRGL_BIND_INDEX_BUFFER || in check_resource_valid()
7575 args->bind == VIRGL_BIND_STREAM_OUTPUT || in check_resource_valid()
7576 args->bind == VIRGL_BIND_VERTEX_BUFFER || in check_resource_valid()
7577 args->bind == VIRGL_BIND_CONSTANT_BUFFER || in check_resource_valid()
7578 args->bind == VIRGL_BIND_QUERY_BUFFER || in check_resource_valid()
7579 args->bind == VIRGL_BIND_COMMAND_ARGS || in check_resource_valid()
7580 args->bind == VIRGL_BIND_SHADER_BUFFER) { in check_resource_valid()
7581 if (args->target != PIPE_BUFFER) { in check_resource_valid()
7582 …ntf(errmsg, 256, "Buffer bind flags requre the buffer target but this is target %d", args->target); in check_resource_valid()
7583 return -1; in check_resource_valid()
7585 if (args->height != 1 || args->depth != 1) { in check_resource_valid()
7586 …tf(errmsg, 256, "Buffer target: Got height=%u, depth=%u, expect (1,1)", args->height, args->depth); in check_resource_valid()
7587 return -1; in check_resource_valid()
7589 if (args->bind == VIRGL_BIND_QUERY_BUFFER && !has_feature(feat_qbo)) { in check_resource_valid()
7591 return -1; in check_resource_valid()
7593 if (args->bind == VIRGL_BIND_COMMAND_ARGS && !has_feature(feat_indirect_draw)) { in check_resource_valid()
7595 return -1; in check_resource_valid()
7598 if (!((args->bind & VIRGL_BIND_SAMPLER_VIEW) || in check_resource_valid()
7599 (args->bind & VIRGL_BIND_DEPTH_STENCIL) || in check_resource_valid()
7600 (args->bind & VIRGL_BIND_RENDER_TARGET) || in check_resource_valid()
7601 (args->bind & VIRGL_BIND_CURSOR) || in check_resource_valid()
7602 (args->bind & VIRGL_BIND_SHARED) || in check_resource_valid()
7603 (args->bind & VIRGL_BIND_LINEAR))) { in check_resource_valid()
7604 snprintf(errmsg, 256, "Invalid texture bind flags 0x%x", args->bind); in check_resource_valid()
7605 return -1; in check_resource_valid()
7609 if (!virgl_gbm_gpu_import_required(args->bind)) { in check_resource_valid()
7614 if (args->target == PIPE_TEXTURE_2D || in check_resource_valid()
7615 args->target == PIPE_TEXTURE_RECT || in check_resource_valid()
7616 args->target == PIPE_TEXTURE_CUBE || in check_resource_valid()
7617 args->target == PIPE_TEXTURE_2D_ARRAY || in check_resource_valid()
7618 args->target == PIPE_TEXTURE_CUBE_ARRAY) { in check_resource_valid()
7619 if (args->depth != 1) { in check_resource_valid()
7620 snprintf(errmsg, 256, "2D texture target with depth=%u != 1", args->depth); in check_resource_valid()
7621 return -1; in check_resource_valid()
7623 if (format_can_texture_storage && !args->height) { in check_resource_valid()
7624 snprintf(errmsg, 256, "2D Texture storage requires non-zero height"); in check_resource_valid()
7625 return -1; in check_resource_valid()
7628 if (args->target == PIPE_TEXTURE_1D || in check_resource_valid()
7629 args->target == PIPE_TEXTURE_1D_ARRAY) { in check_resource_valid()
7630 if (args->height != 1 || args->depth != 1) { in check_resource_valid()
7632 args->height, args->depth); in check_resource_valid()
7633 return -1; in check_resource_valid()
7635 if (args->width > vrend_state.max_texture_2d_size) { in check_resource_valid()
7637 args->width, vrend_state.max_texture_2d_size); in check_resource_valid()
7638 return -1; in check_resource_valid()
7642 if (args->target == PIPE_TEXTURE_2D || in check_resource_valid()
7643 args->target == PIPE_TEXTURE_RECT || in check_resource_valid()
7644 args->target == PIPE_TEXTURE_2D_ARRAY) { in check_resource_valid()
7645 if (args->width > vrend_state.max_texture_2d_size || in check_resource_valid()
7646 args->height > vrend_state.max_texture_2d_size) { in check_resource_valid()
7648 args->width, args->height, vrend_state.max_texture_2d_size); in check_resource_valid()
7649 return -1; in check_resource_valid()
7653 if (args->target == PIPE_TEXTURE_3D) { in check_resource_valid()
7655 (!args->height || !args->depth)) { in check_resource_valid()
7656 snprintf(errmsg, 256, "Texture storage expects non-zero height (%u) and depth (%u)", in check_resource_valid()
7657 args->height, args->depth); in check_resource_valid()
7658 return -1; in check_resource_valid()
7660 if (args->width > vrend_state.max_texture_3d_size || in check_resource_valid()
7661 args->height > vrend_state.max_texture_3d_size || in check_resource_valid()
7662 args->depth > vrend_state.max_texture_3d_size) { in check_resource_valid()
7664 args->width, args->height, args->depth, in check_resource_valid()
7666 return -1; in check_resource_valid()
7669 if (args->target == PIPE_TEXTURE_2D_ARRAY || in check_resource_valid()
7670 args->target == PIPE_TEXTURE_CUBE_ARRAY || in check_resource_valid()
7671 args->target == PIPE_TEXTURE_1D_ARRAY) { in check_resource_valid()
7673 !args->array_size) { in check_resource_valid()
7674 snprintf(errmsg, 256, "Texture arrays require a non-zero arrays size " in check_resource_valid()
7676 return -1; in check_resource_valid()
7679 if (args->target == PIPE_TEXTURE_CUBE || in check_resource_valid()
7680 args->target == PIPE_TEXTURE_CUBE_ARRAY) { in check_resource_valid()
7681 if (args->width != args->height) { in check_resource_valid()
7683 args->width, args->height); in check_resource_valid()
7684 return -1; in check_resource_valid()
7686 if (args->width > vrend_state.max_texture_cube_size) { in check_resource_valid()
7688 args->width, vrend_state.max_texture_cube_size); in check_resource_valid()
7689 return -1; in check_resource_valid()
7713 gr->storage_bits |= VREND_STORAGE_GL_BUFFER; in vrend_create_buffer()
7714 glGenBuffersARB(1, &gr->id); in vrend_create_buffer()
7715 glBindBufferARB(gr->target, gr->id); in vrend_create_buffer()
7719 glBufferStorage(gr->target, width, NULL, buffer_storage_flags); in vrend_create_buffer()
7720 gr->map_info = vrend_state.inferred_gl_caching_type; in vrend_create_buffer()
7725 int fd = -1; in vrend_create_buffer()
7729 struct gbm_bo *bo = gbm_bo_create(gbm->device, width, 1, in vrend_create_buffer()
7736 ret = virgl_gbm_export_fd(gbm->device, gbm_bo_get_handle(bo).u32, &fd); in vrend_create_buffer()
7744 glBufferStorageMemEXT(gr->target, width, memobj, 0); in vrend_create_buffer()
7745 gr->gbm_bo = bo; in vrend_create_buffer()
7746 gr->memobj = memobj; in vrend_create_buffer()
7747 gr->storage_bits |= VREND_STORAGE_GBM_BUFFER | VREND_STORAGE_GL_MEMOBJ; in vrend_create_buffer()
7749 if (!strcmp(gbm_device_get_backend_name(gbm->device), "i915")) in vrend_create_buffer()
7750 gr->map_info = VIRGL_RENDERER_MAP_CACHE_CACHED; in vrend_create_buffer()
7752 gr->map_info = VIRGL_RENDERER_MAP_CACHE_WC; in vrend_create_buffer()
7760 gr->storage_bits |= VREND_STORAGE_GL_IMMUTABLE; in vrend_create_buffer()
7761 gr->buffer_storage_flags = buffer_storage_flags; in vrend_create_buffer()
7762 gr->size = width; in vrend_create_buffer()
7764 glBufferData(gr->target, width, NULL, GL_STREAM_DRAW); in vrend_create_buffer()
7766 glBindBufferARB(gr->target, 0); in vrend_create_buffer()
7772 const uint32_t bind = gr->base.bind; in vrend_resource_alloc_buffer()
7773 const uint32_t size = gr->base.width0; in vrend_resource_alloc_buffer()
7777 gr->storage_bits |= VREND_STORAGE_HOST_SYSTEM_MEMORY; in vrend_resource_alloc_buffer()
7778 gr->ptr = calloc(1, size); in vrend_resource_alloc_buffer()
7779 if (!gr->ptr) in vrend_resource_alloc_buffer()
7780 return -ENOMEM; in vrend_resource_alloc_buffer()
7782 /* staging buffers only use guest memory -- nothing to do. */ in vrend_resource_alloc_buffer()
7784 gr->target = GL_ELEMENT_ARRAY_BUFFER_ARB; in vrend_resource_alloc_buffer()
7787 gr->target = GL_TRANSFORM_FEEDBACK_BUFFER; in vrend_resource_alloc_buffer()
7790 gr->target = GL_ARRAY_BUFFER_ARB; in vrend_resource_alloc_buffer()
7793 gr->target = GL_UNIFORM_BUFFER; in vrend_resource_alloc_buffer()
7796 gr->target = GL_QUERY_BUFFER; in vrend_resource_alloc_buffer()
7799 gr->target = GL_DRAW_INDIRECT_BUFFER; in vrend_resource_alloc_buffer()
7802 gr->target = GL_ARRAY_BUFFER_ARB; in vrend_resource_alloc_buffer()
7815 gr->target = GL_TEXTURE_BUFFER; in vrend_resource_alloc_buffer()
7817 gr->target = GL_PIXEL_PACK_BUFFER_ARB; in vrend_resource_alloc_buffer()
7822 return -EINVAL; in vrend_resource_alloc_buffer()
7835 gr->base.bind = args->bind; in vrend_renderer_resource_copy_args()
7836 gr->base.width0 = args->width; in vrend_renderer_resource_copy_args()
7837 gr->base.height0 = args->height; in vrend_renderer_resource_copy_args()
7838 gr->base.depth0 = args->depth; in vrend_renderer_resource_copy_args()
7839 gr->base.format = args->format; in vrend_renderer_resource_copy_args()
7840 gr->base.target = args->target; in vrend_renderer_resource_copy_args()
7841 gr->base.last_level = args->last_level; in vrend_renderer_resource_copy_args()
7842 gr->base.nr_samples = args->nr_samples; in vrend_renderer_resource_copy_args()
7843 gr->base.array_size = args->array_size; in vrend_renderer_resource_copy_args()
7853 uint32_t gbm_flags = virgl_gbm_convert_flags(gr->base.bind); in vrend_resource_gbm_init()
7860 if (gr->base.depth0 != 1 || gr->base.last_level != 0 || gr->base.nr_samples != 0) in vrend_resource_gbm_init()
7863 if (!gbm || !gbm->device || !gbm_format || !gbm_flags) in vrend_resource_gbm_init()
7866 if (!virgl_gbm_external_allocation_preferred(gr->base.bind)) in vrend_resource_gbm_init()
7869 if (!gbm_device_is_format_supported(gbm->device, gbm_format, gbm_flags)) in vrend_resource_gbm_init()
7872 struct gbm_bo *bo = gbm_bo_create(gbm->device, gr->base.width0, gr->base.height0, in vrend_resource_gbm_init()
7877 gr->gbm_bo = bo; in vrend_resource_gbm_init()
7878 gr->storage_bits |= VREND_STORAGE_GBM_BUFFER; in vrend_resource_gbm_init()
7880 if (!strcmp(gbm_device_get_backend_name(gbm->device), "i915")) in vrend_resource_gbm_init()
7881 gr->map_info = VIRGL_RENDERER_MAP_CACHE_CACHED; in vrend_resource_gbm_init()
7883 gr->map_info = VIRGL_RENDERER_MAP_CACHE_WC; in vrend_resource_gbm_init()
7887 gr->size += gbm_bo_get_plane_size(bo, plane); in vrend_resource_gbm_init()
7889 if (!virgl_gbm_gpu_import_required(gr->base.bind)) in vrend_resource_gbm_init()
7892 gr->egl_image = virgl_egl_image_from_gbm_bo(egl, bo); in vrend_resource_gbm_init()
7893 if (!gr->egl_image) { in vrend_resource_gbm_init()
7894 gr->gbm_bo = NULL; in vrend_resource_gbm_init()
7898 gr->storage_bits |= VREND_STORAGE_EGL_IMAGE; in vrend_resource_gbm_init()
7913 struct pipe_resource *pr = &gr->base; in vrend_resource_alloc_texture() local
7919 gr->storage_bits |= VREND_STORAGE_GL_IMMUTABLE; in vrend_resource_alloc_texture()
7923 if (gr->gbm_bo && !has_bit(gr->storage_bits, VREND_STORAGE_EGL_IMAGE)) in vrend_resource_alloc_texture()
7926 image_oes = gr->egl_image; in vrend_resource_alloc_texture()
7929 gr->target = tgsitargettogltarget(pr->target, pr->nr_samples); in vrend_resource_alloc_texture()
7930 gr->storage_bits |= VREND_STORAGE_GL_TEXTURE; in vrend_resource_alloc_texture()
7933 if (gr->target == GL_TEXTURE_RECTANGLE_NV && in vrend_resource_alloc_texture()
7936 if (pr->width0 != 1 || pr->height0 != 1) { in vrend_resource_alloc_texture()
7939 gr->target = GL_TEXTURE_2D; in vrend_resource_alloc_texture()
7943 if (vrend_state.use_gles && gr->target == GL_TEXTURE_1D) { in vrend_resource_alloc_texture()
7944 gr->target = GL_TEXTURE_2D; in vrend_resource_alloc_texture()
7948 if (vrend_state.use_gles && gr->target == GL_TEXTURE_1D_ARRAY) { in vrend_resource_alloc_texture()
7949 gr->target = GL_TEXTURE_2D_ARRAY; in vrend_resource_alloc_texture()
7952 glGenTextures(1, &gr->id); in vrend_resource_alloc_texture()
7953 glBindTexture(gr->target, gr->id); in vrend_resource_alloc_texture()
7958 if (has_bit(gr->storage_bits, VREND_STORAGE_GL_IMMUTABLE) && in vrend_resource_alloc_texture()
7960 glEGLImageTargetTexStorageEXT(gr->target, (GLeglImageOES) image_oes, NULL); in vrend_resource_alloc_texture()
7962 gr->storage_bits &= ~VREND_STORAGE_GL_IMMUTABLE; in vrend_resource_alloc_texture()
7963 assert(gr->target == GL_TEXTURE_2D); in vrend_resource_alloc_texture()
7964 glEGLImageTargetTexture2DOES(gr->target, (GLeglImageOES) image_oes); in vrend_resource_alloc_texture()
7973 glBindTexture(gr->target, 0); in vrend_resource_alloc_texture()
7976 gr->storage_bits |= VREND_STORAGE_EGL_IMAGE; in vrend_resource_alloc_texture()
7983 vrend_printf("unknown format is %d\n", pr->format); in vrend_resource_alloc_texture()
7984 glBindTexture(gr->target, 0); in vrend_resource_alloc_texture()
7988 if (pr->nr_samples > 0) { in vrend_resource_alloc_texture()
7990 if (gr->target == GL_TEXTURE_2D_MULTISAMPLE) { in vrend_resource_alloc_texture()
7991 glTexStorage2DMultisample(gr->target, pr->nr_samples, in vrend_resource_alloc_texture()
7992 internalformat, pr->width0, pr->height0, in vrend_resource_alloc_texture()
7995 glTexStorage3DMultisample(gr->target, pr->nr_samples, in vrend_resource_alloc_texture()
7996 internalformat, pr->width0, pr->height0, pr->array_size, in vrend_resource_alloc_texture()
8000 if (gr->target == GL_TEXTURE_2D_MULTISAMPLE) { in vrend_resource_alloc_texture()
8001 glTexImage2DMultisample(gr->target, pr->nr_samples, in vrend_resource_alloc_texture()
8002 internalformat, pr->width0, pr->height0, in vrend_resource_alloc_texture()
8005 glTexImage3DMultisample(gr->target, pr->nr_samples, in vrend_resource_alloc_texture()
8006 internalformat, pr->width0, pr->height0, pr->array_size, in vrend_resource_alloc_texture()
8010 } else if (gr->target == GL_TEXTURE_CUBE_MAP) { in vrend_resource_alloc_texture()
8013 … glTexStorage2D(GL_TEXTURE_CUBE_MAP, pr->last_level + 1, internalformat, pr->width0, pr->height0); in vrend_resource_alloc_texture()
8017 for (level = 0; level <= pr->last_level; level++) { in vrend_resource_alloc_texture()
8018 unsigned mwidth = u_minify(pr->width0, level); in vrend_resource_alloc_texture()
8019 unsigned mheight = u_minify(pr->height0, level); in vrend_resource_alloc_texture()
8026 } else if (gr->target == GL_TEXTURE_3D || in vrend_resource_alloc_texture()
8027 gr->target == GL_TEXTURE_2D_ARRAY || in vrend_resource_alloc_texture()
8028 gr->target == GL_TEXTURE_CUBE_MAP_ARRAY) { in vrend_resource_alloc_texture()
8030 …unsigned depth_param = (gr->target == GL_TEXTURE_2D_ARRAY || gr->target == GL_TEXTURE_CUBE_MAP_ARR… in vrend_resource_alloc_texture()
8031 pr->array_size : pr->depth0; in vrend_resource_alloc_texture()
8032 …glTexStorage3D(gr->target, pr->last_level + 1, internalformat, pr->width0, pr->height0, depth_para… in vrend_resource_alloc_texture()
8034 for (level = 0; level <= pr->last_level; level++) { in vrend_resource_alloc_texture()
8035 …unsigned depth_param = (gr->target == GL_TEXTURE_2D_ARRAY || gr->target == GL_TEXTURE_CUBE_MAP_ARR… in vrend_resource_alloc_texture()
8036 pr->array_size : u_minify(pr->depth0, level); in vrend_resource_alloc_texture()
8037 unsigned mwidth = u_minify(pr->width0, level); in vrend_resource_alloc_texture()
8038 unsigned mheight = u_minify(pr->height0, level); in vrend_resource_alloc_texture()
8039 glTexImage3D(gr->target, level, internalformat, mwidth, mheight, in vrend_resource_alloc_texture()
8043 } else if (gr->target == GL_TEXTURE_1D && vrend_state.use_gles) { in vrend_resource_alloc_texture()
8045 } else if (gr->target == GL_TEXTURE_1D) { in vrend_resource_alloc_texture()
8047 glTexStorage1D(gr->target, pr->last_level + 1, internalformat, pr->width0); in vrend_resource_alloc_texture()
8049 for (level = 0; level <= pr->last_level; level++) { in vrend_resource_alloc_texture()
8050 unsigned mwidth = u_minify(pr->width0, level); in vrend_resource_alloc_texture()
8051 glTexImage1D(gr->target, level, internalformat, mwidth, 0, in vrend_resource_alloc_texture()
8057 glTexStorage2D(gr->target, pr->last_level + 1, internalformat, pr->width0, in vrend_resource_alloc_texture()
8058 gr->target == GL_TEXTURE_1D_ARRAY ? pr->array_size : pr->height0); in vrend_resource_alloc_texture()
8060 for (level = 0; level <= pr->last_level; level++) { in vrend_resource_alloc_texture()
8061 unsigned mwidth = u_minify(pr->width0, level); in vrend_resource_alloc_texture()
8062 unsigned mheight = u_minify(pr->height0, level); in vrend_resource_alloc_texture()
8063 glTexImage2D(gr->target, level, internalformat, mwidth, in vrend_resource_alloc_texture()
8064 gr->target == GL_TEXTURE_1D_ARRAY ? pr->array_size : mheight, in vrend_resource_alloc_texture()
8072 glTexParameteri(gr->target, GL_TEXTURE_BASE_LEVEL, 0); in vrend_resource_alloc_texture()
8073 glTexParameteri(gr->target, GL_TEXTURE_MAX_LEVEL, pr->last_level); in vrend_resource_alloc_texture()
8076 glBindTexture(gr->target, 0); in vrend_resource_alloc_texture()
8078 if (image_oes && gr->gbm_bo) { in vrend_resource_alloc_texture()
8080 if (!has_bit(gr->storage_bits, VREND_STORAGE_GL_BUFFER) && in vrend_resource_alloc_texture()
8081 !vrend_format_can_texture_view(gr->base.format)) { in vrend_resource_alloc_texture()
8082 for (int i = 0; i < gbm_bo_get_plane_count(gr->gbm_bo); i++) { in vrend_resource_alloc_texture()
8083 gr->aux_plane_egl_image[i] = in vrend_resource_alloc_texture()
8084 virgl_egl_aux_plane_image_from_gbm_bo(egl, gr->gbm_bo, i); in vrend_resource_alloc_texture()
8090 gt->state.max_lod = -1; in vrend_resource_alloc_texture()
8091 gt->cur_swizzle[0] = gt->cur_swizzle[1] = gt->cur_swizzle[2] = gt->cur_swizzle[3] = -1; in vrend_resource_alloc_texture()
8092 gt->cur_base = -1; in vrend_resource_alloc_texture()
8093 gt->cur_max = 10000; in vrend_resource_alloc_texture()
8115 gr->storage_bits = VREND_STORAGE_GUEST_MEMORY; in vrend_resource_create()
8117 if (args->flags & VIRGL_RESOURCE_Y_0_TOP) in vrend_resource_create()
8118 gr->y_0_top = true; in vrend_resource_create()
8120 pipe_reference_init(&gr->base.reference, 1); in vrend_resource_create()
8136 if (args->target == PIPE_BUFFER) { in vrend_renderer_resource_create()
8137 ret = vrend_resource_alloc_buffer(gr, args->flags); in vrend_renderer_resource_create()
8139 const enum virgl_formats format = gr->base.format; in vrend_renderer_resource_create()
8148 return &gr->base; in vrend_renderer_resource_create()
8153 if (has_bit(res->storage_bits, VREND_STORAGE_GL_TEXTURE)) { in vrend_renderer_resource_destroy()
8154 glDeleteTextures(1, &res->id); in vrend_renderer_resource_destroy()
8155 } else if (has_bit(res->storage_bits, VREND_STORAGE_GL_BUFFER)) { in vrend_renderer_resource_destroy()
8156 glDeleteBuffers(1, &res->id); in vrend_renderer_resource_destroy()
8157 if (res->tbo_tex_id) in vrend_renderer_resource_destroy()
8158 glDeleteTextures(1, &res->tbo_tex_id); in vrend_renderer_resource_destroy()
8159 } else if (has_bit(res->storage_bits, VREND_STORAGE_HOST_SYSTEM_MEMORY)) { in vrend_renderer_resource_destroy()
8160 free(res->ptr); in vrend_renderer_resource_destroy()
8163 if (res->rbo_id) { in vrend_renderer_resource_destroy()
8164 glDeleteRenderbuffers(1, &res->rbo_id); in vrend_renderer_resource_destroy()
8167 if (has_bit(res->storage_bits, VREND_STORAGE_GL_MEMOBJ)) { in vrend_renderer_resource_destroy()
8168 glDeleteMemoryObjectsEXT(1, &res->memobj); in vrend_renderer_resource_destroy()
8172 if (res->egl_image) { in vrend_renderer_resource_destroy()
8173 virgl_egl_image_destroy(egl, res->egl_image); in vrend_renderer_resource_destroy()
8174 for (unsigned i = 0; i < ARRAY_SIZE(res->aux_plane_egl_image); i++) { in vrend_renderer_resource_destroy()
8175 if (res->aux_plane_egl_image[i]) { in vrend_renderer_resource_destroy()
8176 virgl_egl_image_destroy(egl, res->aux_plane_egl_image[i]); in vrend_renderer_resource_destroy()
8182 if (res->gbm_bo) in vrend_renderer_resource_destroy()
8183 gbm_bo_destroy(res->gbm_bo); in vrend_renderer_resource_destroy()
8197 glBufferSubData(d->target, d->box->x + doff, len, src); in iov_buffer_upload()
8225 uint32_t send_size = util_format_get_nblocks(format, box->width, in read_transfer_data()
8226 box->height) * blsize * box->depth; in read_transfer_data()
8227 uint32_t bwx = util_format_get_nblocksx(format, box->width) * blsize; in read_transfer_data()
8228 int32_t bh = util_format_get_nblocksy(format, box->height); in read_transfer_data()
8231 if ((send_size == size || bh == 1) && !invert && box->depth == 1) in read_transfer_data()
8235 for (d = 0; d < box->depth; d++) { in read_transfer_data()
8237 for (h = bh - 1; h >= 0; h--) { in read_transfer_data()
8244 for (d = 0; d < box->depth; d++) { in read_transfer_data()
8266 int blsize = util_format_get_blocksize(res->format); in write_transfer_data()
8268 uint32_t send_size = util_format_get_nblocks(res->format, box->width, in write_transfer_data()
8269 box->height) * blsize * box->depth; in write_transfer_data()
8270 uint32_t bwx = util_format_get_nblocksx(res->format, box->width) * blsize; in write_transfer_data()
8271 int32_t bh = util_format_get_nblocksy(res->format, box->height); in write_transfer_data()
8273 …uint32_t stride = dst_stride ? dst_stride : util_format_get_nblocksx(res->format, u_minify(res->wi… in write_transfer_data()
8275 if ((send_size == size || bh == 1) && !invert && box->depth == 1) { in write_transfer_data()
8278 for (d = 0; d < box->depth; d++) { in write_transfer_data()
8279 uint32_t myoffset = offset + d * stride * u_minify(res->height0, level); in write_transfer_data()
8280 for (h = bh - 1; h >= 0; h--) { in write_transfer_data()
8287 for (d = 0; d < box->depth; d++) { in write_transfer_data()
8288 uint32_t myoffset = offset + d * stride * u_minify(res->height0, level); in write_transfer_data()
8301 return (info->iovec && info->iovec_cnt) || res->iov; in check_transfer_iovec()
8310 if (info->level > res->base.last_level) in check_transfer_bounds()
8312 if (info->box->x < 0 || info->box->y < 0) in check_transfer_bounds()
8315 lwidth = u_minify(res->base.width0, info->level); in check_transfer_bounds()
8316 if (info->box->width > lwidth || info->box->width < 0) in check_transfer_bounds()
8318 if (info->box->x > lwidth) in check_transfer_bounds()
8320 if (info->box->width + info->box->x > lwidth) in check_transfer_bounds()
8323 lheight = u_minify(res->base.height0, info->level); in check_transfer_bounds()
8324 if (info->box->height > lheight || info->box->height < 0) in check_transfer_bounds()
8326 if (info->box->y > lheight) in check_transfer_bounds()
8328 if (info->box->height + info->box->y > lheight) in check_transfer_bounds()
8331 if (res->base.target == PIPE_TEXTURE_3D) { in check_transfer_bounds()
8332 int ldepth = u_minify(res->base.depth0, info->level); in check_transfer_bounds()
8333 if (info->box->depth > ldepth || info->box->depth < 0) in check_transfer_bounds()
8335 if (info->box->z > ldepth) in check_transfer_bounds()
8337 if (info->box->z + info->box->depth > ldepth) in check_transfer_bounds()
8340 if (info->box->depth > (int)res->base.array_size) in check_transfer_bounds()
8342 if (info->box->z > (int)res->base.array_size) in check_transfer_bounds()
8344 if (info->box->z + info->box->depth > (int)res->base.array_size) in check_transfer_bounds()
8358 struct pipe_resource *pres = &vres->base; in vrend_transfer_size()
8359 struct pipe_box *box = info->box; in vrend_transfer_size()
8364 int w = box->width > 0 ? box->width : 1; in vrend_transfer_size()
8365 int h = box->height > 0 ? box->height : 1; in vrend_transfer_size()
8366 uint64_t d = box->depth > 0 ? box->depth : 1; in vrend_transfer_size()
8367 uint64_t nblocksx = util_format_get_nblocksx(pres->format, w); in vrend_transfer_size()
8368 uint64_t nblocksy = util_format_get_nblocksy(pres->format, h); in vrend_transfer_size()
8372 * non 3d/2d-array formats. in vrend_transfer_size()
8374 size = (d - 1) * layer_stride; in vrend_transfer_size()
8377 * is the only block row for non 2d/1d-array formats. in vrend_transfer_size()
8379 size += (nblocksy - 1) * stride; in vrend_transfer_size()
8381 size += nblocksx * util_format_get_blocksize(pres->format); in vrend_transfer_size()
8398 if (info->stride) { in check_iov_bounds()
8399 GLuint min_stride = util_format_get_stride(res->base.format, info->box->width); in check_iov_bounds()
8400 if (info->stride < min_stride) in check_iov_bounds()
8402 valid_stride = info->stride; in check_iov_bounds()
8404 valid_stride = util_format_get_stride(res->base.format, in check_iov_bounds()
8405 u_minify(res->base.width0, info->level)); in check_iov_bounds()
8412 if (info->layer_stride) { in check_iov_bounds()
8413 GLuint min_layer_stride = util_format_get_2d_size(res->base.format, in check_iov_bounds()
8415 info->box->height); in check_iov_bounds()
8416 if (info->layer_stride < min_layer_stride) in check_iov_bounds()
8418 valid_layer_stride = info->layer_stride; in check_iov_bounds()
8421 util_format_get_2d_size(res->base.format, valid_stride, in check_iov_bounds()
8422 u_minify(res->base.height0, info->level)); in check_iov_bounds()
8432 if (iovsize < info->offset) in check_iov_bounds()
8436 if (iovsize < info->offset + transfer_size) in check_iov_bounds()
8460 if ((is_only_bit(res->storage_bits, VREND_STORAGE_GUEST_MEMORY) || in vrend_renderer_transfer_write_iov()
8461 has_bit(res->storage_bits, VREND_STORAGE_HOST_SYSTEM_MEMORY)) && res->iov) { in vrend_renderer_transfer_write_iov()
8462 return vrend_copy_iovec(iov, num_iovs, info->offset, in vrend_renderer_transfer_write_iov()
8463 res->iov, res->num_iovs, info->box->x, in vrend_renderer_transfer_write_iov()
8464 info->box->width, res->ptr); in vrend_renderer_transfer_write_iov()
8467 if (has_bit(res->storage_bits, VREND_STORAGE_HOST_SYSTEM_MEMORY)) { in vrend_renderer_transfer_write_iov()
8468 assert(!res->iov); in vrend_renderer_transfer_write_iov()
8469 vrend_read_from_iovec(iov, num_iovs, info->offset, in vrend_renderer_transfer_write_iov()
8470 res->ptr + info->box->x, info->box->width); in vrend_renderer_transfer_write_iov()
8474 if (has_bit(res->storage_bits, VREND_STORAGE_GL_BUFFER)) { in vrend_renderer_transfer_write_iov()
8477 d.box = info->box; in vrend_renderer_transfer_write_iov()
8478 d.target = res->target; in vrend_renderer_transfer_write_iov()
8480 if (!info->synchronized) in vrend_renderer_transfer_write_iov()
8483 glBindBufferARB(res->target, res->id); in vrend_renderer_transfer_write_iov()
8484 data = glMapBufferRange(res->target, info->box->x, info->box->width, map_flags); in vrend_renderer_transfer_write_iov()
8487 vrend_read_from_iovec_cb(iov, num_iovs, info->offset, info->box->width, &iov_buffer_upload, &d); in vrend_renderer_transfer_write_iov()
8489 vrend_read_from_iovec(iov, num_iovs, info->offset, data, info->box->width); in vrend_renderer_transfer_write_iov()
8490 glUnmapBuffer(res->target); in vrend_renderer_transfer_write_iov()
8492 glBindBufferARB(res->target, 0); in vrend_renderer_transfer_write_iov()
8497 int elsize = util_format_get_blocksize(res->base.format); in vrend_renderer_transfer_write_iov()
8503 uint32_t stride = info->stride; in vrend_renderer_transfer_write_iov()
8504 uint32_t layer_stride = info->layer_stride; in vrend_renderer_transfer_write_iov()
8506 vrend_use_program(ctx->sub, 0); in vrend_renderer_transfer_write_iov()
8509 …stride = util_format_get_nblocksx(res->base.format, u_minify(res->base.width0, info->level)) * els… in vrend_renderer_transfer_write_iov()
8512 layer_stride = util_format_get_2d_size(res->base.format, stride, in vrend_renderer_transfer_write_iov()
8513 u_minify(res->base.height0, info->level)); in vrend_renderer_transfer_write_iov()
8515 compressed = util_format_is_compressed(res->base.format); in vrend_renderer_transfer_write_iov()
8520 if (vrend_state.use_gles && vrend_format_is_bgra(res->base.format)) in vrend_renderer_transfer_write_iov()
8524 (res->y_0_top || (res->base.format == VIRGL_FORMAT_Z24X8_UNORM))) { in vrend_renderer_transfer_write_iov()
8526 if (res->y_0_top) in vrend_renderer_transfer_write_iov()
8530 send_size = util_format_get_nblocks(res->base.format, info->box->width, in vrend_renderer_transfer_write_iov()
8531 info->box->height) * elsize; in vrend_renderer_transfer_write_iov()
8532 if (res->target == GL_TEXTURE_3D || in vrend_renderer_transfer_write_iov()
8533 res->target == GL_TEXTURE_2D_ARRAY || in vrend_renderer_transfer_write_iov()
8534 res->target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY || in vrend_renderer_transfer_write_iov()
8535 res->target == GL_TEXTURE_CUBE_MAP_ARRAY) in vrend_renderer_transfer_write_iov()
8536 send_size *= info->box->depth; in vrend_renderer_transfer_write_iov()
8537 else if (need_temp && info->box->depth != 1) in vrend_renderer_transfer_write_iov()
8544 read_transfer_data(iov, num_iovs, data, res->base.format, info->offset, in vrend_renderer_transfer_write_iov()
8545 stride, layer_stride, info->box, invert); in vrend_renderer_transfer_write_iov()
8547 if (send_size > iov[0].iov_len - info->offset) in vrend_renderer_transfer_write_iov()
8549 data = (char*)iov[0].iov_base + info->offset; in vrend_renderer_transfer_write_iov()
8577 glformat = tex_conv_table[res->base.format].glformat; in vrend_renderer_transfer_write_iov()
8578 gltype = tex_conv_table[res->base.format].gltype; in vrend_renderer_transfer_write_iov()
8580 if ((!vrend_state.use_core_profile) && (res->y_0_top)) { in vrend_renderer_transfer_write_iov()
8586 vrend_fb_bind_texture(res, 0, info->level, 0); in vrend_renderer_transfer_write_iov()
8594 vrend_stencil_test_enable(ctx->sub, false); in vrend_renderer_transfer_write_iov()
8596 glPixelZoom(1.0f, res->y_0_top ? -1.0f : 1.0f); in vrend_renderer_transfer_write_iov()
8597 … glWindowPos2i(info->box->x, res->y_0_top ? (int)res->base.height0 - info->box->y : info->box->y); in vrend_renderer_transfer_write_iov()
8598 glDrawPixels(info->box->width, info->box->height, glformat, gltype, in vrend_renderer_transfer_write_iov()
8603 glBindTexture(res->target, res->id); in vrend_renderer_transfer_write_iov()
8606 glformat = tex_conv_table[res->base.format].internalformat; in vrend_renderer_transfer_write_iov()
8607 comp_size = util_format_get_nblocks(res->base.format, info->box->width, in vrend_renderer_transfer_write_iov()
8608 … info->box->height) * util_format_get_blocksize(res->base.format); in vrend_renderer_transfer_write_iov()
8616 x = info->box->x; in vrend_renderer_transfer_write_iov()
8617 y = invert ? (int)res->base.height0 - info->box->y - info->box->height : info->box->y; in vrend_renderer_transfer_write_iov()
8621 if (vrend_state.use_gles && vrend_format_is_bgra(res->base.format)) { in vrend_renderer_transfer_write_iov()
8622 VREND_DEBUG(dbg_bgra, ctx, "manually swizzling bgra->rgba on upload since gles+bgra\n"); in vrend_renderer_transfer_write_iov()
8632 if (info->level < VR_MAX_TEXTURE_2D_LEVELS) { in vrend_renderer_transfer_write_iov()
8633 int64_t level_height = u_minify(res->base.height0, info->level); in vrend_renderer_transfer_write_iov()
8634 res->mipmap_offsets[info->level] = info->offset - in vrend_renderer_transfer_write_iov()
8635 … ((info->box->z * level_height + y) * stride + x * elsize); in vrend_renderer_transfer_write_iov()
8638 if (res->base.format == VIRGL_FORMAT_Z24X8_UNORM) { in vrend_renderer_transfer_write_iov()
8639 /* we get values from the guest as 24-bit scaled integers in vrend_renderer_transfer_write_iov()
8641 as 32-bit scaled integers, so we need to scale them here */ in vrend_renderer_transfer_write_iov()
8648 if (res->target == GL_TEXTURE_CUBE_MAP) { in vrend_renderer_transfer_write_iov()
8649 GLenum ctarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + info->box->z; in vrend_renderer_transfer_write_iov()
8651 glCompressedTexSubImage2D(ctarget, info->level, x, y, in vrend_renderer_transfer_write_iov()
8652 info->box->width, info->box->height, in vrend_renderer_transfer_write_iov()
8655 glTexSubImage2D(ctarget, info->level, x, y, info->box->width, info->box->height, in vrend_renderer_transfer_write_iov()
8658 …} else if (res->target == GL_TEXTURE_3D || res->target == GL_TEXTURE_2D_ARRAY || res->target == GL… in vrend_renderer_transfer_write_iov()
8660 glCompressedTexSubImage3D(res->target, info->level, x, y, info->box->z, in vrend_renderer_transfer_write_iov()
8661 info->box->width, info->box->height, info->box->depth, in vrend_renderer_transfer_write_iov()
8664 glTexSubImage3D(res->target, info->level, x, y, info->box->z, in vrend_renderer_transfer_write_iov()
8665 info->box->width, info->box->height, info->box->depth, in vrend_renderer_transfer_write_iov()
8668 } else if (res->target == GL_TEXTURE_1D) { in vrend_renderer_transfer_write_iov()
8673 glCompressedTexSubImage1D(res->target, info->level, info->box->x, in vrend_renderer_transfer_write_iov()
8674 info->box->width, in vrend_renderer_transfer_write_iov()
8677 glTexSubImage1D(res->target, info->level, info->box->x, info->box->width, in vrend_renderer_transfer_write_iov()
8682 …glCompressedTexSubImage2D(res->target, info->level, x, res->target == GL_TEXTURE_1D_ARRAY ? info->… in vrend_renderer_transfer_write_iov()
8683 info->box->width, info->box->height, in vrend_renderer_transfer_write_iov()
8686 …glTexSubImage2D(res->target, info->level, x, res->target == GL_TEXTURE_1D_ARRAY ? info->box->z : y, in vrend_renderer_transfer_write_iov()
8687 info->box->width, in vrend_renderer_transfer_write_iov()
8688 … res->target == GL_TEXTURE_1D_ARRAY ? info->box->depth : info->box->height, in vrend_renderer_transfer_write_iov()
8692 if (res->base.format == VIRGL_FORMAT_Z24X8_UNORM) { in vrend_renderer_transfer_write_iov()
8714 if (res->target == GL_TEXTURE_3D) in vrend_get_texture_depth()
8715 depth = u_minify(res->base.depth0, level); in vrend_get_texture_depth()
8716 else if (res->target == GL_TEXTURE_1D_ARRAY || res->target == GL_TEXTURE_2D_ARRAY || in vrend_get_texture_depth()
8717 res->target == GL_TEXTURE_CUBE_MAP || res->target == GL_TEXTURE_CUBE_MAP_ARRAY) in vrend_get_texture_depth()
8718 depth = res->base.array_size; in vrend_get_texture_depth()
8730 int elsize = util_format_get_blocksize(res->base.format); in vrend_transfer_send_getteximage()
8731 int compressed = util_format_is_compressed(res->base.format); in vrend_transfer_send_getteximage()
8734 format = tex_conv_table[res->base.format].glformat; in vrend_transfer_send_getteximage()
8735 type = tex_conv_table[res->base.format].gltype; in vrend_transfer_send_getteximage()
8738 format = tex_conv_table[res->base.format].internalformat; in vrend_transfer_send_getteximage()
8740 …ze = util_format_get_nblocks(res->base.format, u_minify(res->base.width0, info->level), u_minify(r… in vrend_transfer_send_getteximage()
8741 … util_format_get_blocksize(res->base.format) * vrend_get_texture_depth(res, info->level); in vrend_transfer_send_getteximage()
8743 if (info->box->z && res->target != GL_TEXTURE_CUBE_MAP) { in vrend_transfer_send_getteximage()
8744 …->base.format, u_minify(res->base.width0, info->level), u_minify(res->base.height0, info->level)) … in vrend_transfer_send_getteximage()
8767 glBindTexture(res->target, res->id); in vrend_transfer_send_getteximage()
8768 if (res->target == GL_TEXTURE_CUBE_MAP) { in vrend_transfer_send_getteximage()
8769 target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + info->box->z; in vrend_transfer_send_getteximage()
8771 target = res->target; in vrend_transfer_send_getteximage()
8775 glGetnCompressedTexImageARB(target, info->level, tex_size, data); in vrend_transfer_send_getteximage()
8779 glGetCompressedTexImage(target, info->level, data); in vrend_transfer_send_getteximage()
8783 glGetnTexImageARB(target, info->level, format, type, tex_size, data); in vrend_transfer_send_getteximage()
8787 glGetTexImage(target, info->level, format, type, data); in vrend_transfer_send_getteximage()
8793 write_transfer_data(&res->base, iov, num_iovs, data + send_offset, in vrend_transfer_send_getteximage()
8794 info->stride, info->box, info->level, info->offset, in vrend_transfer_send_getteximage()
8825 if (vrend_state.use_gles && !vrend_format_is_ds(res->base.format)) { in do_readpixels()
8842 /* read-color clamping is handled in the mesa frontend */ in do_readpixels()
8862 char *myptr = (char*)iov[0].iov_base + info->offset; in vrend_transfer_send_readpixels()
8869 uint32_t h = u_minify(res->base.height0, info->level); in vrend_transfer_send_readpixels()
8870 int elsize = util_format_get_blocksize(res->base.format); in vrend_transfer_send_readpixels()
8872 int row_stride = info->stride / elsize; in vrend_transfer_send_readpixels()
8875 vrend_use_program(ctx->sub, 0); in vrend_transfer_send_readpixels()
8877 enum virgl_formats fmt = res->base.format; in vrend_transfer_send_readpixels()
8883 actually_invert = res->y_0_top; in vrend_transfer_send_readpixels()
8895 if (vrend_state.use_gles && vrend_format_is_bgra(res->base.format)) in vrend_transfer_send_readpixels()
8899 …il_format_get_nblocks(res->base.format, info->box->width, info->box->height) * info->box->depth * … in vrend_transfer_send_readpixels()
8906 send_size = iov[0].iov_len - info->offset; in vrend_transfer_send_readpixels()
8909 … row_stride = util_format_get_nblocksx(res->base.format, u_minify(res->base.width0, info->level)); in vrend_transfer_send_readpixels()
8915 y1 = h - info->box->y - info->box->height; in vrend_transfer_send_readpixels()
8917 y1 = info->box->y; in vrend_transfer_send_readpixels()
8940 if (res->base.format == VIRGL_FORMAT_Z24X8_UNORM) { in vrend_transfer_send_readpixels()
8941 /* we get values from the guest as 24-bit scaled integers in vrend_transfer_send_readpixels()
8943 as 32-bit scaled integers, so we need to scale them here */ in vrend_transfer_send_readpixels()
8950 do_readpixels(res, 0, info->level, info->box->z, info->box->x, y1, in vrend_transfer_send_readpixels()
8951 info->box->width, info->box->height, format, type, send_size, data); in vrend_transfer_send_readpixels()
8953 /* on GLES, texture-backed BGR* resources are always stored with RGB* internal format, but in vrend_transfer_send_readpixels()
8955 * Since the GLES API doesn't allow format conversions like GL, we CPU-swizzle the data in vrend_transfer_send_readpixels()
8957 * The notable exception is externally-stored (GBM/EGL) BGR* resources, for which BGR* in vrend_transfer_send_readpixels()
8958 * byte-ordering is used instead to match external access patterns. */ in vrend_transfer_send_readpixels()
8959 if (vrend_state.use_gles && vrend_format_is_bgra(res->base.format)) { in vrend_transfer_send_readpixels()
8960 VREND_DEBUG(dbg_bgra, ctx, "manually swizzling rgba->bgra on readback since gles+bgra\n"); in vrend_transfer_send_readpixels()
8964 if (res->base.format == VIRGL_FORMAT_Z24X8_UNORM) { in vrend_transfer_send_readpixels()
8981 write_transfer_data(&res->base, iov, num_iovs, data, in vrend_transfer_send_readpixels()
8982 info->stride, info->box, info->level, info->offset, in vrend_transfer_send_readpixels()
8999 if (res->num_iovs == (uint32_t)num_iovs) { in vrend_transfer_send_readonly()
9000 for (i = 0; i < res->num_iovs; i++) { in vrend_transfer_send_readonly()
9001 if (res->iov[i].iov_len != iov[i].iov_len || in vrend_transfer_send_readonly()
9002 res->iov[i].iov_base != iov[i].iov_base) { in vrend_transfer_send_readonly()
9020 return -1; in vrend_transfer_send_readonly()
9028 if (is_only_bit(res->storage_bits, VREND_STORAGE_GUEST_MEMORY) || in vrend_renderer_transfer_send_iov()
9029 (has_bit(res->storage_bits, VREND_STORAGE_HOST_SYSTEM_MEMORY) && res->iov)) { in vrend_renderer_transfer_send_iov()
9030 return vrend_copy_iovec(res->iov, res->num_iovs, info->box->x, in vrend_renderer_transfer_send_iov()
9031 iov, num_iovs, info->offset, in vrend_renderer_transfer_send_iov()
9032 info->box->width, res->ptr); in vrend_renderer_transfer_send_iov()
9035 if (has_bit(res->storage_bits, VREND_STORAGE_HOST_SYSTEM_MEMORY)) { in vrend_renderer_transfer_send_iov()
9036 assert(!res->iov); in vrend_renderer_transfer_send_iov()
9037 vrend_write_to_iovec(iov, num_iovs, info->offset, in vrend_renderer_transfer_send_iov()
9038 res->ptr + info->box->x, info->box->width); in vrend_renderer_transfer_send_iov()
9042 if (has_bit(res->storage_bits, VREND_STORAGE_GL_BUFFER)) { in vrend_renderer_transfer_send_iov()
9043 uint32_t send_size = info->box->width * util_format_get_blocksize(res->base.format); in vrend_renderer_transfer_send_iov()
9046 glBindBufferARB(res->target, res->id); in vrend_renderer_transfer_send_iov()
9047 data = glMapBufferRange(res->target, info->box->x, info->box->width, GL_MAP_READ_BIT); in vrend_renderer_transfer_send_iov()
9049 vrend_printf("unable to open buffer for reading %d\n", res->target); in vrend_renderer_transfer_send_iov()
9051 vrend_write_to_iovec(iov, num_iovs, info->offset, data, send_size); in vrend_renderer_transfer_send_iov()
9052 glUnmapBuffer(res->target); in vrend_renderer_transfer_send_iov()
9053 glBindBufferARB(res->target, 0); in vrend_renderer_transfer_send_iov()
9055 int ret = -1; in vrend_renderer_transfer_send_iov()
9058 …can_readpixels = vrend_format_can_render(res->base.format) || vrend_format_is_ds(res->base.format); in vrend_renderer_transfer_send_iov()
9063 /* Can hit this on a non-error path as well. */ in vrend_renderer_transfer_send_iov()
9084 if (!info->box) in vrend_renderer_transfer_internal()
9091 if (info->iovec && info->iovec_cnt) { in vrend_renderer_transfer_internal()
9092 iov = info->iovec; in vrend_renderer_transfer_internal()
9093 num_iovs = info->iovec_cnt; in vrend_renderer_transfer_internal()
9095 iov = res->iov; in vrend_renderer_transfer_internal()
9096 num_iovs = res->num_iovs; in vrend_renderer_transfer_internal()
9100 if (res->gbm_bo && (transfer_mode == VIRGL_TRANSFER_TO_HOST || in vrend_renderer_transfer_internal()
9101 !has_bit(res->storage_bits, VREND_STORAGE_EGL_IMAGE))) { in vrend_renderer_transfer_internal()
9102 assert(!info->synchronized); in vrend_renderer_transfer_internal()
9103 return virgl_gbm_transfer(res->gbm_bo, transfer_mode, iov, num_iovs, info); in vrend_renderer_transfer_internal()
9108 vrend_report_context_error(ctx, VIRGL_ERROR_CTX_TRANSFER_IOV_BOUNDS, res->id); in vrend_renderer_transfer_internal()
9113 vrend_report_context_error(ctx, VIRGL_ERROR_CTX_TRANSFER_IOV_BOUNDS, res->id); in vrend_renderer_transfer_internal()
9143 if (has_bit(res->storage_bits, VREND_STORAGE_EGL_IMAGE)) in vrend_renderer_transfer_iov()
9184 if (!check_iov_bounds(res, info, info->iovec, info->iovec_cnt)) { in vrend_transfer_inline_write()
9190 if (res->gbm_bo) { in vrend_transfer_inline_write()
9191 assert(!info->synchronized); in vrend_transfer_inline_write()
9192 return virgl_gbm_transfer(res->gbm_bo, in vrend_transfer_inline_write()
9194 info->iovec, in vrend_transfer_inline_write()
9195 info->iovec_cnt, in vrend_transfer_inline_write()
9200 return vrend_renderer_transfer_write_iov(ctx, res, info->iovec, info->iovec_cnt, info); in vrend_transfer_inline_write()
9224 if (!src_res->iov) { in vrend_renderer_copy_transfer3d()
9234 if (!check_iov_bounds(dst_res, info, src_res->iov, src_res->num_iovs)) { in vrend_renderer_copy_transfer3d()
9240 if (dst_res->gbm_bo) { in vrend_renderer_copy_transfer3d()
9254 if (info->synchronized) { in vrend_renderer_copy_transfer3d()
9255 if (has_bit(dst_res->storage_bits, VREND_STORAGE_GL_IMMUTABLE) && in vrend_renderer_copy_transfer3d()
9256 dst_res->base.format != VIRGL_FORMAT_B8G8R8X8_UNORM) in vrend_renderer_copy_transfer3d()
9263 return virgl_gbm_transfer(dst_res->gbm_bo, in vrend_renderer_copy_transfer3d()
9265 src_res->iov, in vrend_renderer_copy_transfer3d()
9266 src_res->num_iovs, in vrend_renderer_copy_transfer3d()
9272 return vrend_renderer_transfer_write_iov(ctx, dst_res, src_res->iov, in vrend_renderer_copy_transfer3d()
9273 src_res->num_iovs, info); in vrend_renderer_copy_transfer3d()
9296 if (!dst_res->iov) { in vrend_renderer_copy_transfer3d_from_host()
9306 if (!check_iov_bounds(src_res, info, dst_res->iov, dst_res->num_iovs)) { in vrend_renderer_copy_transfer3d_from_host()
9312 if (src_res->gbm_bo) { in vrend_renderer_copy_transfer3d_from_host()
9328 if (info->synchronized) { in vrend_renderer_copy_transfer3d_from_host()
9329 bool can_readpixels = vrend_format_can_render(src_res->base.format) || in vrend_renderer_copy_transfer3d_from_host()
9330 vrend_format_is_ds(src_res->base.format); in vrend_renderer_copy_transfer3d_from_host()
9333 src_res->base.format != VIRGL_FORMAT_B8G8R8X8_UNORM) in vrend_renderer_copy_transfer3d_from_host()
9340 return virgl_gbm_transfer(src_res->gbm_bo, in vrend_renderer_copy_transfer3d_from_host()
9342 dst_res->iov, in vrend_renderer_copy_transfer3d_from_host()
9343 dst_res->num_iovs, in vrend_renderer_copy_transfer3d_from_host()
9349 return vrend_renderer_transfer_send_iov(ctx, src_res, dst_res->iov, in vrend_renderer_copy_transfer3d_from_host()
9350 dst_res->num_iovs, info); in vrend_renderer_copy_transfer3d_from_host()
9356 if (ctx->sub->stencil_refs[0] != ref->ref_value[0] || in vrend_set_stencil_ref()
9357 ctx->sub->stencil_refs[1] != ref->ref_value[1]) { in vrend_set_stencil_ref()
9358 ctx->sub->stencil_refs[0] = ref->ref_value[0]; in vrend_set_stencil_ref()
9359 ctx->sub->stencil_refs[1] = ref->ref_value[1]; in vrend_set_stencil_ref()
9360 ctx->sub->stencil_state_dirty = true; in vrend_set_stencil_ref()
9367 ctx->sub->blend_color = *color; in vrend_set_blend_color()
9368 glBlendColor(color->color[0], color->color[1], color->color[2], in vrend_set_blend_color()
9369 color->color[3]); in vrend_set_blend_color()
9381 ctx->sub->ss[idx] = ss[i]; in vrend_set_scissor_state()
9382 ctx->sub->scissor_state_dirty |= (1 << idx); in vrend_set_scissor_state()
9395 ctx->sub->sysvalue_data.stipple_pattern[i][0] = ps->stipple[i]; in vrend_set_polygon_stipple()
9396 ctx->sub->sysvalue_data_cookie++; in vrend_set_polygon_stipple()
9398 glPolygonStipple((const GLubyte *)ps->stipple); in vrend_set_polygon_stipple()
9405 ctx->sub->ucp_state = *ucp; in vrend_set_clip_state()
9407 ctx->sub->sysvalue_data_cookie++; in vrend_set_clip_state()
9409 memcpy(&ctx->sub->sysvalue_data.clipp[i], in vrend_set_clip_state()
9410 (const GLfloat *) &ctx->sub->ucp_state.ucp[i], sizeof(GLfloat) * 4); in vrend_set_clip_state()
9418 val[j] = ucp->ucp[i][j]; in vrend_set_clip_state()
9433 if (ctx->sub->nr_cbufs > 0 && ctx->sub->surf[0]) { in vrend_set_min_samples()
9434 assert(ctx->sub->surf[0]->texture); in vrend_set_min_samples()
9435 min_sample_shading /= MAX2(1, ctx->sub->surf[0]->texture->base.nr_samples); in vrend_set_min_samples()
9458 for (i = 0; i < so_obj->num_targets; i++) { in vrend_hw_emit_streamout_targets()
9459 if (!so_obj->so_targets[i]) in vrend_hw_emit_streamout_targets()
9461 …else if (so_obj->so_targets[i]->buffer_offset || so_obj->so_targets[i]->buffer_size < so_obj->so_t… in vrend_hw_emit_streamout_targets()
9462 …SFORM_FEEDBACK_BUFFER, i, so_obj->so_targets[i]->buffer->id, so_obj->so_targets[i]->buffer_offset,… in vrend_hw_emit_streamout_targets()
9464 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, i, so_obj->so_targets[i]->buffer->id); in vrend_hw_emit_streamout_targets()
9482 LIST_FOR_EACH_ENTRY(obj, &ctx->sub->streamout_list, head) { in vrend_set_streamout_targets()
9483 if (obj->num_targets == num_targets) { in vrend_set_streamout_targets()
9484 if (!memcmp(handles, obj->handles, num_targets * 4)) { in vrend_set_streamout_targets()
9491 ctx->sub->current_so = obj; in vrend_set_streamout_targets()
9492 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, obj->id); in vrend_set_streamout_targets()
9498 glGenTransformFeedbacks(1, &obj->id); in vrend_set_streamout_targets()
9499 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, obj->id); in vrend_set_streamout_targets()
9501 obj->num_targets = num_targets; in vrend_set_streamout_targets()
9503 obj->handles[i] = handles[i]; in vrend_set_streamout_targets()
9506 … target = vrend_object_lookup(ctx->sub->object_hash, handles[i], VIRGL_OBJECT_STREAMOUT_TARGET); in vrend_set_streamout_targets()
9512 vrend_so_target_reference(&obj->so_targets[i], target); in vrend_set_streamout_targets()
9515 list_addtail(&obj->head, &ctx->sub->streamout_list); in vrend_set_streamout_targets()
9516 ctx->sub->current_so = obj; in vrend_set_streamout_targets()
9517 obj->xfb_state = XFB_STATE_STARTED_NEED_BEGIN; in vrend_set_streamout_targets()
9521 ctx->sub->current_so = NULL; in vrend_set_streamout_targets()
9531 glBindBuffer(GL_COPY_READ_BUFFER, src_res->id); in vrend_resource_buffer_copy()
9532 glBindBuffer(GL_COPY_WRITE_BUFFER, dst_res->id); in vrend_resource_buffer_copy()
9549 int elsize = util_format_get_blocksize(dst_res->base.format); in vrend_resource_copy_fallback()
9550 int compressed = util_format_is_compressed(dst_res->base.format); in vrend_resource_copy_fallback()
9556 if (src_res->target == GL_TEXTURE_CUBE_MAP) in vrend_resource_copy_fallback()
9559 if (src_res->base.format != dst_res->base.format) { in vrend_resource_copy_fallback()
9560 …"copy fallback failed due to mismatched formats %d %d\n", src_res->base.format, dst_res->base.form… in vrend_resource_copy_fallback()
9566 dst_stride = util_format_get_stride(dst_res->base.format, dst_res->base.width0); in vrend_resource_copy_fallback()
9569 …_size = util_format_get_nblocks(src_res->base.format, u_minify(src_res->base.width0, src_level), u… in vrend_resource_copy_fallback()
9570 util_format_get_blocksize(src_res->base.format); in vrend_resource_copy_fallback()
9577 glformat = tex_conv_table[src_res->base.format].glformat; in vrend_resource_copy_fallback()
9578 gltype = tex_conv_table[src_res->base.format].gltype; in vrend_resource_copy_fallback()
9581 glformat = tex_conv_table[src_res->base.format].internalformat; in vrend_resource_copy_fallback()
9590 src_offset = src_res->mipmap_offsets[src_level]; in vrend_resource_copy_fallback()
9591 dst_offset = dst_res->mipmap_offsets[src_level]; in vrend_resource_copy_fallback()
9594 src_stride = util_format_get_nblocksx(src_res->base.format, in vrend_resource_copy_fallback()
9595 u_minify(src_res->base.width0, src_level)) * elsize; in vrend_resource_copy_fallback()
9596 src_layer_stride = util_format_get_2d_size(src_res->base.format, in vrend_resource_copy_fallback()
9598 u_minify(src_res->base.height0, src_level)); in vrend_resource_copy_fallback()
9599 read_transfer_data(src_res->iov, src_res->num_iovs, tptr, in vrend_resource_copy_fallback()
9600 src_res->base.format, src_offset, in vrend_resource_copy_fallback()
9603 * we might need it in a chain copy A->B, B->C */ in vrend_resource_copy_fallback()
9604 write_transfer_data(&dst_res->base, dst_res->iov, dst_res->num_iovs, tptr, in vrend_resource_copy_fallback()
9606 /* we get values from the guest as 24-bit scaled integers in vrend_resource_copy_fallback()
9608 as 32-bit scaled integers, so we need to scale them here */ in vrend_resource_copy_fallback()
9609 if (dst_res->base.format == VIRGL_FORMAT_Z24X8_UNORM) { in vrend_resource_copy_fallback()
9615 * storing in a texture. Iovec data is assumed to have the original byte-order, namely BGR*, in vrend_resource_copy_fallback()
9617 * On the contrary, externally-stored BGR* resources are assumed to remain in BGR* format at in vrend_resource_copy_fallback()
9620 if (vrend_state.use_gles && vrend_format_is_bgra(dst_res->base.format)) in vrend_resource_copy_fallback()
9641 glBindTexture(src_res->target, src_res->id); in vrend_resource_copy_fallback()
9643 read_chunk_size = (src_res->target == GL_TEXTURE_CUBE_MAP) ? slice_size : total_size; in vrend_resource_copy_fallback()
9645 GLenum ctarget = src_res->target == GL_TEXTURE_CUBE_MAP ? in vrend_resource_copy_fallback()
9646 (GLenum)(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i) : src_res->target; in vrend_resource_copy_fallback()
9681 glBindTexture(dst_res->target, dst_res->id); in vrend_resource_copy_fallback()
9682 slice_offset = src_box->z * slice_size; in vrend_resource_copy_fallback()
9683 cube_slice = (src_res->target == GL_TEXTURE_CUBE_MAP) ? src_box->z + src_box->depth : cube_slice; in vrend_resource_copy_fallback()
9684 i = (src_res->target == GL_TEXTURE_CUBE_MAP) ? src_box->z : 0; in vrend_resource_copy_fallback()
9686 GLenum ctarget = dst_res->target == GL_TEXTURE_CUBE_MAP ? in vrend_resource_copy_fallback()
9687 (GLenum)(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i) : dst_res->target; in vrend_resource_copy_fallback()
9691 src_box->width, in vrend_resource_copy_fallback()
9695 src_box->width, src_box->height, in vrend_resource_copy_fallback()
9700 … glTexSubImage1D(ctarget, dst_level, dstx, src_box->width, glformat, gltype, tptr + slice_offset); in vrend_resource_copy_fallback()
9704 …TexSubImage3D(ctarget, dst_level, dstx, dsty, dstz, src_box->width, src_box->height, src_box->dept… in vrend_resource_copy_fallback()
9706 …glTexSubImage2D(ctarget, dst_level, dstx, dsty, src_box->width, src_box->height, glformat, gltype,… in vrend_resource_copy_fallback()
9722 glCopyImageSubData(src_res->id, src_res->target, src_level, in vrend_copy_sub_image()
9723 src_box->x, src_box->y, src_box->z, in vrend_copy_sub_image()
9724 dst_res->id, dst_res->target, dst_level, in vrend_copy_sub_image()
9726 src_box->width, src_box->height,src_box->depth); in vrend_copy_sub_image()
9731 if (has_bit(src_res->storage_bits, VREND_STORAGE_GBM_BUFFER) && in vrend_copy_sub_image()
9749 if (ctx->in_error) in vrend_renderer_resource_copy_region()
9766 util_format_name(src_res->base.format), src_res->base.nr_samples, in vrend_renderer_resource_copy_region()
9767 src_box->x, src_box->y, src_box->z, in vrend_renderer_resource_copy_region()
9768 src_box->width, src_box->height, src_box->depth, in vrend_renderer_resource_copy_region()
9770 util_format_name(dst_res->base.format), dst_res->base.nr_samples, in vrend_renderer_resource_copy_region()
9773 if (src_res->base.target == PIPE_BUFFER && dst_res->base.target == PIPE_BUFFER) { in vrend_renderer_resource_copy_region()
9776 src_box->x, src_box->width); in vrend_renderer_resource_copy_region()
9778 src_box->x, src_box->width); in vrend_renderer_resource_copy_region()
9783 if (src_res->egl_image) in vrend_renderer_resource_copy_region()
9785 if (dst_res->egl_image) in vrend_renderer_resource_copy_region()
9789 format_is_copy_compatible(src_res->base.format,dst_res->base.format, comp_flags) && in vrend_renderer_resource_copy_region()
9790 src_res->base.nr_samples == dst_res->base.nr_samples) { in vrend_renderer_resource_copy_region()
9797 if (!vrend_format_can_render(src_res->base.format) || in vrend_renderer_resource_copy_region()
9798 !vrend_format_can_render(dst_res->base.format)) { in vrend_renderer_resource_copy_region()
9805 glBindFramebuffer(GL_FRAMEBUFFER, ctx->sub->blit_fb_ids[0]); in vrend_renderer_resource_copy_region()
9811 vrend_fb_bind_texture(src_res, 0, src_level, src_box->z); in vrend_renderer_resource_copy_region()
9813 glBindFramebuffer(GL_FRAMEBUFFER, ctx->sub->blit_fb_ids[1]); in vrend_renderer_resource_copy_region()
9817 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, ctx->sub->blit_fb_ids[1]); in vrend_renderer_resource_copy_region()
9819 glBindFramebuffer(GL_READ_FRAMEBUFFER, ctx->sub->blit_fb_ids[0]); in vrend_renderer_resource_copy_region()
9824 if (!src_res->y_0_top) { in vrend_renderer_resource_copy_region()
9825 sy1 = src_box->y; in vrend_renderer_resource_copy_region()
9826 sy2 = src_box->y + src_box->height; in vrend_renderer_resource_copy_region()
9828 sy1 = src_res->base.height0 - src_box->y - src_box->height; in vrend_renderer_resource_copy_region()
9829 sy2 = src_res->base.height0 - src_box->y; in vrend_renderer_resource_copy_region()
9832 if (!dst_res->y_0_top) { in vrend_renderer_resource_copy_region()
9834 dy2 = dsty + src_box->height; in vrend_renderer_resource_copy_region()
9836 dy1 = dst_res->base.height0 - dsty - src_box->height; in vrend_renderer_resource_copy_region()
9837 dy2 = dst_res->base.height0 - dsty; in vrend_renderer_resource_copy_region()
9840 glBlitFramebuffer(src_box->x, sy1, in vrend_renderer_resource_copy_region()
9841 src_box->x + src_box->width, in vrend_renderer_resource_copy_region()
9844 dstx + src_box->width, in vrend_renderer_resource_copy_region()
9848 glBindFramebuffer(GL_READ_FRAMEBUFFER, ctx->sub->blit_fb_ids[0]); in vrend_renderer_resource_copy_region()
9851 glBindFramebuffer(GL_READ_FRAMEBUFFER, ctx->sub->blit_fb_ids[1]); in vrend_renderer_resource_copy_region()
9855 glBindFramebuffer(GL_FRAMEBUFFER, ctx->sub->fb_id); in vrend_renderer_resource_copy_region()
9857 if (ctx->sub->rs_state.scissor) in vrend_renderer_resource_copy_region()
9865 GLenum tex_ifmt = tex_conv_table[res->base.format].internalformat; in vrend_make_view()
9869 return res->id; in vrend_make_view()
9872 if (!has_bit(res->storage_bits, VREND_STORAGE_GL_IMMUTABLE)) in vrend_make_view()
9873 return res->id; in vrend_make_view()
9878 util_format_name(res->base.format), in vrend_make_view()
9882 assert(res->target != GL_TEXTURE_RECTANGLE_NV); in vrend_make_view()
9883 assert(res->target != GL_TEXTURE_1D); in vrend_make_view()
9884 assert(res->target != GL_TEXTURE_1D_ARRAY); in vrend_make_view()
9888 glTextureView(view_id, res->target, res->id, view_ifmt, 0, res->base.last_level + 1, in vrend_make_view()
9889 0, res->base.array_size); in vrend_make_view()
9897 /* EGL-backed bgr* resources are always stored with BGR* internal format, in vrend_blit_needs_redblue_swizzle()
9900 bool src_needs_swizzle = vrend_resource_needs_redblue_swizzle(src_res, info->src.format); in vrend_blit_needs_redblue_swizzle()
9901 bool dst_needs_swizzle = vrend_resource_needs_redblue_swizzle(dst_res, info->dst.format); in vrend_blit_needs_redblue_swizzle()
9910 info->can_fbo_blit = true; in vrend_renderer_prepare_blit_extra_info()
9912 info->gl_filter = convert_mag_filter(info->b.filter); in vrend_renderer_prepare_blit_extra_info()
9914 if (!dst_res->y_0_top) { in vrend_renderer_prepare_blit_extra_info()
9915 info->dst_y1 = info->b.dst.box.y + info->b.dst.box.height; in vrend_renderer_prepare_blit_extra_info()
9916 info->dst_y2 = info->b.dst.box.y; in vrend_renderer_prepare_blit_extra_info()
9918 info->dst_y1 = dst_res->base.height0 - info->b.dst.box.y - info->b.dst.box.height; in vrend_renderer_prepare_blit_extra_info()
9919 info->dst_y2 = dst_res->base.height0 - info->b.dst.box.y; in vrend_renderer_prepare_blit_extra_info()
9922 if (!src_res->y_0_top) { in vrend_renderer_prepare_blit_extra_info()
9923 info->src_y1 = info->b.src.box.y + info->b.src.box.height; in vrend_renderer_prepare_blit_extra_info()
9924 info->src_y2 = info->b.src.box.y; in vrend_renderer_prepare_blit_extra_info()
9926 info->src_y1 = src_res->base.height0 - info->b.src.box.y - info->b.src.box.height; in vrend_renderer_prepare_blit_extra_info()
9927 info->src_y2 = src_res->base.height0 - info->b.src.box.y; in vrend_renderer_prepare_blit_extra_info()
9930 if (vrend_blit_needs_swizzle(info->b.dst.format, info->b.src.format)) { in vrend_renderer_prepare_blit_extra_info()
9931 info->needs_swizzle = true; in vrend_renderer_prepare_blit_extra_info()
9932 info->can_fbo_blit = false; in vrend_renderer_prepare_blit_extra_info()
9935 …if (info->needs_swizzle && vrend_get_format_table_entry(dst_res->base.format)->flags & VIRGL_TEXTU… in vrend_renderer_prepare_blit_extra_info()
9936 memcpy(info->swizzle, tex_conv_table[dst_res->base.format].swizzle, sizeof(info->swizzle)); in vrend_renderer_prepare_blit_extra_info()
9938 if (vrend_blit_needs_redblue_swizzle(src_res, dst_res, &info->b)) { in vrend_renderer_prepare_blit_extra_info()
9940 uint8_t temp = info->swizzle[0]; in vrend_renderer_prepare_blit_extra_info()
9941 info->swizzle[0] = info->swizzle[2]; in vrend_renderer_prepare_blit_extra_info()
9942 info->swizzle[2] = temp; in vrend_renderer_prepare_blit_extra_info()
9943 info->can_fbo_blit = false; in vrend_renderer_prepare_blit_extra_info()
9947 if (info->b.mask & PIPE_MASK_RGBA && in vrend_renderer_prepare_blit_extra_info()
9948 src_res->base.nr_samples > 0 && in vrend_renderer_prepare_blit_extra_info()
9949 src_res->base.nr_samples != dst_res->base.nr_samples && in vrend_renderer_prepare_blit_extra_info()
9950 (info->b.src.box.width != info->b.dst.box.width || in vrend_renderer_prepare_blit_extra_info()
9951 info->b.src.box.height != info->b.dst.box.height)) { in vrend_renderer_prepare_blit_extra_info()
9953 info->gl_filter = GL_SCALED_RESOLVE_NICEST_EXT; in vrend_renderer_prepare_blit_extra_info()
9955 info->can_fbo_blit = false; in vrend_renderer_prepare_blit_extra_info()
9960 * (EGL-image bgr* textures). */ in vrend_renderer_prepare_blit_extra_info()
9961 if (vrend_resource_needs_srgb_decode(src_res, info->b.src.format)) { in vrend_renderer_prepare_blit_extra_info()
9962 info->needs_manual_srgb_decode = true; in vrend_renderer_prepare_blit_extra_info()
9963 info->can_fbo_blit = false; in vrend_renderer_prepare_blit_extra_info()
9965 if (vrend_resource_needs_srgb_encode(dst_res, info->b.dst.format)) { in vrend_renderer_prepare_blit_extra_info()
9966 info->needs_manual_srgb_encode = true; in vrend_renderer_prepare_blit_extra_info()
9967 info->can_fbo_blit = false; in vrend_renderer_prepare_blit_extra_info()
9977 if (!info->can_fbo_blit) in vrend_renderer_prepare_blit()
9981 if (!vrend_format_can_render(src_res->base.format) && in vrend_renderer_prepare_blit()
9982 !vrend_format_is_ds(src_res->base.format)) in vrend_renderer_prepare_blit()
9985 if (!vrend_format_can_render(src_res->base.format) && in vrend_renderer_prepare_blit()
9986 !vrend_format_is_ds(src_res->base.format)) in vrend_renderer_prepare_blit()
9990 if (vrend_format_is_ds(src_res->base.format) && in vrend_renderer_prepare_blit()
9991 vrend_format_is_ds(dst_res->base.format)) { in vrend_renderer_prepare_blit()
9992 if (src_res->base.format != dst_res->base.format) { in vrend_renderer_prepare_blit()
9993 if (!(src_res->base.format == PIPE_FORMAT_S8_UINT_Z24_UNORM && in vrend_renderer_prepare_blit()
9994 (dst_res->base.format == PIPE_FORMAT_Z24X8_UNORM))) { in vrend_renderer_prepare_blit()
9999 /* glBlitFramebuffer - can support depth stencil with NEAREST in vrend_renderer_prepare_blit()
10001 if ((info->b.mask & (PIPE_MASK_Z | PIPE_MASK_S)) && info->gl_filter != GL_NEAREST) in vrend_renderer_prepare_blit()
10005 * https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5034 in vrend_renderer_prepare_blit()
10010 info->b.mask & PIPE_MASK_RGBA && in vrend_renderer_prepare_blit()
10011 src_res->base.format == VIRGL_FORMAT_R8G8B8X8_UNORM && in vrend_renderer_prepare_blit()
10012 dst_res->base.format == VIRGL_FORMAT_R8G8B8X8_UNORM && in vrend_renderer_prepare_blit()
10013 has_bit(src_res->storage_bits, VREND_STORAGE_EGL_IMAGE) != in vrend_renderer_prepare_blit()
10014 has_bit(dst_res->storage_bits, VREND_STORAGE_EGL_IMAGE) && in vrend_renderer_prepare_blit()
10015 (src_res->base.nr_samples || dst_res->base.nr_samples)) { in vrend_renderer_prepare_blit()
10019 /* GLES generally doesn't support blitting to a multi-sample FB, and also not in vrend_renderer_prepare_blit()
10020 * from a multi-sample FB where the regions are not exatly the same or the in vrend_renderer_prepare_blit()
10024 ((dst_res->base.nr_samples > 0) || in vrend_renderer_prepare_blit()
10025 ((info->b.mask & PIPE_MASK_RGBA) && in vrend_renderer_prepare_blit()
10026 (src_res->base.nr_samples > 0) && in vrend_renderer_prepare_blit()
10027 (info->b.src.box.x != info->b.dst.box.x || in vrend_renderer_prepare_blit()
10028 info->b.src.box.width != info->b.dst.box.width || in vrend_renderer_prepare_blit()
10029 info->dst_y1 != info->src_y1 || info->dst_y2 != info->src_y2 || in vrend_renderer_prepare_blit()
10030 info->b.src.format != info->b.dst.format)) in vrend_renderer_prepare_blit()
10032 …VREND_DEBUG(dbg_blit, ctx, "Use GL fallback because dst:ms:%d src:ms:%d (%d %d %d %d) -> (%d %d %d… in vrend_renderer_prepare_blit()
10033 …dst_res->base.nr_samples, src_res->base.nr_samples, info->b.src.box.x, info->b.src.box.x + info->b… in vrend_renderer_prepare_blit()
10034 …info->src_y1, info->src_y2, info->b.dst.box.x, info->b.dst.box.x + info->b.dst.box.width, info->ds… in vrend_renderer_prepare_blit()
10038 /* for 3D mipmapped blits - hand roll time */ in vrend_renderer_prepare_blit()
10039 if (info->b.src.box.depth != info->b.dst.box.depth) in vrend_renderer_prepare_blit()
10051 if (info->b.mask & PIPE_MASK_Z) in vrend_renderer_blit_fbo()
10053 if (info->b.mask & PIPE_MASK_S) in vrend_renderer_blit_fbo()
10055 if (info->b.mask & PIPE_MASK_RGBA) in vrend_renderer_blit_fbo()
10059 if (info->b.scissor_enable) { in vrend_renderer_blit_fbo()
10060 glScissor(info->b.scissor.minx, info->b.scissor.miny, in vrend_renderer_blit_fbo()
10061 info->b.scissor.maxx - info->b.scissor.minx, in vrend_renderer_blit_fbo()
10062 info->b.scissor.maxy - info->b.scissor.miny); in vrend_renderer_blit_fbo()
10063 ctx->sub->scissor_state_dirty = (1 << 0); in vrend_renderer_blit_fbo()
10069 * multi-sample fbo to a non multi-sample fbo and the source and destination in vrend_renderer_blit_fbo()
10075 * limitations on GLES first copy the full frame to a non-multisample in vrend_renderer_blit_fbo()
10083 (info->b.mask & PIPE_MASK_ZS) && in vrend_renderer_blit_fbo()
10084 ((src_res->base.nr_samples > 0) && in vrend_renderer_blit_fbo()
10085 (src_res->base.nr_samples != dst_res->base.nr_samples)) && in vrend_renderer_blit_fbo()
10086 ((info->b.src.box.x != info->b.dst.box.x) || in vrend_renderer_blit_fbo()
10087 (info->src_y1 != info->dst_y1) || in vrend_renderer_blit_fbo()
10088 (info->b.src.box.width != info->b.dst.box.width) || in vrend_renderer_blit_fbo()
10089 (info->src_y2 != info->dst_y2))) { in vrend_renderer_blit_fbo()
10094 * without multi-sample */ in vrend_renderer_blit_fbo()
10097 args.width = src_res->base.width0; in vrend_renderer_blit_fbo()
10098 args.height = src_res->base.height0; in vrend_renderer_blit_fbo()
10099 args.depth = src_res->base.depth0; in vrend_renderer_blit_fbo()
10100 args.format = info->b.src.format; in vrend_renderer_blit_fbo()
10101 args.target = src_res->base.target; in vrend_renderer_blit_fbo()
10102 args.last_level = src_res->base.last_level; in vrend_renderer_blit_fbo()
10103 args.array_size = src_res->base.array_size; in vrend_renderer_blit_fbo()
10115 intermediate_fbo = ctx->sub->blit_fb_ids[0]; in vrend_renderer_blit_fbo()
10119 glBindFramebuffer(GL_FRAMEBUFFER, ctx->sub->blit_fb_ids[0]); in vrend_renderer_blit_fbo()
10120 if (info->b.mask & PIPE_MASK_RGBA) in vrend_renderer_blit_fbo()
10126 glBindFramebuffer(GL_FRAMEBUFFER, ctx->sub->blit_fb_ids[1]); in vrend_renderer_blit_fbo()
10127 if (info->b.mask & PIPE_MASK_RGBA) in vrend_renderer_blit_fbo()
10130 else if (info->b.mask & (PIPE_MASK_Z | PIPE_MASK_S)) in vrend_renderer_blit_fbo()
10134 int n_layers = info->b.src.box.depth == info->b.dst.box.depth ? info->b.dst.box.depth : 1; in vrend_renderer_blit_fbo()
10136 glBindFramebuffer(GL_FRAMEBUFFER, ctx->sub->blit_fb_ids[0]); in vrend_renderer_blit_fbo()
10137 … vrend_fb_bind_texture_id(src_res, info->src_view, 0, info->b.src.level, info->b.src.box.z + i, 0); in vrend_renderer_blit_fbo()
10140 int level_width = u_minify(src_res->base.width0, info->b.src.level); in vrend_renderer_blit_fbo()
10141 int level_height = u_minify(src_res->base.width0, info->b.src.level); in vrend_renderer_blit_fbo()
10145 vrend_fb_bind_texture(intermediate_copy, 0, info->b.src.level, info->b.src.box.z + i); in vrend_renderer_blit_fbo()
10148 glBindFramebuffer(GL_READ_FRAMEBUFFER, ctx->sub->blit_fb_ids[0]); in vrend_renderer_blit_fbo()
10151 glmask, info->gl_filter); in vrend_renderer_blit_fbo()
10154 glBindFramebuffer(GL_FRAMEBUFFER, ctx->sub->blit_fb_ids[1]); in vrend_renderer_blit_fbo()
10155 … vrend_fb_bind_texture_id(dst_res, info->dst_view, 0, info->b.dst.level, info->b.dst.box.z + i, 0); in vrend_renderer_blit_fbo()
10156 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, ctx->sub->blit_fb_ids[1]); in vrend_renderer_blit_fbo()
10159 if (util_format_is_srgb(info->b.dst.format) || in vrend_renderer_blit_fbo()
10160 util_format_is_srgb(info->b.src.format)) in vrend_renderer_blit_fbo()
10168 glBlitFramebuffer(info->b.src.box.x, in vrend_renderer_blit_fbo()
10169 info->src_y1, in vrend_renderer_blit_fbo()
10170 info->b.src.box.x + info->b.src.box.width, in vrend_renderer_blit_fbo()
10171 info->src_y2, in vrend_renderer_blit_fbo()
10172 info->b.dst.box.x, in vrend_renderer_blit_fbo()
10173 info->dst_y1, in vrend_renderer_blit_fbo()
10174 info->b.dst.box.x + info->b.dst.box.width, in vrend_renderer_blit_fbo()
10175 info->dst_y2, in vrend_renderer_blit_fbo()
10176 glmask, info->gl_filter); in vrend_renderer_blit_fbo()
10179 glBindFramebuffer(GL_FRAMEBUFFER, ctx->sub->blit_fb_ids[1]); in vrend_renderer_blit_fbo()
10185 glBindFramebuffer(GL_FRAMEBUFFER, ctx->sub->blit_fb_ids[0]); in vrend_renderer_blit_fbo()
10191 glBindFramebuffer(GL_FRAMEBUFFER, ctx->sub->fb_id); in vrend_renderer_blit_fbo()
10194 if (ctx->sub->framebuffer_srgb_enabled) in vrend_renderer_blit_fbo()
10205 if (ctx->sub->rs_state.scissor) in vrend_renderer_blit_fbo()
10219 .src_view = src_res->id, in vrend_renderer_blit_int()
10220 .dst_view = dst_res->id, in vrend_renderer_blit_int()
10226 if ((src_res->base.format != info->src.format) && has_feature(feat_texture_view) && in vrend_renderer_blit_int()
10227 vrend_resource_supports_view(src_res, info->src.format)) in vrend_renderer_blit_int()
10228 blit_info.src_view = vrend_make_view(src_res, info->src.format); in vrend_renderer_blit_int()
10230 if ((dst_res->base.format != info->dst.format) && has_feature(feat_texture_view) && in vrend_renderer_blit_int()
10231 vrend_resource_supports_view(dst_res, info->dst.format)) in vrend_renderer_blit_int()
10232 blit_info.dst_view = vrend_make_view(dst_res, info->dst.format); in vrend_renderer_blit_int()
10245 vrend_sync_make_current(ctx->sub->gl_context); in vrend_renderer_blit_int()
10248 if (blit_info.src_view != src_res->id) in vrend_renderer_blit_int()
10251 if (blit_info.dst_view != dst_res->id) in vrend_renderer_blit_int()
10274 if (ctx->in_error) in vrend_renderer_blit()
10277 if (!info->src.format || info->src.format >= VIRGL_FORMAT_MAX) { in vrend_renderer_blit()
10278 vrend_report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_FORMAT, info->src.format); in vrend_renderer_blit()
10282 if (!info->dst.format || info->dst.format >= VIRGL_FORMAT_MAX) { in vrend_renderer_blit()
10283 vrend_report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_FORMAT, info->dst.format); in vrend_renderer_blit()
10287 if (info->render_condition_enable == false) in vrend_renderer_blit()
10293 info->render_condition_enable, info->scissor_enable, in vrend_renderer_blit()
10294 info->filter, info->alpha_blend, info->mask, in vrend_renderer_blit()
10295 util_format_name(src_res->base.format), in vrend_renderer_blit()
10296 util_format_name(info->src.format), in vrend_renderer_blit()
10297 src_res->base.nr_samples, in vrend_renderer_blit()
10298 has_bit(src_res->storage_bits, VREND_STORAGE_EGL_IMAGE), in vrend_renderer_blit()
10299 has_bit(src_res->storage_bits, VREND_STORAGE_GBM_BUFFER), in vrend_renderer_blit()
10300 info->src.box.x, info->src.box.y, info->src.box.z, in vrend_renderer_blit()
10301 info->src.box.width, info->src.box.height, info->src.box.depth, in vrend_renderer_blit()
10302 info->src.level, in vrend_renderer_blit()
10303 util_format_name(dst_res->base.format), in vrend_renderer_blit()
10304 util_format_name(info->dst.format), in vrend_renderer_blit()
10305 dst_res->base.nr_samples, in vrend_renderer_blit()
10306 has_bit(dst_res->storage_bits, VREND_STORAGE_EGL_IMAGE), in vrend_renderer_blit()
10307 has_bit(dst_res->storage_bits, VREND_STORAGE_GBM_BUFFER), in vrend_renderer_blit()
10308 info->dst.box.x, info->dst.box.y, info->dst.box.z, in vrend_renderer_blit()
10309 info->dst.box.width, info->dst.box.height, info->dst.box.depth, in vrend_renderer_blit()
10310 info->dst.level); in vrend_renderer_blit()
10312 if (src_res->egl_image) in vrend_renderer_blit()
10314 if (dst_res->egl_image) in vrend_renderer_blit()
10321 !(vrend_resource_needs_srgb_decode(src_res, info->src.format) || in vrend_renderer_blit()
10322 vrend_resource_needs_srgb_encode(dst_res, info->dst.format)); in vrend_renderer_blit()
10324 src_width = u_minify(src_res->base.width0, info->src.level); in vrend_renderer_blit()
10325 src_height = u_minify(src_res->base.height0, info->src.level); in vrend_renderer_blit()
10326 dst_width = u_minify(dst_res->base.width0, info->dst.level); in vrend_renderer_blit()
10327 dst_height = u_minify(dst_res->base.height0, info->dst.level); in vrend_renderer_blit()
10337 (!info->render_condition_enable || !ctx->sub->cond_render_gl_mode) && in vrend_renderer_blit()
10338 format_is_copy_compatible(info->src.format,info->dst.format, comp_flags) && in vrend_renderer_blit()
10340 !info->scissor_enable && (info->filter == PIPE_TEX_FILTER_NEAREST) && in vrend_renderer_blit()
10341 !info->alpha_blend && (info->mask == PIPE_MASK_RGBA) && in vrend_renderer_blit()
10342 src_res->base.nr_samples == dst_res->base.nr_samples && in vrend_renderer_blit()
10343 info->src.box.x + info->src.box.width <= src_width && in vrend_renderer_blit()
10344 info->dst.box.x + info->dst.box.width <= dst_width && in vrend_renderer_blit()
10345 info->src.box.y + info->src.box.height <= src_height && in vrend_renderer_blit()
10346 info->dst.box.y + info->dst.box.height <= dst_height && in vrend_renderer_blit()
10347 info->src.box.width == info->dst.box.width && in vrend_renderer_blit()
10348 info->src.box.height == info->dst.box.height && in vrend_renderer_blit()
10349 info->src.box.depth == info->dst.box.depth) { in vrend_renderer_blit()
10351 vrend_copy_sub_image(src_res, dst_res, info->src.level, &info->src.box, in vrend_renderer_blit()
10352 info->dst.level, info->dst.box.x, info->dst.box.y, in vrend_renderer_blit()
10353 info->dst.box.z); in vrend_renderer_blit()
10359 if (info->render_condition_enable == false) in vrend_renderer_blit()
10367 assert(ctx->ctx_id); in vrend_renderer_set_fence_retire()
10368 ctx->fence_retire = retire; in vrend_renderer_set_fence_retire()
10369 ctx->fence_retire_data = retire_data; in vrend_renderer_set_fence_retire()
10385 fence->ctx = ctx; in vrend_renderer_create_fence()
10386 fence->flags = flags; in vrend_renderer_create_fence()
10387 fence->fence_id = fence_id; in vrend_renderer_create_fence()
10391 fence->eglsyncobj = virgl_egl_fence_create(egl); in vrend_renderer_create_fence()
10395 fence->glsyncobj = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); in vrend_renderer_create_fence()
10399 if (fence->glsyncobj == NULL) in vrend_renderer_create_fence()
10404 list_addtail(&fence->fences, &vrend_state.fence_wait_list); in vrend_renderer_create_fence()
10408 list_addtail(&fence->fences, &vrend_state.fence_list); in vrend_renderer_create_fence()
10423 if (fence->fences.next == signaled_list) in need_fence_retire_signal_locked()
10427 next = LIST_ENTRY(struct vrend_fence, fence->fences.next, fences); in need_fence_retire_signal_locked()
10428 if (next->ctx != fence->ctx) in need_fence_retire_signal_locked()
10432 if (!(fence->flags & VIRGL_RENDERER_FENCE_FLAG_MERGEABLE)) in need_fence_retire_signal_locked()
10452 * by setting fence->ctx to NULL in vrend_renderer_check_fences()
10454 if (!fence->ctx) { in vrend_renderer_check_fences()
10460 list_del(&fence->fences); in vrend_renderer_check_fences()
10461 list_addtail(&fence->fences, &retired_fences); in vrend_renderer_check_fences()
10472 list_del(&fence->fences); in vrend_renderer_check_fences()
10473 list_addtail(&fence->fences, &retired_fences); in vrend_renderer_check_fences()
10492 struct vrend_context *ctx = fence->ctx; in vrend_renderer_check_fences()
10493 ctx->fence_retire(fence->fence_id, ctx->fence_retire_data); in vrend_renderer_check_fences()
10523 if (!ctx->sub->fake_occlusion_query_samples_passed_multiplier) { in vrend_update_oq_samples_multiplier()
10527 ctx->sub->fake_occlusion_query_samples_passed_multiplier = in vrend_update_oq_samples_multiplier()
10538 state.result_size = vrend_is_timer_query(query->gltype) ? 8 : 4; in vrend_check_query()
10539 ret = vrend_get_one_query_result(query->id, state.result_size == 8, in vrend_check_query()
10547 if (query->fake_samples_passed) { in vrend_check_query()
10548 vrend_update_oq_samples_multiplier(query->ctx); in vrend_check_query()
10549 state.result *= query->ctx->sub->fake_occlusion_query_samples_passed_multiplier; in vrend_check_query()
10554 if (query->res->iov) { in vrend_check_query()
10555 vrend_write_to_iovec(query->res->iov, query->res->num_iovs, 0, in vrend_check_query()
10558 *((struct virgl_host_query_state *) query->res->ptr) = state; in vrend_check_query()
10569 if (ctx->sub && ctx->sub->sub_ctx_id == sub_ctx_id) in vrend_renderer_find_sub_ctx()
10570 return ctx->sub; in vrend_renderer_find_sub_ctx()
10572 LIST_FOR_EACH_ENTRY(sub, &ctx->sub_ctxs, head) { in vrend_renderer_find_sub_ctx()
10573 if (sub->sub_ctx_id == sub_ctx_id) in vrend_renderer_find_sub_ctx()
10585 if (ctx == vrend_state.current_ctx && sub_ctx_id == ctx->sub->sub_ctx_id && in vrend_hw_switch_context_with_sub()
10586 ctx->ctx_switch_pending == false) { in vrend_hw_switch_context_with_sub()
10590 if (ctx->ctx_id != 0 && ctx->in_error) in vrend_hw_switch_context_with_sub()
10598 if (ctx->sub != sub) { in vrend_hw_switch_context_with_sub()
10600 ctx->sub = sub; in vrend_hw_switch_context_with_sub()
10603 ctx->ctx_switch_pending = true; in vrend_hw_switch_context_with_sub()
10615 if (!vrend_hw_switch_context_with_sub(query->ctx, query->sub_ctx_id)) { in vrend_renderer_check_queries()
10617 query->ctx->ctx_id, query->sub_ctx_id, query->id); in vrend_renderer_check_queries()
10623 list_delinit(&query->waiting_queries); in vrend_renderer_check_queries()
10635 if (ctx == vrend_state.current_ctx && ctx->ctx_switch_pending == false) in vrend_hw_switch_context()
10638 if (ctx->ctx_id != 0 && ctx->in_error) { in vrend_hw_switch_context()
10642 ctx->ctx_switch_pending = true; in vrend_hw_switch_context()
10652 if (ctx->ctx_switch_pending == false) in vrend_finish_context_switch()
10654 ctx->ctx_switch_pending = false; in vrend_finish_context_switch()
10661 vrend_clicbs->make_current(ctx->sub->gl_context); in vrend_finish_context_switch()
10667 vrend_object_remove(ctx->sub->object_hash, handle, 0); in vrend_renderer_object_destroy()
10673 return vrend_object_insert(ctx->sub->object_hash, data, handle, type); in vrend_renderer_object_insert()
10682 if (!res || !has_bit(res->storage_bits, VREND_STORAGE_HOST_SYSTEM_MEMORY)) { in vrend_create_query()
10707 list_inithead(&q->waiting_queries); in vrend_create_query()
10708 q->type = query_type; in vrend_create_query()
10709 q->index = query_index; in vrend_create_query()
10710 q->ctx = ctx; in vrend_create_query()
10711 q->sub_ctx_id = ctx->sub->sub_ctx_id; in vrend_create_query()
10712 q->fake_samples_passed = fake_samples_passed; in vrend_create_query()
10714 vrend_resource_reference(&q->res, res); in vrend_create_query()
10716 switch (q->type) { in vrend_create_query()
10718 q->gltype = GL_SAMPLES_PASSED_ARB; in vrend_create_query()
10722 q->gltype = GL_ANY_SAMPLES_PASSED; in vrend_create_query()
10728 q->gltype = GL_TIMESTAMP; in vrend_create_query()
10734 q->gltype = GL_TIME_ELAPSED; in vrend_create_query()
10739 q->gltype = GL_PRIMITIVES_GENERATED; in vrend_create_query()
10742 q->gltype = GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN; in vrend_create_query()
10745 q->gltype = GL_ANY_SAMPLES_PASSED_CONSERVATIVE; in vrend_create_query()
10749 q->gltype = GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW_ARB; in vrend_create_query()
10755 q->gltype = GL_TRANSFORM_FEEDBACK_OVERFLOW_ARB; in vrend_create_query()
10760 vrend_printf("unknown query object received %d\n", q->type); in vrend_create_query()
10765 glGenQueries(1, &q->id); in vrend_create_query()
10767 glDeleteQueries(1, &q->id); in vrend_create_query()
10780 vrend_resource_reference(&query->res, NULL); in vrend_destroy_query()
10781 list_del(&query->waiting_queries); in vrend_destroy_query()
10782 glDeleteQueries(1, &query->id); in vrend_destroy_query()
10796 q = vrend_object_lookup(ctx->sub->object_hash, handle, VIRGL_OBJECT_QUERY); in vrend_begin_query()
10800 if (q->index > 0 && !has_feature(feat_transform_feedback3)) in vrend_begin_query()
10803 list_delinit(&q->waiting_queries); in vrend_begin_query()
10805 if (q->gltype == GL_TIMESTAMP) in vrend_begin_query()
10808 if (q->index > 0) in vrend_begin_query()
10809 glBeginQueryIndexed(q->gltype, q->index, q->id); in vrend_begin_query()
10811 glBeginQuery(q->gltype, q->id); in vrend_begin_query()
10818 q = vrend_object_lookup(ctx->sub->object_hash, handle, VIRGL_OBJECT_QUERY); in vrend_end_query()
10822 if (q->index > 0 && !has_feature(feat_transform_feedback3)) in vrend_end_query()
10825 if (vrend_is_timer_query(q->gltype)) { in vrend_end_query()
10826 if (q->gltype == GL_TIMESTAMP && !has_feature(feat_timer_query)) { in vrend_end_query()
10828 } else if (q->gltype == GL_TIMESTAMP) { in vrend_end_query()
10829 glQueryCounter(q->id, q->gltype); in vrend_end_query()
10832 glEndQuery(q->gltype); in vrend_end_query()
10837 if (q->index > 0) in vrend_end_query()
10838 glEndQueryIndexed(q->gltype, q->index); in vrend_end_query()
10840 glEndQuery(q->gltype); in vrend_end_query()
10850 q = vrend_object_lookup(ctx->sub->object_hash, handle, VIRGL_OBJECT_QUERY); in vrend_get_query_result()
10856 list_delinit(&q->waiting_queries); in vrend_get_query_result()
10857 } else if (LIST_IS_EMPTY(&q->waiting_queries)) { in vrend_get_query_result()
10858 list_addtail(&q->waiting_queries, &vrend_state.waiting_query_list); in vrend_get_query_result()
10888 q = vrend_object_lookup(ctx->sub->object_hash, handle, VIRGL_OBJECT_QUERY); in vrend_get_query_result_qbo()
10898 VREND_DEBUG(dbg_query, ctx, "Get query result from Query:%d\n", q->id); in vrend_get_query_result_qbo()
10902 if (index == -1) in vrend_get_query_result_qbo()
10907 if (!q->fake_samples_passed) { in vrend_get_query_result_qbo()
10908 glBindBuffer(GL_QUERY_BUFFER, res->id); in vrend_get_query_result_qbo()
10911 glGetQueryObjectiv(q->id, qtype, buffer_offset(offset)); in vrend_get_query_result_qbo()
10914 glGetQueryObjectuiv(q->id, qtype, buffer_offset(offset)); in vrend_get_query_result_qbo()
10917 glGetQueryObjecti64v(q->id, qtype, buffer_offset(offset)); in vrend_get_query_result_qbo()
10920 glGetQueryObjectui64v(q->id, qtype, buffer_offset(offset)); in vrend_get_query_result_qbo()
10932 glGetQueryObjectiv(q->id, qtype, &value); in vrend_get_query_result_qbo()
10933 …COPY_QUERY_RESULT_TO_BUFFER(q->id, offset, value, 4, ctx->sub->fake_occlusion_query_samples_passed… in vrend_get_query_result_qbo()
10938 glGetQueryObjectuiv(q->id, qtype, &value); in vrend_get_query_result_qbo()
10939 …COPY_QUERY_RESULT_TO_BUFFER(q->id, offset, value, 4, ctx->sub->fake_occlusion_query_samples_passed… in vrend_get_query_result_qbo()
10944 glGetQueryObjecti64v(q->id, qtype, &value); in vrend_get_query_result_qbo()
10945 …COPY_QUERY_RESULT_TO_BUFFER(q->id, offset, value, 8, ctx->sub->fake_occlusion_query_samples_passed… in vrend_get_query_result_qbo()
10950 glGetQueryObjectui64v(q->id, qtype, &value); in vrend_get_query_result_qbo()
10951 …COPY_QUERY_RESULT_TO_BUFFER(q->id, offset, value, 8, ctx->sub->fake_occlusion_query_samples_passed… in vrend_get_query_result_qbo()
10965 if (ctx->sub->cond_render_q_id) { in vrend_pause_render_condition()
10972 if (ctx->sub->cond_render_q_id) { in vrend_pause_render_condition()
10974 glBeginConditionalRender(ctx->sub->cond_render_q_id, in vrend_pause_render_condition()
10975 ctx->sub->cond_render_gl_mode); in vrend_pause_render_condition()
10977 glBeginConditionalRenderNV(ctx->sub->cond_render_q_id, in vrend_pause_render_condition()
10978 ctx->sub->cond_render_gl_mode); in vrend_pause_render_condition()
10996 ctx->sub->cond_render_q_id = 0; in vrend_render_condition()
10997 ctx->sub->cond_render_gl_mode = 0; in vrend_render_condition()
11001 q = vrend_object_lookup(ctx->sub->object_hash, handle, VIRGL_OBJECT_QUERY); in vrend_render_condition()
11024 ctx->sub->cond_render_q_id = q->id; in vrend_render_condition()
11025 ctx->sub->cond_render_gl_mode = glmode; in vrend_render_condition()
11027 glBeginConditionalRender(q->id, glmode); in vrend_render_condition()
11029 glBeginConditionalRenderNV(q->id, glmode); in vrend_render_condition()
11051 pipe_reference_init(&target->reference, 1); in vrend_create_so_target()
11052 target->res_handle = res_handle; in vrend_create_so_target()
11053 target->buffer_offset = buffer_offset; in vrend_create_so_target()
11054 target->buffer_size = buffer_size; in vrend_create_so_target()
11055 target->sub_ctx = ctx->sub; in vrend_create_so_target()
11056 vrend_resource_reference(&target->buffer, res); in vrend_create_so_target()
11090 caps->v1.glsl_level = 120; in vrend_fill_caps_glsl_version()
11093 caps->v1.glsl_level = 310; in vrend_fill_caps_glsl_version()
11095 caps->v1.glsl_level = 130; in vrend_fill_caps_glsl_version()
11099 caps->v1.glsl_level = 130; in vrend_fill_caps_glsl_version()
11102 caps->v1.glsl_level = 140; in vrend_fill_caps_glsl_version()
11104 caps->v1.glsl_level = 150; in vrend_fill_caps_glsl_version()
11106 caps->v1.glsl_level = 10 * gl_ver; in vrend_fill_caps_glsl_version()
11109 if (caps->v1.glsl_level < 400) { in vrend_fill_caps_glsl_version()
11117 caps->v1.glsl_level = 400; in vrend_fill_caps_glsl_version()
11121 caps->v1.glsl_level = 410; in vrend_fill_caps_glsl_version()
11130 caps->v1.glsl_level = 430; in vrend_fill_caps_glsl_version()
11134 vrend_printf("GLSL feature level %d\n", caps->v1.glsl_level); in vrend_fill_caps_glsl_version()
11143 assert(idx < ARRAY_SIZE(mask->bitmask)); in set_format_bit()
11144 mask->bitmask[idx] |= 1u << bit; in set_format_bit()
11160 caps->v1.bset.occlusion_query = 1; in vrend_renderer_fill_caps_v1()
11163 caps->v1.prim_mask = (1 << PIPE_PRIM_POINTS) | (1 << PIPE_PRIM_LINES) | in vrend_renderer_fill_caps_v1()
11169 caps->v1.bset.poly_stipple = 1; in vrend_renderer_fill_caps_v1()
11170 caps->v1.bset.color_clamping = 1; in vrend_renderer_fill_caps_v1()
11171 caps->v1.prim_mask |= (1 << PIPE_PRIM_QUADS) | in vrend_renderer_fill_caps_v1()
11176 if (caps->v1.glsl_level >= 150) { in vrend_renderer_fill_caps_v1()
11177 caps->v1.prim_mask |= (1 << PIPE_PRIM_LINES_ADJACENCY) | in vrend_renderer_fill_caps_v1()
11182 if (caps->v1.glsl_level >= 400 || has_feature(feat_tessellation)) in vrend_renderer_fill_caps_v1()
11183 caps->v1.prim_mask |= (1 << PIPE_PRIM_PATCHES); in vrend_renderer_fill_caps_v1()
11186 set_format_bit(&caps->v1.vertexbuffer, VIRGL_FORMAT_R11G11B10_FLOAT); in vrend_renderer_fill_caps_v1()
11190 caps->v1.bset.conditional_render = 1; in vrend_renderer_fill_caps_v1()
11193 caps->v1.bset.indep_blend_enable = 1; in vrend_renderer_fill_caps_v1()
11196 caps->v1.bset.instanceid = 1; in vrend_renderer_fill_caps_v1()
11202 caps->v1.max_uniform_blocks = max + 1 - 1; in vrend_renderer_fill_caps_v1()
11206 caps->v1.bset.depth_clip_disable = 1; in vrend_renderer_fill_caps_v1()
11209 caps->v1.bset.fragment_coord_conventions = 1; in vrend_renderer_fill_caps_v1()
11210 caps->v1.bset.seamless_cube_map = 1; in vrend_renderer_fill_caps_v1()
11213 caps->v1.bset.fragment_coord_conventions = 1; in vrend_renderer_fill_caps_v1()
11215 caps->v1.bset.seamless_cube_map = 1; in vrend_renderer_fill_caps_v1()
11219 caps->v1.bset.seamless_cube_map_per_texture = 1; in vrend_renderer_fill_caps_v1()
11223 caps->v1.bset.texture_multisample = 1; in vrend_renderer_fill_caps_v1()
11226 caps->v1.bset.has_tessellation_shaders = 1; in vrend_renderer_fill_caps_v1()
11229 caps->v1.bset.has_sample_shading = 1; in vrend_renderer_fill_caps_v1()
11232 caps->v1.bset.has_indirect_draw = 1; in vrend_renderer_fill_caps_v1()
11235 caps->v1.bset.indep_blend_func = 1; in vrend_renderer_fill_caps_v1()
11238 caps->v1.bset.cube_map_array = 1; in vrend_renderer_fill_caps_v1()
11241 caps->v1.bset.texture_query_lod = 1; in vrend_renderer_fill_caps_v1()
11244 caps->v1.bset.has_fp64 = 1; in vrend_renderer_fill_caps_v1()
11249 caps->v1.bset.has_fp64 = 1; in vrend_renderer_fill_caps_v1()
11253 caps->v1.bset.start_instance = 1; in vrend_renderer_fill_caps_v1()
11256 caps->v1.bset.shader_stencil_export = 1; in vrend_renderer_fill_caps_v1()
11260 caps->v1.bset.conditional_render_inverted = 1; in vrend_renderer_fill_caps_v1()
11263 caps->v1.bset.has_cull = 1; in vrend_renderer_fill_caps_v1()
11264 caps->v1.bset.derivative_control = 1; in vrend_renderer_fill_caps_v1()
11267 caps->v1.bset.has_cull = 1; in vrend_renderer_fill_caps_v1()
11269 caps->v1.bset.derivative_control = 1; in vrend_renderer_fill_caps_v1()
11273 caps->v1.bset.polygon_offset_clamp = 1; in vrend_renderer_fill_caps_v1()
11276 caps->v1.bset.transform_feedback_overflow_query = 1; in vrend_renderer_fill_caps_v1()
11281 caps->v1.bset.mirror_clamp = true; in vrend_renderer_fill_caps_v1()
11286 caps->v1.max_texture_array_layers = max; in vrend_renderer_fill_caps_v1()
11292 caps->v1.bset.streamout_pause_resume = 1; in vrend_renderer_fill_caps_v1()
11296 caps->v1.max_streamout_buffers = max; in vrend_renderer_fill_caps_v1()
11301 caps->v1.max_streamout_buffers = 4; in vrend_renderer_fill_caps_v1()
11304 caps->v1.max_streamout_buffers = 4; in vrend_renderer_fill_caps_v1()
11309 caps->v1.max_dual_source_render_targets = max; in vrend_renderer_fill_caps_v1()
11314 vrend_state.max_texture_buffer_size = caps->v1.max_tbo_size = max; in vrend_renderer_fill_caps_v1()
11320 caps->v1.max_texture_gather_components = max; in vrend_renderer_fill_caps_v1()
11322 caps->v1.max_texture_gather_components = 4; in vrend_renderer_fill_caps_v1()
11328 caps->v1.max_viewports = max; in vrend_renderer_fill_caps_v1()
11330 caps->v1.max_viewports = 1; in vrend_renderer_fill_caps_v1()
11334 caps->v1.bset.timer_query = 1; in vrend_renderer_fill_caps_v1()
11338 caps->v1.max_render_targets = vrend_state.max_draw_buffers; in vrend_renderer_fill_caps_v1()
11341 caps->v1.max_samples = max; in vrend_renderer_fill_caps_v1()
11349 set_format_bit(&caps->v1.sampler, fmt); in vrend_renderer_fill_caps_v1()
11351 set_format_bit(&caps->v1.render, fmt); in vrend_renderer_fill_caps_v1()
11359 caps->v1.bset.primitive_restart = 1; in vrend_renderer_fill_caps_v1()
11373 * run on an old virgl host. Use it also to indicate non-cap fixes on the in vrend_renderer_fill_caps_v2()
11375 caps->v2.host_feature_check_version = 15; in vrend_renderer_fill_caps_v2()
11378 strncpy(caps->v2.renderer, renderer, sizeof(caps->v2.renderer) - 1); in vrend_renderer_fill_caps_v2()
11383 char *llvmpipe_string = strstr(caps->v2.renderer, "llvmpipe"); in vrend_renderer_fill_caps_v2()
11388 caps->v2.min_aliased_point_size = range[0]; in vrend_renderer_fill_caps_v2()
11389 caps->v2.max_aliased_point_size = range[1]; in vrend_renderer_fill_caps_v2()
11392 caps->v2.min_aliased_line_width = range[0]; in vrend_renderer_fill_caps_v2()
11393 caps->v2.max_aliased_line_width = range[1]; in vrend_renderer_fill_caps_v2()
11397 caps->v2.min_smooth_point_size = range[0]; in vrend_renderer_fill_caps_v2()
11398 caps->v2.max_smooth_point_size = range[1]; in vrend_renderer_fill_caps_v2()
11401 caps->v2.min_smooth_line_width = range[0]; in vrend_renderer_fill_caps_v2()
11402 caps->v2.max_smooth_line_width = range[1]; in vrend_renderer_fill_caps_v2()
11405 glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &caps->v2.max_texture_lod_bias); in vrend_renderer_fill_caps_v2()
11406 glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, (GLint*)&caps->v2.max_vertex_attribs); in vrend_renderer_fill_caps_v2()
11413 caps->v2.max_vertex_outputs = max / 4; in vrend_renderer_fill_caps_v2()
11415 glGetIntegerv(GL_MIN_PROGRAM_TEXEL_OFFSET, &caps->v2.min_texel_offset); in vrend_renderer_fill_caps_v2()
11416 glGetIntegerv(GL_MAX_PROGRAM_TEXEL_OFFSET, &caps->v2.max_texel_offset); in vrend_renderer_fill_caps_v2()
11418 …glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, (GLint*)&caps->v2.uniform_buffer_offset_alignmen… in vrend_renderer_fill_caps_v2()
11420 glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&caps->v2.max_texture_2d_size); in vrend_renderer_fill_caps_v2()
11421 glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, (GLint*)&caps->v2.max_texture_3d_size); in vrend_renderer_fill_caps_v2()
11422 glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, (GLint*)&caps->v2.max_texture_cube_size); in vrend_renderer_fill_caps_v2()
11423 vrend_state.max_texture_2d_size = caps->v2.max_texture_2d_size; in vrend_renderer_fill_caps_v2()
11424 vrend_state.max_texture_3d_size = caps->v2.max_texture_3d_size; in vrend_renderer_fill_caps_v2()
11425 vrend_state.max_texture_cube_size = caps->v2.max_texture_cube_size; in vrend_renderer_fill_caps_v2()
11431 glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES, (GLint*)&caps->v2.max_geom_output_vertices); in vrend_renderer_fill_caps_v2()
11432 …glGetIntegerv(GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS, (GLint*)&caps->v2.max_geom_total_output_com… in vrend_renderer_fill_caps_v2()
11437 caps->v2.max_shader_patch_varyings = max / 4; in vrend_renderer_fill_caps_v2()
11439 caps->v2.max_shader_patch_varyings = 0; in vrend_renderer_fill_caps_v2()
11441 vrend_state.max_shader_patch_varyings = caps->v2.max_shader_patch_varyings; in vrend_renderer_fill_caps_v2()
11444 glGetIntegerv(GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET, &caps->v2.min_texture_gather_offset); in vrend_renderer_fill_caps_v2()
11445 glGetIntegerv(GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET, &caps->v2.max_texture_gather_offset); in vrend_renderer_fill_caps_v2()
11449 …glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, (GLint*)&caps->v2.texture_buffer_offset_alignmen… in vrend_renderer_fill_caps_v2()
11453 …glGetIntegerv(GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT, (GLint*)&caps->v2.shader_buffer_offset_al… in vrend_renderer_fill_caps_v2()
11458 caps->v2.max_shader_buffer_other_stages = max; in vrend_renderer_fill_caps_v2()
11462 caps->v2.max_shader_buffer_frag_compute = max; in vrend_renderer_fill_caps_v2()
11464 (GLint*)&caps->v2.max_combined_shader_buffers); in vrend_renderer_fill_caps_v2()
11471 caps->v2.max_shader_image_other_stages = max; in vrend_renderer_fill_caps_v2()
11475 caps->v2.max_shader_image_frag_compute = max; in vrend_renderer_fill_caps_v2()
11478 glGetIntegerv(GL_MAX_IMAGE_SAMPLES, (GLint*)&caps->v2.max_image_samples); in vrend_renderer_fill_caps_v2()
11482 caps->v1.max_samples = vrend_renderer_query_multisample_caps(caps->v1.max_samples, &caps->v2); in vrend_renderer_fill_caps_v2()
11484 caps->v2.capability_bits |= VIRGL_CAP_TGSI_INVARIANT | VIRGL_CAP_SET_MIN_SAMPLES | in vrend_renderer_fill_caps_v2()
11490 glGetIntegerv(GL_MAX_VERTEX_ATTRIB_STRIDE, (GLint*)&caps->v2.max_vertex_attrib_stride); in vrend_renderer_fill_caps_v2()
11492 caps->v2.max_vertex_attrib_stride = 2048; in vrend_renderer_fill_caps_v2()
11495 …glGetIntegerv(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS, (GLint*)&caps->v2.max_compute_work_group_invo… in vrend_renderer_fill_caps_v2()
11496 …glGetIntegerv(GL_MAX_COMPUTE_SHARED_MEMORY_SIZE, (GLint*)&caps->v2.max_compute_shared_memory_size); in vrend_renderer_fill_caps_v2()
11497 … glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 0, (GLint*)&caps->v2.max_compute_grid_size[0]); in vrend_renderer_fill_caps_v2()
11498 … glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 1, (GLint*)&caps->v2.max_compute_grid_size[1]); in vrend_renderer_fill_caps_v2()
11499 … glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 2, (GLint*)&caps->v2.max_compute_grid_size[2]); in vrend_renderer_fill_caps_v2()
11500 … glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, (GLint*)&caps->v2.max_compute_block_size[0]); in vrend_renderer_fill_caps_v2()
11501 … glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 1, (GLint*)&caps->v2.max_compute_block_size[1]); in vrend_renderer_fill_caps_v2()
11502 … glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 2, (GLint*)&caps->v2.max_compute_block_size[2]); in vrend_renderer_fill_caps_v2()
11504 caps->v2.capability_bits |= VIRGL_CAP_COMPUTE_SHADER; in vrend_renderer_fill_caps_v2()
11512 (GLint*)(caps->v2.max_atomic_counters + PIPE_SHADER_VERTEX)); in vrend_renderer_fill_caps_v2()
11514 (GLint*)(caps->v2.max_atomic_counters + PIPE_SHADER_FRAGMENT)); in vrend_renderer_fill_caps_v2()
11518 (GLint*)(caps->v2.max_atomic_counters + PIPE_SHADER_GEOMETRY)); in vrend_renderer_fill_caps_v2()
11523 (GLint*)(caps->v2.max_atomic_counters + PIPE_SHADER_TESS_CTRL)); in vrend_renderer_fill_caps_v2()
11525 (GLint*)(caps->v2.max_atomic_counters + PIPE_SHADER_TESS_EVAL)); in vrend_renderer_fill_caps_v2()
11530 (GLint*)(caps->v2.max_atomic_counters + PIPE_SHADER_COMPUTE)); in vrend_renderer_fill_caps_v2()
11534 (GLint*)&caps->v2.max_combined_atomic_counters); in vrend_renderer_fill_caps_v2()
11538 (GLint*)(caps->v2.max_atomic_counter_buffers + PIPE_SHADER_VERTEX)); in vrend_renderer_fill_caps_v2()
11541 (GLint*)(caps->v2.max_atomic_counter_buffers + PIPE_SHADER_FRAGMENT)); in vrend_renderer_fill_caps_v2()
11545 (GLint*)(caps->v2.max_atomic_counter_buffers + PIPE_SHADER_GEOMETRY)); in vrend_renderer_fill_caps_v2()
11549 (GLint*)(caps->v2.max_atomic_counter_buffers + PIPE_SHADER_TESS_CTRL)); in vrend_renderer_fill_caps_v2()
11551 (GLint*)(caps->v2.max_atomic_counter_buffers + PIPE_SHADER_TESS_EVAL)); in vrend_renderer_fill_caps_v2()
11556 (GLint*)(caps->v2.max_atomic_counter_buffers + PIPE_SHADER_COMPUTE)); in vrend_renderer_fill_caps_v2()
11560 (GLint*)&caps->v2.max_combined_atomic_counter_buffers); in vrend_renderer_fill_caps_v2()
11564 caps->v2.capability_bits |= VIRGL_CAP_FB_NO_ATTACH; in vrend_renderer_fill_caps_v2()
11567 caps->v2.capability_bits |= VIRGL_CAP_TEXTURE_VIEW; in vrend_renderer_fill_caps_v2()
11570 caps->v2.capability_bits |= VIRGL_CAP_TXQS; in vrend_renderer_fill_caps_v2()
11573 caps->v2.capability_bits |= VIRGL_CAP_MEMORY_BARRIER; in vrend_renderer_fill_caps_v2()
11576 caps->v2.capability_bits |= VIRGL_CAP_COPY_IMAGE; in vrend_renderer_fill_caps_v2()
11579 caps->v2.capability_bits |= VIRGL_CAP_ROBUST_BUFFER_ACCESS; in vrend_renderer_fill_caps_v2()
11582 caps->v2.capability_bits |= VIRGL_CAP_TGSI_FBFETCH; in vrend_renderer_fill_caps_v2()
11585 caps->v2.capability_bits |= VIRGL_CAP_SHADER_CLOCK; in vrend_renderer_fill_caps_v2()
11588 caps->v2.capability_bits |= VIRGL_CAP_TEXTURE_BARRIER; in vrend_renderer_fill_caps_v2()
11590 caps->v2.capability_bits |= VIRGL_CAP_TGSI_COMPONENTS; in vrend_renderer_fill_caps_v2()
11593 caps->v2.capability_bits |= VIRGL_CAP_SRGB_WRITE_CONTROL; in vrend_renderer_fill_caps_v2()
11596 caps->v2.capability_bits |= VIRGL_CAP_TRANSFORM_FEEDBACK3; in vrend_renderer_fill_caps_v2()
11603 caps->v2.capability_bits |= VIRGL_CAP_GUEST_MAY_INIT_LOG; in vrend_renderer_fill_caps_v2()
11606 caps->v2.capability_bits |= VIRGL_CAP_QBO; in vrend_renderer_fill_caps_v2()
11608 caps->v2.capability_bits |= VIRGL_CAP_TRANSFER; in vrend_renderer_fill_caps_v2()
11611 caps->v2.capability_bits |= VIRGL_CAP_FBO_MIXED_COLOR_FORMATS; in vrend_renderer_fill_caps_v2()
11615 caps->v2.capability_bits |= VIRGL_CAP_HOST_IS_GLES; in vrend_renderer_fill_caps_v2()
11619 caps->v2.capability_bits |= VIRGL_CAP_BIND_COMMAND_ARGS; in vrend_renderer_fill_caps_v2()
11622 caps->v2.capability_bits |= VIRGL_CAP_MULTI_DRAW_INDIRECT; in vrend_renderer_fill_caps_v2()
11625 caps->v2.capability_bits |= VIRGL_CAP_INDIRECT_PARAMS; in vrend_renderer_fill_caps_v2()
11636 set_format_bit(&caps->v2.supported_readback_formats, fmt); in vrend_renderer_fill_caps_v2()
11641 set_format_bit(&caps->v2.supported_multisample_formats, fmt); in vrend_renderer_fill_caps_v2()
11649 set_format_bit(&caps->v2.scanout, fmt); in vrend_renderer_fill_caps_v2()
11653 set_format_bit(&caps->v2.supported_multisample_formats, VIRGL_FORMAT_NONE); in vrend_renderer_fill_caps_v2()
11656 caps->v2.capability_bits |= VIRGL_CAP_CLEAR_TEXTURE; in vrend_renderer_fill_caps_v2()
11659 caps->v2.capability_bits |= VIRGL_CAP_CLIP_HALFZ; in vrend_renderer_fill_caps_v2()
11662 caps->v2.capability_bits |= VIRGL_CAP_3D_ASTC; in vrend_renderer_fill_caps_v2()
11664 caps->v2.capability_bits |= VIRGL_CAP_INDIRECT_INPUT_ADDR; in vrend_renderer_fill_caps_v2()
11666 caps->v2.capability_bits |= VIRGL_CAP_COPY_TRANSFER; in vrend_renderer_fill_caps_v2()
11674 * Intel GPUs (aside from Atom, which doesn't expose GL4.5) are cache-coherent. in vrend_renderer_fill_caps_v2()
11675 * Mesa AMDGPUs use write-combine mappings for coherent/persistent memory (see in vrend_renderer_fill_caps_v2()
11696 caps->v2.capability_bits |= VIRGL_CAP_ARB_BUFFER_STORAGE; in vrend_renderer_fill_caps_v2()
11702 if ((!strcmp(gbm_device_get_backend_name(gbm->device), "i915") || in vrend_renderer_fill_caps_v2()
11703 !strcmp(gbm_device_get_backend_name(gbm->device), "amdgpu")) && in vrend_renderer_fill_caps_v2()
11705 caps->v2.capability_bits |= VIRGL_CAP_ARB_BUFFER_STORAGE; in vrend_renderer_fill_caps_v2()
11707 caps->v2.capability_bits_v2 |= VIRGL_CAP_V2_SCANOUT_USES_GBM; in vrend_renderer_fill_caps_v2()
11712 caps->v2.capability_bits_v2 |= VIRGL_CAP_V2_BLEND_EQUATION; in vrend_renderer_fill_caps_v2()
11716 caps->v2.capability_bits_v2 |= VIRGL_CAP_V2_UNTYPED_RESOURCE; in vrend_renderer_fill_caps_v2()
11721 caps->v2.capability_bits_v2 |= VIRGL_CAP_V2_VIDEO_MEMORY; in vrend_renderer_fill_caps_v2()
11722 caps->v2.max_video_memory = video_memory; in vrend_renderer_fill_caps_v2()
11726 caps->v2.capability_bits_v2 |= VIRGL_CAP_V2_MEMINFO; in vrend_renderer_fill_caps_v2()
11730 caps->v2.capability_bits_v2 |= VIRGL_CAP_V2_STRING_MARKER; in vrend_renderer_fill_caps_v2()
11733 caps->v2.capability_bits_v2 |= VIRGL_CAP_V2_IMPLICIT_MSAA; in vrend_renderer_fill_caps_v2()
11736 caps->v2.capability_bits_v2 |= VIRGL_CAP_V2_DIFFERENT_GPU; in vrend_renderer_fill_caps_v2()
11739 caps->v2.capability_bits_v2 |= VIRGL_CAP_V2_TEXTURE_SHADOW_LOD; in vrend_renderer_fill_caps_v2()
11747 caps->v2.capability_bits_v2 |= VIRGL_CAP_V2_COPY_TRANSFER_BOTH_DIRECTIONS; in vrend_renderer_fill_caps_v2()
11752 caps->v2.max_anisotropy = MIN2(max_aniso, 16.0); in vrend_renderer_fill_caps_v2()
11756 caps->v2.max_texture_image_units = MIN2(max, PIPE_MAX_SHADER_SAMPLER_VIEWS); in vrend_renderer_fill_caps_v2()
11760 caps->v2.max_uniform_block_size = max; in vrend_renderer_fill_caps_v2()
11765 caps->v2.max_const_buffer_size[PIPE_SHADER_VERTEX] = max * 4; in vrend_renderer_fill_caps_v2()
11768 caps->v2.max_const_buffer_size[PIPE_SHADER_FRAGMENT] = max * 4; in vrend_renderer_fill_caps_v2()
11772 caps->v2.max_const_buffer_size[PIPE_SHADER_GEOMETRY] = max * 4; in vrend_renderer_fill_caps_v2()
11777 caps->v2.max_const_buffer_size[PIPE_SHADER_TESS_CTRL] = max * 4; in vrend_renderer_fill_caps_v2()
11779 caps->v2.max_const_buffer_size[PIPE_SHADER_TESS_EVAL] = max * 4; in vrend_renderer_fill_caps_v2()
11784 caps->v2.max_const_buffer_size[PIPE_SHADER_COMPUTE] = max * 4; in vrend_renderer_fill_caps_v2()
11788 caps->v2.capability_bits_v2 |= VIRGL_CAP_V2_SSO; in vrend_renderer_fill_caps_v2()
11793 caps->v2.num_video_caps = 0; in vrend_renderer_fill_caps_v2()
11812 caps->max_version = VREND_CAPSET_VIRGL_MAX_VERSION; in vrend_renderer_fill_caps()
11818 caps->max_version = VREND_CAPSET_VIRGL2_MAX_VERSION; in vrend_renderer_fill_caps()
11825 /* We don't want to deal with stale error states that the caller might not in vrend_renderer_fill_caps()
11829 vrend_printf("%s: Entering with stale GL error: %d\n", __func__, err); in vrend_renderer_fill_caps()
11840 VREND_DEBUG(dbg_features, NULL, "GLSL support level: %d", caps->v1.glsl_level); in vrend_renderer_fill_caps()
11868 if (res->base.width0 > 128 || res->base.height0 > 128) in vrend_renderer_get_cursor_contents()
11871 if (res->target != GL_TEXTURE_2D) in vrend_renderer_get_cursor_contents()
11877 *width = res->base.width0; in vrend_renderer_get_cursor_contents()
11878 *height = res->base.height0; in vrend_renderer_get_cursor_contents()
11880 format = tex_conv_table[res->base.format].glformat; in vrend_renderer_get_cursor_contents()
11881 type = tex_conv_table[res->base.format].gltype; in vrend_renderer_get_cursor_contents()
11882 blsize = util_format_get_blocksize(res->base.format); in vrend_renderer_get_cursor_contents()
11883 size = util_format_get_nblocks(res->base.format, res->base.width0, res->base.height0) * blsize; in vrend_renderer_get_cursor_contents()
11894 glBindTexture(res->target, res->id); in vrend_renderer_get_cursor_contents()
11895 glGetnTexImageARB(res->target, 0, format, type, size, data); in vrend_renderer_get_cursor_contents()
11899 glBindTexture(res->target, res->id); in vrend_renderer_get_cursor_contents()
11900 glGetTexImage(res->target, 0, format, type, data); in vrend_renderer_get_cursor_contents()
11903 for (h = 0; h < res->base.height0; h++) { in vrend_renderer_get_cursor_contents()
11904 uint32_t doff = (res->base.height0 - h - 1) * res->base.width0 * blsize; in vrend_renderer_get_cursor_contents()
11905 uint32_t soff = h * res->base.width0 * blsize; in vrend_renderer_get_cursor_contents()
11907 memcpy(data2 + doff, data + soff, res->base.width0 * blsize); in vrend_renderer_get_cursor_contents()
11910 glBindTexture(res->target, 0); in vrend_renderer_get_cursor_contents()
11935 elsize = util_format_get_blocksize(res->base.format); in vrend_renderer_get_rect()
11945 transfer_info.stride = util_format_get_nblocksx(res->base.format, res->base.width0) * elsize; in vrend_renderer_get_rect()
11957 if (!res->pipe_resource) { in vrend_renderer_attach_res_ctx()
11959 if (unlikely(ctx->untyped_resource_cache)) { in vrend_renderer_attach_res_ctx()
11960 struct virgl_resource *last = ctx->untyped_resource_cache; in vrend_renderer_attach_res_ctx()
11963 wrapper->resource = last; in vrend_renderer_attach_res_ctx()
11964 list_add(&wrapper->head, &ctx->untyped_resources); in vrend_renderer_attach_res_ctx()
11966 vrend_printf("dropping attached resource %d due to OOM\n", last->res_id); in vrend_renderer_attach_res_ctx()
11970 ctx->untyped_resource_cache = res; in vrend_renderer_attach_res_ctx()
11975 vrend_ctx_resource_insert(ctx->res_hash, in vrend_renderer_attach_res_ctx()
11976 res->res_id, in vrend_renderer_attach_res_ctx()
11977 (struct vrend_resource *)res->pipe_resource); in vrend_renderer_attach_res_ctx()
11983 if (!res->pipe_resource) { in vrend_renderer_detach_res_ctx()
11984 if (ctx->untyped_resource_cache == res) { in vrend_renderer_detach_res_ctx()
11985 ctx->untyped_resource_cache = NULL; in vrend_renderer_detach_res_ctx()
11988 LIST_FOR_EACH_ENTRY(iter, &ctx->untyped_resources, head) { in vrend_renderer_detach_res_ctx()
11989 if (iter->resource == res) { in vrend_renderer_detach_res_ctx()
11990 list_del(&iter->head); in vrend_renderer_detach_res_ctx()
12000 vrend_ctx_resource_remove(ctx->res_hash, res->res_id); in vrend_renderer_detach_res_ctx()
12005 return vrend_ctx_resource_lookup(ctx->res_hash, res_handle); in vrend_renderer_ctx_res_lookup()
12011 ctx->debug_flags |= vrend_get_debug_flags(flagstring); in vrend_context_set_debug_flags()
12012 if (ctx->debug_flags & dbg_features) in vrend_context_set_debug_flags()
12023 elsize = util_format_get_blocksize(res->base.format); in vrend_renderer_resource_get_info()
12025 info->tex_id = res->id; in vrend_renderer_resource_get_info()
12026 info->width = res->base.width0; in vrend_renderer_resource_get_info()
12027 info->height = res->base.height0; in vrend_renderer_resource_get_info()
12028 info->depth = res->base.depth0; in vrend_renderer_resource_get_info()
12029 info->format = res->base.format; in vrend_renderer_resource_get_info()
12030 info->flags = res->y_0_top ? VIRGL_RESOURCE_Y_0_TOP : 0; in vrend_renderer_resource_get_info()
12031 … info->stride = util_format_get_nblocksx(res->base.format, u_minify(res->base.width0, 0)) * elsize; in vrend_renderer_resource_get_info()
12059 LIST_FOR_EACH_ENTRY(sub, &ctx->sub_ctxs, head) { in vrend_renderer_create_sub_ctx()
12060 if (sub->sub_ctx_id == sub_ctx_id) { in vrend_renderer_create_sub_ctx()
12069 ctx_params.shared = (ctx->ctx_id == 0 && sub_ctx_id == 0) ? false : true; in vrend_renderer_create_sub_ctx()
12072 sub->gl_context = vrend_clicbs->create_gl_context(0, &ctx_params); in vrend_renderer_create_sub_ctx()
12073 sub->parent = ctx; in vrend_renderer_create_sub_ctx()
12074 vrend_clicbs->make_current(sub->gl_context); in vrend_renderer_create_sub_ctx()
12083 sub->sub_ctx_id = sub_ctx_id; in vrend_renderer_create_sub_ctx()
12087 sub->vps[i].far_val = 1.0; in vrend_renderer_create_sub_ctx()
12092 sub->hw_blend_state.rt[i].colormask = 0xf; in vrend_renderer_create_sub_ctx()
12096 glGenVertexArrays(1, &sub->vaoid); in vrend_renderer_create_sub_ctx()
12097 glBindVertexArray(sub->vaoid); in vrend_renderer_create_sub_ctx()
12100 glGenFramebuffers(1, &sub->fb_id); in vrend_renderer_create_sub_ctx()
12101 glBindFramebuffer(GL_FRAMEBUFFER, sub->fb_id); in vrend_renderer_create_sub_ctx()
12102 glGenFramebuffers(2, sub->blit_fb_ids); in vrend_renderer_create_sub_ctx()
12105 list_inithead(&sub->gl_programs[i]); in vrend_renderer_create_sub_ctx()
12106 list_inithead(&sub->cs_programs); in vrend_renderer_create_sub_ctx()
12107 list_inithead(&sub->streamout_list); in vrend_renderer_create_sub_ctx()
12109 sub->object_hash = vrend_object_init_ctx_table(); in vrend_renderer_create_sub_ctx()
12111 sub->sysvalue_data.winsys_adjust_y = 1.f; in vrend_renderer_create_sub_ctx()
12112 sub->sysvalue_data_cookie = 1; in vrend_renderer_create_sub_ctx()
12114 ctx->sub = sub; in vrend_renderer_create_sub_ctx()
12115 list_add(&sub->head, &ctx->sub_ctxs); in vrend_renderer_create_sub_ctx()
12117 ctx->sub0 = sub; in vrend_renderer_create_sub_ctx()
12119 vrend_set_tweak_from_env(&ctx->sub->tweaks); in vrend_renderer_create_sub_ctx()
12124 return ctx && (ctx->debug_flags & flag); in vrend_context_has_debug_flag()
12130 vrend_printf("%s: ", ctx->debug_name); in vrend_print_context_name()
12144 LIST_FOR_EACH_ENTRY(sub, &ctx->sub_ctxs, head) { in vrend_renderer_destroy_sub_ctx()
12145 if (sub->sub_ctx_id == sub_ctx_id) { in vrend_renderer_destroy_sub_ctx()
12151 if (ctx->sub == tofree) { in vrend_renderer_destroy_sub_ctx()
12152 ctx->sub = ctx->sub0; in vrend_renderer_destroy_sub_ctx()
12155 vrend_clicbs->make_current(ctx->sub->gl_context); in vrend_renderer_destroy_sub_ctx()
12162 if (sub && ctx->sub != sub) { in vrend_renderer_set_sub_ctx()
12163 ctx->sub = sub; in vrend_renderer_set_sub_ctx()
12164 vrend_clicbs->make_current(sub->gl_context); in vrend_renderer_set_sub_ctx()
12200 if (res->gbm_bo) in vrend_renderer_export_query()
12201 return virgl_gbm_export_query(res->gbm_bo, export_query); in vrend_renderer_export_query()
12210 export_query->out_num_fds = 0; in vrend_renderer_export_query()
12211 export_query->out_fourcc = 0; in vrend_renderer_export_query()
12212 export_query->out_modifier = DRM_FORMAT_MOD_INVALID; in vrend_renderer_export_query()
12213 if (export_query->in_export_fds) in vrend_renderer_export_query()
12214 return -EINVAL; in vrend_renderer_export_query()
12227 res->blob_id = blob_id; in vrend_renderer_pipe_resource_create()
12228 list_addtail(&res->head, &ctx->vrend_resources); in vrend_renderer_pipe_resource_create()
12237 LIST_FOR_EACH_ENTRY_SAFE(res, stor, &ctx->vrend_resources, head) { in vrend_get_blob_pipe()
12238 if (res->blob_id != id) in vrend_get_blob_pipe()
12241 list_del(&res->head); in vrend_get_blob_pipe()
12243 res->blob_id = 0; in vrend_get_blob_pipe()
12244 return &res->base; in vrend_get_blob_pipe()
12258 if (ctx->untyped_resource_cache && in vrend_renderer_pipe_resource_set_type()
12259 ctx->untyped_resource_cache->res_id == res_id) { in vrend_renderer_pipe_resource_set_type()
12260 res = ctx->untyped_resource_cache; in vrend_renderer_pipe_resource_set_type()
12261 ctx->untyped_resource_cache = NULL; in vrend_renderer_pipe_resource_set_type()
12265 LIST_FOR_EACH_ENTRY(iter, &ctx->untyped_resources, head) { in vrend_renderer_pipe_resource_set_type()
12266 if (iter->resource->res_id == res_id) { in vrend_renderer_pipe_resource_set_type()
12267 res = iter->resource; in vrend_renderer_pipe_resource_set_type()
12268 list_del(&iter->head); in vrend_renderer_pipe_resource_set_type()
12285 if (!res->pipe_resource) { in vrend_renderer_pipe_resource_set_type()
12289 .format = args->format, in vrend_renderer_pipe_resource_set_type()
12290 .bind = args->bind, in vrend_renderer_pipe_resource_set_type()
12291 .width = args->width, in vrend_renderer_pipe_resource_set_type()
12292 .height = args->height, in vrend_renderer_pipe_resource_set_type()
12305 if (res->fd_type != VIRGL_RESOURCE_FD_DMABUF) in vrend_renderer_pipe_resource_set_type()
12308 for (uint32_t i = 0; i < args->plane_count; i++) in vrend_renderer_pipe_resource_set_type()
12309 plane_fds[i] = res->fd; in vrend_renderer_pipe_resource_set_type()
12315 virgl_format = gr->base.format; in vrend_renderer_pipe_resource_set_type()
12323 gr->egl_image = virgl_egl_image_from_dmabuf(egl, in vrend_renderer_pipe_resource_set_type()
12324 args->width, in vrend_renderer_pipe_resource_set_type()
12325 args->height, in vrend_renderer_pipe_resource_set_type()
12327 args->modifier, in vrend_renderer_pipe_resource_set_type()
12328 args->plane_count, in vrend_renderer_pipe_resource_set_type()
12330 args->plane_strides, in vrend_renderer_pipe_resource_set_type()
12331 args->plane_offsets); in vrend_renderer_pipe_resource_set_type()
12332 if (!gr->egl_image) { in vrend_renderer_pipe_resource_set_type()
12338 gr->storage_bits |= VREND_STORAGE_EGL_IMAGE; in vrend_renderer_pipe_resource_set_type()
12340 ret = vrend_resource_alloc_texture(gr, virgl_format, gr->egl_image); in vrend_renderer_pipe_resource_set_type()
12342 virgl_egl_image_destroy(egl, gr->egl_image); in vrend_renderer_pipe_resource_set_type()
12348 close(res->fd); in vrend_renderer_pipe_resource_set_type()
12349 res->fd = -1; in vrend_renderer_pipe_resource_set_type()
12350 res->fd_type = VIRGL_RESOURCE_FD_INVALID; in vrend_renderer_pipe_resource_set_type()
12351 res->pipe_resource = &gr->base; in vrend_renderer_pipe_resource_set_type()
12359 vrend_ctx_resource_insert(ctx->res_hash, in vrend_renderer_pipe_resource_set_type()
12360 res->res_id, in vrend_renderer_pipe_resource_set_type()
12361 (struct vrend_resource *)res->pipe_resource); in vrend_renderer_pipe_resource_set_type()
12369 return res->map_info; in vrend_renderer_resource_get_map_info()
12375 if (!has_bits(res->storage_bits, VREND_STORAGE_GL_BUFFER | VREND_STORAGE_GL_IMMUTABLE)) in vrend_renderer_resource_map()
12376 return -EINVAL; in vrend_renderer_resource_map()
12378 glBindBufferARB(res->target, res->id); in vrend_renderer_resource_map()
12379 *map = glMapBufferRange(res->target, 0, res->size, res->buffer_storage_flags); in vrend_renderer_resource_map()
12381 return -EINVAL; in vrend_renderer_resource_map()
12383 glBindBufferARB(res->target, 0); in vrend_renderer_resource_map()
12384 *out_size = res->size; in vrend_renderer_resource_map()
12391 if (!has_bits(res->storage_bits, VREND_STORAGE_GL_BUFFER | VREND_STORAGE_GL_IMMUTABLE)) in vrend_renderer_resource_unmap()
12392 return -EINVAL; in vrend_renderer_resource_unmap()
12394 glBindBufferARB(res->target, res->id); in vrend_renderer_resource_unmap()
12395 glUnmapBuffer(res->target); in vrend_renderer_resource_unmap()
12396 glBindBufferARB(res->target, 0); in vrend_renderer_resource_unmap()
12416 if (iter->ctx != vrend_state.ctx0) in find_ctx0_fence_locked()
12419 if (iter->fence_id == fence_id) { in find_ctx0_fence_locked()
12425 if (fence_id < iter->fence_id) in find_ctx0_fence_locked()
12438 return -EINVAL; in vrend_renderer_export_ctx0_fence()
12465 return virgl_egl_export_fence(egl, fence->eglsyncobj, out_fd) ? 0 : -EINVAL; in vrend_renderer_export_ctx0_fence()
12467 return virgl_egl_export_signaled_fence(egl, out_fd) ? 0 : -EINVAL; in vrend_renderer_export_ctx0_fence()
12473 return -EINVAL; in vrend_renderer_export_ctx0_fence()
12487 info = (struct virgl_memory_info *)res->iov->iov_base; in vrend_renderer_get_meminfo()
12492 info->total_device_memory = i; in vrend_renderer_get_meminfo()
12494 info->total_staging_memory = i - info->total_device_memory; in vrend_renderer_get_meminfo()
12496 info->nr_device_memory_evictions = i; in vrend_renderer_get_meminfo()
12498 info->device_memory_evicted = i; in vrend_renderer_get_meminfo()
12504 info->avail_device_memory = i[0]; in vrend_renderer_get_meminfo()
12505 info->avail_staging_memory = i[2]; in vrend_renderer_get_meminfo()
12519 …d vrend_context_emit_string_marker(struct vrend_context *ctx, GLsizei length, const char * message) in vrend_context_emit_string_marker() argument
12521 VREND_DEBUG(dbg_khr, ctx, "MARKER: '%.*s'\n", length, message); in vrend_context_emit_string_marker()
12525 if (length > 6 && !strncmp(message, "BEGIN:", 6)) { in vrend_context_emit_string_marker()
12526 snprintf(buf, 256, "%.*s", length - 6, &message[6]); in vrend_context_emit_string_marker()
12528 } else if (length > 4 && !strncmp(message, "END:", 4)) { in vrend_context_emit_string_marker()
12529 snprintf(buf, 256, "%.*s", length - 4, &message[4]); in vrend_context_emit_string_marker()
12540 length, message); in vrend_context_emit_string_marker()
12545 length, message); in vrend_context_emit_string_marker()
12552 return ctx->video; in vrend_context_get_video_ctx()