diff --git a/base/cvd/BUILD.bazel b/base/cvd/BUILD.bazel index 2159f0f8ad3..0d0f0f94058 100644 --- a/base/cvd/BUILD.bazel +++ b/base/cvd/BUILD.bazel @@ -70,3 +70,27 @@ cc_import( shared_library = ":gfxstream_backend", visibility = ["//visibility:public"], ) + +alias( + name = "virglrenderer", + actual = "@virglrenderer//:libvirglrenderer.so.1", + visibility = ["//visibility:public"], +) + +cc_import( + name = "virglrenderer_import", + shared_library = ":virglrenderer", + visibility = ["//visibility:public"], +) + +alias( + name = "minigbm", + actual = "@minigbm//:libgbm.so.1", + visibility = ["//visibility:public"], +) + +cc_import( + name = "minigbm_import", + shared_library = ":minigbm", + visibility = ["//visibility:public"], +) diff --git a/base/cvd/build_external/build_external.MODULE.bazel b/base/cvd/build_external/build_external.MODULE.bazel index af5acbbf126..5a1ceb70d7c 100644 --- a/base/cvd/build_external/build_external.MODULE.bazel +++ b/base/cvd/build_external/build_external.MODULE.bazel @@ -46,6 +46,7 @@ include("//build_external/libyuv:libyuv.MODULE.bazel") include("//build_external/mako:mako.MODULE.bazel") include("//build_external/markupsafe:markupsafe.MODULE.bazel") include("//build_external/mesa:mesa.MODULE.bazel") +include("//build_external/minigbm:minigbm.MODULE.bazel") include("//build_external/mkbootimg:mkbootimg.MODULE.bazel") include("//build_external/ms-tpm-20-ref:ms-tpm-20-ref.MODULE.bazel") include("//build_external/mtools:mtools.MODULE.bazel") @@ -62,6 +63,8 @@ include("//build_external/spirv_headers:spirv_headers.MODULE.bazel") include("//build_external/spirv_tools:spirv_tools.MODULE.bazel") include("//build_external/swiftshader:swiftshader.MODULE.bazel") include("//build_external/vulkan_headers:vulkan_headers.MODULE.bazel") +include("//build_external/venus_protocol:venus_protocol.MODULE.bazel") +include("//build_external/virglrenderer:virglrenderer.MODULE.bazel") include("//build_external/wayland:wayland.MODULE.bazel") include("//build_external/wmediumd:wmediumd.MODULE.bazel") include("//build_external/xz:xz.MODULE.bazel") diff --git a/base/cvd/build_external/crosvm/PATCH.rutabaga_gfx_build_rs.patch b/base/cvd/build_external/crosvm/PATCH.rutabaga_gfx_build_rs.patch new file mode 100644 index 00000000000..825280aee80 --- /dev/null +++ b/base/cvd/build_external/crosvm/PATCH.rutabaga_gfx_build_rs.patch @@ -0,0 +1,27 @@ +diff --git a/build.rs b/build.rs +index 4e4db7a..789b3a8 100644 +--- a/build.rs ++++ b/build.rs +@@ -89,11 +89,15 @@ fn main() -> PkgConfigResult<()> { + } + + if env::var("CARGO_FEATURE_VIRGL_RENDERER").is_ok() { +- virglrenderer()?; ++ if env::var("CARGO_FEATURE_VIRGL_RENDERER_STUB").is_err() { ++ virglrenderer()?; ++ } + use_fence_passing_option1 = false; + } + +- if env::var("CARGO_FEATURE_GBM").is_ok() { ++ if env::var("CARGO_FEATURE_GBM").is_ok() ++ && env::var("CARGO_FEATURE_GBM_STUB").is_err() ++ { + gbm()?; + } + + if env::var("CARGO_FEATURE_GFXSTREAM").is_ok() + && env::var("CARGO_FEATURE_GFXSTREAM_STUB").is_err() + { + gfxstream()?; + } diff --git a/base/cvd/build_external/crosvm/crosvm.MODULE.bazel b/base/cvd/build_external/crosvm/crosvm.MODULE.bazel index 912c69e5b97..dd674be862a 100644 --- a/base/cvd/build_external/crosvm/crosvm.MODULE.bazel +++ b/base/cvd/build_external/crosvm/crosvm.MODULE.bazel @@ -30,6 +30,8 @@ crosvm_bin.spec( "net_util", "qcow", "usb", + "virgl_renderer", + "wl-dmabuf", ], # TODO: schuffelen - fix the sandbox git = CROSVM_REMOTE, @@ -42,6 +44,8 @@ crosvm_bin.annotation( patch_args = ["-p1"], deps = [ "@@//:gfxstream_backend_import", + "@@//:minigbm_import", + "@@//:virglrenderer_import", ], rustc_flags = [ # Look for shared libraries in the same directory as the binary. @@ -51,8 +55,14 @@ crosvm_bin.annotation( crosvm_bin.annotation( crate = "rutabaga_gfx", + crate_features = [ + "gbm", + "virgl_renderer", + ], deps = [ "@@//:gfxstream_backend_import", + "@@//:minigbm_import", + "@@//:virglrenderer_import", ], rustc_flags = [ # Look for shared libraries in the same directory as this object. @@ -60,9 +70,15 @@ crosvm_bin.annotation( ], build_script_env = { # Disable the build script from trying to automatically locate - # Gfxstream as the dep is directly provided above. + # Gfxstream, minigbm, and virglrenderer as the dep are directly provided above. + "CARGO_FEATURE_GBM_STUB": "bloh", "CARGO_FEATURE_GFXSTREAM_STUB": "blah", + "CARGO_FEATURE_VIRGL_RENDERER_STUB": "bleh", }, + patch_args = ["-p1"], + patches = [ + "@//build_external/crosvm:PATCH.rutabaga_gfx_build_rs.patch", + ], ) crosvm_bin.annotation( diff --git a/base/cvd/build_external/libdrm/BUILD.libdrm.bazel b/base/cvd/build_external/libdrm/BUILD.libdrm.bazel index 59a70bd328c..a01729b6731 100644 --- a/base/cvd/build_external/libdrm/BUILD.libdrm.bazel +++ b/base/cvd/build_external/libdrm/BUILD.libdrm.bazel @@ -5,6 +5,8 @@ package( default_visibility = [ "@//:android_cuttlefish", "@mesa//:__subpackages__", + "@minigbm//:__subpackages__", + "@virglrenderer//:__subpackages__", ], ) @@ -48,10 +50,9 @@ cc_library( "xf86drmRandom.c", "xf86drmSL.c", ], - hdrs = [ - "include/drm/drm.h", - "include/drm/drm_fourcc.h", - "include/drm/drm_mode.h", + hdrs = glob([ + "include/drm/*.h", + ]) + [ "xf86drm.h", "xf86drmHash.h", "xf86drmMode.h", diff --git a/base/cvd/build_external/mako/BUILD.mako.bazel b/base/cvd/build_external/mako/BUILD.mako.bazel index a6f02a04ff1..1cde45651b9 100644 --- a/base/cvd/build_external/mako/BUILD.mako.bazel +++ b/base/cvd/build_external/mako/BUILD.mako.bazel @@ -4,6 +4,7 @@ package( default_visibility = [ "@//:android_cuttlefish", "@mesa//:__subpackages__", + "@venus_protocol//:__subpackages__", ], ) diff --git a/base/cvd/build_external/minigbm/BUILD.bazel b/base/cvd/build_external/minigbm/BUILD.bazel new file mode 100644 index 00000000000..aad1b4fbbec --- /dev/null +++ b/base/cvd/build_external/minigbm/BUILD.bazel @@ -0,0 +1 @@ +# minigbm build external module diff --git a/base/cvd/build_external/minigbm/BUILD.minigbm.bazel b/base/cvd/build_external/minigbm/BUILD.minigbm.bazel new file mode 100644 index 00000000000..2c5e098234e --- /dev/null +++ b/base/cvd/build_external/minigbm/BUILD.minigbm.bazel @@ -0,0 +1,93 @@ +load("@rules_cc//cc:cc_library.bzl", "cc_library") +load("@rules_cc//cc:cc_shared_library.bzl", "cc_shared_library") + +package( + default_visibility = ["//visibility:public"], +) + +genrule( + name = "minigbm_headers", + srcs = [ + "gbm.h", + "minigbm_helpers.h", + ], + outs = [ + "minigbm/gbm.h", + "minigbm/minigbm_helpers.h", + ], + cmd = "mkdir -p $(@D)/minigbm && cp $(location gbm.h) $(@D)/minigbm/gbm.h && cp $(location minigbm_helpers.h) $(@D)/minigbm/minigbm_helpers.h", +) + +cc_library( + name = "libgbm_internal", + srcs = [ + "backend_mock.c", + "drv.c", + "drv_array_helpers.c", + "drv_helpers.c", + "dumb_driver.c", + "gbm.c", + "gbm_helpers.c", + "minigbm_helpers.c", + "virtgpu.c", + "virtgpu_cross_domain.c", + "virtgpu_virgl.c", + ] + select({ + "@platforms//cpu:aarch64": [ + "msm.c", + ], + "@platforms//cpu:x86_64": [ + "i915.c", + "xe.c", + ], + "//conditions:default": [], + }), + hdrs = glob([ + "*.h", + "external/*.h", + ]) + [ + ":minigbm_headers", + ], + copts = [ + "-D_GNU_SOURCE=1", + "-D_FILE_OFFSET_BITS=64", + "-DDRV_VIRTGPU=1", + "-Wno-implicit-function-declaration", + "-Wno-unused-parameter", + ] + select({ + "@platforms//cpu:aarch64": [ + "-DDRV_MSM=1", + ], + "@platforms//cpu:x86_64": [ + "-DDRV_I915=1", + "-DDRV_XE=1", + ], + "//conditions:default": [], + }), + includes = [ + ".", + ], + linkopts = [ + "-ldl", + ], + deps = [ + "@libdrm", + ], +) + +cc_shared_library( + name = "libgbm.so.1", + deps = [":libgbm_internal"], + shared_lib_name = "libgbm.so", +) + +alias( + name = "libgbm", + actual = ":libgbm.so.1", +) + +alias( + name = "libminigbm", + actual = ":libgbm.so.1", +) + diff --git a/base/cvd/build_external/minigbm/minigbm.MODULE.bazel b/base/cvd/build_external/minigbm/minigbm.MODULE.bazel new file mode 100644 index 00000000000..b1e4ee00bcd --- /dev/null +++ b/base/cvd/build_external/minigbm/minigbm.MODULE.bazel @@ -0,0 +1,8 @@ +git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +git_repository( + name = "minigbm", + build_file = "@//build_external/minigbm:BUILD.minigbm.bazel", + commit = "34003c9c8b50661346e49b06389a028ce970f539", + remote = "https://chromium.googlesource.com/chromiumos/platform/minigbm", +) diff --git a/base/cvd/build_external/pyyaml/BUILD.pyyaml.bazel b/base/cvd/build_external/pyyaml/BUILD.pyyaml.bazel index c77560c8529..1ae7b2e5d21 100644 --- a/base/cvd/build_external/pyyaml/BUILD.pyyaml.bazel +++ b/base/cvd/build_external/pyyaml/BUILD.pyyaml.bazel @@ -4,6 +4,7 @@ package( default_visibility = [ "@//:android_cuttlefish", "@mesa//:__subpackages__", + "@virglrenderer//:__subpackages__", ], ) diff --git a/base/cvd/build_external/venus_protocol/BUILD.bazel b/base/cvd/build_external/venus_protocol/BUILD.bazel new file mode 100644 index 00000000000..b72e22b6483 --- /dev/null +++ b/base/cvd/build_external/venus_protocol/BUILD.bazel @@ -0,0 +1 @@ +# Package marker for venus_protocol diff --git a/base/cvd/build_external/venus_protocol/BUILD.venus_protocol.bazel b/base/cvd/build_external/venus_protocol/BUILD.venus_protocol.bazel new file mode 100644 index 00000000000..24b36713ef0 --- /dev/null +++ b/base/cvd/build_external/venus_protocol/BUILD.venus_protocol.bazel @@ -0,0 +1,162 @@ +load("@rules_cc//cc:cc_library.bzl", "cc_library") +load("@rules_python//python:defs.bzl", "py_binary") + +package( + default_visibility = [ + "@//:android_cuttlefish", + "@mesa//:__subpackages__", + "@virglrenderer//:__subpackages__", + ], +) + +py_binary( + name = "vn_protocol_py", + srcs = [ + "vkxml.py", + "vn_protocol.py", + ], + main = "vn_protocol.py", + deps = [ + "@mako", + ], +) + +cc_library( + name = "vulkan_headers", + hdrs = glob([ + "include/**/*.h", + ]), + includes = [ + "include", + ], +) + +VN_PROTOCOL_RENDERER_HEADERS = [ + "vn_protocol_renderer.h", + "vn_protocol_renderer_acceleration_structure.h", + "vn_protocol_renderer_buffer.h", + "vn_protocol_renderer_buffer_view.h", + "vn_protocol_renderer_command_buffer.h", + "vn_protocol_renderer_command_pool.h", + "vn_protocol_renderer_cs.h", + "vn_protocol_renderer_defines.h", + "vn_protocol_renderer_descriptor_heap.h", + "vn_protocol_renderer_descriptor_pool.h", + "vn_protocol_renderer_descriptor_set.h", + "vn_protocol_renderer_descriptor_set_layout.h", + "vn_protocol_renderer_descriptor_update_template.h", + "vn_protocol_renderer_device.h", + "vn_protocol_renderer_device_memory.h", + "vn_protocol_renderer_dispatches.h", + "vn_protocol_renderer_event.h", + "vn_protocol_renderer_fence.h", + "vn_protocol_renderer_framebuffer.h", + "vn_protocol_renderer_handles.h", + "vn_protocol_renderer_host_copy.h", + "vn_protocol_renderer_image.h", + "vn_protocol_renderer_image_view.h", + "vn_protocol_renderer_info.h", + "vn_protocol_renderer_instance.h", + "vn_protocol_renderer_pipeline.h", + "vn_protocol_renderer_pipeline_cache.h", + "vn_protocol_renderer_pipeline_layout.h", + "vn_protocol_renderer_private_data_slot.h", + "vn_protocol_renderer_query_pool.h", + "vn_protocol_renderer_queue.h", + "vn_protocol_renderer_render_pass.h", + "vn_protocol_renderer_sampler.h", + "vn_protocol_renderer_sampler_ycbcr_conversion.h", + "vn_protocol_renderer_semaphore.h", + "vn_protocol_renderer_shader_module.h", + "vn_protocol_renderer_structs.h", + "vn_protocol_renderer_transport.h", + "vn_protocol_renderer_types.h", + "vn_protocol_renderer_util.h", +] + +genrule( + name = "vn_protocol_renderer_gen", + srcs = glob([ + "templates/**", + "xmls/**", + ]), + outs = VN_PROTOCOL_RENDERER_HEADERS, + cmd = """ + SRCDIR=$$(dirname $$(dirname $(location xmls/vk.xml))) + $(location :vn_protocol_py) --srcdir $$SRCDIR --outdir $(@D) --renderer + """, + tools = [":vn_protocol_py"], +) + +cc_library( + name = "vn_protocol_renderer", + hdrs = [":vn_protocol_renderer_gen"], + includes = ["."], + deps = [ + ":vulkan_headers", + ], +) + +VN_PROTOCOL_DRIVER_HEADERS = [ + "vn_protocol_driver.h", + "vn_protocol_driver_acceleration_structure.h", + "vn_protocol_driver_buffer.h", + "vn_protocol_driver_buffer_view.h", + "vn_protocol_driver_command_buffer.h", + "vn_protocol_driver_command_pool.h", + "vn_protocol_driver_cs.h", + "vn_protocol_driver_defines.h", + "vn_protocol_driver_descriptor_heap.h", + "vn_protocol_driver_descriptor_pool.h", + "vn_protocol_driver_descriptor_set.h", + "vn_protocol_driver_descriptor_set_layout.h", + "vn_protocol_driver_descriptor_update_template.h", + "vn_protocol_driver_device.h", + "vn_protocol_driver_device_memory.h", + "vn_protocol_driver_event.h", + "vn_protocol_driver_fence.h", + "vn_protocol_driver_framebuffer.h", + "vn_protocol_driver_handles.h", + "vn_protocol_driver_host_copy.h", + "vn_protocol_driver_image.h", + "vn_protocol_driver_image_view.h", + "vn_protocol_driver_info.h", + "vn_protocol_driver_instance.h", + "vn_protocol_driver_pipeline.h", + "vn_protocol_driver_pipeline_cache.h", + "vn_protocol_driver_pipeline_layout.h", + "vn_protocol_driver_private_data_slot.h", + "vn_protocol_driver_query_pool.h", + "vn_protocol_driver_queue.h", + "vn_protocol_driver_render_pass.h", + "vn_protocol_driver_sampler.h", + "vn_protocol_driver_sampler_ycbcr_conversion.h", + "vn_protocol_driver_semaphore.h", + "vn_protocol_driver_shader_module.h", + "vn_protocol_driver_structs.h", + "vn_protocol_driver_transport.h", + "vn_protocol_driver_types.h", +] + +genrule( + name = "vn_protocol_driver_gen", + srcs = glob([ + "templates/**", + "xmls/**", + ]), + outs = VN_PROTOCOL_DRIVER_HEADERS, + cmd = """ + SRCDIR=$$(dirname $$(dirname $(location xmls/vk.xml))) + $(location :vn_protocol_py) --srcdir $$SRCDIR --outdir $(@D) + """, + tools = [":vn_protocol_py"], +) + +cc_library( + name = "vn_protocol_driver", + hdrs = [":vn_protocol_driver_gen"], + includes = ["."], + deps = [ + ":vulkan_headers", + ], +) diff --git a/base/cvd/build_external/venus_protocol/venus_protocol.MODULE.bazel b/base/cvd/build_external/venus_protocol/venus_protocol.MODULE.bazel new file mode 100644 index 00000000000..fbd1fc0fabe --- /dev/null +++ b/base/cvd/build_external/venus_protocol/venus_protocol.MODULE.bazel @@ -0,0 +1,8 @@ +git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +git_repository( + name = "venus_protocol", + build_file = "@//build_external/venus_protocol:BUILD.venus_protocol.bazel", + commit = "ca19b6358d7cc491bc3e4de76f04c6700876a8fa", # v1.1.3 + remote = "https://gitlab.freedesktop.org/virgl/venus-protocol", +) diff --git a/base/cvd/build_external/virglrenderer/BUILD.bazel b/base/cvd/build_external/virglrenderer/BUILD.bazel new file mode 100644 index 00000000000..820b71b73eb --- /dev/null +++ b/base/cvd/build_external/virglrenderer/BUILD.bazel @@ -0,0 +1 @@ +# Package marker for virglrenderer diff --git a/base/cvd/build_external/virglrenderer/BUILD.virglrenderer.bazel b/base/cvd/build_external/virglrenderer/BUILD.virglrenderer.bazel new file mode 100644 index 00000000000..21e0eec74e8 --- /dev/null +++ b/base/cvd/build_external/virglrenderer/BUILD.virglrenderer.bazel @@ -0,0 +1,519 @@ +load("@rules_cc//cc:cc_binary.bzl", "cc_binary") +load("@rules_cc//cc:cc_library.bzl", "cc_library") +load("@rules_cc//cc:cc_shared_library.bzl", "cc_shared_library") +load("@rules_python//python:defs.bzl", "py_binary") + +package( + default_visibility = [ + "@//:android_cuttlefish", + ], +) + +# Configuration header +genrule( + name = "config_h", + outs = ["config.h"], + cmd = """cat << 'EOF' > $@ +#ifndef CONFIG_H +#define CONFIG_H + +#define _GNU_SOURCE 1 +#define PACKAGE_VERSION "1.3.0" +#define VERSION "1.3.0" +#define VIRGL_RENDERER_UNSTABLE_APIS 1 +#define ENABLE_VENUS 1 +#define ENABLE_GBM 1 +#define ENABLE_GBM_ALLOCATION 1 +#define MINIGBM 1 +#define ENABLE_DRM 1 +#define ENABLE_LIBDRM 1 +#define ENABLE_RENDER_SERVER 1 +#define ENABLE_RENDER_SERVER_WORKER_THREAD 1 +#define ENABLE_VULKAN_DLOAD 1 +#define RENDER_SERVER_EXEC_PATH "virgl_render_server" +#define HAVE_PTHREAD 1 +#define HAVE_PTHREAD_SETAFFINITY 1 +#define HAVE_SYS_UIO_H 1 +#define HAVE_DLFCN_H 1 +#define HAVE_EVENTFD_H 1 +#define HAVE_SYS_SELECT_H 1 +#define HAVE_DMABUF_H 1 +#define HAVE_MEMFD_CREATE 1 +#define HAVE_STRTOK_R 1 +#define HAVE_TIMESPEC_GET 1 +#define HAVE___BUILTIN_BSWAP32 1 +#define HAVE___BUILTIN_BSWAP64 1 +#define HAVE___BUILTIN_CLZ 1 +#define HAVE___BUILTIN_CLZLL 1 +#define HAVE___BUILTIN_EXPECT 1 +#define HAVE___BUILTIN_FFS 1 +#define HAVE___BUILTIN_FFSLL 1 +#define HAVE___BUILTIN_POPCOUNT 1 +#define HAVE___BUILTIN_POPCOUNTLL 1 +#define HAVE___BUILTIN_TYPES_COMPATIBLE_P 1 +#define HAVE___BUILTIN_UNREACHABLE 1 +#define HAVE_FUNC_ATTRIBUTE_CONST 1 +#define HAVE_FUNC_ATTRIBUTE_FLATTEN 1 +#define HAVE_FUNC_ATTRIBUTE_FORMAT 1 +#define HAVE_FUNC_ATTRIBUTE_MALLOC 1 +#define HAVE_FUNC_ATTRIBUTE_NORETURN 1 +#define HAVE_FUNC_ATTRIBUTE_PACKED 1 +#define HAVE_FUNC_ATTRIBUTE_PURE 1 +#define HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL 1 +#define HAVE_FUNC_ATTRIBUTE_UNUSED 1 +#define HAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT 1 +#define HAVE_FUNC_ATTRIBUTE_WEAK 1 +#define HAVE_FUNC_ATTRIBUTE_ALIGNED 1 +#define UTIL_ARCH_LITTLE_ENDIAN 1 +#define UTIL_ARCH_BIG_ENDIAN 0 + +#if defined(__aarch64__) +#define PIPE_ARCH_AARCH64 1 +#elif defined(__x86_64__) +#define PIPE_ARCH_X86_64 1 +#endif + +#endif +EOF +""", +) + +genrule( + name = "virgl_version_h", + outs = ["src/virgl-version.h"], + cmd = """cat << 'EOF' > $@ +#ifndef VIRGL_VERSION_H +#define VIRGL_VERSION_H + +#define VIRGL_MAJOR_VERSION 1 +#define VIRGL_MINOR_VERSION 3 +#define VIRGL_MICRO_VERSION 0 + +#endif +EOF +""", +) + +# Venus Codegen +py_binary( + name = "vkr_device_object_py", + srcs = ["src/venus/vkr_device_object.py"], + main = "src/venus/vkr_device_object.py", +) + +genrule( + name = "venus_codegen", + srcs = [ + "src/venus/vkr_device_object.json", + ], + outs = [ + "src/venus/vkr_acceleration_structure_gen.h", + "src/venus/vkr_buffer_gen.h", + "src/venus/vkr_command_buffer_gen.h", + "src/venus/vkr_descriptor_set_gen.h", + "src/venus/vkr_device_memory_gen.h", + "src/venus/vkr_image_gen.h", + "src/venus/vkr_pipeline_gen.h", + "src/venus/vkr_query_pool_gen.h", + "src/venus/vkr_queue_gen.h", + "src/venus/vkr_render_pass_gen.h", + ], + cmd = "$(location :vkr_device_object_py) -o $(@D)/src/venus $(location src/venus/vkr_device_object.json)", + tools = [":vkr_device_object_py"], +) + +# Gallium Format Codegen +py_binary( + name = "u_format_table_py", + srcs = [ + "src/gallium/auxiliary/util/u_format_parse.py", + "src/gallium/auxiliary/util/u_format_table.py", + ], + imports = ["src/gallium/auxiliary/util"], + main = "src/gallium/auxiliary/util/u_format_table.py", + deps = [ + "@pyyaml//:yaml", + ], +) + +genrule( + name = "u_format_table_c", + srcs = ["src/gallium/auxiliary/util/u_format.yaml"], + outs = ["src/gallium/auxiliary/util/u_format_table.c"], + cmd = "$(location :u_format_table_py) $(location src/gallium/auxiliary/util/u_format.yaml) > $@", + tools = [":u_format_table_py"], +) + +genrule( + name = "u_format_gen_h", + srcs = ["src/gallium/auxiliary/util/u_format.yaml"], + outs = ["src/gallium/auxiliary/util/u_format_gen.h"], + cmd = "$(location :u_format_table_py) $(location src/gallium/auxiliary/util/u_format.yaml) --enums > $@", + tools = [":u_format_table_py"], +) + +VIRGL_COMMON_COPTS = [ + "-Wno-error", + "-include", + "$(execpath :config_h)", +] + +# Core Libraries +cc_library( + name = "mesa_util", + srcs = [ + "src/mesa/util/anon_file.c", + "src/mesa/util/bitscan.c", + "src/mesa/util/hash_table.c", + "src/mesa/util/os_file.c", + "src/mesa/util/os_misc.c", + "src/mesa/util/ralloc.c", + "src/mesa/util/u_cpu_detect.c", + "src/mesa/util/u_debug.c", + "src/mesa/util/u_math.c", + ":config_h", + ], + hdrs = glob([ + "src/mesa/**/*.h", + ]), + copts = VIRGL_COMMON_COPTS, + includes = [ + ".", + "src", + "src/mesa", + "src/mesa/compat", + "src/mesa/pipe", + "src/mesa/util", + ], +) + +cc_library( + name = "gallium_aux", + srcs = [ + "src/gallium/auxiliary/cso_cache/cso_cache.c", + "src/gallium/auxiliary/cso_cache/cso_hash.c", + "src/gallium/auxiliary/tgsi/tgsi_build.c", + "src/gallium/auxiliary/tgsi/tgsi_dump.c", + "src/gallium/auxiliary/tgsi/tgsi_info.c", + "src/gallium/auxiliary/tgsi/tgsi_iterate.c", + "src/gallium/auxiliary/tgsi/tgsi_parse.c", + "src/gallium/auxiliary/tgsi/tgsi_sanity.c", + "src/gallium/auxiliary/tgsi/tgsi_scan.c", + "src/gallium/auxiliary/tgsi/tgsi_strings.c", + "src/gallium/auxiliary/tgsi/tgsi_text.c", + "src/gallium/auxiliary/tgsi/tgsi_util.c", + "src/gallium/auxiliary/util/u_debug_describe.c", + "src/gallium/auxiliary/util/u_format.c", + "src/gallium/auxiliary/util/u_hash_table.c", + "src/gallium/auxiliary/util/u_texture.c", + ":config_h", + ":u_format_table_c", + ], + hdrs = glob([ + "src/gallium/**/*.h", + "src/*.h", + ]) + [ + ":config_h", + ":u_format_gen_h", + ], + copts = VIRGL_COMMON_COPTS, + includes = [ + ".", + "src", + "src/gallium/auxiliary", + "src/gallium/auxiliary/util", + "src/gallium/include", + ], + deps = [ + ":mesa_util", + ], +) + +# Dummy Epoxy headers for virglrenderer.c +genrule( + name = "dummy_epoxy_headers", + outs = [ + "include/epoxy/gl.h", + "include/epoxy/egl.h", + ], + cmd = """cat << 'EOF' > $(location include/epoxy/gl.h) +#ifndef DUMMY_EPOXY_GL_H +#define DUMMY_EPOXY_GL_H +#include +typedef unsigned int GLuint; +typedef unsigned int GLenum; +typedef unsigned int GLbitfield; +typedef int GLint; +typedef int GLsizei; +typedef int64_t GLint64; +typedef uint64_t GLuint64; +typedef float GLfloat; +typedef double GLdouble; +typedef char GLchar; +typedef unsigned char GLboolean; +typedef void GLvoid; +#endif +EOF +cat << 'EOF' > $(location include/epoxy/egl.h) +#ifndef DUMMY_EPOXY_EGL_H +#define DUMMY_EPOXY_EGL_H +#endif +EOF +""", +) + +# Vrend stubs for Venus/Vulkan-only mode +genrule( + name = "vrend_stubs_c", + outs = ["src/vrend_stubs.c"], + cmd = """cat << 'EOF' > $@ +#include "config.h" +#include +#include +#include + +struct virgl_resource_pipe_callbacks; +struct vrend_if_cbs; +struct pipe_resource; +struct vrend_renderer_resource_create_args; +struct vrend_renderer_resource_info; +struct vrend_transfer_info; +union virgl_caps; +typedef void *virgl_renderer_gl_context; +struct virgl_gl_ctx_param; +struct virgl_context; +struct iovec; + +const struct virgl_resource_pipe_callbacks *vrend_renderer_get_pipe_callbacks(void) { + return NULL; +} +int vrend_winsys_init(uint32_t flags, int preferred_fd) { + (void)flags; (void)preferred_fd; + return -1; +} +int vrend_winsys_init_external(void *egl_display) { + (void)egl_display; + return -1; +} +void vrend_winsys_cleanup(void) {} +int vrend_renderer_init(const struct vrend_if_cbs *cb, uint32_t flags) { + (void)cb; (void)flags; + return -1; +} +void vrend_renderer_fini(void) {} +void vrend_renderer_prepare_reset(void) {} +void vrend_renderer_poll(void) {} +int vrend_renderer_create_ctx0_fence(uint32_t fence_id) { + (void)fence_id; + return -1; +} +void vrend_renderer_force_ctx_0(void) {} +struct pipe_resource *vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, void *image) { + (void)args; (void)image; + return NULL; +} +int vrend_renderer_resource_get_map_info(struct pipe_resource *pres) { + (void)pres; + return 0; +} +void vrend_renderer_resource_get_info(struct pipe_resource *pres, struct vrend_renderer_resource_info *info) { + (void)pres; (void)info; +} +void *vrend_renderer_resource_d3d11_texture2d(struct pipe_resource *pres, void *d3d_tex2d) { + (void)pres; (void)d3d_tex2d; + return NULL; +} +int vrend_winsys_get_attrs_for_texture(uint32_t tex_id, uint32_t format, int *fourcc, + bool *has_dmabuf_export, int *planes, uint64_t *modifier) { + (void)tex_id; (void)format; (void)fourcc; (void)has_dmabuf_export; (void)planes; (void)modifier; + return -1; +} +int vrend_winsys_get_fd_for_texture(uint32_t tex_id, int *fd) { + (void)tex_id; (void)fd; + return -1; +} +int vrend_winsys_get_fd_for_texture2(uint32_t tex_id, int *fd, int *stride, int *offset) { + (void)tex_id; (void)fd; (void)stride; (void)offset; + return -1; +} +void vrend_renderer_get_cap_set(uint32_t cap_set, uint32_t *max_ver, uint32_t *max_size) { + (void)cap_set; + if (max_ver) *max_ver = 0; + if (max_size) *max_size = 0; +} +void vrend_renderer_fill_caps(uint32_t set, uint32_t version, union virgl_caps *caps) { + (void)set; (void)version; (void)caps; +} +int vrend_renderer_get_rect(struct pipe_resource *pres, const struct iovec *iov, unsigned int num_iovs, + uint32_t offset, int x, int y, int width, int height) { + (void)pres; (void)iov; (void)num_iovs; (void)offset; (void)x; (void)y; (void)width; (void)height; + return -1; +} +int vrend_renderer_get_cursor_contents(struct pipe_resource *pres, uint32_t *ret_buf) { + (void)pres; (void)ret_buf; + return -1; +} +struct virgl_context *vrend_renderer_context_create(uint32_t ctx_id, uint32_t nlen, const char *name) { + (void)ctx_id; (void)nlen; (void)name; + return NULL; +} +int vrend_renderer_transfer_pipe(struct pipe_resource *pres, const struct vrend_transfer_info *info, int transfer_mode) { + (void)pres; (void)info; (void)transfer_mode; + return -1; +} +virgl_renderer_gl_context vrend_winsys_create_context(struct virgl_gl_ctx_param *param) { + (void)param; + return NULL; +} +void vrend_winsys_destroy_context(virgl_renderer_gl_context ctx) { + (void)ctx; +} +int vrend_winsys_make_context_current(virgl_renderer_gl_context ctx) { + (void)ctx; + return -1; +} +void vrend_renderer_reset(void) {} +int vrend_renderer_get_poll_fd(void) { return -1; } +int vrend_renderer_export_query(struct pipe_resource *pres, void *export_query) { + (void)pres; (void)export_query; + return -1; +} +int vrend_renderer_resource_map(struct pipe_resource *pres, void **map, uint64_t *out_size) { + (void)pres; (void)map; (void)out_size; + return -1; +} +int vrend_renderer_resource_unmap(struct pipe_resource *pres) { + (void)pres; + return -1; +} +EOF +""", +) + +cc_library( + name = "virglrenderer_internal", + srcs = [ + "src/drm/drm_context.c", + "src/drm/drm_fence.c", + "src/drm/drm_renderer.c", + "src/drm/drm_util.c", + "src/proxy/proxy_client.c", + "src/proxy/proxy_common.c", + "src/proxy/proxy_context.c", + "src/proxy/proxy_renderer.c", + "src/proxy/proxy_server.c", + "src/proxy/proxy_socket.c", + "src/vrend/iov.c", + "src/venus/vkr_acceleration_structure.c", + "src/venus/vkr_allocator.c", + "src/venus/vkr_buffer.c", + "src/venus/vkr_command_buffer.c", + "src/venus/vkr_common.c", + "src/venus/vkr_context.c", + "src/venus/vkr_cs.c", + "src/venus/vkr_descriptor_heap.c", + "src/venus/vkr_descriptor_set.c", + "src/venus/vkr_device.c", + "src/venus/vkr_device_memory.c", + "src/venus/vkr_host_copy.c", + "src/venus/vkr_image.c", + "src/venus/vkr_instance.c", + "src/venus/vkr_library.c", + "src/venus/vkr_physical_device.c", + "src/venus/vkr_pipeline.c", + "src/venus/vkr_query_pool.c", + "src/venus/vkr_queue.c", + "src/venus/vkr_render_pass.c", + "src/venus/vkr_renderer.c", + "src/venus/vkr_ring.c", + "src/venus/vkr_transport.c", + "src/virgl_context.c", + "src/virgl_fence.c", + "src/virgl_resource.c", + "src/virgl_util.c", + "src/virglrenderer.c", + ":config_h", + ":vrend_stubs_c", + ], + hdrs = glob([ + "src/**/*.h", + "server/*.h", + ]) + [ + ":venus_codegen", + ":virgl_version_h", + ":config_h", + ":dummy_epoxy_headers", + ":u_format_gen_h", + ], + copts = VIRGL_COMMON_COPTS + [ + "-fvisibility=hidden", + ], + includes = [ + ".", + "include", + "src", + "src/drm", + "src/drm/drm-uapi", + "src/gallium/auxiliary", + "src/gallium/auxiliary/util", + "src/gallium/include", + "src/venus", + ], + linkopts = [ + "-pthread", + "-ldl", + "-lm", + ], + deps = [ + ":gallium_aux", + ":mesa_util", + "@libdrm", + "@minigbm//:libgbm_internal", + "@venus_protocol//:vn_protocol_renderer", + ], +) + +cc_shared_library( + name = "libvirglrenderer.so.1", + deps = [":virglrenderer_internal"], + shared_lib_name = "libvirglrenderer.so", +) + +cc_binary( + name = "virgl_render_server", + srcs = [ + "server/main.c", + "server/render_client.c", + "server/render_common.c", + "server/render_context.c", + "server/render_server.c", + "server/render_socket.c", + "server/render_state.c", + "server/render_worker.c", + ":config_h", + ] + glob([ + "server/*.h", + ]), + copts = VIRGL_COMMON_COPTS + [ + "-O0", + ], + includes = [ + ".", + "include", + "server", + "src", + "src/drm", + "src/drm/drm-uapi", + "src/gallium/auxiliary", + "src/gallium/include", + "src/venus", + ], + linkopts = [ + "-pthread", + ], + deps = [ + ":virglrenderer_internal", + "@libdrm", + "@minigbm//:libgbm_internal", + ], +) diff --git a/base/cvd/build_external/virglrenderer/virglrenderer.MODULE.bazel b/base/cvd/build_external/virglrenderer/virglrenderer.MODULE.bazel new file mode 100644 index 00000000000..cb4eae231cb --- /dev/null +++ b/base/cvd/build_external/virglrenderer/virglrenderer.MODULE.bazel @@ -0,0 +1,8 @@ +git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +git_repository( + name = "virglrenderer", + build_file = "@//build_external/virglrenderer:BUILD.virglrenderer.bazel", + commit = "cf6c62da2a1384b194f463e6221371962fe99575", + remote = "https://gitlab.freedesktop.org/virgl/virglrenderer", +) diff --git a/base/cvd/build_external/vulkan_headers/BUILD.vulkan_headers.bazel b/base/cvd/build_external/vulkan_headers/BUILD.vulkan_headers.bazel index 3c2049020a2..2e72f751c02 100644 --- a/base/cvd/build_external/vulkan_headers/BUILD.vulkan_headers.bazel +++ b/base/cvd/build_external/vulkan_headers/BUILD.vulkan_headers.bazel @@ -1,7 +1,11 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") package( - default_visibility = ["@//:android_cuttlefish"], + default_visibility = [ + "@//:android_cuttlefish", + "@venus_protocol//:__subpackages__", + "@virglrenderer//:__subpackages__", + ], ) cc_library( diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/bootconfig_args.cpp b/base/cvd/cuttlefish/host/commands/assemble_cvd/bootconfig_args.cpp index d73097214ea..8bcc4ce280f 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/bootconfig_args.cpp +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/bootconfig_args.cpp @@ -372,6 +372,11 @@ Result> BootconfigArgsFromConfig( bootconfig_args["androidboot.vendor.apex.com.google.cf.vulkan"] = "com.google.cf.vulkan.swiftshader"; } + } else if (gpu_mode == GpuMode::Venus) { + if (instance.has_vulkan_venus_apex()) { + bootconfig_args["androidboot.vendor.apex.com.google.cf.vulkan"] = + "com.google.cf.vulkan.venus"; + } } } diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc index 620f85a9692..10bc6640358 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc @@ -1169,7 +1169,7 @@ Result InitializeCuttlefishConfiguration( } if (hwcomposer_vec[instance_index] == kHwComposerAuto) { - if (gpu_mode == GpuMode::DrmVirgl) { + if (gpu_mode == GpuMode::DrmVirgl || gpu_mode == GpuMode::Venus) { instance.set_hwcomposer(kHwComposerDrm); } else if (gpu_mode == GpuMode::None) { instance.set_hwcomposer(kHwComposerNone); diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/graphics_flags.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/graphics_flags.cc index fcef013afe8..1f5214d0e9d 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/graphics_flags.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/graphics_flags.cc @@ -153,6 +153,18 @@ GetGpuModeRequirementsMap() { "The guest does not support Gfxstream. This is configured in the " "`android-info.txt` file associated with the guest target build.", }; + const RequirementWithReason kGuestSupportsVenus{ + .func = + [](const CommonState& common) { + return common.guest_config.venus_supported || + common.guest_config.has_vulkan_venus_apex; + }, + .success_explanation = "The guest supports Venus.", + .failure_explanation = + "The guest does not claim support for Venus. This is " + "configured in the `android-info.txt` file associated with the guest " + "target build.", + }; const RequirementWithReason kGuestSupportsLavapipe{ .func = [](const CommonState& common) { @@ -234,10 +246,15 @@ GetGpuModeRequirementsMap() { [](const CommonState& common) { const auto& availability = common.graphics_availability; if (availability.has_vulkan() && - !availability.vulkan().physical_devices().empty() && - (availability.vulkan().physical_devices(0).type() != - ::gfxstream::proto::VulkanPhysicalDevice::TYPE_DISCRETE_GPU)) { - return false; + !availability.vulkan().physical_devices().empty()) { + const auto type = + availability.vulkan().physical_devices(0).type(); + if (type != ::gfxstream::proto::VulkanPhysicalDevice:: + TYPE_DISCRETE_GPU && + type != ::gfxstream::proto::VulkanPhysicalDevice:: + TYPE_INTEGRATED_GPU) { + return false; + } } return true; }, @@ -326,6 +343,16 @@ GetGpuModeRequirementsMap() { kNotUsingHostQemu, }, }, + { + GpuMode::Venus, + { + kGuestSupportsVenus, + kHostVulkanLoaderAvailable, + kHostVulkanDriverAvailable, + kHostVulkanIsNonSoftwareRenderer, + kNotUsingHostQemu, + }, + }, { GpuMode::GuestLavapipe, { @@ -516,6 +543,9 @@ std::vector GetGpuModeCandidates(const GuestConfig& guest_config) { gpu_mode_candidates.push_back(GpuMode::GfxstreamGuestAngleHostSwiftshader); gpu_mode_candidates.push_back(GpuMode::GfxstreamGuestAngleHostLavapipe); gpu_mode_candidates.push_back(GpuMode::GuestSwiftshader); + if (guest_config.venus_supported) { + gpu_mode_candidates.push_back(GpuMode::Venus); + } if (guest_config.guest_lavapipe_supported) { gpu_mode_candidates.push_back(GpuMode::GuestLavapipe); } @@ -525,6 +555,9 @@ std::vector GetGpuModeCandidates(const GuestConfig& guest_config) { gpu_mode_candidates.push_back(GpuMode::GfxstreamGuestAngle); gpu_mode_candidates.push_back(GpuMode::GfxstreamGuestAngleHostSwiftshader); gpu_mode_candidates.push_back(GpuMode::GfxstreamGuestAngleHostLavapipe); + if (guest_config.venus_supported) { + gpu_mode_candidates.push_back(GpuMode::Venus); + } if (guest_config.guest_lavapipe_supported) { gpu_mode_candidates.push_back(GpuMode::GuestLavapipe); } @@ -631,7 +664,7 @@ Result SelectGpuVhostUserMode(const GpuMode gpu_mode, gpu_vhost_user_mode_arg == kGpuVhostUserModeOn || gpu_vhost_user_mode_arg == kGpuVhostUserModeOff); if (gpu_vhost_user_mode_arg == kGpuVhostUserModeAuto) { - if (IsGuestRenderingMode(gpu_mode)) { + if (IsGuestRenderingMode(gpu_mode) || gpu_mode == GpuMode::Venus) { VLOG(0) << "GPU vhost user auto mode: not needed for --gpu_mode=" << GpuModeString(gpu_mode) << ". Not enabling vhost user gpu."; return false; @@ -687,6 +720,12 @@ Result SelectGuestHwuiRenderer( return GuestHwuiRenderer::kSkiaVk; } + if (gpu_mode == GpuMode::Venus) { + VLOG(0) << "Selecting SkiaVk as the HWUI renderer for " + << GpuModeString(gpu_mode) << " GPU mode."; + return GuestHwuiRenderer::kSkiaVk; + } + return GuestHwuiRenderer::kUnknown; } @@ -921,6 +960,7 @@ Result ConfigureGpuSettings( instance.set_has_vulkan_lavapipe_apex(guest_config.has_vulkan_lavapipe_apex); instance.set_has_vulkan_swiftshader_apex( guest_config.has_vulkan_swiftshader_apex); + instance.set_has_vulkan_venus_apex(guest_config.has_vulkan_venus_apex); #ifdef __APPLE__ (void)graphics_availability; diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/guest_config.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/guest_config.cc index c33e2ba027e..c0c5c019091 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/guest_config.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/guest_config.cc @@ -150,6 +150,10 @@ Result ParseGuestConfigTextProto(const std::string& guest_config_path, guest_config.has_vulkan_swiftshader_apex = graphics_config.vulkan_swiftshader_apex_supported(); } + if (graphics_config.has_vulkan_venus_apex_supported()) { + guest_config.has_vulkan_venus_apex = + graphics_config.vulkan_venus_apex_supported(); + } const auto& input_config = proto_config.input(); if (input_config.has_mouse_supported()) { @@ -248,6 +252,8 @@ Result ParseGuestConfigTxt(const std::string& guest_config_path, MapHasValue(info, "vulkan_lavapipe_apex", "supported"); guest_config.has_vulkan_swiftshader_apex = MapHasValue(info, "vulkan_swiftshader_apex", "supported"); + guest_config.has_vulkan_venus_apex = + MapHasValue(info, "vulkan_venus_apex", "supported"); guest_config.mouse_supported = MapHasValue(info, "mouse", "supported"); diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/guest_config.h b/base/cvd/cuttlefish/host/commands/assemble_cvd/guest_config.h index b2e7f4237db..49cf0802d1b 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/guest_config.h +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/guest_config.h @@ -41,6 +41,7 @@ struct GuestConfig { bool gfxstream_supported = false; bool gfxstream_gl_program_binary_link_status_supported = false; bool guest_lavapipe_supported = false; + bool venus_supported = false; bool vhost_user_vsock = false; bool supports_bgra_framebuffers = false; bool prefer_drm_virgl_when_supported = false; @@ -58,6 +59,7 @@ struct GuestConfig { bool has_vulkan_lavapipe_apex = false; bool has_vulkan_gfxstream_apex = false; bool has_vulkan_swiftshader_apex = false; + bool has_vulkan_venus_apex = false; }; PrettyStruct Pretty(const GuestConfig&, diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/proto/guest_config.proto b/base/cvd/cuttlefish/host/commands/assemble_cvd/proto/guest_config.proto index 8fd1e76360f..3160507b1de 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/proto/guest_config.proto +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/proto/guest_config.proto @@ -57,6 +57,9 @@ message Graphics { // Whether the guest has a separate apex for the Swiftshader Vulkan driver. bool vulkan_swiftshader_apex_supported = 8; + + // Whether the guest has a separate apex for the Venus Vulkan driver. + bool vulkan_venus_apex_supported = 9; } message Audio { diff --git a/base/cvd/cuttlefish/host/frontend/webrtc/main.cpp b/base/cvd/cuttlefish/host/frontend/webrtc/main.cpp index 3cf067d3b57..02c24455694 100644 --- a/base/cvd/cuttlefish/host/frontend/webrtc/main.cpp +++ b/base/cvd/cuttlefish/host/frontend/webrtc/main.cpp @@ -553,6 +553,8 @@ int CuttlefishMain() { } else if (instance.gpu_mode() == GpuMode::GfxstreamGuestAngle) { user_friendly_gpu_mode = "Gfxstream (Accelerated Rendering using Host Vulkan)"; + } else if (instance.gpu_mode() == GpuMode::Venus) { + user_friendly_gpu_mode = "Venus (Accelerated Rendering using Host Vulkan)"; } else { user_friendly_gpu_mode = GpuModeString(instance.gpu_mode()); } diff --git a/base/cvd/cuttlefish/host/graphics_detector/graphics_detector.proto b/base/cvd/cuttlefish/host/graphics_detector/graphics_detector.proto index e434f3e438e..0a7e1608da8 100644 --- a/base/cvd/cuttlefish/host/graphics_detector/graphics_detector.proto +++ b/base/cvd/cuttlefish/host/graphics_detector/graphics_detector.proto @@ -66,6 +66,8 @@ message VulkanPhysicalDevice { enum Type { TYPE_OTHER = 0; TYPE_DISCRETE_GPU = 1; + TYPE_INTEGRATED_GPU = 2; + TYPE_CPU = 3; } optional Type type = 3; diff --git a/base/cvd/cuttlefish/host/graphics_detector/graphics_detector_vk.cpp b/base/cvd/cuttlefish/host/graphics_detector/graphics_detector_vk.cpp index bf0a5b57211..da26ded2b35 100644 --- a/base/cvd/cuttlefish/host/graphics_detector/graphics_detector_vk.cpp +++ b/base/cvd/cuttlefish/host/graphics_detector/graphics_detector_vk.cpp @@ -35,10 +35,24 @@ gfxstream::expected PopulateVulkanAvailabilityImpl( const auto props = physicalDevice.getProperties(); outPhysicalDevice->set_name(std::string(props.deviceName)); - outPhysicalDevice->set_type( - props.deviceType == vk::PhysicalDeviceType::eDiscreteGpu - ? ::gfxstream::proto::VulkanPhysicalDevice::TYPE_DISCRETE_GPU - : ::gfxstream::proto::VulkanPhysicalDevice::TYPE_OTHER); + switch (props.deviceType) { + case vk::PhysicalDeviceType::eDiscreteGpu: + outPhysicalDevice->set_type( + ::gfxstream::proto::VulkanPhysicalDevice::TYPE_DISCRETE_GPU); + break; + case vk::PhysicalDeviceType::eIntegratedGpu: + outPhysicalDevice->set_type( + ::gfxstream::proto::VulkanPhysicalDevice::TYPE_INTEGRATED_GPU); + break; + case vk::PhysicalDeviceType::eCpu: + outPhysicalDevice->set_type( + ::gfxstream::proto::VulkanPhysicalDevice::TYPE_CPU); + break; + default: + outPhysicalDevice->set_type( + ::gfxstream::proto::VulkanPhysicalDevice::TYPE_OTHER); + break; + } const auto exts = VK_EXPECT_RV(physicalDevice.enumerateDeviceExtensionProperties()); diff --git a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h index b5968115130..d0b792a7add 100644 --- a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h +++ b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h @@ -532,6 +532,7 @@ class CuttlefishConfig { bool has_vulkan_gfxstream_apex() const; bool has_vulkan_lavapipe_apex() const; bool has_vulkan_swiftshader_apex() const; + bool has_vulkan_venus_apex() const; std::string hwcomposer() const; @@ -771,6 +772,7 @@ class CuttlefishConfig { void set_has_vulkan_gfxstream_apex(bool has_apex); void set_has_vulkan_lavapipe_apex(bool has_apex); void set_has_vulkan_swiftshader_apex(bool has_apex); + void set_has_vulkan_venus_apex(bool has_apex); void set_hwcomposer(const std::string&); diff --git a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp index 01cdf6d1b32..c301cd532eb 100644 --- a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp +++ b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp @@ -902,6 +902,15 @@ bool CuttlefishConfig::InstanceSpecific::has_vulkan_swiftshader_apex() const { return (*Dictionary())[kHasVulkanSwiftshaderApex].asBool(); } +static constexpr char kHasVulkanVenusApex[] = "has_vulkan_venus_apex"; +void CuttlefishConfig::MutableInstanceSpecific::set_has_vulkan_venus_apex( + const bool has_apex) { + (*Dictionary())[kHasVulkanVenusApex] = has_apex; +} +bool CuttlefishConfig::InstanceSpecific::has_vulkan_venus_apex() const { + return (*Dictionary())[kHasVulkanVenusApex].asBool(); +} + static constexpr char kEnableAudio[] = "enable_audio"; void CuttlefishConfig::MutableInstanceSpecific::set_enable_audio(bool enable) { (*Dictionary())[kEnableAudio] = enable; diff --git a/base/cvd/cuttlefish/host/libs/config/gpu_mode.cc b/base/cvd/cuttlefish/host/libs/config/gpu_mode.cc index 5a14b8c0291..c06746efca1 100644 --- a/base/cvd/cuttlefish/host/libs/config/gpu_mode.cc +++ b/base/cvd/cuttlefish/host/libs/config/gpu_mode.cc @@ -40,6 +40,8 @@ Result GpuModeFromString(std::string_view mode) { return GpuMode::GfxstreamGuestAngleHostSwiftshader; } else if (mode == kGpuModeGfxstreamGuestAngleHostLavapipe) { return GpuMode::GfxstreamGuestAngleHostLavapipe; + } else if (mode == kGpuModeVenus) { + return GpuMode::Venus; } else if (mode == kGpuModeGuestLavapipe) { return GpuMode::GuestLavapipe; } else if (mode == kGpuModeGuestSwiftshader) { @@ -75,6 +77,9 @@ std::string_view format_as(GpuMode mode) { case GpuMode::GfxstreamGuestAngleHostSwiftshader: return kGpuModeGfxstreamGuestAngleHostSwiftshader; break; + case GpuMode::Venus: + return kGpuModeVenus; + break; case GpuMode::GuestLavapipe: return kGpuModeGuestLavapipe; break; diff --git a/base/cvd/cuttlefish/host/libs/config/gpu_mode.h b/base/cvd/cuttlefish/host/libs/config/gpu_mode.h index 3fe38c52f57..b653f9d96c3 100644 --- a/base/cvd/cuttlefish/host/libs/config/gpu_mode.h +++ b/base/cvd/cuttlefish/host/libs/config/gpu_mode.h @@ -31,6 +31,7 @@ enum class GpuMode { GfxstreamGuestAngle, GfxstreamGuestAngleHostLavapipe, GfxstreamGuestAngleHostSwiftshader, + Venus, GuestLavapipe, GuestSwiftshader, None, @@ -46,6 +47,7 @@ inline constexpr std::string_view kGpuModeGfxstreamGuestAngleHostLavapipe = "gfxstream_guest_angle_host_lavapipe"; inline constexpr std::string_view kGpuModeGfxstreamGuestAngleHostSwiftshader = "gfxstream_guest_angle_host_swiftshader"; +inline constexpr std::string_view kGpuModeVenus = "venus"; inline constexpr std::string_view kGpuModeGuestLavapipe = "guest_lavapipe"; inline constexpr std::string_view kGpuModeGuestSwiftshader = "guest_swiftshader"; @@ -75,6 +77,9 @@ void AbslStringify(Sink& sink, GpuMode mode) { case GpuMode::GfxstreamGuestAngleHostSwiftshader: sink.Append(kGpuModeGfxstreamGuestAngleHostSwiftshader); break; + case GpuMode::Venus: + sink.Append(kGpuModeVenus); + break; case GpuMode::GuestLavapipe: sink.Append(kGpuModeGuestLavapipe); break; diff --git a/base/cvd/cuttlefish/host/libs/screen_connector/screen_connector.h b/base/cvd/cuttlefish/host/libs/screen_connector/screen_connector.h index 2a677bda786..84558043901 100644 --- a/base/cvd/cuttlefish/host/libs/screen_connector/screen_connector.h +++ b/base/cvd/cuttlefish/host/libs/screen_connector/screen_connector.h @@ -71,6 +71,7 @@ class ScreenConnector : public ScreenConnectorFrameRenderer { GpuMode::GfxstreamGuestAngle, GpuMode::GfxstreamGuestAngleHostSwiftshader, GpuMode::GfxstreamGuestAngleHostLavapipe, + GpuMode::Venus, GpuMode::GuestLavapipe, GpuMode::GuestSwiftshader, }; diff --git a/base/cvd/cuttlefish/host/libs/vm_manager/crosvm_manager.cpp b/base/cvd/cuttlefish/host/libs/vm_manager/crosvm_manager.cpp index e8fe2fd0249..92d341a5298 100644 --- a/base/cvd/cuttlefish/host/libs/vm_manager/crosvm_manager.cpp +++ b/base/cvd/cuttlefish/host/libs/vm_manager/crosvm_manager.cpp @@ -160,6 +160,18 @@ CrosvmManager::ConfigureGraphics( {"androidboot.hardware.gltransport", "virtio-gpu-asg"}, {"androidboot.opengles.version", "196609"}, // OpenGL ES 3.1 }; + } else if (instance.gpu_mode() == GpuMode::Venus) { + bootconfig_args = { + {"androidboot.cpuvulkan.version", "0"}, + {"androidboot.hardware.gralloc", "minigbm"}, + {"androidboot.hardware.guest_renderengine_backend", "skiavkthreaded"}, + {"androidboot.hardware.hwcomposer", instance.hwcomposer()}, + {"androidboot.hardware.hwcomposer.mode", "client"}, + {"androidboot.hardware.hwcomposer.display_finder_mode", "drm"}, + {"androidboot.hardware.egl", "angle"}, + {"androidboot.hardware.vulkan", "virtio"}, + {"androidboot.opengles.version", "196609"}, // OpenGL ES 3.1 + }; } else if (instance.gpu_mode() == GpuMode::None) { return {}; } else { @@ -557,6 +569,14 @@ Result ConfigureGpu(const CuttlefishConfig& config, Command* crosvm_cmd) { crosvm_cmd->AddParameter("--gpu=", gpu_displays_string, "context-types=" + instance.gpu_context_types(), gpu_common_string); + } else if (gpu_mode == GpuMode::Venus) { + crosvm_cmd->AddParameter( + "--gpu=", gpu_displays_string, "fixed-blob-mapping=true,", + "backend=virglrenderer,vulkan=true,context-types=venus:cross-domain", + gpu_common_string, ",egl=false,gles=false,glx=false", + gpu_renderer_features_param); + crosvm_cmd->AddParameter("--gpu-render-server=path=", + HostBinaryPath("virgl_render_server")); } CF_EXPECT(MaybeConfigureVulkanIcd(config, crosvm_cmd)); diff --git a/base/cvd/cuttlefish/metrics/conversion/guest_conversion.cc b/base/cvd/cuttlefish/metrics/conversion/guest_conversion.cc index abd264fa6cf..01b8f90b447 100644 --- a/base/cvd/cuttlefish/metrics/conversion/guest_conversion.cc +++ b/base/cvd/cuttlefish/metrics/conversion/guest_conversion.cc @@ -81,6 +81,9 @@ CuttlefishFlags_GpuMode ConvertGpuMode(GpuMode mode) { case GpuMode::GfxstreamGuestAngleHostSwiftshader: return CuttlefishFlags_GpuMode:: CuttlefishFlags_GpuMode_CUTTLEFISH_FLAGS_GPU_MODE_GUEST_GFXSTREAM_GUEST_ANGLE_HOST_SWIFTSHADER; + case GpuMode::Venus: + return CuttlefishFlags_GpuMode:: + CuttlefishFlags_GpuMode_CUTTLEFISH_FLAGS_GPU_MODE_VENUS; case GpuMode::GuestSwiftshader: return CuttlefishFlags_GpuMode:: CuttlefishFlags_GpuMode_CUTTLEFISH_FLAGS_GPU_MODE_GUEST_SWIFTSHADER; diff --git a/base/cvd/cuttlefish/metrics/external_proto/cf_flags.proto b/base/cvd/cuttlefish/metrics/external_proto/cf_flags.proto index 177fde4b1a4..e3aae88d53d 100644 --- a/base/cvd/cuttlefish/metrics/external_proto/cf_flags.proto +++ b/base/cvd/cuttlefish/metrics/external_proto/cf_flags.proto @@ -82,7 +82,7 @@ message CuttlefishFlags { string extra_kernel_cmdline = 9; - // Next index: 11 + // Next index: 12 enum GpuMode { CUTTLEFISH_FLAGS_GPU_MODE_UNSPECIFIED = 0; CUTTLEFISH_FLAGS_GPU_MODE_AUTO = 1; @@ -95,6 +95,7 @@ message CuttlefishFlags { CUTTLEFISH_FLAGS_GPU_MODE_GUEST_VIRGL_RENDERER = 8; CUTTLEFISH_FLAGS_GPU_MODE_NONE = 9; CUTTLEFISH_FLAGS_GPU_MODE_GUEST_LAVAPIPE = 10; + CUTTLEFISH_FLAGS_GPU_MODE_VENUS = 11; } // The graphics backend that the user asked for through flags. diff --git a/base/cvd/cuttlefish/package/BUILD.bazel b/base/cvd/cuttlefish/package/BUILD.bazel index 80cfc3461ed..436622b3325 100644 --- a/base/cvd/cuttlefish/package/BUILD.bazel +++ b/base/cvd/cuttlefish/package/BUILD.bazel @@ -36,6 +36,10 @@ package_files( "bin/aarch64-linux-gnu/libmem_overrides.so": "bin/libmem_overrides.so", "bin/aarch64-linux-gnu/libvk_swiftshader.so": "bin/libvk_swiftshader.so", "bin/x86_64-linux-gnu/gfxstream_graphics_detector": "bin/graphics_detector", + "bin/libvirglrenderer.so": "bin/libvirglrenderer.so.1", + "bin/libgbm.so": "bin/libgbm.so.1", + "lib64/libgbm.so.1": "bin/libgbm.so.1", + "lib64/libgbm.so": "bin/libgbm.so.1", "lib64/vulkan.lvp.so": "bin/libvk_lavapipe.so", "lib64/vulkan.pastel.so": "bin/libvk_swiftshader.so", "bin/prebuilts/libgfxstream_backend.so": "bin/libgfxstream_backend.so", @@ -82,7 +86,9 @@ package_files( "bin/health": "//cuttlefish/host/commands/health", "bin/kernel_log_monitor": "//cuttlefish/host/commands/kernel_log_monitor", "bin/libmem_overrides.so": "//cuttlefish/host/graphics/mem_overrides:libmem_overrides.so", + "bin/libgbm.so.1": "@minigbm//:libgbm.so.1", "bin/libgfxstream_backend.so": "@gfxstream//host:gfxstream_backend", + "bin/libvirglrenderer.so.1": "@virglrenderer//:libvirglrenderer.so.1", "bin/libvk_lavapipe.so": "@mesa//:vk_lavapipe", "bin/libvk_swiftshader.so": "@swiftshader//:vk_swiftshader", "bin/log_tee": "//cuttlefish/host/commands/log_tee", @@ -127,6 +133,7 @@ package_files( "bin/vhu_media_emulated_camera_splane": "//cuttlefish/host/commands/vhost_user_media/emulated_camera_splane", "bin/vhu_media_emulated_camera_mplane": "//cuttlefish/host/commands/vhost_user_media/emulated_camera_mplane", "bin/vhu_media_v4l2_stream_proxy": "//cuttlefish/host/commands/vhost_user_media/v4l2_stream_proxy", + "bin/virgl_render_server": "@virglrenderer//:virgl_render_server", "bin/vk_lavapipe_icd.json": "//cuttlefish/host/graphics/vulkan:vk_lavapipe_icd", "bin/vk_swiftshader_icd.json": "//cuttlefish/host/graphics/vulkan:vk_swiftshader_icd", "bin/webRTC": "//cuttlefish/host/frontend/webrtc:webRTC",