virgl: Fix compilation on MSVC

* Cast to uint8_t* before doing pointer arithmetics
* Add zero to initializer list to initialize zeroed structs
* Don't include linux sepcific headers on WIN32
* Don't use build_id when it isn't available

Reviewed-by: Feng Jiang <jiangfeng@kylinos.cn>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27308>
This commit is contained in:
Max R 2024-02-01 14:18:25 +03:00 committed by Marge Bot
parent 47c725b53e
commit 468c750c53
12 changed files with 41 additions and 26 deletions

View file

@ -41,9 +41,15 @@ libvirgl = static_library(
dependencies : [dep_libdrm, idep_mesautil, idep_xmlconfig, idep_nir],
)
virgl_deps = [libvirgl]
if not with_platform_windows
virgl_deps += libvirgldrm
virgl_deps += libvirglvtest
endif
driver_virgl = declare_dependency(
compile_args : '-DGALLIUM_VIRGL',
link_with : [libvirgl, libvirgldrm, libvirglvtest],
link_with : virgl_deps,
)
if with_tests

View file

@ -161,7 +161,7 @@ TEST_P(VirglStagingMgrWithAlignment,
struct virgl_hw_res *out_resource[num_resources] = {0};
unsigned expected_offset = 0;
unsigned out_offset;
void *map_ptr;
uint8_t *map_ptr;
bool alloc_succeeded;
for (unsigned i = 0; i < num_resources; ++i) {
@ -197,7 +197,7 @@ TEST_F(VirglStagingMgr,
{
struct virgl_hw_res *out_resource[2] = {0};
unsigned out_offset;
void *map_ptr;
uint8_t *map_ptr;
bool alloc_succeeded;
alloc_succeeded =
@ -229,7 +229,7 @@ TEST_F(VirglStagingMgr,
{
struct virgl_hw_res *out_resource[2] = {0};
unsigned out_offset;
void *map_ptr;
uint8_t *map_ptr;
bool alloc_succeeded;
alloc_succeeded =
@ -261,7 +261,7 @@ TEST_F(VirglStagingMgr,
{
struct virgl_hw_res *out_resource[2] = {0};
unsigned out_offset;
void *map_ptr;
uint8_t *map_ptr;
bool alloc_succeeded;
ASSERT_LT(staging_size, 5123);
@ -295,7 +295,7 @@ TEST_F(VirglStagingMgr, releases_resource_on_destruction)
{
struct virgl_hw_res *out_resource = NULL;
unsigned out_offset;
void *map_ptr;
uint8_t *map_ptr;
bool alloc_succeeded;
alloc_succeeded =
@ -334,7 +334,7 @@ TEST_F(VirglStagingMgr, fails_gracefully_if_resource_create_fails)
struct virgl_screen *vs = virgl_screen(ctx->screen);
struct virgl_hw_res *out_resource = NULL;
unsigned out_offset;
void *map_ptr;
uint8_t *map_ptr;
bool alloc_succeeded;
vs->vws->resource_create = failing_resource_create;
@ -359,7 +359,7 @@ TEST_F(VirglStagingMgr, fails_gracefully_if_map_fails)
struct virgl_screen *vs = virgl_screen(ctx->screen);
struct virgl_hw_res *out_resource = NULL;
unsigned out_offset;
void *map_ptr;
uint8_t *map_ptr;
bool alloc_succeeded;
vs->vws->resource_map = failing_resource_map;
@ -377,7 +377,7 @@ TEST_F(VirglStagingMgr, uses_staging_buffer_resource)
{
struct virgl_hw_res *out_resource = NULL;
unsigned out_offset;
void *map_ptr;
uint8_t *map_ptr;
bool alloc_succeeded;
alloc_succeeded =

View file

@ -21,7 +21,11 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <string.h>
#ifndef _WIN32
#include <libsync.h>
#endif
#include "pipe/p_shader_tokens.h"
#include "compiler/nir/nir.h"
@ -1003,7 +1007,7 @@ static void virgl_draw_vbo(struct pipe_context *ctx,
struct virgl_context *vctx = virgl_context(ctx);
struct virgl_screen *rs = virgl_screen(ctx->screen);
struct virgl_indexbuf ib = {};
struct virgl_indexbuf ib = { 0 };
struct pipe_draw_info info = *dinfo;
if (!indirect &&
@ -1478,7 +1482,7 @@ static void *virgl_create_compute_state(struct pipe_context *ctx,
uint32_t handle;
const struct tgsi_token *ntt_tokens = NULL;
const struct tgsi_token *tokens;
struct pipe_stream_output_info so_info = {};
struct pipe_stream_output_info so_info = { 0 };
int ret;
if (state->ir_type == PIPE_SHADER_IR_NIR) {

View file

@ -350,7 +350,7 @@ virgl_staging_map(struct virgl_context *vctx,
unsigned align_offset;
unsigned stride;
uintptr_t layer_stride;
void *map_addr;
uint8_t *map_addr;
bool alloc_succeeded;
assert(vctx->supports_staging);
@ -529,7 +529,7 @@ virgl_resource_transfer_map(struct pipe_context *ctx,
case VIRGL_TRANSFER_MAP_HW_RES:
trans->hw_res_map = vws->resource_map(vws, vres->hw_res);
if (trans->hw_res_map)
map_addr = trans->hw_res_map + trans->offset;
map_addr = (uint8_t *)trans->hw_res_map + trans->offset;
else
map_addr = NULL;
break;

View file

@ -1054,6 +1054,10 @@ static struct disk_cache *virgl_get_disk_shader_cache (struct pipe_screen *pscre
static void virgl_disk_cache_create(struct virgl_screen *screen)
{
struct mesa_sha1 sha1_ctx;
_mesa_sha1_init(&sha1_ctx);
#ifdef HAVE_DL_ITERATE_PHDR
const struct build_id_note *note =
build_id_find_nhdr_for_addr(virgl_disk_cache_create);
assert(note);
@ -1064,9 +1068,8 @@ static void virgl_disk_cache_create(struct virgl_screen *screen)
const uint8_t *id_sha1 = build_id_data(note);
assert(id_sha1);
struct mesa_sha1 sha1_ctx;
_mesa_sha1_init(&sha1_ctx);
_mesa_sha1_update(&sha1_ctx, id_sha1, build_id_len);
#endif
/* When we switch the host the caps might change and then we might have to
* apply different lowering. */

View file

@ -96,7 +96,7 @@ virgl_staging_alloc(struct virgl_staging_mgr *staging,
unsigned alignment,
unsigned *out_offset,
struct virgl_hw_res **outbuf,
void **ptr)
uint8_t **ptr)
{
struct virgl_winsys *vws = staging->vws;
unsigned offset = align(staging->offset, alignment);

View file

@ -83,7 +83,7 @@ virgl_staging_alloc(struct virgl_staging_mgr *staging,
unsigned alignment,
unsigned *out_offset,
struct virgl_hw_res **outbuf,
void **ptr);
uint8_t **ptr);
#ifdef __cplusplus
} // extern "C" {

View file

@ -190,7 +190,7 @@ static void *texture_transfer_map_resolve(struct pipe_context *ctx,
goto fail;
if (!util_format_translate_3d(resource->format,
ptr + vtex->metadata.level_offset[level],
(uint8_t *)ptr + vtex->metadata.level_offset[level],
trans->base.stride,
trans->base.layer_stride,
box->x, box->y, box->z,
@ -212,7 +212,7 @@ static void *texture_transfer_map_resolve(struct pipe_context *ctx,
if ((usage & PIPE_MAP_WRITE) == 0)
pipe_resource_reference(&trans->resolve_transfer->resource, NULL);
return ptr + trans->offset;
return (uint8_t *)ptr + trans->offset;
}
fail:

View file

@ -372,7 +372,7 @@ virgl_transfer_queue_extend_buffer(struct virgl_transfer_queue *queue,
assert(queued->base.resource->target == PIPE_BUFFER);
assert(queued->hw_res_map);
memcpy(queued->hw_res_map + offset, data, size);
memcpy((uint8_t *)queued->hw_res_map + offset, data, size);
u_box_union_2d(&queued->base.box, &queued->base.box, &box);
queued->offset = queued->base.box.x;

View file

@ -66,12 +66,12 @@
*/
#include <string.h>
#include <sys/param.h>
#include "vl/vl_decoder.h"
#include "vl/vl_video_buffer.h"
#include "util/u_video.h"
#include "util/u_memory.h"
#include "util/macros.h"
#include "virgl_screen.h"
#include "virgl_resource.h"
@ -106,7 +106,7 @@ static int fill_base_picture_desc(const struct pipe_picture_desc *desc,
ITEM_SET(vbase, desc, protected_playback);
ITEM_SET(vbase, desc, key_size);
memcpy(vbase->decrypt_key, desc->decrypt_key,
MIN(desc->key_size, sizeof(vbase->decrypt_key)));
MIN2(desc->key_size, sizeof(vbase->decrypt_key)));
return 0;
}
@ -1042,7 +1042,7 @@ static void virgl_video_decode_bitstream(struct pipe_video_codec *codec,
if (!ptr)
return;
for (i = 0, vcdc->bs_size = 0; i < num_buffers; i++) {
memcpy(ptr + vcdc->bs_size, buffers[i], sizes[i]);
memcpy((uint8_t *)ptr + vcdc->bs_size, buffers[i], sizes[i]);
vcdc->bs_size += sizes[i];
}
pipe_buffer_unmap(&vctx->base, xfer);

View file

@ -167,8 +167,10 @@ else
endif
if with_gallium_virgl
subdir('winsys/virgl/common')
subdir('winsys/virgl/drm')
subdir('winsys/virgl/vtest')
if not with_platform_windows
subdir('winsys/virgl/drm')
subdir('winsys/virgl/vtest')
endif
subdir('drivers/virgl')
else
driver_virgl = declare_dependency()

View file

@ -91,7 +91,7 @@ endif
if with_gallium_etnaviv
subdir('etnaviv')
endif
if system_has_kms_drm
if system_has_kms_drm or with_gallium_virgl
subdir('virtio')
endif
if with_gallium_freedreno or with_freedreno_vk or with_tools.contains('freedreno')