diff --git a/src/virgl_egl_context.c b/src/virgl_egl_context.c index e7114e0..acc7d92 100644 --- a/src/virgl_egl_context.c +++ b/src/virgl_egl_context.c @@ -43,213 +43,213 @@ #include "virgl_hw.h" struct virgl_egl { - int fd; - struct gbm_device *gbm_dev; - EGLDisplay egl_display; - EGLConfig egl_conf; - EGLContext egl_ctx; - bool have_mesa_drm_image; - bool have_mesa_dma_buf_img_export; + int fd; + struct gbm_device *gbm_dev; + EGLDisplay egl_display; + EGLConfig egl_conf; + EGLContext egl_ctx; + bool have_mesa_drm_image; + bool have_mesa_dma_buf_img_export; }; static int egl_rendernode_open(void) { - DIR *dir; - struct dirent *e; - int r, fd; - char *p; - dir = opendir("/dev/dri"); - if (!dir) - return -1; - - fd = -1; - while ((e = readdir(dir))) { - if (e->d_type != DT_CHR) - continue; - - if (strncmp(e->d_name, "renderD", 7)) - continue; - - r = asprintf(&p, "/dev/dri/%s", e->d_name); - if (r < 0) - return -1; - - r = open(p, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK); - if (r < 0){ - free(p); - continue; - } - fd = r; - free(p); - break; - } - - closedir(dir); - if (fd < 0) - return -1; - return fd; + DIR *dir; + struct dirent *e; + int r, fd; + char *p; + dir = opendir("/dev/dri"); + if (!dir) + return -1; + + fd = -1; + while ((e = readdir(dir))) { + if (e->d_type != DT_CHR) + continue; + + if (strncmp(e->d_name, "renderD", 7)) + continue; + + r = asprintf(&p, "/dev/dri/%s", e->d_name); + if (r < 0) + return -1; + + r = open(p, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK); + if (r < 0){ + free(p); + continue; + } + fd = r; + free(p); + break; + } + + closedir(dir); + if (fd < 0) + return -1; + return fd; } static bool virgl_egl_has_extension_in_string(const char *haystack, const char *needle) { - const unsigned needle_len = strlen(needle); + const unsigned needle_len = strlen(needle); - if (needle_len == 0) - return false; + if (needle_len == 0) + return false; - while (true) { - const char *const s = strstr(haystack, needle); + while (true) { + const char *const s = strstr(haystack, needle); - if (s == NULL) - return false; + if (s == NULL) + return false; - if (s[needle_len] == ' ' || s[needle_len] == '\0') { - return true; - } + if (s[needle_len] == ' ' || s[needle_len] == '\0') { + return true; + } - /* strstr found an extension whose name begins with - * needle, but whose name is not equal to needle. - * Restart the search at s + needle_len so that we - * don't just find the same extension again and go - * into an infinite loop. - */ - haystack = s + needle_len; - } + /* strstr found an extension whose name begins with + * needle, but whose name is not equal to needle. + * Restart the search at s + needle_len so that we + * don't just find the same extension again and go + * into an infinite loop. + */ + haystack = s + needle_len; + } - return false; + return false; } struct virgl_egl *virgl_egl_init(void) { - static const EGLint conf_att[] = { - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_ALPHA_SIZE, 0, - EGL_NONE, - }; - static const EGLint ctx_att[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; - EGLBoolean b; - EGLenum api; - EGLint major, minor, n; - const char *extension_list; - struct virgl_egl *d; - - d = malloc(sizeof(struct virgl_egl)); - if (!d) - return NULL; - - d->fd = egl_rendernode_open(); - if (d->fd == -1) - goto fail; - d->gbm_dev = gbm_create_device(d->fd); - if (!d->gbm_dev) - goto fail; - - d->egl_display = eglGetDisplay((EGLNativeDisplayType)d->gbm_dev); - if (!d->egl_display) - goto fail; - - b = eglInitialize(d->egl_display, &major, &minor); - if (!b) - goto fail; - - extension_list = eglQueryString(d->egl_display, EGL_EXTENSIONS); + static const EGLint conf_att[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_ALPHA_SIZE, 0, + EGL_NONE, + }; + static const EGLint ctx_att[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + EGLBoolean b; + EGLenum api; + EGLint major, minor, n; + const char *extension_list; + struct virgl_egl *d; + + d = malloc(sizeof(struct virgl_egl)); + if (!d) + return NULL; + + d->fd = egl_rendernode_open(); + if (d->fd == -1) + goto fail; + d->gbm_dev = gbm_create_device(d->fd); + if (!d->gbm_dev) + goto fail; + + d->egl_display = eglGetDisplay((EGLNativeDisplayType)d->gbm_dev); + if (!d->egl_display) + goto fail; + + b = eglInitialize(d->egl_display, &major, &minor); + if (!b) + goto fail; + + extension_list = eglQueryString(d->egl_display, EGL_EXTENSIONS); #ifdef VIRGL_EGL_DEBUG - fprintf(stderr, "EGL major/minor: %d.%d\n", major, minor); - fprintf(stderr, "EGL version: %s\n", - eglQueryString(d->egl_display, EGL_VERSION)); - fprintf(stderr, "EGL vendor: %s\n", - eglQueryString(d->egl_display, EGL_VENDOR)); - fprintf(stderr, "EGL extensions: %s\n", extension_list); + fprintf(stderr, "EGL major/minor: %d.%d\n", major, minor); + fprintf(stderr, "EGL version: %s\n", + eglQueryString(d->egl_display, EGL_VERSION)); + fprintf(stderr, "EGL vendor: %s\n", + eglQueryString(d->egl_display, EGL_VENDOR)); + fprintf(stderr, "EGL extensions: %s\n", extension_list); #endif - /* require surfaceless context */ - if (!virgl_egl_has_extension_in_string(extension_list, "EGL_KHR_surfaceless_context")) - goto fail; + /* require surfaceless context */ + if (!virgl_egl_has_extension_in_string(extension_list, "EGL_KHR_surfaceless_context")) + goto fail; - d->have_mesa_drm_image = false; - d->have_mesa_dma_buf_img_export = false; - if (virgl_egl_has_extension_in_string(extension_list, "EGL_MESA_drm_image")) - d->have_mesa_drm_image = true; + d->have_mesa_drm_image = false; + d->have_mesa_dma_buf_img_export = false; + if (virgl_egl_has_extension_in_string(extension_list, "EGL_MESA_drm_image")) + d->have_mesa_drm_image = true; - if (virgl_egl_has_extension_in_string(extension_list, "EGL_MESA_image_dma_buf_export")) - d->have_mesa_dma_buf_img_export = true; + if (virgl_egl_has_extension_in_string(extension_list, "EGL_MESA_image_dma_buf_export")) + d->have_mesa_dma_buf_img_export = true; - if (d->have_mesa_drm_image == false && d->have_mesa_dma_buf_img_export == false) { - fprintf(stderr, "failed to find drm image extensions\n"); - goto fail; - } + if (d->have_mesa_drm_image == false && d->have_mesa_dma_buf_img_export == false) { + fprintf(stderr, "failed to find drm image extensions\n"); + goto fail; + } - api = EGL_OPENGL_API; - b = eglBindAPI(api); - if (!b) - goto fail; + api = EGL_OPENGL_API; + b = eglBindAPI(api); + if (!b) + goto fail; - b = eglChooseConfig(d->egl_display, conf_att, &d->egl_conf, - 1, &n); + b = eglChooseConfig(d->egl_display, conf_att, &d->egl_conf, + 1, &n); - if (!b || n != 1) - goto fail; + if (!b || n != 1) + goto fail; - d->egl_ctx = eglCreateContext(d->egl_display, - d->egl_conf, - EGL_NO_CONTEXT, - ctx_att); - if (!d->egl_ctx) - goto fail; + d->egl_ctx = eglCreateContext(d->egl_display, + d->egl_conf, + EGL_NO_CONTEXT, + ctx_att); + if (!d->egl_ctx) + goto fail; - eglMakeCurrent(d->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, - d->egl_ctx); - return d; + eglMakeCurrent(d->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, + d->egl_ctx); + return d; fail: - free(d); - return NULL; + free(d); + return NULL; } void virgl_egl_destroy(struct virgl_egl *d) { - eglMakeCurrent(d->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, - EGL_NO_CONTEXT); - eglDestroyContext(d->egl_display, d->egl_ctx); - eglTerminate(d->egl_display); - gbm_device_destroy(d->gbm_dev); - close(d->fd); - free(d); + eglMakeCurrent(d->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, + EGL_NO_CONTEXT); + eglDestroyContext(d->egl_display, d->egl_ctx); + eglTerminate(d->egl_display); + gbm_device_destroy(d->gbm_dev); + close(d->fd); + free(d); } virgl_renderer_gl_context virgl_egl_create_context(struct virgl_egl *ve, struct virgl_gl_ctx_param *vparams) { - EGLContext eglctx; - EGLint ctx_att[] = { - EGL_CONTEXT_CLIENT_VERSION, vparams->major_ver, - EGL_CONTEXT_MINOR_VERSION_KHR, vparams->minor_ver, - EGL_NONE - }; - eglctx = eglCreateContext(ve->egl_display, - ve->egl_conf, - vparams->shared ? eglGetCurrentContext() : EGL_NO_CONTEXT, - ctx_att); - return (virgl_renderer_gl_context)eglctx; + EGLContext eglctx; + EGLint ctx_att[] = { + EGL_CONTEXT_CLIENT_VERSION, vparams->major_ver, + EGL_CONTEXT_MINOR_VERSION_KHR, vparams->minor_ver, + EGL_NONE + }; + eglctx = eglCreateContext(ve->egl_display, + ve->egl_conf, + vparams->shared ? eglGetCurrentContext() : EGL_NO_CONTEXT, + ctx_att); + return (virgl_renderer_gl_context)eglctx; } void virgl_egl_destroy_context(struct virgl_egl *ve, virgl_renderer_gl_context virglctx) { - EGLContext eglctx = (EGLContext)virglctx; - eglDestroyContext(ve->egl_display, eglctx); + EGLContext eglctx = (EGLContext)virglctx; + eglDestroyContext(ve->egl_display, eglctx); } int virgl_egl_make_context_current(struct virgl_egl *ve, virgl_renderer_gl_context virglctx) { - EGLContext eglctx = (EGLContext)virglctx; + EGLContext eglctx = (EGLContext)virglctx; - return eglMakeCurrent(ve->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, - eglctx); + return eglMakeCurrent(ve->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, + eglctx); } virgl_renderer_gl_context virgl_egl_get_current_context(struct virgl_egl *ve) @@ -289,7 +289,7 @@ int virgl_egl_get_fourcc_for_texture(struct virgl_egl *ve, uint32_t tex_id, uint #endif -fallback: + fallback: *fourcc = virgl_egl_get_gbm_format(format); return ret; } @@ -308,36 +308,36 @@ int virgl_egl_get_fd_for_texture(struct virgl_egl *ve, uint32_t tex_id, int *fd) ret = EINVAL; if (ve->have_mesa_dma_buf_img_export) { #ifdef EGL_MESA_image_dma_buf_export - b = eglExportDMABUFImageMESA(ve->egl_display, - image, - fd, - &stride); + b = eglExportDMABUFImageMESA(ve->egl_display, + image, + fd, + &stride); #else - goto out_destroy; + goto out_destroy; #endif } else { #ifdef EGL_MESA_drm_image - EGLint handle; - int r; - b = eglExportDRMImageMESA(ve->egl_display, - image, - NULL, &handle, - &stride); - - if (!b) + EGLint handle; + int r; + b = eglExportDRMImageMESA(ve->egl_display, + image, + NULL, &handle, + &stride); + + if (!b) goto out_destroy; - fprintf(stderr,"image exported %d %d\n", handle, stride); + fprintf(stderr,"image exported %d %d\n", handle, stride); - r = drmPrimeHandleToFD(ve->fd, handle, DRM_CLOEXEC, fd); - if (r < 0) + r = drmPrimeHandleToFD(ve->fd, handle, DRM_CLOEXEC, fd); + if (r < 0) goto out_destroy; #else - goto out_destroy; + goto out_destroy; #endif } ret = 0; -out_destroy: + out_destroy: eglDestroyImageKHR(ve->egl_display, image); return ret; } diff --git a/src/virgl_hw.h b/src/virgl_hw.h index 0adeb4b..fc96046 100644 --- a/src/virgl_hw.h +++ b/src/virgl_hw.h @@ -163,7 +163,7 @@ enum virgl_formats { VIRGL_FORMAT_L32_SINT = 223, VIRGL_FORMAT_L32A32_SINT = 224, - VIRGL_FORMAT_B10G10R10A2_UINT = 225, + VIRGL_FORMAT_B10G10R10A2_UINT = 225, VIRGL_FORMAT_R8G8B8X8_SNORM = 229, VIRGL_FORMAT_R8G8B8X8_SRGB = 230, diff --git a/src/virgl_protocol.h b/src/virgl_protocol.h index f6c8d27..789d977 100644 --- a/src/virgl_protocol.h +++ b/src/virgl_protocol.h @@ -65,7 +65,7 @@ enum virgl_context_cmd { }; -/* +/* 8-bit cmd headers 8-bit object type 16-bit length diff --git a/src/virglrenderer.c b/src/virglrenderer.c index 95cda9f..98f8fd6 100644 --- a/src/virglrenderer.c +++ b/src/virglrenderer.c @@ -59,7 +59,7 @@ void virgl_renderer_resource_unref(uint32_t res_handle) void virgl_renderer_fill_caps(uint32_t set, uint32_t version, void *caps) { - vrend_renderer_fill_caps(set, version, (union virgl_caps *)caps); + vrend_renderer_fill_caps(set, version, (union virgl_caps *)caps); } int virgl_renderer_context_create(uint32_t handle, uint32_t nlen, const char *name) @@ -76,32 +76,32 @@ int virgl_renderer_submit_cmd(void *buffer, int ctx_id, int ndw) { - return vrend_decode_block(ctx_id, buffer, ndw); + return vrend_decode_block(ctx_id, buffer, ndw); } int virgl_renderer_transfer_write_iov(uint32_t handle, - uint32_t ctx_id, - int level, - uint32_t stride, - uint32_t layer_stride, - struct virgl_box *box, - uint64_t offset, - struct iovec *iovec, - unsigned int iovec_cnt) + uint32_t ctx_id, + int level, + uint32_t stride, + uint32_t layer_stride, + struct virgl_box *box, + uint64_t offset, + struct iovec *iovec, + unsigned int iovec_cnt) { - struct vrend_transfer_info transfer_info; - - transfer_info.handle = handle; - transfer_info.ctx_id = ctx_id; - transfer_info.level = level; - transfer_info.stride = stride; - transfer_info.layer_stride = layer_stride; - transfer_info.box = (struct pipe_box *)box; - transfer_info.offset = offset; - transfer_info.iovec = iovec; - transfer_info.iovec_cnt = iovec_cnt; - - return vrend_renderer_transfer_iov(&transfer_info, VREND_TRANSFER_WRITE); + struct vrend_transfer_info transfer_info; + + transfer_info.handle = handle; + transfer_info.ctx_id = ctx_id; + transfer_info.level = level; + transfer_info.stride = stride; + transfer_info.layer_stride = layer_stride; + transfer_info.box = (struct pipe_box *)box; + transfer_info.offset = offset; + transfer_info.iovec = iovec; + transfer_info.iovec_cnt = iovec_cnt; + + return vrend_renderer_transfer_iov(&transfer_info, VREND_TRANSFER_WRITE); } int virgl_renderer_transfer_read_iov(uint32_t handle, uint32_t ctx_id, @@ -111,23 +111,23 @@ int virgl_renderer_transfer_read_iov(uint32_t handle, uint32_t ctx_id, uint64_t offset, struct iovec *iovec, int iovec_cnt) { - struct vrend_transfer_info transfer_info; - - transfer_info.handle = handle; - transfer_info.ctx_id = ctx_id; - transfer_info.level = level; - transfer_info.stride = stride; - transfer_info.layer_stride = layer_stride; - transfer_info.box = (struct pipe_box *)box; - transfer_info.offset = offset; - transfer_info.iovec = iovec; - transfer_info.iovec_cnt = iovec_cnt; - - return vrend_renderer_transfer_iov(&transfer_info, VREND_TRANSFER_READ); + struct vrend_transfer_info transfer_info; + + transfer_info.handle = handle; + transfer_info.ctx_id = ctx_id; + transfer_info.level = level; + transfer_info.stride = stride; + transfer_info.layer_stride = layer_stride; + transfer_info.box = (struct pipe_box *)box; + transfer_info.offset = offset; + transfer_info.iovec = iovec; + transfer_info.iovec_cnt = iovec_cnt; + + return vrend_renderer_transfer_iov(&transfer_info, VREND_TRANSFER_READ); } int virgl_renderer_resource_attach_iov(int res_handle, struct iovec *iov, - int num_iovs) + int num_iovs) { return vrend_renderer_resource_attach_iov(res_handle, iov, num_iovs); } @@ -174,7 +174,7 @@ void virgl_renderer_get_cap_set(uint32_t cap_set, uint32_t *max_ver, } void virgl_renderer_get_rect(int resource_id, struct iovec *iov, unsigned int num_iovs, - uint32_t offset, int x, int y, int width, int height) + uint32_t offset, int x, int y, int width, int height) { vrend_renderer_get_rect(resource_id, iov, num_iovs, offset, x, y, width, height); } @@ -188,19 +188,19 @@ static int use_egl_context; static struct vrend_if_cbs virgl_cbs; void vrend_transfer_write_return(void *data, uint32_t bytes, uint64_t offset, - struct iovec *iov, int num_iovs) + struct iovec *iov, int num_iovs) { vrend_write_to_iovec(iov, num_iovs, offset, data, bytes); } void vrend_transfer_write_tex_return(struct pipe_resource *res, - struct pipe_box *box, - uint32_t level, - uint32_t dst_stride, - uint64_t offset, - struct iovec *iov, - int num_iovs, - void *myptr, int size, int invert) + struct pipe_box *box, + uint32_t level, + uint32_t dst_stride, + uint64_t offset, + struct iovec *iov, + int num_iovs, + void *myptr, int size, int invert) { int elsize = util_format_get_blocksize(res->format); int h; @@ -227,33 +227,33 @@ void vrend_transfer_write_tex_return(struct pipe_resource *res, static void virgl_write_fence(uint32_t fence_id) { - rcbs->write_fence(dev_cookie, fence_id); + rcbs->write_fence(dev_cookie, fence_id); } static virgl_renderer_gl_context create_gl_context(int scanout_idx, struct virgl_gl_ctx_param *param) { - struct virgl_renderer_gl_ctx_param vparam; - if (use_egl_context) - return virgl_egl_create_context(egl_info, param); - vparam.version = 1; - vparam.shared = param->shared; - vparam.major_ver = param->major_ver; - vparam.minor_ver = param->minor_ver; - return rcbs->create_gl_context(dev_cookie, scanout_idx, &vparam); + struct virgl_renderer_gl_ctx_param vparam; + if (use_egl_context) + return virgl_egl_create_context(egl_info, param); + vparam.version = 1; + vparam.shared = param->shared; + vparam.major_ver = param->major_ver; + vparam.minor_ver = param->minor_ver; + return rcbs->create_gl_context(dev_cookie, scanout_idx, &vparam); } static void destroy_gl_context(virgl_renderer_gl_context ctx) { - if (use_egl_context) - return virgl_egl_destroy_context(egl_info, ctx); - return rcbs->destroy_gl_context(dev_cookie, ctx); + if (use_egl_context) + return virgl_egl_destroy_context(egl_info, ctx); + return rcbs->destroy_gl_context(dev_cookie, ctx); } static int make_current(int scanout_idx, virgl_renderer_gl_context ctx) { - if (use_egl_context) - return virgl_egl_make_context_current(egl_info, ctx); - return rcbs->make_current(dev_cookie, scanout_idx, ctx); + if (use_egl_context) + return virgl_egl_make_context_current(egl_info, ctx); + return rcbs->make_current(dev_cookie, scanout_idx, ctx); } static struct vrend_if_cbs virgl_cbs = { @@ -288,7 +288,7 @@ void virgl_renderer_cleanup(void *cookie) int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks *cbs) { if (!cookie || !cbs) - return -1; + return -1; if (cbs->version != 1) return -1; @@ -297,10 +297,10 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks rcbs = cbs; if (flags & VIRGL_RENDERER_USE_EGL) { - egl_info = virgl_egl_init(); - if (!egl_info) - return -1; - use_egl_context = 1; + egl_info = virgl_egl_init(); + if (!egl_info) + return -1; + use_egl_context = 1; } vrend_renderer_init(&virgl_cbs); @@ -309,7 +309,7 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks int virgl_renderer_get_fd_for_texture(uint32_t tex_id, int *fd) { - return virgl_egl_get_fd_for_texture(egl_info, tex_id, fd); + return virgl_egl_get_fd_for_texture(egl_info, tex_id, fd); } void virgl_renderer_reset(void) diff --git a/src/virglrenderer.h b/src/virglrenderer.h index 376efb8..e3a4a2e 100644 --- a/src/virglrenderer.h +++ b/src/virglrenderer.h @@ -97,7 +97,7 @@ struct virgl_renderer_resource_create_args { }; /* new API */ - + VIRGL_EXPORT int virgl_renderer_resource_create(struct virgl_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs); VIRGL_EXPORT void virgl_renderer_resource_unref(uint32_t res_handle); @@ -109,11 +109,11 @@ VIRGL_EXPORT int virgl_renderer_submit_cmd(void *buffer, int ndw); VIRGL_EXPORT int virgl_renderer_transfer_read_iov(uint32_t handle, uint32_t ctx_id, - uint32_t level, uint32_t stride, - uint32_t layer_stride, - struct virgl_box *box, - uint64_t offset, struct iovec *iov, - int iovec_cnt); + uint32_t level, uint32_t stride, + uint32_t layer_stride, + struct virgl_box *box, + uint64_t offset, struct iovec *iov, + int iovec_cnt); VIRGL_EXPORT int virgl_renderer_transfer_write_iov(uint32_t handle, uint32_t ctx_id, @@ -132,7 +132,7 @@ VIRGL_EXPORT void virgl_renderer_fill_caps(uint32_t set, uint32_t version, void *caps); VIRGL_EXPORT int virgl_renderer_resource_attach_iov(int res_handle, struct iovec *iov, - int num_iovs); + int num_iovs); VIRGL_EXPORT void virgl_renderer_resource_detach_iov(int res_handle, struct iovec **iov, int *num_iovs); VIRGL_EXPORT int virgl_renderer_create_fence(int client_fence_id, uint32_t ctx_id); diff --git a/src/vrend_blitter.c b/src/vrend_blitter.c index c6a6f17..0ff73c6 100644 --- a/src/vrend_blitter.c +++ b/src/vrend_blitter.c @@ -50,261 +50,261 @@ #include "vrend_blitter.h" struct vrend_blitter_ctx { - virgl_gl_context gl_context; - bool initialised; - - GLuint vaoid; - - GLuint vs; - GLuint vs_pos_only; - GLuint fs_texfetch_col[PIPE_MAX_TEXTURE_TYPES]; - GLuint fs_texfetch_depth[PIPE_MAX_TEXTURE_TYPES]; - GLuint fs_texfetch_depth_msaa[PIPE_MAX_TEXTURE_TYPES]; - GLuint fb_id; - - unsigned dst_width; - unsigned dst_height; - - GLuint vbo_id; - GLfloat vertices[4][2][4]; /**< {pos, color} or {pos, texcoord} */ + virgl_gl_context gl_context; + bool initialised; + + GLuint vaoid; + + GLuint vs; + GLuint vs_pos_only; + GLuint fs_texfetch_col[PIPE_MAX_TEXTURE_TYPES]; + GLuint fs_texfetch_depth[PIPE_MAX_TEXTURE_TYPES]; + GLuint fs_texfetch_depth_msaa[PIPE_MAX_TEXTURE_TYPES]; + GLuint fb_id; + + unsigned dst_width; + unsigned dst_height; + + GLuint vbo_id; + GLfloat vertices[4][2][4]; /**< {pos, color} or {pos, texcoord} */ }; static struct vrend_blitter_ctx vrend_blit_ctx; static bool build_and_check(GLuint id, const char *buf) { - GLint param; - glShaderSource(id, 1, (const char **)&buf, NULL); - glCompileShader(id); - - glGetShaderiv(id, GL_COMPILE_STATUS, ¶m); - if (param == GL_FALSE) { - char infolog[65536]; - int len; - glGetShaderInfoLog(id, 65536, &len, infolog); - fprintf(stderr,"shader failed to compile\n%s\n", infolog); - fprintf(stderr,"GLSL:\n%s\n", buf); - return false; - } - return true; + GLint param; + glShaderSource(id, 1, (const char **)&buf, NULL); + glCompileShader(id); + + glGetShaderiv(id, GL_COMPILE_STATUS, ¶m); + if (param == GL_FALSE) { + char infolog[65536]; + int len; + glGetShaderInfoLog(id, 65536, &len, infolog); + fprintf(stderr,"shader failed to compile\n%s\n", infolog); + fprintf(stderr,"GLSL:\n%s\n", buf); + return false; + } + return true; } static bool blit_build_vs_passthrough(struct vrend_blitter_ctx *blit_ctx) { - blit_ctx->vs = glCreateShader(GL_VERTEX_SHADER); - - if (!build_and_check(blit_ctx->vs, vs_passthrough)) { - glDeleteShader(blit_ctx->vs); - blit_ctx->vs = 0; - return false; - } - return true; + blit_ctx->vs = glCreateShader(GL_VERTEX_SHADER); + + if (!build_and_check(blit_ctx->vs, vs_passthrough)) { + glDeleteShader(blit_ctx->vs); + blit_ctx->vs = 0; + return false; + } + return true; } static GLuint blit_build_frag_tex_col(struct vrend_blitter_ctx *blit_ctx, int tgsi_tex_target) { - GLuint fs_id; - char shader_buf[4096]; - int is_shad; - const char *twm; - char *ext_str = ""; - switch (tgsi_tex_target) { - case TGSI_TEXTURE_1D: - case TGSI_TEXTURE_BUFFER: - twm = ".x"; - break; - case TGSI_TEXTURE_1D_ARRAY: - case TGSI_TEXTURE_2D: - case TGSI_TEXTURE_RECT: - case TGSI_TEXTURE_2D_MSAA: - default: - twm = ".xy"; - break; - case TGSI_TEXTURE_SHADOW1D: - case TGSI_TEXTURE_SHADOW2D: - case TGSI_TEXTURE_SHADOW1D_ARRAY: - case TGSI_TEXTURE_SHADOWRECT: - case TGSI_TEXTURE_3D: - case TGSI_TEXTURE_CUBE: - case TGSI_TEXTURE_2D_ARRAY: - case TGSI_TEXTURE_2D_ARRAY_MSAA: - twm = ".xyz"; - break; - case TGSI_TEXTURE_SHADOWCUBE: - case TGSI_TEXTURE_SHADOW2D_ARRAY: - case TGSI_TEXTURE_SHADOWCUBE_ARRAY: - case TGSI_TEXTURE_CUBE_ARRAY: - twm = ""; - break; - } - - if (tgsi_tex_target == TGSI_TEXTURE_CUBE_ARRAY || - tgsi_tex_target == TGSI_TEXTURE_SHADOWCUBE_ARRAY) + GLuint fs_id; + char shader_buf[4096]; + int is_shad; + const char *twm; + char *ext_str = ""; + switch (tgsi_tex_target) { + case TGSI_TEXTURE_1D: + case TGSI_TEXTURE_BUFFER: + twm = ".x"; + break; + case TGSI_TEXTURE_1D_ARRAY: + case TGSI_TEXTURE_2D: + case TGSI_TEXTURE_RECT: + case TGSI_TEXTURE_2D_MSAA: + default: + twm = ".xy"; + break; + case TGSI_TEXTURE_SHADOW1D: + case TGSI_TEXTURE_SHADOW2D: + case TGSI_TEXTURE_SHADOW1D_ARRAY: + case TGSI_TEXTURE_SHADOWRECT: + case TGSI_TEXTURE_3D: + case TGSI_TEXTURE_CUBE: + case TGSI_TEXTURE_2D_ARRAY: + case TGSI_TEXTURE_2D_ARRAY_MSAA: + twm = ".xyz"; + break; + case TGSI_TEXTURE_SHADOWCUBE: + case TGSI_TEXTURE_SHADOW2D_ARRAY: + case TGSI_TEXTURE_SHADOWCUBE_ARRAY: + case TGSI_TEXTURE_CUBE_ARRAY: + twm = ""; + break; + } + + if (tgsi_tex_target == TGSI_TEXTURE_CUBE_ARRAY || + tgsi_tex_target == TGSI_TEXTURE_SHADOWCUBE_ARRAY) ext_str = "#extension GL_ARB_texture_cube_map_array : require\n"; - snprintf(shader_buf, 4096, fs_texfetch_col, ext_str, vrend_shader_samplertypeconv(tgsi_tex_target, &is_shad), twm, ""); + snprintf(shader_buf, 4096, fs_texfetch_col, ext_str, vrend_shader_samplertypeconv(tgsi_tex_target, &is_shad), twm, ""); - fs_id = glCreateShader(GL_FRAGMENT_SHADER); + fs_id = glCreateShader(GL_FRAGMENT_SHADER); - if (!build_and_check(fs_id, shader_buf)) { - glDeleteShader(fs_id); - return 0; - } + if (!build_and_check(fs_id, shader_buf)) { + glDeleteShader(fs_id); + return 0; + } - return fs_id; + return fs_id; } static GLuint blit_build_frag_tex_writedepth(struct vrend_blitter_ctx *blit_ctx, int tgsi_tex_target) { - GLuint fs_id; - char shader_buf[4096]; - int is_shad; - const char *twm; - - switch (tgsi_tex_target) { - case TGSI_TEXTURE_1D: - case TGSI_TEXTURE_BUFFER: - twm = ".x"; - break; - case TGSI_TEXTURE_1D_ARRAY: - case TGSI_TEXTURE_2D: - case TGSI_TEXTURE_RECT: - case TGSI_TEXTURE_2D_MSAA: - default: - twm = ".xy"; - break; - case TGSI_TEXTURE_SHADOW1D: - case TGSI_TEXTURE_SHADOW2D: - case TGSI_TEXTURE_SHADOW1D_ARRAY: - case TGSI_TEXTURE_SHADOWRECT: - case TGSI_TEXTURE_3D: - case TGSI_TEXTURE_CUBE: - case TGSI_TEXTURE_2D_ARRAY: - case TGSI_TEXTURE_2D_ARRAY_MSAA: - twm = ".xyz"; - break; - case TGSI_TEXTURE_SHADOWCUBE: - case TGSI_TEXTURE_SHADOW2D_ARRAY: - case TGSI_TEXTURE_SHADOWCUBE_ARRAY: - case TGSI_TEXTURE_CUBE_ARRAY: - twm = ""; - break; - } - - snprintf(shader_buf, 4096, fs_texfetch_ds, vrend_shader_samplertypeconv(tgsi_tex_target, &is_shad), twm); - - fs_id = glCreateShader(GL_FRAGMENT_SHADER); - - if (!build_and_check(fs_id, shader_buf)) { - glDeleteShader(fs_id); - return 0; - } - - return fs_id; + GLuint fs_id; + char shader_buf[4096]; + int is_shad; + const char *twm; + + switch (tgsi_tex_target) { + case TGSI_TEXTURE_1D: + case TGSI_TEXTURE_BUFFER: + twm = ".x"; + break; + case TGSI_TEXTURE_1D_ARRAY: + case TGSI_TEXTURE_2D: + case TGSI_TEXTURE_RECT: + case TGSI_TEXTURE_2D_MSAA: + default: + twm = ".xy"; + break; + case TGSI_TEXTURE_SHADOW1D: + case TGSI_TEXTURE_SHADOW2D: + case TGSI_TEXTURE_SHADOW1D_ARRAY: + case TGSI_TEXTURE_SHADOWRECT: + case TGSI_TEXTURE_3D: + case TGSI_TEXTURE_CUBE: + case TGSI_TEXTURE_2D_ARRAY: + case TGSI_TEXTURE_2D_ARRAY_MSAA: + twm = ".xyz"; + break; + case TGSI_TEXTURE_SHADOWCUBE: + case TGSI_TEXTURE_SHADOW2D_ARRAY: + case TGSI_TEXTURE_SHADOWCUBE_ARRAY: + case TGSI_TEXTURE_CUBE_ARRAY: + twm = ""; + break; + } + + snprintf(shader_buf, 4096, fs_texfetch_ds, vrend_shader_samplertypeconv(tgsi_tex_target, &is_shad), twm); + + fs_id = glCreateShader(GL_FRAGMENT_SHADER); + + if (!build_and_check(fs_id, shader_buf)) { + glDeleteShader(fs_id); + return 0; + } + + return fs_id; } static GLuint blit_build_frag_blit_msaa_depth(struct vrend_blitter_ctx *blit_ctx, int tgsi_tex_target) { - GLuint fs_id; - char shader_buf[4096]; - int is_shad; - const char *twm; - const char *ivec; - - switch (tgsi_tex_target) { - case TGSI_TEXTURE_2D_MSAA: - twm = ".xy"; - ivec = "ivec2"; - break; - case TGSI_TEXTURE_2D_ARRAY_MSAA: - twm = ".xyz"; - ivec = "ivec3"; - break; - default: - return 0; - } - - snprintf(shader_buf, 4096, fs_texfetch_ds_msaa, vrend_shader_samplertypeconv(tgsi_tex_target, &is_shad), ivec, twm); - - fs_id = glCreateShader(GL_FRAGMENT_SHADER); - - if (!build_and_check(fs_id, shader_buf)) { - glDeleteShader(fs_id); - return 0; - } - - return fs_id; + GLuint fs_id; + char shader_buf[4096]; + int is_shad; + const char *twm; + const char *ivec; + + switch (tgsi_tex_target) { + case TGSI_TEXTURE_2D_MSAA: + twm = ".xy"; + ivec = "ivec2"; + break; + case TGSI_TEXTURE_2D_ARRAY_MSAA: + twm = ".xyz"; + ivec = "ivec3"; + break; + default: + return 0; + } + + snprintf(shader_buf, 4096, fs_texfetch_ds_msaa, vrend_shader_samplertypeconv(tgsi_tex_target, &is_shad), ivec, twm); + + fs_id = glCreateShader(GL_FRAGMENT_SHADER); + + if (!build_and_check(fs_id, shader_buf)) { + glDeleteShader(fs_id); + return 0; + } + + return fs_id; } static GLuint blit_get_frag_tex_writedepth(struct vrend_blitter_ctx *blit_ctx, int pipe_tex_target, unsigned nr_samples) { - assert(pipe_tex_target < PIPE_MAX_TEXTURE_TYPES); + assert(pipe_tex_target < PIPE_MAX_TEXTURE_TYPES); - if (nr_samples > 1) { - GLuint *shader = &blit_ctx->fs_texfetch_depth_msaa[pipe_tex_target]; + if (nr_samples > 1) { + GLuint *shader = &blit_ctx->fs_texfetch_depth_msaa[pipe_tex_target]; - if (!*shader) { - unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(pipe_tex_target, nr_samples); + if (!*shader) { + unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(pipe_tex_target, nr_samples); - *shader = blit_build_frag_blit_msaa_depth(blit_ctx, tgsi_tex); - } - return *shader; + *shader = blit_build_frag_blit_msaa_depth(blit_ctx, tgsi_tex); + } + return *shader; - } else { - GLuint *shader = &blit_ctx->fs_texfetch_depth[pipe_tex_target]; + } else { + GLuint *shader = &blit_ctx->fs_texfetch_depth[pipe_tex_target]; - if (!*shader) { - unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(pipe_tex_target, 0); + if (!*shader) { + unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(pipe_tex_target, 0); - *shader = blit_build_frag_tex_writedepth(blit_ctx, tgsi_tex); - } - return *shader; - } + *shader = blit_build_frag_tex_writedepth(blit_ctx, tgsi_tex); + } + return *shader; + } } static GLuint blit_get_frag_tex_col(struct vrend_blitter_ctx *blit_ctx, int pipe_tex_target, unsigned nr_samples) { - assert(pipe_tex_target < PIPE_MAX_TEXTURE_TYPES); + assert(pipe_tex_target < PIPE_MAX_TEXTURE_TYPES); - if (nr_samples > 1) { - return 0; - } else { - GLuint *shader = &blit_ctx->fs_texfetch_col[pipe_tex_target]; + if (nr_samples > 1) { + return 0; + } else { + GLuint *shader = &blit_ctx->fs_texfetch_col[pipe_tex_target]; - if (!*shader) { - unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(pipe_tex_target, 0); + if (!*shader) { + unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(pipe_tex_target, 0); - *shader = blit_build_frag_tex_col(blit_ctx, tgsi_tex); - } - return *shader; - } + *shader = blit_build_frag_tex_col(blit_ctx, tgsi_tex); + } + return *shader; + } } static void vrend_renderer_init_blit_ctx(struct vrend_blitter_ctx *blit_ctx) { - struct virgl_gl_ctx_param ctx_params; - int i; - if (blit_ctx->initialised) { - vrend_clicbs->make_current(0, blit_ctx->gl_context); - return; - } - - ctx_params.shared = true; - ctx_params.major_ver = VREND_GL_VER_MAJOR; - ctx_params.minor_ver = VREND_GL_VER_MINOR; - blit_ctx->gl_context = vrend_clicbs->create_gl_context(0, &ctx_params); - - vrend_clicbs->make_current(0, blit_ctx->gl_context); - glGenVertexArrays(1, &blit_ctx->vaoid); - glGenFramebuffers(1, &blit_ctx->fb_id); - - glGenBuffers(1, &blit_ctx->vbo_id); - blit_build_vs_passthrough(blit_ctx); - - for (i = 0; i < 4; i++) - blit_ctx->vertices[i][0][3] = 1; /*v.w*/ - glBindVertexArray(blit_ctx->vaoid); - glBindBuffer(GL_ARRAY_BUFFER, blit_ctx->vbo_id); + struct virgl_gl_ctx_param ctx_params; + int i; + if (blit_ctx->initialised) { + vrend_clicbs->make_current(0, blit_ctx->gl_context); + return; + } + + ctx_params.shared = true; + ctx_params.major_ver = VREND_GL_VER_MAJOR; + ctx_params.minor_ver = VREND_GL_VER_MINOR; + blit_ctx->gl_context = vrend_clicbs->create_gl_context(0, &ctx_params); + + vrend_clicbs->make_current(0, blit_ctx->gl_context); + glGenVertexArrays(1, &blit_ctx->vaoid); + glGenFramebuffers(1, &blit_ctx->fb_id); + + glGenBuffers(1, &blit_ctx->vbo_id); + blit_build_vs_passthrough(blit_ctx); + + for (i = 0; i < 4; i++) + blit_ctx->vertices[i][0][3] = 1; /*v.w*/ + glBindVertexArray(blit_ctx->vaoid); + glBindBuffer(GL_ARRAY_BUFFER, blit_ctx->vbo_id); } static inline GLenum convert_mag_filter(unsigned int filter) @@ -317,33 +317,33 @@ static inline GLenum convert_mag_filter(unsigned int filter) static void blitter_set_dst_dim(struct vrend_blitter_ctx *blit_ctx, unsigned width, unsigned height) { - blit_ctx->dst_width = width; - blit_ctx->dst_height = height; + blit_ctx->dst_width = width; + blit_ctx->dst_height = height; } static void blitter_set_rectangle(struct vrend_blitter_ctx *blit_ctx, - int x1, int y1, int x2, int y2, - float depth) + int x1, int y1, int x2, int y2, + float depth) { - int i; + int i; - /* set vertex positions */ - blit_ctx->vertices[0][0][0] = (float)x1 / blit_ctx->dst_width * 2.0f - 1.0f; /*v0.x*/ - blit_ctx->vertices[0][0][1] = (float)y1 / blit_ctx->dst_height * 2.0f - 1.0f; /*v0.y*/ + /* set vertex positions */ + blit_ctx->vertices[0][0][0] = (float)x1 / blit_ctx->dst_width * 2.0f - 1.0f; /*v0.x*/ + blit_ctx->vertices[0][0][1] = (float)y1 / blit_ctx->dst_height * 2.0f - 1.0f; /*v0.y*/ - blit_ctx->vertices[1][0][0] = (float)x2 / blit_ctx->dst_width * 2.0f - 1.0f; /*v1.x*/ - blit_ctx->vertices[1][0][1] = (float)y1 / blit_ctx->dst_height * 2.0f - 1.0f; /*v1.y*/ + blit_ctx->vertices[1][0][0] = (float)x2 / blit_ctx->dst_width * 2.0f - 1.0f; /*v1.x*/ + blit_ctx->vertices[1][0][1] = (float)y1 / blit_ctx->dst_height * 2.0f - 1.0f; /*v1.y*/ - blit_ctx->vertices[2][0][0] = (float)x2 / blit_ctx->dst_width * 2.0f - 1.0f; /*v2.x*/ - blit_ctx->vertices[2][0][1] = (float)y2 / blit_ctx->dst_height * 2.0f - 1.0f; /*v2.y*/ + blit_ctx->vertices[2][0][0] = (float)x2 / blit_ctx->dst_width * 2.0f - 1.0f; /*v2.x*/ + blit_ctx->vertices[2][0][1] = (float)y2 / blit_ctx->dst_height * 2.0f - 1.0f; /*v2.y*/ - blit_ctx->vertices[3][0][0] = (float)x1 / blit_ctx->dst_width * 2.0f - 1.0f; /*v3.x*/ - blit_ctx->vertices[3][0][1] = (float)y2 / blit_ctx->dst_height * 2.0f - 1.0f; /*v3.y*/ + blit_ctx->vertices[3][0][0] = (float)x1 / blit_ctx->dst_width * 2.0f - 1.0f; /*v3.x*/ + blit_ctx->vertices[3][0][1] = (float)y2 / blit_ctx->dst_height * 2.0f - 1.0f; /*v3.y*/ - for (i = 0; i < 4; i++) - blit_ctx->vertices[i][0][2] = depth; /*z*/ + for (i = 0; i < 4; i++) + blit_ctx->vertices[i][0][2] = depth; /*z*/ - glViewport(0, 0, blit_ctx->dst_width, blit_ctx->dst_height); + glViewport(0, 0, blit_ctx->dst_width, blit_ctx->dst_height); } static void get_texcoords(struct vrend_resource *src_res, @@ -352,7 +352,7 @@ static void get_texcoords(struct vrend_resource *src_res, float out[4]) { bool normalized = src_res->base.target != PIPE_TEXTURE_RECT && - src_res->base.nr_samples <= 1; + src_res->base.nr_samples <= 1; if (normalized) { out[0] = x1 / (float)u_minify(src_res->base.width0, src_level); @@ -407,13 +407,13 @@ static void blitter_set_texcoords(struct vrend_blitter_ctx *blit_ctx, switch (src_res->base.target) { case PIPE_TEXTURE_3D: - { - float r = layer / (float)u_minify(src_res->base.depth0, - level); - for (i = 0; i < 4; i++) - blit_ctx->vertices[i][1][2] = r; /*r*/ - } - break; + { + float r = layer / (float)u_minify(src_res->base.depth0, + level); + for (i = 0; i < 4; i++) + blit_ctx->vertices[i][1][2] = r; /*r*/ + } + break; case PIPE_TEXTURE_1D_ARRAY: for (i = 0; i < 4; i++) @@ -431,140 +431,140 @@ static void blitter_set_texcoords(struct vrend_blitter_ctx *blit_ctx, blit_ctx->vertices[i][1][3] = (float) ((unsigned)layer / 6); /*w*/ break; case PIPE_TEXTURE_2D: - for (i = 0; i < 4; i++) { - blit_ctx->vertices[i][1][3] = (float) sample; /*r*/ - } - break; + for (i = 0; i < 4; i++) { + blit_ctx->vertices[i][1][3] = (float) sample; /*r*/ + } + break; default:; } } #if 0 static void set_dsa_keep_depth_stencil(void) { - glDisable(GL_STENCIL_TEST); - glDisable(GL_DEPTH_TEST); - glDepthMask(GL_FALSE); + glDisable(GL_STENCIL_TEST); + glDisable(GL_DEPTH_TEST); + glDepthMask(GL_FALSE); } #endif static void set_dsa_write_depth_keep_stencil(void) { - glDisable(GL_STENCIL_TEST); - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_ALWAYS); - glDepthMask(GL_TRUE); + glDisable(GL_STENCIL_TEST); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_ALWAYS); + glDepthMask(GL_TRUE); } - + /* implement blitting using OpenGL. */ void vrend_renderer_blit_gl(struct vrend_context *ctx, struct vrend_resource *src_res, struct vrend_resource *dst_res, const struct pipe_blit_info *info) { - struct vrend_blitter_ctx *blit_ctx = &vrend_blit_ctx; - GLuint prog_id; - GLuint fs_id; - GLint lret; - GLenum filter; - GLuint pos_loc, tc_loc; - GLuint samp_loc; - bool has_depth, has_stencil; - bool blit_stencil, blit_depth; - int dst_z; - const struct util_format_description *src_desc = - util_format_description(src_res->base.format); - const struct util_format_description *dst_desc = - util_format_description(dst_res->base.format); - - has_depth = util_format_has_depth(src_desc) && - util_format_has_depth(dst_desc); - has_stencil = util_format_has_stencil(src_desc) && - util_format_has_stencil(dst_desc); - - blit_depth = has_depth && (info->mask & PIPE_MASK_Z); - blit_stencil = has_stencil && (info->mask & PIPE_MASK_S) & 0; - - filter = convert_mag_filter(info->filter); - vrend_renderer_init_blit_ctx(blit_ctx); - - blitter_set_dst_dim(blit_ctx, - u_minify(dst_res->base.width0, info->dst.level), - u_minify(dst_res->base.height0, info->dst.level)); - - blitter_set_rectangle(blit_ctx, info->dst.box.x, info->dst.box.y, - info->dst.box.x + info->dst.box.width, - info->dst.box.y + info->dst.box.height, 0); - - - prog_id = glCreateProgram(); - glAttachShader(prog_id, blit_ctx->vs); - - if (blit_depth || blit_stencil) - fs_id = blit_get_frag_tex_writedepth(blit_ctx, src_res->base.target, src_res->base.nr_samples); - else - fs_id = blit_get_frag_tex_col(blit_ctx, src_res->base.target, src_res->base.nr_samples); - glAttachShader(prog_id, fs_id); - - glLinkProgram(prog_id); - glGetProgramiv(prog_id, GL_LINK_STATUS, &lret); - if (lret == GL_FALSE) { - char infolog[65536]; - int len; - glGetProgramInfoLog(prog_id, 65536, &len, infolog); - fprintf(stderr,"got error linking\n%s\n", infolog); - /* dump shaders */ - glDeleteProgram(prog_id); - return; - } - - glUseProgram(prog_id); - - glBindFramebuffer(GL_FRAMEBUFFER_EXT, blit_ctx->fb_id); - vrend_fb_bind_texture(dst_res, 0, info->dst.level, info->dst.box.z); - - glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); - - glBindTexture(src_res->target, src_res->id); - - glTexParameteri(src_res->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(src_res->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(src_res->target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); - - glTexParameteri(src_res->target, GL_TEXTURE_BASE_LEVEL, info->src.level); - glTexParameteri(src_res->target, GL_TEXTURE_MAX_LEVEL, info->src.level); - glTexParameterf(src_res->target, GL_TEXTURE_MAG_FILTER, filter); - glTexParameterf(src_res->target, GL_TEXTURE_MIN_FILTER, filter); - pos_loc = glGetAttribLocation(prog_id, "arg0"); - tc_loc = glGetAttribLocation(prog_id, "arg1"); - samp_loc = glGetUniformLocation(prog_id, "samp"); - - glUniform1i(samp_loc, 0); - - glVertexAttribPointer(pos_loc, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void *)0); - glVertexAttribPointer(tc_loc, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void *)(4 * sizeof(float))); - - glEnableVertexAttribArray(pos_loc); - glEnableVertexAttribArray(tc_loc); - - set_dsa_write_depth_keep_stencil(); - - for (dst_z = 0; dst_z < info->dst.box.depth; dst_z++) { - float dst2src_scale = info->src.box.depth / (float)info->dst.box.depth; - float dst_offset = ((info->src.box.depth - 1) - - (info->dst.box.depth - 1) * dst2src_scale) * 0.5; - float src_z = (dst_z + dst_offset) * dst2src_scale; - - glBindFramebuffer(GL_FRAMEBUFFER_EXT, blit_ctx->fb_id); - vrend_fb_bind_texture(dst_res, 0, info->dst.level, dst_z); - - glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); - blitter_set_texcoords(blit_ctx, src_res, info->src.level, - info->src.box.z + src_z, 0, - info->src.box.x, info->src.box.y, - info->src.box.x + info->src.box.width, - info->src.box.y + info->src.box.height); - - glBufferData(GL_ARRAY_BUFFER, sizeof(blit_ctx->vertices), blit_ctx->vertices, GL_STATIC_DRAW); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - } + struct vrend_blitter_ctx *blit_ctx = &vrend_blit_ctx; + GLuint prog_id; + GLuint fs_id; + GLint lret; + GLenum filter; + GLuint pos_loc, tc_loc; + GLuint samp_loc; + bool has_depth, has_stencil; + bool blit_stencil, blit_depth; + int dst_z; + const struct util_format_description *src_desc = + util_format_description(src_res->base.format); + const struct util_format_description *dst_desc = + util_format_description(dst_res->base.format); + + has_depth = util_format_has_depth(src_desc) && + util_format_has_depth(dst_desc); + has_stencil = util_format_has_stencil(src_desc) && + util_format_has_stencil(dst_desc); + + blit_depth = has_depth && (info->mask & PIPE_MASK_Z); + blit_stencil = has_stencil && (info->mask & PIPE_MASK_S) & 0; + + filter = convert_mag_filter(info->filter); + vrend_renderer_init_blit_ctx(blit_ctx); + + blitter_set_dst_dim(blit_ctx, + u_minify(dst_res->base.width0, info->dst.level), + u_minify(dst_res->base.height0, info->dst.level)); + + blitter_set_rectangle(blit_ctx, info->dst.box.x, info->dst.box.y, + info->dst.box.x + info->dst.box.width, + info->dst.box.y + info->dst.box.height, 0); + + + prog_id = glCreateProgram(); + glAttachShader(prog_id, blit_ctx->vs); + + if (blit_depth || blit_stencil) + fs_id = blit_get_frag_tex_writedepth(blit_ctx, src_res->base.target, src_res->base.nr_samples); + else + fs_id = blit_get_frag_tex_col(blit_ctx, src_res->base.target, src_res->base.nr_samples); + glAttachShader(prog_id, fs_id); + + glLinkProgram(prog_id); + glGetProgramiv(prog_id, GL_LINK_STATUS, &lret); + if (lret == GL_FALSE) { + char infolog[65536]; + int len; + glGetProgramInfoLog(prog_id, 65536, &len, infolog); + fprintf(stderr,"got error linking\n%s\n", infolog); + /* dump shaders */ + glDeleteProgram(prog_id); + return; + } + + glUseProgram(prog_id); + + glBindFramebuffer(GL_FRAMEBUFFER_EXT, blit_ctx->fb_id); + vrend_fb_bind_texture(dst_res, 0, info->dst.level, info->dst.box.z); + + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + + glBindTexture(src_res->target, src_res->id); + + glTexParameteri(src_res->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(src_res->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(src_res->target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); + + glTexParameteri(src_res->target, GL_TEXTURE_BASE_LEVEL, info->src.level); + glTexParameteri(src_res->target, GL_TEXTURE_MAX_LEVEL, info->src.level); + glTexParameterf(src_res->target, GL_TEXTURE_MAG_FILTER, filter); + glTexParameterf(src_res->target, GL_TEXTURE_MIN_FILTER, filter); + pos_loc = glGetAttribLocation(prog_id, "arg0"); + tc_loc = glGetAttribLocation(prog_id, "arg1"); + samp_loc = glGetUniformLocation(prog_id, "samp"); + + glUniform1i(samp_loc, 0); + + glVertexAttribPointer(pos_loc, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void *)0); + glVertexAttribPointer(tc_loc, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void *)(4 * sizeof(float))); + + glEnableVertexAttribArray(pos_loc); + glEnableVertexAttribArray(tc_loc); + + set_dsa_write_depth_keep_stencil(); + + for (dst_z = 0; dst_z < info->dst.box.depth; dst_z++) { + float dst2src_scale = info->src.box.depth / (float)info->dst.box.depth; + float dst_offset = ((info->src.box.depth - 1) - + (info->dst.box.depth - 1) * dst2src_scale) * 0.5; + float src_z = (dst_z + dst_offset) * dst2src_scale; + + glBindFramebuffer(GL_FRAMEBUFFER_EXT, blit_ctx->fb_id); + vrend_fb_bind_texture(dst_res, 0, info->dst.level, dst_z); + + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + blitter_set_texcoords(blit_ctx, src_res, info->src.level, + info->src.box.z + src_z, 0, + info->src.box.x, info->src.box.y, + info->src.box.x + info->src.box.width, + info->src.box.y + info->src.box.height); + + glBufferData(GL_ARRAY_BUFFER, sizeof(blit_ctx->vertices), blit_ctx->vertices, GL_STATIC_DRAW); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + } } diff --git a/src/vrend_blitter.h b/src/vrend_blitter.h index 54acb46..46f62b2 100644 --- a/src/vrend_blitter.h +++ b/src/vrend_blitter.h @@ -1,5 +1,28 @@ -#ifndef VREND_BLITTER -#define VREND_BLITTER +/************************************************************************** + * + * Copyright (C) 2014 Red Hat Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +#ifndef VREND_BLITTER_H +#define VREND_BLITTER_H /* shaders for blitting */ diff --git a/src/vrend_decode.c b/src/vrend_decode.c index 7ba2bf7..f57fdd8 100644 --- a/src/vrend_decode.c +++ b/src/vrend_decode.c @@ -62,8 +62,8 @@ static inline void *get_buf_ptr(struct vrend_decode_ctx *ctx, } static int vrend_decode_create_shader(struct vrend_decode_ctx *ctx, uint32_t type, - uint32_t handle, - uint16_t length) + uint32_t handle, + uint16_t length) { struct pipe_shader_state *state; struct tgsi_token *tokens; @@ -96,12 +96,12 @@ static int vrend_decode_create_shader(struct vrend_decode_ctx *ctx, uint32_t typ state->stream_output.stride[i] = get_buf_entry(ctx, VIRGL_OBJ_SHADER_SO_STRIDE(i)); for (i = 0; i < state->stream_output.num_outputs; i++) { uint32_t tmp = get_buf_entry(ctx, VIRGL_OBJ_SHADER_SO_OUTPUT0(i)); - + state->stream_output.output[i].register_index = tmp & 0xff; state->stream_output.output[i].start_component = (tmp >> 8) & 0x3; state->stream_output.output[i].num_components = (tmp >> 10) & 0x7; state->stream_output.output[i].output_buffer = (tmp >> 13) & 0x7; - state->stream_output.output[i].dst_offset = (tmp >> 16) & 0xffff; + state->stream_output.output[i].dst_offset = (tmp >> 16) & 0xffff; } shader_offset = 8 + state->stream_output.num_outputs; } else @@ -207,7 +207,7 @@ static int vrend_decode_set_viewport_state(struct vrend_decode_ctx *ctx, int len for (i = 0; i < 3; i++) vps[v].translate[i] = uif(get_buf_entry(ctx, VIRGL_SET_VIEWPORT_STATE_TRANSLATE_0(v) + i)); } - + vrend_set_viewport_states(ctx->grctx, start_slot, num_viewports, vps); return 0; } @@ -263,8 +263,8 @@ static int vrend_decode_set_vertex_buffers(struct vrend_decode_ctx *ctx, uint16_ num_vbo = (length / 3); if (num_vbo > PIPE_MAX_ATTRIBS) - return EINVAL; - + 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)), @@ -307,7 +307,7 @@ static int vrend_decode_resource_inline_write(struct vrend_decode_ctx *ctx, uint return EINVAL; if (length + ctx->ds->buf_offset > ctx->ds->buf_total) - return EINVAL; + return EINVAL; res_handle = get_buf_entry(ctx, VIRGL_RESOURCE_IW_RES_HANDLE); data_len = (length - 11) * 4; @@ -423,7 +423,7 @@ static int vrend_decode_create_dsa(struct vrend_decode_ctx *ctx, uint32_t handle 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; @@ -510,9 +510,9 @@ static int vrend_decode_create_rasterizer(struct vrend_decode_ctx *ctx, uint32_t 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); + VIRGL_OBJECT_RASTERIZER); if (tmp == 0) { FREE(rs_state); return ENOMEM; @@ -527,7 +527,7 @@ static int vrend_decode_create_surface(struct vrend_decode_ctx *ctx, uint32_t ha 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 */ @@ -543,7 +543,7 @@ static int vrend_decode_create_sampler_view(struct vrend_decode_ctx *ctx, uint32 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); @@ -595,17 +595,17 @@ static int vrend_decode_create_ve(struct vrend_decode_ctx *ctx, uint32_t handle, num_elements = (length - 1) / 4; if (num_elements) { - ve = calloc(num_elements, sizeof(struct pipe_vertex_element)); + ve = calloc(num_elements, sizeof(struct pipe_vertex_element)); - if (!ve) - return ENOMEM; + 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)); - ve[i].src_format = get_buf_entry(ctx, VIRGL_OBJ_VERTEX_ELEMENTS_V0_SRC_FORMAT(i)); - } + 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)); + 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); @@ -622,7 +622,7 @@ static int vrend_decode_create_query(struct vrend_decode_ctx *ctx, uint32_t hand if (length != VIRGL_OBJ_QUERY_SIZE) return EINVAL; - + query_type = get_buf_entry(ctx, VIRGL_OBJ_QUERY_TYPE); offset = get_buf_entry(ctx, VIRGL_OBJ_QUERY_OFFSET); res_handle = get_buf_entry(ctx, VIRGL_OBJ_QUERY_RES_HANDLE); @@ -638,7 +638,7 @@ static int vrend_decode_create_object(struct vrend_decode_ctx *ctx, int length) int ret = 0; if (length < 1) - return EINVAL; + return EINVAL; switch (obj_type){ case VIRGL_OBJECT_BLEND: @@ -736,7 +736,7 @@ static int vrend_decode_set_stencil_ref(struct vrend_decode_ctx *ctx, int length if (length != VIRGL_SET_STENCIL_REF_SIZE) return EINVAL; - + ref.ref_value[0] = val & 0xff; ref.ref_value[1] = (val >> 8) & 0xff; vrend_set_stencil_ref(ctx->grctx, &ref); @@ -750,7 +750,7 @@ static int vrend_decode_set_blend_color(struct vrend_decode_ctx *ctx, int length 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))); @@ -840,7 +840,7 @@ static int vrend_decode_resource_copy_region(struct vrend_decode_ctx *ctx, int l 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); @@ -856,9 +856,9 @@ static int vrend_decode_resource_copy_region(struct vrend_decode_ctx *ctx, int l 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); + dst_level, dstx, dsty, dstz, + src_handle, src_level, + &box); return 0; } @@ -1011,17 +1011,17 @@ static int vrend_decode_set_streamout_targets(struct vrend_decode_ctx *ctx, } void vrend_renderer_context_create_internal(uint32_t handle, uint32_t nlen, - const char *debug_name) + const char *debug_name) { struct vrend_decode_ctx *dctx; if (handle > VREND_MAX_CTX) return; - + dctx = malloc(sizeof(struct vrend_decode_ctx)); if (!dctx) - return; - + return; + dctx->grctx = vrend_create_context(handle, nlen, debug_name); if (!dctx->grctx) { free(dctx); @@ -1055,13 +1055,13 @@ void vrend_renderer_context_destroy(uint32_t handle) ctx = dec_ctx[handle]; if (!ctx) - return; + return; dec_ctx[handle] = NULL; ret = vrend_destroy_context(ctx->grctx); free(ctx); /* switch to ctx 0 */ if (ret && handle != 0) - vrend_hw_switch_context(dec_ctx[0]->grctx, true); + vrend_hw_switch_context(dec_ctx[0]->grctx, true); } struct vrend_context *vrend_lookup_renderer_ctx(uint32_t ctx_id) @@ -1107,7 +1107,7 @@ int vrend_decode_block(uint32_t ctx_id, uint32_t *block, int ndw) break; } // fprintf(stderr,"[%d] cmd is %d (obj %d) len %d\n", gdctx->ds->buf_offset, header & 0xff, (header >> 8 & 0xff), (len)); - + switch (header & 0xff) { case VIRGL_CCMD_CREATE_OBJECT: ret = vrend_decode_create_object(gdctx, len); @@ -1206,11 +1206,11 @@ int vrend_decode_block(uint32_t ctx_id, uint32_t *block, int ndw) goto out; } if (ret == ENOMEM) - goto out; + goto out; gdctx->ds->buf_offset += (len) + 1; } return 0; -out: + out: return ret; } @@ -1221,20 +1221,20 @@ void vrend_decode_reset(bool ctx_0_only) 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; + for (i = 1; i < VREND_MAX_CTX; i++) { + if (!dec_ctx[i]) + continue; - if (!dec_ctx[i]->grctx) - continue; + if (!dec_ctx[i]->grctx) + continue; - vrend_destroy_context(dec_ctx[i]->grctx); - free(dec_ctx[i]); - dec_ctx[i] = NULL; - } + 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; + vrend_destroy_context(dec_ctx[0]->grctx); + free(dec_ctx[0]); + dec_ctx[0] = NULL; } } diff --git a/src/vrend_formats.c b/src/vrend_formats.c index 7985471..fc2bf8d 100644 --- a/src/vrend_formats.c +++ b/src/vrend_formats.c @@ -28,331 +28,331 @@ #include "util/u_format.h" /* fill the format table */ static struct vrend_format_table base_rgba_formats[] = -{ - { VIRGL_FORMAT_B8G8R8X8_UNORM, GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE, 0 }, - { VIRGL_FORMAT_B8G8R8A8_UNORM, GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE, 0 }, + { + { VIRGL_FORMAT_B8G8R8X8_UNORM, GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE, 0 }, + { VIRGL_FORMAT_B8G8R8A8_UNORM, GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE, 0 }, - { VIRGL_FORMAT_R8G8B8X8_UNORM, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, 0 }, - { VIRGL_FORMAT_R8G8B8A8_UNORM, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, 0 }, + { VIRGL_FORMAT_R8G8B8X8_UNORM, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, 0 }, + { VIRGL_FORMAT_R8G8B8A8_UNORM, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, 0 }, - { VIRGL_FORMAT_A8R8G8B8_UNORM, GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, 0 }, - { VIRGL_FORMAT_X8R8G8B8_UNORM, GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, 0 }, + { VIRGL_FORMAT_A8R8G8B8_UNORM, GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, 0 }, + { VIRGL_FORMAT_X8R8G8B8_UNORM, GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, 0 }, - { VIRGL_FORMAT_A8B8G8R8_UNORM, GL_RGBA8, GL_ABGR_EXT, GL_UNSIGNED_BYTE, 0}, + { VIRGL_FORMAT_A8B8G8R8_UNORM, GL_RGBA8, GL_ABGR_EXT, GL_UNSIGNED_BYTE, 0}, - { VIRGL_FORMAT_B4G4R4A4_UNORM, GL_RGBA4, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV }, - { VIRGL_FORMAT_B4G4R4X4_UNORM, GL_RGBA4, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV }, - { VIRGL_FORMAT_B5G5R5X1_UNORM, GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV }, - { VIRGL_FORMAT_B5G5R5A1_UNORM, GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV }, + { VIRGL_FORMAT_B4G4R4A4_UNORM, GL_RGBA4, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV }, + { VIRGL_FORMAT_B4G4R4X4_UNORM, GL_RGBA4, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV }, + { VIRGL_FORMAT_B5G5R5X1_UNORM, GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV }, + { VIRGL_FORMAT_B5G5R5A1_UNORM, GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV }, - { VIRGL_FORMAT_B5G6R5_UNORM, GL_RGB4, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 }, - { VIRGL_FORMAT_B2G3R3_UNORM, GL_R3_G3_B2, GL_RGB, GL_UNSIGNED_BYTE_3_3_2 }, + { VIRGL_FORMAT_B5G6R5_UNORM, GL_RGB4, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 }, + { VIRGL_FORMAT_B2G3R3_UNORM, GL_R3_G3_B2, GL_RGB, GL_UNSIGNED_BYTE_3_3_2 }, - { VIRGL_FORMAT_R16G16B16X16_UNORM, GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT }, + { VIRGL_FORMAT_R16G16B16X16_UNORM, GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT }, - { VIRGL_FORMAT_R16G16B16A16_UNORM, GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT }, -}; + { VIRGL_FORMAT_R16G16B16A16_UNORM, GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT }, + }; static struct vrend_format_table base_depth_formats[] = -{ - { VIRGL_FORMAT_Z16_UNORM, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0 }, - { VIRGL_FORMAT_Z32_UNORM, GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0 }, - { VIRGL_FORMAT_S8_UINT_Z24_UNORM, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0 }, - { VIRGL_FORMAT_Z24X8_UNORM, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT }, - { VIRGL_FORMAT_Z32_FLOAT, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT }, - /* this is probably a separate format */ - { VIRGL_FORMAT_Z32_FLOAT_S8X24_UINT, GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV}, -}; + { + { VIRGL_FORMAT_Z16_UNORM, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0 }, + { VIRGL_FORMAT_Z32_UNORM, GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0 }, + { VIRGL_FORMAT_S8_UINT_Z24_UNORM, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0 }, + { VIRGL_FORMAT_Z24X8_UNORM, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT }, + { VIRGL_FORMAT_Z32_FLOAT, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT }, + /* this is probably a separate format */ + { VIRGL_FORMAT_Z32_FLOAT_S8X24_UINT, GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV}, + }; static struct vrend_format_table base_la_formats[] = { - { VIRGL_FORMAT_A8_UNORM, GL_ALPHA8, GL_ALPHA, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_L8_UNORM, GL_LUMINANCE8, GL_LUMINANCE, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_L8A8_UNORM, GL_LUMINANCE8_ALPHA8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_A16_UNORM, GL_ALPHA16, GL_ALPHA, GL_UNSIGNED_SHORT }, - { VIRGL_FORMAT_L16_UNORM, GL_LUMINANCE16, GL_LUMINANCE, GL_UNSIGNED_SHORT }, - { VIRGL_FORMAT_L16A16_UNORM, GL_LUMINANCE16_ALPHA16, GL_LUMINANCE_ALPHA, GL_UNSIGNED_SHORT }, + { VIRGL_FORMAT_A8_UNORM, GL_ALPHA8, GL_ALPHA, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_L8_UNORM, GL_LUMINANCE8, GL_LUMINANCE, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_L8A8_UNORM, GL_LUMINANCE8_ALPHA8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_A16_UNORM, GL_ALPHA16, GL_ALPHA, GL_UNSIGNED_SHORT }, + { VIRGL_FORMAT_L16_UNORM, GL_LUMINANCE16, GL_LUMINANCE, GL_UNSIGNED_SHORT }, + { VIRGL_FORMAT_L16A16_UNORM, GL_LUMINANCE16_ALPHA16, GL_LUMINANCE_ALPHA, GL_UNSIGNED_SHORT }, }; static struct vrend_format_table rg_base_formats[] = { - { VIRGL_FORMAT_R8_UNORM, GL_R8, GL_RED, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_R8G8_UNORM, GL_RG8, GL_RG, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_R16_UNORM, GL_R16, GL_RED, GL_UNSIGNED_SHORT }, - { VIRGL_FORMAT_R16G16_UNORM, GL_RG16, GL_RG, GL_UNSIGNED_SHORT }, + { VIRGL_FORMAT_R8_UNORM, GL_R8, GL_RED, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_R8G8_UNORM, GL_RG8, GL_RG, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_R16_UNORM, GL_R16, GL_RED, GL_UNSIGNED_SHORT }, + { VIRGL_FORMAT_R16G16_UNORM, GL_RG16, GL_RG, GL_UNSIGNED_SHORT }, }; - + static struct vrend_format_table integer_base_formats[] = { - { VIRGL_FORMAT_R8G8B8A8_UINT, GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_R8G8B8A8_SINT, GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE }, + { VIRGL_FORMAT_R8G8B8A8_UINT, GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_R8G8B8A8_SINT, GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE }, - { VIRGL_FORMAT_R16G16B16A16_UINT, GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT }, - { VIRGL_FORMAT_R16G16B16A16_SINT, GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT }, + { VIRGL_FORMAT_R16G16B16A16_UINT, GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT }, + { VIRGL_FORMAT_R16G16B16A16_SINT, GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT }, - { VIRGL_FORMAT_R32G32B32A32_UINT, GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT }, - { VIRGL_FORMAT_R32G32B32A32_SINT, GL_RGBA32I, GL_RGBA_INTEGER, GL_INT }, + { VIRGL_FORMAT_R32G32B32A32_UINT, GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT }, + { VIRGL_FORMAT_R32G32B32A32_SINT, GL_RGBA32I, GL_RGBA_INTEGER, GL_INT }, }; static struct vrend_format_table integer_3comp_formats[] = { - { VIRGL_FORMAT_R8G8B8_UINT, GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_R8G8B8_SINT, GL_RGB8I, GL_RGB_INTEGER, GL_BYTE }, - { VIRGL_FORMAT_R16G16B16_UINT, GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT }, - { VIRGL_FORMAT_R16G16B16_SINT, GL_RGB16I, GL_RGB_INTEGER, GL_SHORT }, - { VIRGL_FORMAT_R32G32B32_UINT, GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT }, - { VIRGL_FORMAT_R32G32B32_SINT, GL_RGB32I, GL_RGB_INTEGER, GL_INT }, + { VIRGL_FORMAT_R8G8B8_UINT, GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_R8G8B8_SINT, GL_RGB8I, GL_RGB_INTEGER, GL_BYTE }, + { VIRGL_FORMAT_R16G16B16_UINT, GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT }, + { VIRGL_FORMAT_R16G16B16_SINT, GL_RGB16I, GL_RGB_INTEGER, GL_SHORT }, + { VIRGL_FORMAT_R32G32B32_UINT, GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT }, + { VIRGL_FORMAT_R32G32B32_SINT, GL_RGB32I, GL_RGB_INTEGER, GL_INT }, }; static struct vrend_format_table float_base_formats[] = { - { VIRGL_FORMAT_R16G16B16A16_FLOAT, GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT }, - { VIRGL_FORMAT_R32G32B32A32_FLOAT, GL_RGBA32F, GL_RGBA, GL_FLOAT }, + { VIRGL_FORMAT_R16G16B16A16_FLOAT, GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT }, + { VIRGL_FORMAT_R32G32B32A32_FLOAT, GL_RGBA32F, GL_RGBA, GL_FLOAT }, }; static struct vrend_format_table float_la_formats[] = { - { VIRGL_FORMAT_A16_FLOAT, GL_ALPHA16F_ARB, GL_ALPHA, GL_HALF_FLOAT }, - { VIRGL_FORMAT_L16_FLOAT, GL_LUMINANCE16F_ARB, GL_LUMINANCE, GL_HALF_FLOAT }, - { VIRGL_FORMAT_L16A16_FLOAT, GL_LUMINANCE_ALPHA16F_ARB, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT }, + { VIRGL_FORMAT_A16_FLOAT, GL_ALPHA16F_ARB, GL_ALPHA, GL_HALF_FLOAT }, + { VIRGL_FORMAT_L16_FLOAT, GL_LUMINANCE16F_ARB, GL_LUMINANCE, GL_HALF_FLOAT }, + { VIRGL_FORMAT_L16A16_FLOAT, GL_LUMINANCE_ALPHA16F_ARB, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT }, - { VIRGL_FORMAT_A32_FLOAT, GL_ALPHA32F_ARB, GL_ALPHA, GL_FLOAT }, - { VIRGL_FORMAT_L32_FLOAT, GL_LUMINANCE32F_ARB, GL_LUMINANCE, GL_FLOAT }, - { VIRGL_FORMAT_L32A32_FLOAT, GL_LUMINANCE_ALPHA32F_ARB, GL_LUMINANCE_ALPHA, GL_FLOAT }, + { VIRGL_FORMAT_A32_FLOAT, GL_ALPHA32F_ARB, GL_ALPHA, GL_FLOAT }, + { VIRGL_FORMAT_L32_FLOAT, GL_LUMINANCE32F_ARB, GL_LUMINANCE, GL_FLOAT }, + { VIRGL_FORMAT_L32A32_FLOAT, GL_LUMINANCE_ALPHA32F_ARB, GL_LUMINANCE_ALPHA, GL_FLOAT }, }; static struct vrend_format_table integer_rg_formats[] = { - { VIRGL_FORMAT_R8_UINT, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_R8G8_UINT, GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_R8_SINT, GL_R8I, GL_RED_INTEGER, GL_BYTE }, - { VIRGL_FORMAT_R8G8_SINT, GL_RG8I, GL_RG_INTEGER, GL_BYTE }, - - { VIRGL_FORMAT_R16_UINT, GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT }, - { VIRGL_FORMAT_R16G16_UINT, GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT }, - { VIRGL_FORMAT_R16_SINT, GL_R16I, GL_RED_INTEGER, GL_SHORT }, - { VIRGL_FORMAT_R16G16_SINT, GL_RG16I, GL_RG_INTEGER, GL_SHORT }, - - { VIRGL_FORMAT_R32_UINT, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT }, - { VIRGL_FORMAT_R32G32_UINT, GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT }, - { VIRGL_FORMAT_R32_SINT, GL_R32I, GL_RED_INTEGER, GL_INT }, - { VIRGL_FORMAT_R32G32_SINT, GL_RG32I, GL_RG_INTEGER, GL_INT }, + { VIRGL_FORMAT_R8_UINT, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_R8G8_UINT, GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_R8_SINT, GL_R8I, GL_RED_INTEGER, GL_BYTE }, + { VIRGL_FORMAT_R8G8_SINT, GL_RG8I, GL_RG_INTEGER, GL_BYTE }, + + { VIRGL_FORMAT_R16_UINT, GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT }, + { VIRGL_FORMAT_R16G16_UINT, GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT }, + { VIRGL_FORMAT_R16_SINT, GL_R16I, GL_RED_INTEGER, GL_SHORT }, + { VIRGL_FORMAT_R16G16_SINT, GL_RG16I, GL_RG_INTEGER, GL_SHORT }, + + { VIRGL_FORMAT_R32_UINT, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT }, + { VIRGL_FORMAT_R32G32_UINT, GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT }, + { VIRGL_FORMAT_R32_SINT, GL_R32I, GL_RED_INTEGER, GL_INT }, + { VIRGL_FORMAT_R32G32_SINT, GL_RG32I, GL_RG_INTEGER, GL_INT }, }; static struct vrend_format_table float_rg_formats[] = { - { VIRGL_FORMAT_R16_FLOAT, GL_R16F, GL_RED, GL_HALF_FLOAT }, - { VIRGL_FORMAT_R16G16_FLOAT, GL_RG16F, GL_RG, GL_HALF_FLOAT }, - { VIRGL_FORMAT_R32_FLOAT, GL_R32F, GL_RED, GL_FLOAT }, - { VIRGL_FORMAT_R32G32_FLOAT, GL_RG32F, GL_RG, GL_FLOAT }, + { VIRGL_FORMAT_R16_FLOAT, GL_R16F, GL_RED, GL_HALF_FLOAT }, + { VIRGL_FORMAT_R16G16_FLOAT, GL_RG16F, GL_RG, GL_HALF_FLOAT }, + { VIRGL_FORMAT_R32_FLOAT, GL_R32F, GL_RED, GL_FLOAT }, + { VIRGL_FORMAT_R32G32_FLOAT, GL_RG32F, GL_RG, GL_FLOAT }, }; static struct vrend_format_table float_3comp_formats[] = { - { VIRGL_FORMAT_R16G16B16_FLOAT, GL_RGB16F, GL_RGB, GL_HALF_FLOAT }, - { VIRGL_FORMAT_R32G32B32_FLOAT, GL_RGB32F, GL_RGB, GL_FLOAT }, + { VIRGL_FORMAT_R16G16B16_FLOAT, GL_RGB16F, GL_RGB, GL_HALF_FLOAT }, + { VIRGL_FORMAT_R32G32B32_FLOAT, GL_RGB32F, GL_RGB, GL_FLOAT }, }; static struct vrend_format_table integer_la_formats[] = { - { VIRGL_FORMAT_A8_UINT, GL_ALPHA8UI_EXT, GL_ALPHA_INTEGER, GL_UNSIGNED_BYTE}, - { VIRGL_FORMAT_L8_UINT, GL_LUMINANCE8UI_EXT, GL_LUMINANCE_INTEGER_EXT, GL_UNSIGNED_BYTE}, - { VIRGL_FORMAT_L8A8_UINT, GL_LUMINANCE_ALPHA8UI_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_UNSIGNED_BYTE}, - { VIRGL_FORMAT_A8_SINT, GL_ALPHA8I_EXT, GL_ALPHA_INTEGER, GL_BYTE}, - { VIRGL_FORMAT_L8_SINT, GL_LUMINANCE8I_EXT, GL_LUMINANCE_INTEGER_EXT, GL_BYTE}, - { VIRGL_FORMAT_L8A8_SINT, GL_LUMINANCE_ALPHA8I_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_BYTE}, + { VIRGL_FORMAT_A8_UINT, GL_ALPHA8UI_EXT, GL_ALPHA_INTEGER, GL_UNSIGNED_BYTE}, + { VIRGL_FORMAT_L8_UINT, GL_LUMINANCE8UI_EXT, GL_LUMINANCE_INTEGER_EXT, GL_UNSIGNED_BYTE}, + { VIRGL_FORMAT_L8A8_UINT, GL_LUMINANCE_ALPHA8UI_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_UNSIGNED_BYTE}, + { VIRGL_FORMAT_A8_SINT, GL_ALPHA8I_EXT, GL_ALPHA_INTEGER, GL_BYTE}, + { VIRGL_FORMAT_L8_SINT, GL_LUMINANCE8I_EXT, GL_LUMINANCE_INTEGER_EXT, GL_BYTE}, + { VIRGL_FORMAT_L8A8_SINT, GL_LUMINANCE_ALPHA8I_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_BYTE}, - { VIRGL_FORMAT_A16_UINT, GL_ALPHA16UI_EXT, GL_ALPHA_INTEGER, GL_UNSIGNED_SHORT}, - { VIRGL_FORMAT_L16_UINT, GL_LUMINANCE16UI_EXT, GL_LUMINANCE_INTEGER_EXT, GL_UNSIGNED_SHORT}, - { VIRGL_FORMAT_L16A16_UINT, GL_LUMINANCE_ALPHA16UI_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_UNSIGNED_SHORT}, + { VIRGL_FORMAT_A16_UINT, GL_ALPHA16UI_EXT, GL_ALPHA_INTEGER, GL_UNSIGNED_SHORT}, + { VIRGL_FORMAT_L16_UINT, GL_LUMINANCE16UI_EXT, GL_LUMINANCE_INTEGER_EXT, GL_UNSIGNED_SHORT}, + { VIRGL_FORMAT_L16A16_UINT, GL_LUMINANCE_ALPHA16UI_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_UNSIGNED_SHORT}, - { VIRGL_FORMAT_A16_SINT, GL_ALPHA16I_EXT, GL_ALPHA_INTEGER, GL_SHORT}, - { VIRGL_FORMAT_L16_SINT, GL_LUMINANCE16I_EXT, GL_LUMINANCE_INTEGER_EXT, GL_SHORT}, - { VIRGL_FORMAT_L16A16_SINT, GL_LUMINANCE_ALPHA16I_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_SHORT}, + { VIRGL_FORMAT_A16_SINT, GL_ALPHA16I_EXT, GL_ALPHA_INTEGER, GL_SHORT}, + { VIRGL_FORMAT_L16_SINT, GL_LUMINANCE16I_EXT, GL_LUMINANCE_INTEGER_EXT, GL_SHORT}, + { VIRGL_FORMAT_L16A16_SINT, GL_LUMINANCE_ALPHA16I_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_SHORT}, - { VIRGL_FORMAT_A32_UINT, GL_ALPHA32UI_EXT, GL_ALPHA_INTEGER, GL_UNSIGNED_INT}, - { VIRGL_FORMAT_L32_UINT, GL_LUMINANCE32UI_EXT, GL_LUMINANCE_INTEGER_EXT, GL_UNSIGNED_INT}, - { VIRGL_FORMAT_L32A32_UINT, GL_LUMINANCE_ALPHA32UI_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_UNSIGNED_INT}, + { VIRGL_FORMAT_A32_UINT, GL_ALPHA32UI_EXT, GL_ALPHA_INTEGER, GL_UNSIGNED_INT}, + { VIRGL_FORMAT_L32_UINT, GL_LUMINANCE32UI_EXT, GL_LUMINANCE_INTEGER_EXT, GL_UNSIGNED_INT}, + { VIRGL_FORMAT_L32A32_UINT, GL_LUMINANCE_ALPHA32UI_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_UNSIGNED_INT}, - { VIRGL_FORMAT_A32_SINT, GL_ALPHA32I_EXT, GL_ALPHA_INTEGER, GL_INT}, - { VIRGL_FORMAT_L32_SINT, GL_LUMINANCE32I_EXT, GL_LUMINANCE_INTEGER_EXT, GL_INT}, - { VIRGL_FORMAT_L32A32_SINT, GL_LUMINANCE_ALPHA32I_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_INT}, + { VIRGL_FORMAT_A32_SINT, GL_ALPHA32I_EXT, GL_ALPHA_INTEGER, GL_INT}, + { VIRGL_FORMAT_L32_SINT, GL_LUMINANCE32I_EXT, GL_LUMINANCE_INTEGER_EXT, GL_INT}, + { VIRGL_FORMAT_L32A32_SINT, GL_LUMINANCE_ALPHA32I_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, GL_INT}, }; static struct vrend_format_table snorm_formats[] = { - { VIRGL_FORMAT_R8_SNORM, GL_R8_SNORM, GL_RED, GL_BYTE }, - { VIRGL_FORMAT_R8G8_SNORM, GL_RG8_SNORM, GL_RG, GL_BYTE }, + { VIRGL_FORMAT_R8_SNORM, GL_R8_SNORM, GL_RED, GL_BYTE }, + { VIRGL_FORMAT_R8G8_SNORM, GL_RG8_SNORM, GL_RG, GL_BYTE }, - { VIRGL_FORMAT_R8G8B8A8_SNORM, GL_RGBA8_SNORM, GL_RGBA, GL_BYTE }, - { VIRGL_FORMAT_R8G8B8X8_SNORM, GL_RGBA8_SNORM, GL_RGBA, GL_BYTE }, + { VIRGL_FORMAT_R8G8B8A8_SNORM, GL_RGBA8_SNORM, GL_RGBA, GL_BYTE }, + { VIRGL_FORMAT_R8G8B8X8_SNORM, GL_RGBA8_SNORM, GL_RGBA, GL_BYTE }, - { VIRGL_FORMAT_R16_SNORM, GL_R16_SNORM, GL_RED, GL_SHORT }, - { VIRGL_FORMAT_R16G16_SNORM, GL_RG16_SNORM, GL_RG, GL_SHORT }, - { VIRGL_FORMAT_R16G16B16A16_SNORM, GL_RGBA16_SNORM, GL_RGBA, GL_SHORT }, + { VIRGL_FORMAT_R16_SNORM, GL_R16_SNORM, GL_RED, GL_SHORT }, + { VIRGL_FORMAT_R16G16_SNORM, GL_RG16_SNORM, GL_RG, GL_SHORT }, + { VIRGL_FORMAT_R16G16B16A16_SNORM, GL_RGBA16_SNORM, GL_RGBA, GL_SHORT }, - { VIRGL_FORMAT_R16G16B16X16_SNORM, GL_RGBA16_SNORM, GL_RGBA, GL_SHORT }, + { VIRGL_FORMAT_R16G16B16X16_SNORM, GL_RGBA16_SNORM, GL_RGBA, GL_SHORT }, }; static struct vrend_format_table snorm_la_formats[] = { - { VIRGL_FORMAT_A8_SNORM, GL_ALPHA8_SNORM, GL_ALPHA, GL_BYTE }, - { VIRGL_FORMAT_L8_SNORM, GL_LUMINANCE8_SNORM, GL_LUMINANCE, GL_BYTE }, - { VIRGL_FORMAT_L8A8_SNORM, GL_LUMINANCE8_ALPHA8_SNORM, GL_LUMINANCE_ALPHA, GL_BYTE }, - { VIRGL_FORMAT_A16_SNORM, GL_ALPHA16_SNORM, GL_ALPHA, GL_SHORT }, - { VIRGL_FORMAT_L16_SNORM, GL_LUMINANCE16_SNORM, GL_LUMINANCE, GL_SHORT }, - { VIRGL_FORMAT_L16A16_SNORM, GL_LUMINANCE16_ALPHA16_SNORM, GL_LUMINANCE_ALPHA, GL_SHORT }, + { VIRGL_FORMAT_A8_SNORM, GL_ALPHA8_SNORM, GL_ALPHA, GL_BYTE }, + { VIRGL_FORMAT_L8_SNORM, GL_LUMINANCE8_SNORM, GL_LUMINANCE, GL_BYTE }, + { VIRGL_FORMAT_L8A8_SNORM, GL_LUMINANCE8_ALPHA8_SNORM, GL_LUMINANCE_ALPHA, GL_BYTE }, + { VIRGL_FORMAT_A16_SNORM, GL_ALPHA16_SNORM, GL_ALPHA, GL_SHORT }, + { VIRGL_FORMAT_L16_SNORM, GL_LUMINANCE16_SNORM, GL_LUMINANCE, GL_SHORT }, + { VIRGL_FORMAT_L16A16_SNORM, GL_LUMINANCE16_ALPHA16_SNORM, GL_LUMINANCE_ALPHA, GL_SHORT }, }; static struct vrend_format_table dxtn_formats[] = { - { VIRGL_FORMAT_DXT1_RGB, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_RGB, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_DXT1_RGBA, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_RGBA, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_DXT3_RGBA, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_RGBA, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_DXT5_RGBA, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_RGBA, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_DXT1_RGB, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_RGB, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_DXT1_RGBA, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_RGBA, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_DXT3_RGBA, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_RGBA, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_DXT5_RGBA, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_RGBA, GL_UNSIGNED_BYTE }, }; static struct vrend_format_table dxtn_srgb_formats[] = { - { VIRGL_FORMAT_DXT1_SRGB, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, GL_RGB, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_DXT1_SRGBA, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_RGBA, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_DXT3_SRGBA, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_RGBA, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_DXT5_SRGBA, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_RGBA, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_DXT1_SRGB, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, GL_RGB, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_DXT1_SRGBA, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_RGBA, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_DXT3_SRGBA, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_RGBA, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_DXT5_SRGBA, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_RGBA, GL_UNSIGNED_BYTE }, }; static struct vrend_format_table rgtc_formats[] = { - { VIRGL_FORMAT_RGTC1_UNORM, GL_COMPRESSED_RED_RGTC1, GL_RED, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_RGTC1_SNORM, GL_COMPRESSED_SIGNED_RED_RGTC1, GL_RED, GL_BYTE }, + { VIRGL_FORMAT_RGTC1_UNORM, GL_COMPRESSED_RED_RGTC1, GL_RED, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_RGTC1_SNORM, GL_COMPRESSED_SIGNED_RED_RGTC1, GL_RED, GL_BYTE }, - { VIRGL_FORMAT_RGTC2_UNORM, GL_COMPRESSED_RG_RGTC2, GL_RG, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_RGTC2_SNORM, GL_COMPRESSED_SIGNED_RG_RGTC2, GL_RG, GL_BYTE }, + { VIRGL_FORMAT_RGTC2_UNORM, GL_COMPRESSED_RG_RGTC2, GL_RG, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_RGTC2_SNORM, GL_COMPRESSED_SIGNED_RG_RGTC2, GL_RG, GL_BYTE }, }; static struct vrend_format_table srgb_formats[] = { - { VIRGL_FORMAT_B8G8R8X8_SRGB, GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_B8G8R8A8_SRGB, GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_R8G8B8X8_SRGB, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_B8G8R8X8_SRGB, GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_B8G8R8A8_SRGB, GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_R8G8B8X8_SRGB, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_L8_SRGB, GL_SLUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE }, - { VIRGL_FORMAT_L8A8_SRGB, GL_SLUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_L8_SRGB, GL_SLUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE }, + { VIRGL_FORMAT_L8A8_SRGB, GL_SLUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE }, }; static struct vrend_format_table bit10_formats[] = { - { VIRGL_FORMAT_B10G10R10X2_UNORM, GL_RGB10_A2, GL_BGRA, GL_UNSIGNED_INT_2_10_10_10_REV }, - { VIRGL_FORMAT_B10G10R10A2_UNORM, GL_RGB10_A2, GL_BGRA, GL_UNSIGNED_INT_2_10_10_10_REV }, - { VIRGL_FORMAT_B10G10R10A2_UINT, GL_RGB10_A2UI, GL_BGRA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV }, + { VIRGL_FORMAT_B10G10R10X2_UNORM, GL_RGB10_A2, GL_BGRA, GL_UNSIGNED_INT_2_10_10_10_REV }, + { VIRGL_FORMAT_B10G10R10A2_UNORM, GL_RGB10_A2, GL_BGRA, GL_UNSIGNED_INT_2_10_10_10_REV }, + { VIRGL_FORMAT_B10G10R10A2_UINT, GL_RGB10_A2UI, GL_BGRA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV }, }; static struct vrend_format_table packed_float_formats[] = { - { VIRGL_FORMAT_R11G11B10_FLOAT, GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV}, + { VIRGL_FORMAT_R11G11B10_FLOAT, GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV}, }; static struct vrend_format_table exponent_float_formats[] = { - { VIRGL_FORMAT_R9G9B9E5_FLOAT, GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV}, + { VIRGL_FORMAT_R9G9B9E5_FLOAT, GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV}, }; static void vrend_add_formats(struct vrend_format_table *table, int num_entries) { - int i; - uint32_t binding = 0; - GLuint tex_id, fb_id; - for (i = 0; i < num_entries; i++) { - GLenum status; - bool is_depth = false; - /**/ - glGenTextures(1, &tex_id); - glGenFramebuffers(1, &fb_id); - - glBindTexture(GL_TEXTURE_2D, tex_id); - glBindFramebuffer(GL_FRAMEBUFFER, fb_id); - - glTexImage2D(GL_TEXTURE_2D, 0, table[i].internalformat, 32, 32, 0, table[i].glformat, table[i].gltype, NULL); - status = glGetError(); - if (status == GL_INVALID_VALUE) { - struct vrend_format_table *entry = NULL; - uint8_t swizzle[4]; - binding = VREND_BIND_SAMPLER | VREND_BIND_NEED_SWIZZLE; - - switch (table[i].format) { - case PIPE_FORMAT_A8_UNORM: - entry = &rg_base_formats[0]; - swizzle[0] = swizzle[1] = swizzle[2] = PIPE_SWIZZLE_ZERO; - swizzle[3] = PIPE_SWIZZLE_RED; - break; - case PIPE_FORMAT_A16_UNORM: - entry = &rg_base_formats[2]; - swizzle[0] = swizzle[1] = swizzle[2] = PIPE_SWIZZLE_ZERO; - swizzle[3] = PIPE_SWIZZLE_RED; - break; - default: - break; - } - - if (entry) { - vrend_insert_format_swizzle(table[i].format, entry, binding, swizzle); - } - glDeleteTextures(1, &tex_id); - glDeleteFramebuffers(1, &fb_id); - continue; + int i; + uint32_t binding = 0; + GLuint tex_id, fb_id; + for (i = 0; i < num_entries; i++) { + GLenum status; + bool is_depth = false; + /**/ + glGenTextures(1, &tex_id); + glGenFramebuffers(1, &fb_id); + + glBindTexture(GL_TEXTURE_2D, tex_id); + glBindFramebuffer(GL_FRAMEBUFFER, fb_id); + + glTexImage2D(GL_TEXTURE_2D, 0, table[i].internalformat, 32, 32, 0, table[i].glformat, table[i].gltype, NULL); + status = glGetError(); + if (status == GL_INVALID_VALUE) { + struct vrend_format_table *entry = NULL; + uint8_t swizzle[4]; + binding = VREND_BIND_SAMPLER | VREND_BIND_NEED_SWIZZLE; + + switch (table[i].format) { + case PIPE_FORMAT_A8_UNORM: + entry = &rg_base_formats[0]; + swizzle[0] = swizzle[1] = swizzle[2] = PIPE_SWIZZLE_ZERO; + swizzle[3] = PIPE_SWIZZLE_RED; + break; + case PIPE_FORMAT_A16_UNORM: + entry = &rg_base_formats[2]; + swizzle[0] = swizzle[1] = swizzle[2] = PIPE_SWIZZLE_ZERO; + swizzle[3] = PIPE_SWIZZLE_RED; + break; + default: + break; } - if (util_format_is_depth_or_stencil(table[i].format)) { - GLenum attachment; - - if (table[i].format == VIRGL_FORMAT_Z24X8_UNORM || table[i].format == VIRGL_FORMAT_Z32_UNORM || table[i].format == VIRGL_FORMAT_Z16_UNORM || table[i].format == VIRGL_FORMAT_Z32_FLOAT) - attachment = GL_DEPTH_ATTACHMENT; - else - attachment = GL_DEPTH_STENCIL_ATTACHMENT; - glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_2D, tex_id, 0); - - is_depth = true; - glDrawBuffer(GL_NONE); - } else { - glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex_id, 0); - - glDrawBuffer(GL_COLOR_ATTACHMENT0); + if (entry) { + vrend_insert_format_swizzle(table[i].format, entry, binding, swizzle); } - - status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - binding = VREND_BIND_SAMPLER; - if (status == GL_FRAMEBUFFER_COMPLETE) - binding |= (is_depth ? VREND_BIND_DEPTHSTENCIL : VREND_BIND_RENDER); - glDeleteTextures(1, &tex_id); glDeleteFramebuffers(1, &fb_id); - vrend_insert_format(&table[i], binding); - } + continue; + } + + if (util_format_is_depth_or_stencil(table[i].format)) { + GLenum attachment; + + if (table[i].format == VIRGL_FORMAT_Z24X8_UNORM || table[i].format == VIRGL_FORMAT_Z32_UNORM || table[i].format == VIRGL_FORMAT_Z16_UNORM || table[i].format == VIRGL_FORMAT_Z32_FLOAT) + attachment = GL_DEPTH_ATTACHMENT; + else + attachment = GL_DEPTH_STENCIL_ATTACHMENT; + glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_2D, tex_id, 0); + + is_depth = true; + glDrawBuffer(GL_NONE); + } else { + glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex_id, 0); + + glDrawBuffer(GL_COLOR_ATTACHMENT0); + } + + status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + binding = VREND_BIND_SAMPLER; + if (status == GL_FRAMEBUFFER_COMPLETE) + binding |= (is_depth ? VREND_BIND_DEPTHSTENCIL : VREND_BIND_RENDER); + + glDeleteTextures(1, &tex_id); + glDeleteFramebuffers(1, &fb_id); + vrend_insert_format(&table[i], binding); + } } #define add_formats(x) vrend_add_formats((x), ARRAY_SIZE((x))) void vrend_build_format_list(void) { - add_formats(base_rgba_formats); - add_formats(base_depth_formats); - add_formats(base_la_formats); - - /* float support */ - add_formats(float_base_formats); - add_formats(float_la_formats); - add_formats(float_3comp_formats); - - /* texture integer support ? */ - add_formats(integer_base_formats); - add_formats(integer_la_formats); - add_formats(integer_3comp_formats); - - /* RG support? */ - add_formats(rg_base_formats); - /* integer + rg */ - add_formats(integer_rg_formats); - /* float + rg */ - add_formats(float_rg_formats); - - /* snorm */ - add_formats(snorm_formats); - add_formats(snorm_la_formats); - - /* compressed */ - add_formats(rgtc_formats); - add_formats(dxtn_formats); - add_formats(dxtn_srgb_formats); - - add_formats(srgb_formats); - - add_formats(bit10_formats); - - add_formats(packed_float_formats); - add_formats(exponent_float_formats); + add_formats(base_rgba_formats); + add_formats(base_depth_formats); + add_formats(base_la_formats); + + /* float support */ + add_formats(float_base_formats); + add_formats(float_la_formats); + add_formats(float_3comp_formats); + + /* texture integer support ? */ + add_formats(integer_base_formats); + add_formats(integer_la_formats); + add_formats(integer_3comp_formats); + + /* RG support? */ + add_formats(rg_base_formats); + /* integer + rg */ + add_formats(integer_rg_formats); + /* float + rg */ + add_formats(float_rg_formats); + + /* snorm */ + add_formats(snorm_formats); + add_formats(snorm_la_formats); + + /* compressed */ + add_formats(rgtc_formats); + add_formats(dxtn_formats); + add_formats(dxtn_srgb_formats); + + add_formats(srgb_formats); + + add_formats(bit10_formats); + + add_formats(packed_float_formats); + add_formats(exponent_float_formats); } diff --git a/src/vrend_object.c b/src/vrend_object.c index 7cb1d78..92418eb 100644 --- a/src/vrend_object.c +++ b/src/vrend_object.c @@ -34,7 +34,7 @@ struct vrend_object_types { static void (*resource_unref)(void *); -void vrend_object_set_destroy_callback(int type, void (*cb)(void *)) +void vrend_object_set_destroy_callback(int type, void (*cb)(void *)) { obj_types[type].unref = cb; } @@ -102,7 +102,7 @@ void vrend_object_fini_ctx_table(struct util_hash_table *ctx_hash) { if (!ctx_hash) return; - + util_hash_table_foreach(ctx_hash, free_cb, NULL); util_hash_table_destroy(ctx_hash); } @@ -166,12 +166,12 @@ vrend_object_remove(struct util_hash_table *handle_hash, return; util_hash_table_remove(handle_hash, intptr_to_pointer(handle)); - + vrend_object_free(obj); } void *vrend_object_lookup(struct util_hash_table *handle_hash, - uint32_t handle, enum virgl_object_type type) + uint32_t handle, enum virgl_object_type type) { struct vrend_object *obj; diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index bd2f693..1dc6647 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -119,30 +119,30 @@ struct global_renderer_state { static struct global_renderer_state vrend_state; struct vrend_linked_shader_program { - struct list_head head; - struct list_head sl[PIPE_SHADER_TYPES]; - GLuint id; + struct list_head head; + struct list_head sl[PIPE_SHADER_TYPES]; + GLuint id; - bool dual_src_linked; - struct vrend_shader *ss[PIPE_SHADER_TYPES]; + bool dual_src_linked; + struct vrend_shader *ss[PIPE_SHADER_TYPES]; - uint32_t samplers_used_mask[PIPE_SHADER_TYPES]; - GLuint *samp_locs[PIPE_SHADER_TYPES]; + uint32_t samplers_used_mask[PIPE_SHADER_TYPES]; + GLuint *samp_locs[PIPE_SHADER_TYPES]; - GLuint *shadow_samp_mask_locs[PIPE_SHADER_TYPES]; - GLuint *shadow_samp_add_locs[PIPE_SHADER_TYPES]; + GLuint *shadow_samp_mask_locs[PIPE_SHADER_TYPES]; + GLuint *shadow_samp_add_locs[PIPE_SHADER_TYPES]; - GLuint *const_locs[PIPE_SHADER_TYPES]; + GLuint *const_locs[PIPE_SHADER_TYPES]; - GLuint *attrib_locs; - uint32_t shadow_samp_mask[PIPE_SHADER_TYPES]; + GLuint *attrib_locs; + uint32_t shadow_samp_mask[PIPE_SHADER_TYPES]; - GLuint *ubo_locs[PIPE_SHADER_TYPES]; - GLuint vs_ws_adjust_loc; + GLuint *ubo_locs[PIPE_SHADER_TYPES]; + GLuint vs_ws_adjust_loc; - GLuint fs_stipple_loc; + GLuint fs_stipple_loc; - GLuint clip_locs[8]; + GLuint clip_locs[8]; }; struct vrend_shader { @@ -459,7 +459,7 @@ static inline bool should_invert_viewport(struct vrend_context *ctx) /* if we have a negative viewport then gallium wanted to invert it, however since we are rendering to GL FBOs we need to invert it again unless we are rendering upside down already - - confused? + - confused? so if gallium asks for a negative viewport */ return !(ctx->sub->viewport_is_negative ^ ctx->sub->inverted_fbo_content); } @@ -517,7 +517,7 @@ static void vrend_shader_destroy(struct vrend_shader *shader) struct vrend_linked_shader_program *ent, *tmp; LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, &shader->programs, sl[shader->sel->type]) { - vrend_destroy_program(ent); + vrend_destroy_program(ent); } glDeleteShader(shader->id); @@ -543,7 +543,7 @@ static void vrend_destroy_shader_selector(struct vrend_shader_selector *sel) } static bool vrend_compile_shader(struct vrend_context *ctx, - struct vrend_shader *shader) + struct vrend_shader *shader) { GLint param; glShaderSource(shader->id, 1, (const char **)&shader->glsl_prog, NULL); @@ -581,18 +581,18 @@ vrend_insert_format(struct vrend_format_table *entry, uint32_t bindings) void vrend_insert_format_swizzle(int override_format, struct vrend_format_table *entry, uint32_t bindings, uint8_t swizzle[4]) { - int i; + int i; tex_conv_table[override_format] = *entry; tex_conv_table[override_format].bindings = bindings; tex_conv_table[override_format].flags = VREND_BIND_NEED_SWIZZLE; for (i = 0; i < 4; i++) - tex_conv_table[override_format].swizzle[i] = swizzle[i]; + tex_conv_table[override_format].swizzle[i] = swizzle[i]; } static bool vrend_is_timer_query(GLenum gltype) { - return gltype == GL_TIMESTAMP || - gltype == GL_TIME_ELAPSED; + return gltype == GL_TIMESTAMP || + gltype == GL_TIME_ELAPSED; } static void vrend_use_program(struct vrend_context *ctx, GLuint program_id) @@ -641,8 +641,8 @@ static void vrend_depth_test_enable(struct vrend_context *ctx, bool depth_test_e static void vrend_alpha_test_enable(struct vrend_context *ctx, bool alpha_test_enable) { if (vrend_state.use_core_profile) { - /* handled in shaders */ - return; + /* handled in shaders */ + return; } if (ctx->sub->alpha_test_enabled != alpha_test_enable) { ctx->sub->alpha_test_enabled = alpha_test_enable; @@ -774,228 +774,228 @@ static struct vrend_linked_shader_program *add_shader_program(struct vrend_conte struct vrend_shader *gs) { struct vrend_linked_shader_program *sprog = CALLOC_STRUCT(vrend_linked_shader_program); - char name[16]; - int i; - GLuint prog_id; - GLint lret; - int id; - - if (!sprog) - return NULL; - - /* need to rewrite VS code to add interpolation params */ - if ((gs && gs->compiled_fs_id != fs->id) || - (!gs && vs->compiled_fs_id != fs->id)) { - bool ret; - - if (gs) - vrend_patch_vertex_shader_interpolants(gs->glsl_prog, - &gs->sel->sinfo, - &fs->sel->sinfo, true, fs->key.flatshade); - else - vrend_patch_vertex_shader_interpolants(vs->glsl_prog, - &vs->sel->sinfo, - &fs->sel->sinfo, false, fs->key.flatshade); - ret = vrend_compile_shader(ctx, gs ? gs : vs); - if (ret == false) { - glDeleteShader(gs ? gs->id : vs->id); - free(sprog); - return NULL; - } - if (gs) - gs->compiled_fs_id = fs->id; - else - vs->compiled_fs_id = fs->id; - } - - prog_id = glCreateProgram(); - glAttachShader(prog_id, vs->id); - if (gs) { - if (gs->id > 0) - glAttachShader(prog_id, gs->id); - set_stream_out_varyings(prog_id, &gs->sel->sinfo); - } - else - set_stream_out_varyings(prog_id, &vs->sel->sinfo); - glAttachShader(prog_id, fs->id); - - if (fs->sel->sinfo.num_outputs > 1) { - if (util_blend_state_is_dual(&ctx->sub->blend_state, 0)) { - glBindFragDataLocationIndexed(prog_id, 0, 0, "fsout_c0"); - glBindFragDataLocationIndexed(prog_id, 0, 1, "fsout_c1"); - sprog->dual_src_linked = true; - } else { - glBindFragDataLocationIndexed(prog_id, 0, 0, "fsout_c0"); - glBindFragDataLocationIndexed(prog_id, 1, 0, "fsout_c1"); - sprog->dual_src_linked = false; - } - } else - sprog->dual_src_linked = false; - - if (vrend_state.have_vertex_attrib_binding) { - for (i = 0; i < vs->sel->sinfo.num_inputs; i++) { - snprintf(name, 10, "in_%d", i); - glBindAttribLocation(prog_id, i, name); - } - } - - glLinkProgram(prog_id); - - glGetProgramiv(prog_id, GL_LINK_STATUS, &lret); - if (lret == GL_FALSE) { - char infolog[65536]; - int len; - glGetProgramInfoLog(prog_id, 65536, &len, infolog); - fprintf(stderr,"got error linking\n%s\n", infolog); - /* dump shaders */ - report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_SHADER, 0); - fprintf(stderr,"vert shader: %d GLSL\n%s\n", vs->id, vs->glsl_prog); - if (gs) - fprintf(stderr,"geom shader: %d GLSL\n%s\n", gs->id, gs->glsl_prog); - fprintf(stderr,"frag shader: %d GLSL\n%s\n", fs->id, fs->glsl_prog); - glDeleteProgram(prog_id); - return NULL; - } - - sprog->ss[PIPE_SHADER_VERTEX] = vs; - sprog->ss[PIPE_SHADER_FRAGMENT] = fs; - sprog->ss[PIPE_SHADER_GEOMETRY] = gs; - - list_add(&sprog->sl[PIPE_SHADER_VERTEX], &vs->programs); - list_add(&sprog->sl[PIPE_SHADER_FRAGMENT], &fs->programs); - if (gs) + char name[16]; + int i; + GLuint prog_id; + GLint lret; + int id; + + if (!sprog) + return NULL; + + /* need to rewrite VS code to add interpolation params */ + if ((gs && gs->compiled_fs_id != fs->id) || + (!gs && vs->compiled_fs_id != fs->id)) { + bool ret; + + if (gs) + vrend_patch_vertex_shader_interpolants(gs->glsl_prog, + &gs->sel->sinfo, + &fs->sel->sinfo, true, fs->key.flatshade); + else + vrend_patch_vertex_shader_interpolants(vs->glsl_prog, + &vs->sel->sinfo, + &fs->sel->sinfo, false, fs->key.flatshade); + ret = vrend_compile_shader(ctx, gs ? gs : vs); + if (ret == false) { + glDeleteShader(gs ? gs->id : vs->id); + free(sprog); + return NULL; + } + if (gs) + gs->compiled_fs_id = fs->id; + else + vs->compiled_fs_id = fs->id; + } + + prog_id = glCreateProgram(); + glAttachShader(prog_id, vs->id); + if (gs) { + if (gs->id > 0) + glAttachShader(prog_id, gs->id); + set_stream_out_varyings(prog_id, &gs->sel->sinfo); + } + else + set_stream_out_varyings(prog_id, &vs->sel->sinfo); + glAttachShader(prog_id, fs->id); + + if (fs->sel->sinfo.num_outputs > 1) { + if (util_blend_state_is_dual(&ctx->sub->blend_state, 0)) { + glBindFragDataLocationIndexed(prog_id, 0, 0, "fsout_c0"); + glBindFragDataLocationIndexed(prog_id, 0, 1, "fsout_c1"); + sprog->dual_src_linked = true; + } else { + glBindFragDataLocationIndexed(prog_id, 0, 0, "fsout_c0"); + glBindFragDataLocationIndexed(prog_id, 1, 0, "fsout_c1"); + sprog->dual_src_linked = false; + } + } else + sprog->dual_src_linked = false; + + if (vrend_state.have_vertex_attrib_binding) { + for (i = 0; i < vs->sel->sinfo.num_inputs; i++) { + snprintf(name, 10, "in_%d", i); + glBindAttribLocation(prog_id, i, name); + } + } + + glLinkProgram(prog_id); + + glGetProgramiv(prog_id, GL_LINK_STATUS, &lret); + if (lret == GL_FALSE) { + char infolog[65536]; + int len; + glGetProgramInfoLog(prog_id, 65536, &len, infolog); + fprintf(stderr,"got error linking\n%s\n", infolog); + /* dump shaders */ + report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_SHADER, 0); + fprintf(stderr,"vert shader: %d GLSL\n%s\n", vs->id, vs->glsl_prog); + if (gs) + fprintf(stderr,"geom shader: %d GLSL\n%s\n", gs->id, gs->glsl_prog); + fprintf(stderr,"frag shader: %d GLSL\n%s\n", fs->id, fs->glsl_prog); + glDeleteProgram(prog_id); + return NULL; + } + + sprog->ss[PIPE_SHADER_VERTEX] = vs; + sprog->ss[PIPE_SHADER_FRAGMENT] = fs; + sprog->ss[PIPE_SHADER_GEOMETRY] = gs; + + list_add(&sprog->sl[PIPE_SHADER_VERTEX], &vs->programs); + list_add(&sprog->sl[PIPE_SHADER_FRAGMENT], &fs->programs); + if (gs) list_add(&sprog->sl[PIPE_SHADER_GEOMETRY], &gs->programs); - sprog->id = prog_id; - - list_add(&sprog->head, &ctx->sub->programs); - - if (fs->key.pstipple_tex) - sprog->fs_stipple_loc = glGetUniformLocation(prog_id, "pstipple_sampler"); - else - sprog->fs_stipple_loc = -1; - sprog->vs_ws_adjust_loc = glGetUniformLocation(prog_id, "winsys_adjust"); - for (id = PIPE_SHADER_VERTEX; id <= (gs ? PIPE_SHADER_GEOMETRY : PIPE_SHADER_FRAGMENT); id++) { - if (sprog->ss[id]->sel->sinfo.samplers_used_mask) { - uint32_t mask = sprog->ss[id]->sel->sinfo.samplers_used_mask; - int nsamp = util_bitcount(sprog->ss[id]->sel->sinfo.samplers_used_mask); - int index; - sprog->shadow_samp_mask[id] = sprog->ss[id]->sel->sinfo.shadow_samp_mask; - if (sprog->ss[id]->sel->sinfo.shadow_samp_mask) { - sprog->shadow_samp_mask_locs[id] = calloc(nsamp, sizeof(uint32_t)); - sprog->shadow_samp_add_locs[id] = calloc(nsamp, sizeof(uint32_t)); - } else { - sprog->shadow_samp_mask_locs[id] = sprog->shadow_samp_add_locs[id] = NULL; - } - sprog->samp_locs[id] = calloc(nsamp, sizeof(uint32_t)); - if (sprog->samp_locs[id]) { - const char *prefix = pipe_shader_to_prefix(id); - index = 0; - while(mask) { - i = u_bit_scan(&mask); - snprintf(name, 10, "%ssamp%d", prefix, i); - sprog->samp_locs[id][index] = glGetUniformLocation(prog_id, name); - if (sprog->ss[id]->sel->sinfo.shadow_samp_mask & (1 << i)) { - snprintf(name, 14, "%sshadmask%d", prefix, i); - sprog->shadow_samp_mask_locs[id][index] = glGetUniformLocation(prog_id, name); - snprintf(name, 14, "%sshadadd%d", prefix, i); - sprog->shadow_samp_add_locs[id][index] = glGetUniformLocation(prog_id, name); - } - index++; - } - } - } else { - sprog->samp_locs[id] = NULL; - sprog->shadow_samp_mask_locs[id] = NULL; - sprog->shadow_samp_add_locs[id] = NULL; - sprog->shadow_samp_mask[id] = 0; - } - sprog->samplers_used_mask[id] = sprog->ss[id]->sel->sinfo.samplers_used_mask; - } - - for (id = PIPE_SHADER_VERTEX; id <= (gs ? PIPE_SHADER_GEOMETRY : PIPE_SHADER_FRAGMENT); id++) { - if (sprog->ss[id]->sel->sinfo.num_consts) { - sprog->const_locs[id] = calloc(sprog->ss[id]->sel->sinfo.num_consts, sizeof(uint32_t)); - if (sprog->const_locs[id]) { - const char *prefix = pipe_shader_to_prefix(id); - for (i = 0; i < sprog->ss[id]->sel->sinfo.num_consts; i++) { - snprintf(name, 16, "%sconst0[%d]", prefix, i); - sprog->const_locs[id][i] = glGetUniformLocation(prog_id, name); - } - } - } else - sprog->const_locs[id] = NULL; - } - - if (!vrend_state.have_vertex_attrib_binding) { - if (vs->sel->sinfo.num_inputs) { - sprog->attrib_locs = calloc(vs->sel->sinfo.num_inputs, sizeof(uint32_t)); - if (sprog->attrib_locs) { - for (i = 0; i < vs->sel->sinfo.num_inputs; i++) { - snprintf(name, 10, "in_%d", i); - sprog->attrib_locs[i] = glGetAttribLocation(prog_id, name); - } + sprog->id = prog_id; + + list_add(&sprog->head, &ctx->sub->programs); + + if (fs->key.pstipple_tex) + sprog->fs_stipple_loc = glGetUniformLocation(prog_id, "pstipple_sampler"); + else + sprog->fs_stipple_loc = -1; + sprog->vs_ws_adjust_loc = glGetUniformLocation(prog_id, "winsys_adjust"); + for (id = PIPE_SHADER_VERTEX; id <= (gs ? PIPE_SHADER_GEOMETRY : PIPE_SHADER_FRAGMENT); id++) { + if (sprog->ss[id]->sel->sinfo.samplers_used_mask) { + uint32_t mask = sprog->ss[id]->sel->sinfo.samplers_used_mask; + int nsamp = util_bitcount(sprog->ss[id]->sel->sinfo.samplers_used_mask); + int index; + sprog->shadow_samp_mask[id] = sprog->ss[id]->sel->sinfo.shadow_samp_mask; + if (sprog->ss[id]->sel->sinfo.shadow_samp_mask) { + sprog->shadow_samp_mask_locs[id] = calloc(nsamp, sizeof(uint32_t)); + sprog->shadow_samp_add_locs[id] = calloc(nsamp, sizeof(uint32_t)); + } else { + sprog->shadow_samp_mask_locs[id] = sprog->shadow_samp_add_locs[id] = NULL; + } + sprog->samp_locs[id] = calloc(nsamp, sizeof(uint32_t)); + if (sprog->samp_locs[id]) { + const char *prefix = pipe_shader_to_prefix(id); + index = 0; + while(mask) { + i = u_bit_scan(&mask); + snprintf(name, 10, "%ssamp%d", prefix, i); + sprog->samp_locs[id][index] = glGetUniformLocation(prog_id, name); + if (sprog->ss[id]->sel->sinfo.shadow_samp_mask & (1 << i)) { + snprintf(name, 14, "%sshadmask%d", prefix, i); + sprog->shadow_samp_mask_locs[id][index] = glGetUniformLocation(prog_id, name); + snprintf(name, 14, "%sshadadd%d", prefix, i); + sprog->shadow_samp_add_locs[id][index] = glGetUniformLocation(prog_id, name); + } + index++; + } + } + } else { + sprog->samp_locs[id] = NULL; + sprog->shadow_samp_mask_locs[id] = NULL; + sprog->shadow_samp_add_locs[id] = NULL; + sprog->shadow_samp_mask[id] = 0; } - } else - sprog->attrib_locs = NULL; - } - - for (id = PIPE_SHADER_VERTEX; id <= (gs ? PIPE_SHADER_GEOMETRY : PIPE_SHADER_FRAGMENT); id++) { - if (sprog->ss[id]->sel->sinfo.num_ubos) { - const char *prefix = pipe_shader_to_prefix(id); - - sprog->ubo_locs[id] = calloc(sprog->ss[id]->sel->sinfo.num_ubos, sizeof(uint32_t)); - for (i = 0; i < sprog->ss[id]->sel->sinfo.num_ubos; i++) { - snprintf(name, 16, "%subo%d", prefix, i + 1); - sprog->ubo_locs[id][i] = glGetUniformBlockIndex(prog_id, name); - } - } else - sprog->ubo_locs[id] = NULL; - } - - if (vs->sel->sinfo.num_ucp) { - for (i = 0; i < vs->sel->sinfo.num_ucp; i++) { - snprintf(name, 10, "clipp[%d]", i); - sprog->clip_locs[i] = glGetUniformLocation(prog_id, name); - } - } - return sprog; + sprog->samplers_used_mask[id] = sprog->ss[id]->sel->sinfo.samplers_used_mask; + } + + for (id = PIPE_SHADER_VERTEX; id <= (gs ? PIPE_SHADER_GEOMETRY : PIPE_SHADER_FRAGMENT); id++) { + if (sprog->ss[id]->sel->sinfo.num_consts) { + sprog->const_locs[id] = calloc(sprog->ss[id]->sel->sinfo.num_consts, sizeof(uint32_t)); + if (sprog->const_locs[id]) { + const char *prefix = pipe_shader_to_prefix(id); + for (i = 0; i < sprog->ss[id]->sel->sinfo.num_consts; i++) { + snprintf(name, 16, "%sconst0[%d]", prefix, i); + sprog->const_locs[id][i] = glGetUniformLocation(prog_id, name); + } + } + } else + sprog->const_locs[id] = NULL; + } + + if (!vrend_state.have_vertex_attrib_binding) { + if (vs->sel->sinfo.num_inputs) { + sprog->attrib_locs = calloc(vs->sel->sinfo.num_inputs, sizeof(uint32_t)); + if (sprog->attrib_locs) { + for (i = 0; i < vs->sel->sinfo.num_inputs; i++) { + snprintf(name, 10, "in_%d", i); + sprog->attrib_locs[i] = glGetAttribLocation(prog_id, name); + } + } + } else + sprog->attrib_locs = NULL; + } + + for (id = PIPE_SHADER_VERTEX; id <= (gs ? PIPE_SHADER_GEOMETRY : PIPE_SHADER_FRAGMENT); id++) { + if (sprog->ss[id]->sel->sinfo.num_ubos) { + const char *prefix = pipe_shader_to_prefix(id); + + sprog->ubo_locs[id] = calloc(sprog->ss[id]->sel->sinfo.num_ubos, sizeof(uint32_t)); + for (i = 0; i < sprog->ss[id]->sel->sinfo.num_ubos; i++) { + snprintf(name, 16, "%subo%d", prefix, i + 1); + sprog->ubo_locs[id][i] = glGetUniformBlockIndex(prog_id, name); + } + } else + sprog->ubo_locs[id] = NULL; + } + + if (vs->sel->sinfo.num_ucp) { + for (i = 0; i < vs->sel->sinfo.num_ucp; i++) { + snprintf(name, 10, "clipp[%d]", i); + sprog->clip_locs[i] = glGetUniformLocation(prog_id, name); + } + } + return sprog; } static struct vrend_linked_shader_program *lookup_shader_program(struct vrend_context *ctx, GLuint vs_id, GLuint fs_id, GLuint gs_id, bool dual_src) { - struct vrend_linked_shader_program *ent; - LIST_FOR_EACH_ENTRY(ent, &ctx->sub->programs, head) { - if (ent->dual_src_linked != dual_src) - continue; - if (ent->ss[PIPE_SHADER_VERTEX]->id == vs_id && ent->ss[PIPE_SHADER_FRAGMENT]->id == fs_id) { - if (!ent->ss[PIPE_SHADER_GEOMETRY] && gs_id == 0) - return ent; - if (ent->ss[PIPE_SHADER_GEOMETRY] && ent->ss[PIPE_SHADER_GEOMETRY]->id == gs_id) - return ent; - } - } - return NULL; + struct vrend_linked_shader_program *ent; + LIST_FOR_EACH_ENTRY(ent, &ctx->sub->programs, head) { + if (ent->dual_src_linked != dual_src) + continue; + if (ent->ss[PIPE_SHADER_VERTEX]->id == vs_id && ent->ss[PIPE_SHADER_FRAGMENT]->id == fs_id) { + if (!ent->ss[PIPE_SHADER_GEOMETRY] && gs_id == 0) + return ent; + if (ent->ss[PIPE_SHADER_GEOMETRY] && ent->ss[PIPE_SHADER_GEOMETRY]->id == gs_id) + return ent; + } + } + return NULL; } static void vrend_destroy_program(struct vrend_linked_shader_program *ent) { - int i; - glDeleteProgram(ent->id); - list_del(&ent->head); + int i; + glDeleteProgram(ent->id); + list_del(&ent->head); - for (i = PIPE_SHADER_VERTEX; i <= PIPE_SHADER_GEOMETRY; i++) { - if (ent->ss[i]) - list_del(&ent->sl[i]); - free(ent->shadow_samp_mask_locs[i]); - free(ent->shadow_samp_add_locs[i]); - free(ent->samp_locs[i]); - free(ent->const_locs[i]); - free(ent->ubo_locs[i]); - } - free(ent->attrib_locs); - free(ent); + for (i = PIPE_SHADER_VERTEX; i <= PIPE_SHADER_GEOMETRY; i++) { + if (ent->ss[i]) + list_del(&ent->sl[i]); + free(ent->shadow_samp_mask_locs[i]); + free(ent->shadow_samp_add_locs[i]); + free(ent->samp_locs[i]); + free(ent->const_locs[i]); + free(ent->ubo_locs[i]); + } + free(ent->attrib_locs); + free(ent); } static void vrend_free_programs(struct vrend_sub_context *sub) @@ -1003,12 +1003,12 @@ static void vrend_free_programs(struct vrend_sub_context *sub) struct vrend_linked_shader_program *ent, *tmp; if (LIST_IS_EMPTY(&sub->programs)) - return; + return; LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, &sub->programs, head) { - vrend_destroy_program(ent); + vrend_destroy_program(ent); } -} +} static void vrend_destroy_streamout_object(struct vrend_streamout_object *obj) { @@ -1024,7 +1024,6 @@ int vrend_create_surface(struct vrend_context *ctx, uint32_t handle, uint32_t res_handle, uint32_t format, uint32_t val0, uint32_t val1) - { struct vrend_surface *surf; struct vrend_resource *res; @@ -1137,7 +1136,7 @@ static GLuint convert_wrap(int wrap) assert(0); return -1; } -} +} static inline GLenum convert_mag_filter(unsigned int filter) { @@ -1231,7 +1230,7 @@ int vrend_create_sampler_view(struct vrend_context *ctx, report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_RESOURCE, res_handle); return EINVAL; } - + view = CALLOC_STRUCT(vrend_sampler_view); if (!view) return ENOMEM; @@ -1265,10 +1264,10 @@ int vrend_create_sampler_view(struct vrend_context *ctx, view->gl_swizzle_b = to_gl_swizzle(view->swizzle_b); if (tex_conv_table[format].flags & VREND_BIND_NEED_SWIZZLE) { - view->gl_swizzle_r = to_gl_swizzle(tex_conv_table[format].swizzle[0]); - view->gl_swizzle_g = to_gl_swizzle(tex_conv_table[format].swizzle[1]); - view->gl_swizzle_b = to_gl_swizzle(tex_conv_table[format].swizzle[2]); - view->gl_swizzle_a = to_gl_swizzle(tex_conv_table[format].swizzle[3]); + view->gl_swizzle_r = to_gl_swizzle(tex_conv_table[format].swizzle[0]); + view->gl_swizzle_g = to_gl_swizzle(tex_conv_table[format].swizzle[1]); + view->gl_swizzle_b = to_gl_swizzle(tex_conv_table[format].swizzle[2]); + view->gl_swizzle_a = to_gl_swizzle(tex_conv_table[format].swizzle[3]); } ret_handle = vrend_renderer_object_insert(ctx, view, sizeof(*view), handle, VIRGL_OBJECT_SAMPLER_VIEW); if (ret_handle == 0) { @@ -1282,62 +1281,62 @@ void vrend_fb_bind_texture(struct vrend_resource *res, int idx, uint32_t level, uint32_t layer) { - const struct util_format_description *desc = util_format_description(res->base.format); - GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + idx; - - if (vrend_format_is_ds(res->base.format)) { { - if (util_format_has_stencil(desc)) { - if (util_format_has_depth(desc)) - attachment = GL_DEPTH_STENCIL_ATTACHMENT; - else - attachment = GL_STENCIL_ATTACHMENT; - } else - attachment = GL_DEPTH_ATTACHMENT; - } - } - - switch (res->target) { - case GL_TEXTURE_1D_ARRAY: - case GL_TEXTURE_2D_ARRAY: - case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: - case GL_TEXTURE_CUBE_MAP_ARRAY: - if (layer == 0xffffffff) - glFramebufferTexture(GL_FRAMEBUFFER_EXT, attachment, - res->id, level); - else - glFramebufferTextureLayer(GL_FRAMEBUFFER_EXT, attachment, - res->id, level, layer); - break; - case GL_TEXTURE_3D: - if (layer == 0xffffffff) - glFramebufferTexture(GL_FRAMEBUFFER_EXT, attachment, - res->id, level); - else - glFramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, attachment, - res->target, res->id, level, layer); - break; - case GL_TEXTURE_CUBE_MAP: - if (layer == 0xffffffff) - glFramebufferTexture(GL_FRAMEBUFFER_EXT, attachment, - res->id, level); - else - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, - GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer, res->id, level); - break; - case GL_TEXTURE_1D: - glFramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT, attachment, - res->target, res->id, level); - break; - case GL_TEXTURE_2D: - default: - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, - res->target, res->id, level); - break; - } - - if (attachment == GL_DEPTH_ATTACHMENT) - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT, - 0, 0, 0); + const struct util_format_description *desc = util_format_description(res->base.format); + GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + idx; + + if (vrend_format_is_ds(res->base.format)) { { + if (util_format_has_stencil(desc)) { + if (util_format_has_depth(desc)) + attachment = GL_DEPTH_STENCIL_ATTACHMENT; + else + attachment = GL_STENCIL_ATTACHMENT; + } else + attachment = GL_DEPTH_ATTACHMENT; + } + } + + switch (res->target) { + case GL_TEXTURE_1D_ARRAY: + case GL_TEXTURE_2D_ARRAY: + case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: + case GL_TEXTURE_CUBE_MAP_ARRAY: + if (layer == 0xffffffff) + glFramebufferTexture(GL_FRAMEBUFFER_EXT, attachment, + res->id, level); + else + glFramebufferTextureLayer(GL_FRAMEBUFFER_EXT, attachment, + res->id, level, layer); + break; + case GL_TEXTURE_3D: + if (layer == 0xffffffff) + glFramebufferTexture(GL_FRAMEBUFFER_EXT, attachment, + res->id, level); + else + glFramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, attachment, + res->target, res->id, level, layer); + break; + case GL_TEXTURE_CUBE_MAP: + if (layer == 0xffffffff) + glFramebufferTexture(GL_FRAMEBUFFER_EXT, attachment, + res->id, level); + else + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, + GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer, res->id, level); + break; + case GL_TEXTURE_1D: + glFramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT, attachment, + res->target, res->id, level); + break; + case GL_TEXTURE_2D: + default: + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, + res->target, res->id, level); + break; + } + + if (attachment == GL_DEPTH_ATTACHMENT) + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT, + 0, 0, 0); } static void vrend_hw_set_zsurf_texture(struct vrend_context *ctx) @@ -1371,13 +1370,13 @@ static void vrend_hw_set_color_surface(struct vrend_context *ctx, int index) glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_2D, 0, 0); } else { - int first_layer = ctx->sub->surf[index]->val1 & 0xffff; - int last_layer = (ctx->sub->surf[index]->val1 >> 16) & 0xffff; - tex = ctx->sub->surf[index]->texture; + int first_layer = ctx->sub->surf[index]->val1 & 0xffff; + int last_layer = (ctx->sub->surf[index]->val1 >> 16) & 0xffff; + tex = ctx->sub->surf[index]->texture; - vrend_fb_bind_texture(tex, index, ctx->sub->surf[index]->val0, - first_layer != last_layer ? 0xffffffff : first_layer); + vrend_fb_bind_texture(tex, index, ctx->sub->surf[index]->val0, + first_layer != last_layer ? 0xffffffff : first_layer); } @@ -1398,8 +1397,8 @@ static void vrend_hw_emit_framebuffer_state(struct vrend_context *ctx) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ctx->sub->fb_id); if (ctx->sub->nr_cbufs == 0) { - glReadBuffer(GL_NONE); - glDisable(GL_FRAMEBUFFER_SRGB_EXT); + glReadBuffer(GL_NONE); + glDisable(GL_FRAMEBUFFER_SRGB_EXT); } else { struct vrend_surface *surf = NULL; int i; @@ -1473,23 +1472,23 @@ void vrend_set_framebuffer_state(struct vrend_context *ctx, /* find a buffer to set fb_height from */ if (ctx->sub->nr_cbufs == 0 && !ctx->sub->zsurf) { - new_height = 0; - new_ibf = false; + 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; - } + 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; - } - } - assert(surf); - new_height = u_minify(surf->texture->base.height0, surf->val0); - new_ibf = surf->texture->y_0_top ? true : false; + surf = NULL; + for (i = 0; i < ctx->sub->nr_cbufs; i++) { + if (ctx->sub->surf[i]) { + surf = ctx->sub->surf[i]; + break; + } + } + assert(surf); + new_height = u_minify(surf->texture->base.height0, surf->val0); + new_ibf = surf->texture->y_0_top ? true : false; } if (new_height != -1) { @@ -1589,7 +1588,7 @@ int vrend_create_vertex_elements_state(struct vrend_context *ctx, memcpy(&v->elements[i].base, &elements[i], sizeof(struct pipe_vertex_element)); desc = util_format_description(elements[i].src_format); - + type = GL_FALSE; if (desc->channel[0].type == UTIL_FORMAT_TYPE_FLOAT) { if (desc->channel[0].size == 32) @@ -1599,22 +1598,22 @@ int vrend_create_vertex_elements_state(struct vrend_context *ctx, else if (desc->channel[0].size == 16) type = GL_HALF_FLOAT; } else if (desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED && - desc->channel[0].size == 8) + desc->channel[0].size == 8) type = GL_UNSIGNED_BYTE; else if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED && - desc->channel[0].size == 8) + desc->channel[0].size == 8) type = GL_BYTE; else if (desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED && - desc->channel[0].size == 16) + desc->channel[0].size == 16) type = GL_UNSIGNED_SHORT; else if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED && - desc->channel[0].size == 16) + desc->channel[0].size == 16) type = GL_SHORT; else if (desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED && - desc->channel[0].size == 32) + desc->channel[0].size == 32) type = GL_UNSIGNED_INT; else if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED && - desc->channel[0].size == 32) + desc->channel[0].size == 32) type = GL_INT; else if (elements[i].src_format == PIPE_FORMAT_R10G10B10A2_SSCALED || elements[i].src_format == PIPE_FORMAT_R10G10B10A2_SNORM || @@ -1660,7 +1659,7 @@ int vrend_create_vertex_elements_state(struct vrend_context *ctx, } } ret_handle = vrend_renderer_object_insert(ctx, v, sizeof(struct vrend_vertex_element), handle, - VIRGL_OBJECT_VERTEX_ELEMENTS); + VIRGL_OBJECT_VERTEX_ELEMENTS); if (!ret_handle) { FREE(v); return ENOMEM; @@ -1722,8 +1721,8 @@ void vrend_set_uniform_buffer(struct vrend_context *ctx, res = vrend_renderer_ctx_res_lookup(ctx, res_handle); if (!res) { - report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_RESOURCE, res_handle); - return; + 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; @@ -1765,10 +1764,10 @@ void vrend_set_index_buffer(struct vrend_context *ctx, } void vrend_set_single_vbo(struct vrend_context *ctx, - int index, - uint32_t stride, - uint32_t buffer_offset, - uint32_t res_handle) + int index, + uint32_t stride, + uint32_t buffer_offset, + uint32_t res_handle) { struct vrend_resource *res; @@ -1796,8 +1795,8 @@ void vrend_set_single_vbo(struct vrend_context *ctx, } void vrend_set_num_vbo(struct vrend_context *ctx, - int num_vbo) -{ + int num_vbo) +{ int old_num = ctx->sub->num_vbos; int i; @@ -1882,7 +1881,7 @@ void vrend_set_single_sampler_view(struct vrend_context *ctx, } } } else { - GLenum internalformat; + GLenum internalformat; tex = (struct vrend_texture *)view->texture; glBindTexture(GL_TEXTURE_BUFFER, view->texture->tbo_tex_id); @@ -1895,9 +1894,9 @@ void vrend_set_single_sampler_view(struct vrend_context *ctx, } void vrend_set_num_sampler_views(struct vrend_context *ctx, - uint32_t shader_type, - uint32_t start_slot, - int num_sampler_views) + 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; @@ -2289,31 +2288,31 @@ static void vrend_draw_bind_vertex_legacy(struct vrend_context *ctx, buf = (struct vrend_buffer *)ctx->sub->vbo[vbo_index].buffer; if (!buf) { - fprintf(stderr,"cannot find vbo buf %d %d %d\n", i, va->count, ctx->sub->prog->ss[PIPE_SHADER_VERTEX]->sel->sinfo.num_inputs); - continue; + fprintf(stderr,"cannot find vbo buf %d %d %d\n", i, va->count, ctx->sub->prog->ss[PIPE_SHADER_VERTEX]->sel->sinfo.num_inputs); + continue; } if (vrend_state.use_explicit_locations || vrend_state.have_vertex_attrib_binding) { loc = i; } else { - if (ctx->sub->prog->attrib_locs) { - loc = ctx->sub->prog->attrib_locs[i]; - } else loc = -1; - - if (loc == -1) { - fprintf(stderr,"%s: cannot find loc %d %d %d\n", ctx->debug_name, i, va->count, ctx->sub->prog->ss[PIPE_SHADER_VERTEX]->sel->sinfo.num_inputs); - num_enable--; - if (i == 0) { - fprintf(stderr,"%s: shader probably didn't compile - skipping rendering\n", ctx->debug_name); - return; - } - continue; - } + if (ctx->sub->prog->attrib_locs) { + loc = ctx->sub->prog->attrib_locs[i]; + } else loc = -1; + + if (loc == -1) { + fprintf(stderr,"%s: cannot find loc %d %d %d\n", ctx->debug_name, i, va->count, ctx->sub->prog->ss[PIPE_SHADER_VERTEX]->sel->sinfo.num_inputs); + num_enable--; + if (i == 0) { + fprintf(stderr,"%s: shader probably didn't compile - skipping rendering\n", ctx->debug_name); + return; + } + continue; + } } if (ve->type == GL_FALSE) { - fprintf(stderr,"failed to translate vertex type - skipping render\n"); - return; + fprintf(stderr,"failed to translate vertex type - skipping render\n"); + return; } glBindBuffer(GL_ARRAY_BUFFER, buf->base.id); @@ -2331,7 +2330,7 @@ static void vrend_draw_bind_vertex_legacy(struct vrend_context *ctx, glVertexAttrib2fv(loc, data); break; case 3: - glVertexAttrib3fv(loc, data); + glVertexAttrib3fv(loc, data); break; case 4: default: @@ -2418,18 +2417,18 @@ static void vrend_draw_bind_samplers(struct vrend_context *ctx) if (ctx->sub->prog->shadow_samp_mask[shader_type] & (1 << i)) { struct vrend_sampler_view *tview = ctx->sub->views[shader_type].views[i]; - glUniform4f(ctx->sub->prog->shadow_samp_mask_locs[shader_type][index], - tview->gl_swizzle_r == GL_ZERO ? 0.0 : 1.0, - tview->gl_swizzle_g == GL_ZERO ? 0.0 : 1.0, - tview->gl_swizzle_b == GL_ZERO ? 0.0 : 1.0, + glUniform4f(ctx->sub->prog->shadow_samp_mask_locs[shader_type][index], + tview->gl_swizzle_r == GL_ZERO ? 0.0 : 1.0, + tview->gl_swizzle_g == GL_ZERO ? 0.0 : 1.0, + tview->gl_swizzle_b == GL_ZERO ? 0.0 : 1.0, tview->gl_swizzle_a == GL_ZERO ? 0.0 : 1.0); - glUniform4f(ctx->sub->prog->shadow_samp_add_locs[shader_type][index], - tview->gl_swizzle_r == GL_ONE ? 1.0 : 0.0, - tview->gl_swizzle_g == GL_ONE ? 1.0 : 0.0, - tview->gl_swizzle_b == GL_ONE ? 1.0 : 0.0, + glUniform4f(ctx->sub->prog->shadow_samp_add_locs[shader_type][index], + tview->gl_swizzle_r == GL_ONE ? 1.0 : 0.0, + tview->gl_swizzle_g == GL_ONE ? 1.0 : 0.0, + tview->gl_swizzle_b == GL_ONE ? 1.0 : 0.0, tview->gl_swizzle_a == GL_ONE ? 1.0 : 0.0); } - + glActiveTexture(GL_TEXTURE0 + sampler_id); if (texture) { int id; @@ -2525,33 +2524,33 @@ void vrend_draw_vbo(struct vrend_context *ctx, vrend_patch_blend_func(ctx); if (ctx->sub->shader_dirty) { - struct vrend_linked_shader_program *prog; - bool fs_dirty, vs_dirty, gs_dirty; - bool dual_src = util_blend_state_is_dual(&ctx->sub->blend_state, 0); - if (!ctx->sub->vs || !ctx->sub->fs) { - fprintf(stderr,"dropping rendering due to missing shaders: %s\n", ctx->debug_name); - return; - } - - vrend_shader_select(ctx, ctx->sub->fs, &fs_dirty); - vrend_shader_select(ctx, ctx->sub->vs, &vs_dirty); - if (ctx->sub->gs) - vrend_shader_select(ctx, ctx->sub->gs, &gs_dirty); - - if (!ctx->sub->vs->current || !ctx->sub->fs->current || (ctx->sub->gs && !ctx->sub->gs->current)) { - fprintf(stderr, "failure to compile shader variants: %s\n", ctx->debug_name); - return; - } - prog = lookup_shader_program(ctx, ctx->sub->vs->current->id, ctx->sub->fs->current->id, ctx->sub->gs ? ctx->sub->gs->current->id : 0, dual_src); - if (!prog) { - prog = add_shader_program(ctx, ctx->sub->vs->current, ctx->sub->fs->current, ctx->sub->gs ? ctx->sub->gs->current : NULL); - if (!prog) - return; - } - if (ctx->sub->prog != prog) { - new_program = true; - ctx->sub->prog = prog; - } + struct vrend_linked_shader_program *prog; + bool fs_dirty, vs_dirty, gs_dirty; + bool dual_src = util_blend_state_is_dual(&ctx->sub->blend_state, 0); + if (!ctx->sub->vs || !ctx->sub->fs) { + fprintf(stderr,"dropping rendering due to missing shaders: %s\n", ctx->debug_name); + return; + } + + vrend_shader_select(ctx, ctx->sub->fs, &fs_dirty); + vrend_shader_select(ctx, ctx->sub->vs, &vs_dirty); + if (ctx->sub->gs) + vrend_shader_select(ctx, ctx->sub->gs, &gs_dirty); + + if (!ctx->sub->vs->current || !ctx->sub->fs->current || (ctx->sub->gs && !ctx->sub->gs->current)) { + fprintf(stderr, "failure to compile shader variants: %s\n", ctx->debug_name); + return; + } + prog = lookup_shader_program(ctx, ctx->sub->vs->current->id, ctx->sub->fs->current->id, ctx->sub->gs ? ctx->sub->gs->current->id : 0, dual_src); + if (!prog) { + prog = add_shader_program(ctx, ctx->sub->vs->current, ctx->sub->fs->current, ctx->sub->gs ? ctx->sub->gs->current : NULL); + if (!prog) + return; + } + if (ctx->sub->prog != prog) { + new_program = true; + ctx->sub->prog = prog; + } } glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ctx->sub->fb_id); @@ -2643,7 +2642,7 @@ void vrend_draw_vbo(struct vrend_context *ctx, case 1: elsz = GL_UNSIGNED_BYTE; break; - case 2: + case 2: elsz = GL_UNSIGNED_SHORT; break; case 4: @@ -2765,7 +2764,7 @@ static GLenum translate_stencil_op(GLuint op) { switch (op) { -#define CASE(x) case PIPE_STENCIL_OP_##x: return GL_##x +#define CASE(x) case PIPE_STENCIL_OP_##x: return GL_##x CASE(KEEP); CASE(ZERO); CASE(REPLACE); @@ -2823,29 +2822,29 @@ static void vrend_patch_blend_func(struct vrend_context *ctx) is_dst_blend(state->rt[i].alpha_src_factor) || is_dst_blend(state->rt[i].alpha_dst_factor))) continue; - + rsf = translate_blend_factor(conv_dst_blend(state->rt[i].rgb_src_factor)); rdf = translate_blend_factor(conv_dst_blend(state->rt[i].rgb_dst_factor)); asf = translate_blend_factor(conv_dst_blend(state->rt[i].alpha_src_factor)); adf = translate_blend_factor(conv_dst_blend(state->rt[i].alpha_dst_factor)); - + glBlendFuncSeparateiARB(i, rsf, rdf, asf, adf); } } } else { if (state->rt[0].blend_enable) { - if (!(is_dst_blend(state->rt[0].rgb_src_factor) || - is_dst_blend(state->rt[0].rgb_dst_factor) || - is_dst_blend(state->rt[0].alpha_src_factor) || - is_dst_blend(state->rt[0].alpha_dst_factor))) - return; + if (!(is_dst_blend(state->rt[0].rgb_src_factor) || + is_dst_blend(state->rt[0].rgb_dst_factor) || + is_dst_blend(state->rt[0].alpha_src_factor) || + is_dst_blend(state->rt[0].alpha_dst_factor))) + return; - rsf = translate_blend_factor(conv_dst_blend(state->rt[i].rgb_src_factor)); - rdf = translate_blend_factor(conv_dst_blend(state->rt[i].rgb_dst_factor)); - asf = translate_blend_factor(conv_dst_blend(state->rt[i].alpha_src_factor)); - adf = translate_blend_factor(conv_dst_blend(state->rt[i].alpha_dst_factor)); + rsf = translate_blend_factor(conv_dst_blend(state->rt[i].rgb_src_factor)); + rdf = translate_blend_factor(conv_dst_blend(state->rt[i].rgb_dst_factor)); + asf = translate_blend_factor(conv_dst_blend(state->rt[i].alpha_src_factor)); + adf = translate_blend_factor(conv_dst_blend(state->rt[i].alpha_dst_factor)); - glBlendFuncSeparate(rsf, rdf, asf, adf); + glBlendFuncSeparate(rsf, rdf, asf, adf); } } } @@ -2870,11 +2869,11 @@ static void vrend_hw_emit_blend(struct vrend_context *ctx) for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { if (state->rt[i].blend_enable) { glBlendFuncSeparateiARB(i, translate_blend_factor(state->rt[i].rgb_src_factor), - translate_blend_factor(state->rt[i].rgb_dst_factor), - translate_blend_factor(state->rt[i].alpha_src_factor), - translate_blend_factor(state->rt[i].alpha_dst_factor)); + translate_blend_factor(state->rt[i].rgb_dst_factor), + translate_blend_factor(state->rt[i].alpha_src_factor), + translate_blend_factor(state->rt[i].alpha_dst_factor)); glBlendEquationSeparateiARB(i, translate_blend_func(state->rt[0].rgb_func), - translate_blend_func(state->rt[0].alpha_func)); + translate_blend_func(state->rt[0].alpha_func)); glEnableIndexedEXT(GL_BLEND, i); } else glDisableIndexedEXT(GL_BLEND, i); @@ -2896,7 +2895,7 @@ static void vrend_hw_emit_blend(struct vrend_context *ctx) glBlendEquationSeparate(translate_blend_func(state->rt[0].rgb_func), translate_blend_func(state->rt[0].alpha_func)); vrend_blend_enable(ctx, true); - } + } else vrend_blend_enable(ctx, false); @@ -2916,7 +2915,7 @@ static void vrend_hw_emit_blend(struct vrend_context *ctx) glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); else glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); - + if (state->alpha_to_one) glEnable(GL_SAMPLE_ALPHA_TO_ONE); else @@ -2958,7 +2957,7 @@ static void vrend_hw_emit_dsa(struct vrend_context *ctx) glDepthMask(GL_FALSE); } else vrend_depth_test_enable(ctx, false); - + if (state->alpha.enabled) { vrend_alpha_test_enable(ctx, true); if (!vrend_state.use_core_profile) @@ -3021,7 +3020,7 @@ void vrend_update_stencil_state(struct vrend_context *ctx) if (state->stencil[0].enabled) { vrend_stencil_test_enable(ctx, true); - glStencilOp(translate_stencil_op(state->stencil[0].fail_op), + glStencilOp(translate_stencil_op(state->stencil[0].fail_op), translate_stencil_op(state->stencil[0].zfail_op), translate_stencil_op(state->stencil[0].zpass_op)); @@ -3080,7 +3079,7 @@ static void vrend_hw_emit_rs(struct vrend_context *ctx) } else { glDisable(GL_PROGRAM_POINT_SIZE); if (state->point_size) - glPointSize(state->point_size); + glPointSize(state->point_size); } if (state->rasterizer_discard != ctx->sub->hw_rs_state.rasterizer_discard) { @@ -3194,7 +3193,7 @@ static void vrend_hw_emit_rs(struct vrend_context *ctx) else glDisable(GL_LINE_STIPPLE); } else if (state->line_stipple_enable) - report_core_warn(ctx, CORE_PROFILE_WARN_STIPPLE, 0); + report_core_warn(ctx, CORE_PROFILE_WARN_STIPPLE, 0); if (state->line_smooth) glEnable(GL_LINE_SMOOTH); @@ -3243,7 +3242,7 @@ void vrend_object_bind_rasterizer(struct vrend_context *ctx, } state = vrend_object_lookup(ctx->sub->object_hash, handle, VIRGL_OBJECT_RASTERIZER); - + if (!state) { report_context_error(ctx, VIRGL_ERROR_CTX_ILLEGAL_HANDLE, handle); return; @@ -3271,7 +3270,7 @@ void vrend_bind_sampler_states(struct vrend_context *ctx, state = NULL; else state = vrend_object_lookup(ctx->sub->object_hash, handles[i], VIRGL_OBJECT_SAMPLER_STATE); - + ctx->sub->sampler_state[shader_type][i + start_slot] = state; } ctx->sub->sampler_state_dirty = true; @@ -3309,7 +3308,7 @@ static void vrend_apply_sampler_state(struct vrend_context *ctx, if (vrend_state.have_samplers) { glBindSampler(sampler_id, vstate->id); glSamplerParameteri(vstate->id, GL_TEXTURE_SRGB_DECODE_EXT, - srgb_decode); + srgb_decode); return; } @@ -3428,7 +3427,7 @@ void vrend_renderer_init(struct vrend_if_cbs *cbs) 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 (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")) @@ -3477,7 +3476,7 @@ static void vrend_destroy_sub_context(struct vrend_sub_context *sub) if (sub->fb_id) glDeleteFramebuffers(1, &sub->fb_id); - + if (sub->blit_fb_ids[0]) glDeleteFramebuffers(2, sub->blit_fb_ids); @@ -3495,7 +3494,7 @@ static void vrend_destroy_sub_context(struct vrend_sub_context *sub) glBindVertexArray(0); if (sub->current_so) - glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0); + glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0); LIST_FOR_EACH_ENTRY_SAFE(obj, tmp, &sub->streamout_list, head) { vrend_destroy_streamout_object(obj); @@ -3541,7 +3540,7 @@ bool vrend_destroy_context(struct vrend_context *ctx) vrend_set_index_buffer(ctx, 0, 0, 0); LIST_FOR_EACH_ENTRY_SAFE(sub, tmp, &ctx->sub_ctxs, head) - vrend_destroy_sub_context(sub); + vrend_destroy_sub_context(sub); vrend_object_fini_ctx_table(ctx->res_hash); @@ -3582,10 +3581,10 @@ struct vrend_context *vrend_create_context(int id, uint32_t nlen, const char *de } int vrend_renderer_resource_attach_iov(int res_handle, struct iovec *iov, - int num_iovs) + int num_iovs) { struct vrend_resource *res; - + res = vrend_resource_lookup(res_handle, 0); if (!res) return EINVAL; @@ -3597,8 +3596,8 @@ int vrend_renderer_resource_attach_iov(int res_handle, struct iovec *iov, } void vrend_renderer_resource_detach_iov(int res_handle, - struct iovec **iov_p, - int *num_iovs_p) + struct iovec **iov_p, + int *num_iovs_p) { struct vrend_resource *res; res = vrend_resource_lookup(res_handle, 0); @@ -3606,9 +3605,9 @@ void vrend_renderer_resource_detach_iov(int res_handle, return; } if (iov_p) - *iov_p = res->iov; + *iov_p = res->iov; if (num_iovs_p) - *num_iovs_p = res->num_iovs; + *num_iovs_p = res->num_iovs; res->iov = NULL; res->num_iovs = 0; @@ -3616,79 +3615,79 @@ void vrend_renderer_resource_detach_iov(int res_handle, static int check_resource_valid(struct vrend_renderer_resource_create_args *args) { - /* limit the target */ - if (args->target >= PIPE_MAX_TEXTURE_TYPES) - return -1; - - if (args->format >= VIRGL_FORMAT_MAX) - return -1; - - /* only texture 2d and 2d array can have multiple samples */ - if (args->nr_samples > 1) { - if (args->target != PIPE_TEXTURE_2D && args->target != PIPE_TEXTURE_2D_ARRAY) - return -1; - /* multisample can't have miplevels */ - if (args->last_level > 0) - return -1; - } - - if (args->last_level > 0) { - /* buffer and rect textures can't have mipmaps */ - if (args->target == PIPE_BUFFER || args->target == PIPE_TEXTURE_RECT) - return -1; - } - if (args->flags != 0 && args->flags != VIRGL_RESOURCE_Y_0_TOP) + /* limit the target */ + if (args->target >= PIPE_MAX_TEXTURE_TYPES) + return -1; + + if (args->format >= VIRGL_FORMAT_MAX) + return -1; + + /* only texture 2d and 2d array can have multiple samples */ + if (args->nr_samples > 1) { + if (args->target != PIPE_TEXTURE_2D && args->target != PIPE_TEXTURE_2D_ARRAY) + return -1; + /* multisample can't have miplevels */ + if (args->last_level > 0) + return -1; + } + + if (args->last_level > 0) { + /* buffer and rect textures can't have mipmaps */ + if (args->target == PIPE_BUFFER || args->target == PIPE_TEXTURE_RECT) + return -1; + } + if (args->flags != 0 && args->flags != VIRGL_RESOURCE_Y_0_TOP) return -1; - if (args->flags & VIRGL_RESOURCE_Y_0_TOP) + if (args->flags & VIRGL_RESOURCE_Y_0_TOP) if (args->target != PIPE_TEXTURE_2D && args->target != PIPE_TEXTURE_RECT) - return -1; - - /* array size for array textures only */ - if (args->target == PIPE_TEXTURE_CUBE) { - if (args->array_size != 6) - return -1; - } else if (args->target == PIPE_TEXTURE_CUBE_ARRAY) { - if (args->array_size % 6) - return -1; - } else if (args->array_size > 1) { - if (args->target != PIPE_TEXTURE_2D_ARRAY && - args->target != PIPE_TEXTURE_1D_ARRAY) - return -1; - } - - if (args->bind == 0 || - args->bind == VREND_RES_BIND_CUSTOM || - args->bind == VREND_RES_BIND_INDEX_BUFFER || - args->bind == VREND_RES_BIND_STREAM_OUTPUT || - args->bind == VREND_RES_BIND_VERTEX_BUFFER || - args->bind == VREND_RES_BIND_CONSTANT_BUFFER) { - if (args->target != PIPE_BUFFER) - return -1; - if (args->height != 1 || args->depth != 1) - return -1; - } else { - if (!((args->bind & VREND_RES_BIND_SAMPLER_VIEW) || - (args->bind & VREND_RES_BIND_DEPTH_STENCIL) || - (args->bind & VREND_RES_BIND_RENDER_TARGET) || - (args->bind & VREND_RES_BIND_CURSOR))) - return -1; - - if (args->target == PIPE_TEXTURE_2D || - args->target == PIPE_TEXTURE_RECT || - args->target == PIPE_TEXTURE_CUBE || - args->target == PIPE_TEXTURE_2D_ARRAY || - args->target == PIPE_TEXTURE_CUBE_ARRAY) { - if (args->depth != 1) - return -1; - } - if (args->target == PIPE_TEXTURE_1D || - args->target == PIPE_TEXTURE_1D_ARRAY) { - if (args->height != 1 || args->depth != 1) - return -1; - } - } - return 0; + return -1; + + /* array size for array textures only */ + if (args->target == PIPE_TEXTURE_CUBE) { + if (args->array_size != 6) + return -1; + } else if (args->target == PIPE_TEXTURE_CUBE_ARRAY) { + if (args->array_size % 6) + return -1; + } else if (args->array_size > 1) { + if (args->target != PIPE_TEXTURE_2D_ARRAY && + args->target != PIPE_TEXTURE_1D_ARRAY) + return -1; + } + + if (args->bind == 0 || + args->bind == VREND_RES_BIND_CUSTOM || + args->bind == VREND_RES_BIND_INDEX_BUFFER || + args->bind == VREND_RES_BIND_STREAM_OUTPUT || + args->bind == VREND_RES_BIND_VERTEX_BUFFER || + args->bind == VREND_RES_BIND_CONSTANT_BUFFER) { + if (args->target != PIPE_BUFFER) + return -1; + if (args->height != 1 || args->depth != 1) + return -1; + } else { + if (!((args->bind & VREND_RES_BIND_SAMPLER_VIEW) || + (args->bind & VREND_RES_BIND_DEPTH_STENCIL) || + (args->bind & VREND_RES_BIND_RENDER_TARGET) || + (args->bind & VREND_RES_BIND_CURSOR))) + return -1; + + if (args->target == PIPE_TEXTURE_2D || + args->target == PIPE_TEXTURE_RECT || + args->target == PIPE_TEXTURE_CUBE || + args->target == PIPE_TEXTURE_2D_ARRAY || + args->target == PIPE_TEXTURE_CUBE_ARRAY) { + if (args->depth != 1) + return -1; + } + if (args->target == PIPE_TEXTURE_1D || + args->target == PIPE_TEXTURE_1D_ARRAY) { + if (args->height != 1 || args->depth != 1) + return -1; + } + } + return 0; } int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs) { @@ -3698,7 +3697,7 @@ int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *a ret = check_resource_valid(args); if (ret) - return EINVAL; + return EINVAL; gr = (struct vrend_resource *)CALLOC_STRUCT(vrend_texture); if (!gr) @@ -3968,19 +3967,19 @@ static bool check_transfer_bounds(struct vrend_resource *res, /* these will catch bad y/z/w/d with 1D textures etc */ lwidth = u_minify(res->base.width0, info->level); if (info->box->width > lwidth) - return false; + return false; if (info->box->x > lwidth) - return false; + return false; if (info->box->width + info->box->x > lwidth) - return false; + return false; lheight = u_minify(res->base.height0, info->level); if (info->box->height > lheight) - return false; + return false; if (info->box->y > lheight) - return false; + return false; if (info->box->height + info->box->y > lheight) - return false; + return false; if (res->base.target == PIPE_TEXTURE_3D) { int ldepth = u_minify(res->base.depth0, info->level); @@ -4006,56 +4005,56 @@ static bool check_iov_bounds(struct vrend_resource *res, const struct vrend_transfer_info *info, struct iovec *iov, int num_iovs) { - GLuint send_size; - GLuint iovsize = vrend_get_iovec_size(iov, num_iovs); - GLuint valid_stride, valid_layer_stride; - - /* validate the send size */ - valid_stride = util_format_get_stride(res->base.format, info->box->width); - if (info->stride) { - /* only validate passed in stride for boxes with height */ - if (info->box->height > 1) { - if (info->stride < valid_stride) - return false; - valid_stride = info->stride; - } - } - - valid_layer_stride = util_format_get_2d_size(res->base.format, valid_stride, - info->box->height); - - /* layer stride only makes sense for 3d,cube and arrays */ - if (info->layer_stride) { - if ((res->base.target != PIPE_TEXTURE_3D && - res->base.target != PIPE_TEXTURE_CUBE && - res->base.target != PIPE_TEXTURE_1D_ARRAY && - res->base.target != PIPE_TEXTURE_2D_ARRAY && - res->base.target != PIPE_TEXTURE_CUBE_ARRAY)) - return false; - - /* only validate passed in layer_stride for boxes with depth */ - if (info->box->depth > 1) { - if (info->layer_stride < valid_layer_stride) - return false; - valid_layer_stride = info->layer_stride; - } - } - - send_size = valid_layer_stride * info->box->depth; - if (iovsize < info->offset) - return false; - if (iovsize < send_size) - return false; - if (iovsize < info->offset + send_size) - return false; - - return true; + GLuint send_size; + GLuint iovsize = vrend_get_iovec_size(iov, num_iovs); + GLuint valid_stride, valid_layer_stride; + + /* validate the send size */ + valid_stride = util_format_get_stride(res->base.format, info->box->width); + if (info->stride) { + /* only validate passed in stride for boxes with height */ + if (info->box->height > 1) { + if (info->stride < valid_stride) + return false; + valid_stride = info->stride; + } + } + + valid_layer_stride = util_format_get_2d_size(res->base.format, valid_stride, + info->box->height); + + /* layer stride only makes sense for 3d,cube and arrays */ + if (info->layer_stride) { + if ((res->base.target != PIPE_TEXTURE_3D && + res->base.target != PIPE_TEXTURE_CUBE && + res->base.target != PIPE_TEXTURE_1D_ARRAY && + res->base.target != PIPE_TEXTURE_2D_ARRAY && + res->base.target != PIPE_TEXTURE_CUBE_ARRAY)) + return false; + + /* only validate passed in layer_stride for boxes with depth */ + if (info->box->depth > 1) { + if (info->layer_stride < valid_layer_stride) + return false; + valid_layer_stride = info->layer_stride; + } + } + + send_size = valid_layer_stride * info->box->depth; + if (iovsize < info->offset) + return false; + if (iovsize < send_size) + return false; + if (iovsize < info->offset + send_size) + return false; + + return true; } 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) + struct vrend_resource *res, + struct iovec *iov, int num_iovs, + const struct vrend_transfer_info *info) { void *data; @@ -4147,14 +4146,14 @@ static int vrend_renderer_transfer_write_iov(struct vrend_context *ctx, } glformat = tex_conv_table[res->base.format].glformat; - gltype = tex_conv_table[res->base.format].gltype; + 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); @@ -4270,7 +4269,7 @@ static int vrend_transfer_send_getteximage(struct vrend_context *ctx, uint32_t depth = 1; uint32_t send_offset = 0; format = tex_conv_table[res->base.format].glformat; - type = tex_conv_table[res->base.format].gltype; + type = tex_conv_table[res->base.format].gltype; if (compressed) format = tex_conv_table[res->base.format].internalformat; @@ -4281,7 +4280,7 @@ static int vrend_transfer_send_getteximage(struct vrend_context *ctx, depth = res->base.array_size; tex_size = util_format_get_nblocks(res->base.format, u_minify(res->base.width0, info->level), u_minify(res->base.height0, info->level)) * util_format_get_blocksize(res->base.format) * depth; - + send_size = util_format_get_nblocks(res->base.format, info->box->width, info->box->height) * util_format_get_blocksize(res->base.format) * info->box->depth; if (info->box->z && res->target != GL_TEXTURE_CUBE_MAP) { @@ -4313,7 +4312,7 @@ static int vrend_transfer_send_getteximage(struct vrend_context *ctx, target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + info->box->z; } else target = res->target; - + if (compressed) { if (vrend_state.have_robustness) glGetnCompressedTexImageARB(target, info->level, tex_size, data); @@ -4325,7 +4324,7 @@ static int vrend_transfer_send_getteximage(struct vrend_context *ctx, else glGetTexImage(target, info->level, format, type, data); } - + glPixelStorei(GL_PACK_ALIGNMENT, 4); vrend_transfer_write_tex_return(&res->base, info->box, info->level, @@ -4355,7 +4354,7 @@ static int vrend_transfer_send_readpixels(struct vrend_context *ctx, vrend_use_program(ctx, 0); format = tex_conv_table[res->base.format].glformat; - type = tex_conv_table[res->base.format].gltype; + type = tex_conv_table[res->base.format].gltype; /* if we are asked to invert and reading from a front then don't */ actually_invert = res->y_0_top; @@ -4382,7 +4381,7 @@ static int vrend_transfer_send_readpixels(struct vrend_context *ctx, if (res->readback_fb_id) glDeleteFramebuffers(1, &res->readback_fb_id); - + glGenFramebuffers(1, &fb_id); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb_id); @@ -4419,7 +4418,7 @@ static int vrend_transfer_send_readpixels(struct vrend_context *ctx, case 8: glPixelStorei(GL_PACK_ALIGNMENT, 8); break; - } + } if (res->base.format == (enum pipe_format)VIRGL_FORMAT_Z24X8_UNORM) { /* we get values from the guest as 24-bit scaled integers @@ -4514,9 +4513,9 @@ int vrend_renderer_transfer_iov(const struct vrend_transfer_info *info, return EINVAL; if (info->ctx_id == 0) - res = vrend_resource_lookup(info->handle, 0); + res = vrend_resource_lookup(info->handle, 0); else - res = vrend_renderer_ctx_res_lookup(ctx, info->handle); + res = vrend_renderer_ctx_res_lookup(ctx, info->handle); if (!res) { if (info->ctx_id) @@ -4589,7 +4588,6 @@ void vrend_set_stencil_ref(struct vrend_context *ctx, ctx->sub->stencil_refs[1] = ref->ref_value[1]; ctx->sub->stencil_state_dirty = true; } - } void vrend_set_blend_color(struct vrend_context *ctx, @@ -4722,8 +4720,8 @@ void vrend_set_streamout_targets(struct vrend_context *ctx, ctx->sub->current_so = obj; obj->xfb_state = XFB_STATE_STARTED_NEED_BEGIN; } else { - glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0); - ctx->sub->current_so = NULL; + glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0); + ctx->sub->current_so = NULL; } } @@ -4776,11 +4774,11 @@ static void vrend_resource_copy_fallback(struct vrend_context *ctx, return; glformat = tex_conv_table[src_res->base.format].glformat; - gltype = tex_conv_table[src_res->base.format].gltype; + 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); @@ -4865,12 +4863,12 @@ static void vrend_resource_copy_fallback(struct vrend_context *ctx, } 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) + 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; + struct vrend_resource *src_res, *dst_res; GLbitfield glmask = 0; GLint sy1, sy2, dy1, dy2; @@ -4909,7 +4907,7 @@ void vrend_renderer_resource_copy_region(struct vrend_context *ctx, 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); @@ -4981,7 +4979,7 @@ static void vrend_renderer_blit_int(struct vrend_context *ctx, /* glBlitFramebuffer - can support depth stencil with NEAREST which we use for mipmaps */ if ((info->mask & (PIPE_MASK_Z | PIPE_MASK_S)) && info->filter == PIPE_TEX_FILTER_LINEAR) - use_gl = true; + use_gl = true; /* for scaled MS blits we either need extensions or hand roll */ if (src_res->base.nr_samples > 1 && @@ -5077,8 +5075,8 @@ static void vrend_renderer_blit_int(struct vrend_context *ctx, } void vrend_renderer_blit(struct vrend_context *ctx, - uint32_t dst_handle, uint32_t src_handle, - const struct pipe_blit_info *info) + uint32_t dst_handle, uint32_t src_handle, + const struct pipe_blit_info *info) { struct vrend_resource *src_res, *dst_res; src_res = vrend_renderer_ctx_res_lookup(ctx, src_handle); @@ -5105,7 +5103,7 @@ int vrend_renderer_create_fence(int client_fence_id, uint32_t ctx_id) fence = malloc(sizeof(struct vrend_fence)); if (!fence) - return ENOMEM; + return ENOMEM; fence->ctx_id = ctx_id; fence->fence_id = client_fence_id; @@ -5171,7 +5169,7 @@ static bool vrend_check_query(struct vrend_query *query) ret = vrend_get_one_query_result(query->id, false, &result); if (ret == false) - return false; + return false; state = query->res->ptr; state->result = result; @@ -5184,8 +5182,8 @@ void vrend_renderer_check_queries(void) struct vrend_query *query, *stor; if (!vrend_state.inited) - return; - + return; + LIST_FOR_EACH_ENTRY_SAFE(query, stor, &vrend_state.waiting_query_list, waiting_queries) { vrend_hw_switch_context(vrend_lookup_renderer_ctx(query->ctx_id), true); if (vrend_check_query(query)) @@ -5232,7 +5230,7 @@ vrend_renderer_object_destroy(struct vrend_context *ctx, uint32_t handle) } uint32_t vrend_renderer_object_insert(struct vrend_context *ctx, void *data, - uint32_t size, uint32_t handle, enum virgl_object_type type) + uint32_t size, uint32_t handle, enum virgl_object_type type) { return vrend_object_insert(ctx->sub->object_hash, data, size, handle, type); } @@ -5262,7 +5260,7 @@ int vrend_create_query(struct vrend_context *ctx, uint32_t handle, switch (q->type) { case PIPE_QUERY_OCCLUSION_COUNTER: - q->gltype = GL_SAMPLES_PASSED_ARB; + q->gltype = GL_SAMPLES_PASSED_ARB; break; case PIPE_QUERY_OCCLUSION_PREDICATE: q->gltype = GL_ANY_SAMPLES_PASSED; @@ -5333,7 +5331,7 @@ void vrend_end_query(struct vrend_context *ctx, uint32_t handle) if (vrend_is_timer_query(q->gltype)) { if (q->gltype == GL_TIMESTAMP) glQueryCounter(q->id, q->gltype); - /* remove from active query list for this context */ + /* remove from active query list for this context */ else glEndQuery(q->gltype); return; @@ -5446,14 +5444,14 @@ static void vrender_get_glsl_version(int *glsl_version) } void vrend_renderer_fill_caps(uint32_t set, uint32_t version, - union virgl_caps *caps) + union virgl_caps *caps) { int i; GLint max; int gl_ver = epoxy_gl_version(); if (!caps) - return; + return; memset(caps, 0, sizeof(*caps)); @@ -5510,7 +5508,7 @@ void vrend_renderer_fill_caps(uint32_t set, uint32_t version, caps->v1.bset.seamless_cube_map_per_texture = 1; if (epoxy_has_gl_extension("GL_ARB_texture_multisample")) { - /* disable multisample until developed */ + /* disable multisample until developed */ caps->v1.bset.texture_multisample = 1; } if (gl_ver >= 40) { @@ -5531,7 +5529,7 @@ void vrend_renderer_fill_caps(uint32_t set, uint32_t version, } 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; @@ -5578,8 +5576,8 @@ void vrend_renderer_fill_caps(uint32_t set, uint32_t version, } 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; + 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")) { @@ -5649,11 +5647,11 @@ void *vrend_renderer_get_cursor_contents(uint32_t res_handle, uint32_t *width, u return NULL; if (width) - *width = res->base.width0; + *width = res->base.width0; if (height) - *height = res->base.height0; + *height = res->base.height0; format = tex_conv_table[res->base.format].glformat; - type = tex_conv_table[res->base.format].gltype; + 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); @@ -5672,7 +5670,7 @@ void *vrend_renderer_get_cursor_contents(uint32_t res_handle, uint32_t *width, u memcpy(data2 + doff, data + soff, res->base.width0 * blsize); } free(data); - + return data2; } @@ -5686,7 +5684,7 @@ void vrend_renderer_force_ctx_0(void) } 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) + 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; @@ -5719,11 +5717,11 @@ void vrend_renderer_attach_res_ctx(int ctx_id, int resource_id) struct vrend_resource *res; if (!ctx) - return; + return; res = vrend_resource_lookup(resource_id, 0); if (!res) - return; + return; vrend_object_insert_nofree(ctx->res_hash, res, sizeof(*res), resource_id, 1, false); } @@ -5759,7 +5757,7 @@ int vrend_renderer_resource_get_info(int res_handle, int elsize; if (!info) - return EINVAL; + return EINVAL; res = vrend_resource_lookup(res_handle, 0); if (!res) return EINVAL; @@ -5779,8 +5777,8 @@ int vrend_renderer_resource_get_info(int res_handle, } void vrend_renderer_get_cap_set(uint32_t cap_set, uint32_t *max_ver, - uint32_t *max_size) -{ + uint32_t *max_size) +{ if (cap_set != VREND_CAP_SET) { *max_ver = 0; *max_size = 0; @@ -5830,7 +5828,7 @@ void vrend_renderer_create_sub_ctx(struct vrend_context *ctx, int sub_ctx_id) ctx->sub = sub; list_add(&sub->head, &ctx->sub_ctxs); if (sub_ctx_id == 0) - ctx->sub0 = sub; + ctx->sub0 = sub; } @@ -5845,7 +5843,7 @@ void vrend_renderer_destroy_sub_ctx(struct vrend_context *ctx, int sub_ctx_id) LIST_FOR_EACH_ENTRY(sub, &ctx->sub_ctxs, head) { if (sub->sub_ctx_id == sub_ctx_id) { tofree = sub; - } + } } if (tofree) { @@ -5872,7 +5870,7 @@ void vrend_renderer_set_sub_ctx(struct vrend_context *ctx, int sub_ctx_id) break; } } -} +} static void vrend_reset_fences(void) { diff --git a/src/vrend_renderer.h b/src/vrend_renderer.h index 5578992..2b53e4a 100644 --- a/src/vrend_renderer.h +++ b/src/vrend_renderer.h @@ -79,15 +79,15 @@ struct vrend_format_table { }; struct vrend_transfer_info { - uint32_t handle; - uint32_t ctx_id; - int level; - uint32_t stride; - uint32_t layer_stride; - struct pipe_box *box; - uint64_t offset; - struct iovec *iovec; - unsigned int iovec_cnt; + uint32_t handle; + uint32_t ctx_id; + int level; + uint32_t stride; + uint32_t layer_stride; + struct pipe_box *box; + uint64_t offset; + struct iovec *iovec; + unsigned int iovec_cnt; }; struct vrend_if_cbs { @@ -128,7 +128,7 @@ void vrend_draw_vbo(struct vrend_context *ctx, void vrend_set_framebuffer_state(struct vrend_context *ctx, uint32_t nr_cbufs, uint32_t surf_handle[8], - uint32_t zsurf_handle); + uint32_t zsurf_handle); void vrend_flush(struct vrend_context *ctx); @@ -165,7 +165,7 @@ struct vrend_renderer_resource_create_args { uint32_t nr_samples; uint32_t flags; }; - + int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs); void vrend_renderer_resource_unref(uint32_t handle); @@ -202,12 +202,12 @@ void vrend_bind_vertex_elements_state(struct vrend_context *ctx, uint32_t handle); void vrend_set_single_vbo(struct vrend_context *ctx, - int index, - uint32_t stride, - uint32_t buffer_offset, - uint32_t res_handle); + int index, + uint32_t stride, + uint32_t buffer_offset, + uint32_t res_handle); void vrend_set_num_vbo(struct vrend_context *ctx, - int num_vbo); + int num_vbo); int vrend_transfer_inline_write(struct vrend_context *ctx, struct vrend_transfer_info *info, @@ -228,7 +228,7 @@ void vrend_set_single_sampler_view(struct vrend_context *ctx, void vrend_object_bind_blend(struct vrend_context *ctx, uint32_t handle); void vrend_object_bind_dsa(struct vrend_context *ctx, - uint32_t handle); + uint32_t handle); void vrend_object_bind_rasterizer(struct vrend_context *ctx, uint32_t handle); @@ -248,14 +248,14 @@ void vrend_set_index_buffer(struct vrend_context *ctx, int vrend_renderer_transfer_iov(const struct vrend_transfer_info *info, int transfer_mode); 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); + 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); void vrend_renderer_blit(struct vrend_context *ctx, - uint32_t dst_handle, uint32_t src_handle, - const struct pipe_blit_info *info); + uint32_t dst_handle, uint32_t src_handle, + const struct pipe_blit_info *info); void vrend_set_stencil_ref(struct vrend_context *ctx, struct pipe_stencil_ref *ref); void vrend_set_blend_color(struct vrend_context *ctx, struct pipe_blend_color *color); @@ -280,16 +280,16 @@ void vrend_set_uniform_buffer(struct vrend_context *ctx, uint32_t shader, uint32_t res_handle); void vrend_transfer_write_return(void *data, uint32_t bytes, uint64_t offset, - struct iovec *iov, int iovec_cnt); + struct iovec *iov, int iovec_cnt); void vrend_transfer_write_tex_return(struct pipe_resource *res, - struct pipe_box *box, - uint32_t level, - uint32_t dst_stride, - uint64_t offset, - struct iovec *iov, - int num_iovs, - void *myptr, int size, int invert); + struct pipe_box *box, + uint32_t level, + uint32_t dst_stride, + uint64_t offset, + struct iovec *iov, + int num_iovs, + void *myptr, int size, int invert); void vrend_renderer_fini(void); @@ -303,7 +303,7 @@ void vrend_renderer_check_queries(void); bool vrend_hw_switch_context(struct vrend_context *ctx, bool now); uint32_t vrend_renderer_object_insert(struct vrend_context *ctx, void *data, - uint32_t size, uint32_t handle, enum virgl_object_type type); + uint32_t size, uint32_t handle, enum virgl_object_type type); void vrend_renderer_object_destroy(struct vrend_context *ctx, uint32_t handle); int vrend_create_query(struct vrend_context *ctx, uint32_t handle, @@ -321,10 +321,10 @@ void vrend_render_condition(struct vrend_context *ctx, void *vrend_renderer_get_cursor_contents(uint32_t res_handle, uint32_t *width, uint32_t *height); void vrend_bind_va(GLuint vaoid); int vrend_renderer_flush_buffer_res(struct vrend_resource *res, - struct pipe_box *box); + struct pipe_box *box); void vrend_renderer_fill_caps(uint32_t set, uint32_t version, - union virgl_caps *caps); + union virgl_caps *caps); GLint64 vrend_renderer_get_timestamp(void); /* formats */ @@ -350,7 +350,7 @@ vrend_resource_reference(struct vrend_resource **ptr, struct vrend_resource *tex void vrend_renderer_force_ctx_0(void); void vrend_renderer_get_rect(int resource_id, struct iovec *iov, unsigned int num_iovs, - uint32_t offset, int x, int y, int width, int height); + uint32_t offset, int x, int y, int width, int height); void vrend_renderer_attach_res_ctx(int ctx_id, int resource_id); void vrend_renderer_detach_res_ctx(int ctx_id, int resource_id); @@ -372,7 +372,7 @@ int vrend_renderer_resource_get_info(int res_handle, #define VREND_CAP_SET 1 void vrend_renderer_get_cap_set(uint32_t cap_set, uint32_t *max_ver, - uint32_t *max_size); + uint32_t *max_size); void vrend_renderer_create_sub_ctx(struct vrend_context *ctx, int sub_ctx_id); void vrend_renderer_destroy_sub_ctx(struct vrend_context *ctx, int sub_ctx_id); diff --git a/src/vrend_shader.c b/src/vrend_shader.c index bd79936..bdddd31 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -31,12 +31,6 @@ #include #include "vrend_shader.h" extern int vrend_dump_shaders; -/* - * TODO list - * loops - * DDX/DDY/TXD - * missing opcodes - */ /* start convert of tgsi to glsl */ @@ -101,7 +95,7 @@ struct dump_ctx { int ubo_idx[32]; int ubo_sizes[32]; int num_address; - + struct pipe_stream_output_info *so; char **so_names; bool write_so_outputs[PIPE_MAX_SO_OUTPUTS]; @@ -180,7 +174,7 @@ static inline bool fs_emit_layout(struct dump_ctx *ctx) if coord origin is 1 and invert is 0 - emit nothing (lower) if coord_origin is 1 and invert is 1 - emit origin upper left */ if (!(ctx->fs_coord_origin ^ ctx->key->invert_fs_origin)) - return true; + return true; return false; } @@ -482,8 +476,8 @@ iter_declaration(struct tgsi_iterate_context *iter, ctx->outputs[i].override_no_wm = true; ctx->outputs[i].is_int = true; name_prefix = "gl_ViewportIndex"; - if (ctx->glsl_ver_required >= 140) - ctx->has_viewport_idx = true; + if (ctx->glsl_ver_required >= 140) + ctx->has_viewport_idx = true; break; } case TGSI_SEMANTIC_GENERIC: @@ -529,10 +523,10 @@ iter_declaration(struct tgsi_iterate_context *iter, break; case TGSI_FILE_CONSTANT: if (decl->Declaration.Dimension) { - if (ctx->num_ubo >= ARRAY_SIZE(ctx->ubo_idx)) { - fprintf(stderr, "Number of uniforms exceeded, max is %lu\n", ARRAY_SIZE(ctx->ubo_idx)); - return FALSE; - } + if (ctx->num_ubo >= ARRAY_SIZE(ctx->ubo_idx)) { + fprintf(stderr, "Number of uniforms exceeded, max is %lu\n", ARRAY_SIZE(ctx->ubo_idx)); + return FALSE; + } ctx->ubo_idx[ctx->num_ubo] = decl->Dim.Index2D; ctx->ubo_sizes[ctx->num_ubo] = decl->Range.Last + 1; ctx->num_ubo++; @@ -559,7 +553,7 @@ iter_declaration(struct tgsi_iterate_context *iter, name_prefix = "gl_InstanceID"; ctx->has_instanceid = true; } else if (decl->Semantic.Name == TGSI_SEMANTIC_VERTEXID) { - name_prefix = "gl_VertexID"; + name_prefix = "gl_VertexID"; ctx->has_ints = true; } else { fprintf(stderr, "unsupported system value %d\n", decl->Semantic.Name); @@ -618,8 +612,8 @@ iter_immediate( int first = ctx->num_imm; if (first >= ARRAY_SIZE(ctx->imm)) { - fprintf(stderr, "Number of immediates exceeded, max is: %lu\n", ARRAY_SIZE(ctx->imm)); - return FALSE; + fprintf(stderr, "Number of immediates exceeded, max is: %lu\n", ARRAY_SIZE(ctx->imm)); + return FALSE; } ctx->imm[first].type = imm->Immediate.DataType; @@ -632,7 +626,7 @@ iter_immediate( } else if (imm->Immediate.DataType == TGSI_IMM_INT32) { ctx->has_ints = true; ctx->imm[first].val[i].i = imm->u[i].Int; - } + } } ctx->num_imm++; return TRUE; @@ -725,7 +719,7 @@ static int emit_prescale(struct dump_ctx *ctx) { char buf[255]; char *sret; - + snprintf(buf, 255, "gl_Position.y = gl_Position.y * winsys_adjust.y;\n"); sret = add_str_to_glsl_main(ctx, buf); if (!sret) @@ -763,13 +757,13 @@ static int emit_so_movs(struct dump_ctx *ctx) writemask[0] = 0; if (ctx->so->output[i].num_components == 4 && writemask[0] == 0 && !(ctx->outputs[ctx->so->output[i].register_index].name == TGSI_SEMANTIC_CLIPDIST) && !(ctx->outputs[ctx->so->output[i].register_index].name == TGSI_SEMANTIC_POSITION)) { - if (ctx->so->output[i].register_index > ctx->num_outputs) - ctx->so_names[i] = NULL; - else if (ctx->outputs[ctx->so->output[i].register_index].name == TGSI_SEMANTIC_CLIPVERTEX && ctx->has_clipvertex) { - ctx->so_names[i] = strdup("clipv_tmp"); - ctx->has_clipvertex_so = true; - } else - ctx->so_names[i] = strdup(ctx->outputs[ctx->so->output[i].register_index].glsl_name); + if (ctx->so->output[i].register_index > ctx->num_outputs) + ctx->so_names[i] = NULL; + else if (ctx->outputs[ctx->so->output[i].register_index].name == TGSI_SEMANTIC_CLIPVERTEX && ctx->has_clipvertex) { + ctx->so_names[i] = strdup("clipv_tmp"); + ctx->has_clipvertex_so = true; + } else + ctx->so_names[i] = strdup(ctx->outputs[ctx->so->output[i].register_index].glsl_name); ctx->write_so_outputs[i] = false; } else { @@ -858,19 +852,19 @@ static int emit_buf(struct dump_ctx *ctx, char *buf) return sret ? 0 : ENOMEM; } -#define EMIT_BUF_WITH_RET(ctx, buf) do { \ - int ret = emit_buf((ctx), (buf)); \ - if (ret) return FALSE; \ +#define EMIT_BUF_WITH_RET(ctx, buf) do { \ + int ret = emit_buf((ctx), (buf)); \ + if (ret) return FALSE; \ } while(0) static int translate_tex(struct dump_ctx *ctx, - struct tgsi_full_instruction *inst, - int sreg_index, - char srcs[4][255], - char dsts[3][255], - const char *writemask, - const char *dstconv, - const char *dtypeprefix) + struct tgsi_full_instruction *inst, + int sreg_index, + char srcs[4][255], + char dsts[3][255], + const char *writemask, + const char *dstconv, + const char *dtypeprefix) { char *twm, *gwm = NULL, *txfi; bool is_shad = false; @@ -929,12 +923,12 @@ static int translate_tex(struct dump_ctx *ctx, /* need to emit a textureQueryLevels */ if (inst->Dst[0].Register.WriteMask & 0x8) { - ctx->uses_txq_levels = true; - snprintf(buf, 255, "%s = %s(%s(textureQueryLevels(%s)));\n", dsts[0], dstconv, dtypeprefix, srcs[sampler_index]); - return emit_buf(ctx, buf); + ctx->uses_txq_levels = true; + snprintf(buf, 255, "%s = %s(%s(textureQueryLevels(%s)));\n", dsts[0], dstconv, dtypeprefix, srcs[sampler_index]); + return emit_buf(ctx, buf); } else { - snprintf(buf, 255, "%s = %s(%s(textureSize(%s%s)));\n", dsts[0], dstconv, dtypeprefix, srcs[sampler_index], bias); - return emit_buf(ctx, buf); + snprintf(buf, 255, "%s = %s(%s(textureSize(%s%s)));\n", dsts[0], dstconv, dtypeprefix, srcs[sampler_index], bias); + return emit_buf(ctx, buf); } } @@ -1070,9 +1064,9 @@ static int translate_tex(struct dump_ctx *ctx, tex_ext = "Grad"; } else if (inst->Instruction.Opcode == TGSI_OPCODE_TG4) { if (inst->Texture.NumOffsets == 1) - tex_ext = "GatherOffset"; + tex_ext = "GatherOffset"; else - tex_ext = "Gather"; + tex_ext = "Gather"; } else { if (inst->Texture.NumOffsets == 1) tex_ext = "Offset"; @@ -1160,13 +1154,13 @@ iter_instruction(struct tgsi_iterate_context *iter, } else { switch (dtype) { case TGSI_TYPE_UNSIGNED: - dtypeprefix = "uintBitsToFloat"; - break; + dtypeprefix = "uintBitsToFloat"; + break; case TGSI_TYPE_SIGNED: - dtypeprefix = "intBitsToFloat"; - break; + dtypeprefix = "intBitsToFloat"; + break; default: - break; + break; } } @@ -1216,8 +1210,8 @@ iter_instruction(struct tgsi_iterate_context *iter, snprintf(udstconv, 6, "uvec%d", wm_idx-1); } } else { - snprintf(dstconv, 6, "vec4"); - snprintf(udstconv, 6, "uvec4"); + snprintf(dstconv, 6, "vec4"); + snprintf(udstconv, 6, "uvec4"); } if (dst->Register.File == TGSI_FILE_OUTPUT) { for (j = 0; j < ctx->num_outputs; j++) { @@ -1248,7 +1242,7 @@ iter_instruction(struct tgsi_iterate_context *iter, snprintf(dsts[i], 255, "temps[%d]%s", dst->Register.Index, writemask); } } - + for (i = 0; i < inst->Instruction.NumSrcRegs; i++) { const struct tgsi_full_src_register *src = &inst->Src[i]; char swizzle[8] = {0}; @@ -1256,7 +1250,7 @@ iter_instruction(struct tgsi_iterate_context *iter, char arrayname[8] = {0}; int swz_idx = 0, pre_idx = 0; boolean isabsolute = src->Register.Absolute; - + override_no_wm[i] = false; if (isabsolute) swizzle[swz_idx++] = ')'; @@ -1299,12 +1293,12 @@ iter_instruction(struct tgsi_iterate_context *iter, snprintf(srcs[i], 255, "%s(vec4(intBitsToFloat(%s)))", stypeprefix, ctx->inputs[j].glsl_name); else if (ctx->inputs[j].name == TGSI_SEMANTIC_FACE) snprintf(srcs[i], 255, "%s(%s ? 1.0 : -1.0)", stypeprefix, ctx->inputs[j].glsl_name); - else if (ctx->inputs[j].name == TGSI_SEMANTIC_CLIPDIST) { - int idx; - idx = ctx->inputs[j].sid * 4; - idx += src->Register.SwizzleX; - snprintf(srcs[i], 255, "%s(vec4(%s%s%s[%d]))", stypeprefix, prefix, arrayname, ctx->inputs[j].glsl_name, idx); - } else + else if (ctx->inputs[j].name == TGSI_SEMANTIC_CLIPDIST) { + int idx; + idx = ctx->inputs[j].sid * 4; + idx += src->Register.SwizzleX; + snprintf(srcs[i], 255, "%s(vec4(%s%s%s[%d]))", stypeprefix, prefix, arrayname, ctx->inputs[j].glsl_name, idx); + } else snprintf(srcs[i], 255, "%s(%s%s%s%s)", stypeprefix, prefix, ctx->inputs[j].glsl_name, arrayname, swizzle); override_no_wm[i] = ctx->inputs[j].override_no_wm; break; @@ -1316,33 +1310,33 @@ iter_instruction(struct tgsi_iterate_context *iter, } else snprintf(srcs[i], 255, "%s%c%stemps[%d]%s%c", stypeprefix, stprefix ? '(' : ' ', prefix, src->Register.Index, swizzle, stprefix ? ')' : ' '); } else if (src->Register.File == TGSI_FILE_CONSTANT) { - const char *cname = tgsi_proc_to_prefix(ctx->prog_type); - int dim = 0; - if (src->Register.Dimension) { - dim = src->Dimension.Index; - if (src->Register.Indirect) { - snprintf(srcs[i], 255, "%s(%s%subo%dcontents[addr0 + %d]%s)", stypeprefix, prefix, cname, dim, src->Register.Index, swizzle); - } else - snprintf(srcs[i], 255, "%s(%s%subo%dcontents[%d]%s)", stypeprefix, prefix, cname, dim, src->Register.Index, swizzle); - } else { - const char *csp; - ctx->has_ints = true; - if (stype == TGSI_TYPE_FLOAT || stype == TGSI_TYPE_UNTYPED) - csp = "uintBitsToFloat"; - else if (stype == TGSI_TYPE_SIGNED) - csp = "ivec4"; - else - csp = ""; - - if (src->Register.Indirect) { - snprintf(srcs[i], 255, "%s%s(%sconst%d[addr0 + %d]%s)", prefix, csp, cname, dim, src->Register.Index, swizzle); - } else - snprintf(srcs[i], 255, "%s%s(%sconst%d[%d]%s)", prefix, csp, cname, dim, src->Register.Index, swizzle); - } + const char *cname = tgsi_proc_to_prefix(ctx->prog_type); + int dim = 0; + if (src->Register.Dimension) { + dim = src->Dimension.Index; + if (src->Register.Indirect) { + snprintf(srcs[i], 255, "%s(%s%subo%dcontents[addr0 + %d]%s)", stypeprefix, prefix, cname, dim, src->Register.Index, swizzle); + } else + snprintf(srcs[i], 255, "%s(%s%subo%dcontents[%d]%s)", stypeprefix, prefix, cname, dim, src->Register.Index, swizzle); + } else { + const char *csp; + ctx->has_ints = true; + if (stype == TGSI_TYPE_FLOAT || stype == TGSI_TYPE_UNTYPED) + csp = "uintBitsToFloat"; + else if (stype == TGSI_TYPE_SIGNED) + csp = "ivec4"; + else + csp = ""; + + if (src->Register.Indirect) { + snprintf(srcs[i], 255, "%s%s(%sconst%d[addr0 + %d]%s)", prefix, csp, cname, dim, src->Register.Index, swizzle); + } else + snprintf(srcs[i], 255, "%s%s(%sconst%d[%d]%s)", prefix, csp, cname, dim, src->Register.Index, swizzle); + } } else if (src->Register.File == TGSI_FILE_SAMPLER) { - const char *cname = tgsi_proc_to_prefix(ctx->prog_type); - snprintf(srcs[i], 255, "%ssamp%d%s", cname, src->Register.Index, swizzle); - sreg_index = src->Register.Index; + const char *cname = tgsi_proc_to_prefix(ctx->prog_type); + snprintf(srcs[i], 255, "%ssamp%d%s", cname, src->Register.Index, swizzle); + sreg_index = src->Register.Index; } else if (src->Register.File == TGSI_FILE_IMMEDIATE) { struct immed *imd = &ctx->imm[(src->Register.Index)]; int idx = src->Register.SwizzleX; @@ -1367,7 +1361,6 @@ iter_instruction(struct tgsi_iterate_context *iter, imm_stypeprefix = "uintBitsToFloat"; } else if (stype == TGSI_TYPE_UNSIGNED || stype == TGSI_TYPE_SIGNED) imm_stypeprefix = ""; - } /* build up a vec4 of immediates */ @@ -1519,7 +1512,7 @@ iter_instruction(struct tgsi_iterate_context *iter, case TGSI_OPCODE_SCS: snprintf(buf, 255, "%s = %s(vec4(cos(%s.x), sin(%s.x), 0, 1)%s);\n", dsts[0], dstconv, srcs[0], srcs[0], writemask); - EMIT_BUF_WITH_RET(ctx, buf); + EMIT_BUF_WITH_RET(ctx, buf); break; case TGSI_OPCODE_DDX: emit_op1("dFdx"); @@ -1663,11 +1656,11 @@ iter_instruction(struct tgsi_iterate_context *iter, EMIT_BUF_WITH_RET(ctx, buf); break; case TGSI_OPCODE_F2I: - snprintf(buf, 255, "%s = %s(%s(ivec4(%s)));\n", dsts[0], dstconv, dtypeprefix, srcs[0]); + snprintf(buf, 255, "%s = %s(%s(ivec4(%s)));\n", dsts[0], dstconv, dtypeprefix, srcs[0]); EMIT_BUF_WITH_RET(ctx, buf); break; case TGSI_OPCODE_F2U: - snprintf(buf, 255, "%s = %s(%s(uvec4(%s)));\n", dsts[0], dstconv, dtypeprefix, srcs[0]); + snprintf(buf, 255, "%s = %s(%s(uvec4(%s)));\n", dsts[0], dstconv, dtypeprefix, srcs[0]); EMIT_BUF_WITH_RET(ctx, buf); break; case TGSI_OPCODE_NOT: @@ -1721,9 +1714,9 @@ iter_instruction(struct tgsi_iterate_context *iter, EMIT_BUF_WITH_RET(ctx, buf); break; case TGSI_OPCODE_CMP: - snprintf(buf, 255, "%s = mix(%s, %s, greaterThanEqual(%s, vec4(0.0)))%s;\n", dsts[0], srcs[1], srcs[2], srcs[0], writemask); - EMIT_BUF_WITH_RET(ctx, buf); - break; + snprintf(buf, 255, "%s = mix(%s, %s, greaterThanEqual(%s, vec4(0.0)))%s;\n", dsts[0], srcs[1], srcs[2], srcs[0], writemask); + EMIT_BUF_WITH_RET(ctx, buf); + break; case TGSI_OPCODE_UCMP: snprintf(buf, 255, "%s = mix(%s, %s, notEqual(floatBitsToUint(%s), uvec4(0.0)))%s;\n", dsts[0], srcs[2], srcs[1], srcs[0], writemask); EMIT_BUF_WITH_RET(ctx, buf); @@ -1798,7 +1791,7 @@ iter_instruction(struct tgsi_iterate_context *iter, break; case TGSI_OPCODE_EMIT: if (ctx->so && ctx->key->gs_present) { - emit_so_movs(ctx); + emit_so_movs(ctx); } ret = emit_prescale(ctx); if (ret) @@ -1822,7 +1815,6 @@ iter_instruction(struct tgsi_iterate_context *iter, snprintf(buf, 255, "%s = clamp(%s, 0.0, 1.0);\n", dsts[0], dsts[0]); EMIT_BUF_WITH_RET(ctx, buf); } - return TRUE; } @@ -1842,7 +1834,7 @@ prolog(struct tgsi_iterate_context *iter) } #define STRCAT_WITH_RET(mainstr, buf) do { \ - (mainstr) = strcat_realloc((mainstr), (buf)); \ + (mainstr) = strcat_realloc((mainstr), (buf)); \ if ((mainstr) == NULL) return NULL; \ } while(0) @@ -1884,27 +1876,27 @@ static char *emit_header(struct dump_ctx *ctx, char *glsl_hdr) const char *vrend_shader_samplertypeconv(int sampler_type, int *is_shad) { - switch (sampler_type) { - case TGSI_TEXTURE_BUFFER: return "Buffer"; - case TGSI_TEXTURE_1D: return "1D"; - case TGSI_TEXTURE_2D: return "2D"; - case TGSI_TEXTURE_3D: return "3D"; - case TGSI_TEXTURE_CUBE: return "Cube"; - case TGSI_TEXTURE_RECT: return "2DRect"; - case TGSI_TEXTURE_SHADOW1D: *is_shad = 1; return "1DShadow"; - case TGSI_TEXTURE_SHADOW2D: *is_shad = 1; return "2DShadow"; - case TGSI_TEXTURE_SHADOWRECT: *is_shad = 1; return "2DRectShadow"; - case TGSI_TEXTURE_1D_ARRAY: return "1DArray"; - case TGSI_TEXTURE_2D_ARRAY: return "2DArray"; - case TGSI_TEXTURE_SHADOW1D_ARRAY: *is_shad = 1; return "1DArrayShadow"; - case TGSI_TEXTURE_SHADOW2D_ARRAY: *is_shad = 1; return "2DArrayShadow"; - case TGSI_TEXTURE_SHADOWCUBE: *is_shad = 1; return "CubeShadow"; - case TGSI_TEXTURE_CUBE_ARRAY: return "CubeArray"; - case TGSI_TEXTURE_SHADOWCUBE_ARRAY: *is_shad = 1; return "CubeArrayShadow"; - case TGSI_TEXTURE_2D_MSAA: return "2DMS"; - case TGSI_TEXTURE_2D_ARRAY_MSAA: return "2DMSArray"; - default: return NULL; - } + switch (sampler_type) { + case TGSI_TEXTURE_BUFFER: return "Buffer"; + case TGSI_TEXTURE_1D: return "1D"; + case TGSI_TEXTURE_2D: return "2D"; + case TGSI_TEXTURE_3D: return "3D"; + case TGSI_TEXTURE_CUBE: return "Cube"; + case TGSI_TEXTURE_RECT: return "2DRect"; + case TGSI_TEXTURE_SHADOW1D: *is_shad = 1; return "1DShadow"; + case TGSI_TEXTURE_SHADOW2D: *is_shad = 1; return "2DShadow"; + case TGSI_TEXTURE_SHADOWRECT: *is_shad = 1; return "2DRectShadow"; + case TGSI_TEXTURE_1D_ARRAY: return "1DArray"; + case TGSI_TEXTURE_2D_ARRAY: return "2DArray"; + case TGSI_TEXTURE_SHADOW1D_ARRAY: *is_shad = 1; return "1DArrayShadow"; + case TGSI_TEXTURE_SHADOW2D_ARRAY: *is_shad = 1; return "2DArrayShadow"; + case TGSI_TEXTURE_SHADOWCUBE: *is_shad = 1; return "CubeShadow"; + case TGSI_TEXTURE_CUBE_ARRAY: return "CubeArray"; + case TGSI_TEXTURE_SHADOWCUBE_ARRAY: *is_shad = 1; return "CubeArrayShadow"; + case TGSI_TEXTURE_2D_MSAA: return "2DMS"; + case TGSI_TEXTURE_2D_ARRAY_MSAA: return "2DMSArray"; + default: return NULL; + } } static const char *get_interp_string(int interpolate, bool flatshade) @@ -1934,7 +1926,7 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr) if (ctx->prog_type == TGSI_PROCESSOR_FRAGMENT) { if (fs_emit_layout(ctx)) { - bool upper_left = !(ctx->fs_coord_origin ^ ctx->key->invert_fs_origin); + bool upper_left = !(ctx->fs_coord_origin ^ ctx->key->invert_fs_origin); char comma = (upper_left && ctx->fs_pixel_center) ? ',' : ' '; snprintf(buf, 255, "layout(%s%c%s) in vec4 gl_FragCoord;\n", @@ -1947,11 +1939,11 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr) if (ctx->prog_type == TGSI_PROCESSOR_GEOMETRY) { snprintf(buf, 255, "layout(%s) in;\n", prim_to_name(ctx->gs_in_prim)); STRCAT_WITH_RET(glsl_hdr, buf); - snprintf(buf, 255, "layout(%s, max_vertices = %d) out;\n", prim_to_name(ctx->gs_out_prim), ctx->gs_max_out_verts); + snprintf(buf, 255, "layout(%s, max_vertices = %d) out;\n", prim_to_name(ctx->gs_out_prim), ctx->gs_max_out_verts); STRCAT_WITH_RET(glsl_hdr, buf); } for (i = 0; i < ctx->num_inputs; i++) { - if (!ctx->inputs[i].glsl_predefined_no_emit) { + if (!ctx->inputs[i].glsl_predefined_no_emit) { if (ctx->prog_type == TGSI_PROCESSOR_VERTEX && ctx->cfg->use_explicit_locations) { snprintf(buf, 255, "layout(location=%d) ", ctx->inputs[i].first); STRCAT_WITH_RET(glsl_hdr, buf); @@ -1998,8 +1990,8 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr) STRCAT_WITH_RET(glsl_hdr, buf); if (ctx->has_clipvertex) { - snprintf(buf, 255, "%svec4 clipv_tmp;\n", ctx->has_clipvertex_so ? "out " : ""); - STRCAT_WITH_RET(glsl_hdr, buf); + snprintf(buf, 255, "%svec4 clipv_tmp;\n", ctx->has_clipvertex_so ? "out " : ""); + STRCAT_WITH_RET(glsl_hdr, buf); } if (ctx->num_clip_dist || ctx->key->clip_plane_enable) { @@ -2033,7 +2025,7 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr) STRCAT_WITH_RET(glsl_hdr, buf); } } - + if (ctx->so) { char outtype[6] = {0}; for (i = 0; i < ctx->so->num_outputs; i++) { @@ -2147,7 +2139,7 @@ static boolean fill_interpolants(struct dump_ctx *ctx, struct vrend_shader_info sinfo->interpinfo = calloc(ctx->num_interps, sizeof(struct vrend_interp_info)); if (!sinfo->interpinfo) return FALSE; - + ret = fill_fragment_interpolants(ctx, sinfo); if (ret == FALSE) goto out_fail; @@ -2256,7 +2248,7 @@ static void replace_interp(char *program, int mylen = strlen(INTERP_PREFIX) + strlen("out vec4 "); ptr = strstr(program, var_name); - + if (!ptr) return; diff --git a/src/vrend_shader.h b/src/vrend_shader.h index d21b5f1..7dfed35 100644 --- a/src/vrend_shader.h +++ b/src/vrend_shader.h @@ -63,7 +63,7 @@ struct vrend_shader_key { bool gs_present; bool flatshade; }; - + struct vrend_shader_cfg { int glsl_version; bool use_core_profile;