Hash :
611bbaab
Author :
Date :
2018-12-06T01:59:53
Vulkan: Convert vertex attributes in compute In this commit, VertexArrayVk::convertVertexBuffer() is renamed to VertexArrayVk::convertVertexBufferCpu() to explicitly show it does a CPU readback. A new VertexArrayVk::convertVertexBuffer() function is added that has the same functionality in gpu (with some assumptions, where the CPU fallback is used should those assumptions fail). Currently, the only requirement is that buffer offset/stride are divided by the component size. ConvertVertex.comp is the shader responsible for this conversion, and it implements the functionality in renderer/copyvertex.inc, minus a few functions that are not used in the Vulkan backend. Bug: angleproject:2958, angleproject:3009 Change-Id: I8ec9a5f4672509bcf7b9e352cd27663970ad4653 Reviewed-on: https://chromium-review.googlesource.com/c/1364451 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Yuly Novikov <ynovikov@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
//
// Copyright 2016 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.
//
// vk_format_utils:
// Helper for Vulkan format code.
#include "libANGLE/renderer/vulkan/vk_format_utils.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/load_functions_table.h"
#include "libANGLE/renderer/vulkan/RendererVk.h"
#include "libANGLE/renderer/vulkan/vk_caps_utils.h"
namespace rx
{
namespace
{
void AddSampleCounts(VkSampleCountFlags sampleCounts, gl::SupportedSampleSet *outSet)
{
// The possible bits are VK_SAMPLE_COUNT_n_BIT = n, with n = 1 << b. At the time of this
// writing, b is in [0, 6], however, we test all 32 bits in case the enum is extended.
for (unsigned int i = 0; i < 32; ++i)
{
if ((sampleCounts & (1 << i)) != 0)
{
outSet->insert(1 << i);
}
}
}
void FillTextureFormatCaps(RendererVk *renderer, VkFormat format, gl::TextureCaps *outTextureCaps)
{
const VkPhysicalDeviceLimits &physicalDeviceLimits =
renderer->getPhysicalDeviceProperties().limits;
bool hasColorAttachmentFeatureBit =
renderer->hasTextureFormatFeatureBits(format, VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
bool hasDepthAttachmentFeatureBit = renderer->hasTextureFormatFeatureBits(
format, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
outTextureCaps->texturable =
renderer->hasTextureFormatFeatureBits(format, VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
outTextureCaps->filterable = renderer->hasTextureFormatFeatureBits(
format, VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT);
outTextureCaps->textureAttachment =
hasColorAttachmentFeatureBit || hasDepthAttachmentFeatureBit;
outTextureCaps->renderbuffer = outTextureCaps->textureAttachment;
if (outTextureCaps->renderbuffer)
{
if (hasColorAttachmentFeatureBit)
{
AddSampleCounts(physicalDeviceLimits.framebufferColorSampleCounts,
&outTextureCaps->sampleCounts);
}
if (hasDepthAttachmentFeatureBit)
{
AddSampleCounts(physicalDeviceLimits.framebufferDepthSampleCounts,
&outTextureCaps->sampleCounts);
AddSampleCounts(physicalDeviceLimits.framebufferStencilSampleCounts,
&outTextureCaps->sampleCounts);
}
}
}
bool HasFullTextureFormatSupport(RendererVk *renderer, VkFormat vkFormat)
{
constexpr uint32_t kBitsColor = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
constexpr uint32_t kBitsDepth = VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
return renderer->hasTextureFormatFeatureBits(vkFormat, kBitsColor) ||
renderer->hasTextureFormatFeatureBits(vkFormat, kBitsDepth);
}
bool HasFullBufferFormatSupport(RendererVk *renderer, VkFormat vkFormat)
{
return renderer->hasBufferFormatFeatureBits(vkFormat, VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT);
}
using SupportTest = bool (*)(RendererVk *renderer, VkFormat vkFormat);
template <class FormatInitInfo>
int FindSupportedFormat(RendererVk *renderer,
const FormatInitInfo *info,
int numInfo,
SupportTest hasSupport)
{
ASSERT(numInfo > 0);
const int last = numInfo - 1;
for (int i = 0; i < last; ++i)
{
ASSERT(info[i].format != angle::FormatID::NONE);
if (hasSupport(renderer, info[i].vkFormat))
return i;
}
// List must contain a supported item. We failed on all the others so the last one must be it.
ASSERT(info[last].format != angle::FormatID::NONE);
ASSERT(hasSupport(renderer, info[last].vkFormat));
return last;
}
} // anonymous namespace
namespace vk
{
// Format implementation.
Format::Format()
: angleFormatID(angle::FormatID::NONE),
internalFormat(GL_NONE),
textureFormatID(angle::FormatID::NONE),
vkTextureFormat(VK_FORMAT_UNDEFINED),
bufferFormatID(angle::FormatID::NONE),
vkBufferFormat(VK_FORMAT_UNDEFINED),
textureInitializerFunction(nullptr),
textureLoadFunctions(),
vertexLoadRequiresConversion(false),
vkBufferFormatIsPacked(false),
vkSupportsStorageBuffer(false),
vkFormatIsInt(false),
vkFormatIsUnsigned(false)
{}
void Format::initTextureFallback(RendererVk *renderer,
const TextureFormatInitInfo *info,
int numInfo)
{
size_t skip = renderer->getFeatures().forceFallbackFormat ? 1 : 0;
int i = FindSupportedFormat(renderer, info + skip, numInfo - skip, HasFullTextureFormatSupport);
i += skip;
textureFormatID = info[i].format;
vkTextureFormat = info[i].vkFormat;
textureInitializerFunction = info[i].initializer;
}
void Format::initBufferFallback(RendererVk *renderer, const BufferFormatInitInfo *info, int numInfo)
{
size_t skip = renderer->getFeatures().forceFallbackFormat ? 1 : 0;
int i = FindSupportedFormat(renderer, info + skip, numInfo - skip, HasFullBufferFormatSupport);
i += skip;
bufferFormatID = info[i].format;
vkBufferFormat = info[i].vkFormat;
vkBufferFormatIsPacked = info[i].vkFormatIsPacked;
vertexLoadFunction = info[i].vertexLoadFunction;
vertexLoadRequiresConversion = info[i].vertexLoadRequiresConversion;
}
const angle::Format &Format::textureFormat() const
{
return angle::Format::Get(textureFormatID);
}
const angle::Format &Format::bufferFormat() const
{
return angle::Format::Get(bufferFormatID);
}
const angle::Format &Format::angleFormat() const
{
return angle::Format::Get(angleFormatID);
}
bool operator==(const Format &lhs, const Format &rhs)
{
return &lhs == &rhs;
}
bool operator!=(const Format &lhs, const Format &rhs)
{
return &lhs != &rhs;
}
// FormatTable implementation.
FormatTable::FormatTable() {}
FormatTable::~FormatTable() {}
void FormatTable::initialize(RendererVk *renderer,
gl::TextureCapsMap *outTextureCapsMap,
std::vector<GLenum> *outCompressedTextureFormats)
{
for (size_t formatIndex = 0; formatIndex < angle::kNumANGLEFormats; ++formatIndex)
{
vk::Format &format = mFormatData[formatIndex];
const auto formatID = static_cast<angle::FormatID>(formatIndex);
const angle::Format &angleFormat = angle::Format::Get(formatID);
format.initialize(renderer, angleFormat);
const GLenum internalFormat = format.internalFormat;
format.textureLoadFunctions = GetLoadFunctionsMap(internalFormat, format.textureFormatID);
format.angleFormatID = formatID;
if (!format.valid())
{
continue;
}
format.vkSupportsStorageBuffer = renderer->hasBufferFormatFeatureBits(
format.vkBufferFormat, VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT);
gl::TextureCaps textureCaps;
FillTextureFormatCaps(renderer, format.vkTextureFormat, &textureCaps);
outTextureCapsMap->set(formatID, textureCaps);
if (angleFormat.isBlock)
{
outCompressedTextureFormats->push_back(internalFormat);
}
}
}
const Format &FormatTable::operator[](GLenum internalFormat) const
{
angle::FormatID formatID = angle::Format::InternalFormatToID(internalFormat);
return mFormatData[static_cast<size_t>(formatID)];
}
const Format &FormatTable::operator[](angle::FormatID formatID) const
{
return mFormatData[static_cast<size_t>(formatID)];
}
} // namespace vk
size_t GetVertexInputAlignment(const vk::Format &format)
{
const angle::Format &bufferFormat = format.bufferFormat();
size_t pixelBytes = bufferFormat.pixelBytes;
return format.vkBufferFormatIsPacked ? pixelBytes : (pixelBytes / bufferFormat.channelCount());
}
} // namespace rx