Commit deb43a31 by Jamie Madill Committed by Commit Bot

Vulkan: Store VkExtents3D in ImageHelper.

This makes the distinction between a gl::Extents (includes a depth value for 2D array texture layer count) and a Vulkan extents (2D array textures have a "1" for depth) clearer. Preparation refactor patch. Bug: angleproject:3189 Change-Id: I9a13379c421e7f3c7856ac15b7a73013258ab9fe Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1709754Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent da2b649c
...@@ -20,14 +20,13 @@ GLuint CreateSimpleTexture2D() ...@@ -20,14 +20,13 @@ GLuint CreateSimpleTexture2D()
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
// Load the texture: 2x2 Image, 3 bytes per pixel (R, G, B) // Load the texture: 2x2 Image, 3 bytes per pixel (R, G, B)
const size_t width = 2; const size_t width = 2;
const size_t height = 2; const size_t height = 2;
GLubyte pixels[width * height * 3] = GLubyte pixels[width * height * 3] = {
{ 255, 0, 0, // Red
255, 0, 0, // Red 0, 255, 0, // Green
0, 255, 0, // Green 0, 0, 255, // Blue
0, 0, 255, // Blue 255, 255, 0, // Yellow
255, 255, 0, // Yellow
}; };
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
...@@ -48,21 +47,18 @@ GLuint CreateSimpleTextureCubemap() ...@@ -48,21 +47,18 @@ GLuint CreateSimpleTextureCubemap()
glBindTexture(GL_TEXTURE_CUBE_MAP, texture); glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
// Load the texture faces // Load the texture faces
GLubyte pixels[6][3] = GLubyte pixels[6][3] = {// Face 0 - Red
{ {255, 0, 0},
// Face 0 - Red // Face 1 - Green,
{ 255, 0, 0 }, {0, 255, 0},
// Face 1 - Green, // Face 3 - Blue
{ 0, 255, 0 }, {0, 0, 255},
// Face 3 - Blue // Face 4 - Yellow
{ 0, 0, 255 }, {255, 255, 0},
// Face 4 - Yellow // Face 5 - Purple
{ 255, 255, 0 }, {255, 0, 255},
// Face 5 - Purple // Face 6 - White
{ 255, 0, 255 }, {255, 255, 255}};
// Face 6 - White
{ 255, 255, 255 }
};
for (size_t i = 0; i < 6; i++) for (size_t i = 0; i < 6; i++)
{ {
...@@ -80,7 +76,7 @@ GLuint CreateSimpleTextureCubemap() ...@@ -80,7 +76,7 @@ GLuint CreateSimpleTextureCubemap()
GLuint CreateMipMappedTexture2D() GLuint CreateMipMappedTexture2D()
{ {
// Texture object handle // Texture object handle
const size_t width = 256; const size_t width = 256;
const size_t height = 256; const size_t height = 256;
std::array<GLubyte, width * height * 3> pixels; std::array<GLubyte, width * height * 3> pixels;
...@@ -103,7 +99,7 @@ GLuint CreateMipMappedTexture2D() ...@@ -103,7 +99,7 @@ GLuint CreateMipMappedTexture2D()
rColor = 255 * (1 - ((y / checkerSize) % 2)); rColor = 255 * (1 - ((y / checkerSize) % 2));
} }
pixels[(y * height + x) * 3] = rColor; pixels[(y * height + x) * 3] = rColor;
pixels[(y * height + x) * 3 + 1] = 0; pixels[(y * height + x) * 3 + 1] = 0;
pixels[(y * height + x) * 3 + 2] = bColor; pixels[(y * height + x) * 3 + 2] = bColor;
} }
...@@ -117,7 +113,8 @@ GLuint CreateMipMappedTexture2D() ...@@ -117,7 +113,8 @@ GLuint CreateMipMappedTexture2D()
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
// Load mipmap level 0 // Load mipmap level 0
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels.data()); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE,
pixels.data());
// Generate mipmaps // Generate mipmaps
glGenerateMipmap(GL_TEXTURE_2D); glGenerateMipmap(GL_TEXTURE_2D);
......
...@@ -885,7 +885,7 @@ angle::Result WindowSurfaceVk::present(ContextVk *contextVk, ...@@ -885,7 +885,7 @@ angle::Result WindowSurfaceVk::present(ContextVk *contextVk,
resolveRegion.srcOffset = {}; resolveRegion.srcOffset = {};
resolveRegion.dstSubresource = resolveRegion.srcSubresource; resolveRegion.dstSubresource = resolveRegion.srcSubresource;
resolveRegion.dstOffset = {}; resolveRegion.dstOffset = {};
gl_vk::GetExtent(image.image.getExtents(), &resolveRegion.extent); resolveRegion.extent = image.image.getExtents();
ANGLE_TRY(image.image.recordCommands(contextVk, &swapCommands)); ANGLE_TRY(image.image.recordCommands(contextVk, &swapCommands));
mColorImageMS.resolve(&image.image, resolveRegion, swapCommands); mColorImageMS.resolve(&image.image, resolveRegion, swapCommands);
......
...@@ -973,8 +973,8 @@ angle::Result TextureVk::generateMipmapsWithCPU(const gl::Context *context) ...@@ -973,8 +973,8 @@ angle::Result TextureVk::generateMipmapsWithCPU(const gl::Context *context)
{ {
ContextVk *contextVk = vk::GetImpl(context); ContextVk *contextVk = vk::GetImpl(context);
const gl::Extents baseLevelExtents = mImage->getExtents(); const VkExtent3D baseLevelExtents = mImage->getExtents();
uint32_t imageLayerCount = mImage->getLayerCount(); uint32_t imageLayerCount = mImage->getLayerCount();
uint8_t *imageData = nullptr; uint8_t *imageData = nullptr;
gl::Rectangle imageArea(0, 0, baseLevelExtents.width, baseLevelExtents.height); gl::Rectangle imageArea(0, 0, baseLevelExtents.width, baseLevelExtents.height);
......
...@@ -1523,7 +1523,7 @@ angle::Result ImageHelper::initExternal(Context *context, ...@@ -1523,7 +1523,7 @@ angle::Result ImageHelper::initExternal(Context *context,
ASSERT(textureType != gl::TextureType::Rectangle || layerCount == 1); ASSERT(textureType != gl::TextureType::Rectangle || layerCount == 1);
ASSERT(textureType != gl::TextureType::CubeMap || layerCount == gl::kCubeFaceCount); ASSERT(textureType != gl::TextureType::CubeMap || layerCount == gl::kCubeFaceCount);
mExtents = extents; gl_vk::GetExtent(extents, &mExtents);
mFormat = &format; mFormat = &format;
mSamples = samples; mSamples = samples;
mLayerCount = layerCount; mLayerCount = layerCount;
...@@ -1535,9 +1535,7 @@ angle::Result ImageHelper::initExternal(Context *context, ...@@ -1535,9 +1535,7 @@ angle::Result ImageHelper::initExternal(Context *context,
imageInfo.flags = GetImageCreateFlags(textureType); imageInfo.flags = GetImageCreateFlags(textureType);
imageInfo.imageType = gl_vk::GetImageType(textureType); imageInfo.imageType = gl_vk::GetImageType(textureType);
imageInfo.format = format.vkImageFormat; imageInfo.format = format.vkImageFormat;
imageInfo.extent.width = static_cast<uint32_t>(extents.width); imageInfo.extent = mExtents;
imageInfo.extent.height = static_cast<uint32_t>(extents.height);
imageInfo.extent.depth = static_cast<uint32_t>(extents.depth);
imageInfo.mipLevels = mipLevels; imageInfo.mipLevels = mipLevels;
imageInfo.arrayLayers = mLayerCount; imageInfo.arrayLayers = mLayerCount;
imageInfo.samples = gl_vk::GetSamples(samples); imageInfo.samples = gl_vk::GetSamples(samples);
...@@ -1688,7 +1686,7 @@ void ImageHelper::init2DWeakReference(VkImage handle, ...@@ -1688,7 +1686,7 @@ void ImageHelper::init2DWeakReference(VkImage handle,
{ {
ASSERT(!valid()); ASSERT(!valid());
mExtents = extents; gl_vk::GetExtent(extents, &mExtents);
mFormat = &format; mFormat = &format;
mSamples = samples; mSamples = samples;
mCurrentLayout = ImageLayout::Undefined; mCurrentLayout = ImageLayout::Undefined;
...@@ -1707,7 +1705,7 @@ angle::Result ImageHelper::init2DStaging(Context *context, ...@@ -1707,7 +1705,7 @@ angle::Result ImageHelper::init2DStaging(Context *context,
{ {
ASSERT(!valid()); ASSERT(!valid());
mExtents = extents; gl_vk::GetExtent(extents, &mExtents);
mFormat = &format; mFormat = &format;
mSamples = 1; mSamples = 1;
mLayerCount = layerCount; mLayerCount = layerCount;
...@@ -1760,8 +1758,8 @@ VkImageLayout ImageHelper::getCurrentLayout() const ...@@ -1760,8 +1758,8 @@ VkImageLayout ImageHelper::getCurrentLayout() const
gl::Extents ImageHelper::getLevelExtents2D(uint32_t level) const gl::Extents ImageHelper::getLevelExtents2D(uint32_t level) const
{ {
int width = std::max(mExtents.width >> level, 1); uint32_t width = std::max(mExtents.width >> level, 1u);
int height = std::max(mExtents.height >> level, 1); uint32_t height = std::max(mExtents.height >> level, 1u);
return gl::Extents(width, height, 1); return gl::Extents(width, height, 1);
} }
...@@ -1922,8 +1920,8 @@ gl::Extents ImageHelper::getSize(const gl::ImageIndex &index) const ...@@ -1922,8 +1920,8 @@ gl::Extents ImageHelper::getSize(const gl::ImageIndex &index) const
GLint mipLevel = index.getLevelIndex(); GLint mipLevel = index.getLevelIndex();
// Level 0 should be the size of the extents, after that every time you increase a level // Level 0 should be the size of the extents, after that every time you increase a level
// you shrink the extents by half. // you shrink the extents by half.
return gl::Extents(std::max(1, mExtents.width >> mipLevel), return gl::Extents(std::max(1u, mExtents.width >> mipLevel),
std::max(1, mExtents.height >> mipLevel), mExtents.depth); std::max(1u, mExtents.height >> mipLevel), mExtents.depth);
} }
// static // static
......
...@@ -719,7 +719,7 @@ class ImageHelper final : public CommandGraphResource ...@@ -719,7 +719,7 @@ class ImageHelper final : public CommandGraphResource
const Image &getImage() const { return mImage; } const Image &getImage() const { return mImage; }
const DeviceMemory &getDeviceMemory() const { return mDeviceMemory; } const DeviceMemory &getDeviceMemory() const { return mDeviceMemory; }
const gl::Extents &getExtents() const { return mExtents; } const VkExtent3D &getExtents() const { return mExtents; }
uint32_t getLayerCount() const { return mLayerCount; } uint32_t getLayerCount() const { return mLayerCount; }
uint32_t getLevelCount() const { return mLevelCount; } uint32_t getLevelCount() const { return mLevelCount; }
const Format &getFormat() const { return *mFormat; } const Format &getFormat() const { return *mFormat; }
...@@ -927,7 +927,7 @@ class ImageHelper final : public CommandGraphResource ...@@ -927,7 +927,7 @@ class ImageHelper final : public CommandGraphResource
DeviceMemory mDeviceMemory; DeviceMemory mDeviceMemory;
// Image properties. // Image properties.
gl::Extents mExtents; VkExtent3D mExtents;
const Format *mFormat; const Format *mFormat;
GLint mSamples; GLint mSamples;
......
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