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 ...@@ -31,13 +31,13 @@ namespace sw
{ {
const void *buffer[6]; const void *buffer[6];
short uHalf[4]; short4 uHalf;
short vHalf[4]; short4 vHalf;
short wHalf[4]; short4 wHalf;
int4 width; int4 width;
int4 height; int4 height;
int4 depth; int4 depth;
short onePitchP[4]; short4 onePitchP;
int4 pitchP; int4 pitchP;
int4 sliceP; int4 sliceP;
}; };
......
...@@ -333,14 +333,17 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor ...@@ -333,14 +333,17 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor
} }
} }
else if (entry.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER || else if (entry.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER ||
entry.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) entry.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE)
{ {
SampledImageDescriptor *imageSampler = reinterpret_cast<SampledImageDescriptor*>(memToWrite); SampledImageDescriptor *imageSampler = reinterpret_cast<SampledImageDescriptor*>(memToWrite);
for(uint32_t i = 0; i < entry.descriptorCount; i++) for(uint32_t i = 0; i < entry.descriptorCount; i++)
{ {
auto update = reinterpret_cast<VkDescriptorImageInfo const *>(src + entry.offset + entry.stride * i); auto update = reinterpret_cast<VkDescriptorImageInfo const *>(src + entry.offset + entry.stride * i);
vk::ImageView *imageView = vk::Cast(update->imageView); vk::ImageView *imageView = vk::Cast(update->imageView);
Format format = imageView->getFormat(ImageView::SAMPLING);
sw::Texture *texture = &imageSampler[i].texture; sw::Texture *texture = &imageSampler[i].texture;
// "All consecutive bindings updated via a single VkWriteDescriptorSet structure, except those with a // "All consecutive bindings updated via a single VkWriteDescriptorSet structure, except those with a
...@@ -357,7 +360,7 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor ...@@ -357,7 +360,7 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor
imageSampler[i].sampleCount = imageView->getSampleCount(); imageSampler[i].sampleCount = imageView->getSampleCount();
imageSampler[i].type = imageView->getType(); imageSampler[i].type = imageView->getType();
imageSampler[i].swizzle = imageView->getComponentMapping(); imageSampler[i].swizzle = imageView->getComponentMapping();
imageSampler[i].format = imageView->getFormat(ImageView::SAMPLING); imageSampler[i].format = format;
auto &subresourceRange = imageView->getSubresourceRange(); auto &subresourceRange = imageView->getSubresourceRange();
...@@ -387,113 +390,15 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor ...@@ -387,113 +390,15 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor
} }
VkExtent3D extent = imageView->getMipLevelExtent(level); 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 width = extent.width;
int height = extent.height; 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 depth = layers > 1 ? layers : extent.depth;
int pitchP = imageView->rowPitchBytes(aspect, level, ImageView::SAMPLING) / format.bytes(); 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(); 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);
{
texture->widthWidthHeightHeight[0] = width;
texture->widthWidthHeightHeight[1] = width;
texture->widthWidthHeightHeight[2] = height;
texture->widthWidthHeightHeight[3] = height;
texture->width[0] = width;
texture->width[1] = width;
texture->width[2] = width;
texture->width[3] = width;
texture->height[0] = height;
texture->height[1] = height;
texture->height[2] = height;
texture->height[3] = height;
texture->depth[0] = depth;
texture->depth[1] = depth;
texture->depth[2] = depth;
texture->depth[3] = depth;
}
short halfTexelU = 0x8000 / width;
short halfTexelV = 0x8000 / height;
short halfTexelW = 0x8000 / depth;
mipmap.uHalf[0] = halfTexelU;
mipmap.uHalf[1] = halfTexelU;
mipmap.uHalf[2] = halfTexelU;
mipmap.uHalf[3] = halfTexelU;
mipmap.vHalf[0] = halfTexelV;
mipmap.vHalf[1] = halfTexelV;
mipmap.vHalf[2] = halfTexelV;
mipmap.vHalf[3] = halfTexelV;
mipmap.wHalf[0] = halfTexelW;
mipmap.wHalf[1] = halfTexelW;
mipmap.wHalf[2] = halfTexelW;
mipmap.wHalf[3] = halfTexelW;
mipmap.width[0] = width;
mipmap.width[1] = width;
mipmap.width[2] = width;
mipmap.width[3] = width;
mipmap.height[0] = height;
mipmap.height[1] = height;
mipmap.height[2] = height;
mipmap.height[3] = height;
mipmap.depth[0] = depth;
mipmap.depth[1] = depth;
mipmap.depth[2] = depth;
mipmap.depth[3] = depth;
mipmap.onePitchP[0] = 1;
mipmap.onePitchP[1] = pitchP;
mipmap.onePitchP[2] = 1;
mipmap.onePitchP[3] = pitchP;
mipmap.pitchP[0] = pitchP;
mipmap.pitchP[1] = pitchP;
mipmap.pitchP[2] = pitchP;
mipmap.pitchP[3] = pitchP;
mipmap.sliceP[0] = sliceP;
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;
}
} }
} }
} }
...@@ -561,6 +466,83 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor ...@@ -561,6 +466,83 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor
} }
} }
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;
texture->widthWidthHeightHeight[2] = height;
texture->widthWidthHeightHeight[3] = height;
texture->width[0] = width;
texture->width[1] = width;
texture->width[2] = width;
texture->width[3] = width;
texture->height[0] = height;
texture->height[1] = height;
texture->height[2] = height;
texture->height[3] = height;
texture->depth[0] = depth;
texture->depth[1] = depth;
texture->depth[2] = depth;
texture->depth[3] = depth;
}
sw::Mipmap &mipmap = texture->mipmap[level];
short halfTexelU = 0x8000 / width;
short halfTexelV = 0x8000 / height;
short halfTexelW = 0x8000 / depth;
mipmap.uHalf[0] = halfTexelU;
mipmap.uHalf[1] = halfTexelU;
mipmap.uHalf[2] = halfTexelU;
mipmap.uHalf[3] = halfTexelU;
mipmap.vHalf[0] = halfTexelV;
mipmap.vHalf[1] = halfTexelV;
mipmap.vHalf[2] = halfTexelV;
mipmap.vHalf[3] = halfTexelV;
mipmap.wHalf[0] = halfTexelW;
mipmap.wHalf[1] = halfTexelW;
mipmap.wHalf[2] = halfTexelW;
mipmap.wHalf[3] = halfTexelW;
mipmap.width[0] = width;
mipmap.width[1] = width;
mipmap.width[2] = width;
mipmap.width[3] = width;
mipmap.height[0] = height;
mipmap.height[1] = height;
mipmap.height[2] = height;
mipmap.height[3] = height;
mipmap.depth[0] = depth;
mipmap.depth[1] = depth;
mipmap.depth[2] = depth;
mipmap.depth[3] = depth;
mipmap.onePitchP[0] = 1;
mipmap.onePitchP[1] = pitchP;
mipmap.onePitchP[2] = 1;
mipmap.onePitchP[3] = pitchP;
mipmap.pitchP[0] = pitchP;
mipmap.pitchP[1] = pitchP;
mipmap.pitchP[2] = pitchP;
mipmap.pitchP[3] = pitchP;
mipmap.sliceP[0] = sliceP;
mipmap.sliceP[1] = sliceP;
mipmap.sliceP[2] = sliceP;
mipmap.sliceP[3] = sliceP;
}
void DescriptorSetLayout::WriteDescriptorSet(const VkWriteDescriptorSet& writeDescriptorSet) void DescriptorSetLayout::WriteDescriptorSet(const VkWriteDescriptorSet& writeDescriptorSet)
{ {
DescriptorSet* dstSet = vk::Cast(writeDescriptorSet.dstSet); DescriptorSet* dstSet = vk::Cast(writeDescriptorSet.dstSet);
......
...@@ -82,6 +82,7 @@ public: ...@@ -82,6 +82,7 @@ public:
static void CopyDescriptorSet(const VkCopyDescriptorSet& descriptorCopies); static void CopyDescriptorSet(const VkCopyDescriptorSet& descriptorCopies);
static void WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptorUpdateTemplateEntry const &entry, char const *src); 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); 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