diff options
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/winsys/svga/drm/Makefile.sources | 4 | ||||
-rw-r--r-- | src/gallium/winsys/svga/drm/vmw_query.c | 144 | ||||
-rw-r--r-- | src/gallium/winsys/svga/drm/vmw_query.h | 67 |
3 files changed, 214 insertions, 1 deletions
diff --git a/src/gallium/winsys/svga/drm/Makefile.sources b/src/gallium/winsys/svga/drm/Makefile.sources index ab2b9321f3e..f82b0097b5b 100644 --- a/src/gallium/winsys/svga/drm/Makefile.sources +++ b/src/gallium/winsys/svga/drm/Makefile.sources @@ -17,4 +17,6 @@ C_SOURCES := \ vmw_surface.c \ vmw_surface.h \ vmw_shader.c \ - vmw_shader.h + vmw_shader.h \ + vmw_query.c \ + vmw_query.h diff --git a/src/gallium/winsys/svga/drm/vmw_query.c b/src/gallium/winsys/svga/drm/vmw_query.c new file mode 100644 index 00000000000..7baf2c1d7ae --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_query.c @@ -0,0 +1,144 @@ +/********************************************************** + * Copyright 2015 VMware, Inc. All rights reserved. + * + * 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. + * + **********************************************************/ + +#include "pipebuffer/pb_bufmgr.h" +#include "util/u_memory.h" + +#include "vmw_screen.h" +#include "vmw_buffer.h" +#include "vmw_query.h" + + + +struct svga_winsys_gb_query * +vmw_svga_winsys_query_create(struct svga_winsys_screen *sws, + uint32 queryResultLen) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + struct pb_manager *provider = vws->pools.gmr; + struct pb_desc desc = {0}; + struct pb_buffer *pb_buf; + struct svga_winsys_gb_query *query; + + query = CALLOC_STRUCT(svga_winsys_gb_query); + if (!query) + return NULL; + + /* Allocate memory to hold queries for this context */ + desc.alignment = 4096; + pb_buf = provider->create_buffer(provider, queryResultLen, &desc); + query->buf = vmw_svga_winsys_buffer_wrap(pb_buf); + + if (!query->buf) { + debug_printf("Failed to allocate memory for queries\n"); + FREE(query); + query = NULL; + } + + return query; +} + + + +void +vmw_svga_winsys_query_destroy(struct svga_winsys_screen *sws, + struct svga_winsys_gb_query *query) +{ + vmw_svga_winsys_buffer_destroy(sws, query->buf); + FREE(query); +} + + + +int +vmw_svga_winsys_query_init(struct svga_winsys_screen *sws, + struct svga_winsys_gb_query *query, + unsigned offset, + SVGA3dQueryState queryState) +{ + SVGA3dQueryState *state; + + state = (SVGA3dQueryState *) vmw_svga_winsys_buffer_map(sws, + query->buf, + PIPE_TRANSFER_WRITE); + if (!state) { + debug_printf("Failed to map query result memory for initialization\n"); + return -1; + } + + /* Initialize the query state for the specified query slot */ + state = (SVGA3dQueryState *)((char *)state + offset); + *state = queryState; + + vmw_svga_winsys_buffer_unmap(sws, query->buf); + + return 0; +} + + + +void +vmw_svga_winsys_query_get_result(struct svga_winsys_screen *sws, + struct svga_winsys_gb_query *query, + unsigned offset, + SVGA3dQueryState *queryState, + void *result, uint32 resultLen) +{ + SVGA3dQueryState *state; + + state = (SVGA3dQueryState *) vmw_svga_winsys_buffer_map(sws, + query->buf, + PIPE_TRANSFER_READ); + if (!state) { + debug_printf("Failed to lock query result memory\n"); + + if (queryState) + *queryState = SVGA3D_QUERYSTATE_FAILED; + + return; + } + + state = (SVGA3dQueryState *)((char *)state + offset); + + if (queryState) + *queryState = *state; + + if (result) { + memcpy(result, state + 1, resultLen); + } + + vmw_svga_winsys_buffer_unmap(sws, query->buf); +} + + +enum pipe_error +vmw_swc_query_bind(struct svga_winsys_context *swc, + struct svga_winsys_gb_query *query, + unsigned flags) +{ + /* no-op on Linux */ + return PIPE_OK; +} + diff --git a/src/gallium/winsys/svga/drm/vmw_query.h b/src/gallium/winsys/svga/drm/vmw_query.h new file mode 100644 index 00000000000..a8b58e6182f --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_query.h @@ -0,0 +1,67 @@ +/********************************************************** + * Copyright 2015 VMware, Inc. All rights reserved. + * + * 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 VMW_DRM_QUERY_H +#define VMW_DRM_QUERY_H + +#include "svga3d_reg.h" + + + +/** Guest-backed query */ +struct svga_winsys_gb_query +{ + struct svga_winsys_buffer *buf; +}; + + +struct svga_winsys_gb_query * +vmw_svga_winsys_query_create(struct svga_winsys_screen *sws, + uint32 queryResultLen); + +void +vmw_svga_winsys_query_destroy(struct svga_winsys_screen *sws, + struct svga_winsys_gb_query *query); + +int +vmw_svga_winsys_query_init(struct svga_winsys_screen *sws, + struct svga_winsys_gb_query *query, + unsigned offset, + SVGA3dQueryState queryState); + +void +vmw_svga_winsys_query_get_result(struct svga_winsys_screen *sws, + struct svga_winsys_gb_query *query, + unsigned offset, + SVGA3dQueryState *queryState, + void *result, uint32 resultLen); + +enum pipe_error +vmw_swc_query_bind(struct svga_winsys_context *swc, + struct svga_winsys_gb_query *query, + unsigned flags); + +#endif /* VMW_DRM_QUERY_H */ + |