Remove deprecated SetIndexBuffer (without format).

This also simplifies a bunch of code in backends that was used to handle
getting the indexFormat from the pipeline "late".

Bug: dawn:502

Change-Id: Ibae50c8df21323fd391515f6036552e9fb868d93
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/32023
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Corentin Wallez
2020-11-25 08:54:14 +00:00
committed by Commit Bot service account
parent 33f29ea9b2
commit 5fad85bbd9
22 changed files with 145 additions and 352 deletions

View File

@@ -126,20 +126,12 @@ namespace dawn_native {
}
}
if (aspects[VALIDATION_ASPECT_INDEX_BUFFER]) {
if (mIndexBufferSet) {
wgpu::IndexFormat pipelineIndexFormat =
mLastRenderPipeline->GetVertexStateDescriptor()->indexFormat;
if (mIndexFormat != wgpu::IndexFormat::Undefined) {
if (!IsStripPrimitiveTopology(mLastRenderPipeline->GetPrimitiveTopology()) ||
mIndexFormat == pipelineIndexFormat) {
mAspects.set(VALIDATION_ASPECT_INDEX_BUFFER);
}
} else if (pipelineIndexFormat != wgpu::IndexFormat::Undefined) {
// TODO(crbug.com/dawn/502): Deprecated path. Remove once setIndexFormat always
// requires an index format.
mAspects.set(VALIDATION_ASPECT_INDEX_BUFFER);
}
if (aspects[VALIDATION_ASPECT_INDEX_BUFFER] && mIndexBufferSet) {
wgpu::IndexFormat pipelineIndexFormat =
mLastRenderPipeline->GetVertexStateDescriptor()->indexFormat;
if (!IsStripPrimitiveTopology(mLastRenderPipeline->GetPrimitiveTopology()) ||
mIndexFormat == pipelineIndexFormat) {
mAspects.set(VALIDATION_ASPECT_INDEX_BUFFER);
}
}
}
@@ -154,17 +146,10 @@ namespace dawn_native {
mLastRenderPipeline->GetVertexStateDescriptor()->indexFormat;
if (!mIndexBufferSet) {
return DAWN_VALIDATION_ERROR("Missing index buffer");
} else if (mIndexFormat != wgpu::IndexFormat::Undefined &&
IsStripPrimitiveTopology(mLastRenderPipeline->GetPrimitiveTopology()) &&
mIndexFormat != pipelineIndexFormat) {
} else if (IsStripPrimitiveTopology(mLastRenderPipeline->GetPrimitiveTopology()) &&
mIndexFormat != pipelineIndexFormat) {
return DAWN_VALIDATION_ERROR(
"Pipeline strip index format does not match index buffer format");
} else if (mIndexFormat == wgpu::IndexFormat::Undefined &&
pipelineIndexFormat == wgpu::IndexFormat::Undefined) {
// TODO(crbug.com/dawn/502): Deprecated path. Remove once setIndexFormat always
// requires an index format.
return DAWN_VALIDATION_ERROR(
"Index format must be specified on the pipeline or in setIndexBuffer");
}
// The chunk of code above should be similar to the one in |RecomputeLazyAspects|.

View File

@@ -153,24 +153,25 @@ namespace dawn_native {
});
}
void RenderEncoderBase::SetIndexBuffer(BufferBase* buffer, uint64_t offset, uint64_t size) {
GetDevice()->EmitDeprecationWarning(
"RenderEncoderBase::SetIndexBuffer is deprecated. Use RenderEncoderBase::SetIndexBufferWithFormat instead");
SetIndexBufferCommon(buffer, wgpu::IndexFormat::Undefined, offset, size, false);
}
void RenderEncoderBase::SetIndexBufferWithFormat(BufferBase* buffer, wgpu::IndexFormat format,
uint64_t offset, uint64_t size) {
SetIndexBufferCommon(buffer, format, offset, size, true);
GetDevice()->EmitDeprecationWarning(
"RenderEncoderBase::SetIndexBufferWithFormat is deprecated. Use "
"RenderEncoderBase::SetIndexBuffer instead.");
SetIndexBuffer(buffer, format, offset, size);
}
void RenderEncoderBase::SetIndexBufferCommon(BufferBase* buffer, wgpu::IndexFormat format,
uint64_t offset, uint64_t size,
bool requireFormat) {
void RenderEncoderBase::SetIndexBuffer(BufferBase* buffer,
wgpu::IndexFormat format,
uint64_t offset,
uint64_t size) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
DAWN_TRY(GetDevice()->ValidateObject(buffer));
DAWN_TRY(ValidateIndexFormat(format));
if (format == wgpu::IndexFormat::Undefined) {
return DAWN_VALIDATION_ERROR("Index format must be specified");
}
uint64_t bufferSize = buffer->GetSize();
if (offset > bufferSize) {
@@ -186,12 +187,6 @@ namespace dawn_native {
}
}
if (requireFormat && format == wgpu::IndexFormat::Undefined) {
return DAWN_VALIDATION_ERROR("Index format must be specified");
} else if (!requireFormat) {
ASSERT(format == wgpu::IndexFormat::Undefined);
}
SetIndexBufferCmd* cmd =
allocator->Allocate<SetIndexBufferCmd>(Command::SetIndexBuffer);
cmd->buffer = buffer;

View File

@@ -40,7 +40,10 @@ namespace dawn_native {
void SetPipeline(RenderPipelineBase* pipeline);
void SetVertexBuffer(uint32_t slot, BufferBase* buffer, uint64_t offset, uint64_t size);
void SetIndexBuffer(BufferBase* buffer, uint64_t offset, uint64_t size);
void SetIndexBuffer(BufferBase* buffer,
wgpu::IndexFormat format,
uint64_t offset,
uint64_t size);
void SetIndexBufferWithFormat(BufferBase* buffer, wgpu::IndexFormat format, uint64_t offset,
uint64_t size);
@@ -49,9 +52,6 @@ namespace dawn_native {
RenderEncoderBase(DeviceBase* device, EncodingContext* encodingContext, ErrorTag errorTag);
private:
void SetIndexBufferCommon(BufferBase* buffer, wgpu::IndexFormat format, uint64_t offset,
uint64_t size, bool requireFormat);
const bool mDisableBaseVertex;
const bool mDisableBaseInstance;
};

View File

@@ -94,15 +94,16 @@ namespace dawn_native {
}
DAWN_TRY(ValidateIndexFormat(descriptor->indexFormat));
// Pipeline descriptors using strip topologies must not have an undefined index format.
// Pipeline descriptors must have indexFormat != undefined IFF they are using strip
// topologies.
if (IsStripPrimitiveTopology(primitiveTopology)) {
if (descriptor->indexFormat == wgpu::IndexFormat::Undefined) {
return DAWN_VALIDATION_ERROR(
"indexFormat must not be undefined when using strip primitive topologies");
}
} else if (descriptor->indexFormat != wgpu::IndexFormat::Undefined) {
device->EmitDeprecationWarning(
"Specifying an indexFormat when using list primitive topologies is deprecated");
return DAWN_VALIDATION_ERROR(
"indexFormat must be undefined when using non-strip primitive topologies");
}
if (descriptor->vertexBufferCount > kMaxVertexBuffers) {

View File

@@ -505,46 +505,6 @@ namespace dawn_native { namespace d3d12 {
mD3D12BufferViews = {};
};
class IndexBufferTracker {
public:
void OnSetIndexBuffer(Buffer* buffer,
wgpu::IndexFormat format,
uint64_t offset,
uint64_t size) {
mD3D12BufferView.BufferLocation = buffer->GetVA() + offset;
mD3D12BufferView.SizeInBytes = size;
mBufferIndexFormat = DXGIIndexFormat(format);
// We don't need to dirty the state unless BufferLocation or SizeInBytes
// change, but most of the time this will always be the case.
mLastAppliedIndexFormat = DXGI_FORMAT_UNKNOWN;
}
void OnSetPipeline(const RenderPipelineBase* pipeline) {
mPipelineIndexFormat =
DXGIIndexFormat(pipeline->GetVertexStateDescriptor()->indexFormat);
}
void Apply(ID3D12GraphicsCommandList* commandList) {
DXGI_FORMAT newIndexFormat = mBufferIndexFormat;
if (newIndexFormat == DXGI_FORMAT_UNKNOWN) {
newIndexFormat = mPipelineIndexFormat;
}
if (newIndexFormat != mLastAppliedIndexFormat) {
mD3D12BufferView.Format = newIndexFormat;
commandList->IASetIndexBuffer(&mD3D12BufferView);
mLastAppliedIndexFormat = newIndexFormat;
}
}
private:
DXGI_FORMAT mBufferIndexFormat = DXGI_FORMAT_UNKNOWN;
DXGI_FORMAT mPipelineIndexFormat = DXGI_FORMAT_UNKNOWN;
DXGI_FORMAT mLastAppliedIndexFormat = DXGI_FORMAT_UNKNOWN;
D3D12_INDEX_BUFFER_VIEW mD3D12BufferView = {};
};
void ResolveMultisampledRenderPass(CommandRecordingContext* commandContext,
BeginRenderPassCmd* renderPass) {
ASSERT(renderPass != nullptr);
@@ -1269,7 +1229,6 @@ namespace dawn_native { namespace d3d12 {
RenderPipeline* lastPipeline = nullptr;
PipelineLayout* lastLayout = nullptr;
VertexBufferTracker vertexBufferTracker = {};
IndexBufferTracker indexBufferTracker = {};
auto EncodeRenderBundleCommand = [&](CommandIterator* iter, Command type) -> MaybeError {
switch (type) {
@@ -1287,7 +1246,6 @@ namespace dawn_native { namespace d3d12 {
DrawIndexedCmd* draw = iter->NextCommand<DrawIndexedCmd>();
DAWN_TRY(bindingTracker->Apply(commandContext));
indexBufferTracker.Apply(commandList);
vertexBufferTracker.Apply(commandList, lastPipeline);
commandList->DrawIndexedInstanced(draw->indexCount, draw->instanceCount,
draw->firstIndex, draw->baseVertex,
@@ -1312,7 +1270,6 @@ namespace dawn_native { namespace d3d12 {
DrawIndexedIndirectCmd* draw = iter->NextCommand<DrawIndexedIndirectCmd>();
DAWN_TRY(bindingTracker->Apply(commandContext));
indexBufferTracker.Apply(commandList);
vertexBufferTracker.Apply(commandList, lastPipeline);
Buffer* buffer = ToBackend(draw->indirectBuffer.Get());
ComPtr<ID3D12CommandSignature> signature =
@@ -1371,7 +1328,6 @@ namespace dawn_native { namespace d3d12 {
commandList->IASetPrimitiveTopology(pipeline->GetD3D12PrimitiveTopology());
bindingTracker->OnSetPipeline(pipeline);
indexBufferTracker.OnSetPipeline(pipeline);
lastPipeline = pipeline;
lastLayout = layout;
@@ -1395,8 +1351,12 @@ namespace dawn_native { namespace d3d12 {
case Command::SetIndexBuffer: {
SetIndexBufferCmd* cmd = iter->NextCommand<SetIndexBufferCmd>();
indexBufferTracker.OnSetIndexBuffer(ToBackend(cmd->buffer.Get()), cmd->format,
cmd->offset, cmd->size);
D3D12_INDEX_BUFFER_VIEW bufferView;
bufferView.Format = DXGIIndexFormat(cmd->format);
bufferView.BufferLocation = ToBackend(cmd->buffer)->GetVA() + cmd->offset;
bufferView.SizeInBytes = cmd->size;
commandList->IASetIndexBuffer(&bufferView);
break;
}

View File

@@ -1030,7 +1030,9 @@ namespace dawn_native { namespace metal {
RenderPipeline* lastPipeline = nullptr;
id<MTLBuffer> indexBuffer = nullptr;
uint32_t indexBufferBaseOffset = 0;
wgpu::IndexFormat indexBufferFormat = wgpu::IndexFormat::Undefined;
MTLIndexType indexBufferType;
uint64_t indexTypeSize = 0;
StorageBufferLengthTracker storageBufferLengths = {};
VertexBufferTracker vertexBuffers(&storageBufferLengths);
BindGroupTracker bindGroups(&storageBufferLengths);
@@ -1072,15 +1074,6 @@ namespace dawn_native { namespace metal {
bindGroups.Apply(encoder);
storageBufferLengths.Apply(encoder, lastPipeline, enableVertexPulling);
// If a index format was specified in setIndexBuffer always use it.
wgpu::IndexFormat indexFormat = indexBufferFormat;
if (indexFormat == wgpu::IndexFormat::Undefined) {
// Otherwise use the pipeline's index format.
// TODO(crbug.com/dawn/502): This path is deprecated.
indexFormat = lastPipeline->GetVertexStateDescriptor()->indexFormat;
}
size_t formatSize = IndexFormatSize(indexFormat);
// The index and instance count must be non-zero, otherwise no-op
if (draw->indexCount != 0 && draw->instanceCount != 0) {
// MTLFeatureSet_iOS_GPUFamily3_v1 does not support baseInstance and
@@ -1088,18 +1081,18 @@ namespace dawn_native { namespace metal {
if (draw->baseVertex == 0 && draw->firstInstance == 0) {
[encoder drawIndexedPrimitives:lastPipeline->GetMTLPrimitiveTopology()
indexCount:draw->indexCount
indexType:MTLIndexFormat(indexFormat)
indexType:indexBufferType
indexBuffer:indexBuffer
indexBufferOffset:indexBufferBaseOffset +
draw->firstIndex * formatSize
draw->firstIndex * indexTypeSize
instanceCount:draw->instanceCount];
} else {
[encoder drawIndexedPrimitives:lastPipeline->GetMTLPrimitiveTopology()
indexCount:draw->indexCount
indexType:MTLIndexFormat(indexFormat)
indexType:indexBufferType
indexBuffer:indexBuffer
indexBufferOffset:indexBufferBaseOffset +
draw->firstIndex * formatSize
draw->firstIndex * indexTypeSize
instanceCount:draw->instanceCount
baseVertex:draw->baseVertex
baseInstance:draw->firstInstance];
@@ -1130,18 +1123,10 @@ namespace dawn_native { namespace metal {
bindGroups.Apply(encoder);
storageBufferLengths.Apply(encoder, lastPipeline, enableVertexPulling);
// If a index format was specified in setIndexBuffer always use it.
wgpu::IndexFormat indexFormat = indexBufferFormat;
if (indexFormat == wgpu::IndexFormat::Undefined) {
// Otherwise use the pipeline's index format.
// TODO(crbug.com/dawn/502): This path is deprecated.
indexFormat = lastPipeline->GetVertexStateDescriptor()->indexFormat;
}
Buffer* buffer = ToBackend(draw->indirectBuffer.Get());
id<MTLBuffer> indirectBuffer = buffer->GetMTLBuffer();
[encoder drawIndexedPrimitives:lastPipeline->GetMTLPrimitiveTopology()
indexType:MTLIndexFormat(indexFormat)
indexType:indexBufferType
indexBuffer:indexBuffer
indexBufferOffset:indexBufferBaseOffset
indirectBuffer:indirectBuffer
@@ -1210,9 +1195,8 @@ namespace dawn_native { namespace metal {
auto b = ToBackend(cmd->buffer.Get());
indexBuffer = b->GetMTLBuffer();
indexBufferBaseOffset = cmd->offset;
// TODO(crbug.com/dawn/502): Once setIndexBuffer is required to specify an
// index buffer format store as an MTLIndexType.
indexBufferFormat = cmd->format;
indexBufferType = MTLIndexFormat(cmd->format);
indexTypeSize = IndexFormatSize(cmd->format);
break;
}

View File

@@ -1009,7 +1009,8 @@ namespace dawn_native { namespace opengl {
RenderPipeline* lastPipeline = nullptr;
uint64_t indexBufferBaseOffset = 0;
wgpu::IndexFormat indexBufferFormat;
GLenum indexBufferFormat;
uint32_t indexFormatSize;
VertexStateBufferBindingTracker vertexStateBufferBindingTracker;
BindGroupTracker bindGroupTracker = {};
@@ -1039,20 +1040,11 @@ namespace dawn_native { namespace opengl {
vertexStateBufferBindingTracker.Apply(gl);
bindGroupTracker.Apply(gl);
// If a index format was specified in setIndexBuffer always use it.
wgpu::IndexFormat indexFormat = indexBufferFormat;
if (indexFormat == wgpu::IndexFormat::Undefined) {
// Otherwise use the pipeline's index format.
// TODO(crbug.com/dawn/502): This path is deprecated.
indexFormat = lastPipeline->GetVertexStateDescriptor()->indexFormat;
}
size_t formatSize = IndexFormatSize(indexFormat);
if (draw->firstInstance > 0) {
gl.DrawElementsInstancedBaseVertexBaseInstance(
lastPipeline->GetGLPrimitiveTopology(), draw->indexCount,
IndexFormatType(indexFormat),
reinterpret_cast<void*>(draw->firstIndex * formatSize +
indexBufferFormat,
reinterpret_cast<void*>(draw->firstIndex * indexFormatSize +
indexBufferBaseOffset),
draw->instanceCount, draw->baseVertex, draw->firstInstance);
} else {
@@ -1060,16 +1052,16 @@ namespace dawn_native { namespace opengl {
if (draw->baseVertex != 0) {
gl.DrawElementsInstancedBaseVertex(
lastPipeline->GetGLPrimitiveTopology(), draw->indexCount,
IndexFormatType(indexFormat),
reinterpret_cast<void*>(draw->firstIndex * formatSize +
indexBufferFormat,
reinterpret_cast<void*>(draw->firstIndex * indexFormatSize +
indexBufferBaseOffset),
draw->instanceCount, draw->baseVertex);
} else {
// This branch is only needed on OpenGL < 3.2; ES < 3.2
gl.DrawElementsInstanced(
lastPipeline->GetGLPrimitiveTopology(), draw->indexCount,
IndexFormatType(indexFormat),
reinterpret_cast<void*>(draw->firstIndex * formatSize +
indexBufferFormat,
reinterpret_cast<void*>(draw->firstIndex * indexFormatSize +
indexBufferBaseOffset),
draw->instanceCount);
}
@@ -1100,17 +1092,9 @@ namespace dawn_native { namespace opengl {
uint64_t indirectBufferOffset = draw->indirectOffset;
Buffer* indirectBuffer = ToBackend(draw->indirectBuffer.Get());
// If a index format was specified in setIndexBuffer always use it.
wgpu::IndexFormat indexFormat = indexBufferFormat;
if (indexFormat == wgpu::IndexFormat::Undefined) {
// Otherwise use the pipeline's index format.
// TODO(crbug.com/dawn/502): This path is deprecated.
indexFormat = lastPipeline->GetVertexStateDescriptor()->indexFormat;
}
gl.BindBuffer(GL_DRAW_INDIRECT_BUFFER, indirectBuffer->GetHandle());
gl.DrawElementsIndirect(
lastPipeline->GetGLPrimitiveTopology(), IndexFormatType(indexFormat),
lastPipeline->GetGLPrimitiveTopology(), indexBufferFormat,
reinterpret_cast<void*>(static_cast<intptr_t>(indirectBufferOffset)));
break;
}
@@ -1147,10 +1131,10 @@ namespace dawn_native { namespace opengl {
case Command::SetIndexBuffer: {
SetIndexBufferCmd* cmd = iter->NextCommand<SetIndexBufferCmd>();
// TODO(crbug.com/dawn/502): Once setIndexBuffer is required to specify an
// index buffer format store as an GLenum.
indexBufferFormat = cmd->format;
indexBufferBaseOffset = cmd->offset;
indexBufferFormat = IndexFormatType(cmd->format);
indexFormatSize = IndexFormatSize(cmd->format);
vertexStateBufferBindingTracker.OnSetIndexBuffer(cmd->buffer.Get());
break;
}

View File

@@ -224,41 +224,6 @@ namespace dawn_native { namespace vulkan {
}
};
class IndexBufferTracker {
public:
void OnSetIndexBuffer(VkBuffer buffer, wgpu::IndexFormat format, VkDeviceSize offset) {
mIndexBuffer = buffer;
mOffset = offset;
mBufferIndexFormat = format;
mLastAppliedIndexFormat = wgpu::IndexFormat::Undefined;
}
void OnSetPipeline(RenderPipeline* pipeline) {
mPipelineIndexFormat = pipeline->GetVertexStateDescriptor()->indexFormat;
}
void Apply(Device* device, VkCommandBuffer commands) {
wgpu::IndexFormat newIndexFormat = mBufferIndexFormat;
if (newIndexFormat == wgpu::IndexFormat::Undefined) {
newIndexFormat = mPipelineIndexFormat;
}
if (newIndexFormat != mLastAppliedIndexFormat) {
device->fn.CmdBindIndexBuffer(commands, mIndexBuffer, mOffset,
VulkanIndexType(newIndexFormat));
mLastAppliedIndexFormat = newIndexFormat;
}
}
private:
wgpu::IndexFormat mBufferIndexFormat = wgpu::IndexFormat::Undefined;
wgpu::IndexFormat mPipelineIndexFormat = wgpu::IndexFormat::Undefined;
wgpu::IndexFormat mLastAppliedIndexFormat = wgpu::IndexFormat::Undefined;
VkBuffer mIndexBuffer = VK_NULL_HANDLE;
VkDeviceSize mOffset;
};
MaybeError RecordBeginRenderPass(CommandRecordingContext* recordingContext,
Device* device,
BeginRenderPassCmd* renderPass) {
@@ -1000,7 +965,6 @@ namespace dawn_native { namespace vulkan {
}
RenderDescriptorSetTracker descriptorSets = {};
IndexBufferTracker indexBufferTracker = {};
RenderPipeline* lastPipeline = nullptr;
auto EncodeRenderBundleCommand = [&](CommandIterator* iter, Command type) {
@@ -1018,7 +982,6 @@ namespace dawn_native { namespace vulkan {
DrawIndexedCmd* draw = iter->NextCommand<DrawIndexedCmd>();
descriptorSets.Apply(device, recordingContext, VK_PIPELINE_BIND_POINT_GRAPHICS);
indexBufferTracker.Apply(device, commands);
device->fn.CmdDrawIndexed(commands, draw->indexCount, draw->instanceCount,
draw->firstIndex, draw->baseVertex,
draw->firstInstance);
@@ -1041,7 +1004,6 @@ namespace dawn_native { namespace vulkan {
VkBuffer indirectBuffer = ToBackend(draw->indirectBuffer)->GetHandle();
descriptorSets.Apply(device, recordingContext, VK_PIPELINE_BIND_POINT_GRAPHICS);
indexBufferTracker.Apply(device, commands);
device->fn.CmdDrawIndexedIndirect(
commands, indirectBuffer, static_cast<VkDeviceSize>(draw->indirectOffset),
1, 0);
@@ -1115,8 +1077,8 @@ namespace dawn_native { namespace vulkan {
SetIndexBufferCmd* cmd = iter->NextCommand<SetIndexBufferCmd>();
VkBuffer indexBuffer = ToBackend(cmd->buffer)->GetHandle();
indexBufferTracker.OnSetIndexBuffer(indexBuffer, cmd->format,
static_cast<VkDeviceSize>(cmd->offset));
device->fn.CmdBindIndexBuffer(commands, indexBuffer, cmd->offset,
VulkanIndexType(cmd->format));
break;
}
@@ -1129,7 +1091,6 @@ namespace dawn_native { namespace vulkan {
lastPipeline = pipeline;
descriptorSets.OnSetPipeline(pipeline);
indexBufferTracker.OnSetPipeline(pipeline);
break;
}