VulkanBenchmarks: refactor into Image class

Bug: b/176981107 Change-Id: Ifab91e61ceb74c5b6caf62b8f9f1abbd8fef9e01 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/45848Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Commit-Queue: Nicolas Capens <nicolascapens@google.com>
parent eeb81843
...@@ -394,8 +394,63 @@ private: ...@@ -394,8 +394,63 @@ private:
std::vector<vk::ImageView> imageViews; std::vector<vk::ImageView> imageViews;
}; };
struct Image class Image
{ {
public:
Image(vk::Device device, uint32_t width, uint32_t height, vk::Format format, vk::SampleCountFlagBits sampleCount = vk::SampleCountFlagBits::e1)
: device(device)
{
vk::ImageCreateInfo imageInfo;
imageInfo.imageType = vk::ImageType::e2D;
imageInfo.format = format;
imageInfo.tiling = vk::ImageTiling::eOptimal;
imageInfo.initialLayout = vk::ImageLayout::eGeneral;
imageInfo.usage = vk::ImageUsageFlagBits::eColorAttachment;
imageInfo.samples = sampleCount;
imageInfo.extent = vk::Extent3D(width, height, 1);
imageInfo.mipLevels = 1;
imageInfo.arrayLayers = 1;
image = device.createImage(imageInfo);
vk::MemoryRequirements memoryRequirements = device.getImageMemoryRequirements(image);
vk::MemoryAllocateInfo allocateInfo;
allocateInfo.allocationSize = memoryRequirements.size;
allocateInfo.memoryTypeIndex = 0; //getMemoryTypeIndex(memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eDeviceLocal);
imageMemory = device.allocateMemory(allocateInfo);
device.bindImageMemory(image, imageMemory, 0);
vk::ImageViewCreateInfo imageViewInfo;
imageViewInfo.image = image;
imageViewInfo.viewType = vk::ImageViewType::e2D;
imageViewInfo.format = format;
imageViewInfo.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor;
imageViewInfo.subresourceRange.baseMipLevel = 0;
imageViewInfo.subresourceRange.levelCount = 1;
imageViewInfo.subresourceRange.baseArrayLayer = 0;
imageViewInfo.subresourceRange.layerCount = 1;
imageView = device.createImageView(imageViewInfo);
}
~Image()
{
device.destroyImage(image);
device.destroyImageView(imageView);
device.freeMemory(imageMemory);
}
vk::ImageView getImageView()
{
return imageView;
}
private:
const vk::Device device;
vk::Image image; vk::Image image;
vk::DeviceMemory imageMemory; vk::DeviceMemory imageMemory;
vk::ImageView imageView; vk::ImageView imageView;
...@@ -411,44 +466,10 @@ public: ...@@ -411,44 +466,10 @@ public:
if(multisample) if(multisample)
{ {
// Create multisample images multisampleImage = new Image(device, width, height, colorFormat, vk::SampleCountFlagBits::e4);
vk::ImageCreateInfo imageInfo;
imageInfo.imageType = vk::ImageType::e2D;
imageInfo.format = colorFormat;
imageInfo.tiling = vk::ImageTiling::eOptimal;
imageInfo.initialLayout = vk::ImageLayout::eGeneral;
imageInfo.usage = vk::ImageUsageFlagBits::eColorAttachment;
imageInfo.samples = vk::SampleCountFlagBits::e4;
imageInfo.extent = vk::Extent3D(width, height, 1);
imageInfo.mipLevels = 1;
imageInfo.arrayLayers = 1;
multisampleImage.image = device.createImage(imageInfo);
vk::MemoryRequirements memoryRequirements = device.getImageMemoryRequirements(multisampleImage.image);
vk::MemoryAllocateInfo allocateInfo;
allocateInfo.allocationSize = memoryRequirements.size;
allocateInfo.memoryTypeIndex = 0; //getMemoryTypeIndex(memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eDeviceLocal);
multisampleImage.imageMemory = device.allocateMemory(allocateInfo);
device.bindImageMemory(multisampleImage.image, multisampleImage.imageMemory, 0);
vk::ImageViewCreateInfo colorAttachmentView;
colorAttachmentView.image = multisampleImage.image;
colorAttachmentView.viewType = vk::ImageViewType::e2D;
colorAttachmentView.format = colorFormat;
colorAttachmentView.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor;
colorAttachmentView.subresourceRange.baseMipLevel = 0;
colorAttachmentView.subresourceRange.levelCount = 1;
colorAttachmentView.subresourceRange.baseArrayLayer = 0;
colorAttachmentView.subresourceRange.layerCount = 1;
multisampleImage.imageView = device.createImageView(colorAttachmentView);
// We'll be rendering to attachment location 0 // We'll be rendering to attachment location 0
attachments[0] = multisampleImage.imageView; attachments[0] = multisampleImage->getImageView();
attachments[1] = attachment; // Resolve attachment attachments[1] = attachment; // Resolve attachment
} }
else else
...@@ -470,11 +491,9 @@ public: ...@@ -470,11 +491,9 @@ public:
~Framebuffer() ~Framebuffer()
{ {
device.destroyFramebuffer(framebuffer, nullptr); device.destroyFramebuffer(framebuffer);
device.destroyImage(multisampleImage.image, nullptr); delete multisampleImage;
device.destroyImageView(multisampleImage.imageView, nullptr);
device.freeMemory(multisampleImage.imageMemory, nullptr);
} }
vk::Framebuffer getFramebuffer() vk::Framebuffer getFramebuffer()
...@@ -483,11 +502,11 @@ public: ...@@ -483,11 +502,11 @@ public:
} }
private: private:
vk::Device device; const vk::Device device;
vk::Framebuffer framebuffer; vk::Framebuffer framebuffer;
Image multisampleImage; Image *multisampleImage = nullptr;
}; };
static std::vector<uint32_t> compileGLSLtoSPIRV(const char *glslSource, EShLanguage glslLanguage) static std::vector<uint32_t> compileGLSLtoSPIRV(const char *glslSource, EShLanguage glslLanguage)
......
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