project
stringclasses 633
values | commit_id
stringlengths 7
81
| target
int64 0
1
| func
stringlengths 5
484k
| cwe
stringclasses 131
values | big_vul_idx
float64 0
189k
⌀ | idx
int64 0
522k
| hash
stringlengths 34
39
| size
float64 1
24k
⌀ | message
stringlengths 0
11.5k
⌀ | dataset
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
int vrend_renderer_create_fence(int client_fence_id, uint32_t ctx_id)
{
struct vrend_fence *fence;
fence = malloc(sizeof(struct vrend_fence));
if (!fence)
return ENOMEM;
fence->ctx_id = ctx_id;
fence->fence_id = client_fence_id;
fence->syncobj = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
if (fence->syncobj == NULL)
goto fail;
if (vrend_state.sync_thread) {
pipe_mutex_lock(vrend_state.fence_mutex);
list_addtail(&fence->fences, &vrend_state.fence_wait_list);
pipe_mutex_unlock(vrend_state.fence_mutex);
pipe_condvar_signal(vrend_state.fence_cond);
} else
list_addtail(&fence->fences, &vrend_state.fence_list);
return 0;
fail:
fprintf(stderr, "failed to create fence sync object\n");
free(fence);
return ENOMEM;
}
|
CWE-772
| 8,894 | 16,151 |
196742439392277626417643216031745264558
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_renderer_create_sub_ctx(struct vrend_context *ctx, int sub_ctx_id)
{
struct vrend_sub_context *sub;
struct virgl_gl_ctx_param ctx_params;
LIST_FOR_EACH_ENTRY(sub, &ctx->sub_ctxs, head) {
if (sub->sub_ctx_id == sub_ctx_id) {
return;
}
}
sub = CALLOC_STRUCT(vrend_sub_context);
if (!sub)
return;
ctx_params.shared = (ctx->ctx_id == 0 && sub_ctx_id == 0) ? false : true;
ctx_params.major_ver = vrend_state.gl_major_ver;
ctx_params.minor_ver = vrend_state.gl_minor_ver;
sub->gl_context = vrend_clicbs->create_gl_context(0, &ctx_params);
vrend_clicbs->make_current(0, sub->gl_context);
sub->sub_ctx_id = sub_ctx_id;
if (!vrend_state.have_vertex_attrib_binding) {
glGenVertexArrays(1, &sub->vaoid);
glBindVertexArray(sub->vaoid);
}
glGenFramebuffers(1, &sub->fb_id);
glGenFramebuffers(2, sub->blit_fb_ids);
list_inithead(&sub->programs);
list_inithead(&sub->streamout_list);
sub->object_hash = vrend_object_init_ctx_table();
ctx->sub = sub;
list_add(&sub->head, &ctx->sub_ctxs);
if (sub_ctx_id == 0)
ctx->sub0 = sub;
}
|
CWE-772
| 8,895 | 16,152 |
65007740014028958533030573142166962708
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
static struct vrend_resource *vrend_renderer_ctx_res_lookup(struct vrend_context *ctx, int res_handle)
{
struct vrend_resource *res = vrend_object_lookup(ctx->res_hash, res_handle, 1);
return res;
}
|
CWE-772
| 8,896 | 16,153 |
191295117649076589308348472160609273070
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_renderer_destroy_sub_ctx(struct vrend_context *ctx, int sub_ctx_id)
{
struct vrend_sub_context *sub, *tofree = NULL;
/* never destroy sub context id 0 */
if (sub_ctx_id == 0)
return;
LIST_FOR_EACH_ENTRY(sub, &ctx->sub_ctxs, head) {
if (sub->sub_ctx_id == sub_ctx_id) {
tofree = sub;
}
}
if (tofree) {
if (ctx->sub == tofree) {
ctx->sub = ctx->sub0;
vrend_clicbs->make_current(0, ctx->sub->gl_context);
}
vrend_destroy_sub_context(tofree);
}
}
|
CWE-772
| 8,897 | 16,154 |
188995803616276290865313063436911643277
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_renderer_detach_res_ctx(int ctx_id, int res_handle)
{
struct vrend_context *ctx = vrend_lookup_renderer_ctx(ctx_id);
if (!ctx)
return;
vrend_renderer_detach_res_ctx_p(ctx, res_handle);
}
|
CWE-772
| 8,898 | 16,155 |
255219606414535750738900959865733907195
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
static void vrend_renderer_detach_res_ctx_p(struct vrend_context *ctx, int res_handle)
{
struct vrend_resource *res;
res = vrend_object_lookup(ctx->res_hash, res_handle, 1);
if (!res)
return;
vrend_object_remove(ctx->res_hash, res_handle, 1);
}
|
CWE-772
| 8,899 | 16,156 |
282368577410394664315335903999899224679
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_renderer_fill_caps(uint32_t set, uint32_t version,
union virgl_caps *caps)
{
int i;
GLint max;
int gl_ver = epoxy_gl_version();
if (!caps)
return;
memset(caps, 0, sizeof(*caps));
if (set != 1 && set != 0) {
caps->max_version = 0;
return;
}
caps->max_version = 1;
caps->v1.bset.occlusion_query = 1;
if (gl_ver >= 30) {
caps->v1.bset.indep_blend_enable = 1;
caps->v1.bset.conditional_render = 1;
} else {
if (epoxy_has_gl_extension("GL_EXT_draw_buffers2"))
caps->v1.bset.indep_blend_enable = 1;
if (epoxy_has_gl_extension("GL_NV_conditional_render"))
caps->v1.bset.conditional_render = 1;
}
if (vrend_state.use_core_profile) {
caps->v1.bset.poly_stipple = 0;
caps->v1.bset.color_clamping = 0;
} else {
caps->v1.bset.poly_stipple = 1;
caps->v1.bset.color_clamping = 1;
}
if (gl_ver >= 31) {
caps->v1.bset.instanceid = 1;
glGetIntegerv(GL_MAX_VERTEX_UNIFORM_BLOCKS, &max);
vrend_state.max_uniform_blocks = max;
caps->v1.max_uniform_blocks = max + 1;
} else {
if (epoxy_has_gl_extension("GL_ARB_draw_instanced"))
caps->v1.bset.instanceid = 1;
}
if (vrend_state.have_nv_prim_restart || vrend_state.have_gl_prim_restart)
caps->v1.bset.primitive_restart = 1;
if (gl_ver >= 32) {
caps->v1.bset.fragment_coord_conventions = 1;
caps->v1.bset.depth_clip_disable = 1;
caps->v1.bset.seamless_cube_map = 1;
} else {
if (epoxy_has_gl_extension("GL_ARB_fragment_coord_conventions"))
caps->v1.bset.fragment_coord_conventions = 1;
if (epoxy_has_gl_extension("GL_ARB_seamless_cube_map"))
caps->v1.bset.seamless_cube_map = 1;
}
if (epoxy_has_gl_extension("GL_AMD_seamless_cube_map_per_texture"))
caps->v1.bset.seamless_cube_map_per_texture = 1;
if (epoxy_has_gl_extension("GL_ARB_texture_multisample")) {
/* disable multisample until developed */
caps->v1.bset.texture_multisample = 1;
}
if (gl_ver >= 40) {
caps->v1.bset.indep_blend_func = 1;
caps->v1.bset.cube_map_array = 1;
caps->v1.bset.texture_query_lod = 1;
} else {
if (epoxy_has_gl_extension("GL_ARB_draw_buffers_blend"))
caps->v1.bset.indep_blend_func = 1;
if (epoxy_has_gl_extension("GL_ARB_texture_cube_map_array"))
caps->v1.bset.cube_map_array = 1;
if (epoxy_has_gl_extension("GL_ARB_texture_query_lod"))
caps->v1.bset.texture_query_lod = 1;
}
if (gl_ver >= 42) {
caps->v1.bset.start_instance = 1;
} else {
if (epoxy_has_gl_extension("GL_ARB_base_instance"))
caps->v1.bset.start_instance = 1;
}
if (epoxy_has_gl_extension("GL_ARB_shader_stencil_export"))
caps->v1.bset.shader_stencil_export = 1;
/* we only support up to GLSL 1.40 features now */
caps->v1.glsl_level = 130;
if (vrend_state.use_core_profile) {
if (gl_ver == 31)
caps->v1.glsl_level = 140;
else if (gl_ver == 32)
caps->v1.glsl_level = 150;
else if (gl_ver >= 33)
caps->v1.glsl_level = 330;
}
if (epoxy_has_gl_extension("GL_EXT_texture_mirror_clamp"))
caps->v1.bset.mirror_clamp = true;
if (epoxy_has_gl_extension("GL_EXT_texture_array")) {
glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &max);
caps->v1.max_texture_array_layers = max;
}
/* we need tf3 so we can do gallium skip buffers */
if (epoxy_has_gl_extension("GL_ARB_transform_feedback2")) {
caps->v1.bset.streamout_pause_resume = 1;
}
if (epoxy_has_gl_extension("GL_ARB_transform_feedback3")) {
glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max);
caps->v1.max_streamout_buffers = max;
} else if (epoxy_has_gl_extension("GL_EXT_transform_feedback"))
caps->v1.max_streamout_buffers = 4;
if (epoxy_has_gl_extension("GL_ARB_blend_func_extended")) {
glGetIntegerv(GL_MAX_DUAL_SOURCE_DRAW_BUFFERS, &max);
caps->v1.max_dual_source_render_targets = max;
} else
caps->v1.max_dual_source_render_targets = 0;
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &max);
caps->v1.max_render_targets = max;
glGetIntegerv(GL_MAX_SAMPLES, &max);
caps->v1.max_samples = max;
if (epoxy_has_gl_extension("GL_ARB_texture_buffer_object")) {
glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &max);
caps->v1.max_tbo_size = max;
}
if (epoxy_has_gl_extension("GL_ARB_texture_gather")) {
glGetIntegerv(GL_MAX_PROGRAM_TEXTURE_GATHER_COMPONENTS_ARB, &max);
caps->v1.max_texture_gather_components = max;
}
if (epoxy_has_gl_extension("GL_ARB_viewport_array")) {
glGetIntegerv(GL_MAX_VIEWPORTS, &max);
caps->v1.max_viewports = max;
} else
caps->v1.max_viewports = 1;
caps->v1.prim_mask = (1 << PIPE_PRIM_POINTS) | (1 << PIPE_PRIM_LINES) | (1 << PIPE_PRIM_LINE_STRIP) | (1 << PIPE_PRIM_LINE_LOOP) | (1 << PIPE_PRIM_TRIANGLES) | (1 << PIPE_PRIM_TRIANGLE_STRIP) | (1 << PIPE_PRIM_TRIANGLE_FAN);
if (vrend_state.use_core_profile == false) {
caps->v1.prim_mask |= (1 << PIPE_PRIM_QUADS) | (1 << PIPE_PRIM_QUAD_STRIP) | (1 << PIPE_PRIM_POLYGON);
}
if (caps->v1.glsl_level >= 150)
caps->v1.prim_mask |= (1 << PIPE_PRIM_LINES_ADJACENCY) |
(1 << PIPE_PRIM_LINE_STRIP_ADJACENCY) |
(1 << PIPE_PRIM_TRIANGLES_ADJACENCY) |
(1 << PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY);
if (epoxy_has_gl_extension("GL_ARB_vertex_type_10f_11f_11f_rev")) {
int val = VIRGL_FORMAT_R11G11B10_FLOAT;
uint32_t offset = val / 32;
uint32_t index = val % 32;
caps->v1.vertexbuffer.bitmask[offset] |= (1 << index);
}
for (i = 0; i < VIRGL_FORMAT_MAX; i++) {
uint32_t offset = i / 32;
uint32_t index = i % 32;
if (tex_conv_table[i].internalformat != 0) {
if (vrend_format_can_sample(i)) {
caps->v1.sampler.bitmask[offset] |= (1 << index);
if (vrend_format_can_render(i))
caps->v1.render.bitmask[offset] |= (1 << index);
}
}
}
}
|
CWE-772
| 8,900 | 16,157 |
99531650661402477925088976577018469714
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
vrend_renderer_fini(void)
{
if (!vrend_state.inited)
return;
vrend_free_sync_thread();
if (vrend_state.eventfd != -1) {
close(vrend_state.eventfd);
vrend_state.eventfd = -1;
}
vrend_decode_reset(false);
vrend_object_fini_resource_table();
vrend_decode_reset(true);
vrend_state.inited = false;
}
|
CWE-772
| 8,901 | 16,158 |
173592311132449482878351432158253292839
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_renderer_force_ctx_0(void)
{
struct vrend_context *ctx0 = vrend_lookup_renderer_ctx(0);
vrend_state.current_ctx = NULL;
vrend_state.current_hw_ctx = NULL;
vrend_hw_switch_context(ctx0, true);
vrend_clicbs->make_current(0, ctx0->sub->gl_context);
}
|
CWE-772
| 8,902 | 16,159 |
257707483883739083530129142552109609067
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_renderer_get_cap_set(uint32_t cap_set, uint32_t *max_ver,
uint32_t *max_size)
{
if (cap_set != VREND_CAP_SET) {
*max_ver = 0;
*max_size = 0;
return;
}
*max_ver = 1;
*max_size = sizeof(union virgl_caps);
}
|
CWE-772
| 8,903 | 16,160 |
176468650601210925009514277871586267700
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void *vrend_renderer_get_cursor_contents(uint32_t res_handle, uint32_t *width, uint32_t *height)
{
GLenum format, type;
struct vrend_resource *res;
int blsize;
char *data, *data2;
int size;
int h;
res = vrend_resource_lookup(res_handle, 0);
if (!res)
return NULL;
if (res->base.width0 > 128 || res->base.height0 > 128)
return NULL;
if (res->target != GL_TEXTURE_2D)
return NULL;
if (width)
*width = res->base.width0;
if (height)
*height = res->base.height0;
format = tex_conv_table[res->base.format].glformat;
type = tex_conv_table[res->base.format].gltype;
blsize = util_format_get_blocksize(res->base.format);
size = util_format_get_nblocks(res->base.format, res->base.width0, res->base.height0) * blsize;
data = malloc(size);
data2 = malloc(size);
if (!data || !data2) {
free(data);
free(data2);
return NULL;
}
glBindTexture(res->target, res->id);
glGetnTexImageARB(res->target, 0, format, type, size, data);
for (h = 0; h < res->base.height0; h++) {
uint32_t doff = (res->base.height0 - h - 1) * res->base.width0 * blsize;
uint32_t soff = h * res->base.width0 * blsize;
memcpy(data2 + doff, data + soff, res->base.width0 * blsize);
}
free(data);
return data2;
}
|
CWE-772
| 8,904 | 16,161 |
97179869061741053036825799516754424210
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
int vrend_renderer_get_poll_fd(void)
{
if (!vrend_state.inited)
return -1;
return vrend_state.eventfd;
}
|
CWE-772
| 8,905 | 16,162 |
338443353637629835625819209411499846572
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_renderer_get_rect(int res_handle, struct iovec *iov, unsigned int num_iovs,
uint32_t offset, int x, int y, int width, int height)
{
struct vrend_resource *res = vrend_resource_lookup(res_handle, 0);
struct vrend_transfer_info transfer_info;
struct pipe_box box;
int elsize;
memset(&transfer_info, 0, sizeof(transfer_info));
elsize = util_format_get_blocksize(res->base.format);
box.x = x;
box.y = y;
box.z = 0;
box.width = width;
box.height = height;
box.depth = 1;
transfer_info.box = &box;
transfer_info.stride = util_format_get_nblocksx(res->base.format, res->base.width0) * elsize;
transfer_info.offset = offset;
transfer_info.handle = res->handle;
transfer_info.iovec = iov;
transfer_info.iovec_cnt = num_iovs;
vrend_renderer_transfer_iov(&transfer_info, VREND_TRANSFER_READ);
}
|
CWE-772
| 8,906 | 16,163 |
81179403697819350155703032971381234684
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
GLint64 vrend_renderer_get_timestamp(void)
{
GLint64 v;
glGetInteger64v(GL_TIMESTAMP, &v);
return v;
}
|
CWE-772
| 8,907 | 16,164 |
272768473370521976325260076551718413623
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
int vrend_renderer_init(struct vrend_if_cbs *cbs, uint32_t flags)
{
int gl_ver;
virgl_gl_context gl_context;
struct virgl_gl_ctx_param ctx_params;
if (!vrend_state.inited) {
vrend_state.inited = true;
vrend_object_init_resource_table();
vrend_clicbs = cbs;
}
ctx_params.shared = false;
ctx_params.major_ver = VREND_GL_VER_MAJOR;
ctx_params.minor_ver = VREND_GL_VER_MINOR;
gl_context = vrend_clicbs->create_gl_context(0, &ctx_params);
vrend_clicbs->make_current(0, gl_context);
gl_ver = epoxy_gl_version();
vrend_state.gl_major_ver = gl_ver / 10;
vrend_state.gl_minor_ver = gl_ver % 10;
if (gl_ver > 30 && !epoxy_has_gl_extension("GL_ARB_compatibility")) {
fprintf(stderr, "gl_version %d - core profile enabled\n", gl_ver);
vrend_state.use_core_profile = 1;
} else {
fprintf(stderr, "gl_version %d - compat profile\n", gl_ver);
}
if (epoxy_has_gl_extension("GL_ARB_robustness"))
vrend_state.have_robustness = true;
else
fprintf(stderr,"WARNING: running without ARB robustness in place may crash\n");
if (epoxy_has_gl_extension("GL_MESA_pack_invert"))
vrend_state.have_mesa_invert = true;
if (gl_ver >= 43 || epoxy_has_gl_extension("GL_ARB_vertex_attrib_binding"))
vrend_state.have_vertex_attrib_binding = true;
if (gl_ver >= 33 || epoxy_has_gl_extension("GL_ARB_sampler_objects"))
vrend_state.have_samplers = true;
if (gl_ver >= 33 || epoxy_has_gl_extension("GL_ARB_shader_bit_encoding"))
vrend_state.have_bit_encoding = true;
if (gl_ver >= 31)
vrend_state.have_gl_prim_restart = true;
else if (epoxy_has_gl_extension("GL_NV_primitive_restart"))
vrend_state.have_nv_prim_restart = true;
if (gl_ver >= 40 || epoxy_has_gl_extension("GL_ARB_transform_feedback2"))
vrend_state.have_tf2 = true;
if (epoxy_has_gl_extension("GL_EXT_framebuffer_multisample") && epoxy_has_gl_extension("GL_ARB_texture_multisample")) {
vrend_state.have_multisample = true;
if (epoxy_has_gl_extension("GL_EXT_framebuffer_multisample_blit_scaled"))
vrend_state.have_ms_scaled_blit = true;
}
/* callbacks for when we are cleaning up the object table */
vrend_resource_set_destroy_callback(vrend_destroy_resource_object);
vrend_object_set_destroy_callback(VIRGL_OBJECT_QUERY, vrend_destroy_query_object);
vrend_object_set_destroy_callback(VIRGL_OBJECT_SURFACE, vrend_destroy_surface_object);
vrend_object_set_destroy_callback(VIRGL_OBJECT_SHADER, vrend_destroy_shader_object);
vrend_object_set_destroy_callback(VIRGL_OBJECT_SAMPLER_VIEW, vrend_destroy_sampler_view_object);
vrend_object_set_destroy_callback(VIRGL_OBJECT_STREAMOUT_TARGET, vrend_destroy_so_target_object);
vrend_object_set_destroy_callback(VIRGL_OBJECT_SAMPLER_STATE, vrend_destroy_sampler_state_object);
vrend_object_set_destroy_callback(VIRGL_OBJECT_VERTEX_ELEMENTS, vrend_destroy_vertex_elements_object);
vrend_build_format_list();
vrend_clicbs->destroy_gl_context(gl_context);
list_inithead(&vrend_state.fence_list);
list_inithead(&vrend_state.fence_wait_list);
list_inithead(&vrend_state.waiting_query_list);
list_inithead(&vrend_state.active_ctx_list);
/* create 0 context */
vrend_renderer_context_create_internal(0, 0, NULL);
vrend_state.eventfd = -1;
if (flags & VREND_USE_THREAD_SYNC) {
vrend_renderer_use_threaded_sync();
}
return 0;
}
|
CWE-772
| 8,908 | 16,165 |
122182282329448430583012100659384778445
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
vrend_renderer_object_destroy(struct vrend_context *ctx, uint32_t handle)
{
vrend_object_remove(ctx->sub->object_hash, handle, 0);
}
|
CWE-772
| 8,909 | 16,166 |
305590750147032513622512109933100941590
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
uint32_t vrend_renderer_object_insert(struct vrend_context *ctx, void *data,
uint32_t size, uint32_t handle, enum virgl_object_type type)
{
return vrend_object_insert(ctx->sub->object_hash, data, size, handle, type);
}
|
CWE-772
| 8,910 | 16,167 |
88173248568328337488379578951520478108
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_renderer_reset(void)
{
if (vrend_state.sync_thread) {
vrend_free_sync_thread();
vrend_state.stop_sync_thread = false;
}
vrend_reset_fences();
vrend_decode_reset(false);
vrend_object_fini_resource_table();
vrend_decode_reset(true);
vrend_object_init_resource_table();
vrend_renderer_context_create_internal(0, 0, NULL);
}
|
CWE-772
| 8,911 | 16,168 |
7434954354082659911108964914325766402
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
int vrend_renderer_resource_attach_iov(int res_handle, struct iovec *iov,
int num_iovs)
{
struct vrend_resource *res;
res = vrend_resource_lookup(res_handle, 0);
if (!res)
return EINVAL;
if (res->iov)
return 0;
/* work out size and max resource size */
res->iov = iov;
res->num_iovs = num_iovs;
return 0;
}
|
CWE-772
| 8,912 | 16,169 |
184598739807978206684827003078680645920
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_renderer_resource_copy_region(struct vrend_context *ctx,
uint32_t dst_handle, uint32_t dst_level,
uint32_t dstx, uint32_t dsty, uint32_t dstz,
uint32_t src_handle, uint32_t src_level,
const struct pipe_box *src_box)
{
struct vrend_resource *src_res, *dst_res;
GLbitfield glmask = 0;
GLint sy1, sy2, dy1, dy2;
if (ctx->in_error)
return;
src_res = vrend_renderer_ctx_res_lookup(ctx, src_handle);
dst_res = vrend_renderer_ctx_res_lookup(ctx, dst_handle);
if (!src_res) {
report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_RESOURCE, src_handle);
return;
}
if (!dst_res) {
report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_RESOURCE, dst_handle);
return;
}
if (src_res->base.target == PIPE_BUFFER && dst_res->base.target == PIPE_BUFFER) {
/* do a buffer copy */
vrend_resource_buffer_copy(ctx, src_res, dst_res, dstx,
src_box->x, src_box->width);
return;
}
if (!vrend_format_can_render(src_res->base.format) ||
!vrend_format_can_render(dst_res->base.format)) {
vrend_resource_copy_fallback(ctx, src_res, dst_res, dst_level, dstx,
dsty, dstz, src_level, src_box);
return;
}
glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->sub->blit_fb_ids[0]);
/* clean out fb ids */
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT,
GL_TEXTURE_2D, 0, 0);
vrend_fb_bind_texture(src_res, 0, src_level, src_box->z);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->sub->blit_fb_ids[1]);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT,
GL_TEXTURE_2D, 0, 0);
vrend_fb_bind_texture(dst_res, 0, dst_level, dstz);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, ctx->sub->blit_fb_ids[1]);
glBindFramebuffer(GL_READ_FRAMEBUFFER, ctx->sub->blit_fb_ids[0]);
glmask = GL_COLOR_BUFFER_BIT;
glDisable(GL_SCISSOR_TEST);
if (!src_res->y_0_top) {
sy1 = src_box->y;
sy2 = src_box->y + src_box->height;
} else {
sy1 = src_res->base.height0 - src_box->y - src_box->height;
sy2 = src_res->base.height0 - src_box->y;
}
if (!dst_res->y_0_top) {
dy1 = dsty;
dy2 = dsty + src_box->height;
} else {
dy1 = dst_res->base.height0 - dsty - src_box->height;
dy2 = dst_res->base.height0 - dsty;
}
glBlitFramebuffer(src_box->x, sy1,
src_box->x + src_box->width,
sy2,
dstx, dy1,
dstx + src_box->width,
dy2,
glmask, GL_NEAREST);
}
|
CWE-772
| 8,913 | 16,170 |
143081637137860802550471913314230304694
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs)
{
struct vrend_resource *gr;
int level;
int ret;
ret = check_resource_valid(args);
if (ret)
return EINVAL;
gr = (struct vrend_resource *)CALLOC_STRUCT(vrend_texture);
if (!gr)
return ENOMEM;
gr->handle = args->handle;
gr->iov = iov;
gr->num_iovs = num_iovs;
gr->base.width0 = args->width;
gr->base.height0 = args->height;
gr->base.depth0 = args->depth;
gr->base.format = args->format;
gr->base.target = args->target;
gr->base.last_level = args->last_level;
gr->base.nr_samples = args->nr_samples;
gr->base.array_size = args->array_size;
if (args->flags & VIRGL_RESOURCE_Y_0_TOP)
gr->y_0_top = true;
pipe_reference_init(&gr->base.reference, 1);
if (args->bind == VREND_RES_BIND_CUSTOM) {
/* custom should only be for buffers */
gr->ptr = malloc(args->width);
if (!gr->ptr) {
FREE(gr);
return ENOMEM;
}
} else if (args->bind == VREND_RES_BIND_INDEX_BUFFER) {
gr->target = GL_ELEMENT_ARRAY_BUFFER_ARB;
glGenBuffersARB(1, &gr->id);
glBindBufferARB(gr->target, gr->id);
glBufferData(gr->target, args->width, NULL, GL_STREAM_DRAW);
} else if (args->bind == VREND_RES_BIND_STREAM_OUTPUT) {
gr->target = GL_TRANSFORM_FEEDBACK_BUFFER;
glGenBuffersARB(1, &gr->id);
glBindBuffer(gr->target, gr->id);
glBufferData(gr->target, args->width, NULL, GL_STREAM_DRAW);
} else if (args->bind == VREND_RES_BIND_VERTEX_BUFFER) {
gr->target = GL_ARRAY_BUFFER_ARB;
glGenBuffersARB(1, &gr->id);
glBindBufferARB(gr->target, gr->id);
glBufferData(gr->target, args->width, NULL, GL_STREAM_DRAW);
} else if (args->bind == VREND_RES_BIND_CONSTANT_BUFFER) {
gr->target = GL_UNIFORM_BUFFER;
glGenBuffersARB(1, &gr->id);
glBindBufferARB(gr->target, gr->id);
glBufferData(gr->target, args->width, NULL, GL_STREAM_DRAW);
} else if (args->target == PIPE_BUFFER && args->bind == 0) {
gr->target = GL_ARRAY_BUFFER_ARB;
glGenBuffersARB(1, &gr->id);
glBindBufferARB(gr->target, gr->id);
glBufferData(gr->target, args->width, NULL, GL_STREAM_DRAW);
} else if (args->target == PIPE_BUFFER && (args->bind & VREND_RES_BIND_SAMPLER_VIEW)) {
GLenum internalformat;
/* need to check GL version here */
if (epoxy_has_gl_extension("GL_ARB_texture_buffer_object")) {
gr->target = GL_TEXTURE_BUFFER;
glGenBuffersARB(1, &gr->id);
glBindBufferARB(gr->target, gr->id);
glGenTextures(1, &gr->tbo_tex_id);
glBufferData(gr->target, args->width, NULL, GL_STREAM_DRAW);
glBindTexture(gr->target, gr->tbo_tex_id);
internalformat = tex_conv_table[args->format].internalformat;
glTexBuffer(gr->target, internalformat, gr->id);
} else {
gr->target = GL_PIXEL_PACK_BUFFER_ARB;
glGenBuffersARB(1, &gr->id);
glBindBufferARB(gr->target, gr->id);
glBufferData(gr->target, args->width, NULL, GL_STREAM_DRAW);
}
} else {
struct vrend_texture *gt = (struct vrend_texture *)gr;
GLenum internalformat, glformat, gltype;
gr->target = tgsitargettogltarget(args->target, args->nr_samples);
glGenTextures(1, &gr->id);
glBindTexture(gr->target, gr->id);
internalformat = tex_conv_table[args->format].internalformat;
glformat = tex_conv_table[args->format].glformat;
gltype = tex_conv_table[args->format].gltype;
if (internalformat == 0) {
fprintf(stderr,"unknown format is %d\n", args->format);
FREE(gr);
return EINVAL;
}
if (args->nr_samples > 1) {
if (gr->target == GL_TEXTURE_2D_MULTISAMPLE) {
glTexImage2DMultisample(gr->target, args->nr_samples,
internalformat, args->width, args->height,
GL_TRUE);
} else {
glTexImage3DMultisample(gr->target, args->nr_samples,
internalformat, args->width, args->height, args->array_size,
GL_TRUE);
}
} else if (gr->target == GL_TEXTURE_CUBE_MAP) {
int i;
for (i = 0; i < 6; i++) {
GLenum ctarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
for (level = 0; level <= args->last_level; level++) {
unsigned mwidth = u_minify(args->width, level);
unsigned mheight = u_minify(args->height, level);
glTexImage2D(ctarget, level, internalformat, mwidth, mheight, 0, glformat,
gltype, NULL);
}
}
} else if (gr->target == GL_TEXTURE_3D ||
gr->target == GL_TEXTURE_2D_ARRAY ||
gr->target == GL_TEXTURE_CUBE_MAP_ARRAY) {
for (level = 0; level <= args->last_level; level++) {
unsigned depth_param = (gr->target == GL_TEXTURE_2D_ARRAY || gr->target == GL_TEXTURE_CUBE_MAP_ARRAY) ? args->array_size : u_minify(args->depth, level);
unsigned mwidth = u_minify(args->width, level);
unsigned mheight = u_minify(args->height, level);
glTexImage3D(gr->target, level, internalformat, mwidth, mheight, depth_param, 0,
glformat,
gltype, NULL);
}
} else if (gr->target == GL_TEXTURE_1D) {
for (level = 0; level <= args->last_level; level++) {
unsigned mwidth = u_minify(args->width, level);
glTexImage1D(gr->target, level, internalformat, mwidth, 0,
glformat,
gltype, NULL);
}
} else {
for (level = 0; level <= args->last_level; level++) {
unsigned mwidth = u_minify(args->width, level);
unsigned mheight = u_minify(args->height, level);
glTexImage2D(gr->target, level, internalformat, mwidth, gr->target == GL_TEXTURE_1D_ARRAY ? args->array_size : mheight, 0, glformat,
gltype, NULL);
}
}
gt->state.max_lod = -1;
gt->cur_swizzle_r = gt->cur_swizzle_g = gt->cur_swizzle_b = gt->cur_swizzle_a = -1;
}
ret = vrend_resource_insert(gr, args->handle);
if (ret == 0) {
vrend_renderer_resource_destroy(gr, true);
return ENOMEM;
}
return 0;
}
|
CWE-772
| 8,914 | 16,171 |
310440683672518120900330763339473868866
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_renderer_resource_destroy(struct vrend_resource *res, bool remove)
{
if (res->readback_fb_id)
glDeleteFramebuffers(1, &res->readback_fb_id);
if (res->ptr)
free(res->ptr);
if (res->id) {
if (res->target == GL_ELEMENT_ARRAY_BUFFER_ARB ||
res->target == GL_ARRAY_BUFFER_ARB ||
res->target == GL_UNIFORM_BUFFER||
res->target == GL_TEXTURE_BUFFER||
res->target == GL_TRANSFORM_FEEDBACK_BUFFER) {
glDeleteBuffers(1, &res->id);
if (res->target == GL_TEXTURE_BUFFER)
glDeleteTextures(1, &res->tbo_tex_id);
} else
glDeleteTextures(1, &res->id);
}
if (res->handle && remove)
vrend_resource_remove(res->handle);
free(res);
}
|
CWE-772
| 8,915 | 16,172 |
95283584350327088927604967136882947934
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_renderer_resource_detach_iov(int res_handle,
struct iovec **iov_p,
int *num_iovs_p)
{
struct vrend_resource *res;
res = vrend_resource_lookup(res_handle, 0);
if (!res) {
return;
}
if (iov_p)
*iov_p = res->iov;
if (num_iovs_p)
*num_iovs_p = res->num_iovs;
res->iov = NULL;
res->num_iovs = 0;
}
|
CWE-772
| 8,916 | 16,173 |
204515471668978324848873594511108858393
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_renderer_resource_unref(uint32_t res_handle)
{
struct vrend_resource *res;
struct vrend_context *ctx;
res = vrend_resource_lookup(res_handle, 0);
if (!res)
return;
/* find in all contexts and detach also */
/* remove from any contexts */
LIST_FOR_EACH_ENTRY(ctx, &vrend_state.active_ctx_list, ctx_entry) {
vrend_renderer_detach_res_ctx_p(ctx, res->handle);
}
vrend_resource_remove(res->handle);
}
|
CWE-772
| 8,918 | 16,174 |
327643283834888333718950795484199756154
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_renderer_set_sub_ctx(struct vrend_context *ctx, int sub_ctx_id)
{
struct vrend_sub_context *sub;
/* find the sub ctx */
if (ctx->sub && ctx->sub->sub_ctx_id == sub_ctx_id)
return;
LIST_FOR_EACH_ENTRY(sub, &ctx->sub_ctxs, head) {
if (sub->sub_ctx_id == sub_ctx_id) {
ctx->sub = sub;
vrend_clicbs->make_current(0, sub->gl_context);
break;
}
}
}
|
CWE-772
| 8,919 | 16,175 |
256549908463984460453738329557480165702
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
static int vrend_renderer_transfer_send_iov(struct vrend_context *ctx,
struct vrend_resource *res,
struct iovec *iov, int num_iovs,
const struct vrend_transfer_info *info)
{
if (res->target == 0 && res->ptr) {
uint32_t send_size = info->box->width * util_format_get_blocksize(res->base.format);
vrend_write_to_iovec(iov, num_iovs, info->offset, res->ptr + info->box->x, send_size);
return 0;
}
if (res->target == GL_ELEMENT_ARRAY_BUFFER_ARB ||
res->target == GL_ARRAY_BUFFER_ARB ||
res->target == GL_TRANSFORM_FEEDBACK_BUFFER ||
res->target == GL_TEXTURE_BUFFER ||
res->target == GL_UNIFORM_BUFFER) {
uint32_t send_size = info->box->width * util_format_get_blocksize(res->base.format);
void *data;
glBindBufferARB(res->target, res->id);
data = glMapBufferRange(res->target, info->box->x, info->box->width, GL_MAP_READ_BIT);
if (!data)
fprintf(stderr,"unable to open buffer for reading %d\n", res->target);
else
vrend_write_to_iovec(iov, num_iovs, info->offset, data, send_size);
glUnmapBuffer(res->target);
} else {
bool can_readpixels = true;
can_readpixels = vrend_format_can_render(res->base.format) || vrend_format_is_ds(res->base.format);
if (can_readpixels) {
return vrend_transfer_send_readpixels(ctx, res,
iov, num_iovs, info);
}
return vrend_transfer_send_getteximage(ctx, res,
iov, num_iovs, info);
}
return 0;
}
|
CWE-772
| 8,921 | 16,176 |
213920107212556857633839970030866574028
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
static int vrend_renderer_transfer_write_iov(struct vrend_context *ctx,
struct vrend_resource *res,
struct iovec *iov, int num_iovs,
const struct vrend_transfer_info *info)
{
void *data;
if (res->target == 0 && res->ptr) {
vrend_read_from_iovec(iov, num_iovs, info->offset, res->ptr + info->box->x, info->box->width);
return 0;
}
if (res->target == GL_TRANSFORM_FEEDBACK_BUFFER ||
res->target == GL_ELEMENT_ARRAY_BUFFER_ARB ||
res->target == GL_ARRAY_BUFFER_ARB ||
res->target == GL_TEXTURE_BUFFER ||
res->target == GL_UNIFORM_BUFFER) {
struct virgl_sub_upload_data d;
d.box = info->box;
d.target = res->target;
glBindBufferARB(res->target, res->id);
if (use_sub_data == 1) {
vrend_read_from_iovec_cb(iov, num_iovs, info->offset, info->box->width, &iov_buffer_upload, &d);
} else {
data = glMapBufferRange(res->target, info->box->x, info->box->width, GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_WRITE_BIT);
if (data == NULL) {
fprintf(stderr,"map failed for element buffer\n");
vrend_read_from_iovec_cb(iov, num_iovs, info->offset, info->box->width, &iov_buffer_upload, &d);
} else {
vrend_read_from_iovec(iov, num_iovs, info->offset, data, info->box->width);
glUnmapBuffer(res->target);
}
}
} else {
GLenum glformat;
GLenum gltype;
int need_temp = 0;
int elsize = util_format_get_blocksize(res->base.format);
int x = 0, y = 0;
bool compressed;
bool invert = false;
float depth_scale;
GLuint send_size = 0;
uint32_t stride = info->stride;
vrend_use_program(ctx, 0);
if (!stride)
stride = util_format_get_nblocksx(res->base.format, u_minify(res->base.width0, info->level)) * elsize;
compressed = util_format_is_compressed(res->base.format);
if (num_iovs > 1 || compressed) {
need_temp = true;
}
if (vrend_state.use_core_profile == true && (res->y_0_top || (res->base.format == (enum pipe_format)VIRGL_FORMAT_Z24X8_UNORM))) {
need_temp = true;
if (res->y_0_top)
invert = true;
}
if (need_temp) {
send_size = util_format_get_nblocks(res->base.format, info->box->width,
info->box->height) * elsize * info->box->depth;
data = malloc(send_size);
if (!data)
return ENOMEM;
read_transfer_data(&res->base, iov, num_iovs, data, stride,
info->box, info->offset, invert);
} else {
data = (char*)iov[0].iov_base + info->offset;
}
if (stride && !need_temp) {
glPixelStorei(GL_UNPACK_ROW_LENGTH, stride / elsize);
} else
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
switch (elsize) {
case 1:
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
break;
case 2:
case 6:
glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
break;
case 4:
default:
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
break;
case 8:
glPixelStorei(GL_UNPACK_ALIGNMENT, 8);
break;
}
glformat = tex_conv_table[res->base.format].glformat;
gltype = tex_conv_table[res->base.format].gltype;
if ((!vrend_state.use_core_profile) && (res->y_0_top)) {
if (res->readback_fb_id == 0 || res->readback_fb_level != info->level) {
GLuint fb_id;
if (res->readback_fb_id)
glDeleteFramebuffers(1, &res->readback_fb_id);
glGenFramebuffers(1, &fb_id);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb_id);
vrend_fb_bind_texture(res, 0, info->level, 0);
res->readback_fb_id = fb_id;
res->readback_fb_level = info->level;
} else {
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, res->readback_fb_id);
}
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
vrend_blend_enable(ctx, false);
vrend_depth_test_enable(ctx, false);
vrend_alpha_test_enable(ctx, false);
vrend_stencil_test_enable(ctx, false);
glPixelZoom(1.0f, res->y_0_top ? -1.0f : 1.0f);
glWindowPos2i(info->box->x, res->y_0_top ? res->base.height0 - info->box->y : info->box->y);
glDrawPixels(info->box->width, info->box->height, glformat, gltype,
data);
} else {
uint32_t comp_size;
glBindTexture(res->target, res->id);
if (compressed) {
glformat = tex_conv_table[res->base.format].internalformat;
comp_size = util_format_get_nblocks(res->base.format, info->box->width,
info->box->height) * util_format_get_blocksize(res->base.format);
}
if (glformat == 0) {
glformat = GL_BGRA;
gltype = GL_UNSIGNED_BYTE;
}
x = info->box->x;
y = invert ? res->base.height0 - info->box->y - info->box->height : info->box->y;
if (res->base.format == (enum pipe_format)VIRGL_FORMAT_Z24X8_UNORM) {
/* we get values from the guest as 24-bit scaled integers
but we give them to the host GL and it interprets them
as 32-bit scaled integers, so we need to scale them here */
depth_scale = 256.0;
if (!vrend_state.use_core_profile)
glPixelTransferf(GL_DEPTH_SCALE, depth_scale);
else
vrend_scale_depth(data, send_size, depth_scale);
}
if (res->target == GL_TEXTURE_CUBE_MAP) {
GLenum ctarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + info->box->z;
if (compressed) {
glCompressedTexSubImage2D(ctarget, info->level, x, y,
info->box->width, info->box->height,
glformat, comp_size, data);
} else {
glTexSubImage2D(ctarget, info->level, x, y, info->box->width, info->box->height,
glformat, gltype, data);
}
} else if (res->target == GL_TEXTURE_3D || res->target == GL_TEXTURE_2D_ARRAY || res->target == GL_TEXTURE_CUBE_MAP_ARRAY) {
if (compressed) {
glCompressedTexSubImage3D(res->target, info->level, x, y, info->box->z,
info->box->width, info->box->height, info->box->depth,
glformat, comp_size, data);
} else {
glTexSubImage3D(res->target, info->level, x, y, info->box->z,
info->box->width, info->box->height, info->box->depth,
glformat, gltype, data);
}
} else if (res->target == GL_TEXTURE_1D) {
if (compressed) {
glCompressedTexSubImage1D(res->target, info->level, info->box->x,
info->box->width,
glformat, comp_size, data);
} else {
glTexSubImage1D(res->target, info->level, info->box->x, info->box->width,
glformat, gltype, data);
}
} else {
if (compressed) {
glCompressedTexSubImage2D(res->target, info->level, x, res->target == GL_TEXTURE_1D_ARRAY ? info->box->z : y,
info->box->width, info->box->height,
glformat, comp_size, data);
} else {
glTexSubImage2D(res->target, info->level, x, res->target == GL_TEXTURE_1D_ARRAY ? info->box->z : y,
info->box->width, info->box->height,
glformat, gltype, data);
}
}
if (res->base.format == (enum pipe_format)VIRGL_FORMAT_Z24X8_UNORM) {
if (!vrend_state.use_core_profile)
glPixelTransferf(GL_DEPTH_SCALE, 1.0);
}
}
if (stride && !need_temp)
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
if (need_temp)
free(data);
}
return 0;
}
|
CWE-772
| 8,922 | 16,177 |
108529665280130622530722228014242398352
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
static void vrend_renderer_use_threaded_sync(void)
{
struct virgl_gl_ctx_param ctx_params;
if (getenv("VIRGL_DISABLE_MT"))
return;
ctx_params.shared = true;
ctx_params.major_ver = vrend_state.gl_major_ver;
ctx_params.minor_ver = vrend_state.gl_minor_ver;
vrend_state.stop_sync_thread = false;
vrend_state.sync_context = vrend_clicbs->create_gl_context(0, &ctx_params);
if (vrend_state.sync_context == NULL) {
fprintf(stderr, "failed to create sync opengl context\n");
return;
}
vrend_state.eventfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
if (vrend_state.eventfd == -1) {
fprintf(stderr, "Failed to create eventfd\n");
vrend_clicbs->destroy_gl_context(vrend_state.sync_context);
return;
}
pipe_condvar_init(vrend_state.fence_cond);
pipe_mutex_init(vrend_state.fence_mutex);
vrend_state.sync_thread = pipe_thread_create(thread_sync, NULL);
if (!vrend_state.sync_thread) {
close(vrend_state.eventfd);
vrend_state.eventfd = -1;
vrend_clicbs->destroy_gl_context(vrend_state.sync_context);
pipe_condvar_destroy(vrend_state.fence_cond);
pipe_mutex_destroy(vrend_state.fence_mutex);
}
}
|
CWE-772
| 8,923 | 16,178 |
46232961006885468143685823422292877492
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
static void vrend_renderer_use_threaded_sync(void)
{
}
|
CWE-772
| 8,924 | 16,179 |
80639234999454856887303457870546098689
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_report_buffer_error(struct vrend_context *ctx, int cmd)
{
report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_CMD_BUFFER, cmd);
}
|
CWE-772
| 8,925 | 16,180 |
319377214922662353072836034551745496207
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
static void vrend_reset_fences(void)
{
struct vrend_fence *fence, *stor;
if (vrend_state.sync_thread)
pipe_mutex_lock(vrend_state.fence_mutex);
LIST_FOR_EACH_ENTRY_SAFE(fence, stor, &vrend_state.fence_list, fences) {
free_fence_locked(fence);
}
if (vrend_state.sync_thread)
pipe_mutex_unlock(vrend_state.fence_mutex);
}
|
CWE-772
| 8,926 | 16,181 |
131458194250853741122132675705940677601
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
static void vrend_resource_buffer_copy(struct vrend_context *ctx,
struct vrend_resource *src_res,
struct vrend_resource *dst_res,
uint32_t dstx, uint32_t srcx,
uint32_t width)
{
glBindBuffer(GL_COPY_READ_BUFFER, src_res->id);
glBindBuffer(GL_COPY_WRITE_BUFFER, dst_res->id);
glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, srcx, dstx, width);
glBindBuffer(GL_COPY_READ_BUFFER, 0);
glBindBuffer(GL_COPY_WRITE_BUFFER, 0);
}
|
CWE-772
| 8,927 | 16,182 |
106188525658441757172255164141330855163
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
static void vrend_resource_copy_fallback(struct vrend_context *ctx,
struct vrend_resource *src_res,
struct vrend_resource *dst_res,
uint32_t dst_level,
uint32_t dstx, uint32_t dsty,
uint32_t dstz, uint32_t src_level,
const struct pipe_box *src_box)
{
char *tptr;
uint32_t transfer_size;
GLenum glformat, gltype;
int elsize = util_format_get_blocksize(dst_res->base.format);
int compressed = util_format_is_compressed(dst_res->base.format);
int cube_slice = 1;
uint32_t slice_size, slice_offset;
int i;
if (src_res->target == GL_TEXTURE_CUBE_MAP)
cube_slice = 6;
if (src_res->base.format != dst_res->base.format) {
fprintf(stderr, "copy fallback failed due to mismatched formats %d %d\n", src_res->base.format, dst_res->base.format);
return;
}
/* this is ugly need to do a full GetTexImage */
slice_size = util_format_get_nblocks(src_res->base.format, u_minify(src_res->base.width0, src_level), u_minify(src_res->base.height0, src_level)) *
u_minify(src_res->base.depth0, src_level) * util_format_get_blocksize(src_res->base.format);
transfer_size = slice_size * src_res->base.array_size;
tptr = malloc(transfer_size);
if (!tptr)
return;
glformat = tex_conv_table[src_res->base.format].glformat;
gltype = tex_conv_table[src_res->base.format].gltype;
if (compressed)
glformat = tex_conv_table[src_res->base.format].internalformat;
switch (elsize) {
case 1:
glPixelStorei(GL_PACK_ALIGNMENT, 1);
break;
case 2:
glPixelStorei(GL_PACK_ALIGNMENT, 2);
break;
case 4:
default:
glPixelStorei(GL_PACK_ALIGNMENT, 4);
break;
case 8:
glPixelStorei(GL_PACK_ALIGNMENT, 8);
break;
}
glBindTexture(src_res->target, src_res->id);
slice_offset = 0;
for (i = 0; i < cube_slice; i++) {
GLenum ctarget = src_res->target == GL_TEXTURE_CUBE_MAP ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + i : src_res->target;
if (compressed) {
if (vrend_state.have_robustness)
glGetnCompressedTexImageARB(ctarget, src_level, transfer_size, tptr + slice_offset);
else
glGetCompressedTexImage(ctarget, src_level, tptr + slice_offset);
} else {
if (vrend_state.have_robustness)
glGetnTexImageARB(ctarget, src_level, glformat, gltype, transfer_size, tptr + slice_offset);
else
glGetTexImage(ctarget, src_level, glformat, gltype, tptr + slice_offset);
}
slice_offset += slice_size;
}
glPixelStorei(GL_PACK_ALIGNMENT, 4);
switch (elsize) {
case 1:
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
break;
case 2:
glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
break;
case 4:
default:
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
break;
case 8:
glPixelStorei(GL_UNPACK_ALIGNMENT, 8);
break;
}
glBindTexture(dst_res->target, dst_res->id);
slice_offset = 0;
for (i = 0; i < cube_slice; i++) {
GLenum ctarget = dst_res->target == GL_TEXTURE_CUBE_MAP ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + i : dst_res->target;
if (compressed) {
if (ctarget == GL_TEXTURE_1D) {
glCompressedTexSubImage1D(ctarget, dst_level, dstx,
src_box->width,
glformat, transfer_size, tptr + slice_offset);
} else {
glCompressedTexSubImage2D(ctarget, dst_level, dstx, dsty,
src_box->width, src_box->height,
glformat, transfer_size, tptr + slice_offset);
}
} else {
if (ctarget == GL_TEXTURE_1D) {
glTexSubImage1D(ctarget, dst_level, dstx, src_box->width, glformat, gltype, tptr + slice_offset);
} else if (ctarget == GL_TEXTURE_3D ||
ctarget == GL_TEXTURE_2D_ARRAY ||
ctarget == GL_TEXTURE_CUBE_MAP_ARRAY) {
glTexSubImage3D(ctarget, dst_level, dstx, dsty, 0,src_box->width, src_box->height, src_box->depth, glformat, gltype, tptr + slice_offset);
} else {
glTexSubImage2D(ctarget, dst_level, dstx, dsty, src_box->width, src_box->height, glformat, gltype, tptr + slice_offset);
}
}
slice_offset += slice_size;
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
free(tptr);
}
|
CWE-772
| 8,928 | 16,183 |
125178718706626629690593244837147036819
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
vrend_sampler_view_reference(struct vrend_sampler_view **ptr, struct vrend_sampler_view *view)
{
struct vrend_sampler_view *old_view = *ptr;
if (pipe_reference(&(*ptr)->reference, &view->reference))
vrend_destroy_sampler_view(old_view);
*ptr = view;
}
|
CWE-772
| 8,929 | 16,184 |
218818890876491541153008029563364403272
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
static void vrend_scale_depth(void *ptr, int size, float scale_val)
{
GLuint *ival = ptr;
const GLfloat myscale = 1.0f / 0xffffff;
int i;
for (i = 0; i < size / 4; i++) {
GLuint value = ival[i];
GLfloat d = ((float)(value >> 8) * myscale) * scale_val;
d = CLAMP(d, 0.0F, 1.0F);
ival[i] = (int)(d / myscale) << 8;
}
}
|
CWE-772
| 8,930 | 16,185 |
200584424546728613477559400691110017357
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_set_blend_color(struct vrend_context *ctx,
struct pipe_blend_color *color)
{
ctx->sub->blend_color = *color;
glBlendColor(color->color[0], color->color[1], color->color[2],
color->color[3]);
}
|
CWE-772
| 8,931 | 16,186 |
184919234598292823550124811114704220437
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_set_clip_state(struct vrend_context *ctx, struct pipe_clip_state *ucp)
{
if (vrend_state.use_core_profile) {
ctx->sub->ucp_state = *ucp;
} else {
int i, j;
GLdouble val[4];
for (i = 0; i < 8; i++) {
for (j = 0; j < 4; j++)
val[j] = ucp->ucp[i][j];
glClipPlane(GL_CLIP_PLANE0 + i, val);
}
}
}
|
CWE-772
| 8,932 | 16,187 |
138914496878891511257657963066692112726
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_set_constants(struct vrend_context *ctx,
uint32_t shader,
uint32_t index,
uint32_t num_constant,
float *data)
{
struct vrend_constants *consts;
int i;
consts = &ctx->sub->consts[shader];
ctx->sub->const_dirty[shader] = true;
consts->consts = realloc(consts->consts, num_constant * sizeof(float));
if (!consts->consts)
return;
consts->num_consts = num_constant;
for (i = 0; i < num_constant; i++)
consts->consts[i] = ((unsigned int *)data)[i];
}
|
CWE-772
| 8,933 | 16,188 |
142251723118231173357462491092986393393
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_set_framebuffer_state(struct vrend_context *ctx,
uint32_t nr_cbufs, uint32_t surf_handle[PIPE_MAX_COLOR_BUFS],
uint32_t zsurf_handle)
{
struct vrend_surface *surf, *zsurf;
int i;
int old_num;
GLenum status;
GLint new_height = -1;
bool new_ibf = false;
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ctx->sub->fb_id);
if (zsurf_handle) {
zsurf = vrend_object_lookup(ctx->sub->object_hash, zsurf_handle, VIRGL_OBJECT_SURFACE);
if (!zsurf) {
report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_SURFACE, zsurf_handle);
return;
}
} else
zsurf = NULL;
if (ctx->sub->zsurf != zsurf) {
vrend_surface_reference(&ctx->sub->zsurf, zsurf);
vrend_hw_set_zsurf_texture(ctx);
}
old_num = ctx->sub->nr_cbufs;
ctx->sub->nr_cbufs = nr_cbufs;
ctx->sub->old_nr_cbufs = old_num;
for (i = 0; i < nr_cbufs; i++) {
if (surf_handle[i] != 0) {
surf = vrend_object_lookup(ctx->sub->object_hash, surf_handle[i], VIRGL_OBJECT_SURFACE);
if (!surf) {
report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_SURFACE, surf_handle[i]);
return;
}
} else
surf = NULL;
if (ctx->sub->surf[i] != surf) {
vrend_surface_reference(&ctx->sub->surf[i], surf);
vrend_hw_set_color_surface(ctx, i);
}
}
if (old_num > ctx->sub->nr_cbufs) {
for (i = ctx->sub->nr_cbufs; i < old_num; i++) {
vrend_surface_reference(&ctx->sub->surf[i], NULL);
vrend_hw_set_color_surface(ctx, i);
}
}
/* find a buffer to set fb_height from */
if (ctx->sub->nr_cbufs == 0 && !ctx->sub->zsurf) {
new_height = 0;
new_ibf = false;
} else if (ctx->sub->nr_cbufs == 0) {
new_height = u_minify(ctx->sub->zsurf->texture->base.height0, ctx->sub->zsurf->val0);
new_ibf = ctx->sub->zsurf->texture->y_0_top ? true : false;
}
else {
surf = NULL;
for (i = 0; i < ctx->sub->nr_cbufs; i++) {
if (ctx->sub->surf[i]) {
surf = ctx->sub->surf[i];
break;
}
}
if (surf == NULL) {
report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_SURFACE, i);
return;
}
new_height = u_minify(surf->texture->base.height0, surf->val0);
new_ibf = surf->texture->y_0_top ? true : false;
}
if (new_height != -1) {
if (ctx->sub->fb_height != new_height || ctx->sub->inverted_fbo_content != new_ibf) {
ctx->sub->fb_height = new_height;
ctx->sub->inverted_fbo_content = new_ibf;
ctx->sub->scissor_state_dirty = (1 << 0);
ctx->sub->viewport_state_dirty = (1 << 0);
}
}
vrend_hw_emit_framebuffer_state(ctx);
if (ctx->sub->nr_cbufs > 0 || ctx->sub->zsurf) {
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE)
fprintf(stderr,"failed to complete framebuffer 0x%x %s\n", status, ctx->debug_name);
}
ctx->sub->shader_dirty = true;
}
|
CWE-772
| 8,934 | 16,189 |
116178415820268431171263693472710588774
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_set_index_buffer(struct vrend_context *ctx,
uint32_t res_handle,
uint32_t index_size,
uint32_t offset)
{
struct vrend_resource *res;
ctx->sub->ib.index_size = index_size;
ctx->sub->ib.offset = offset;
if (res_handle) {
if (ctx->sub->index_buffer_res_id != res_handle) {
res = vrend_renderer_ctx_res_lookup(ctx, res_handle);
if (!res) {
vrend_resource_reference((struct vrend_resource **)&ctx->sub->ib.buffer, NULL);
ctx->sub->index_buffer_res_id = 0;
report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_RESOURCE, res_handle);
return;
}
vrend_resource_reference((struct vrend_resource **)&ctx->sub->ib.buffer, res);
ctx->sub->index_buffer_res_id = res_handle;
}
} else {
vrend_resource_reference((struct vrend_resource **)&ctx->sub->ib.buffer, NULL);
ctx->sub->index_buffer_res_id = 0;
}
}
|
CWE-772
| 8,935 | 16,190 |
196246954026724126194371606826505139261
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_set_num_sampler_views(struct vrend_context *ctx,
uint32_t shader_type,
uint32_t start_slot,
int num_sampler_views)
{
if (start_slot + num_sampler_views < ctx->sub->views[shader_type].num_views) {
int i;
for (i = start_slot + num_sampler_views; i < ctx->sub->views[shader_type].num_views; i++)
vrend_sampler_view_reference(&ctx->sub->views[shader_type].views[i], NULL);
}
ctx->sub->views[shader_type].num_views = start_slot + num_sampler_views;
}
|
CWE-772
| 8,936 | 16,191 |
122360346639651182107962510075341579300
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_set_num_vbo(struct vrend_context *ctx,
int num_vbo)
{
int old_num = ctx->sub->num_vbos;
int i;
ctx->sub->num_vbos = num_vbo;
ctx->sub->old_num_vbos = old_num;
if (old_num != num_vbo)
ctx->sub->vbo_dirty = true;
for (i = num_vbo; i < old_num; i++) {
vrend_resource_reference((struct vrend_resource **)&ctx->sub->vbo[i].buffer, NULL);
ctx->sub->vbo_res_ids[i] = 0;
}
}
|
CWE-772
| 8,937 | 16,192 |
193175970998319948272795422521618054585
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_set_polygon_stipple(struct vrend_context *ctx,
struct pipe_poly_stipple *ps)
{
if (vrend_state.use_core_profile) {
static const unsigned bit31 = 1 << 31;
GLubyte *stip = calloc(1, 1024);
int i, j;
if (!ctx->pstip_inited)
vrend_init_pstipple_texture(ctx);
if (!stip)
return;
for (i = 0; i < 32; i++) {
for (j = 0; j < 32; j++) {
if (ps->stipple[i] & (bit31 >> j))
stip[i * 32 + j] = 0;
else
stip[i * 32 + j] = 255;
}
}
glBindTexture(GL_TEXTURE_2D, ctx->pstipple_tex_id);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 32, 32,
GL_RED, GL_UNSIGNED_BYTE, stip);
free(stip);
return;
}
glPolygonStipple((const GLubyte *)ps->stipple);
}
|
CWE-772
| 8,938 | 16,193 |
15926015979332342042614069531587466295
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_set_sample_mask(struct vrend_context *ctx, unsigned sample_mask)
{
glSampleMaski(0, sample_mask);
}
|
CWE-772
| 8,939 | 16,194 |
183897519816553644247480034815884767529
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_set_scissor_state(struct vrend_context *ctx,
uint32_t start_slot,
uint32_t num_scissor,
struct pipe_scissor_state *ss)
{
int i, idx;
if (start_slot > PIPE_MAX_VIEWPORTS ||
num_scissor > (PIPE_MAX_VIEWPORTS - start_slot)) {
vrend_report_buffer_error(ctx, 0);
return;
}
for (i = 0; i < num_scissor; i++) {
idx = start_slot + i;
ctx->sub->ss[idx] = ss[i];
ctx->sub->scissor_state_dirty |= (1 << idx);
}
}
|
CWE-772
| 8,940 | 16,195 |
72182741543292235055984537326088131857
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_set_single_sampler_view(struct vrend_context *ctx,
uint32_t shader_type,
int index,
uint32_t handle)
{
struct vrend_sampler_view *view = NULL;
struct vrend_texture *tex;
if (handle) {
view = vrend_object_lookup(ctx->sub->object_hash, handle, VIRGL_OBJECT_SAMPLER_VIEW);
if (!view) {
ctx->sub->views[shader_type].views[index] = NULL;
report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_HANDLE, handle);
return;
}
if (ctx->sub->views[shader_type].views[index] == view) {
return;
}
/* we should have a reference to this texture taken at create time */
tex = (struct vrend_texture *)view->texture;
if (!tex) {
return;
}
if (view->texture->target != GL_TEXTURE_BUFFER) {
glBindTexture(view->texture->target, view->texture->id);
if (util_format_is_depth_or_stencil(view->format)) {
if (vrend_state.use_core_profile == false) {
/* setting depth texture mode is deprecated in core profile */
if (view->depth_texture_mode != GL_RED) {
glTexParameteri(view->texture->target, GL_DEPTH_TEXTURE_MODE, GL_RED);
view->depth_texture_mode = GL_RED;
}
}
}
if (view->cur_base != (view->val1 & 0xff)) {
view->cur_base = view->val1 & 0xff;
glTexParameteri(view->texture->target, GL_TEXTURE_BASE_LEVEL, view->cur_base);
}
if (view->cur_max != ((view->val1 >> 8) & 0xff)) {
view->cur_max = (view->val1 >> 8) & 0xff;
glTexParameteri(view->texture->target, GL_TEXTURE_MAX_LEVEL, view->cur_max);
}
if (tex->cur_swizzle_r != view->gl_swizzle_r) {
glTexParameteri(view->texture->target, GL_TEXTURE_SWIZZLE_R, view->gl_swizzle_r);
tex->cur_swizzle_r = view->gl_swizzle_r;
}
if (tex->cur_swizzle_g != view->gl_swizzle_g) {
glTexParameteri(view->texture->target, GL_TEXTURE_SWIZZLE_G, view->gl_swizzle_g);
tex->cur_swizzle_g = view->gl_swizzle_g;
}
if (tex->cur_swizzle_b != view->gl_swizzle_b) {
glTexParameteri(view->texture->target, GL_TEXTURE_SWIZZLE_B, view->gl_swizzle_b);
tex->cur_swizzle_b = view->gl_swizzle_b;
}
if (tex->cur_swizzle_a != view->gl_swizzle_a) {
glTexParameteri(view->texture->target, GL_TEXTURE_SWIZZLE_A, view->gl_swizzle_a);
tex->cur_swizzle_a = view->gl_swizzle_a;
}
if (tex->srgb_decode != view->srgb_decode && util_format_is_srgb(tex->base.base.format)) {
if (vrend_state.have_samplers)
ctx->sub->sampler_state_dirty = true;
else {
glTexParameteri(view->texture->target, GL_TEXTURE_SRGB_DECODE_EXT,
view->srgb_decode);
tex->srgb_decode = view->srgb_decode;
}
}
} else {
GLenum internalformat;
glBindTexture(GL_TEXTURE_BUFFER, view->texture->tbo_tex_id);
internalformat = tex_conv_table[view->format].internalformat;
glTexBuffer(GL_TEXTURE_BUFFER, internalformat, view->texture->id);
}
}
vrend_sampler_view_reference(&ctx->sub->views[shader_type].views[index], view);
}
|
CWE-772
| 8,941 | 16,196 |
69774322620589822247784378100643929533
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_set_single_vbo(struct vrend_context *ctx,
int index,
uint32_t stride,
uint32_t buffer_offset,
uint32_t res_handle)
{
struct vrend_resource *res;
if (ctx->sub->vbo[index].stride != stride ||
ctx->sub->vbo[index].buffer_offset != buffer_offset ||
ctx->sub->vbo_res_ids[index] != res_handle)
ctx->sub->vbo_dirty = true;
ctx->sub->vbo[index].stride = stride;
ctx->sub->vbo[index].buffer_offset = buffer_offset;
if (res_handle == 0) {
vrend_resource_reference((struct vrend_resource **)&ctx->sub->vbo[index].buffer, NULL);
ctx->sub->vbo_res_ids[index] = 0;
} else if (ctx->sub->vbo_res_ids[index] != res_handle) {
res = vrend_renderer_ctx_res_lookup(ctx, res_handle);
if (!res) {
report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_RESOURCE, res_handle);
ctx->sub->vbo_res_ids[index] = 0;
return;
}
vrend_resource_reference((struct vrend_resource **)&ctx->sub->vbo[index].buffer, res);
ctx->sub->vbo_res_ids[index] = res_handle;
}
}
|
CWE-772
| 8,942 | 16,197 |
62508674063491705241098253104376531910
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_set_stencil_ref(struct vrend_context *ctx,
struct pipe_stencil_ref *ref)
{
if (ctx->sub->stencil_refs[0] != ref->ref_value[0] ||
ctx->sub->stencil_refs[1] != ref->ref_value[1]) {
ctx->sub->stencil_refs[0] = ref->ref_value[0];
ctx->sub->stencil_refs[1] = ref->ref_value[1];
ctx->sub->stencil_state_dirty = true;
}
}
|
CWE-772
| 8,943 | 16,198 |
172426444017596229777755120315212434268
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_set_streamout_targets(struct vrend_context *ctx,
uint32_t append_bitmask,
uint32_t num_targets,
uint32_t *handles)
{
struct vrend_so_target *target;
int i;
if (num_targets) {
bool found = false;
struct vrend_streamout_object *obj;
LIST_FOR_EACH_ENTRY(obj, &ctx->sub->streamout_list, head) {
if (obj->num_targets == num_targets) {
if (!memcmp(handles, obj->handles, num_targets * 4)) {
found = true;
break;
}
}
}
if (found) {
ctx->sub->current_so = obj;
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, obj->id);
return;
}
obj = CALLOC_STRUCT(vrend_streamout_object);
if (vrend_state.have_tf2) {
glGenTransformFeedbacks(1, &obj->id);
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, obj->id);
}
obj->num_targets = num_targets;
for (i = 0; i < num_targets; i++) {
obj->handles[i] = handles[i];
target = vrend_object_lookup(ctx->sub->object_hash, handles[i], VIRGL_OBJECT_STREAMOUT_TARGET);
if (!target) {
report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_HANDLE, handles[i]);
free(obj);
return;
}
vrend_so_target_reference(&obj->so_targets[i], target);
}
vrend_hw_emit_streamout_targets(ctx, obj);
list_addtail(&obj->head, &ctx->sub->streamout_list);
ctx->sub->current_so = obj;
obj->xfb_state = XFB_STATE_STARTED_NEED_BEGIN;
} else {
if (vrend_state.have_tf2)
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
ctx->sub->current_so = NULL;
}
}
|
CWE-772
| 8,944 | 16,199 |
97202188249457428063141472949644351214
| null | null | null |
virglrenderer
|
737c3350850ca4dbc5633b3bdb4118176ce59920
| 0 |
void vrend_set_uniform_buffer(struct vrend_context *ctx,
uint32_t shader,
uint32_t index,
uint32_t offset,
uint32_t length,
uint32_t res_handle)
{
struct vrend_resource *res;
if (res_handle) {
res = vrend_renderer_ctx_res_lookup(ctx, res_handle);
if (!res) {
report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_RESOURCE, res_handle);
return;
}
vrend_resource_reference((struct vrend_resource **)&ctx->sub->cbs[shader][index].buffer, res);
ctx->sub->cbs[shader][index].buffer_offset = offset;
ctx->sub->cbs[shader][index].buffer_size = length;
ctx->sub->const_bufs_used_mask[shader] |= (1 << index);
} else {
vrend_resource_reference((struct vrend_resource **)&ctx->sub->cbs[shader][index].buffer, NULL);
ctx->sub->cbs[shader][index].buffer_offset = 0;
ctx->sub->cbs[shader][index].buffer_size = 0;
ctx->sub->const_bufs_used_mask[shader] &= ~(1 << index);
}
}
|
CWE-772
| 8,945 | 16,200 |
310506596659820087432209503731305812325
| null | null | null |
virglrenderer
|
a2f12a1b0f95b13b6f8dc3d05d7b74b4386394e4
| 0 |
int vrend_create_shader(struct vrend_context *ctx,
uint32_t handle,
const struct pipe_stream_output_info *so_info,
const char *shd_text, uint32_t offlen, uint32_t num_tokens,
uint32_t type, uint32_t pkt_length)
{
struct vrend_shader_selector *sel = NULL;
int ret_handle;
bool new_shader = true, long_shader = false;
bool finished = false;
int ret;
if (type > PIPE_SHADER_GEOMETRY)
return EINVAL;
if (offlen & VIRGL_OBJ_SHADER_OFFSET_CONT)
new_shader = false;
else if (((offlen + 3) / 4) > pkt_length)
long_shader = true;
/* if we have an in progress one - don't allow a new shader
of that type or a different handle. */
if (ctx->sub->long_shader_in_progress_handle[type]) {
if (new_shader == true)
return EINVAL;
if (handle != ctx->sub->long_shader_in_progress_handle[type])
return EINVAL;
}
if (new_shader) {
sel = vrend_create_shader_state(ctx, so_info, type);
if (sel == NULL)
return ENOMEM;
if (long_shader) {
sel->buf_len = ((offlen + 3) / 4) * 4; /* round up buffer size */
sel->tmp_buf = malloc(sel->buf_len);
if (!sel->tmp_buf) {
ret = ENOMEM;
goto error;
}
memcpy(sel->tmp_buf, shd_text, pkt_length * 4);
sel->buf_offset = pkt_length * 4;
ctx->sub->long_shader_in_progress_handle[type] = handle;
} else
finished = true;
} else {
sel = vrend_object_lookup(ctx->sub->object_hash, handle, VIRGL_OBJECT_SHADER);
if (!sel) {
fprintf(stderr, "got continuation without original shader %d\n", handle);
ret = EINVAL;
goto error;
}
offlen &= ~VIRGL_OBJ_SHADER_OFFSET_CONT;
if (offlen != sel->buf_offset) {
fprintf(stderr, "Got mismatched shader continuation %d vs %d\n",
offlen, sel->buf_offset);
ret = EINVAL;
goto error;
}
if ((pkt_length * 4 + sel->buf_offset) > sel->buf_len) {
fprintf(stderr, "Got too large shader continuation %d vs %d\n",
pkt_length * 4 + sel->buf_offset, sel->buf_len);
ret = EINVAL;
goto error;
}
memcpy(sel->tmp_buf + sel->buf_offset, shd_text, pkt_length * 4);
sel->buf_offset += pkt_length * 4;
if (sel->buf_offset >= sel->buf_len) {
finished = true;
shd_text = sel->tmp_buf;
}
}
if (finished) {
struct tgsi_token *tokens;
tokens = calloc(num_tokens + 10, sizeof(struct tgsi_token));
if (!tokens) {
ret = ENOMEM;
goto error;
}
if (vrend_dump_shaders)
fprintf(stderr,"shader\n%s\n", shd_text);
if (!tgsi_text_translate((const char *)shd_text, tokens, num_tokens + 10)) {
free(tokens);
ret = EINVAL;
goto error;
}
if (vrend_finish_shader(ctx, sel, tokens)) {
free(tokens);
ret = EINVAL;
goto error;
} else {
free(sel->tmp_buf);
sel->tmp_buf = NULL;
}
free(tokens);
ctx->sub->long_shader_in_progress_handle[type] = 0;
}
if (new_shader) {
ret_handle = vrend_renderer_object_insert(ctx, sel, sizeof(*sel), handle, VIRGL_OBJECT_SHADER);
if (ret_handle == 0) {
ret = ENOMEM;
goto error;
}
}
return 0;
error:
if (new_shader)
vrend_destroy_shader_selector(sel);
else
vrend_renderer_object_destroy(ctx, handle);
return ret;
}
|
CWE-772
| 8,950 | 16,201 |
90675852073179821105504104528700802716
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static inline uint32_t get_buf_entry(struct vrend_decode_ctx *ctx, uint32_t offset)
{
return ctx->ds->buf[ctx->ds->buf_offset + offset];
}
|
CWE-476
| 9,083 | 16,202 |
32419485451690320224735256322778776061
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static inline void *get_buf_ptr(struct vrend_decode_ctx *ctx,
uint32_t offset)
{
return &ctx->ds->buf[ctx->ds->buf_offset + offset];
}
|
CWE-476
| 9,084 | 16,203 |
263756263122968169422105274059913893368
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static float uif(unsigned int ui)
{
union { float f; unsigned int ui; } myuif;
myuif.ui = ui;
return myuif.f;
}
|
CWE-476
| 9,085 | 16,204 |
213972007199642215160004107201357739831
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_begin_query(struct vrend_decode_ctx *ctx, int length)
{
if (length != 1)
return EINVAL;
uint32_t handle = get_buf_entry(ctx, VIRGL_QUERY_BEGIN_HANDLE);
vrend_begin_query(ctx->grctx, handle);
return 0;
}
|
CWE-476
| 9,086 | 16,205 |
261162820332326999522794481447346502705
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_bind_object(struct vrend_decode_ctx *ctx, uint16_t length)
{
if (length != 1)
return EINVAL;
uint32_t header = get_buf_entry(ctx, VIRGL_OBJ_BIND_HEADER);
uint32_t handle = get_buf_entry(ctx, VIRGL_OBJ_BIND_HANDLE);
uint8_t obj_type = (header >> 8) & 0xff;
switch (obj_type) {
case VIRGL_OBJECT_BLEND:
vrend_object_bind_blend(ctx->grctx, handle);
break;
case VIRGL_OBJECT_DSA:
vrend_object_bind_dsa(ctx->grctx, handle);
break;
case VIRGL_OBJECT_RASTERIZER:
vrend_object_bind_rasterizer(ctx->grctx, handle);
break;
case VIRGL_OBJECT_VERTEX_ELEMENTS:
vrend_bind_vertex_elements_state(ctx->grctx, handle);
break;
default:
return EINVAL;
}
return 0;
}
|
CWE-476
| 9,087 | 16,206 |
45934015913914518294776262081758588498
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_bind_sampler_states(struct vrend_decode_ctx *ctx, int length)
{
if (length < 2)
return EINVAL;
uint32_t shader_type = get_buf_entry(ctx, VIRGL_BIND_SAMPLER_STATES_SHADER_TYPE);
uint32_t start_slot = get_buf_entry(ctx, VIRGL_BIND_SAMPLER_STATES_START_SLOT);
uint32_t num_states = length - 2;
if (shader_type >= PIPE_SHADER_TYPES)
return EINVAL;
vrend_bind_sampler_states(ctx->grctx, shader_type, start_slot, num_states,
get_buf_ptr(ctx, VIRGL_BIND_SAMPLER_STATES_S0_HANDLE));
return 0;
}
|
CWE-476
| 9,088 | 16,207 |
334068791851453595740091891435274011602
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_bind_shader(struct vrend_decode_ctx *ctx, int length)
{
uint32_t handle, type;
if (length != VIRGL_BIND_SHADER_SIZE)
return EINVAL;
handle = get_buf_entry(ctx, VIRGL_BIND_SHADER_HANDLE);
type = get_buf_entry(ctx, VIRGL_BIND_SHADER_TYPE);
vrend_bind_shader(ctx->grctx, handle, type);
return 0;
}
|
CWE-476
| 9,089 | 16,208 |
262296693155790481109296105183219775113
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_blit(struct vrend_decode_ctx *ctx, int length)
{
struct pipe_blit_info info;
uint32_t dst_handle, src_handle, temp;
if (length != VIRGL_CMD_BLIT_SIZE)
return EINVAL;
temp = get_buf_entry(ctx, VIRGL_CMD_BLIT_S0);
info.mask = temp & 0xff;
info.filter = (temp >> 8) & 0x3;
info.scissor_enable = (temp >> 10) & 0x1;
info.render_condition_enable = (temp >> 11) & 0x1;
info.alpha_blend = (temp >> 12) & 0x1;
temp = get_buf_entry(ctx, VIRGL_CMD_BLIT_SCISSOR_MINX_MINY);
info.scissor.minx = temp & 0xffff;
info.scissor.miny = (temp >> 16) & 0xffff;
temp = get_buf_entry(ctx, VIRGL_CMD_BLIT_SCISSOR_MAXX_MAXY);
info.scissor.maxx = temp & 0xffff;
info.scissor.maxy = (temp >> 16) & 0xffff;
dst_handle = get_buf_entry(ctx, VIRGL_CMD_BLIT_DST_RES_HANDLE);
info.dst.level = get_buf_entry(ctx, VIRGL_CMD_BLIT_DST_LEVEL);
info.dst.format = get_buf_entry(ctx, VIRGL_CMD_BLIT_DST_FORMAT);
info.dst.box.x = get_buf_entry(ctx, VIRGL_CMD_BLIT_DST_X);
info.dst.box.y = get_buf_entry(ctx, VIRGL_CMD_BLIT_DST_Y);
info.dst.box.z = get_buf_entry(ctx, VIRGL_CMD_BLIT_DST_Z);
info.dst.box.width = get_buf_entry(ctx, VIRGL_CMD_BLIT_DST_W);
info.dst.box.height = get_buf_entry(ctx, VIRGL_CMD_BLIT_DST_H);
info.dst.box.depth = get_buf_entry(ctx, VIRGL_CMD_BLIT_DST_D);
src_handle = get_buf_entry(ctx, VIRGL_CMD_BLIT_SRC_RES_HANDLE);
info.src.level = get_buf_entry(ctx, VIRGL_CMD_BLIT_SRC_LEVEL);
info.src.format = get_buf_entry(ctx, VIRGL_CMD_BLIT_SRC_FORMAT);
info.src.box.x = get_buf_entry(ctx, VIRGL_CMD_BLIT_SRC_X);
info.src.box.y = get_buf_entry(ctx, VIRGL_CMD_BLIT_SRC_Y);
info.src.box.z = get_buf_entry(ctx, VIRGL_CMD_BLIT_SRC_Z);
info.src.box.width = get_buf_entry(ctx, VIRGL_CMD_BLIT_SRC_W);
info.src.box.height = get_buf_entry(ctx, VIRGL_CMD_BLIT_SRC_H);
info.src.box.depth = get_buf_entry(ctx, VIRGL_CMD_BLIT_SRC_D);
vrend_renderer_blit(ctx->grctx, dst_handle, src_handle, &info);
return 0;
}
|
CWE-476
| 9,090 | 16,209 |
206135415445995394146139907155247576494
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
int vrend_decode_block(uint32_t ctx_id, uint32_t *block, int ndw)
{
struct vrend_decode_ctx *gdctx;
bool bret;
int ret;
if (ctx_id >= VREND_MAX_CTX)
return EINVAL;
if (dec_ctx[ctx_id] == NULL)
return EINVAL;
gdctx = dec_ctx[ctx_id];
bret = vrend_hw_switch_context(gdctx->grctx, true);
if (bret == false)
return EINVAL;
gdctx->ds->buf = block;
gdctx->ds->buf_total = ndw;
gdctx->ds->buf_offset = 0;
while (gdctx->ds->buf_offset < gdctx->ds->buf_total) {
uint32_t header = gdctx->ds->buf[gdctx->ds->buf_offset];
uint32_t len = header >> 16;
ret = 0;
/* check if the guest is doing something bad */
if (gdctx->ds->buf_offset + len + 1 > gdctx->ds->buf_total) {
vrend_report_buffer_error(gdctx->grctx, 0);
break;
}
switch (header & 0xff) {
case VIRGL_CCMD_CREATE_OBJECT:
ret = vrend_decode_create_object(gdctx, len);
break;
case VIRGL_CCMD_BIND_OBJECT:
ret = vrend_decode_bind_object(gdctx, len);
break;
case VIRGL_CCMD_DESTROY_OBJECT:
ret = vrend_decode_destroy_object(gdctx, len);
break;
case VIRGL_CCMD_CLEAR:
ret = vrend_decode_clear(gdctx, len);
break;
case VIRGL_CCMD_DRAW_VBO:
ret = vrend_decode_draw_vbo(gdctx, len);
break;
case VIRGL_CCMD_SET_FRAMEBUFFER_STATE:
ret = vrend_decode_set_framebuffer_state(gdctx, len);
break;
case VIRGL_CCMD_SET_VERTEX_BUFFERS:
ret = vrend_decode_set_vertex_buffers(gdctx, len);
break;
case VIRGL_CCMD_RESOURCE_INLINE_WRITE:
ret = vrend_decode_resource_inline_write(gdctx, len);
break;
case VIRGL_CCMD_SET_VIEWPORT_STATE:
ret = vrend_decode_set_viewport_state(gdctx, len);
break;
case VIRGL_CCMD_SET_SAMPLER_VIEWS:
ret = vrend_decode_set_sampler_views(gdctx, len);
break;
case VIRGL_CCMD_SET_INDEX_BUFFER:
ret = vrend_decode_set_index_buffer(gdctx, len);
break;
case VIRGL_CCMD_SET_CONSTANT_BUFFER:
ret = vrend_decode_set_constant_buffer(gdctx, len);
break;
case VIRGL_CCMD_SET_STENCIL_REF:
ret = vrend_decode_set_stencil_ref(gdctx, len);
break;
case VIRGL_CCMD_SET_BLEND_COLOR:
ret = vrend_decode_set_blend_color(gdctx, len);
break;
case VIRGL_CCMD_SET_SCISSOR_STATE:
ret = vrend_decode_set_scissor_state(gdctx, len);
break;
case VIRGL_CCMD_BLIT:
ret = vrend_decode_blit(gdctx, len);
break;
case VIRGL_CCMD_RESOURCE_COPY_REGION:
ret = vrend_decode_resource_copy_region(gdctx, len);
break;
case VIRGL_CCMD_BIND_SAMPLER_STATES:
ret = vrend_decode_bind_sampler_states(gdctx, len);
break;
case VIRGL_CCMD_BEGIN_QUERY:
ret = vrend_decode_begin_query(gdctx, len);
break;
case VIRGL_CCMD_END_QUERY:
ret = vrend_decode_end_query(gdctx, len);
break;
case VIRGL_CCMD_GET_QUERY_RESULT:
ret = vrend_decode_get_query_result(gdctx, len);
break;
case VIRGL_CCMD_SET_POLYGON_STIPPLE:
ret = vrend_decode_set_polygon_stipple(gdctx, len);
break;
case VIRGL_CCMD_SET_CLIP_STATE:
ret = vrend_decode_set_clip_state(gdctx, len);
break;
case VIRGL_CCMD_SET_SAMPLE_MASK:
ret = vrend_decode_set_sample_mask(gdctx, len);
break;
case VIRGL_CCMD_SET_STREAMOUT_TARGETS:
ret = vrend_decode_set_streamout_targets(gdctx, len);
break;
case VIRGL_CCMD_SET_RENDER_CONDITION:
ret = vrend_decode_set_render_condition(gdctx, len);
break;
case VIRGL_CCMD_SET_UNIFORM_BUFFER:
ret = vrend_decode_set_uniform_buffer(gdctx, len);
break;
case VIRGL_CCMD_SET_SUB_CTX:
ret = vrend_decode_set_sub_ctx(gdctx, len);
break;
case VIRGL_CCMD_CREATE_SUB_CTX:
ret = vrend_decode_create_sub_ctx(gdctx, len);
break;
case VIRGL_CCMD_DESTROY_SUB_CTX:
ret = vrend_decode_destroy_sub_ctx(gdctx, len);
break;
case VIRGL_CCMD_BIND_SHADER:
ret = vrend_decode_bind_shader(gdctx, len);
break;
default:
ret = EINVAL;
}
if (ret == EINVAL) {
vrend_report_buffer_error(gdctx->grctx, header);
goto out;
}
if (ret == ENOMEM)
goto out;
gdctx->ds->buf_offset += (len) + 1;
}
return 0;
out:
return ret;
}
|
CWE-476
| 9,091 | 16,210 |
153820514952150785673533299095029371932
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_clear(struct vrend_decode_ctx *ctx, int length)
{
union pipe_color_union color;
double depth;
unsigned stencil, buffers;
int i;
if (length != VIRGL_OBJ_CLEAR_SIZE)
return EINVAL;
buffers = get_buf_entry(ctx, VIRGL_OBJ_CLEAR_BUFFERS);
for (i = 0; i < 4; i++)
color.ui[i] = get_buf_entry(ctx, VIRGL_OBJ_CLEAR_COLOR_0 + i);
depth = *(double *)(uint64_t *)get_buf_ptr(ctx, VIRGL_OBJ_CLEAR_DEPTH_0);
stencil = get_buf_entry(ctx, VIRGL_OBJ_CLEAR_STENCIL);
vrend_clear(ctx->grctx, buffers, &color, depth, stencil);
return 0;
}
|
CWE-476
| 9,092 | 16,211 |
102715618151186764265371948266836878097
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_create_blend(struct vrend_decode_ctx *ctx, uint32_t handle, uint16_t length)
{
struct pipe_blend_state *blend_state;
uint32_t tmp;
int i;
if (length != VIRGL_OBJ_BLEND_SIZE) {
return EINVAL;
}
blend_state = CALLOC_STRUCT(pipe_blend_state);
if (!blend_state)
return ENOMEM;
tmp = get_buf_entry(ctx, VIRGL_OBJ_BLEND_S0);
blend_state->independent_blend_enable = (tmp & 1);
blend_state->logicop_enable = (tmp >> 1) & 0x1;
blend_state->dither = (tmp >> 2) & 0x1;
blend_state->alpha_to_coverage = (tmp >> 3) & 0x1;
blend_state->alpha_to_one = (tmp >> 4) & 0x1;
tmp = get_buf_entry(ctx, VIRGL_OBJ_BLEND_S1);
blend_state->logicop_func = tmp & 0xf;
for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
tmp = get_buf_entry(ctx, VIRGL_OBJ_BLEND_S2(i));
blend_state->rt[i].blend_enable = tmp & 0x1;
blend_state->rt[i].rgb_func = (tmp >> 1) & 0x7;
blend_state->rt[i].rgb_src_factor = (tmp >> 4) & 0x1f;
blend_state->rt[i].rgb_dst_factor = (tmp >> 9) & 0x1f;
blend_state->rt[i].alpha_func = (tmp >> 14) & 0x7;
blend_state->rt[i].alpha_src_factor = (tmp >> 17) & 0x1f;
blend_state->rt[i].alpha_dst_factor = (tmp >> 22) & 0x1f;
blend_state->rt[i].colormask = (tmp >> 27) & 0xf;
}
tmp = vrend_renderer_object_insert(ctx->grctx, blend_state, sizeof(struct pipe_blend_state), handle,
VIRGL_OBJECT_BLEND);
if (tmp == 0) {
FREE(blend_state);
return ENOMEM;
}
return 0;
}
|
CWE-476
| 9,093 | 16,212 |
151964231845521437875341021423221573472
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_create_dsa(struct vrend_decode_ctx *ctx, uint32_t handle, uint16_t length)
{
int i;
struct pipe_depth_stencil_alpha_state *dsa_state;
uint32_t tmp;
if (length != VIRGL_OBJ_DSA_SIZE)
return EINVAL;
dsa_state = CALLOC_STRUCT(pipe_depth_stencil_alpha_state);
if (!dsa_state)
return ENOMEM;
tmp = get_buf_entry(ctx, VIRGL_OBJ_DSA_S0);
dsa_state->depth.enabled = tmp & 0x1;
dsa_state->depth.writemask = (tmp >> 1) & 0x1;
dsa_state->depth.func = (tmp >> 2) & 0x7;
dsa_state->alpha.enabled = (tmp >> 8) & 0x1;
dsa_state->alpha.func = (tmp >> 9) & 0x7;
for (i = 0; i < 2; i++) {
tmp = get_buf_entry(ctx, VIRGL_OBJ_DSA_S1 + i);
dsa_state->stencil[i].enabled = tmp & 0x1;
dsa_state->stencil[i].func = (tmp >> 1) & 0x7;
dsa_state->stencil[i].fail_op = (tmp >> 4) & 0x7;
dsa_state->stencil[i].zpass_op = (tmp >> 7) & 0x7;
dsa_state->stencil[i].zfail_op = (tmp >> 10) & 0x7;
dsa_state->stencil[i].valuemask = (tmp >> 13) & 0xff;
dsa_state->stencil[i].writemask = (tmp >> 21) & 0xff;
}
tmp = get_buf_entry(ctx, VIRGL_OBJ_DSA_ALPHA_REF);
dsa_state->alpha.ref_value = uif(tmp);
tmp = vrend_renderer_object_insert(ctx->grctx, dsa_state, sizeof(struct pipe_depth_stencil_alpha_state), handle,
VIRGL_OBJECT_DSA);
if (tmp == 0) {
FREE(dsa_state);
return ENOMEM;
}
return 0;
}
|
CWE-476
| 9,094 | 16,213 |
105027334576595804049446799617906312509
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_create_object(struct vrend_decode_ctx *ctx, int length)
{
if (length < 1)
return EINVAL;
uint32_t header = get_buf_entry(ctx, VIRGL_OBJ_CREATE_HEADER);
uint32_t handle = get_buf_entry(ctx, VIRGL_OBJ_CREATE_HANDLE);
uint8_t obj_type = (header >> 8) & 0xff;
int ret = 0;
if (handle == 0)
return EINVAL;
switch (obj_type){
case VIRGL_OBJECT_BLEND:
ret = vrend_decode_create_blend(ctx, handle, length);
break;
case VIRGL_OBJECT_DSA:
ret = vrend_decode_create_dsa(ctx, handle, length);
break;
case VIRGL_OBJECT_RASTERIZER:
ret = vrend_decode_create_rasterizer(ctx, handle, length);
break;
case VIRGL_OBJECT_SHADER:
ret = vrend_decode_create_shader(ctx, handle, length);
break;
case VIRGL_OBJECT_VERTEX_ELEMENTS:
ret = vrend_decode_create_ve(ctx, handle, length);
break;
case VIRGL_OBJECT_SURFACE:
ret = vrend_decode_create_surface(ctx, handle, length);
break;
case VIRGL_OBJECT_SAMPLER_VIEW:
ret = vrend_decode_create_sampler_view(ctx, handle, length);
break;
case VIRGL_OBJECT_SAMPLER_STATE:
ret = vrend_decode_create_sampler_state(ctx, handle, length);
break;
case VIRGL_OBJECT_QUERY:
ret = vrend_decode_create_query(ctx, handle, length);
break;
case VIRGL_OBJECT_STREAMOUT_TARGET:
ret = vrend_decode_create_stream_output_target(ctx, handle, length);
break;
default:
return EINVAL;
}
return ret;
}
|
CWE-476
| 9,095 | 16,214 |
316414197598373483814233756061436546643
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_create_query(struct vrend_decode_ctx *ctx, uint32_t handle, uint16_t length)
{
uint32_t query_type;
uint32_t query_index;
uint32_t res_handle;
uint32_t offset;
uint32_t tmp;
if (length != VIRGL_OBJ_QUERY_SIZE)
return EINVAL;
tmp = get_buf_entry(ctx, VIRGL_OBJ_QUERY_TYPE_INDEX);
query_type = VIRGL_OBJ_QUERY_TYPE(tmp);
query_index = VIRGL_OBJ_QUERY_INDEX(tmp);
offset = get_buf_entry(ctx, VIRGL_OBJ_QUERY_OFFSET);
res_handle = get_buf_entry(ctx, VIRGL_OBJ_QUERY_RES_HANDLE);
return vrend_create_query(ctx->grctx, handle, query_type, query_index, res_handle, offset);
}
|
CWE-476
| 9,096 | 16,215 |
248373186044193285079920055413390338046
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_create_rasterizer(struct vrend_decode_ctx *ctx, uint32_t handle, uint16_t length)
{
struct pipe_rasterizer_state *rs_state;
uint32_t tmp;
if (length != VIRGL_OBJ_RS_SIZE)
return EINVAL;
rs_state = CALLOC_STRUCT(pipe_rasterizer_state);
if (!rs_state)
return ENOMEM;
tmp = get_buf_entry(ctx, VIRGL_OBJ_RS_S0);
#define ebit(name, bit) rs_state->name = (tmp >> bit) & 0x1
#define emask(name, bit, mask) rs_state->name = (tmp >> bit) & mask
ebit(flatshade, 0);
ebit(depth_clip, 1);
ebit(clip_halfz, 2);
ebit(rasterizer_discard, 3);
ebit(flatshade_first, 4);
ebit(light_twoside, 5);
ebit(sprite_coord_mode, 6);
ebit(point_quad_rasterization, 7);
emask(cull_face, 8, 0x3);
emask(fill_front, 10, 0x3);
emask(fill_back, 12, 0x3);
ebit(scissor, 14);
ebit(front_ccw, 15);
ebit(clamp_vertex_color, 16);
ebit(clamp_fragment_color, 17);
ebit(offset_line, 18);
ebit(offset_point, 19);
ebit(offset_tri, 20);
ebit(poly_smooth, 21);
ebit(poly_stipple_enable, 22);
ebit(point_smooth, 23);
ebit(point_size_per_vertex, 24);
ebit(multisample, 25);
ebit(line_smooth, 26);
ebit(line_stipple_enable, 27);
ebit(line_last_pixel, 28);
ebit(half_pixel_center, 29);
ebit(bottom_edge_rule, 30);
rs_state->point_size = uif(get_buf_entry(ctx, VIRGL_OBJ_RS_POINT_SIZE));
rs_state->sprite_coord_enable = get_buf_entry(ctx, VIRGL_OBJ_RS_SPRITE_COORD_ENABLE);
tmp = get_buf_entry(ctx, VIRGL_OBJ_RS_S3);
emask(line_stipple_pattern, 0, 0xffff);
emask(line_stipple_factor, 16, 0xff);
emask(clip_plane_enable, 24, 0xff);
rs_state->line_width = uif(get_buf_entry(ctx, VIRGL_OBJ_RS_LINE_WIDTH));
rs_state->offset_units = uif(get_buf_entry(ctx, VIRGL_OBJ_RS_OFFSET_UNITS));
rs_state->offset_scale = uif(get_buf_entry(ctx, VIRGL_OBJ_RS_OFFSET_SCALE));
rs_state->offset_clamp = uif(get_buf_entry(ctx, VIRGL_OBJ_RS_OFFSET_CLAMP));
tmp = vrend_renderer_object_insert(ctx->grctx, rs_state, sizeof(struct pipe_rasterizer_state), handle,
VIRGL_OBJECT_RASTERIZER);
if (tmp == 0) {
FREE(rs_state);
return ENOMEM;
}
return 0;
}
|
CWE-476
| 9,097 | 16,216 |
263694757642323717000042987789420638846
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_create_sampler_state(struct vrend_decode_ctx *ctx, uint32_t handle, uint16_t length)
{
struct pipe_sampler_state state;
int i;
uint32_t tmp;
if (length != VIRGL_OBJ_SAMPLER_STATE_SIZE)
return EINVAL;
tmp = get_buf_entry(ctx, VIRGL_OBJ_SAMPLER_STATE_S0);
state.wrap_s = tmp & 0x7;
state.wrap_t = (tmp >> 3) & 0x7;
state.wrap_r = (tmp >> 6) & 0x7;
state.min_img_filter = (tmp >> 9) & 0x3;
state.min_mip_filter = (tmp >> 11) & 0x3;
state.mag_img_filter = (tmp >> 13) & 0x3;
state.compare_mode = (tmp >> 15) & 0x1;
state.compare_func = (tmp >> 16) & 0x7;
state.lod_bias = uif(get_buf_entry(ctx, VIRGL_OBJ_SAMPLER_STATE_LOD_BIAS));
state.min_lod = uif(get_buf_entry(ctx, VIRGL_OBJ_SAMPLER_STATE_MIN_LOD));
state.max_lod = uif(get_buf_entry(ctx, VIRGL_OBJ_SAMPLER_STATE_MAX_LOD));
for (i = 0; i < 4; i++)
state.border_color.ui[i] = get_buf_entry(ctx, VIRGL_OBJ_SAMPLER_STATE_BORDER_COLOR(i));
return vrend_create_sampler_state(ctx->grctx, handle, &state);
}
|
CWE-476
| 9,098 | 16,217 |
145847363990917784258104297875349690305
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_create_sampler_view(struct vrend_decode_ctx *ctx, uint32_t handle, uint16_t length)
{
uint32_t res_handle, format, val0, val1, swizzle_packed;
if (length != VIRGL_OBJ_SAMPLER_VIEW_SIZE)
return EINVAL;
res_handle = get_buf_entry(ctx, VIRGL_OBJ_SAMPLER_VIEW_RES_HANDLE);
format = get_buf_entry(ctx, VIRGL_OBJ_SAMPLER_VIEW_FORMAT);
val0 = get_buf_entry(ctx, VIRGL_OBJ_SAMPLER_VIEW_BUFFER_FIRST_ELEMENT);
val1 = get_buf_entry(ctx, VIRGL_OBJ_SAMPLER_VIEW_BUFFER_LAST_ELEMENT);
swizzle_packed = get_buf_entry(ctx, VIRGL_OBJ_SAMPLER_VIEW_SWIZZLE);
return vrend_create_sampler_view(ctx->grctx, handle, res_handle, format, val0, val1,swizzle_packed);
}
|
CWE-476
| 9,099 | 16,218 |
295903250356839035010010809679457729077
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_create_shader(struct vrend_decode_ctx *ctx,
uint32_t handle,
uint16_t length)
{
struct pipe_stream_output_info so_info;
int i, ret;
uint32_t shader_offset;
unsigned num_tokens, num_so_outputs, offlen;
uint8_t *shd_text;
uint32_t type;
if (length < 5)
return EINVAL;
type = get_buf_entry(ctx, VIRGL_OBJ_SHADER_TYPE);
num_tokens = get_buf_entry(ctx, VIRGL_OBJ_SHADER_NUM_TOKENS);
offlen = get_buf_entry(ctx, VIRGL_OBJ_SHADER_OFFSET);
num_so_outputs = get_buf_entry(ctx, VIRGL_OBJ_SHADER_SO_NUM_OUTPUTS);
if (num_so_outputs > PIPE_MAX_SO_OUTPUTS)
return EINVAL;
shader_offset = 6;
if (num_so_outputs) {
so_info.num_outputs = num_so_outputs;
if (so_info.num_outputs) {
for (i = 0; i < 4; i++)
so_info.stride[i] = get_buf_entry(ctx, VIRGL_OBJ_SHADER_SO_STRIDE(i));
for (i = 0; i < so_info.num_outputs; i++) {
uint32_t tmp = get_buf_entry(ctx, VIRGL_OBJ_SHADER_SO_OUTPUT0(i));
so_info.output[i].register_index = tmp & 0xff;
so_info.output[i].start_component = (tmp >> 8) & 0x3;
so_info.output[i].num_components = (tmp >> 10) & 0x7;
so_info.output[i].output_buffer = (tmp >> 13) & 0x7;
so_info.output[i].dst_offset = (tmp >> 16) & 0xffff;
}
}
shader_offset += 4 + (2 * num_so_outputs);
} else
memset(&so_info, 0, sizeof(so_info));
shd_text = get_buf_ptr(ctx, shader_offset);
ret = vrend_create_shader(ctx->grctx, handle, &so_info, (const char *)shd_text, offlen, num_tokens, type, length - shader_offset + 1);
return ret;
}
|
CWE-476
| 9,100 | 16,219 |
111439815067170719982005037497777902845
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_create_stream_output_target(struct vrend_decode_ctx *ctx, uint32_t handle, uint16_t length)
{
uint32_t res_handle, buffer_size, buffer_offset;
if (length != VIRGL_OBJ_STREAMOUT_SIZE)
return EINVAL;
res_handle = get_buf_entry(ctx, VIRGL_OBJ_STREAMOUT_RES_HANDLE);
buffer_offset = get_buf_entry(ctx, VIRGL_OBJ_STREAMOUT_BUFFER_OFFSET);
buffer_size = get_buf_entry(ctx, VIRGL_OBJ_STREAMOUT_BUFFER_SIZE);
return vrend_create_so_target(ctx->grctx, handle, res_handle, buffer_offset,
buffer_size);
}
|
CWE-476
| 9,101 | 16,220 |
293651333347139537951083324809553572313
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_create_sub_ctx(struct vrend_decode_ctx *ctx, int length)
{
if (length != 1)
return EINVAL;
uint32_t ctx_sub_id = get_buf_entry(ctx, 1);
vrend_renderer_create_sub_ctx(ctx->grctx, ctx_sub_id);
return 0;
}
|
CWE-476
| 9,102 | 16,221 |
90918197582153683798221689226043164258
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_create_surface(struct vrend_decode_ctx *ctx, uint32_t handle, uint16_t length)
{
uint32_t res_handle, format, val0, val1;
int ret;
if (length != VIRGL_OBJ_SURFACE_SIZE)
return EINVAL;
res_handle = get_buf_entry(ctx, VIRGL_OBJ_SURFACE_RES_HANDLE);
format = get_buf_entry(ctx, VIRGL_OBJ_SURFACE_FORMAT);
/* decide later if these are texture or buffer */
val0 = get_buf_entry(ctx, VIRGL_OBJ_SURFACE_BUFFER_FIRST_ELEMENT);
val1 = get_buf_entry(ctx, VIRGL_OBJ_SURFACE_BUFFER_LAST_ELEMENT);
ret = vrend_create_surface(ctx->grctx, handle, res_handle, format, val0, val1);
return ret;
}
|
CWE-476
| 9,103 | 16,222 |
263294198854748723293695899728840531155
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_create_ve(struct vrend_decode_ctx *ctx, uint32_t handle, uint16_t length)
{
struct pipe_vertex_element *ve = NULL;
int num_elements;
int i;
int ret;
if (length < 1)
return EINVAL;
if ((length - 1) % 4)
return EINVAL;
num_elements = (length - 1) / 4;
if (num_elements) {
ve = calloc(num_elements, sizeof(struct pipe_vertex_element));
if (!ve)
return ENOMEM;
for (i = 0; i < num_elements; i++) {
ve[i].src_offset = get_buf_entry(ctx, VIRGL_OBJ_VERTEX_ELEMENTS_V0_SRC_OFFSET(i));
ve[i].instance_divisor = get_buf_entry(ctx, VIRGL_OBJ_VERTEX_ELEMENTS_V0_INSTANCE_DIVISOR(i));
ve[i].vertex_buffer_index = get_buf_entry(ctx, VIRGL_OBJ_VERTEX_ELEMENTS_V0_VERTEX_BUFFER_INDEX(i));
if (ve[i].vertex_buffer_index >= PIPE_MAX_ATTRIBS)
return EINVAL;
ve[i].src_format = get_buf_entry(ctx, VIRGL_OBJ_VERTEX_ELEMENTS_V0_SRC_FORMAT(i));
}
}
ret = vrend_create_vertex_elements_state(ctx->grctx, handle, num_elements, ve);
FREE(ve);
return ret;
}
|
CWE-476
| 9,104 | 16,223 |
299027673952818998902532399794235097239
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_destroy_object(struct vrend_decode_ctx *ctx, int length)
{
if (length != 1)
return EINVAL;
uint32_t handle = get_buf_entry(ctx, VIRGL_OBJ_DESTROY_HANDLE);
vrend_renderer_object_destroy(ctx->grctx, handle);
return 0;
}
|
CWE-476
| 9,105 | 16,224 |
69580039304519554366581774671163022396
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_draw_vbo(struct vrend_decode_ctx *ctx, int length)
{
struct pipe_draw_info info;
uint32_t cso;
if (length != VIRGL_DRAW_VBO_SIZE)
return EINVAL;
memset(&info, 0, sizeof(struct pipe_draw_info));
info.start = get_buf_entry(ctx, VIRGL_DRAW_VBO_START);
info.count = get_buf_entry(ctx, VIRGL_DRAW_VBO_COUNT);
info.mode = get_buf_entry(ctx, VIRGL_DRAW_VBO_MODE);
info.indexed = get_buf_entry(ctx, VIRGL_DRAW_VBO_INDEXED);
info.instance_count = get_buf_entry(ctx, VIRGL_DRAW_VBO_INSTANCE_COUNT);
info.index_bias = get_buf_entry(ctx, VIRGL_DRAW_VBO_INDEX_BIAS);
info.start_instance = get_buf_entry(ctx, VIRGL_DRAW_VBO_START_INSTANCE);
info.primitive_restart = get_buf_entry(ctx, VIRGL_DRAW_VBO_PRIMITIVE_RESTART);
info.restart_index = get_buf_entry(ctx, VIRGL_DRAW_VBO_RESTART_INDEX);
info.min_index = get_buf_entry(ctx, VIRGL_DRAW_VBO_MIN_INDEX);
info.max_index = get_buf_entry(ctx, VIRGL_DRAW_VBO_MAX_INDEX);
cso = get_buf_entry(ctx, VIRGL_DRAW_VBO_COUNT_FROM_SO);
vrend_draw_vbo(ctx->grctx, &info, cso);
return 0;
}
|
CWE-476
| 9,107 | 16,225 |
192985478648532634831471492490696949391
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_end_query(struct vrend_decode_ctx *ctx, int length)
{
if (length != 1)
return EINVAL;
uint32_t handle = get_buf_entry(ctx, VIRGL_QUERY_END_HANDLE);
vrend_end_query(ctx->grctx, handle);
return 0;
}
|
CWE-476
| 9,108 | 16,226 |
313679727749472365105609605268768675244
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_get_query_result(struct vrend_decode_ctx *ctx, int length)
{
if (length != 2)
return EINVAL;
uint32_t handle = get_buf_entry(ctx, VIRGL_QUERY_RESULT_HANDLE);
uint32_t wait = get_buf_entry(ctx, VIRGL_QUERY_RESULT_WAIT);
vrend_get_query_result(ctx->grctx, handle, wait);
return 0;
}
|
CWE-476
| 9,109 | 16,227 |
75205192536116611743434062098283011206
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
void vrend_decode_reset(bool ctx_0_only)
{
int i;
vrend_hw_switch_context(dec_ctx[0]->grctx, true);
if (ctx_0_only == false) {
for (i = 1; i < VREND_MAX_CTX; i++) {
if (!dec_ctx[i])
continue;
if (!dec_ctx[i]->grctx)
continue;
vrend_destroy_context(dec_ctx[i]->grctx);
free(dec_ctx[i]);
dec_ctx[i] = NULL;
}
} else {
vrend_destroy_context(dec_ctx[0]->grctx);
free(dec_ctx[0]);
dec_ctx[0] = NULL;
}
}
|
CWE-476
| 9,110 | 16,228 |
255618711974961993615865965342191673517
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_resource_copy_region(struct vrend_decode_ctx *ctx, int length)
{
struct pipe_box box;
uint32_t dst_handle, src_handle;
uint32_t dst_level, dstx, dsty, dstz;
uint32_t src_level;
if (length != VIRGL_CMD_RESOURCE_COPY_REGION_SIZE)
return EINVAL;
dst_handle = get_buf_entry(ctx, VIRGL_CMD_RCR_DST_RES_HANDLE);
dst_level = get_buf_entry(ctx, VIRGL_CMD_RCR_DST_LEVEL);
dstx = get_buf_entry(ctx, VIRGL_CMD_RCR_DST_X);
dsty = get_buf_entry(ctx, VIRGL_CMD_RCR_DST_Y);
dstz = get_buf_entry(ctx, VIRGL_CMD_RCR_DST_Z);
src_handle = get_buf_entry(ctx, VIRGL_CMD_RCR_SRC_RES_HANDLE);
src_level = get_buf_entry(ctx, VIRGL_CMD_RCR_SRC_LEVEL);
box.x = get_buf_entry(ctx, VIRGL_CMD_RCR_SRC_X);
box.y = get_buf_entry(ctx, VIRGL_CMD_RCR_SRC_Y);
box.z = get_buf_entry(ctx, VIRGL_CMD_RCR_SRC_Z);
box.width = get_buf_entry(ctx, VIRGL_CMD_RCR_SRC_W);
box.height = get_buf_entry(ctx, VIRGL_CMD_RCR_SRC_H);
box.depth = get_buf_entry(ctx, VIRGL_CMD_RCR_SRC_D);
vrend_renderer_resource_copy_region(ctx->grctx, dst_handle,
dst_level, dstx, dsty, dstz,
src_handle, src_level,
&box);
return 0;
}
|
CWE-476
| 9,111 | 16,229 |
333450520017244767535569344603560172034
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_resource_inline_write(struct vrend_decode_ctx *ctx, uint16_t length)
{
struct vrend_transfer_info info;
struct pipe_box box;
uint32_t res_handle;
uint32_t level, usage, stride, layer_stride, data_len;
struct iovec dataiovec;
void *data;
if (length < 12)
return EINVAL;
if (length + ctx->ds->buf_offset > ctx->ds->buf_total)
return EINVAL;
res_handle = get_buf_entry(ctx, VIRGL_RESOURCE_IW_RES_HANDLE);
data_len = (length - 11) * 4;
level = get_buf_entry(ctx, VIRGL_RESOURCE_IW_LEVEL);
usage = get_buf_entry(ctx, VIRGL_RESOURCE_IW_USAGE);
stride = get_buf_entry(ctx, VIRGL_RESOURCE_IW_STRIDE);
layer_stride = get_buf_entry(ctx, VIRGL_RESOURCE_IW_LAYER_STRIDE);
box.x = get_buf_entry(ctx, VIRGL_RESOURCE_IW_X);
box.y = get_buf_entry(ctx, VIRGL_RESOURCE_IW_Y);
box.z = get_buf_entry(ctx, VIRGL_RESOURCE_IW_Z);
box.width = get_buf_entry(ctx, VIRGL_RESOURCE_IW_W);
box.height = get_buf_entry(ctx, VIRGL_RESOURCE_IW_H);
box.depth = get_buf_entry(ctx, VIRGL_RESOURCE_IW_D);
data = get_buf_ptr(ctx, VIRGL_RESOURCE_IW_DATA_START);
info.handle = res_handle;
info.ctx_id = 0;
info.level = level;
info.stride = stride;
info.layer_stride = layer_stride;
info.box = &box;
info.offset = 0;
dataiovec.iov_base = data;
dataiovec.iov_len = data_len;
info.iovec = &dataiovec;
info.iovec_cnt = 1;
return vrend_transfer_inline_write(ctx->grctx, &info, usage);
}
|
CWE-476
| 9,112 | 16,230 |
32681065364479830889489199394006946994
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_set_blend_color(struct vrend_decode_ctx *ctx, int length)
{
struct pipe_blend_color color;
int i;
if (length != VIRGL_SET_BLEND_COLOR_SIZE)
return EINVAL;
for (i = 0; i < 4; i++)
color.color[i] = uif(get_buf_entry(ctx, VIRGL_SET_BLEND_COLOR(i)));
vrend_set_blend_color(ctx->grctx, &color);
return 0;
}
|
CWE-476
| 9,113 | 16,231 |
121876721096764464110537276767445200986
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_set_clip_state(struct vrend_decode_ctx *ctx, int length)
{
struct pipe_clip_state clip;
int i, j;
if (length != VIRGL_SET_CLIP_STATE_SIZE)
return EINVAL;
for (i = 0; i < 8; i++)
for (j = 0; j < 4; j++)
clip.ucp[i][j] = uif(get_buf_entry(ctx, VIRGL_SET_CLIP_STATE_C0 + (i * 4) + j));
vrend_set_clip_state(ctx->grctx, &clip);
return 0;
}
|
CWE-476
| 9,114 | 16,232 |
91914391052597668603427069555711601318
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_set_constant_buffer(struct vrend_decode_ctx *ctx, uint16_t length)
{
uint32_t shader;
uint32_t index;
int nc = (length - 2);
if (length < 2)
return EINVAL;
shader = get_buf_entry(ctx, VIRGL_SET_CONSTANT_BUFFER_SHADER_TYPE);
index = get_buf_entry(ctx, VIRGL_SET_CONSTANT_BUFFER_INDEX);
if (shader >= PIPE_SHADER_TYPES)
return EINVAL;
vrend_set_constants(ctx->grctx, shader, index, nc, get_buf_ptr(ctx, VIRGL_SET_CONSTANT_BUFFER_DATA_START));
return 0;
}
|
CWE-476
| 9,115 | 16,233 |
124201968531136925919200503368389953453
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_set_framebuffer_state(struct vrend_decode_ctx *ctx, int length)
{
if (length < 2)
return EINVAL;
uint32_t nr_cbufs = get_buf_entry(ctx, VIRGL_SET_FRAMEBUFFER_STATE_NR_CBUFS);
uint32_t zsurf_handle = get_buf_entry(ctx, VIRGL_SET_FRAMEBUFFER_STATE_NR_ZSURF_HANDLE);
uint32_t surf_handle[8];
int i;
if (length != (2 + nr_cbufs))
return EINVAL;
if (nr_cbufs > 8)
return EINVAL;
for (i = 0; i < nr_cbufs; i++)
surf_handle[i] = get_buf_entry(ctx, VIRGL_SET_FRAMEBUFFER_STATE_CBUF_HANDLE(i));
vrend_set_framebuffer_state(ctx->grctx, nr_cbufs, surf_handle, zsurf_handle);
return 0;
}
|
CWE-476
| 9,116 | 16,234 |
86408269789452771321845776828011279200
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_set_index_buffer(struct vrend_decode_ctx *ctx, int length)
{
if (length != 1 && length != 3)
return EINVAL;
vrend_set_index_buffer(ctx->grctx,
get_buf_entry(ctx, VIRGL_SET_INDEX_BUFFER_HANDLE),
(length == 3) ? get_buf_entry(ctx, VIRGL_SET_INDEX_BUFFER_INDEX_SIZE) : 0,
(length == 3) ? get_buf_entry(ctx, VIRGL_SET_INDEX_BUFFER_OFFSET) : 0);
return 0;
}
|
CWE-476
| 9,117 | 16,235 |
232224722574989558566194959206918159018
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_set_render_condition(struct vrend_decode_ctx *ctx, int length)
{
if (length != VIRGL_RENDER_CONDITION_SIZE)
return EINVAL;
uint32_t handle = get_buf_entry(ctx, VIRGL_RENDER_CONDITION_HANDLE);
bool condition = get_buf_entry(ctx, VIRGL_RENDER_CONDITION_CONDITION) & 1;
uint mode = get_buf_entry(ctx, VIRGL_RENDER_CONDITION_MODE);
vrend_render_condition(ctx->grctx, handle, condition, mode);
return 0;
}
|
CWE-476
| 9,119 | 16,236 |
107996433528763449615613424624728813732
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_set_sample_mask(struct vrend_decode_ctx *ctx, int length)
{
unsigned mask;
if (length != VIRGL_SET_SAMPLE_MASK_SIZE)
return EINVAL;
mask = get_buf_entry(ctx, VIRGL_SET_SAMPLE_MASK_MASK);
vrend_set_sample_mask(ctx->grctx, mask);
return 0;
}
|
CWE-476
| 9,120 | 16,237 |
228160038241499809204049839029075588595
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_set_sampler_views(struct vrend_decode_ctx *ctx, uint16_t length)
{
int num_samps;
int i;
uint32_t shader_type, start_slot;
if (length < 2)
return EINVAL;
num_samps = length - 2;
shader_type = get_buf_entry(ctx, VIRGL_SET_SAMPLER_VIEWS_SHADER_TYPE);
start_slot = get_buf_entry(ctx, VIRGL_SET_SAMPLER_VIEWS_START_SLOT);
if (shader_type >= PIPE_SHADER_TYPES)
return EINVAL;
if (num_samps > PIPE_MAX_SHADER_SAMPLER_VIEWS ||
start_slot > (PIPE_MAX_SHADER_SAMPLER_VIEWS - num_samps))
return EINVAL;
for (i = 0; i < num_samps; i++) {
uint32_t handle = get_buf_entry(ctx, VIRGL_SET_SAMPLER_VIEWS_V0_HANDLE + i);
vrend_set_single_sampler_view(ctx->grctx, shader_type, i + start_slot, handle);
}
vrend_set_num_sampler_views(ctx->grctx, shader_type, start_slot, num_samps);
return 0;
}
|
CWE-476
| 9,121 | 16,238 |
222162027872923599870765787953613485489
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_set_scissor_state(struct vrend_decode_ctx *ctx, int length)
{
struct pipe_scissor_state ss[PIPE_MAX_VIEWPORTS];
uint32_t temp;
uint32_t num_scissor, start_slot;
int s;
if (length < 1)
return EINVAL;
if ((length - 1) % 2)
return EINVAL;
num_scissor = (length - 1) / 2;
if (num_scissor > PIPE_MAX_VIEWPORTS)
return EINVAL;
start_slot = get_buf_entry(ctx, VIRGL_SET_SCISSOR_START_SLOT);
for (s = 0; s < num_scissor; s++) {
temp = get_buf_entry(ctx, VIRGL_SET_SCISSOR_MINX_MINY(s));
ss[s].minx = temp & 0xffff;
ss[s].miny = (temp >> 16) & 0xffff;
temp = get_buf_entry(ctx, VIRGL_SET_SCISSOR_MAXX_MAXY(s));
ss[s].maxx = temp & 0xffff;
ss[s].maxy = (temp >> 16) & 0xffff;
}
vrend_set_scissor_state(ctx->grctx, start_slot, num_scissor, ss);
return 0;
}
|
CWE-476
| 9,122 | 16,239 |
304203084802824141221934917324424325338
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_set_stencil_ref(struct vrend_decode_ctx *ctx, int length)
{
if (length != VIRGL_SET_STENCIL_REF_SIZE)
return EINVAL;
struct pipe_stencil_ref ref;
uint32_t val = get_buf_entry(ctx, VIRGL_SET_STENCIL_REF);
ref.ref_value[0] = val & 0xff;
ref.ref_value[1] = (val >> 8) & 0xff;
vrend_set_stencil_ref(ctx->grctx, &ref);
return 0;
}
|
CWE-476
| 9,123 | 16,240 |
33471486470249237789820620275754143093
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_set_streamout_targets(struct vrend_decode_ctx *ctx,
uint16_t length)
{
uint32_t handles[16];
uint32_t num_handles = length - 1;
uint32_t append_bitmask;
int i;
if (length < 1)
return EINVAL;
if (num_handles > ARRAY_SIZE(handles))
return EINVAL;
append_bitmask = get_buf_entry(ctx, VIRGL_SET_STREAMOUT_TARGETS_APPEND_BITMASK);
for (i = 0; i < num_handles; i++)
handles[i] = get_buf_entry(ctx, VIRGL_SET_STREAMOUT_TARGETS_H0 + i);
vrend_set_streamout_targets(ctx->grctx, append_bitmask, num_handles, handles);
return 0;
}
|
CWE-476
| 9,124 | 16,241 |
117587104473418854008206430230369427929
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_set_sub_ctx(struct vrend_decode_ctx *ctx, int length)
{
if (length != 1)
return EINVAL;
uint32_t ctx_sub_id = get_buf_entry(ctx, 1);
vrend_renderer_set_sub_ctx(ctx->grctx, ctx_sub_id);
return 0;
}
|
CWE-476
| 9,125 | 16,242 |
62870414490944067525618936387172919618
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_set_uniform_buffer(struct vrend_decode_ctx *ctx, int length)
{
if (length != VIRGL_SET_UNIFORM_BUFFER_SIZE)
return EINVAL;
uint32_t shader = get_buf_entry(ctx, VIRGL_SET_UNIFORM_BUFFER_SHADER_TYPE);
uint32_t index = get_buf_entry(ctx, VIRGL_SET_UNIFORM_BUFFER_INDEX);
uint32_t offset = get_buf_entry(ctx, VIRGL_SET_UNIFORM_BUFFER_OFFSET);
uint32_t blength = get_buf_entry(ctx, VIRGL_SET_UNIFORM_BUFFER_LENGTH);
uint32_t handle = get_buf_entry(ctx, VIRGL_SET_UNIFORM_BUFFER_RES_HANDLE);
if (shader >= PIPE_SHADER_TYPES)
return EINVAL;
if (index >= PIPE_MAX_CONSTANT_BUFFERS)
return EINVAL;
vrend_set_uniform_buffer(ctx->grctx, shader, index, offset, blength, handle);
return 0;
}
|
CWE-476
| 9,126 | 16,243 |
196485960482577012016920218977976210291
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
static int vrend_decode_set_vertex_buffers(struct vrend_decode_ctx *ctx, uint16_t length)
{
int num_vbo;
int i;
/* must be a multiple of 3 */
if (length && (length % 3))
return EINVAL;
num_vbo = (length / 3);
if (num_vbo > PIPE_MAX_ATTRIBS)
return EINVAL;
for (i = 0; i < num_vbo; i++) {
vrend_set_single_vbo(ctx->grctx, i,
get_buf_entry(ctx, VIRGL_SET_VERTEX_BUFFER_STRIDE(i)),
get_buf_entry(ctx, VIRGL_SET_VERTEX_BUFFER_OFFSET(i)),
get_buf_entry(ctx, VIRGL_SET_VERTEX_BUFFER_HANDLE(i)));
}
vrend_set_num_vbo(ctx->grctx, num_vbo);
return 0;
}
|
CWE-476
| 9,127 | 16,244 |
143740420111094112009805415519938220026
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
struct vrend_context *vrend_lookup_renderer_ctx(uint32_t ctx_id)
{
if (ctx_id >= VREND_MAX_CTX)
return NULL;
if (dec_ctx[ctx_id] == NULL)
return NULL;
return dec_ctx[ctx_id]->grctx;
}
|
CWE-476
| 9,129 | 16,245 |
181654337417707140663598848097914557804
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
int vrend_renderer_context_create(uint32_t handle, uint32_t nlen, const char *debug_name)
{
if (handle >= VREND_MAX_CTX)
return EINVAL;
/* context 0 is always available with no guarantees */
if (handle == 0)
return EINVAL;
vrend_renderer_context_create_internal(handle, nlen, debug_name);
return 0;
}
|
CWE-476
| 9,130 | 16,246 |
122900034354789308424202624222088517751
| null | null | null |
virglrenderer
|
0a5dff15912207b83018485f83e067474e818bab
| 0 |
void vrend_renderer_context_create_internal(uint32_t handle, uint32_t nlen,
const char *debug_name)
{
struct vrend_decode_ctx *dctx;
if (handle >= VREND_MAX_CTX)
return;
dctx = dec_ctx[handle];
if (dctx)
return;
dctx = malloc(sizeof(struct vrend_decode_ctx));
if (!dctx)
return;
dctx->grctx = vrend_create_context(handle, nlen, debug_name);
if (!dctx->grctx) {
free(dctx);
return;
}
dctx->ds = &dctx->ids;
dec_ctx[handle] = dctx;
}
|
CWE-476
| 9,131 | 16,247 |
281467029163562988536852075239154727909
| null | null | null |
virglrenderer
|
e534b51ca3c3cd25f3990589932a9ed711c59b27
| 0 |
static void eat_opt_white( const char **pcur )
{
while (**pcur == ' ' || **pcur == '\t' || **pcur == '\n')
(*pcur)++;
}
|
CWE-119
| 9,136 | 16,248 |
243348369308448661142432933205964528677
| null | null | null |
virglrenderer
|
e534b51ca3c3cd25f3990589932a9ed711c59b27
| 0 |
static void eat_until_eol( const char **pcur )
{
while (**pcur != '\0' && **pcur != '\n')
(*pcur)++;
}
|
CWE-119
| 9,137 | 16,249 |
312626506492585684923897609648451690902
| null | null | null |
virglrenderer
|
e534b51ca3c3cd25f3990589932a9ed711c59b27
| 0 |
static boolean eat_white( const char **pcur )
{
const char *cur = *pcur;
eat_opt_white( pcur );
return *pcur > cur;
}
|
CWE-119
| 9,138 | 16,250 |
36790406525666811717893869606808853396
| null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.