Hash :
6b275406
Author :
Date :
2020-01-09T11:14:47
Vulkan: Workaround vertex attributes vs stride issue on AMD
Under robustBufferAccess, Vulkan states that:
Vertex input attributes are considered out of bounds if the offset of
the attribute in the bound vertex buffer range plus the size of the
attribute is greater than either:
- vertexBufferRangeSize, if bindingStride == 0; or
- (vertexBufferRangeSize - (vertexBufferRangeSize % bindingStride))
The latter implies that if the buffer size is not a multiple of the
vertex attribute stride, what lies beyond the last multiple of stride is
considered out of bounds.
It also says:
Out-of-bounds buffer loads will return any of the following values:
- Values from anywhere within the memory range(s) bound to the buffer
(possibly including bytes of memory past the end of the buffer, up to
the end of the bound range).
- Zero values, or (0,0,0,x) vectors for vector reads where x is a valid
value represented in the type of the vector components and may be any
of ...
The first bullet point indicates that the driver is allowed to load the
attribute values from the buffer if its range still lies within the
buffer size.
Take the following example:
- Buffer size = 12
- Attribute stride = 8
- Attribute offset = 0
- Attribute size = 4
Basically the buffer is thus laid out as follows:
attr stride
_________/\_________
/ \
+----------+----------+----------+
| vertex 0 | padding | vertex 1 |
+----------+----------+----------+
\___ ____/
V
attr size
In the above example, the attribute for vertex 1 is considered out of
bounds, but the driver is allowed to either read it correctly, or return
(0, 0, 0, 1) for it.
Most drivers implement the former, while AMD implements the latter.
This change introduces a workaround for AMD where
GL_MAX_VERTEX_ATTRIB_STRIDE is limited to 2048 (the common value for it
according to gpuinfo.org) and conservatively rounds up every buffer
allocation to that size.
While technically, this workaround should be applied on any device with
the robustBufferAccess feature enabled, it is currently limited to AMD
to avoid the inefficiency. A possible future revision of Vulkan may
relax the above restrictions.
Bug: angleproject:2848
Change-Id: Ida5ae5d777da10f22ce8be5a09a7644b5bbd778e
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1991709
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Tim Van Patten <timvp@google.com>
Commit-Queue: 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
//
// Copyright 2013 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.
//
// Contants.h: Defines some implementation specific and gl constants
#ifndef LIBANGLE_CONSTANTS_H_
#define LIBANGLE_CONSTANTS_H_
#include "common/platform.h"
#include <stdint.h>
namespace gl
{
// The binary cache is currently left disable by default, and the application can enable it.
const size_t kDefaultMaxProgramCacheMemoryBytes = 0;
enum
{
// Implementation upper limits, real maximums depend on the hardware
MAX_SAMPLE_MASK_WORDS = 2,
MAX_VERTEX_ATTRIBS = 16,
MAX_VERTEX_ATTRIB_BINDINGS = 16,
// Implementation upper limits, real maximums depend on the hardware
IMPLEMENTATION_MAX_VARYING_VECTORS = 32,
IMPLEMENTATION_MAX_DRAW_BUFFERS = 8,
IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS =
IMPLEMENTATION_MAX_DRAW_BUFFERS + 2, // 2 extra for depth and/or stencil buffers
IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS = 16,
IMPLEMENTATION_MAX_GEOMETRY_SHADER_UNIFORM_BUFFERS = 16,
IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS = 16,
IMPLEMENTATION_MAX_COMPUTE_SHADER_UNIFORM_BUFFERS = 16,
// GL_EXT_geometry_shader increases the minimum value of GL_MAX_COMBINED_UNIFORM_BLOCKS to 36.
IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS = 36,
// GL_EXT_geometry_shader increases the minimum value of GL_MAX_UNIFORM_BUFFER_BINDINGS to 48.
IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS = 48,
// Transform feedback limits set to the minimum required by the spec.
IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS = 128,
IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 4,
IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS = 4,
IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS = 4,
// Maximum number of views which are supported by the implementation of ANGLE_multiview.
IMPLEMENTATION_ANGLE_MULTIVIEW_MAX_VIEWS = 4,
// These are the maximums the implementation can support
// The actual GL caps are limited by the device caps
// and should be queried from the Context
IMPLEMENTATION_MAX_2D_TEXTURE_SIZE = 32768,
IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 32768,
IMPLEMENTATION_MAX_3D_TEXTURE_SIZE = 16384,
IMPLEMENTATION_MAX_2D_ARRAY_TEXTURE_LAYERS = 2048,
// 1+log2 of max of MAX_*_TEXTURE_SIZE
IMPLEMENTATION_MAX_TEXTURE_LEVELS = 16,
// Limit active textures so we can use fast bitsets.
IMPLEMENTATION_MAX_SHADER_TEXTURES = 32,
IMPLEMENTATION_MAX_ACTIVE_TEXTURES = IMPLEMENTATION_MAX_SHADER_TEXTURES * 2,
IMPLEMENTATION_MAX_IMAGE_UNITS = IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
// Maximum number of slots allocated for atomic counter buffers.
IMPLEMENTATION_MAX_ATOMIC_COUNTER_BUFFERS = 8,
// Implementation upper limits, real maximums depend on the hardware.
IMPLEMENTATION_MAX_SHADER_STORAGE_BUFFER_BINDINGS = 64,
};
namespace limits
{
// Almost all drivers use 2048 (the minimum value) as GL_MAX_VERTEX_ATTRIB_STRIDE. ANGLE advertizes
// the same limit.
constexpr uint32_t kMaxVertexAttribStride = 2048;
// Some of the minimums required by GL, used to detect if the backend meets the minimum requirement.
// Currently, there's no need to separate these values per spec version.
constexpr uint32_t kMinimumComputeStorageBuffers = 4;
// OpenGL ES 3.0+ Minimum Values
// Table 6.31 MAX_VERTEX_UNIFORM_BLOCKS minimum value = 12
// Table 6.32 MAX_FRAGMENT_UNIFORM_BLOCKS minimum value = 12
constexpr uint32_t kMinimumShaderUniformBlocks = 12;
// Table 6.31 MAX_VERTEX_OUTPUT_COMPONENTS minimum value = 64
constexpr uint32_t kMinimumVertexOutputComponents = 64;
} // namespace limits
} // namespace gl
#endif // LIBANGLE_CONSTANTS_H_