Hash :
0946393d
Author :
Date :
2018-04-04T05:26:59
Move Buffer Subject/Observer to front end. This makes BufferImpl into an Observer Subject. It also refactors the Vertex Array updates for the D3D11 backend use more of a dirty bit coding style. This change makes it so Buffer contents changes trigger front-end dirty bits from the back-end, which may be undesirable. Bug: angleproject:2389 Change-Id: Iac8ce1171284a86851c18cd1373ddf24fcefe40b Reviewed-on: https://chromium-review.googlesource.com/979812 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@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
//
// Copyright 2014 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.
//
// Buffer11.h: Defines the rx::Buffer11 class which implements rx::BufferImpl via rx::BufferD3D.
#ifndef LIBANGLE_RENDERER_D3D_D3D11_BUFFER11_H_
#define LIBANGLE_RENDERER_D3D_D3D11_BUFFER11_H_
#include <array>
#include <map>
#include "libANGLE/angletypes.h"
#include "libANGLE/renderer/d3d/BufferD3D.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
namespace gl
{
class FramebufferAttachment;
}
namespace rx
{
struct PackPixelsParams;
class Renderer11;
struct SourceIndexData;
struct TranslatedAttribute;
// The order of this enum governs priority of 'getLatestBufferStorage'.
enum BufferUsage
{
BUFFER_USAGE_SYSTEM_MEMORY,
BUFFER_USAGE_STAGING,
BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK,
BUFFER_USAGE_INDEX,
// TODO: possibly share this buffer type with shader storage buffers.
BUFFER_USAGE_INDIRECT,
BUFFER_USAGE_PIXEL_UNPACK,
BUFFER_USAGE_PIXEL_PACK,
BUFFER_USAGE_UNIFORM,
BUFFER_USAGE_EMULATED_INDEXED_VERTEX,
BUFFER_USAGE_COUNT,
};
typedef size_t DataRevision;
class Buffer11 : public BufferD3D
{
public:
Buffer11(const gl::BufferState &state, Renderer11 *renderer);
~Buffer11() override;
gl::ErrorOrResult<ID3D11Buffer *> getBuffer(const gl::Context *context, BufferUsage usage);
gl::ErrorOrResult<ID3D11Buffer *> getEmulatedIndexedBuffer(const gl::Context *context,
SourceIndexData *indexInfo,
const TranslatedAttribute &attribute,
GLint startVertex);
gl::Error getConstantBufferRange(const gl::Context *context,
GLintptr offset,
GLsizeiptr size,
const d3d11::Buffer **bufferOut,
UINT *firstConstantOut,
UINT *numConstantsOut);
gl::ErrorOrResult<const d3d11::ShaderResourceView *> getSRV(const gl::Context *context,
DXGI_FORMAT srvFormat);
bool isMapped() const { return mMappedStorage != nullptr; }
gl::Error packPixels(const gl::Context *context,
const gl::FramebufferAttachment &readAttachment,
const PackPixelsParams ¶ms);
size_t getTotalCPUBufferMemoryBytes() const;
// BufferD3D implementation
size_t getSize() const override;
bool supportsDirectBinding() const override;
gl::Error getData(const gl::Context *context, const uint8_t **outData) override;
void initializeStaticData(const gl::Context *context) override;
void invalidateStaticData(const gl::Context *context) override;
// BufferImpl implementation
gl::Error setData(const gl::Context *context,
gl::BufferBinding target,
const void *data,
size_t size,
gl::BufferUsage usage) override;
gl::Error setSubData(const gl::Context *context,
gl::BufferBinding target,
const void *data,
size_t size,
size_t offset) override;
gl::Error copySubData(const gl::Context *context,
BufferImpl *source,
GLintptr sourceOffset,
GLintptr destOffset,
GLsizeiptr size) override;
gl::Error map(const gl::Context *context, GLenum access, void **mapPtr) override;
gl::Error mapRange(const gl::Context *context,
size_t offset,
size_t length,
GLbitfield access,
void **mapPtr) override;
gl::Error unmap(const gl::Context *context, GLboolean *result) override;
gl::Error markTransformFeedbackUsage(const gl::Context *context) override;
private:
class BufferStorage;
class EmulatedIndexedStorage;
class NativeStorage;
class PackStorage;
class SystemMemoryStorage;
struct ConstantBufferCacheEntry
{
ConstantBufferCacheEntry() : storage(nullptr), lruCount(0) {}
BufferStorage *storage;
unsigned int lruCount;
};
void markBufferUsage(BufferUsage usage);
gl::Error garbageCollection(const gl::Context *context, BufferUsage currentUsage);
gl::ErrorOrResult<NativeStorage *> getStagingStorage(const gl::Context *context);
gl::ErrorOrResult<PackStorage *> getPackStorage(const gl::Context *context);
gl::ErrorOrResult<SystemMemoryStorage *> getSystemMemoryStorage(const gl::Context *context);
gl::Error updateBufferStorage(const gl::Context *context,
BufferStorage *storage,
size_t sourceOffset,
size_t storageSize);
gl::ErrorOrResult<BufferStorage *> getBufferStorage(const gl::Context *context,
BufferUsage usage);
gl::ErrorOrResult<BufferStorage *> getLatestBufferStorage(const gl::Context *context) const;
gl::ErrorOrResult<BufferStorage *> getConstantBufferRangeStorage(const gl::Context *context,
GLintptr offset,
GLsizeiptr size);
BufferStorage *allocateStorage(BufferUsage usage);
void updateDeallocThreshold(BufferUsage usage);
// Free the storage if we decide it isn't being used very often.
gl::Error checkForDeallocation(const gl::Context *context, BufferUsage usage);
// For some cases of uniform buffer storage, we can't deallocate system memory storage.
bool canDeallocateSystemMemory() const;
// Updates data revisions and latest storage.
void onCopyStorage(BufferStorage *dest, BufferStorage *source);
void onStorageUpdate(BufferStorage *updatedStorage);
Renderer11 *mRenderer;
size_t mSize;
BufferStorage *mMappedStorage;
// Buffer storages are sorted by usage. It's important that the latest buffer storage picks
// the lowest usage in the case where two storages are tied on data revision - this ensures
// we never do anything dangerous like map a uniform buffer over a staging or system memory
// copy.
std::array<BufferStorage *, BUFFER_USAGE_COUNT> mBufferStorages;
BufferStorage *mLatestBufferStorage;
// These two arrays are used to track when to free unused storage.
std::array<unsigned int, BUFFER_USAGE_COUNT> mDeallocThresholds;
std::array<unsigned int, BUFFER_USAGE_COUNT> mIdleness;
// Cache of D3D11 constant buffer for specific ranges of buffer data.
// This is used to emulate UBO ranges on 11.0 devices.
// Constant buffers are indexed by there start offset.
typedef std::map<GLintptr /*offset*/, ConstantBufferCacheEntry> ConstantBufferCache;
ConstantBufferCache mConstantBufferRangeStoragesCache;
size_t mConstantBufferStorageAdditionalSize;
unsigned int mMaxConstantBufferLruCount;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_D3D_D3D11_BUFFER11_H_