Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/presubmit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,13 @@ jobs:
//host:gfxstream_backend_static
//host:gfxstream_backend_shared
//host:gfxstream_backend
# Nothing is run yet: this job exists to keep the macOS host build
# compiling. Tests need a graphics driver environment that macOS does not
# have here yet.
run-tests: false
# Only tests that need no graphics driver run: macOS has no driver
# environment here yet. The WorkerThread case is not run anywhere yet
# and fails on every platform, so it stays out until it is fixed.
test-targets: >-
common/base:gfxstream_common_base_tests
additional-bazel-args: >-
--test_arg=--gtest_filter=-WorkerThread.TheReturnedFutureFromEnqueueShouldBeReadyBeforeTheWorkerStarts

run-gfxstream-cmake-build:
runs-on: ubuntu-22.04
Expand Down
21 changes: 14 additions & 7 deletions .github/workflows/presubmit_bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ on:
type: boolean
default: true

# Which tests to run. Defaults to the full suite; platforms that can only
# build part of the target graph can override this with a curated list.
test-targets:
type: string
default: >-
host:gfxstream_framebuffer_tests
host/vulkan:gfxstream_compositorvk_tests
host/vulkan:gfxstream_emulatedphysicalmemory_tests
host/vulkan:vk_common_operations_tests
host/vulkan:vk_format_utils_tests
tests/end2end:gfxstream_end2end_tests

permissions:
contents: read

Expand Down Expand Up @@ -91,16 +103,11 @@ jobs:
- name: Test
if: ${{ inputs.run-tests }}
env:
TEST_TARGETS: ${{ inputs.test-targets }}
ADDITIONAL_BAZEL_ARGS: ${{ inputs.additional-bazel-args }}
run: |
bazel test \
bazel test $TEST_TARGETS \
--disk_cache=$HOME/bazel-disk-cache \
--test_output=streamed \
--verbose_failures \
host:gfxstream_framebuffer_tests \
host/vulkan:gfxstream_compositorvk_tests \
host/vulkan:gfxstream_emulatedphysicalmemory_tests \
host/vulkan:vk_common_operations_tests \
host/vulkan:vk_format_utils_tests \
tests/end2end:gfxstream_end2end_tests \
$ADDITIONAL_BAZEL_ARGS
10 changes: 9 additions & 1 deletion common/base/SharedMemory_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,15 @@ int SharedMemory::openInternal(int oflag, int mode, bool doMapping) {
struct stat sb;
if (mShareType == ShareType::SHARED_MEMORY) {
#if defined(__APPLE__)
mFd = ::shm_open(mName.c_str(), oflag, mode);
// An object left behind by a dead process cannot be resized, and one another process
// still uses must not be shared by accident: create fresh, replacing whatever has the
// name. Its owner, if any, keeps it through its descriptor.
const int createFlags = (oflag & O_CREAT) ? (oflag | O_EXCL) : oflag;
mFd = ::shm_open(mName.c_str(), createFlags, mode);
if (mFd == -1 && errno == EEXIST && (oflag & O_CREAT)) {
shm_unlink(mName.c_str());
mFd = ::shm_open(mName.c_str(), createFlags, mode);
}
#elif defined(HAVE_MEMFD_CREATE)
mFd = memfd_create(mName.c_str(), MFD_CLOEXEC | MFD_ALLOW_SEALING);
#else
Expand Down
16 changes: 6 additions & 10 deletions host/vulkan/vk_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11747,14 +11747,12 @@ size_t VkDecoder::Impl::decode(void* buf, size_t len, IOStream* ioStream,
VkDevice device;
const VkDeviceBufferMemoryRequirements* pInfo;
VkMemoryRequirements2* pMemoryRequirements;
// Begin non wrapped dispatchable handle unboxing for device;
// Begin global wrapped dispatchable handle unboxing for device;
uint64_t cgen_var_0;
memcpy((uint64_t*)&cgen_var_0, *readStreamPtrPtr, 1 * 8);
*readStreamPtrPtr += 1 * 8;
*(VkDevice*)&device = (VkDevice)(VkDevice)((VkDevice)(*&cgen_var_0));
auto unboxed_device = unbox_VkDevice(device);
auto vk = dispatch_VkDevice(device);
// End manual dispatchable handle unboxing for device;
vkReadStream->alloc((void**)&pInfo, sizeof(const VkDeviceBufferMemoryRequirements));
reservedunmarshal_VkDeviceBufferMemoryRequirements(
vkReadStream, VK_STRUCTURE_TYPE_MAX_ENUM,
Expand All @@ -11780,8 +11778,8 @@ size_t VkDecoder::Impl::decode(void* buf, size_t len, IOStream* ioStream,
(unsigned long long)pMemoryRequirements);
}
if (CC_LIKELY(vk)) {
vk->vkGetDeviceBufferMemoryRequirements(unboxed_device, pInfo,
pMemoryRequirements);
m_state->on_vkGetDeviceBufferMemoryRequirements(
&m_pool, snapshotApiCallHandle, device, pInfo, pMemoryRequirements);
}
vkStream->unsetHandleMapping();
if (pMemoryRequirements) {
Expand Down Expand Up @@ -17634,14 +17632,12 @@ size_t VkDecoder::Impl::decode(void* buf, size_t len, IOStream* ioStream,
VkDevice device;
const VkDeviceBufferMemoryRequirements* pInfo;
VkMemoryRequirements2* pMemoryRequirements;
// Begin non wrapped dispatchable handle unboxing for device;
// Begin global wrapped dispatchable handle unboxing for device;
uint64_t cgen_var_0;
memcpy((uint64_t*)&cgen_var_0, *readStreamPtrPtr, 1 * 8);
*readStreamPtrPtr += 1 * 8;
*(VkDevice*)&device = (VkDevice)(VkDevice)((VkDevice)(*&cgen_var_0));
auto unboxed_device = unbox_VkDevice(device);
auto vk = dispatch_VkDevice(device);
// End manual dispatchable handle unboxing for device;
vkReadStream->alloc((void**)&pInfo, sizeof(const VkDeviceBufferMemoryRequirements));
reservedunmarshal_VkDeviceBufferMemoryRequirements(
vkReadStream, VK_STRUCTURE_TYPE_MAX_ENUM,
Expand All @@ -17668,8 +17664,8 @@ size_t VkDecoder::Impl::decode(void* buf, size_t len, IOStream* ioStream,
(unsigned long long)pMemoryRequirements);
}
if (CC_LIKELY(vk)) {
vk->vkGetDeviceBufferMemoryRequirementsKHR(unboxed_device, pInfo,
pMemoryRequirements);
m_state->on_vkGetDeviceBufferMemoryRequirementsKHR(
&m_pool, snapshotApiCallHandle, device, pInfo, pMemoryRequirements);
}
vkStream->unsetHandleMapping();
if (pMemoryRequirements) {
Expand Down
96 changes: 78 additions & 18 deletions host/vulkan/vk_decoder_global_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2768,13 +2768,6 @@ class VkDecoderGlobalState::Impl {
GFXSTREAM_FATAL("%s: function implementation cannot be found!");
}

const VkFormat format = pInfo->pCreateInfo->format;
bool needDecompression = isEtc2(format) || isAstc(format);
if (!needDecompression) {
// No modifications needed
return;
}

std::lock_guard<std::mutex> lock(mMutex);

auto* deviceInfo = gfxstream::base::find(mDeviceInfo, device);
Expand All @@ -2783,9 +2776,20 @@ class VkDecoderGlobalState::Impl {
return;
}

needDecompression = deviceInfo->needEmulatedDecompression(format);
auto* physicalDeviceInfo = gfxstream::base::find(mPhysdevInfo, deviceInfo->physicalDevice);
if (!physicalDeviceInfo) {
GFXSTREAM_ERROR("Failed to find physical device info for physical device:%p",
deviceInfo->physicalDevice);
return;
}
auto& physicalDeviceMemHelper = physicalDeviceInfo->memoryPropertiesHelper;

const VkFormat format = pInfo->pCreateInfo->format;
const bool needDecompression =
(isEtc2(format) || isAstc(format)) && deviceInfo->needEmulatedDecompression(format);
if (!needDecompression) {
// No modifications needed
physicalDeviceMemHelper->transformToGuestImageMemoryRequirements(
pInfo->pCreateInfo->tiling, &pMemoryRequirements->memoryRequirements);
return;
}

Expand All @@ -2808,15 +2812,42 @@ class VkDecoderGlobalState::Impl {
pMemoryRequirements->memoryRequirements = cmpInfo.getMemoryRequirements();
cmpInfo.destroy(vk);

physicalDeviceMemHelper->transformToGuestImageMemoryRequirements(
pInfo->pCreateInfo->tiling, &pMemoryRequirements->memoryRequirements);
}

void on_vkGetDeviceBufferMemoryRequirements(gfxstream::base::BumpPool* pool,
Comment thread
utzcoz marked this conversation as resolved.
VkSnapshotApiCallHandle apiCallHandle,
VkDevice boxed_device,
const VkDeviceBufferMemoryRequirements* pInfo,
VkMemoryRequirements2* pMemoryRequirements) {
auto device = unbox_VkDevice(boxed_device);
auto vk = dispatch_VkDevice(boxed_device);

if (vk->vkGetDeviceBufferMemoryRequirements) {
vk->vkGetDeviceBufferMemoryRequirements(device, pInfo, pMemoryRequirements);
} else if (vk->vkGetDeviceBufferMemoryRequirementsKHR) {
vk->vkGetDeviceBufferMemoryRequirementsKHR(device, pInfo, pMemoryRequirements);
} else {
GFXSTREAM_FATAL("%s: function implementation cannot be found!", __func__);
}

std::lock_guard<std::mutex> lock(mMutex);

auto* deviceInfo = gfxstream::base::find(mDeviceInfo, device);
if (!deviceInfo) {
GFXSTREAM_ERROR("%s: Failed to find device info for device: %p", __func__, device);
return;
}

auto* physicalDeviceInfo = gfxstream::base::find(mPhysdevInfo, deviceInfo->physicalDevice);
if (!physicalDeviceInfo) {
GFXSTREAM_ERROR("Failed to find physical device info for physical device:%p",
deviceInfo->physicalDevice);
return;
}

auto& physicalDeviceMemHelper = physicalDeviceInfo->memoryPropertiesHelper;
physicalDeviceMemHelper->transformToGuestMemoryRequirements(
physicalDeviceInfo->memoryPropertiesHelper->transformToGuestMemoryRequirements(
&pMemoryRequirements->memoryRequirements);
}

Expand Down Expand Up @@ -5602,7 +5633,8 @@ class VkDecoderGlobalState::Impl {

auto& physicalDeviceMemHelper = physicalDeviceInfo->memoryPropertiesHelper;
updateImageMemoryRequirementsLocked(device, image, pMemoryRequirements);
physicalDeviceMemHelper->transformToGuestMemoryRequirements(pMemoryRequirements);
physicalDeviceMemHelper->transformToGuestImageMemoryRequirements(
imageTilingLocked(image), pMemoryRequirements);
}

// A driver that defers the layout also reports rowPitch=0; answer with the AHB's stride.
Expand Down Expand Up @@ -5668,8 +5700,8 @@ class VkDecoderGlobalState::Impl {
auto& physicalDeviceMemHelper = physicalDeviceInfo->memoryPropertiesHelper;
updateImageMemoryRequirementsLocked(device, pInfo->image,
&pMemoryRequirements->memoryRequirements);
physicalDeviceMemHelper->transformToGuestMemoryRequirements(
&pMemoryRequirements->memoryRequirements);
physicalDeviceMemHelper->transformToGuestImageMemoryRequirements(
imageTilingLocked(pInfo->image), &pMemoryRequirements->memoryRequirements);
}

void on_vkGetBufferMemoryRequirements(gfxstream::base::BumpPool* pool, VkSnapshotApiCallHandle,
Expand Down Expand Up @@ -6855,15 +6887,25 @@ class VkDecoderGlobalState::Impl {
#endif
} else if (m_vkEmulation->getFeatures().SystemBlob.enabled() ||
m_vkEmulation->getFeatures().VulkanAllocateHostVisibleAsUdmabuf.enabled()) {
// A system blob is imported as a host pointer, and a driver can ask for a
// coarser alignment than a page: Apple silicon pages are 16KB.
uint64_t blobAlignment = kPageSizeforBlob;
if (m_vkEmulation->supportsExternalMemoryHostProperties()) {
blobAlignment = std::max<uint64_t>(blobAlignment,
m_vkEmulation->externalMemoryHostProperties()
.minImportedHostPointerAlignment);
}

// Ensure size is page-aligned.
VkDeviceSize alignedSize = ALIGN(localAllocInfo.allocationSize, kPageSizeforBlob);
VkDeviceSize alignedSize = ALIGN(localAllocInfo.allocationSize, blobAlignment);
if (alignedSize != localAllocInfo.allocationSize) {
GFXSTREAM_ERROR("Warning: Aligning allocation size from %llu to %llu",
static_cast<unsigned long long>(localAllocInfo.allocationSize),
static_cast<unsigned long long>(alignedSize));
}
localAllocInfo.allocationSize = alignedSize;
auto memory = SharedMemory("shared-memory-vk-" + std::to_string(sUniqueShmemId++),
auto memory = SharedMemory("shared-memory-vk-" + std::to_string(getpid()) + "-" +
std::to_string(sUniqueShmemId++),
localAllocInfo.allocationSize);

if (m_vkEmulation->getFeatures().VulkanAllocateHostVisibleAsUdmabuf.enabled()) {
Expand Down Expand Up @@ -6908,8 +6950,7 @@ class VkDecoderGlobalState::Impl {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
mappedPtr = memory.get();
int mappedPtrAlignment =
reinterpret_cast<uintptr_t>(mappedPtr) % kPageSizeforBlob;
int mappedPtrAlignment = reinterpret_cast<uintptr_t>(mappedPtr) % blobAlignment;
if (mappedPtrAlignment != 0) {
GFXSTREAM_ERROR(
"Warning: Mapped shared memory pointer is not aligned to page size, "
Expand Down Expand Up @@ -10495,6 +10536,11 @@ class VkDecoderGlobalState::Impl {
return false;
}

VkImageTiling imageTilingLocked(VkImage image) REQUIRES(mMutex) {
auto* imageInfo = gfxstream::base::find(mImageInfo, image);
return imageInfo ? imageInfo->imageCreateInfoShallow.tiling : VK_IMAGE_TILING_OPTIMAL;
}

void updateImageMemoryRequirementsLocked(VkDevice device, VkImage image,
VkMemoryRequirements* pMemoryRequirements)
REQUIRES(mMutex) {
Expand Down Expand Up @@ -11767,6 +11813,20 @@ void VkDecoderGlobalState::on_vkGetDeviceImageMemoryRequirementsKHR(
pMemoryRequirements);
}

void VkDecoderGlobalState::on_vkGetDeviceBufferMemoryRequirements(
gfxstream::base::BumpPool* pool, VkSnapshotApiCallHandle apiCallHandle, VkDevice device,
const VkDeviceBufferMemoryRequirements* pInfo, VkMemoryRequirements2* pMemoryRequirements) {
mImpl->on_vkGetDeviceBufferMemoryRequirements(pool, apiCallHandle, device, pInfo,
pMemoryRequirements);
}

void VkDecoderGlobalState::on_vkGetDeviceBufferMemoryRequirementsKHR(
gfxstream::base::BumpPool* pool, VkSnapshotApiCallHandle apiCallHandle, VkDevice device,
const VkDeviceBufferMemoryRequirements* pInfo, VkMemoryRequirements2* pMemoryRequirements) {
mImpl->on_vkGetDeviceBufferMemoryRequirements(pool, apiCallHandle, device, pInfo,
pMemoryRequirements);
}

void VkDecoderGlobalState::on_vkDestroyDevice(gfxstream::base::BumpPool* pool,
VkSnapshotApiCallHandle apiCallHandle,
VkDevice device, const VkAllocationCallbacks*) {
Expand Down
11 changes: 11 additions & 0 deletions host/vulkan/vk_decoder_global_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,17 @@ class VkDecoderGlobalState {
const VkDeviceImageMemoryRequirements* pInfo,
VkMemoryRequirements2* pMemoryRequirements);

void on_vkGetDeviceBufferMemoryRequirements(gfxstream::base::BumpPool* pool,
VkSnapshotApiCallHandle apiCallHandle,
VkDevice device,
const VkDeviceBufferMemoryRequirements* pInfo,
VkMemoryRequirements2* pMemoryRequirements);
void on_vkGetDeviceBufferMemoryRequirementsKHR(gfxstream::base::BumpPool* pool,
VkSnapshotApiCallHandle apiCallHandle,
VkDevice device,
const VkDeviceBufferMemoryRequirements* pInfo,
VkMemoryRequirements2* pMemoryRequirements);

void on_vkDestroyDevice(gfxstream::base::BumpPool* pool, VkSnapshotApiCallHandle apiCallHandle,
VkDevice device, const VkAllocationCallbacks* pAllocator);

Expand Down
Loading
Loading