Commit fcc64415 by Nicolas Capens Committed by Nicolas Capens

Refactor writing texture level descriptor info

This will make it easier to write YCbCr plane data as mipmap levels. Also removes the unused fWidth, fHeight, and fDepth from sw::Mipmap, and ensured the other members are aligned to their vector size. Bug: b/132437008 Tests: dEQP-VK.*ycbcr* Change-Id: Ib2b0cbebf9e4fd640fcc104281097ff3c4c73b5d Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/31616 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com>
parent ba873309
......@@ -31,13 +31,13 @@ namespace sw
{
const void *buffer[6];
short uHalf[4];
short vHalf[4];
short wHalf[4];
short4 uHalf;
short4 vHalf;
short4 wHalf;
int4 width;
int4 height;
int4 depth;
short onePitchP[4];
short4 onePitchP;
int4 pitchP;
int4 sliceP;
};
......
......@@ -340,7 +340,10 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor
for(uint32_t i = 0; i < entry.descriptorCount; i++)
{
auto update = reinterpret_cast<VkDescriptorImageInfo const *>(src + entry.offset + entry.stride * i);
vk::ImageView *imageView = vk::Cast(update->imageView);
Format format = imageView->getFormat(ImageView::SAMPLING);
sw::Texture *texture = &imageSampler[i].texture;
// "All consecutive bindings updated via a single VkWriteDescriptorSet structure, except those with a
......@@ -357,7 +360,7 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor
imageSampler[i].sampleCount = imageView->getSampleCount();
imageSampler[i].type = imageView->getType();
imageSampler[i].swizzle = imageView->getComponentMapping();
imageSampler[i].format = imageView->getFormat(ImageView::SAMPLING);
imageSampler[i].format = format;
auto &subresourceRange = imageView->getSubresourceRange();
......@@ -387,16 +390,85 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor
}
VkExtent3D extent = imageView->getMipLevelExtent(level);
Format format = imageView->getFormat(ImageView::SAMPLING);
int layers = imageView->getSubresourceRange().layerCount;
// TODO(b/129523279): Untangle depth vs layers throughout the sampler
int width = extent.width;
int height = extent.height;
int layers = imageView->getSubresourceRange().layerCount; // TODO(b/129523279): Untangle depth vs layers throughout the sampler
int depth = layers > 1 ? layers : extent.depth;
int pitchP = imageView->rowPitchBytes(aspect, level, ImageView::SAMPLING) / format.bytes();
int sliceP = (layers > 1 ? imageView->layerPitchBytes(aspect, ImageView::SAMPLING) : imageView->slicePitchBytes(aspect, level, ImageView::SAMPLING)) / format.bytes();
if(mipmapLevel == 0)
WriteTextureLevelInfo(texture, mipmapLevel, width, height, depth, pitchP, sliceP);
}
}
}
else if (entry.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE ||
entry.descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)
{
auto descriptor = reinterpret_cast<StorageImageDescriptor *>(memToWrite);
for(uint32_t i = 0; i < entry.descriptorCount; i++)
{
auto update = reinterpret_cast<VkDescriptorImageInfo const *>(src + entry.offset + entry.stride * i);
auto imageView = Cast(update->imageView);
descriptor[i].ptr = imageView->getOffsetPointer({0, 0, 0}, VK_IMAGE_ASPECT_COLOR_BIT, 0, 0);
descriptor[i].extent = imageView->getMipLevelExtent(0);
descriptor[i].rowPitchBytes = imageView->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0);
descriptor[i].samplePitchBytes = imageView->getSubresourceRange().layerCount > 1
? imageView->layerPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT)
: imageView->slicePitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0);
descriptor[i].slicePitchBytes = descriptor[i].samplePitchBytes * imageView->getSampleCount();
descriptor[i].arrayLayers = imageView->getSubresourceRange().layerCount;
descriptor[i].sampleCount = imageView->getSampleCount();
descriptor[i].sizeInBytes = imageView->getImageSizeInBytes();
if (imageView->getFormat().isStencil())
{
descriptor[i].stencilPtr = imageView->getOffsetPointer({0, 0, 0}, VK_IMAGE_ASPECT_STENCIL_BIT, 0, 0);
descriptor[i].stencilRowPitchBytes = imageView->rowPitchBytes(VK_IMAGE_ASPECT_STENCIL_BIT, 0);
descriptor[i].stencilSamplePitchBytes = imageView->getSubresourceRange().layerCount > 1
? imageView->layerPitchBytes(VK_IMAGE_ASPECT_STENCIL_BIT)
: imageView->slicePitchBytes(VK_IMAGE_ASPECT_STENCIL_BIT, 0);
descriptor[i].stencilSlicePitchBytes = descriptor[i].stencilSamplePitchBytes * imageView->getSampleCount();
}
}
}
else if (entry.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)
{
auto descriptor = reinterpret_cast<StorageImageDescriptor *>(memToWrite);
for (uint32_t i = 0; i < entry.descriptorCount; i++)
{
auto update = reinterpret_cast<VkBufferView const *>(src + entry.offset + entry.stride * i);
auto bufferView = Cast(*update);
descriptor[i].ptr = bufferView->getPointer();
descriptor[i].extent = {bufferView->getElementCount(), 1, 1};
descriptor[i].rowPitchBytes = 0;
descriptor[i].slicePitchBytes = 0;
descriptor[i].samplePitchBytes = 0;
descriptor[i].arrayLayers = 1;
descriptor[i].sampleCount = 1;
descriptor[i].sizeInBytes = bufferView->getRangeInBytes();
}
}
else if (entry.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ||
entry.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
entry.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER ||
entry.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)
{
auto descriptor = reinterpret_cast<BufferDescriptor *>(memToWrite);
for (uint32_t i = 0; i < entry.descriptorCount; i++)
{
auto update = reinterpret_cast<VkDescriptorBufferInfo const *>(src + entry.offset + entry.stride * i);
auto buffer = Cast(update->buffer);
descriptor[i].ptr = buffer->getOffsetPointer(update->offset);
descriptor[i].sizeInBytes = (update->range == VK_WHOLE_SIZE) ? buffer->getSize() - update->offset : update->range;
descriptor[i].robustnessSize = buffer->getSize() - update->offset;
}
}
}
void DescriptorSetLayout::WriteTextureLevelInfo(sw::Texture *texture, int level, int width, int height, int depth, int pitchP, int sliceP)
{
if(level == 0)
{
texture->widthWidthHeightHeight[0] = width;
texture->widthWidthHeightHeight[1] = width;
......@@ -419,6 +491,8 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor
texture->depth[3] = depth;
}
sw::Mipmap &mipmap = texture->mipmap[level];
short halfTexelU = 0x8000 / width;
short halfTexelV = 0x8000 / height;
short halfTexelW = 0x8000 / depth;
......@@ -467,98 +541,6 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor
mipmap.sliceP[1] = sliceP;
mipmap.sliceP[2] = sliceP;
mipmap.sliceP[3] = sliceP;
// TODO(b/129523279)
if(false/*format == FORMAT_YV12_BT601 ||
format == FORMAT_YV12_BT709 ||
format == FORMAT_YV12_JFIF*/)
{
unsigned int YStride = pitchP;
unsigned int YSize = YStride * height;
unsigned int CStride = sw::align<16>(YStride / 2);
unsigned int CSize = CStride * height / 2;
mipmap.buffer[1] = (sw::byte*)mipmap.buffer[0] + YSize;
mipmap.buffer[2] = (sw::byte*)mipmap.buffer[1] + CSize;
texture->mipmap[1].width[0] = width / 2;
texture->mipmap[1].width[1] = width / 2;
texture->mipmap[1].width[2] = width / 2;
texture->mipmap[1].width[3] = width / 2;
texture->mipmap[1].height[0] = height / 2;
texture->mipmap[1].height[1] = height / 2;
texture->mipmap[1].height[2] = height / 2;
texture->mipmap[1].height[3] = height / 2;
texture->mipmap[1].onePitchP[0] = 1;
texture->mipmap[1].onePitchP[1] = CStride;
texture->mipmap[1].onePitchP[2] = 1;
texture->mipmap[1].onePitchP[3] = CStride;
}
}
}
}
else if (entry.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE ||
entry.descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)
{
auto descriptor = reinterpret_cast<StorageImageDescriptor *>(memToWrite);
for(uint32_t i = 0; i < entry.descriptorCount; i++)
{
auto update = reinterpret_cast<VkDescriptorImageInfo const *>(src + entry.offset + entry.stride * i);
auto imageView = Cast(update->imageView);
descriptor[i].ptr = imageView->getOffsetPointer({0, 0, 0}, VK_IMAGE_ASPECT_COLOR_BIT, 0, 0);
descriptor[i].extent = imageView->getMipLevelExtent(0);
descriptor[i].rowPitchBytes = imageView->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0);
descriptor[i].samplePitchBytes = imageView->getSubresourceRange().layerCount > 1
? imageView->layerPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT)
: imageView->slicePitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0);
descriptor[i].slicePitchBytes = descriptor[i].samplePitchBytes * imageView->getSampleCount();
descriptor[i].arrayLayers = imageView->getSubresourceRange().layerCount;
descriptor[i].sampleCount = imageView->getSampleCount();
descriptor[i].sizeInBytes = imageView->getImageSizeInBytes();
if (imageView->getFormat().isStencil())
{
descriptor[i].stencilPtr = imageView->getOffsetPointer({0, 0, 0}, VK_IMAGE_ASPECT_STENCIL_BIT, 0, 0);
descriptor[i].stencilRowPitchBytes = imageView->rowPitchBytes(VK_IMAGE_ASPECT_STENCIL_BIT, 0);
descriptor[i].stencilSamplePitchBytes = imageView->getSubresourceRange().layerCount > 1
? imageView->layerPitchBytes(VK_IMAGE_ASPECT_STENCIL_BIT)
: imageView->slicePitchBytes(VK_IMAGE_ASPECT_STENCIL_BIT, 0);
descriptor[i].stencilSlicePitchBytes = descriptor[i].stencilSamplePitchBytes * imageView->getSampleCount();
}
}
}
else if (entry.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)
{
auto descriptor = reinterpret_cast<StorageImageDescriptor *>(memToWrite);
for (uint32_t i = 0; i < entry.descriptorCount; i++)
{
auto update = reinterpret_cast<VkBufferView const *>(src + entry.offset + entry.stride * i);
auto bufferView = Cast(*update);
descriptor[i].ptr = bufferView->getPointer();
descriptor[i].extent = {bufferView->getElementCount(), 1, 1};
descriptor[i].rowPitchBytes = 0;
descriptor[i].slicePitchBytes = 0;
descriptor[i].samplePitchBytes = 0;
descriptor[i].arrayLayers = 1;
descriptor[i].sampleCount = 1;
descriptor[i].sizeInBytes = bufferView->getRangeInBytes();
}
}
else if (entry.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ||
entry.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
entry.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER ||
entry.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)
{
auto descriptor = reinterpret_cast<BufferDescriptor *>(memToWrite);
for (uint32_t i = 0; i < entry.descriptorCount; i++)
{
auto update = reinterpret_cast<VkDescriptorBufferInfo const *>(src + entry.offset + entry.stride * i);
auto buffer = Cast(update->buffer);
descriptor[i].ptr = buffer->getOffsetPointer(update->offset);
descriptor[i].sizeInBytes = (update->range == VK_WHOLE_SIZE) ? buffer->getSize() - update->offset : update->range;
descriptor[i].robustnessSize = buffer->getSize() - update->offset;
}
}
}
void DescriptorSetLayout::WriteDescriptorSet(const VkWriteDescriptorSet& writeDescriptorSet)
......
......@@ -82,6 +82,7 @@ public:
static void CopyDescriptorSet(const VkCopyDescriptorSet& descriptorCopies);
static void WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptorUpdateTemplateEntry const &entry, char const *src);
static void WriteTextureLevelInfo(sw::Texture *texture, int level, int width, int height, int depth, int pitchP, int sliceP);
void initialize(VkDescriptorSet descriptorSet);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment