Hash :
9fa248e1
Author :
Date :
2019-05-06T14:55:18
Vulkan: Implement EXT_draw_buffers In GLES, color attachments are referenced by their indices. These indices match between the API and GLSL. For example, if a shader has: layout(location=0) out color; layout(location=3) out roughness; Then GLES would bind and enable GL_COLOR_ATTACHMENT0 and GL_COLOR_ATTACHMENT3. In Vulkan, the framebuffer object and the corresponding renderpass define the color attachments, and they don't allow gaps in color attachments as GLES does. A render subpass creates the mapping between the color attachments as defined in the framebuffer and the attachments used by the shader (with possible gaps). This change packs the enabled GL color attachments for the sake of the framebuffer, and sets the subpass up in such a way that the shaders continue to use the same color output indices as GLES. In the example above, we have the attachment indices as follows: Status | GLES | GLSL | RenderPass | Subpass enabled 0 0 0 0 disabled 1 - VK_ATTACHMENT_UNUSED disabled 2 - VK_ATTACHMENT_UNUSED enabled 3 3 1 1 That is, the array of color attachments in the Vulkan framebuffer/renderpass is: [0] = GL color attachment 0 [1] = GL color attachment 3 And the array of color attachment references in the Vulkan render subpass is: [0] = 0 (index 0 of the renderpass attachment array) [1] = VK_ATTACHMENT_UNUSED [2] = VK_ATTACHMENT_UNUSED [3] = 1 (index 1 of the renderpass attachment array) Bug: angleproject:2394 Change-Id: Ib6cd2b60882643ea152986eee453270d09cd4aed Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1595442 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// UtilsVk.h:
// Defines the UtilsVk class, a helper for various internal draw/dispatch utilities such as
// buffer clear and copy, image clear and copy, texture mip map generation, etc.
//
// - Buffer clear: Implemented, but no current users
// - Buffer copy:
// * Used by VertexArrayVk::updateIndexTranslation() to convert a ubyte index array to ushort
// - Convert vertex attribute:
// * Used by VertexArrayVk::convertVertexBuffer() to convert vertex attributes from unsupported
// formats to their fallbacks.
// - Image clear: Used by FramebufferVk::clearWithDraw().
// - Image copy: Not yet implemented
// - Mipmap generation: Not yet implemented
//
#ifndef LIBANGLE_RENDERER_VULKAN_UTILSVK_H_
#define LIBANGLE_RENDERER_VULKAN_UTILSVK_H_
#include "libANGLE/renderer/vulkan/vk_cache_utils.h"
#include "libANGLE/renderer/vulkan/vk_helpers.h"
#include "libANGLE/renderer/vulkan/vk_internal_shaders_autogen.h"
namespace rx
{
class UtilsVk : angle::NonCopyable
{
public:
UtilsVk();
~UtilsVk();
void destroy(VkDevice device);
struct ClearParameters
{
VkClearColorValue clearValue;
size_t offset;
size_t size;
};
struct CopyParameters
{
size_t destOffset;
size_t srcOffset;
size_t size;
};
struct ConvertVertexParameters
{
size_t vertexCount;
const angle::Format *srcFormat;
const angle::Format *destFormat;
size_t srcStride;
size_t srcOffset;
size_t destOffset;
};
struct ClearFramebufferParameters
{
// Satisfy chromium-style with a constructor that does what = {} was already doing in a
// safer way.
ClearFramebufferParameters();
const vk::RenderPassDesc *renderPassDesc;
GLint renderAreaHeight;
gl::Rectangle clearArea;
// Note that depth clear is never needed to be done with a draw call.
bool clearColor;
bool clearStencil;
uint8_t stencilMask;
VkColorComponentFlags colorMaskFlags;
uint32_t colorAttachmentIndexGL;
const angle::Format *colorFormat;
VkClearColorValue colorClearValue;
uint8_t stencilClearValue;
};
struct CopyImageParameters
{
int srcOffset[2];
int srcExtents[2];
int destOffset[2];
int srcMip;
int srcLayer;
int srcHeight;
bool srcPremultiplyAlpha;
bool srcUnmultiplyAlpha;
bool srcFlipY;
bool destFlipY;
};
angle::Result clearBuffer(vk::Context *context,
vk::BufferHelper *dest,
const ClearParameters ¶ms);
angle::Result copyBuffer(vk::Context *context,
vk::BufferHelper *dest,
vk::BufferHelper *src,
const CopyParameters ¶ms);
angle::Result convertVertexBuffer(vk::Context *context,
vk::BufferHelper *dest,
vk::BufferHelper *src,
const ConvertVertexParameters ¶ms);
angle::Result clearFramebuffer(ContextVk *contextVk,
FramebufferVk *framebuffer,
const ClearFramebufferParameters ¶ms);
angle::Result copyImage(ContextVk *contextVk,
vk::ImageHelper *dest,
const vk::ImageView *destView,
vk::ImageHelper *src,
const vk::ImageView *srcView,
const CopyImageParameters ¶ms);
private:
struct BufferUtilsShaderParams
{
// Structure matching PushConstants in BufferUtils.comp
uint32_t destOffset = 0;
uint32_t size = 0;
uint32_t srcOffset = 0;
uint32_t padding = 0;
VkClearColorValue clearValue = {};
};
struct ConvertVertexShaderParams
{
ConvertVertexShaderParams();
// Structure matching PushConstants in ConvertVertex.comp
uint32_t outputCount = 0;
uint32_t componentCount = 0;
uint32_t srcOffset = 0;
uint32_t destOffset = 0;
uint32_t Ns = 0;
uint32_t Bs = 0;
uint32_t Ss = 0;
uint32_t Es = 0;
uint32_t Nd = 0;
uint32_t Bd = 0;
uint32_t Sd = 0;
uint32_t Ed = 0;
};
struct ImageClearShaderParams
{
// Structure matching PushConstants in ImageClear.frag
VkClearColorValue clearValue = {};
};
struct ImageCopyShaderParams
{
ImageCopyShaderParams();
// Structure matching PushConstants in ImageCopy.frag
int32_t srcOffset[2] = {};
int32_t destOffset[2] = {};
int32_t srcMip = 0;
int32_t srcLayer = 0;
uint32_t flipY = 0;
uint32_t premultiplyAlpha = 0;
uint32_t unmultiplyAlpha = 0;
uint32_t destHasLuminance = 0;
uint32_t destIsAlpha = 0;
uint32_t destDefaultChannelsMask = 0;
};
// Functions implemented by the class:
enum class Function
{
// Functions implemented in graphics
ImageClear = 0,
ImageCopy = 1,
// Functions implemented in compute
ComputeStartIndex = 2, // Special value to separate draw and dispatch functions.
BufferClear = 2,
BufferCopy = 3,
ConvertVertexBuffer = 4,
InvalidEnum = 5,
EnumCount = 5,
};
// Common function that creates the pipeline for the specified function, binds it and prepares
// the draw/dispatch call. If function >= ComputeStartIndex, fsCsShader is expected to be a
// compute shader, vsShader and pipelineDesc should be nullptr, and this will set up a dispatch
// call. Otherwise fsCsShader is expected to be a fragment shader and this will set up a draw
// call.
angle::Result setupProgram(vk::Context *context,
Function function,
vk::RefCounted<vk::ShaderAndSerial> *fsCsShader,
vk::RefCounted<vk::ShaderAndSerial> *vsShader,
vk::ShaderProgramHelper *program,
const vk::GraphicsPipelineDesc *pipelineDesc,
const VkDescriptorSet descriptorSet,
const void *pushConstants,
size_t pushConstantsSize,
vk::CommandBuffer *commandBuffer);
// Initializes descriptor set layout, pipeline layout and descriptor pool corresponding to given
// function, if not already initialized. Uses setSizes to create the layout. For example, if
// this array has two entries {STORAGE_TEXEL_BUFFER, 1} and {UNIFORM_TEXEL_BUFFER, 3}, then the
// created set layout would be binding 0 for storage texel buffer and bindings 1 through 3 for
// uniform texel buffer. All resources are put in set 0.
angle::Result ensureResourcesInitialized(vk::Context *context,
Function function,
VkDescriptorPoolSize *setSizes,
size_t setSizesCount,
size_t pushConstantsSize);
// Initializers corresponding to functions, calling into ensureResourcesInitialized with the
// appropriate parameters.
angle::Result ensureBufferClearResourcesInitialized(vk::Context *context);
angle::Result ensureBufferCopyResourcesInitialized(vk::Context *context);
angle::Result ensureConvertVertexResourcesInitialized(vk::Context *context);
angle::Result ensureImageClearResourcesInitialized(vk::Context *context);
angle::Result ensureImageCopyResourcesInitialized(vk::Context *context);
angle::Result startRenderPass(ContextVk *contextVk,
vk::ImageHelper *image,
const vk::ImageView *imageView,
const vk::RenderPassDesc &renderPassDesc,
const gl::Rectangle &renderArea,
vk::CommandBuffer **commandBufferOut);
angle::PackedEnumMap<Function, vk::DescriptorSetLayoutPointerArray> mDescriptorSetLayouts;
angle::PackedEnumMap<Function, vk::BindingPointer<vk::PipelineLayout>> mPipelineLayouts;
angle::PackedEnumMap<Function, vk::DynamicDescriptorPool> mDescriptorPools;
vk::ShaderProgramHelper
mBufferUtilsPrograms[vk::InternalShader::BufferUtils_comp::kFlagsMask |
vk::InternalShader::BufferUtils_comp::kFunctionMask |
vk::InternalShader::BufferUtils_comp::kFormatMask];
vk::ShaderProgramHelper
mConvertVertexPrograms[vk::InternalShader::ConvertVertex_comp::kFlagsMask |
vk::InternalShader::ConvertVertex_comp::kConversionMask];
vk::ShaderProgramHelper mImageClearProgramVSOnly;
vk::ShaderProgramHelper
mImageClearProgram[vk::InternalShader::ImageClear_frag::kAttachmentIndexMask |
vk::InternalShader::ImageClear_frag::kFormatMask];
vk::ShaderProgramHelper mImageCopyPrograms[vk::InternalShader::ImageCopy_frag::kFlagsMask |
vk::InternalShader::ImageCopy_frag::kSrcFormatMask |
vk::InternalShader::ImageCopy_frag::kDestFormatMask];
};
} // namespace rx
#endif // LIBANGLE_RENDERER_VULKAN_UTILSVK_H_