mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
Update naming for vertex state
- VertexInputDescriptor -> VertexStateDescriptor - VertexBufferDescriptor -> VertexBufferLayoutDescriptor - VertexBufferDescriptor.stride -> .arrayStride - VertexAttributeDescriptor.offset no longer optional gpuweb PR: https://github.com/gpuweb/gpuweb/pull/469 Bug: dawn:22 Change-Id: I5431df4ba22cfbdb1bc81e6709e562cd736892a3 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/13100 Commit-Queue: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
c3284fa40e
commit
ae1f25fee8
@@ -133,9 +133,9 @@ namespace dawn_native { namespace opengl {
|
||||
}
|
||||
|
||||
// Vertex buffers and index buffers are implemented as part of an OpenGL VAO that
|
||||
// corresponds to an VertexInput. On the contrary in Dawn they are part of the global state.
|
||||
// This means that we have to re-apply these buffers on an VertexInput change.
|
||||
class InputBufferTracker {
|
||||
// corresponds to a VertexState. On the contrary in Dawn they are part of the global state.
|
||||
// This means that we have to re-apply these buffers on a VertexState change.
|
||||
class VertexStateBufferBindingTracker {
|
||||
public:
|
||||
void OnSetIndexBuffer(BufferBase* buffer) {
|
||||
mIndexBufferDirty = true;
|
||||
@@ -157,7 +157,7 @@ namespace dawn_native { namespace opengl {
|
||||
}
|
||||
|
||||
mIndexBufferDirty = true;
|
||||
mDirtyVertexBuffers |= pipeline->GetInputsSetMask();
|
||||
mDirtyVertexBuffers |= pipeline->GetVertexBufferSlotsUsed();
|
||||
|
||||
mLastPipeline = pipeline;
|
||||
}
|
||||
@@ -168,30 +168,32 @@ namespace dawn_native { namespace opengl {
|
||||
mIndexBufferDirty = false;
|
||||
}
|
||||
|
||||
for (uint32_t slot :
|
||||
IterateBitSet(mDirtyVertexBuffers & mLastPipeline->GetInputsSetMask())) {
|
||||
for (uint32_t slot : IterateBitSet(mDirtyVertexBuffers &
|
||||
mLastPipeline->GetVertexBufferSlotsUsed())) {
|
||||
for (uint32_t location :
|
||||
IterateBitSet(mLastPipeline->GetAttributesUsingInput(slot))) {
|
||||
auto attribute = mLastPipeline->GetAttribute(location);
|
||||
IterateBitSet(mLastPipeline->GetAttributesUsingVertexBuffer(slot))) {
|
||||
const VertexAttributeInfo& attribute =
|
||||
mLastPipeline->GetAttribute(location);
|
||||
|
||||
GLuint buffer = mVertexBuffers[slot]->GetHandle();
|
||||
uint64_t offset = mVertexBufferOffsets[slot];
|
||||
|
||||
auto input = mLastPipeline->GetInput(slot);
|
||||
auto components = VertexFormatNumComponents(attribute.format);
|
||||
auto formatType = VertexFormatType(attribute.format);
|
||||
const VertexBufferInfo& vertexBuffer = mLastPipeline->GetVertexBuffer(slot);
|
||||
uint32_t components = VertexFormatNumComponents(attribute.format);
|
||||
GLenum formatType = VertexFormatType(attribute.format);
|
||||
|
||||
GLboolean normalized = VertexFormatIsNormalized(attribute.format);
|
||||
gl.BindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
if (VertexFormatIsInt(attribute.format)) {
|
||||
gl.VertexAttribIPointer(location, components, formatType, input.stride,
|
||||
reinterpret_cast<void*>(static_cast<intptr_t>(
|
||||
offset + attribute.offset)));
|
||||
} else {
|
||||
gl.VertexAttribPointer(
|
||||
location, components, formatType, normalized, input.stride,
|
||||
gl.VertexAttribIPointer(
|
||||
location, components, formatType, vertexBuffer.arrayStride,
|
||||
reinterpret_cast<void*>(
|
||||
static_cast<intptr_t>(offset + attribute.offset)));
|
||||
} else {
|
||||
gl.VertexAttribPointer(location, components, formatType, normalized,
|
||||
vertexBuffer.arrayStride,
|
||||
reinterpret_cast<void*>(static_cast<intptr_t>(
|
||||
offset + attribute.offset)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -855,14 +857,14 @@ namespace dawn_native { namespace opengl {
|
||||
RenderPipeline* lastPipeline = nullptr;
|
||||
uint64_t indexBufferBaseOffset = 0;
|
||||
|
||||
InputBufferTracker inputBuffers;
|
||||
VertexStateBufferBindingTracker vertexStateBufferBindingTracker;
|
||||
BindGroupTracker bindGroupTracker = {};
|
||||
|
||||
auto DoRenderBundleCommand = [&](CommandIterator* iter, Command type) {
|
||||
switch (type) {
|
||||
case Command::Draw: {
|
||||
DrawCmd* draw = iter->NextCommand<DrawCmd>();
|
||||
inputBuffers.Apply(gl);
|
||||
vertexStateBufferBindingTracker.Apply(gl);
|
||||
bindGroupTracker.Apply(gl);
|
||||
|
||||
if (draw->firstInstance > 0) {
|
||||
@@ -879,11 +881,11 @@ namespace dawn_native { namespace opengl {
|
||||
|
||||
case Command::DrawIndexed: {
|
||||
DrawIndexedCmd* draw = iter->NextCommand<DrawIndexedCmd>();
|
||||
inputBuffers.Apply(gl);
|
||||
vertexStateBufferBindingTracker.Apply(gl);
|
||||
bindGroupTracker.Apply(gl);
|
||||
|
||||
wgpu::IndexFormat indexFormat =
|
||||
lastPipeline->GetVertexInputDescriptor()->indexFormat;
|
||||
lastPipeline->GetVertexStateDescriptor()->indexFormat;
|
||||
size_t formatSize = IndexFormatSize(indexFormat);
|
||||
GLenum formatType = IndexFormatType(indexFormat);
|
||||
|
||||
@@ -905,7 +907,7 @@ namespace dawn_native { namespace opengl {
|
||||
|
||||
case Command::DrawIndirect: {
|
||||
DrawIndirectCmd* draw = iter->NextCommand<DrawIndirectCmd>();
|
||||
inputBuffers.Apply(gl);
|
||||
vertexStateBufferBindingTracker.Apply(gl);
|
||||
bindGroupTracker.Apply(gl);
|
||||
|
||||
uint64_t indirectBufferOffset = draw->indirectOffset;
|
||||
@@ -919,11 +921,11 @@ namespace dawn_native { namespace opengl {
|
||||
|
||||
case Command::DrawIndexedIndirect: {
|
||||
DrawIndexedIndirectCmd* draw = iter->NextCommand<DrawIndexedIndirectCmd>();
|
||||
inputBuffers.Apply(gl);
|
||||
vertexStateBufferBindingTracker.Apply(gl);
|
||||
bindGroupTracker.Apply(gl);
|
||||
|
||||
wgpu::IndexFormat indexFormat =
|
||||
lastPipeline->GetVertexInputDescriptor()->indexFormat;
|
||||
lastPipeline->GetVertexStateDescriptor()->indexFormat;
|
||||
GLenum formatType = IndexFormatType(indexFormat);
|
||||
|
||||
uint64_t indirectBufferOffset = draw->indirectOffset;
|
||||
@@ -948,7 +950,7 @@ namespace dawn_native { namespace opengl {
|
||||
lastPipeline = ToBackend(cmd->pipeline).Get();
|
||||
lastPipeline->ApplyNow(persistentPipelineState);
|
||||
|
||||
inputBuffers.OnSetPipeline(lastPipeline);
|
||||
vertexStateBufferBindingTracker.OnSetPipeline(lastPipeline);
|
||||
bindGroupTracker.OnSetPipeline(lastPipeline);
|
||||
} break;
|
||||
|
||||
@@ -965,12 +967,13 @@ namespace dawn_native { namespace opengl {
|
||||
case Command::SetIndexBuffer: {
|
||||
SetIndexBufferCmd* cmd = iter->NextCommand<SetIndexBufferCmd>();
|
||||
indexBufferBaseOffset = cmd->offset;
|
||||
inputBuffers.OnSetIndexBuffer(cmd->buffer.Get());
|
||||
vertexStateBufferBindingTracker.OnSetIndexBuffer(cmd->buffer.Get());
|
||||
} break;
|
||||
|
||||
case Command::SetVertexBuffer: {
|
||||
SetVertexBufferCmd* cmd = iter->NextCommand<SetVertexBufferCmd>();
|
||||
inputBuffers.OnSetVertexBuffer(cmd->slot, cmd->buffer.Get(), cmd->offset);
|
||||
vertexStateBufferBindingTracker.OnSetVertexBuffer(cmd->slot, cmd->buffer.Get(),
|
||||
cmd->offset);
|
||||
} break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace dawn_native { namespace opengl {
|
||||
modules[SingleShaderStage::Fragment] = ToBackend(descriptor->fragmentStage->module);
|
||||
|
||||
PipelineGL::Initialize(device->gl, ToBackend(GetLayout()), modules);
|
||||
CreateVAOForVertexInput(descriptor->vertexInput);
|
||||
CreateVAOForVertexState(descriptor->vertexState);
|
||||
}
|
||||
|
||||
RenderPipeline::~RenderPipeline() {
|
||||
@@ -215,25 +215,25 @@ namespace dawn_native { namespace opengl {
|
||||
return mGlPrimitiveTopology;
|
||||
}
|
||||
|
||||
void RenderPipeline::CreateVAOForVertexInput(const VertexInputDescriptor* vertexInput) {
|
||||
void RenderPipeline::CreateVAOForVertexState(const VertexStateDescriptor* vertexState) {
|
||||
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl;
|
||||
|
||||
gl.GenVertexArrays(1, &mVertexArrayObject);
|
||||
gl.BindVertexArray(mVertexArrayObject);
|
||||
|
||||
for (uint32_t location : IterateBitSet(GetAttributesSetMask())) {
|
||||
for (uint32_t location : IterateBitSet(GetAttributeLocationsUsed())) {
|
||||
const auto& attribute = GetAttribute(location);
|
||||
gl.EnableVertexAttribArray(location);
|
||||
|
||||
attributesUsingInput[attribute.inputSlot][location] = true;
|
||||
auto input = GetInput(attribute.inputSlot);
|
||||
attributesUsingVertexBuffer[attribute.vertexBufferSlot][location] = true;
|
||||
const VertexBufferInfo& vertexBuffer = GetVertexBuffer(attribute.vertexBufferSlot);
|
||||
|
||||
if (input.stride == 0) {
|
||||
if (vertexBuffer.arrayStride == 0) {
|
||||
// Emulate a stride of zero (constant vertex attribute) by
|
||||
// setting the attribute instance divisor to a huge number.
|
||||
gl.VertexAttribDivisor(location, 0xffffffff);
|
||||
} else {
|
||||
switch (input.stepMode) {
|
||||
switch (vertexBuffer.stepMode) {
|
||||
case wgpu::InputStepMode::Vertex:
|
||||
break;
|
||||
case wgpu::InputStepMode::Instance:
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace dawn_native { namespace opengl {
|
||||
void ApplyNow(PersistentPipelineState& persistentPipelineState);
|
||||
|
||||
private:
|
||||
void CreateVAOForVertexInput(const VertexInputDescriptor* vertexInput);
|
||||
void CreateVAOForVertexState(const VertexStateDescriptor* vertexState);
|
||||
|
||||
// TODO(yunchao.he@intel.com): vao need to be deduplicated between pipelines.
|
||||
GLuint mVertexArrayObject;
|
||||
|
||||
Reference in New Issue
Block a user