Hash :
3b38b379
Author :
Date :
2022-04-20T10:44:24
Vulkan: Add feature avoid HOST_VISIBLE and DEVICE_LOCAL combination Discrete GPUs device local memory usually is not CPU accessible. This adds a feature flag to control that. Fixed bug in BufferVk that when mapRangeImpl is called from angle internal, unmapImpl was using front end mapping parameters that is incorrect. We have to cache the mapping parameters in the backend to hangle the mapRangeImpl/unmapImpl calls from internal. Fixed the test bug in ComputeShaderTest.BufferImageBufferMapWrite that we are calling glMapBufferRange with GL_MAP_READ_BIT but are actually writing to the map pointer. This should result in undefined behavior per spec. Fixed the test bug in GLSLTest.* that VerifyBuffer calls glMapBufferRange, but was giving incorrect length which result in data only been partially copied. This bug was hidden due to previously all buffers are CPU accessible and there is no copy needed. Fixed the test bug in ReadPixelsPBOTest.* and ReadPixelsPBONVTest.* that calls glMapBufferRangeEXT, but was giving incorrect length which result in data only been partially copied. This bug was hidden due to previously all buffers are CPU accessible and there is no copy needed. Added new skipped syncval messages. Because this CL triggers a copyToBuffer call for some of the buffers and that changes the syncval message signature for the same reasons (i.e, feedback loop or synval does not know the exact range of buffer been used for vertex buffers etc). Bug: angleproject:7047 Change-Id: I28c96ae0f23db8e5b51af8259e5b97e12e8b91f2 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3597711 Reviewed-by: Yuxin Hu <yuxinhu@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Charlie Lao <cclao@google.com>
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
//
// 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.
//
// BufferVk.h:
// Defines the class interface for BufferVk, implementing BufferImpl.
//
#ifndef LIBANGLE_RENDERER_VULKAN_BUFFERVK_H_
#define LIBANGLE_RENDERER_VULKAN_BUFFERVK_H_
#include "libANGLE/Buffer.h"
#include "libANGLE/Observer.h"
#include "libANGLE/renderer/BufferImpl.h"
#include "libANGLE/renderer/vulkan/vk_helpers.h"
namespace rx
{
class RendererVk;
// Conversion buffers hold translated index and vertex data.
struct ConversionBuffer
{
ConversionBuffer(RendererVk *renderer,
VkBufferUsageFlags usageFlags,
size_t initialSize,
size_t alignment,
bool hostVisible);
~ConversionBuffer();
ConversionBuffer(ConversionBuffer &&other);
// One state value determines if we need to re-stream vertex data.
bool dirty;
// Where the conversion data is stored.
std::unique_ptr<vk::BufferHelper> data;
};
enum class BufferUpdateType
{
StorageRedefined,
ContentsUpdate,
};
VkBufferUsageFlags GetDefaultBufferUsageFlags(RendererVk *renderer);
class BufferVk : public BufferImpl
{
public:
BufferVk(const gl::BufferState &state);
~BufferVk() override;
void destroy(const gl::Context *context) override;
angle::Result setExternalBufferData(const gl::Context *context,
gl::BufferBinding target,
GLeglClientBufferEXT clientBuffer,
size_t size,
VkMemoryPropertyFlags memoryPropertyFlags);
angle::Result setDataWithUsageFlags(const gl::Context *context,
gl::BufferBinding target,
GLeglClientBufferEXT clientBuffer,
const void *data,
size_t size,
gl::BufferUsage usage,
GLbitfield flags) override;
angle::Result setData(const gl::Context *context,
gl::BufferBinding target,
const void *data,
size_t size,
gl::BufferUsage usage) override;
angle::Result setSubData(const gl::Context *context,
gl::BufferBinding target,
const void *data,
size_t size,
size_t offset) override;
angle::Result copySubData(const gl::Context *context,
BufferImpl *source,
GLintptr sourceOffset,
GLintptr destOffset,
GLsizeiptr size) override;
angle::Result map(const gl::Context *context, GLenum access, void **mapPtr) override;
angle::Result mapRange(const gl::Context *context,
size_t offset,
size_t length,
GLbitfield access,
void **mapPtr) override;
angle::Result unmap(const gl::Context *context, GLboolean *result) override;
angle::Result getSubData(const gl::Context *context,
GLintptr offset,
GLsizeiptr size,
void *outData) override;
angle::Result getIndexRange(const gl::Context *context,
gl::DrawElementsType type,
size_t offset,
size_t count,
bool primitiveRestartEnabled,
gl::IndexRange *outRange) override;
GLint64 getSize() const { return mState.getSize(); }
void onDataChanged() override;
vk::BufferHelper &getBuffer()
{
ASSERT(isBufferValid());
return mBuffer;
}
bool isBufferValid() const { return mBuffer.valid(); }
bool isCurrentlyInUse(ContextVk *contextVk) const;
angle::Result mapImpl(ContextVk *contextVk, GLbitfield access, void **mapPtr);
angle::Result mapRangeImpl(ContextVk *contextVk,
VkDeviceSize offset,
VkDeviceSize length,
GLbitfield access,
void **mapPtr);
angle::Result unmapImpl(ContextVk *contextVk);
angle::Result ghostMappedBuffer(ContextVk *contextVk,
VkDeviceSize offset,
VkDeviceSize length,
GLbitfield access,
void **mapPtr);
ConversionBuffer *getVertexConversionBuffer(RendererVk *renderer,
angle::FormatID formatID,
GLuint stride,
size_t offset,
bool hostVisible);
private:
angle::Result updateBuffer(ContextVk *contextVk,
const uint8_t *data,
size_t size,
size_t offset);
angle::Result directUpdate(ContextVk *contextVk,
const uint8_t *data,
size_t size,
size_t offset);
angle::Result stagedUpdate(ContextVk *contextVk,
const uint8_t *data,
size_t size,
size_t offset);
angle::Result allocStagingBuffer(ContextVk *contextVk,
vk::MemoryCoherency coherency,
VkDeviceSize size,
uint8_t **mapPtr);
angle::Result flushStagingBuffer(ContextVk *contextVk, VkDeviceSize offset, VkDeviceSize size);
angle::Result acquireAndUpdate(ContextVk *contextVk,
const uint8_t *data,
size_t updateSize,
size_t offset,
BufferUpdateType updateType);
angle::Result setDataWithMemoryType(const gl::Context *context,
gl::BufferBinding target,
const void *data,
size_t size,
VkMemoryPropertyFlags memoryPropertyFlags,
bool persistentMapRequired,
gl::BufferUsage usage);
angle::Result handleDeviceLocalBufferMap(ContextVk *contextVk,
VkDeviceSize offset,
VkDeviceSize size,
uint8_t **mapPtr);
angle::Result setDataImpl(ContextVk *contextVk,
const uint8_t *data,
size_t size,
size_t offset,
BufferUpdateType updateType);
void release(ContextVk *context);
void dataUpdated();
angle::Result acquireBufferHelper(ContextVk *contextVk,
size_t sizeInBytes,
BufferUpdateType updateType);
bool isExternalBuffer() const { return mClientBuffer != nullptr; }
struct VertexConversionBuffer : public ConversionBuffer
{
VertexConversionBuffer(RendererVk *renderer,
angle::FormatID formatIDIn,
GLuint strideIn,
size_t offsetIn,
bool hostVisible);
~VertexConversionBuffer();
VertexConversionBuffer(VertexConversionBuffer &&other);
// The conversion is identified by the triple of {format, stride, offset}.
angle::FormatID formatID;
GLuint stride;
size_t offset;
};
vk::BufferHelper mBuffer;
// If not null, this is the external memory pointer passed from client API.
void *mClientBuffer;
uint32_t mMemoryTypeIndex;
// Memory/Usage property that will be used for memory allocation.
VkMemoryPropertyFlags mMemoryPropertyFlags;
// The staging buffer to aid map operations. This is used when buffers are not host visible or
// for performance optimization when only a smaller range of buffer is mapped.
vk::BufferHelper mStagingBuffer;
// A cache of converted vertex data.
std::vector<VertexConversionBuffer> mVertexConversionBuffers;
// Tracks whether mStagingBuffer has been mapped to user or not
bool mIsStagingBufferMapped;
// Tracks if BufferVk object has valid data or not.
bool mHasValidData;
// True if the buffer is currently mapped for CPU write access. If the map call is originated
// from OpenGLES API call, then this should be consistent with mState.getAccessFlags() bits.
// Otherwise it is mapped from ANGLE internal and will not be consistent with mState access
// bits, so we have to keep record of it.
bool mIsMappedForWrite;
// Similar as mIsMappedForWrite, this maybe different from mState's getMapOffset/getMapLength if
// mapped from angle internal.
VkDeviceSize mMappedOffset;
VkDeviceSize mMappedLength;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_VULKAN_BUFFERVK_H_