Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First pass on adding multi-planar images. #2691

Merged
merged 2 commits into from
May 23, 2019
Merged
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
14 changes: 8 additions & 6 deletions gapii/cc/vulkan_extras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,25 +583,27 @@ VulkanSpy::fetchPhysicalDeviceFormatProperties(

gapil::Ref<FetchedImageMemoryRequirements>
VulkanSpy::fetchImageMemoryRequirements(CallObserver* observer, VkDevice device,
VkImage image, bool hasSparseBit) {
gapil::Ref<ImageObject> image,
bool hasSparseBit) {
auto reqs = gapil::Ref<FetchedImageMemoryRequirements>::create(arena());
VkMemoryRequirements rawReq{0};
mImports.mVkDeviceFunctions[device].vkGetImageMemoryRequirements(
device, image, &rawReq);
device, image->mVulkanHandle, &rawReq);
// TODO: Handle multi-planar images
reqs->mPlaneBitsToMemoryRequirements[0] = rawReq;
if (hasSparseBit) {
uint32_t sparse_mem_req_count = 0;
mImports.mVkDeviceFunctions[device].vkGetImageSparseMemoryRequirements(
device, image, &sparse_mem_req_count, nullptr);
device, image->mVulkanHandle, &sparse_mem_req_count, nullptr);
core::Arena arena;
std::vector<VkSparseImageMemoryRequirements> sparse_mem_reqs(
sparse_mem_req_count, VkSparseImageMemoryRequirements(&arena));
mImports.mVkDeviceFunctions[device].vkGetImageSparseMemoryRequirements(
device, image, &sparse_mem_req_count, sparse_mem_reqs.data());
device, image->mVulkanHandle, &sparse_mem_req_count,
sparse_mem_reqs.data());
for (VkSparseImageMemoryRequirements& req : sparse_mem_reqs) {
auto aspect_map = subUnpackImageAspectFlags(
nullptr, nullptr, req.mformatProperties.maspectMask);
nullptr, nullptr, image, req.mformatProperties.maspectMask);
for (auto aspect : aspect_map) {
reqs->mAspectBitsToSparseMemoryRequirements[aspect.second] = req;
}
Expand Down Expand Up @@ -941,7 +943,7 @@ void VulkanSpy::walkImageSubRng(
uint32_t level_count =
subImageSubresourceLevelCount(nullptr, nullptr, img, rng);
auto aspect_map =
subUnpackImageAspectFlags(nullptr, nullptr, rng.maspectMask);
subUnpackImageAspectFlags(nullptr, nullptr, img, rng.maspectMask);
for (auto b : aspect_map) {
auto ai = img->mAspects.find(b.second);
if (ai == img->mAspects.end()) {
Expand Down
70 changes: 41 additions & 29 deletions gapii/cc/vulkan_mid_execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,16 +435,12 @@ void VulkanSpy::serializeGPUBuffers(StateSerializer *serializer) {

auto get_element_size = [this](uint32_t format, uint32_t aspect_bit,
bool in_buffer) -> uint32_t {
switch (aspect_bit) {
case VkImageAspectFlagBits::VK_IMAGE_ASPECT_COLOR_BIT:
return subGetElementAndTexelBlockSize(nullptr, nullptr, format)
.mElementSize;
case VkImageAspectFlagBits::VK_IMAGE_ASPECT_DEPTH_BIT:
return subGetDepthElementSize(nullptr, nullptr, format, in_buffer);
case VkImageAspectFlagBits::VK_IMAGE_ASPECT_STENCIL_BIT:
return 1;
if (VkImageAspectFlagBits::VK_IMAGE_ASPECT_STENCIL_BIT == aspect_bit) {
return subGetDepthElementSize(nullptr, nullptr, format, in_buffer);
}
return 0;
return subGetElementAndTexelBlockSizeForAspect(nullptr, nullptr, format,
aspect_bit)
.mElementSize;
};

auto next_multiple_of_8 = [](size_t value) -> size_t {
Expand All @@ -469,17 +465,22 @@ void VulkanSpy::serializeGPUBuffers(StateSerializer *serializer) {
auto &lev = img->mAspects[aspect_bit]->mLayers[layer]->mLevels[level];
const bool has_linear_layout =
(lev->mLinearLayout != nullptr) && (lev->mLinearLayout->msize != 0);
auto elementAndTexelBlockSize =
subGetElementAndTexelBlockSize(nullptr, nullptr, info.mFormat);
auto elementAndTexelBlockSize = subGetElementAndTexelBlockSizeForAspect(
nullptr, nullptr, info.mFormat, aspect_bit);
auto divisor =
subGetAspectSizeDivisor(nullptr, nullptr, info.mFormat, aspect_bit);

const uint32_t texel_width =
elementAndTexelBlockSize.mTexelBlockSize.mWidth;
const uint32_t texel_height =
elementAndTexelBlockSize.mTexelBlockSize.mHeight;

const uint32_t width =
subGetMipSize(nullptr, nullptr, info.mExtent.mWidth, level);
subGetMipSize(nullptr, nullptr, info.mExtent.mWidth, level) /
divisor.mWidth;
const uint32_t height =
subGetMipSize(nullptr, nullptr, info.mExtent.mHeight, level);
subGetMipSize(nullptr, nullptr, info.mExtent.mHeight, level) /
divisor.mHeight;
const uint32_t width_in_blocks =
subRoundUpTo(nullptr, nullptr, width, texel_width);
const uint32_t height_in_blocks =
Expand All @@ -506,17 +507,21 @@ void VulkanSpy::serializeGPUBuffers(StateSerializer *serializer) {
auto extent_pitch = [this, &get_element_size](
const VkExtent3D &extent, uint32_t format,
uint32_t aspect_bit) -> pitch {
auto elementAndTexelBlockSize =
subGetElementAndTexelBlockSize(nullptr, nullptr, format);
auto elementAndTexelBlockSize = subGetElementAndTexelBlockSizeForAspect(
nullptr, nullptr, format, aspect_bit);
auto divisor =
subGetAspectSizeDivisor(nullptr, nullptr, format, aspect_bit);
const uint32_t texel_width =
elementAndTexelBlockSize.mTexelBlockSize.mWidth;
const uint32_t texel_height =
elementAndTexelBlockSize.mTexelBlockSize.mHeight;

const uint32_t width_in_blocks =
subRoundUpTo(nullptr, nullptr, extent.mWidth, texel_width);
subRoundUpTo(nullptr, nullptr, extent.mWidth, texel_width) /
divisor.mWidth;
const uint32_t height_in_blocks =
subRoundUpTo(nullptr, nullptr, extent.mHeight, texel_height);
subRoundUpTo(nullptr, nullptr, extent.mHeight, texel_height) /
divisor.mHeight;
const uint32_t element_size = get_element_size(format, aspect_bit, false);

return pitch{
Expand All @@ -540,19 +545,26 @@ void VulkanSpy::serializeGPUBuffers(StateSerializer *serializer) {

auto level_size = [this, &get_element_size, &next_multiple_of_8](
const VkExtent3D &extent, uint32_t format,
uint32_t mip_level,
uint32_t aspect_bit) -> byte_size_and_extent {
uint32_t mip_level, uint32_t aspect_bit,
bool account_for_plane) -> byte_size_and_extent {
auto elementAndTexelBlockSize =
subGetElementAndTexelBlockSize(nullptr, nullptr, format);

auto divisor =
subGetAspectSizeDivisor(nullptr, nullptr, format, aspect_bit);
if (!account_for_plane) {
divisor.mWidth = 1;
divisor.mHeight = 1;
}
const uint32_t texel_width =
elementAndTexelBlockSize.mTexelBlockSize.mWidth;
const uint32_t texel_height =
elementAndTexelBlockSize.mTexelBlockSize.mHeight;
const uint32_t width =
subGetMipSize(nullptr, nullptr, extent.mWidth, mip_level);
subGetMipSize(nullptr, nullptr, extent.mWidth, mip_level) /
divisor.mWidth;
const uint32_t height =
subGetMipSize(nullptr, nullptr, extent.mHeight, mip_level);
subGetMipSize(nullptr, nullptr, extent.mHeight, mip_level) /
divisor.mHeight;
const uint32_t depth =
subGetMipSize(nullptr, nullptr, extent.mDepth, mip_level);
const uint32_t width_in_blocks =
Expand Down Expand Up @@ -588,8 +600,8 @@ void VulkanSpy::serializeGPUBuffers(StateSerializer *serializer) {
uint32_t aspect, uint32_t layer, uint32_t level) {
auto img_level =
img->mAspects[aspect]->mLayers[layer]->mLevels[level];
level_sizes[img_level.get()] =
level_size(img->mInfo.mExtent, img->mInfo.mFormat, level, aspect);
level_sizes[img_level.get()] = level_size(
img->mInfo.mExtent, img->mInfo.mFormat, level, aspect, true);
uint64_t pool_size = level_sizes[img_level.get()].level_size;
if (img_level->mLinearLayout != nullptr &&
img_level->mLinearLayout->msize > pool_size) {
Expand Down Expand Up @@ -769,8 +781,8 @@ void VulkanSpy::serializeGPUBuffers(StateSerializer *serializer) {
}

if (sparseResidency) {
for (auto &aspect_i :
subUnpackImageAspectFlags(nullptr, nullptr, img->mImageAspect)) {
for (auto &aspect_i : subUnpackImageAspectFlags(nullptr, nullptr, img,
img->mImageAspect)) {
uint32_t aspect_bit = aspect_i.second;
if (img->mSparseImageMemoryBindings.find(aspect_bit) !=
img->mSparseImageMemoryBindings.end()) {
Expand Down Expand Up @@ -806,7 +818,7 @@ void VulkanSpy::serializeGPUBuffers(StateSerializer *serializer) {
copies_in_order.push_back(copy);
byte_size_and_extent e =
level_size(block_i.second->mExtent, image_info.mFormat, 0,
aspect_bit);
aspect_bit, false);
offset += e.aligned_level_size_in_buf;
}
}
Expand Down Expand Up @@ -892,8 +904,8 @@ void VulkanSpy::serializeGPUBuffers(StateSerializer *serializer) {
(uint32_t)copy.mimageSubresource.maspectMask;
const uint32_t mip_level = copy.mimageSubresource.mmipLevel;
const uint32_t array_layer = copy.mimageSubresource.mbaseArrayLayer;
byte_size_and_extent e =
level_size(copy.mimageExtent, image_info.mFormat, 0, aspect_bit);
byte_size_and_extent e = level_size(
copy.mimageExtent, image_info.mFormat, 0, aspect_bit, false);

if ((image_info.mFormat == VkFormat::VK_FORMAT_X8_D24_UNORM_PACK32 ||
image_info.mFormat == VkFormat::VK_FORMAT_D24_UNORM_S8_UINT) &&
Expand Down
1 change: 1 addition & 0 deletions gapis/api/templates/mutate.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"github.com/google/gapid/gapis/replay/value"
"github.com/google/gapid/gapis/stringtable"


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: remove.

ϟmem "github.com/google/gapid/gapis/memory"
)

Expand Down
15 changes: 3 additions & 12 deletions gapis/api/vulkan/api/coherent_memory.api
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ sub void readCoherentMemoryInImage(ref!ImageObject image) {
}

// VkImageSubresourceRange data

@spy_disabled
sub void accessImageSubresourceSlice(ref!ImageObject image, VkImageSubresourceRange rng, u32 baseDepth, u32 depthCount, bool isWrite) {
VK_REMAINING_ARRAY_LAYERS := as!u32(0xFFFFFFFF)
Expand All @@ -219,20 +218,12 @@ sub void accessImageSubresourceSlice(ref!ImageObject image, VkImageSubresourceRa

format := image.Info.Format
elementAndTexelBlockSize := getElementAndTexelBlockSize(format)
depthElementSize := getDepthElementSize(format, false)
blockWidth := as!u64(elementAndTexelBlockSize.TexelBlockSize.Width)
blockHeight := as!u64(elementAndTexelBlockSize.TexelBlockSize.Height)

for _ , _ , aspectBit in getAspectKeysWithAspectFlags(image, rng.aspectMask) {
elementSize := switch (aspectBit) {
case VK_IMAGE_ASPECT_COLOR_BIT:
as!u64(elementAndTexelBlockSize.ElementSize)
case VK_IMAGE_ASPECT_DEPTH_BIT:
as!u64(depthElementSize)
case VK_IMAGE_ASPECT_STENCIL_BIT:
as!u64(1)
}
for _ , _ , aspectBit in unpackImageAspectFlags(image, rng.aspectMask) {
if !aspectBit in image.Aspects { vkErrorInvalidImageAspect(image.VulkanHandle, aspectBit) } else {
elementSize := getElementAndTexelBlockSizeForAspect(format, as!VkImageAspectFlagBits(aspectBit))
for _, i, layer in image.Aspects[aspectBit].Layers {
if (i >= rng.baseArrayLayer) && (i < rng.baseArrayLayer + layerCount) {
for _, k, level in layer.Levels {
Expand All @@ -247,7 +238,7 @@ sub void accessImageSubresourceSlice(ref!ImageObject image, VkImageSubresourceRa
imageLevelHeightInBlocks := as!u64(roundUpTo(level.Height, as!u32(blockHeight)))
depthPitch := switch level.LinearLayout {
case null:
imageLevelHeightInBlocks * imageLevelWidthInBlocks * elementSize
imageLevelHeightInBlocks * imageLevelWidthInBlocks * as!u64(elementSize.ElementSize)
default:
as!u64(level.LinearLayout.depthPitch)
}
Expand Down
Loading