зеркало из https://github.com/AvaloniaUI/angle.git
D3D11: Don't store device in InputLayoutCache.
We will need the Renderer pointer for resource allocation, so pass it around instead of storing the device and context. BUG=angleproject:2034 Change-Id: Iaf271913f88c5402895aa81de310aa22fcd72cc4 Reviewed-on: https://chromium-review.googlesource.com/509930 Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
This commit is contained in:
Родитель
341a36cce4
Коммит
caafd890bf
|
@ -12,12 +12,13 @@
|
|||
#include "common/bitset_utils.h"
|
||||
#include "common/utilities.h"
|
||||
#include "libANGLE/Program.h"
|
||||
#include "libANGLE/VertexAttribute.h"
|
||||
#include "libANGLE/VertexArray.h"
|
||||
#include "libANGLE/VertexAttribute.h"
|
||||
#include "libANGLE/renderer/d3d/IndexDataManager.h"
|
||||
#include "libANGLE/renderer/d3d/ProgramD3D.h"
|
||||
#include "libANGLE/renderer/d3d/VertexDataManager.h"
|
||||
#include "libANGLE/renderer/d3d/d3d11/Buffer11.h"
|
||||
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
|
||||
#include "libANGLE/renderer/d3d/d3d11/ShaderExecutable11.h"
|
||||
#include "libANGLE/renderer/d3d/d3d11/VertexBuffer11.h"
|
||||
#include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
|
||||
|
@ -171,12 +172,10 @@ bool InputLayoutCache::PackedAttributeLayout::operator<(const PackedAttributeLay
|
|||
}
|
||||
|
||||
InputLayoutCache::InputLayoutCache()
|
||||
: mCurrentIL(nullptr),
|
||||
: mCurrentIL(angle::DirtyPointer),
|
||||
mPointSpriteVertexBuffer(nullptr),
|
||||
mPointSpriteIndexBuffer(nullptr),
|
||||
mCacheSize(kDefaultCacheSize),
|
||||
mDevice(nullptr),
|
||||
mDeviceContext(nullptr)
|
||||
mCacheSize(kDefaultCacheSize)
|
||||
{
|
||||
mCurrentBuffers.fill(nullptr);
|
||||
mCurrentVertexStrides.fill(std::numeric_limits<UINT>::max());
|
||||
|
@ -189,12 +188,9 @@ InputLayoutCache::~InputLayoutCache()
|
|||
clear();
|
||||
}
|
||||
|
||||
void InputLayoutCache::initialize(ID3D11Device *device, ID3D11DeviceContext *context)
|
||||
void InputLayoutCache::initialize()
|
||||
{
|
||||
clear();
|
||||
mDevice = device;
|
||||
mDeviceContext = context;
|
||||
mFeatureLevel = device->GetFeatureLevel();
|
||||
}
|
||||
|
||||
void InputLayoutCache::clear()
|
||||
|
@ -211,7 +207,7 @@ void InputLayoutCache::clear()
|
|||
|
||||
void InputLayoutCache::markDirty()
|
||||
{
|
||||
mCurrentIL = nullptr;
|
||||
mCurrentIL = angle::DirtyPointer;
|
||||
for (unsigned int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
|
||||
{
|
||||
mCurrentBuffers[i] = nullptr;
|
||||
|
@ -221,6 +217,7 @@ void InputLayoutCache::markDirty()
|
|||
}
|
||||
|
||||
gl::Error InputLayoutCache::applyVertexBuffers(
|
||||
Renderer11 *renderer,
|
||||
const gl::State &state,
|
||||
const std::vector<TranslatedAttribute> &vertexArrayAttribs,
|
||||
const std::vector<TranslatedAttribute> ¤tValueAttribs,
|
||||
|
@ -229,7 +226,8 @@ gl::Error InputLayoutCache::applyVertexBuffers(
|
|||
TranslatedIndexData *indexInfo,
|
||||
GLsizei numIndicesPerInstance)
|
||||
{
|
||||
ASSERT(mDevice && mDeviceContext);
|
||||
ID3D11DeviceContext *deviceContext = renderer->getDeviceContext();
|
||||
ID3D11Device *device = renderer->getDevice();
|
||||
|
||||
gl::Program *program = state.getProgram();
|
||||
ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program);
|
||||
|
@ -241,8 +239,10 @@ gl::Error InputLayoutCache::applyVertexBuffers(
|
|||
SortAttributesByLayout(program, vertexArrayAttribs, currentValueAttribs, &sortedSemanticIndices,
|
||||
&mCurrentAttributes);
|
||||
|
||||
auto featureLevel = renderer->getRenderer11DeviceCaps().featureLevel;
|
||||
|
||||
// If we are using FL 9_3, make sure the first attribute is not instanced
|
||||
if (mFeatureLevel <= D3D_FEATURE_LEVEL_9_3 && !mCurrentAttributes.empty())
|
||||
if (featureLevel <= D3D_FEATURE_LEVEL_9_3 && !mCurrentAttributes.empty())
|
||||
{
|
||||
if (mCurrentAttributes[0]->divisor > 0)
|
||||
{
|
||||
|
@ -256,7 +256,8 @@ gl::Error InputLayoutCache::applyVertexBuffers(
|
|||
}
|
||||
}
|
||||
|
||||
ANGLE_TRY(updateInputLayout(state, mode, sortedSemanticIndices, numIndicesPerInstance));
|
||||
ANGLE_TRY(
|
||||
updateInputLayout(renderer, state, mode, sortedSemanticIndices, numIndicesPerInstance));
|
||||
|
||||
bool dirtyBuffers = false;
|
||||
size_t minDiff = gl::MAX_VERTEX_ATTRIBS;
|
||||
|
@ -339,7 +340,6 @@ gl::Error InputLayoutCache::applyVertexBuffers(
|
|||
// handle missing vertex data and will TDR the system.
|
||||
if (programUsesInstancedPointSprites)
|
||||
{
|
||||
HRESULT result = S_OK;
|
||||
const UINT pointSpriteVertexStride = sizeof(float) * 5;
|
||||
|
||||
if (!mPointSpriteVertexBuffer)
|
||||
|
@ -364,7 +364,8 @@ gl::Error InputLayoutCache::applyVertexBuffers(
|
|||
vertexBufferDesc.MiscFlags = 0;
|
||||
vertexBufferDesc.StructureByteStride = 0;
|
||||
|
||||
result = mDevice->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &mPointSpriteVertexBuffer);
|
||||
HRESULT result = device->CreateBuffer(&vertexBufferDesc, &vertexBufferData,
|
||||
&mPointSpriteVertexBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create instanced pointsprite emulation vertex buffer, HRESULT: 0x%08x", result);
|
||||
|
@ -399,7 +400,8 @@ gl::Error InputLayoutCache::applyVertexBuffers(
|
|||
indexBufferDesc.MiscFlags = 0;
|
||||
indexBufferDesc.StructureByteStride = 0;
|
||||
|
||||
result = mDevice->CreateBuffer(&indexBufferDesc, &indexBufferData, &mPointSpriteIndexBuffer);
|
||||
HRESULT result =
|
||||
device->CreateBuffer(&indexBufferDesc, &indexBufferData, &mPointSpriteIndexBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
SafeRelease(mPointSpriteVertexBuffer);
|
||||
|
@ -413,14 +415,14 @@ gl::Error InputLayoutCache::applyVertexBuffers(
|
|||
// non-indexed rendering path in ANGLE (DrawArrays). This means that applyIndexBuffer()
|
||||
// on the renderer will not be called and setting this buffer here ensures that the
|
||||
// rendering path will contain the correct index buffers.
|
||||
mDeviceContext->IASetIndexBuffer(mPointSpriteIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
|
||||
deviceContext->IASetIndexBuffer(mPointSpriteIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (dirtyBuffers)
|
||||
{
|
||||
ASSERT(minDiff <= maxDiff && maxDiff < gl::MAX_VERTEX_ATTRIBS);
|
||||
mDeviceContext->IASetVertexBuffers(
|
||||
deviceContext->IASetVertexBuffers(
|
||||
static_cast<UINT>(minDiff), static_cast<UINT>(maxDiff - minDiff + 1),
|
||||
&mCurrentBuffers[minDiff], &mCurrentVertexStrides[minDiff],
|
||||
&mCurrentVertexOffsets[minDiff]);
|
||||
|
@ -429,7 +431,8 @@ gl::Error InputLayoutCache::applyVertexBuffers(
|
|||
return gl::NoError();
|
||||
}
|
||||
|
||||
gl::Error InputLayoutCache::updateVertexOffsetsForPointSpritesEmulation(GLint startVertex,
|
||||
gl::Error InputLayoutCache::updateVertexOffsetsForPointSpritesEmulation(Renderer11 *renderer,
|
||||
GLint startVertex,
|
||||
GLsizei emulatedInstanceId)
|
||||
{
|
||||
size_t reservedBuffers = GetReservedBufferCount(true);
|
||||
|
@ -447,13 +450,15 @@ gl::Error InputLayoutCache::updateVertexOffsetsForPointSpritesEmulation(GLint st
|
|||
}
|
||||
}
|
||||
|
||||
mDeviceContext->IASetVertexBuffers(0, gl::MAX_VERTEX_ATTRIBS, mCurrentBuffers.data(),
|
||||
mCurrentVertexStrides.data(), mCurrentVertexOffsets.data());
|
||||
ID3D11DeviceContext *deviceContext = renderer->getDeviceContext();
|
||||
deviceContext->IASetVertexBuffers(0, gl::MAX_VERTEX_ATTRIBS, mCurrentBuffers.data(),
|
||||
mCurrentVertexStrides.data(), mCurrentVertexOffsets.data());
|
||||
|
||||
return gl::NoError();
|
||||
}
|
||||
|
||||
gl::Error InputLayoutCache::updateInputLayout(const gl::State &state,
|
||||
gl::Error InputLayoutCache::updateInputLayout(Renderer11 *renderer,
|
||||
const gl::State &state,
|
||||
GLenum mode,
|
||||
const AttribIndexArray &sortedSemanticIndices,
|
||||
GLsizei numIndicesPerInstance)
|
||||
|
@ -513,8 +518,8 @@ gl::Error InputLayoutCache::updateInputLayout(const gl::State &state,
|
|||
}
|
||||
else
|
||||
{
|
||||
ANGLE_TRY(createInputLayout(sortedSemanticIndices, mode, program, numIndicesPerInstance,
|
||||
&inputLayout));
|
||||
ANGLE_TRY(createInputLayout(renderer, sortedSemanticIndices, mode, program,
|
||||
numIndicesPerInstance, &inputLayout));
|
||||
if (mLayoutMap.size() >= mCacheSize)
|
||||
{
|
||||
WARN() << "Overflowed the limit of " << mCacheSize
|
||||
|
@ -538,22 +543,25 @@ gl::Error InputLayoutCache::updateInputLayout(const gl::State &state,
|
|||
}
|
||||
}
|
||||
|
||||
if (inputLayout != mCurrentIL)
|
||||
if (reinterpret_cast<uintptr_t>(inputLayout) != mCurrentIL)
|
||||
{
|
||||
mDeviceContext->IASetInputLayout(inputLayout);
|
||||
mCurrentIL = inputLayout;
|
||||
ID3D11DeviceContext *deviceContext = renderer->getDeviceContext();
|
||||
deviceContext->IASetInputLayout(inputLayout);
|
||||
mCurrentIL = reinterpret_cast<uintptr_t>(inputLayout);
|
||||
}
|
||||
|
||||
return gl::NoError();
|
||||
}
|
||||
|
||||
gl::Error InputLayoutCache::createInputLayout(const AttribIndexArray &sortedSemanticIndices,
|
||||
gl::Error InputLayoutCache::createInputLayout(Renderer11 *renderer,
|
||||
const AttribIndexArray &sortedSemanticIndices,
|
||||
GLenum mode,
|
||||
gl::Program *program,
|
||||
GLsizei numIndicesPerInstance,
|
||||
ID3D11InputLayout **inputLayoutOut)
|
||||
{
|
||||
ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program);
|
||||
auto featureLevel = renderer->getRenderer11DeviceCaps().featureLevel;
|
||||
|
||||
bool programUsesInstancedPointSprites =
|
||||
programD3D->usesPointSize() && programD3D->usesInstancedPointSpriteEmulation();
|
||||
|
@ -571,7 +579,7 @@ gl::Error InputLayoutCache::createInputLayout(const AttribIndexArray &sortedSema
|
|||
|
||||
const auto &vertexFormatType =
|
||||
gl::GetVertexFormatType(*attrib.attribute, attrib.currentValueType);
|
||||
const auto &vertexFormatInfo = d3d11::GetVertexFormatInfo(vertexFormatType, mFeatureLevel);
|
||||
const auto &vertexFormatInfo = d3d11::GetVertexFormatInfo(vertexFormatType, featureLevel);
|
||||
|
||||
auto *inputElement = &inputElements[inputElementCount];
|
||||
|
||||
|
@ -640,15 +648,15 @@ gl::Error InputLayoutCache::createInputLayout(const AttribIndexArray &sortedSema
|
|||
|
||||
ShaderExecutableD3D *shader11 = GetAs<ShaderExecutable11>(shader);
|
||||
|
||||
ID3D11Device *device = renderer->getDevice();
|
||||
HRESULT result =
|
||||
mDevice->CreateInputLayout(inputElements.data(), inputElementCount, shader11->getFunction(),
|
||||
shader11->getLength(), inputLayoutOut);
|
||||
device->CreateInputLayout(inputElements.data(), inputElementCount, shader11->getFunction(),
|
||||
shader11->getLength(), inputLayoutOut);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return gl::Error(GL_OUT_OF_MEMORY,
|
||||
"Failed to create internal input layout, HRESULT: 0x%08x", result);
|
||||
}
|
||||
|
||||
return gl::NoError();
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ struct TranslatedAttribute;
|
|||
struct TranslatedIndexData;
|
||||
struct SourceIndexData;
|
||||
class ProgramD3D;
|
||||
class Renderer11;
|
||||
|
||||
class InputLayoutCache : angle::NonCopyable
|
||||
{
|
||||
|
@ -41,11 +42,12 @@ class InputLayoutCache : angle::NonCopyable
|
|||
InputLayoutCache();
|
||||
virtual ~InputLayoutCache();
|
||||
|
||||
void initialize(ID3D11Device *device, ID3D11DeviceContext *context);
|
||||
void initialize();
|
||||
void clear();
|
||||
void markDirty();
|
||||
|
||||
gl::Error applyVertexBuffers(const gl::State &state,
|
||||
gl::Error applyVertexBuffers(Renderer11 *renderer,
|
||||
const gl::State &state,
|
||||
const std::vector<TranslatedAttribute> &vertexArrayAttribs,
|
||||
const std::vector<TranslatedAttribute> ¤tValueAttribs,
|
||||
GLenum mode,
|
||||
|
@ -53,7 +55,8 @@ class InputLayoutCache : angle::NonCopyable
|
|||
TranslatedIndexData *indexInfo,
|
||||
GLsizei numIndicesPerInstance);
|
||||
|
||||
gl::Error updateVertexOffsetsForPointSpritesEmulation(GLint startVertex,
|
||||
gl::Error updateVertexOffsetsForPointSpritesEmulation(Renderer11 *renderer,
|
||||
GLint startVertex,
|
||||
GLsizei emulatedInstanceId);
|
||||
|
||||
// Useful for testing
|
||||
|
@ -87,11 +90,13 @@ class InputLayoutCache : angle::NonCopyable
|
|||
uint32_t attributeData[gl::MAX_VERTEX_ATTRIBS];
|
||||
};
|
||||
|
||||
gl::Error updateInputLayout(const gl::State &state,
|
||||
gl::Error updateInputLayout(Renderer11 *renderer,
|
||||
const gl::State &state,
|
||||
GLenum mode,
|
||||
const AttribIndexArray &sortedSemanticIndices,
|
||||
GLsizei numIndicesPerInstance);
|
||||
gl::Error createInputLayout(const AttribIndexArray &sortedSemanticIndices,
|
||||
gl::Error createInputLayout(Renderer11 *renderer,
|
||||
const AttribIndexArray &sortedSemanticIndices,
|
||||
GLenum mode,
|
||||
gl::Program *program,
|
||||
GLsizei numIndicesPerInstance,
|
||||
|
@ -99,7 +104,7 @@ class InputLayoutCache : angle::NonCopyable
|
|||
|
||||
std::map<PackedAttributeLayout, ID3D11InputLayout *> mLayoutMap;
|
||||
|
||||
ID3D11InputLayout *mCurrentIL;
|
||||
uintptr_t mCurrentIL;
|
||||
std::array<ID3D11Buffer *, gl::MAX_VERTEX_ATTRIBS> mCurrentBuffers;
|
||||
std::array<UINT, gl::MAX_VERTEX_ATTRIBS> mCurrentVertexStrides;
|
||||
std::array<UINT, gl::MAX_VERTEX_ATTRIBS> mCurrentVertexOffsets;
|
||||
|
@ -109,10 +114,6 @@ class InputLayoutCache : angle::NonCopyable
|
|||
ID3D11Buffer *mPointSpriteIndexBuffer;
|
||||
|
||||
unsigned int mCacheSize;
|
||||
|
||||
ID3D11Device *mDevice;
|
||||
ID3D11DeviceContext *mDeviceContext;
|
||||
D3D_FEATURE_LEVEL mFeatureLevel;
|
||||
};
|
||||
|
||||
} // namespace rx
|
||||
|
|
|
@ -796,7 +796,7 @@ void Renderer11::initializeDevice()
|
|||
populateRenderer11DeviceCaps();
|
||||
|
||||
mStateCache.initialize(mDevice);
|
||||
mInputLayoutCache.initialize(mDevice, mDeviceContext);
|
||||
mInputLayoutCache.initialize();
|
||||
|
||||
ASSERT(!mVertexDataManager && !mIndexDataManager);
|
||||
mVertexDataManager = new VertexDataManager(this);
|
||||
|
@ -1811,8 +1811,9 @@ gl::Error Renderer11::applyVertexBuffer(const gl::State &state,
|
|||
}
|
||||
const auto &vertexArrayAttribs = vertexArray11->getTranslatedAttribs();
|
||||
const auto ¤tValueAttribs = mStateManager.getCurrentValueAttribs();
|
||||
ANGLE_TRY(mInputLayoutCache.applyVertexBuffers(state, vertexArrayAttribs, currentValueAttribs,
|
||||
mode, first, indexInfo, numIndicesPerInstance));
|
||||
ANGLE_TRY(mInputLayoutCache.applyVertexBuffers(this, state, vertexArrayAttribs,
|
||||
currentValueAttribs, mode, first, indexInfo,
|
||||
numIndicesPerInstance));
|
||||
|
||||
// InputLayoutCache::applyVertexBuffers calls through to the Bufer11 to get the native vertex
|
||||
// buffer (ID3D11Buffer *). Because we allocate these buffers lazily, this will trigger
|
||||
|
@ -1994,8 +1995,8 @@ gl::Error Renderer11::drawArraysImpl(const gl::ContextState &data,
|
|||
// offsets.
|
||||
for (GLsizei i = 0; i < instances; i++)
|
||||
{
|
||||
ANGLE_TRY(
|
||||
mInputLayoutCache.updateVertexOffsetsForPointSpritesEmulation(startVertex, i));
|
||||
ANGLE_TRY(mInputLayoutCache.updateVertexOffsetsForPointSpritesEmulation(
|
||||
this, startVertex, i));
|
||||
mDeviceContext->DrawIndexedInstanced(6, count, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
@ -2057,8 +2058,8 @@ gl::Error Renderer11::drawElementsImpl(const gl::ContextState &data,
|
|||
// offsets.
|
||||
for (GLsizei i = 0; i < instances; i++)
|
||||
{
|
||||
ANGLE_TRY(
|
||||
mInputLayoutCache.updateVertexOffsetsForPointSpritesEmulation(startVertex, i));
|
||||
ANGLE_TRY(mInputLayoutCache.updateVertexOffsetsForPointSpritesEmulation(
|
||||
this, startVertex, i));
|
||||
mDeviceContext->DrawIndexedInstanced(6, elementsToRender, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче