Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bc54342

Browse files
null77Commit Bot
authored andcommitted
Vulkan: Make RenderTargetVk use ImageHelper.
Bug: angleproject:2318 Change-Id: I9bc4bb7f5bcd3029a31c8570809f253cf5e4b12a Reviewed-on: https://chromium-review.googlesource.com/980773 Commit-Queue: Jamie Madill <[email protected]> Reviewed-by: Luc Ferron <[email protected]> Reviewed-by: Frank Henigman <[email protected]>
1 parent 62059a5 commit bc54342

File tree

12 files changed

+139
-196
lines changed

12 files changed

+139
-196
lines changed

src/libANGLE/renderer/vulkan/CommandGraph.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,14 @@ void CommandGraphNode::storeRenderPassInfo(const Framebuffer &framebuffer,
140140

141141
void CommandGraphNode::appendColorRenderTarget(Serial serial, RenderTargetVk *colorRenderTarget)
142142
{
143-
// TODO(jmadill): Layout transition?
144-
mRenderPassDesc.packColorAttachment(*colorRenderTarget->format, colorRenderTarget->samples);
143+
mRenderPassDesc.packColorAttachment(*colorRenderTarget->image);
145144
colorRenderTarget->resource->onWriteResource(this, serial);
146145
}
147146

148147
void CommandGraphNode::appendDepthStencilRenderTarget(Serial serial,
149148
RenderTargetVk *depthStencilRenderTarget)
150149
{
151-
// TODO(jmadill): Layout transition?
152-
mRenderPassDesc.packDepthStencilAttachment(*depthStencilRenderTarget->format,
153-
depthStencilRenderTarget->samples);
150+
mRenderPassDesc.packDepthStencilAttachment(*depthStencilRenderTarget->image);
154151
depthStencilRenderTarget->resource->onWriteResource(this, serial);
155152
}
156153

src/libANGLE/renderer/vulkan/FramebufferVk.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ namespace
3434
const gl::InternalFormat &GetReadAttachmentInfo(const gl::Context *context,
3535
RenderTargetVk *renderTarget)
3636
{
37-
GLenum implFormat = renderTarget->format->textureFormat().fboImplementationInternalFormat;
37+
GLenum implFormat =
38+
renderTarget->image->getFormat().textureFormat().fboImplementationInternalFormat;
3839
return gl::GetSizedInternalFormatInfo(implFormat);
3940
}
4041
} // anonymous namespace
@@ -149,11 +150,11 @@ gl::Error FramebufferVk::clear(const gl::Context *context, GLbitfield mask)
149150

150151
RenderTargetVk *renderTarget = mRenderTargetCache.getDepthStencil();
151152
renderTarget->resource->onWriteResource(writingNode, currentSerial);
152-
renderTarget->image->changeLayoutWithStages(
153+
renderTarget->image->getImage().changeLayoutWithStages(
153154
aspectFlags, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
154155
VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer);
155156

156-
commandBuffer->clearSingleDepthStencilImage(*renderTarget->image, aspectFlags,
157+
commandBuffer->clearSingleDepthStencilImage(renderTarget->image->getImage(), aspectFlags,
157158
clearDepthStencilValue);
158159

159160
if ((mask & GL_COLOR_BUFFER_BIT) == 0)
@@ -188,11 +189,11 @@ gl::Error FramebufferVk::clear(const gl::Context *context, GLbitfield mask)
188189
ASSERT(colorRenderTarget);
189190
colorRenderTarget->resource->onWriteResource(writingNode, currentSerial);
190191

191-
colorRenderTarget->image->changeLayoutWithStages(
192+
colorRenderTarget->image->getImage().changeLayoutWithStages(
192193
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
193194
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer);
194195

195-
commandBuffer->clearSingleColorImage(*colorRenderTarget->image,
196+
commandBuffer->clearSingleColorImage(colorRenderTarget->image->getImage(),
196197
contextVk->getClearColorValue().color);
197198
}
198199

@@ -260,10 +261,10 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
260261
RenderTargetVk *renderTarget = mRenderTargetCache.getColorRead(mState);
261262
ASSERT(renderTarget);
262263

263-
vk::Image *readImage = renderTarget->image;
264+
vk::Image &readImage = renderTarget->image->getImage();
264265
vk::ImageHelper stagingImage;
265266
ANGLE_TRY(stagingImage.init2DStaging(
266-
device, renderer->getMemoryProperties(), *renderTarget->format,
267+
device, renderer->getMemoryProperties(), renderTarget->image->getFormat(),
267268
gl::Extents(area.width, area.height, 1), vk::StagingUsage::Read));
268269

269270
vk::CommandBuffer *commandBuffer = nullptr;
@@ -272,7 +273,7 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
272273
stagingImage.getImage().changeLayoutTop(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL,
273274
commandBuffer);
274275

275-
readImage->changeLayoutWithStages(
276+
readImage.changeLayoutWithStages(
276277
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
277278
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer);
278279

@@ -295,7 +296,7 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
295296
region.extent.height = area.height;
296297
region.extent.depth = 1;
297298

298-
commandBuffer->copyImage(*readImage, stagingImage.getImage(), 1, &region);
299+
commandBuffer->copyImage(readImage, stagingImage.getImage(), 1, &region);
299300

300301
// Triggers a full finish.
301302
// TODO(jmadill): Don't block on asynchronous readback.
@@ -306,7 +307,7 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
306307
ANGLE_TRY(stagingImage.getDeviceMemory().map(device, 0, stagingImage.getAllocatedMemorySize(),
307308
0, &mapPointer));
308309

309-
const angle::Format &angleFormat = renderTarget->format->textureFormat();
310+
const angle::Format &angleFormat = renderTarget->image->getFormat().textureFormat();
310311

311312
// TODO(jmadill): Use pixel bytes from the ANGLE format directly.
312313
const auto &glFormat = gl::GetSizedInternalFormatInfo(angleFormat.glInternalFormat);
@@ -384,14 +385,13 @@ const vk::RenderPassDesc &FramebufferVk::getRenderPassDesc(const gl::Context *co
384385
{
385386
RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndex];
386387
ASSERT(colorRenderTarget);
387-
desc.packColorAttachment(*colorRenderTarget->format, colorRenderTarget->samples);
388+
desc.packColorAttachment(*colorRenderTarget->image);
388389
}
389390

390391
RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil();
391392
if (depthStencilRenderTarget)
392393
{
393-
desc.packDepthStencilAttachment(*depthStencilRenderTarget->format,
394-
depthStencilRenderTarget->samples);
394+
desc.packDepthStencilAttachment(*depthStencilRenderTarget->image);
395395
}
396396

397397
mRenderPassDesc = desc;
@@ -431,17 +431,19 @@ gl::ErrorOrResult<vk::Framebuffer *> FramebufferVk::getFramebuffer(const gl::Con
431431
ASSERT(colorRenderTarget);
432432
attachments.push_back(colorRenderTarget->imageView->getHandle());
433433

434-
ASSERT(attachmentsSize.empty() || attachmentsSize == colorRenderTarget->extents);
435-
attachmentsSize = colorRenderTarget->extents;
434+
ASSERT(attachmentsSize.empty() ||
435+
attachmentsSize == colorRenderTarget->image->getExtents());
436+
attachmentsSize = colorRenderTarget->image->getExtents();
436437
}
437438

438439
RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil();
439440
if (depthStencilRenderTarget)
440441
{
441442
attachments.push_back(depthStencilRenderTarget->imageView->getHandle());
442443

443-
ASSERT(attachmentsSize.empty() || attachmentsSize == depthStencilRenderTarget->extents);
444-
attachmentsSize = depthStencilRenderTarget->extents;
444+
ASSERT(attachmentsSize.empty() ||
445+
attachmentsSize == depthStencilRenderTarget->image->getExtents());
446+
attachmentsSize = depthStencilRenderTarget->image->getExtents();
445447
}
446448

447449
ASSERT(!attachments.empty());
@@ -547,7 +549,7 @@ gl::Error FramebufferVk::getCommandGraphNodeForDraw(const gl::Context *context,
547549
ASSERT(colorRenderTarget);
548550

549551
// TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361
550-
colorRenderTarget->image->changeLayoutWithStages(
552+
colorRenderTarget->image->getImage().changeLayoutWithStages(
551553
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
552554
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
553555
commandBuffer);
@@ -559,11 +561,11 @@ gl::Error FramebufferVk::getCommandGraphNodeForDraw(const gl::Context *context,
559561
if (depthStencilRenderTarget)
560562
{
561563
// TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361
562-
const angle::Format &format = depthStencilRenderTarget->format->textureFormat();
564+
const angle::Format &format = depthStencilRenderTarget->image->getFormat().textureFormat();
563565
VkImageAspectFlags aspectFlags = (format.depthBits > 0 ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) |
564566
(format.stencilBits > 0 ? VK_IMAGE_ASPECT_STENCIL_BIT : 0);
565567

566-
depthStencilRenderTarget->image->changeLayoutWithStages(
568+
depthStencilRenderTarget->image->getImage().changeLayoutWithStages(
567569
aspectFlags, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
568570
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
569571
commandBuffer);

src/libANGLE/renderer/vulkan/RenderTargetVk.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,7 @@
1111

1212
namespace rx
1313
{
14-
15-
RenderTargetVk::RenderTargetVk()
14+
RenderTargetVk::RenderTargetVk() : image(nullptr), imageView(nullptr), resource(nullptr)
1615
{
17-
reset();
1816
}
19-
20-
void RenderTargetVk::reset()
21-
{
22-
format = nullptr;
23-
image = nullptr;
24-
imageView = nullptr;
25-
extents = gl::Extents();
26-
samples = VK_SAMPLE_COUNT_1_BIT;
27-
resource = nullptr;
28-
}
29-
3017
} // namespace rx

src/libANGLE/renderer/vulkan/RenderTargetVk.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ class ResourceVk;
2020

2121
namespace vk
2222
{
23-
struct Format;
24-
class Image;
23+
class ImageHelper;
2524
class ImageView;
26-
}
25+
} // namespace vk
2726

2827
// This is a very light-weight class that does not own to the resources it points to.
2928
// It's meant only to copy across some information from a FramebufferAttachment to the
@@ -33,13 +32,8 @@ class RenderTargetVk final : public FramebufferAttachmentRenderTarget
3332
public:
3433
RenderTargetVk();
3534

36-
void reset();
37-
38-
const vk::Format *format;
39-
vk::Image *image;
35+
vk::ImageHelper *image;
4036
vk::ImageView *imageView;
41-
gl::Extents extents;
42-
VkSampleCountFlagBits samples;
4337
ResourceVk *resource;
4438
};
4539

src/libANGLE/renderer/vulkan/RenderbufferVk.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ constexpr VkClearColorValue kBlackClearColorValue = {{0}};
2525

2626
RenderbufferVk::RenderbufferVk(const gl::RenderbufferState &state) : RenderbufferImpl(state)
2727
{
28-
mRenderTarget.image = &mImage.getImage();
28+
mRenderTarget.image = &mImage;
2929
mRenderTarget.imageView = &mImageView;
3030
mRenderTarget.resource = this;
3131
}
@@ -70,13 +70,6 @@ gl::Error RenderbufferVk::setStorage(const gl::Context *context,
7070
}
7171
}
7272

73-
// Init RenderTarget.
74-
mRenderTarget.extents.width = static_cast<int>(width);
75-
mRenderTarget.extents.height = static_cast<int>(height);
76-
mRenderTarget.extents.depth = 1;
77-
mRenderTarget.format = &vkFormat;
78-
mRenderTarget.samples = VK_SAMPLE_COUNT_1_BIT; // TODO(jmadill): Multisample bits.
79-
8073
if (!mImage.valid() && (width != 0 || height != 0))
8174
{
8275
const angle::Format &textureFormat = vkFormat.textureFormat();
@@ -87,7 +80,8 @@ gl::Error RenderbufferVk::setStorage(const gl::Context *context,
8780
(textureFormat.redBits > 0 ? VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT : 0) |
8881
(isDepthOrStencilFormat ? VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT : 0);
8982

90-
ANGLE_TRY(mImage.init2D(device, mRenderTarget.extents, vkFormat, 1, usage));
83+
gl::Extents extents(static_cast<int>(width), static_cast<int>(height), 1);
84+
ANGLE_TRY(mImage.init2D(device, extents, vkFormat, 1, usage));
9185

9286
VkMemoryPropertyFlags flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
9387
ANGLE_TRY(mImage.initMemory(device, renderer->getMemoryProperties(), flags));

0 commit comments

Comments
 (0)