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>
diff --git a/BUILD.gn b/BUILD.gn
index 59e3228..6f157fd 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -839,7 +839,7 @@
"src/tests/unittests/validation/ValidationTest.cpp",
"src/tests/unittests/validation/ValidationTest.h",
"src/tests/unittests/validation/VertexBufferValidationTests.cpp",
- "src/tests/unittests/validation/VertexInputValidationTests.cpp",
+ "src/tests/unittests/validation/VertexStateValidationTests.cpp",
"src/tests/unittests/wire/WireArgumentTests.cpp",
"src/tests/unittests/wire/WireBasicTests.cpp",
"src/tests/unittests/wire/WireBufferMappingTests.cpp",
@@ -918,7 +918,7 @@
"src/tests/end2end/TextureViewTests.cpp",
"src/tests/end2end/TextureZeroInitTests.cpp",
"src/tests/end2end/VertexFormatTests.cpp",
- "src/tests/end2end/VertexInputTests.cpp",
+ "src/tests/end2end/VertexStateTests.cpp",
"src/tests/end2end/ViewportOrientationTests.cpp",
"src/tests/end2end/ViewportTests.cpp",
]
diff --git a/dawn.json b/dawn.json
index 83b5518..4886a70 100644
--- a/dawn.json
+++ b/dawn.json
@@ -693,28 +693,28 @@
"category": "structure",
"extensible": false,
"members": [
- {"name": "shader location", "type": "uint32_t"},
- {"name": "offset", "type": "uint64_t", "default": "0"},
- {"name": "format", "type": "vertex format"}
+ {"name": "format", "type": "vertex format"},
+ {"name": "offset", "type": "uint64_t"},
+ {"name": "shader location", "type": "uint32_t"}
]
},
- "vertex buffer descriptor": {
+ "vertex buffer layout descriptor": {
"category": "structure",
"extensible": false,
"members": [
- {"name": "stride", "type": "uint64_t"},
+ {"name": "array stride", "type": "uint64_t"},
{"name": "step mode", "type": "input step mode", "default": "vertex"},
{"name": "attribute count", "type": "uint32_t"},
{"name": "attributes", "type": "vertex attribute descriptor", "annotation": "const*", "length": "attribute count"}
]
},
- "vertex input descriptor": {
+ "vertex state descriptor": {
"category": "structure",
"extensible": true,
"members": [
{"name": "index format", "type": "index format", "default": "uint32"},
- {"name": "buffer count", "type": "uint32_t", "default": 0},
- {"name": "buffers", "type": "vertex buffer descriptor", "annotation": "const*", "length": "buffer count"}
+ {"name": "vertex buffer count", "type": "uint32_t", "default": 0},
+ {"name": "vertex buffers", "type": "vertex buffer layout descriptor", "annotation": "const*", "length": "vertex buffer count"}
]
},
"input step mode": {
@@ -1102,7 +1102,7 @@
{"name": "layout", "type": "pipeline layout"},
{"name": "vertex stage", "type": "programmable stage descriptor"},
{"name": "fragment stage", "type": "programmable stage descriptor", "annotation": "const*", "optional": true},
- {"name": "vertex input", "type": "vertex input descriptor", "annotation": "const*", "optional": true},
+ {"name": "vertex state", "type": "vertex state descriptor", "annotation": "const*", "optional": true},
{"name": "primitive topology", "type": "primitive topology"},
{"name": "rasterization state", "type": "rasterization state descriptor", "annotation": "const*", "optional": true},
{"name": "sample count", "type": "uint32_t", "default": "1"},
diff --git a/examples/CHelloTriangle.cpp b/examples/CHelloTriangle.cpp
index 493f1a8..2082b9e 100644
--- a/examples/CHelloTriangle.cpp
+++ b/examples/CHelloTriangle.cpp
@@ -95,12 +95,12 @@
pl.bindGroupLayouts = nullptr;
descriptor.layout = wgpuDeviceCreatePipelineLayout(device, &pl);
- WGPUVertexInputDescriptor vertexInput;
- vertexInput.nextInChain = nullptr;
- vertexInput.indexFormat = WGPUIndexFormat_Uint32;
- vertexInput.bufferCount = 0;
- vertexInput.buffers = nullptr;
- descriptor.vertexInput = &vertexInput;
+ WGPUVertexStateDescriptor vertexState;
+ vertexState.nextInChain = nullptr;
+ vertexState.indexFormat = WGPUIndexFormat_Uint32;
+ vertexState.vertexBufferCount = 0;
+ vertexState.vertexBuffers = nullptr;
+ descriptor.vertexState = &vertexState;
WGPURasterizationStateDescriptor rasterizationState;
rasterizationState.nextInChain = nullptr;
diff --git a/examples/ComputeBoids.cpp b/examples/ComputeBoids.cpp
index 2c85a0f..185fe0c 100644
--- a/examples/ComputeBoids.cpp
+++ b/examples/ComputeBoids.cpp
@@ -125,20 +125,20 @@
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
- descriptor.cVertexInput.bufferCount = 2;
- descriptor.cVertexInput.cBuffers[0].stride = sizeof(Particle);
- descriptor.cVertexInput.cBuffers[0].stepMode = wgpu::InputStepMode::Instance;
- descriptor.cVertexInput.cBuffers[0].attributeCount = 2;
- descriptor.cVertexInput.cAttributes[0].offset = offsetof(Particle, pos);
- descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float2;
- descriptor.cVertexInput.cAttributes[1].shaderLocation = 1;
- descriptor.cVertexInput.cAttributes[1].offset = offsetof(Particle, vel);
- descriptor.cVertexInput.cAttributes[1].format = wgpu::VertexFormat::Float2;
- descriptor.cVertexInput.cBuffers[1].stride = sizeof(glm::vec2);
- descriptor.cVertexInput.cBuffers[1].attributeCount = 1;
- descriptor.cVertexInput.cBuffers[1].attributes = &descriptor.cVertexInput.cAttributes[2];
- descriptor.cVertexInput.cAttributes[2].shaderLocation = 2;
- descriptor.cVertexInput.cAttributes[2].format = wgpu::VertexFormat::Float2;
+ descriptor.cVertexState.vertexBufferCount = 2;
+ descriptor.cVertexState.cVertexBuffers[0].arrayStride = sizeof(Particle);
+ descriptor.cVertexState.cVertexBuffers[0].stepMode = wgpu::InputStepMode::Instance;
+ descriptor.cVertexState.cVertexBuffers[0].attributeCount = 2;
+ descriptor.cVertexState.cAttributes[0].offset = offsetof(Particle, pos);
+ descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float2;
+ descriptor.cVertexState.cAttributes[1].shaderLocation = 1;
+ descriptor.cVertexState.cAttributes[1].offset = offsetof(Particle, vel);
+ descriptor.cVertexState.cAttributes[1].format = wgpu::VertexFormat::Float2;
+ descriptor.cVertexState.cVertexBuffers[1].arrayStride = sizeof(glm::vec2);
+ descriptor.cVertexState.cVertexBuffers[1].attributeCount = 1;
+ descriptor.cVertexState.cVertexBuffers[1].attributes = &descriptor.cVertexState.cAttributes[2];
+ descriptor.cVertexState.cAttributes[2].shaderLocation = 2;
+ descriptor.cVertexState.cAttributes[2].format = wgpu::VertexFormat::Float2;
descriptor.depthStencilState = &descriptor.cDepthStencilState;
descriptor.cDepthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
descriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
diff --git a/examples/CppHelloTriangle.cpp b/examples/CppHelloTriangle.cpp
index 4a8ecff..0568278 100644
--- a/examples/CppHelloTriangle.cpp
+++ b/examples/CppHelloTriangle.cpp
@@ -129,10 +129,10 @@
descriptor.layout = utils::MakeBasicPipelineLayout(device, &bgl);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
- descriptor.cVertexInput.bufferCount = 1;
- descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
- descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
- descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
+ descriptor.cVertexState.vertexBufferCount = 1;
+ descriptor.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
+ descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
+ descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.depthStencilState = &descriptor.cDepthStencilState;
descriptor.cDepthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
descriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
diff --git a/examples/CubeReflection.cpp b/examples/CubeReflection.cpp
index 8875c27..2531af77 100644
--- a/examples/CubeReflection.cpp
+++ b/examples/CubeReflection.cpp
@@ -160,15 +160,15 @@
fragColor = vec4(mix(f_col, vec3(0.5, 0.5, 0.5), 0.5), 1.0);
})");
- utils::ComboVertexInputDescriptor vertexInput;
- vertexInput.cBuffers[0].attributeCount = 2;
- vertexInput.cAttributes[0].format = wgpu::VertexFormat::Float3;
- vertexInput.cAttributes[1].shaderLocation = 1;
- vertexInput.cAttributes[1].offset = 3 * sizeof(float);
- vertexInput.cAttributes[1].format = wgpu::VertexFormat::Float3;
+ utils::ComboVertexStateDescriptor vertexState;
+ vertexState.cVertexBuffers[0].attributeCount = 2;
+ vertexState.cAttributes[0].format = wgpu::VertexFormat::Float3;
+ vertexState.cAttributes[1].shaderLocation = 1;
+ vertexState.cAttributes[1].offset = 3 * sizeof(float);
+ vertexState.cAttributes[1].format = wgpu::VertexFormat::Float3;
- vertexInput.bufferCount = 1;
- vertexInput.cBuffers[0].stride = 6 * sizeof(float);
+ vertexState.vertexBufferCount = 1;
+ vertexState.cVertexBuffers[0].arrayStride = 6 * sizeof(float);
auto bgl = utils::MakeBindGroupLayout(
device, {
@@ -207,7 +207,7 @@
descriptor.layout = pl;
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
- descriptor.vertexInput = &vertexInput;
+ descriptor.vertexState = &vertexState;
descriptor.depthStencilState = &descriptor.cDepthStencilState;
descriptor.cDepthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
descriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
@@ -220,7 +220,7 @@
pDescriptor.layout = pl;
pDescriptor.vertexStage.module = vsModule;
pDescriptor.cFragmentStage.module = fsModule;
- pDescriptor.vertexInput = &vertexInput;
+ pDescriptor.vertexState = &vertexState;
pDescriptor.depthStencilState = &pDescriptor.cDepthStencilState;
pDescriptor.cDepthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
pDescriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
@@ -234,7 +234,7 @@
rfDescriptor.layout = pl;
rfDescriptor.vertexStage.module = vsModule;
rfDescriptor.cFragmentStage.module = fsReflectionModule;
- rfDescriptor.vertexInput = &vertexInput;
+ rfDescriptor.vertexState = &vertexState;
rfDescriptor.depthStencilState = &rfDescriptor.cDepthStencilState;
rfDescriptor.cDepthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
rfDescriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
diff --git a/src/dawn_native/CommandBufferStateTracker.cpp b/src/dawn_native/CommandBufferStateTracker.cpp
index 943b67b..d6ef68b 100644
--- a/src/dawn_native/CommandBufferStateTracker.cpp
+++ b/src/dawn_native/CommandBufferStateTracker.cpp
@@ -106,8 +106,9 @@
if (aspects[VALIDATION_ASPECT_VERTEX_BUFFERS]) {
ASSERT(mLastRenderPipeline != nullptr);
- auto requiredInputs = mLastRenderPipeline->GetInputsSetMask();
- if ((mInputsSet & requiredInputs) == requiredInputs) {
+ const std::bitset<kMaxVertexBuffers>& requiredVertexBuffers =
+ mLastRenderPipeline->GetVertexBufferSlotsUsed();
+ if ((mVertexBufferSlotsUsed & requiredVertexBuffers) == requiredVertexBuffers) {
mAspects.set(VALIDATION_ASPECT_VERTEX_BUFFERS);
}
}
@@ -153,7 +154,7 @@
}
void CommandBufferStateTracker::SetVertexBuffer(uint32_t slot) {
- mInputsSet.set(slot);
+ mVertexBufferSlotsUsed.set(slot);
}
void CommandBufferStateTracker::SetPipelineCommon(PipelineBase* pipeline) {
diff --git a/src/dawn_native/CommandBufferStateTracker.h b/src/dawn_native/CommandBufferStateTracker.h
index 5be9dca..50e5107 100644
--- a/src/dawn_native/CommandBufferStateTracker.h
+++ b/src/dawn_native/CommandBufferStateTracker.h
@@ -53,7 +53,7 @@
ValidationAspects mAspects;
std::array<BindGroupBase*, kMaxBindGroups> mBindgroups = {};
- std::bitset<kMaxVertexBuffers> mInputsSet;
+ std::bitset<kMaxVertexBuffers> mVertexBufferSlotsUsed;
PipelineLayoutBase* mLastPipelineLayout = nullptr;
RenderPipelineBase* mLastRenderPipeline = nullptr;
diff --git a/src/dawn_native/RenderPipeline.cpp b/src/dawn_native/RenderPipeline.cpp
index 54c5a72..160b3d2 100644
--- a/src/dawn_native/RenderPipeline.cpp
+++ b/src/dawn_native/RenderPipeline.cpp
@@ -61,44 +61,44 @@
return {};
}
- MaybeError ValidateVertexBufferDescriptor(
- const VertexBufferDescriptor* buffer,
+ MaybeError ValidateVertexBufferLayoutDescriptor(
+ const VertexBufferLayoutDescriptor* buffer,
std::bitset<kMaxVertexAttributes>* attributesSetMask) {
DAWN_TRY(ValidateInputStepMode(buffer->stepMode));
- if (buffer->stride > kMaxVertexBufferStride) {
- return DAWN_VALIDATION_ERROR("Setting input stride out of bounds");
+ if (buffer->arrayStride > kMaxVertexBufferStride) {
+ return DAWN_VALIDATION_ERROR("Setting arrayStride out of bounds");
}
- if (buffer->stride % 4 != 0) {
+ if (buffer->arrayStride % 4 != 0) {
return DAWN_VALIDATION_ERROR(
- "Stride of Vertex buffer needs to be a multiple of 4 bytes");
+ "arrayStride of Vertex buffer needs to be a multiple of 4 bytes");
}
for (uint32_t i = 0; i < buffer->attributeCount; ++i) {
- DAWN_TRY(ValidateVertexAttributeDescriptor(&buffer->attributes[i], buffer->stride,
- attributesSetMask));
+ DAWN_TRY(ValidateVertexAttributeDescriptor(&buffer->attributes[i],
+ buffer->arrayStride, attributesSetMask));
}
return {};
}
- MaybeError ValidateVertexInputDescriptor(
- const VertexInputDescriptor* descriptor,
+ MaybeError ValidateVertexStateDescriptor(
+ const VertexStateDescriptor* descriptor,
std::bitset<kMaxVertexAttributes>* attributesSetMask) {
if (descriptor->nextInChain != nullptr) {
return DAWN_VALIDATION_ERROR("nextInChain must be nullptr");
}
DAWN_TRY(ValidateIndexFormat(descriptor->indexFormat));
- if (descriptor->bufferCount > kMaxVertexBuffers) {
- return DAWN_VALIDATION_ERROR("Vertex Inputs number exceeds maximum");
+ if (descriptor->vertexBufferCount > kMaxVertexBuffers) {
+ return DAWN_VALIDATION_ERROR("Vertex buffer count exceeds maximum");
}
uint32_t totalAttributesNum = 0;
- for (uint32_t i = 0; i < descriptor->bufferCount; ++i) {
- DAWN_TRY(
- ValidateVertexBufferDescriptor(&descriptor->buffers[i], attributesSetMask));
- totalAttributesNum += descriptor->buffers[i].attributeCount;
+ for (uint32_t i = 0; i < descriptor->vertexBufferCount; ++i) {
+ DAWN_TRY(ValidateVertexBufferLayoutDescriptor(&descriptor->vertexBuffers[i],
+ attributesSetMask));
+ totalAttributesNum += descriptor->vertexBuffers[i].attributeCount;
}
// Every vertex attribute has a member called shaderLocation, and there are some
@@ -288,8 +288,8 @@
}
std::bitset<kMaxVertexAttributes> attributesSetMask;
- if (descriptor->vertexInput) {
- DAWN_TRY(ValidateVertexInputDescriptor(descriptor->vertexInput, &attributesSetMask));
+ if (descriptor->vertexState) {
+ DAWN_TRY(ValidateVertexStateDescriptor(descriptor->vertexState, &attributesSetMask));
}
DAWN_TRY(ValidatePrimitiveTopology(descriptor->primitiveTopology));
@@ -305,7 +305,7 @@
if ((descriptor->vertexStage.module->GetUsedVertexAttributes() & ~attributesSetMask)
.any()) {
return DAWN_VALIDATION_ERROR(
- "Pipeline vertex stage uses inputs not in the input state");
+ "Pipeline vertex stage uses vertex buffers not in the vertex state");
}
if (!IsValidSampleCount(descriptor->sampleCount)) {
@@ -378,29 +378,31 @@
mVertexEntryPoint(descriptor->vertexStage.entryPoint),
mFragmentModule(descriptor->fragmentStage->module),
mFragmentEntryPoint(descriptor->fragmentStage->entryPoint) {
- if (descriptor->vertexInput != nullptr) {
- mVertexInput = *descriptor->vertexInput;
+ if (descriptor->vertexState != nullptr) {
+ mVertexState = *descriptor->vertexState;
} else {
- mVertexInput = VertexInputDescriptor();
+ mVertexState = VertexStateDescriptor();
}
- for (uint32_t slot = 0; slot < mVertexInput.bufferCount; ++slot) {
- if (mVertexInput.buffers[slot].attributeCount == 0) {
+ for (uint32_t slot = 0; slot < mVertexState.vertexBufferCount; ++slot) {
+ if (mVertexState.vertexBuffers[slot].attributeCount == 0) {
continue;
}
- mInputsSetMask.set(slot);
- mInputInfos[slot].stride = mVertexInput.buffers[slot].stride;
- mInputInfos[slot].stepMode = mVertexInput.buffers[slot].stepMode;
+ mVertexBufferSlotsUsed.set(slot);
+ mVertexBufferInfos[slot].arrayStride = mVertexState.vertexBuffers[slot].arrayStride;
+ mVertexBufferInfos[slot].stepMode = mVertexState.vertexBuffers[slot].stepMode;
uint32_t location = 0;
- for (uint32_t i = 0; i < mVertexInput.buffers[slot].attributeCount; ++i) {
- location = mVertexInput.buffers[slot].attributes[i].shaderLocation;
- mAttributesSetMask.set(location);
+ for (uint32_t i = 0; i < mVertexState.vertexBuffers[slot].attributeCount; ++i) {
+ location = mVertexState.vertexBuffers[slot].attributes[i].shaderLocation;
+ mAttributeLocationsUsed.set(location);
mAttributeInfos[location].shaderLocation = location;
- mAttributeInfos[location].inputSlot = slot;
- mAttributeInfos[location].offset = mVertexInput.buffers[slot].attributes[i].offset;
- mAttributeInfos[location].format = mVertexInput.buffers[slot].attributes[i].format;
+ mAttributeInfos[location].vertexBufferSlot = slot;
+ mAttributeInfos[location].offset =
+ mVertexState.vertexBuffers[slot].attributes[i].offset;
+ mAttributeInfos[location].format =
+ mVertexState.vertexBuffers[slot].attributes[i].format;
}
}
@@ -454,31 +456,31 @@
}
}
- const VertexInputDescriptor* RenderPipelineBase::GetVertexInputDescriptor() const {
+ const VertexStateDescriptor* RenderPipelineBase::GetVertexStateDescriptor() const {
ASSERT(!IsError());
- return &mVertexInput;
+ return &mVertexState;
}
- const std::bitset<kMaxVertexAttributes>& RenderPipelineBase::GetAttributesSetMask() const {
+ const std::bitset<kMaxVertexAttributes>& RenderPipelineBase::GetAttributeLocationsUsed() const {
ASSERT(!IsError());
- return mAttributesSetMask;
+ return mAttributeLocationsUsed;
}
const VertexAttributeInfo& RenderPipelineBase::GetAttribute(uint32_t location) const {
ASSERT(!IsError());
- ASSERT(mAttributesSetMask[location]);
+ ASSERT(mAttributeLocationsUsed[location]);
return mAttributeInfos[location];
}
- const std::bitset<kMaxVertexBuffers>& RenderPipelineBase::GetInputsSetMask() const {
+ const std::bitset<kMaxVertexBuffers>& RenderPipelineBase::GetVertexBufferSlotsUsed() const {
ASSERT(!IsError());
- return mInputsSetMask;
+ return mVertexBufferSlotsUsed;
}
- const VertexBufferInfo& RenderPipelineBase::GetInput(uint32_t slot) const {
+ const VertexBufferInfo& RenderPipelineBase::GetVertexBuffer(uint32_t slot) const {
ASSERT(!IsError());
- ASSERT(mInputsSetMask[slot]);
- return mInputInfos[slot];
+ ASSERT(mVertexBufferSlotsUsed[slot]);
+ return mVertexBufferInfos[slot];
}
const ColorStateDescriptor* RenderPipelineBase::GetColorStateDescriptor(
@@ -540,10 +542,10 @@
return mAttachmentState.Get();
}
- std::bitset<kMaxVertexAttributes> RenderPipelineBase::GetAttributesUsingInput(
+ std::bitset<kMaxVertexAttributes> RenderPipelineBase::GetAttributesUsingVertexBuffer(
uint32_t slot) const {
ASSERT(!IsError());
- return attributesUsingInput[slot];
+ return attributesUsingVertexBuffer[slot];
}
size_t RenderPipelineBase::HashFunc::operator()(const RenderPipelineBase* pipeline) const {
@@ -578,20 +580,21 @@
desc.stencilBack.depthFailOp, desc.stencilBack.passOp);
}
- // Hash vertex input state
- HashCombine(&hash, pipeline->mAttributesSetMask);
- for (uint32_t i : IterateBitSet(pipeline->mAttributesSetMask)) {
+ // Hash vertex state
+ HashCombine(&hash, pipeline->mAttributeLocationsUsed);
+ for (uint32_t i : IterateBitSet(pipeline->mAttributeLocationsUsed)) {
const VertexAttributeInfo& desc = pipeline->GetAttribute(i);
- HashCombine(&hash, desc.shaderLocation, desc.inputSlot, desc.offset, desc.format);
+ HashCombine(&hash, desc.shaderLocation, desc.vertexBufferSlot, desc.offset,
+ desc.format);
}
- HashCombine(&hash, pipeline->mInputsSetMask);
- for (uint32_t i : IterateBitSet(pipeline->mInputsSetMask)) {
- const VertexBufferInfo& desc = pipeline->GetInput(i);
- HashCombine(&hash, desc.stride, desc.stepMode);
+ HashCombine(&hash, pipeline->mVertexBufferSlotsUsed);
+ for (uint32_t i : IterateBitSet(pipeline->mVertexBufferSlotsUsed)) {
+ const VertexBufferInfo& desc = pipeline->GetVertexBuffer(i);
+ HashCombine(&hash, desc.arrayStride, desc.stepMode);
}
- HashCombine(&hash, pipeline->mVertexInput.indexFormat);
+ HashCombine(&hash, pipeline->mVertexState.indexFormat);
// Hash rasterization state
{
@@ -666,34 +669,34 @@
}
}
- // Check vertex input state
- if (a->mAttributesSetMask != b->mAttributesSetMask) {
+ // Check vertex state
+ if (a->mAttributeLocationsUsed != b->mAttributeLocationsUsed) {
return false;
}
- for (uint32_t i : IterateBitSet(a->mAttributesSetMask)) {
+ for (uint32_t i : IterateBitSet(a->mAttributeLocationsUsed)) {
const VertexAttributeInfo& descA = a->GetAttribute(i);
const VertexAttributeInfo& descB = b->GetAttribute(i);
if (descA.shaderLocation != descB.shaderLocation ||
- descA.inputSlot != descB.inputSlot || descA.offset != descB.offset ||
+ descA.vertexBufferSlot != descB.vertexBufferSlot || descA.offset != descB.offset ||
descA.format != descB.format) {
return false;
}
}
- if (a->mInputsSetMask != b->mInputsSetMask) {
+ if (a->mVertexBufferSlotsUsed != b->mVertexBufferSlotsUsed) {
return false;
}
- for (uint32_t i : IterateBitSet(a->mInputsSetMask)) {
- const VertexBufferInfo& descA = a->GetInput(i);
- const VertexBufferInfo& descB = b->GetInput(i);
- if (descA.stride != descB.stride || descA.stepMode != descB.stepMode) {
+ for (uint32_t i : IterateBitSet(a->mVertexBufferSlotsUsed)) {
+ const VertexBufferInfo& descA = a->GetVertexBuffer(i);
+ const VertexBufferInfo& descB = b->GetVertexBuffer(i);
+ if (descA.arrayStride != descB.arrayStride || descA.stepMode != descB.stepMode) {
return false;
}
}
- if (a->mVertexInput.indexFormat != b->mVertexInput.indexFormat) {
+ if (a->mVertexState.indexFormat != b->mVertexState.indexFormat) {
return false;
}
diff --git a/src/dawn_native/RenderPipeline.h b/src/dawn_native/RenderPipeline.h
index 7cf2861..6f3f56a 100644
--- a/src/dawn_native/RenderPipeline.h
+++ b/src/dawn_native/RenderPipeline.h
@@ -41,14 +41,14 @@
bool BlendEnabled(const ColorStateDescriptor* mColorState);
struct VertexAttributeInfo {
- uint32_t shaderLocation;
- uint32_t inputSlot;
- uint64_t offset;
wgpu::VertexFormat format;
+ uint64_t offset;
+ uint32_t shaderLocation;
+ uint32_t vertexBufferSlot;
};
struct VertexBufferInfo {
- uint64_t stride;
+ uint64_t arrayStride;
wgpu::InputStepMode stepMode;
};
@@ -59,11 +59,11 @@
static RenderPipelineBase* MakeError(DeviceBase* device);
- const VertexInputDescriptor* GetVertexInputDescriptor() const;
- const std::bitset<kMaxVertexAttributes>& GetAttributesSetMask() const;
+ const VertexStateDescriptor* GetVertexStateDescriptor() const;
+ const std::bitset<kMaxVertexAttributes>& GetAttributeLocationsUsed() const;
const VertexAttributeInfo& GetAttribute(uint32_t location) const;
- const std::bitset<kMaxVertexBuffers>& GetInputsSetMask() const;
- const VertexBufferInfo& GetInput(uint32_t slot) const;
+ const std::bitset<kMaxVertexBuffers>& GetVertexBufferSlotsUsed() const;
+ const VertexBufferInfo& GetVertexBuffer(uint32_t slot) const;
const ColorStateDescriptor* GetColorStateDescriptor(uint32_t attachmentSlot) const;
const DepthStencilStateDescriptor* GetDepthStencilStateDescriptor() const;
@@ -79,8 +79,9 @@
const AttachmentState* GetAttachmentState() const;
- std::bitset<kMaxVertexAttributes> GetAttributesUsingInput(uint32_t slot) const;
- std::array<std::bitset<kMaxVertexAttributes>, kMaxVertexBuffers> attributesUsingInput;
+ std::bitset<kMaxVertexAttributes> GetAttributesUsingVertexBuffer(uint32_t slot) const;
+ std::array<std::bitset<kMaxVertexAttributes>, kMaxVertexBuffers>
+ attributesUsingVertexBuffer;
// Functors necessary for the unordered_set<RenderPipelineBase*>-based cache.
struct HashFunc {
@@ -93,12 +94,12 @@
private:
RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag);
- // Vertex input
- VertexInputDescriptor mVertexInput;
- std::bitset<kMaxVertexAttributes> mAttributesSetMask;
+ // Vertex state
+ VertexStateDescriptor mVertexState;
+ std::bitset<kMaxVertexAttributes> mAttributeLocationsUsed;
std::array<VertexAttributeInfo, kMaxVertexAttributes> mAttributeInfos;
- std::bitset<kMaxVertexBuffers> mInputsSetMask;
- std::array<VertexBufferInfo, kMaxVertexBuffers> mInputInfos;
+ std::bitset<kMaxVertexBuffers> mVertexBufferSlotsUsed;
+ std::array<VertexBufferInfo, kMaxVertexBuffers> mVertexBufferInfos;
// Attachments
Ref<AttachmentState> mAttachmentState;
diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp
index 431b4c2..61ff14a 100644
--- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp
+++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp
@@ -397,29 +397,30 @@
auto* d3d12BufferView = &mD3D12BufferViews[slot];
d3d12BufferView->BufferLocation = buffer->GetVA() + offset;
d3d12BufferView->SizeInBytes = buffer->GetSize() - offset;
- // The bufferView stride is set based on the input state before a draw.
+ // The bufferView stride is set based on the vertex state before a draw.
}
void Apply(ID3D12GraphicsCommandList* commandList,
const RenderPipeline* renderPipeline) {
ASSERT(renderPipeline != nullptr);
- std::bitset<kMaxVertexBuffers> inputsMask = renderPipeline->GetInputsSetMask();
+ std::bitset<kMaxVertexBuffers> vertexBufferSlotsUsed =
+ renderPipeline->GetVertexBufferSlotsUsed();
uint32_t startSlot = mStartSlot;
uint32_t endSlot = mEndSlot;
- // If the input state has changed, we need to update the StrideInBytes
+ // If the vertex state has changed, we need to update the StrideInBytes
// for the D3D12 buffer views. We also need to extend the dirty range to
// touch all these slots because the stride may have changed.
if (mLastAppliedRenderPipeline != renderPipeline) {
mLastAppliedRenderPipeline = renderPipeline;
- for (uint32_t slot : IterateBitSet(inputsMask)) {
+ for (uint32_t slot : IterateBitSet(vertexBufferSlotsUsed)) {
startSlot = std::min(startSlot, slot);
endSlot = std::max(endSlot, slot + 1);
mD3D12BufferViews[slot].StrideInBytes =
- renderPipeline->GetInput(slot).stride;
+ renderPipeline->GetVertexBuffer(slot).arrayStride;
}
}
@@ -462,7 +463,7 @@
void OnSetPipeline(const RenderPipelineBase* pipeline) {
mD3D12BufferView.Format =
- DXGIIndexFormat(pipeline->GetVertexInputDescriptor()->indexFormat);
+ DXGIIndexFormat(pipeline->GetVertexStateDescriptor()->indexFormat);
}
void Apply(ID3D12GraphicsCommandList* commandList) {
diff --git a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp
index f8d90a7..1025c27 100644
--- a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp
+++ b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp
@@ -359,7 +359,7 @@
// D3D12 logs warnings if any empty input state is used
std::array<D3D12_INPUT_ELEMENT_DESC, kMaxVertexAttributes> inputElementDescriptors;
- if (GetAttributesSetMask().any()) {
+ if (GetAttributeLocationsUsed().any()) {
descriptorD3D12.InputLayout = ComputeInputLayout(&inputElementDescriptors);
}
@@ -423,7 +423,7 @@
D3D12_INPUT_LAYOUT_DESC RenderPipeline::ComputeInputLayout(
std::array<D3D12_INPUT_ELEMENT_DESC, kMaxVertexAttributes>* inputElementDescriptors) {
unsigned int count = 0;
- for (auto i : IterateBitSet(GetAttributesSetMask())) {
+ for (auto i : IterateBitSet(GetAttributeLocationsUsed())) {
D3D12_INPUT_ELEMENT_DESC& inputElementDescriptor = (*inputElementDescriptors)[count++];
const VertexAttributeInfo& attribute = GetAttribute(i);
@@ -433,9 +433,9 @@
inputElementDescriptor.SemanticName = "TEXCOORD";
inputElementDescriptor.SemanticIndex = static_cast<uint32_t>(i);
inputElementDescriptor.Format = VertexFormatType(attribute.format);
- inputElementDescriptor.InputSlot = attribute.inputSlot;
+ inputElementDescriptor.InputSlot = attribute.vertexBufferSlot;
- const VertexBufferInfo& input = GetInput(attribute.inputSlot);
+ const VertexBufferInfo& input = GetVertexBuffer(attribute.vertexBufferSlot);
inputElementDescriptor.AlignedByteOffset = attribute.offset;
inputElementDescriptor.InputSlotClass = InputStepModeFunction(input.stepMode);
diff --git a/src/dawn_native/metal/CommandBufferMTL.mm b/src/dawn_native/metal/CommandBufferMTL.mm
index ebb22a3..91e29df 100644
--- a/src/dawn_native/metal/CommandBufferMTL.mm
+++ b/src/dawn_native/metal/CommandBufferMTL.mm
@@ -549,7 +549,7 @@
// Keeps track of the dirty vertex buffer values so they can be lazily applied when we know
// all the relevant state.
- class VertexInputBufferTracker {
+ class VertexBufferTracker {
public:
void OnSetVertexBuffer(uint32_t slot, Buffer* buffer, uint64_t offset) {
mVertexBuffers[slot] = buffer->GetMTLBuffer();
@@ -564,12 +564,12 @@
// When a new pipeline is bound we must set all the vertex buffers again because
// they might have been offset by the pipeline layout, and they might be packed
// differently from the previous pipeline.
- mDirtyVertexBuffers |= pipeline->GetInputsSetMask();
+ mDirtyVertexBuffers |= pipeline->GetVertexBufferSlotsUsed();
}
void Apply(id<MTLRenderCommandEncoder> encoder, RenderPipeline* pipeline) {
std::bitset<kMaxVertexBuffers> vertexBuffersToApply =
- mDirtyVertexBuffers & pipeline->GetInputsSetMask();
+ mDirtyVertexBuffers & pipeline->GetVertexBufferSlotsUsed();
for (uint32_t dawnIndex : IterateBitSet(vertexBuffersToApply)) {
uint32_t metalIndex = pipeline->GetMtlVertexBufferIndex(dawnIndex);
@@ -904,7 +904,7 @@
RenderPipeline* lastPipeline = nullptr;
id<MTLBuffer> indexBuffer = nil;
uint32_t indexBufferBaseOffset = 0;
- VertexInputBufferTracker vertexInputBuffers;
+ VertexBufferTracker vertexBuffers;
StorageBufferLengthTracker storageBufferLengths = {};
BindGroupTracker bindGroups(&storageBufferLengths);
@@ -917,7 +917,7 @@
case Command::Draw: {
DrawCmd* draw = iter->NextCommand<DrawCmd>();
- vertexInputBuffers.Apply(encoder, lastPipeline);
+ vertexBuffers.Apply(encoder, lastPipeline);
bindGroups.Apply(encoder);
storageBufferLengths.Apply(encoder, lastPipeline);
@@ -934,9 +934,9 @@
case Command::DrawIndexed: {
DrawIndexedCmd* draw = iter->NextCommand<DrawIndexedCmd>();
size_t formatSize =
- IndexFormatSize(lastPipeline->GetVertexInputDescriptor()->indexFormat);
+ IndexFormatSize(lastPipeline->GetVertexStateDescriptor()->indexFormat);
- vertexInputBuffers.Apply(encoder, lastPipeline);
+ vertexBuffers.Apply(encoder, lastPipeline);
bindGroups.Apply(encoder);
storageBufferLengths.Apply(encoder, lastPipeline);
@@ -957,7 +957,7 @@
case Command::DrawIndirect: {
DrawIndirectCmd* draw = iter->NextCommand<DrawIndirectCmd>();
- vertexInputBuffers.Apply(encoder, lastPipeline);
+ vertexBuffers.Apply(encoder, lastPipeline);
bindGroups.Apply(encoder);
storageBufferLengths.Apply(encoder, lastPipeline);
@@ -971,7 +971,7 @@
case Command::DrawIndexedIndirect: {
DrawIndirectCmd* draw = iter->NextCommand<DrawIndirectCmd>();
- vertexInputBuffers.Apply(encoder, lastPipeline);
+ vertexBuffers.Apply(encoder, lastPipeline);
bindGroups.Apply(encoder);
storageBufferLengths.Apply(encoder, lastPipeline);
@@ -1013,7 +1013,7 @@
SetRenderPipelineCmd* cmd = iter->NextCommand<SetRenderPipelineCmd>();
RenderPipeline* newPipeline = ToBackend(cmd->pipeline).Get();
- vertexInputBuffers.OnSetPipeline(lastPipeline, newPipeline);
+ vertexBuffers.OnSetPipeline(lastPipeline, newPipeline);
bindGroups.OnSetPipeline(newPipeline);
[encoder setDepthStencilState:newPipeline->GetMTLDepthStencilState()];
@@ -1045,8 +1045,8 @@
case Command::SetVertexBuffer: {
SetVertexBufferCmd* cmd = iter->NextCommand<SetVertexBufferCmd>();
- vertexInputBuffers.OnSetVertexBuffer(cmd->slot, ToBackend(cmd->buffer.Get()),
- cmd->offset);
+ vertexBuffers.OnSetVertexBuffer(cmd->slot, ToBackend(cmd->buffer.Get()),
+ cmd->offset);
} break;
default:
diff --git a/src/dawn_native/metal/RenderPipelineMTL.mm b/src/dawn_native/metal/RenderPipelineMTL.mm
index de85f4c..3c4d852 100644
--- a/src/dawn_native/metal/RenderPipelineMTL.mm
+++ b/src/dawn_native/metal/RenderPipelineMTL.mm
@@ -313,7 +313,7 @@
RenderPipeline::RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor)
: RenderPipelineBase(device, descriptor),
- mMtlIndexType(MTLIndexFormat(GetVertexInputDescriptor()->indexFormat)),
+ mMtlIndexType(MTLIndexFormat(GetVertexStateDescriptor()->indexFormat)),
mMtlPrimitiveTopology(MTLPrimitiveTopology(GetPrimitiveTopology())),
mMtlFrontFace(MTLFrontFace(GetFrontFace())),
mMtlCullMode(ToMTLCullMode(GetCullMode())) {
@@ -432,49 +432,49 @@
uint32_t mtlVertexBufferIndex =
ToBackend(GetLayout())->GetBufferBindingCount(SingleShaderStage::Vertex);
- for (uint32_t dawnVertexBufferIndex : IterateBitSet(GetInputsSetMask())) {
- const VertexBufferInfo& info = GetInput(dawnVertexBufferIndex);
+ for (uint32_t dawnVertexBufferSlot : IterateBitSet(GetVertexBufferSlotsUsed())) {
+ const VertexBufferInfo& info = GetVertexBuffer(dawnVertexBufferSlot);
MTLVertexBufferLayoutDescriptor* layoutDesc = [MTLVertexBufferLayoutDescriptor new];
- if (info.stride == 0) {
+ if (info.arrayStride == 0) {
// For MTLVertexStepFunctionConstant, the stepRate must be 0,
- // but the stride must NOT be 0, so we made up it with
+ // but the arrayStride must NOT be 0, so we made up it with
// max(attrib.offset + sizeof(attrib) for each attrib)
- size_t max_stride = 0;
- for (uint32_t attribIndex : IterateBitSet(GetAttributesSetMask())) {
+ size_t maxArrayStride = 0;
+ for (uint32_t attribIndex : IterateBitSet(GetAttributeLocationsUsed())) {
const VertexAttributeInfo& attrib = GetAttribute(attribIndex);
// Only use the attributes that use the current input
- if (attrib.inputSlot != dawnVertexBufferIndex) {
+ if (attrib.vertexBufferSlot != dawnVertexBufferSlot) {
continue;
}
- max_stride = std::max(max_stride,
- VertexFormatSize(attrib.format) + size_t(attrib.offset));
+ maxArrayStride = std::max(
+ maxArrayStride, VertexFormatSize(attrib.format) + size_t(attrib.offset));
}
layoutDesc.stepFunction = MTLVertexStepFunctionConstant;
layoutDesc.stepRate = 0;
// Metal requires the stride must be a multiple of 4 bytes, align it with next
// multiple of 4 if it's not.
- layoutDesc.stride = Align(max_stride, 4);
+ layoutDesc.stride = Align(maxArrayStride, 4);
} else {
layoutDesc.stepFunction = InputStepModeFunction(info.stepMode);
layoutDesc.stepRate = 1;
- layoutDesc.stride = info.stride;
+ layoutDesc.stride = info.arrayStride;
}
mtlVertexDescriptor.layouts[mtlVertexBufferIndex] = layoutDesc;
[layoutDesc release];
- mMtlVertexBufferIndices[dawnVertexBufferIndex] = mtlVertexBufferIndex;
+ mMtlVertexBufferIndices[dawnVertexBufferSlot] = mtlVertexBufferIndex;
mtlVertexBufferIndex++;
}
- for (uint32_t i : IterateBitSet(GetAttributesSetMask())) {
+ for (uint32_t i : IterateBitSet(GetAttributeLocationsUsed())) {
const VertexAttributeInfo& info = GetAttribute(i);
auto attribDesc = [MTLVertexAttributeDescriptor new];
attribDesc.format = VertexFormatType(info.format);
attribDesc.offset = info.offset;
- attribDesc.bufferIndex = mMtlVertexBufferIndices[info.inputSlot];
+ attribDesc.bufferIndex = mMtlVertexBufferIndices[info.vertexBufferSlot];
mtlVertexDescriptor.attributes[i] = attribDesc;
[attribDesc release];
}
diff --git a/src/dawn_native/opengl/CommandBufferGL.cpp b/src/dawn_native/opengl/CommandBufferGL.cpp
index f006346..48e3605 100644
--- a/src/dawn_native/opengl/CommandBufferGL.cpp
+++ b/src/dawn_native/opengl/CommandBufferGL.cpp
@@ -133,9 +133,9 @@
}
// 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 @@
}
mIndexBufferDirty = true;
- mDirtyVertexBuffers |= pipeline->GetInputsSetMask();
+ mDirtyVertexBuffers |= pipeline->GetVertexBufferSlotsUsed();
mLastPipeline = pipeline;
}
@@ -168,30 +168,32 @@
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 @@
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 @@
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 @@
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 @@
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 @@
lastPipeline = ToBackend(cmd->pipeline).Get();
lastPipeline->ApplyNow(persistentPipelineState);
- inputBuffers.OnSetPipeline(lastPipeline);
+ vertexStateBufferBindingTracker.OnSetPipeline(lastPipeline);
bindGroupTracker.OnSetPipeline(lastPipeline);
} break;
@@ -965,12 +967,13 @@
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:
diff --git a/src/dawn_native/opengl/RenderPipelineGL.cpp b/src/dawn_native/opengl/RenderPipelineGL.cpp
index b7e7448..b16783c 100644
--- a/src/dawn_native/opengl/RenderPipelineGL.cpp
+++ b/src/dawn_native/opengl/RenderPipelineGL.cpp
@@ -202,7 +202,7 @@
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 @@
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:
diff --git a/src/dawn_native/opengl/RenderPipelineGL.h b/src/dawn_native/opengl/RenderPipelineGL.h
index b0dc2e8..b8bcb26 100644
--- a/src/dawn_native/opengl/RenderPipelineGL.h
+++ b/src/dawn_native/opengl/RenderPipelineGL.h
@@ -37,7 +37,7 @@
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;
diff --git a/src/dawn_native/vulkan/CommandBufferVk.cpp b/src/dawn_native/vulkan/CommandBufferVk.cpp
index 4e70266..f8bcaf1 100644
--- a/src/dawn_native/vulkan/CommandBufferVk.cpp
+++ b/src/dawn_native/vulkan/CommandBufferVk.cpp
@@ -867,7 +867,7 @@
// and rebind if needed on pipeline change
ASSERT(lastPipeline != nullptr);
VkIndexType indexType =
- VulkanIndexType(lastPipeline->GetVertexInputDescriptor()->indexFormat);
+ VulkanIndexType(lastPipeline->GetVertexStateDescriptor()->indexFormat);
device->fn.CmdBindIndexBuffer(
commands, indexBuffer, static_cast<VkDeviceSize>(cmd->offset), indexType);
} break;
diff --git a/src/dawn_native/vulkan/RenderPipelineVk.cpp b/src/dawn_native/vulkan/RenderPipelineVk.cpp
index 9a32628..4b770a5 100644
--- a/src/dawn_native/vulkan/RenderPipelineVk.cpp
+++ b/src/dawn_native/vulkan/RenderPipelineVk.cpp
@@ -351,11 +351,9 @@
shaderStages[1].pName = descriptor->fragmentStage->entryPoint;
}
- std::array<VkVertexInputBindingDescription, kMaxVertexBuffers> mBindings;
- std::array<VkVertexInputAttributeDescription, kMaxVertexAttributes> mAttributes;
- const VertexInputDescriptor* vertexInput = GetVertexInputDescriptor();
+ PipelineVertexInputStateCreateInfoTemporaryAllocations tempAllocations;
VkPipelineVertexInputStateCreateInfo vertexInputCreateInfo =
- ComputeVertexInputDesc(vertexInput, &mBindings, &mAttributes);
+ ComputeVertexInputDesc(&tempAllocations);
VkPipelineInputAssemblyStateCreateInfo inputAssembly;
inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
@@ -507,32 +505,31 @@
}
VkPipelineVertexInputStateCreateInfo RenderPipeline::ComputeVertexInputDesc(
- const VertexInputDescriptor* vertexInput,
- std::array<VkVertexInputBindingDescription, kMaxVertexBuffers>* mBindings,
- std::array<VkVertexInputAttributeDescription, kMaxVertexAttributes>* mAttributes) {
+ PipelineVertexInputStateCreateInfoTemporaryAllocations* tempAllocations) {
// Fill in the "binding info" that will be chained in the create info
uint32_t bindingCount = 0;
- for (uint32_t i : IterateBitSet(GetInputsSetMask())) {
- const auto& bindingInfo = GetInput(i);
+ for (uint32_t i : IterateBitSet(GetVertexBufferSlotsUsed())) {
+ const VertexBufferInfo& bindingInfo = GetVertexBuffer(i);
- auto& bindingDesc = (*mBindings)[bindingCount];
- bindingDesc.binding = i;
- bindingDesc.stride = bindingInfo.stride;
- bindingDesc.inputRate = VulkanInputRate(bindingInfo.stepMode);
+ VkVertexInputBindingDescription* bindingDesc = &tempAllocations->bindings[bindingCount];
+ bindingDesc->binding = i;
+ bindingDesc->stride = bindingInfo.arrayStride;
+ bindingDesc->inputRate = VulkanInputRate(bindingInfo.stepMode);
bindingCount++;
}
// Fill in the "attribute info" that will be chained in the create info
uint32_t attributeCount = 0;
- for (uint32_t i : IterateBitSet(GetAttributesSetMask())) {
- const auto& attributeInfo = GetAttribute(i);
+ for (uint32_t i : IterateBitSet(GetAttributeLocationsUsed())) {
+ const VertexAttributeInfo& attributeInfo = GetAttribute(i);
- auto& attributeDesc = (*mAttributes)[attributeCount];
- attributeDesc.location = i;
- attributeDesc.binding = attributeInfo.inputSlot;
- attributeDesc.format = VulkanVertexFormat(attributeInfo.format);
- attributeDesc.offset = attributeInfo.offset;
+ VkVertexInputAttributeDescription* attributeDesc =
+ &tempAllocations->attributes[attributeCount];
+ attributeDesc->location = i;
+ attributeDesc->binding = attributeInfo.vertexBufferSlot;
+ attributeDesc->format = VulkanVertexFormat(attributeInfo.format);
+ attributeDesc->offset = attributeInfo.offset;
attributeCount++;
}
@@ -543,9 +540,9 @@
mCreateInfo.pNext = nullptr;
mCreateInfo.flags = 0;
mCreateInfo.vertexBindingDescriptionCount = bindingCount;
- mCreateInfo.pVertexBindingDescriptions = &(*mBindings)[0];
+ mCreateInfo.pVertexBindingDescriptions = tempAllocations->bindings.data();
mCreateInfo.vertexAttributeDescriptionCount = attributeCount;
- mCreateInfo.pVertexAttributeDescriptions = &(*mAttributes)[0];
+ mCreateInfo.pVertexAttributeDescriptions = tempAllocations->attributes.data();
return mCreateInfo;
}
diff --git a/src/dawn_native/vulkan/RenderPipelineVk.h b/src/dawn_native/vulkan/RenderPipelineVk.h
index 9d2d300..6c61a6e 100644
--- a/src/dawn_native/vulkan/RenderPipelineVk.h
+++ b/src/dawn_native/vulkan/RenderPipelineVk.h
@@ -36,10 +36,12 @@
using RenderPipelineBase::RenderPipelineBase;
MaybeError Initialize(const RenderPipelineDescriptor* descriptor);
+ struct PipelineVertexInputStateCreateInfoTemporaryAllocations {
+ std::array<VkVertexInputBindingDescription, kMaxVertexBuffers> bindings;
+ std::array<VkVertexInputAttributeDescription, kMaxVertexAttributes> attributes;
+ };
VkPipelineVertexInputStateCreateInfo ComputeVertexInputDesc(
- const VertexInputDescriptor* vertexInput,
- std::array<VkVertexInputBindingDescription, kMaxVertexBuffers>* mBindings,
- std::array<VkVertexInputAttributeDescription, kMaxVertexAttributes>* mAttributes);
+ PipelineVertexInputStateCreateInfoTemporaryAllocations* temporaryAllocations);
VkPipeline mHandle = VK_NULL_HANDLE;
};
diff --git a/src/tests/end2end/DestroyTests.cpp b/src/tests/end2end/DestroyTests.cpp
index afce3f2..916fb55 100644
--- a/src/tests/end2end/DestroyTests.cpp
+++ b/src/tests/end2end/DestroyTests.cpp
@@ -46,10 +46,10 @@
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
- descriptor.cVertexInput.bufferCount = 1;
- descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
- descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
- descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
+ descriptor.cVertexState.vertexBufferCount = 1;
+ descriptor.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
+ descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
+ descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat;
pipeline = device.CreateRenderPipeline(&descriptor);
diff --git a/src/tests/end2end/DrawIndexedIndirectTests.cpp b/src/tests/end2end/DrawIndexedIndirectTests.cpp
index 990a271..7fd841e 100644
--- a/src/tests/end2end/DrawIndexedIndirectTests.cpp
+++ b/src/tests/end2end/DrawIndexedIndirectTests.cpp
@@ -46,10 +46,10 @@
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
- descriptor.cVertexInput.bufferCount = 1;
- descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
- descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
- descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
+ descriptor.cVertexState.vertexBufferCount = 1;
+ descriptor.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
+ descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
+ descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat;
pipeline = device.CreateRenderPipeline(&descriptor);
diff --git a/src/tests/end2end/DrawIndexedTests.cpp b/src/tests/end2end/DrawIndexedTests.cpp
index faa9e30..f6f07ae 100644
--- a/src/tests/end2end/DrawIndexedTests.cpp
+++ b/src/tests/end2end/DrawIndexedTests.cpp
@@ -46,10 +46,10 @@
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
- descriptor.cVertexInput.bufferCount = 1;
- descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
- descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
- descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
+ descriptor.cVertexState.vertexBufferCount = 1;
+ descriptor.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
+ descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
+ descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat;
pipeline = device.CreateRenderPipeline(&descriptor);
diff --git a/src/tests/end2end/DrawIndirectTests.cpp b/src/tests/end2end/DrawIndirectTests.cpp
index 702cffe..2b39f5d 100644
--- a/src/tests/end2end/DrawIndirectTests.cpp
+++ b/src/tests/end2end/DrawIndirectTests.cpp
@@ -46,10 +46,10 @@
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
- descriptor.cVertexInput.bufferCount = 1;
- descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
- descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
- descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
+ descriptor.cVertexState.vertexBufferCount = 1;
+ descriptor.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
+ descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
+ descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat;
pipeline = device.CreateRenderPipeline(&descriptor);
diff --git a/src/tests/end2end/DrawTests.cpp b/src/tests/end2end/DrawTests.cpp
index 8b93cf7..1bc0734 100644
--- a/src/tests/end2end/DrawTests.cpp
+++ b/src/tests/end2end/DrawTests.cpp
@@ -46,10 +46,10 @@
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
- descriptor.cVertexInput.bufferCount = 1;
- descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
- descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
- descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
+ descriptor.cVertexState.vertexBufferCount = 1;
+ descriptor.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
+ descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
+ descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat;
pipeline = device.CreateRenderPipeline(&descriptor);
diff --git a/src/tests/end2end/IndexFormatTests.cpp b/src/tests/end2end/IndexFormatTests.cpp
index 8adf2b8..7bf118d 100644
--- a/src/tests/end2end/IndexFormatTests.cpp
+++ b/src/tests/end2end/IndexFormatTests.cpp
@@ -51,11 +51,11 @@
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
- descriptor.cVertexInput.indexFormat = format;
- descriptor.cVertexInput.bufferCount = 1;
- descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
- descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
- descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
+ descriptor.cVertexState.indexFormat = format;
+ descriptor.cVertexState.vertexBufferCount = 1;
+ descriptor.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
+ descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
+ descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat;
return device.CreateRenderPipeline(&descriptor);
diff --git a/src/tests/end2end/PrimitiveTopologyTests.cpp b/src/tests/end2end/PrimitiveTopologyTests.cpp
index 212b124..81b79d0 100644
--- a/src/tests/end2end/PrimitiveTopologyTests.cpp
+++ b/src/tests/end2end/PrimitiveTopologyTests.cpp
@@ -187,10 +187,10 @@
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = primitiveTopology;
- descriptor.cVertexInput.bufferCount = 1;
- descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
- descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
- descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
+ descriptor.cVertexState.vertexBufferCount = 1;
+ descriptor.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
+ descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
+ descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat;
wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
diff --git a/src/tests/end2end/RenderBundleTests.cpp b/src/tests/end2end/RenderBundleTests.cpp
index f5c187b..e101038 100644
--- a/src/tests/end2end/RenderBundleTests.cpp
+++ b/src/tests/end2end/RenderBundleTests.cpp
@@ -77,10 +77,10 @@
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
- descriptor.cVertexInput.bufferCount = 1;
- descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
- descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
- descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
+ descriptor.cVertexState.vertexBufferCount = 1;
+ descriptor.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
+ descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
+ descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat;
pipeline = device.CreateRenderPipeline(&descriptor);
diff --git a/src/tests/end2end/VertexFormatTests.cpp b/src/tests/end2end/VertexFormatTests.cpp
index 704e2c3..0286c97 100644
--- a/src/tests/end2end/VertexFormatTests.cpp
+++ b/src/tests/end2end/VertexFormatTests.cpp
@@ -362,10 +362,10 @@
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
- descriptor.cVertexInput.bufferCount = 1;
- descriptor.cVertexInput.cBuffers[0].stride = strideBytes;
- descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
- descriptor.cVertexInput.cAttributes[0].format = format;
+ descriptor.cVertexState.vertexBufferCount = 1;
+ descriptor.cVertexState.cVertexBuffers[0].arrayStride = strideBytes;
+ descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
+ descriptor.cVertexState.cAttributes[0].format = format;
descriptor.cColorStates[0].format = renderPass.colorFormat;
return device.CreateRenderPipeline(&descriptor);
diff --git a/src/tests/end2end/VertexInputTests.cpp b/src/tests/end2end/VertexStateTests.cpp
similarity index 79%
rename from src/tests/end2end/VertexInputTests.cpp
rename to src/tests/end2end/VertexStateTests.cpp
index 884ec26..a2edad4 100644
--- a/src/tests/end2end/VertexInputTests.cpp
+++ b/src/tests/end2end/VertexStateTests.cpp
@@ -21,10 +21,11 @@
using wgpu::InputStepMode;
using wgpu::VertexFormat;
-// Input state tests all work the same way: the test will render triangles in a grid up to 4x4. Each triangle
-// is position in the grid such that X will correspond to the "triangle number" and the Y to the instance number.
-// Each test will set up an input state and buffers, and the vertex shader will check that the vertex attributes
-// corresponds to predetermined values. On success it outputs green, otherwise red.
+// Input state tests all work the same way: the test will render triangles in a grid up to 4x4. Each
+// triangle is position in the grid such that X will correspond to the "triangle number" and the Y
+// to the instance number. Each test will set up an input state and buffers, and the vertex shader
+// will check that the vertex attributes corresponds to predetermined values. On success it outputs
+// green, otherwise red.
//
// The predetermined values are "K * gl_VertexID + componentIndex" for vertex-indexed buffers, and
// "K * gl_InstanceID + componentIndex" for instance-indexed buffers.
@@ -33,7 +34,7 @@
constexpr static unsigned int kRTCellOffset = 50;
constexpr static unsigned int kRTCellSize = 100;
-class VertexInputTest : public DawnTest {
+class VertexStateTest : public DawnTest {
protected:
void TestSetUp() override {
DawnTest::TestSetUp();
@@ -64,7 +65,7 @@
VertexFormat format;
InputStepMode step;
};
- wgpu::RenderPipeline MakeTestPipeline(const wgpu::VertexInputDescriptor& vertexInput,
+ wgpu::RenderPipeline MakeTestPipeline(const wgpu::VertexStateDescriptor& vertexState,
int multiplier,
const std::vector<ShaderTestSpec>& testSpec) {
std::ostringstream vs;
@@ -131,7 +132,7 @@
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
- descriptor.vertexInput = &vertexInput;
+ descriptor.vertexState = &vertexState;
descriptor.cColorStates[0].format = renderPass.colorFormat;
return device.CreateRenderPipeline(&descriptor);
@@ -143,37 +144,37 @@
VertexFormat format;
};
struct VertexBufferSpec {
- uint64_t stride;
+ uint64_t arrayStride;
InputStepMode step;
std::vector<VertexAttributeSpec> attributes;
};
- utils::ComboVertexInputDescriptor MakeVertexInput(
+ utils::ComboVertexStateDescriptor MakeVertexState(
const std::vector<VertexBufferSpec>& buffers) {
- utils::ComboVertexInputDescriptor vertexInput;
- uint32_t bufferCount = 0;
+ utils::ComboVertexStateDescriptor vertexState;
+ uint32_t vertexBufferCount = 0;
uint32_t totalNumAttributes = 0;
for (const VertexBufferSpec& buffer : buffers) {
- vertexInput.cBuffers[bufferCount].stride = buffer.stride;
- vertexInput.cBuffers[bufferCount].stepMode = buffer.step;
+ vertexState.cVertexBuffers[vertexBufferCount].arrayStride = buffer.arrayStride;
+ vertexState.cVertexBuffers[vertexBufferCount].stepMode = buffer.step;
- vertexInput.cBuffers[bufferCount].attributes =
- &vertexInput.cAttributes[totalNumAttributes];
+ vertexState.cVertexBuffers[vertexBufferCount].attributes =
+ &vertexState.cAttributes[totalNumAttributes];
for (const VertexAttributeSpec& attribute : buffer.attributes) {
- vertexInput.cAttributes[totalNumAttributes].shaderLocation = attribute.location;
- vertexInput.cAttributes[totalNumAttributes].offset = attribute.offset;
- vertexInput.cAttributes[totalNumAttributes].format = attribute.format;
+ vertexState.cAttributes[totalNumAttributes].shaderLocation = attribute.location;
+ vertexState.cAttributes[totalNumAttributes].offset = attribute.offset;
+ vertexState.cAttributes[totalNumAttributes].format = attribute.format;
totalNumAttributes++;
}
- vertexInput.cBuffers[bufferCount].attributeCount =
+ vertexState.cVertexBuffers[vertexBufferCount].attributeCount =
static_cast<uint32_t>(buffer.attributes.size());
- bufferCount++;
+ vertexBufferCount++;
}
- vertexInput.bufferCount = bufferCount;
- return vertexInput;
+ vertexState.vertexBufferCount = vertexBufferCount;
+ return vertexState;
}
template <typename T>
@@ -232,11 +233,11 @@
};
// Test compilation and usage of the fixture :)
-TEST_P(VertexInputTest, Basic) {
- utils::ComboVertexInputDescriptor vertexInput = MakeVertexInput(
+TEST_P(VertexStateTest, Basic) {
+ utils::ComboVertexStateDescriptor vertexState = MakeVertexState(
{{4 * sizeof(float), InputStepMode::Vertex, {{0, 0, VertexFormat::Float4}}}});
wgpu::RenderPipeline pipeline =
- MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
+ MakeTestPipeline(vertexState, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
// clang-format off
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({
@@ -249,14 +250,14 @@
}
// Test a stride of 0 works
-TEST_P(VertexInputTest, ZeroStride) {
+TEST_P(VertexStateTest, ZeroStride) {
// This test was failing only on AMD but the OpenGL backend doesn't gather PCI info yet.
DAWN_SKIP_TEST_IF(IsLinux() && IsOpenGL());
- utils::ComboVertexInputDescriptor vertexInput =
- MakeVertexInput({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float4}}}});
+ utils::ComboVertexStateDescriptor vertexState =
+ MakeVertexState({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float4}}}});
wgpu::RenderPipeline pipeline =
- MakeTestPipeline(vertexInput, 0, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
+ MakeTestPipeline(vertexState, 0, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({
0,
@@ -268,36 +269,36 @@
}
// Test attributes defaults to (0, 0, 0, 1) if the input state doesn't have all components
-TEST_P(VertexInputTest, AttributeExpanding) {
+TEST_P(VertexStateTest, AttributeExpanding) {
// This test was failing only on AMD but the OpenGL backend doesn't gather PCI info yet.
DAWN_SKIP_TEST_IF(IsLinux() && IsOpenGL());
// R32F case
{
- utils::ComboVertexInputDescriptor vertexInput =
- MakeVertexInput({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float}}}});
+ utils::ComboVertexStateDescriptor vertexState =
+ MakeVertexState({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float}}}});
wgpu::RenderPipeline pipeline =
- MakeTestPipeline(vertexInput, 0, {{0, VertexFormat::Float, InputStepMode::Vertex}});
+ MakeTestPipeline(vertexState, 0, {{0, VertexFormat::Float, InputStepMode::Vertex}});
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({0, 1, 2, 3});
DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}});
}
// RG32F case
{
- utils::ComboVertexInputDescriptor vertexInput =
- MakeVertexInput({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float2}}}});
+ utils::ComboVertexStateDescriptor vertexState =
+ MakeVertexState({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float2}}}});
wgpu::RenderPipeline pipeline =
- MakeTestPipeline(vertexInput, 0, {{0, VertexFormat::Float2, InputStepMode::Vertex}});
+ MakeTestPipeline(vertexState, 0, {{0, VertexFormat::Float2, InputStepMode::Vertex}});
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({0, 1, 2, 3});
DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}});
}
// RGB32F case
{
- utils::ComboVertexInputDescriptor vertexInput =
- MakeVertexInput({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float3}}}});
+ utils::ComboVertexStateDescriptor vertexState =
+ MakeVertexState({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float3}}}});
wgpu::RenderPipeline pipeline =
- MakeTestPipeline(vertexInput, 0, {{0, VertexFormat::Float3, InputStepMode::Vertex}});
+ MakeTestPipeline(vertexState, 0, {{0, VertexFormat::Float3, InputStepMode::Vertex}});
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({0, 1, 2, 3});
DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}});
@@ -305,14 +306,14 @@
}
// Test a stride larger than the attributes
-TEST_P(VertexInputTest, StrideLargerThanAttributes) {
+TEST_P(VertexStateTest, StrideLargerThanAttributes) {
// This test was failing only on AMD but the OpenGL backend doesn't gather PCI info yet.
DAWN_SKIP_TEST_IF(IsLinux() && IsOpenGL());
- utils::ComboVertexInputDescriptor vertexInput = MakeVertexInput(
+ utils::ComboVertexStateDescriptor vertexState = MakeVertexState(
{{8 * sizeof(float), InputStepMode::Vertex, {{0, 0, VertexFormat::Float4}}}});
wgpu::RenderPipeline pipeline =
- MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
+ MakeTestPipeline(vertexState, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
// clang-format off
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({
@@ -325,13 +326,13 @@
}
// Test two attributes at an offset, vertex version
-TEST_P(VertexInputTest, TwoAttributesAtAnOffsetVertex) {
- utils::ComboVertexInputDescriptor vertexInput = MakeVertexInput(
+TEST_P(VertexStateTest, TwoAttributesAtAnOffsetVertex) {
+ utils::ComboVertexStateDescriptor vertexState = MakeVertexState(
{{8 * sizeof(float),
InputStepMode::Vertex,
{{0, 0, VertexFormat::Float4}, {1, 4 * sizeof(float), VertexFormat::Float4}}}});
wgpu::RenderPipeline pipeline =
- MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
+ MakeTestPipeline(vertexState, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
// clang-format off
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({
@@ -344,13 +345,13 @@
}
// Test two attributes at an offset, instance version
-TEST_P(VertexInputTest, TwoAttributesAtAnOffsetInstance) {
- utils::ComboVertexInputDescriptor vertexInput = MakeVertexInput(
+TEST_P(VertexStateTest, TwoAttributesAtAnOffsetInstance) {
+ utils::ComboVertexStateDescriptor vertexState = MakeVertexState(
{{8 * sizeof(float),
InputStepMode::Instance,
{{0, 0, VertexFormat::Float4}, {1, 4 * sizeof(float), VertexFormat::Float4}}}});
wgpu::RenderPipeline pipeline =
- MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}});
+ MakeTestPipeline(vertexState, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}});
// clang-format off
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({
@@ -363,11 +364,11 @@
}
// Test a pure-instance input state
-TEST_P(VertexInputTest, PureInstance) {
- utils::ComboVertexInputDescriptor vertexInput = MakeVertexInput(
+TEST_P(VertexStateTest, PureInstance) {
+ utils::ComboVertexStateDescriptor vertexState = MakeVertexState(
{{4 * sizeof(float), InputStepMode::Instance, {{0, 0, VertexFormat::Float4}}}});
wgpu::RenderPipeline pipeline =
- MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}});
+ MakeTestPipeline(vertexState, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}});
// clang-format off
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({
@@ -382,8 +383,8 @@
// Test with mixed everything, vertex vs. instance, different stride and offsets
// different attribute types
-TEST_P(VertexInputTest, MixedEverything) {
- utils::ComboVertexInputDescriptor vertexInput = MakeVertexInput(
+TEST_P(VertexStateTest, MixedEverything) {
+ utils::ComboVertexStateDescriptor vertexState = MakeVertexState(
{{12 * sizeof(float),
InputStepMode::Vertex,
{{0, 0, VertexFormat::Float}, {1, 6 * sizeof(float), VertexFormat::Float2}}},
@@ -391,7 +392,7 @@
InputStepMode::Instance,
{{2, 0, VertexFormat::Float3}, {3, 5 * sizeof(float), VertexFormat::Float4}}}});
wgpu::RenderPipeline pipeline =
- MakeTestPipeline(vertexInput, 1,
+ MakeTestPipeline(vertexState, 1,
{{0, VertexFormat::Float, InputStepMode::Vertex},
{1, VertexFormat::Float2, InputStepMode::Vertex},
{2, VertexFormat::Float3, InputStepMode::Instance},
@@ -415,13 +416,13 @@
}
// Test input state is unaffected by unused vertex slot
-TEST_P(VertexInputTest, UnusedVertexSlot) {
+TEST_P(VertexStateTest, UnusedVertexSlot) {
// Instance input state, using slot 1
- utils::ComboVertexInputDescriptor instanceVertexInput = MakeVertexInput(
+ utils::ComboVertexStateDescriptor instanceVertexState = MakeVertexState(
{{0, InputStepMode::Vertex, {}},
{4 * sizeof(float), InputStepMode::Instance, {{0, 0, VertexFormat::Float4}}}});
wgpu::RenderPipeline instancePipeline = MakeTestPipeline(
- instanceVertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}});
+ instanceVertexState, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}});
// clang-format off
wgpu::Buffer buffer = MakeVertexBuffer<float>({
@@ -454,19 +455,19 @@
// This was a problem with the D3D12 backend where SetVertexBuffer
// was getting the input from the last set pipeline, not the current.
// SetVertexBuffer should be reapplied when the input state changes.
-TEST_P(VertexInputTest, MultiplePipelinesMixedVertexInput) {
+TEST_P(VertexStateTest, MultiplePipelinesMixedVertexState) {
// Basic input state, using slot 0
- utils::ComboVertexInputDescriptor vertexVertexInput = MakeVertexInput(
+ utils::ComboVertexStateDescriptor vertexVertexState = MakeVertexState(
{{4 * sizeof(float), InputStepMode::Vertex, {{0, 0, VertexFormat::Float4}}}});
wgpu::RenderPipeline vertexPipeline =
- MakeTestPipeline(vertexVertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
+ MakeTestPipeline(vertexVertexState, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
// Instance input state, using slot 1
- utils::ComboVertexInputDescriptor instanceVertexInput = MakeVertexInput(
+ utils::ComboVertexStateDescriptor instanceVertexState = MakeVertexState(
{{0, InputStepMode::Instance, {}},
{4 * sizeof(float), InputStepMode::Instance, {{0, 0, VertexFormat::Float4}}}});
wgpu::RenderPipeline instancePipeline = MakeTestPipeline(
- instanceVertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}});
+ instanceVertexState, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}});
// clang-format off
wgpu::Buffer buffer = MakeVertexBuffer<float>({
@@ -499,28 +500,28 @@
}
// Checks that using the last vertex buffer doesn't overflow the vertex buffer table in Metal.
-TEST_P(VertexInputTest, LastAllowedVertexBuffer) {
+TEST_P(VertexStateTest, LastAllowedVertexBuffer) {
constexpr uint32_t kBufferIndex = kMaxVertexBuffers - 1;
- utils::ComboVertexInputDescriptor vertexInput;
+ utils::ComboVertexStateDescriptor vertexState;
// All the other vertex buffers default to no attributes
- vertexInput.bufferCount = kMaxVertexBuffers;
- vertexInput.cBuffers[kBufferIndex].stride = 4 * sizeof(float);
- vertexInput.cBuffers[kBufferIndex].stepMode = InputStepMode::Vertex;
- vertexInput.cBuffers[kBufferIndex].attributeCount = 1;
- vertexInput.cBuffers[kBufferIndex].attributes = &vertexInput.cAttributes[0];
- vertexInput.cAttributes[0].shaderLocation = 0;
- vertexInput.cAttributes[0].offset = 0;
- vertexInput.cAttributes[0].format = VertexFormat::Float4;
+ vertexState.vertexBufferCount = kMaxVertexBuffers;
+ vertexState.cVertexBuffers[kBufferIndex].arrayStride = 4 * sizeof(float);
+ vertexState.cVertexBuffers[kBufferIndex].stepMode = InputStepMode::Vertex;
+ vertexState.cVertexBuffers[kBufferIndex].attributeCount = 1;
+ vertexState.cVertexBuffers[kBufferIndex].attributes = &vertexState.cAttributes[0];
+ vertexState.cAttributes[0].shaderLocation = 0;
+ vertexState.cAttributes[0].offset = 0;
+ vertexState.cAttributes[0].format = VertexFormat::Float4;
wgpu::RenderPipeline pipeline =
- MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
+ MakeTestPipeline(vertexState, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5});
DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{kMaxVertexBuffers - 1, &buffer0}});
}
-DAWN_INSTANTIATE_TEST(VertexInputTest, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend);
+DAWN_INSTANTIATE_TEST(VertexStateTest, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend);
// TODO for the input state:
// - Add more vertex formats
@@ -530,10 +531,10 @@
// - Check for attribute narrowing
// - Check that the input state and the pipeline vertex input types match
-class OptionalVertexInputTest : public DawnTest {};
+class OptionalVertexStateTest : public DawnTest {};
// Test that vertex input is not required in render pipeline descriptor.
-TEST_P(OptionalVertexInputTest, Basic) {
+TEST_P(OptionalVertexStateTest, Basic) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 3, 3);
wgpu::ShaderModule vsModule =
@@ -556,7 +557,7 @@
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::PointList;
- descriptor.vertexInput = nullptr;
+ descriptor.vertexState = nullptr;
wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
@@ -574,7 +575,7 @@
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 1, 1);
}
-DAWN_INSTANTIATE_TEST(OptionalVertexInputTest,
+DAWN_INSTANTIATE_TEST(OptionalVertexStateTest,
D3D12Backend,
MetalBackend,
OpenGLBackend,
diff --git a/src/tests/perf_tests/DrawCallPerf.cpp b/src/tests/perf_tests/DrawCallPerf.cpp
index 84ec9b9..e21c9ae 100644
--- a/src/tests/perf_tests/DrawCallPerf.cpp
+++ b/src/tests/perf_tests/DrawCallPerf.cpp
@@ -346,10 +346,10 @@
// Setup the base render pipeline descriptor.
utils::ComboRenderPipelineDescriptor renderPipelineDesc(device);
- renderPipelineDesc.cVertexInput.bufferCount = 1;
- renderPipelineDesc.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
- renderPipelineDesc.cVertexInput.cBuffers[0].attributeCount = 1;
- renderPipelineDesc.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
+ renderPipelineDesc.cVertexState.vertexBufferCount = 1;
+ renderPipelineDesc.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
+ renderPipelineDesc.cVertexState.cVertexBuffers[0].attributeCount = 1;
+ renderPipelineDesc.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
renderPipelineDesc.depthStencilState = &renderPipelineDesc.cDepthStencilState;
renderPipelineDesc.cDepthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
renderPipelineDesc.cColorStates[0].format = wgpu::TextureFormat::RGBA8Unorm;
diff --git a/src/tests/unittests/validation/RenderBundleValidationTests.cpp b/src/tests/unittests/validation/RenderBundleValidationTests.cpp
index b2dbb34..3a4eb97 100644
--- a/src/tests/unittests/validation/RenderBundleValidationTests.cpp
+++ b/src/tests/unittests/validation/RenderBundleValidationTests.cpp
@@ -98,11 +98,11 @@
descriptor->layout = pipelineLayout;
descriptor->vertexStage.module = vsModule;
descriptor->cFragmentStage.module = fsModule;
- descriptor->cVertexInput.bufferCount = 1;
- descriptor->cVertexInput.cBuffers[0].stride = 2 * sizeof(float);
- descriptor->cVertexInput.cBuffers[0].attributeCount = 1;
- descriptor->cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float2;
- descriptor->cVertexInput.cAttributes[0].shaderLocation = 0;
+ descriptor->cVertexState.vertexBufferCount = 1;
+ descriptor->cVertexState.cVertexBuffers[0].arrayStride = 2 * sizeof(float);
+ descriptor->cVertexState.cVertexBuffers[0].attributeCount = 1;
+ descriptor->cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float2;
+ descriptor->cVertexState.cAttributes[0].shaderLocation = 0;
}
wgpu::ShaderModule vsModule;
diff --git a/src/tests/unittests/validation/RenderPipelineValidationTests.cpp b/src/tests/unittests/validation/RenderPipelineValidationTests.cpp
index a0c723c..a215e65 100644
--- a/src/tests/unittests/validation/RenderPipelineValidationTests.cpp
+++ b/src/tests/unittests/validation/RenderPipelineValidationTests.cpp
@@ -57,7 +57,7 @@
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
- descriptor.vertexInput = nullptr;
+ descriptor.vertexState = nullptr;
device.CreateRenderPipeline(&descriptor);
}
diff --git a/src/tests/unittests/validation/VertexBufferValidationTests.cpp b/src/tests/unittests/validation/VertexBufferValidationTests.cpp
index 178a4ec..a906c4f 100644
--- a/src/tests/unittests/validation/VertexBufferValidationTests.cpp
+++ b/src/tests/unittests/validation/VertexBufferValidationTests.cpp
@@ -70,13 +70,13 @@
descriptor.cFragmentStage.module = fsModule;
for (unsigned int i = 0; i < bufferCount; ++i) {
- descriptor.cVertexInput.cBuffers[i].attributeCount = 1;
- descriptor.cVertexInput.cBuffers[i].attributes =
- &descriptor.cVertexInput.cAttributes[i];
- descriptor.cVertexInput.cAttributes[i].shaderLocation = i;
- descriptor.cVertexInput.cAttributes[i].format = wgpu::VertexFormat::Float3;
+ descriptor.cVertexState.cVertexBuffers[i].attributeCount = 1;
+ descriptor.cVertexState.cVertexBuffers[i].attributes =
+ &descriptor.cVertexState.cAttributes[i];
+ descriptor.cVertexState.cAttributes[i].shaderLocation = i;
+ descriptor.cVertexState.cAttributes[i].format = wgpu::VertexFormat::Float3;
}
- descriptor.cVertexInput.bufferCount = bufferCount;
+ descriptor.cVertexState.vertexBufferCount = bufferCount;
return device.CreateRenderPipeline(&descriptor);
}
diff --git a/src/tests/unittests/validation/VertexInputValidationTests.cpp b/src/tests/unittests/validation/VertexStateValidationTests.cpp
similarity index 66%
rename from src/tests/unittests/validation/VertexInputValidationTests.cpp
rename to src/tests/unittests/validation/VertexStateValidationTests.cpp
index f3fbb33..42d7025 100644
--- a/src/tests/unittests/validation/VertexInputValidationTests.cpp
+++ b/src/tests/unittests/validation/VertexStateValidationTests.cpp
@@ -17,10 +17,10 @@
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/WGPUHelpers.h"
-class VertexInputTest : public ValidationTest {
+class VertexStateTest : public ValidationTest {
protected:
void CreatePipeline(bool success,
- const utils::ComboVertexInputDescriptor& state,
+ const utils::ComboVertexStateDescriptor& state,
std::string vertexSource) {
wgpu::ShaderModule vsModule = utils::CreateShaderModule(
device, utils::SingleShaderStage::Vertex, vertexSource.c_str());
@@ -36,7 +36,7 @@
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
- descriptor.vertexInput = &state;
+ descriptor.vertexState = &state;
descriptor.cColorStates[0].format = wgpu::TextureFormat::RGBA8Unorm;
if (!success) {
@@ -48,8 +48,8 @@
};
// Check an empty vertex input is valid
-TEST_F(VertexInputTest, EmptyIsOk) {
- utils::ComboVertexInputDescriptor state;
+TEST_F(VertexStateTest, EmptyIsOk) {
+ utils::ComboVertexStateDescriptor state;
CreatePipeline(true, state, R"(
#version 450
void main() {
@@ -59,13 +59,13 @@
}
// Check null buffer is valid
-TEST_F(VertexInputTest, NullBufferIsOk) {
- utils::ComboVertexInputDescriptor state;
+TEST_F(VertexStateTest, NullBufferIsOk) {
+ utils::ComboVertexStateDescriptor state;
// One null buffer (buffer[0]) is OK
- state.bufferCount = 1;
- state.cBuffers[0].stride = 0;
- state.cBuffers[0].attributeCount = 0;
- state.cBuffers[0].attributes = nullptr;
+ state.vertexBufferCount = 1;
+ state.cVertexBuffers[0].arrayStride = 0;
+ state.cVertexBuffers[0].attributeCount = 0;
+ state.cVertexBuffers[0].attributes = nullptr;
CreatePipeline(true, state, R"(
#version 450
void main() {
@@ -74,10 +74,10 @@
)");
// One null buffer (buffer[0]) followed by a buffer (buffer[1]) is OK
- state.bufferCount = 2;
- state.cBuffers[1].stride = 0;
- state.cBuffers[1].attributeCount = 1;
- state.cBuffers[1].attributes = &state.cAttributes[0];
+ state.vertexBufferCount = 2;
+ state.cVertexBuffers[1].arrayStride = 0;
+ state.cVertexBuffers[1].attributeCount = 1;
+ state.cVertexBuffers[1].attributes = &state.cAttributes[0];
state.cAttributes[0].shaderLocation = 0;
CreatePipeline(true, state, R"(
#version 450
@@ -87,11 +87,11 @@
)");
// Null buffer (buffer[2]) sitting between buffers (buffer[1] and buffer[3]) is OK
- state.bufferCount = 4;
- state.cBuffers[2].attributeCount = 0;
- state.cBuffers[2].attributes = nullptr;
- state.cBuffers[3].attributeCount = 1;
- state.cBuffers[3].attributes = &state.cAttributes[1];
+ state.vertexBufferCount = 4;
+ state.cVertexBuffers[2].attributeCount = 0;
+ state.cVertexBuffers[2].attributes = nullptr;
+ state.cVertexBuffers[3].attributeCount = 1;
+ state.cVertexBuffers[3].attributes = &state.cAttributes[1];
state.cAttributes[1].shaderLocation = 1;
CreatePipeline(true, state, R"(
#version 450
@@ -103,11 +103,11 @@
// Check validation that pipeline vertex buffers are backed by attributes in the vertex input
// Check validation that pipeline vertex buffers are backed by attributes in the vertex input
-TEST_F(VertexInputTest, PipelineCompatibility) {
- utils::ComboVertexInputDescriptor state;
- state.bufferCount = 1;
- state.cBuffers[0].stride = 2 * sizeof(float);
- state.cBuffers[0].attributeCount = 2;
+TEST_F(VertexStateTest, PipelineCompatibility) {
+ utils::ComboVertexStateDescriptor state;
+ state.vertexBufferCount = 1;
+ state.cVertexBuffers[0].arrayStride = 2 * sizeof(float);
+ state.cVertexBuffers[0].attributeCount = 2;
state.cAttributes[0].shaderLocation = 0;
state.cAttributes[1].shaderLocation = 1;
state.cAttributes[1].offset = sizeof(float);
@@ -122,7 +122,7 @@
}
)");
- // Check it is valid for the pipeline to use a subset of the VertexInput
+ // Check it is valid for the pipeline to use a subset of the VertexState
CreatePipeline(true, state, R"(
#version 450
layout(location = 0) in vec4 a;
@@ -141,13 +141,13 @@
)");
}
-// Test that a stride of 0 is valid
-TEST_F(VertexInputTest, StrideZero) {
+// Test that a arrayStride of 0 is valid
+TEST_F(VertexStateTest, StrideZero) {
// Works ok without attributes
- utils::ComboVertexInputDescriptor state;
- state.bufferCount = 1;
- state.cBuffers[0].stride = 0;
- state.cBuffers[0].attributeCount = 1;
+ utils::ComboVertexStateDescriptor state;
+ state.vertexBufferCount = 1;
+ state.cVertexBuffers[0].arrayStride = 0;
+ state.cVertexBuffers[0].attributeCount = 1;
CreatePipeline(true, state, R"(
#version 450
void main() {
@@ -165,14 +165,14 @@
)");
}
-// Check validation that vertex attribute offset should be within vertex buffer stride,
-// if vertex buffer stride is not zero.
-TEST_F(VertexInputTest, SetOffsetOutOfBounds) {
- // Control case, setting correct stride and offset
- utils::ComboVertexInputDescriptor state;
- state.bufferCount = 1;
- state.cBuffers[0].stride = 2 * sizeof(float);
- state.cBuffers[0].attributeCount = 2;
+// Check validation that vertex attribute offset should be within vertex buffer arrayStride,
+// if vertex buffer arrayStride is not zero.
+TEST_F(VertexStateTest, SetOffsetOutOfBounds) {
+ // Control case, setting correct arrayStride and offset
+ utils::ComboVertexStateDescriptor state;
+ state.vertexBufferCount = 1;
+ state.cVertexBuffers[0].arrayStride = 2 * sizeof(float);
+ state.cVertexBuffers[0].attributeCount = 2;
state.cAttributes[0].shaderLocation = 0;
state.cAttributes[1].shaderLocation = 1;
state.cAttributes[1].offset = sizeof(float);
@@ -183,8 +183,8 @@
}
)");
- // Test vertex attribute offset exceed vertex buffer stride range
- state.cBuffers[0].stride = sizeof(float);
+ // Test vertex attribute offset exceed vertex buffer arrayStride range
+ state.cVertexBuffers[0].arrayStride = sizeof(float);
CreatePipeline(false, state, R"(
#version 450
void main() {
@@ -192,8 +192,8 @@
}
)");
- // It's OK if stride is zero
- state.cBuffers[0].stride = 0;
+ // It's OK if arrayStride is zero
+ state.cVertexBuffers[0].arrayStride = 0;
CreatePipeline(true, state, R"(
#version 450
void main() {
@@ -203,13 +203,13 @@
}
// Check out of bounds condition on total number of vertex buffers
-TEST_F(VertexInputTest, SetVertexBuffersNumLimit) {
+TEST_F(VertexStateTest, SetVertexBuffersNumLimit) {
// Control case, setting max vertex buffer number
- utils::ComboVertexInputDescriptor state;
- state.bufferCount = kMaxVertexBuffers;
+ utils::ComboVertexStateDescriptor state;
+ state.vertexBufferCount = kMaxVertexBuffers;
for (uint32_t i = 0; i < kMaxVertexBuffers; ++i) {
- state.cBuffers[i].attributeCount = 1;
- state.cBuffers[i].attributes = &state.cAttributes[i];
+ state.cVertexBuffers[i].attributeCount = 1;
+ state.cVertexBuffers[i].attributes = &state.cAttributes[i];
state.cAttributes[i].shaderLocation = i;
}
CreatePipeline(true, state, R"(
@@ -220,7 +220,7 @@
)");
// Test vertex buffer number exceed the limit
- state.bufferCount = kMaxVertexBuffers + 1;
+ state.vertexBufferCount = kMaxVertexBuffers + 1;
CreatePipeline(false, state, R"(
#version 450
void main() {
@@ -230,11 +230,11 @@
}
// Check out of bounds condition on total number of vertex attributes
-TEST_F(VertexInputTest, SetVertexAttributesNumLimit) {
+TEST_F(VertexStateTest, SetVertexAttributesNumLimit) {
// Control case, setting max vertex attribute number
- utils::ComboVertexInputDescriptor state;
- state.bufferCount = 2;
- state.cBuffers[0].attributeCount = kMaxVertexAttributes;
+ utils::ComboVertexStateDescriptor state;
+ state.vertexBufferCount = 2;
+ state.cVertexBuffers[0].attributeCount = kMaxVertexAttributes;
for (uint32_t i = 0; i < kMaxVertexAttributes; ++i) {
state.cAttributes[i].shaderLocation = i;
}
@@ -246,8 +246,8 @@
)");
// Test vertex attribute number exceed the limit
- state.cBuffers[1].attributeCount = 1;
- state.cBuffers[1].attributes = &state.cAttributes[kMaxVertexAttributes - 1];
+ state.cVertexBuffers[1].attributeCount = 1;
+ state.cVertexBuffers[1].attributes = &state.cAttributes[kMaxVertexAttributes - 1];
CreatePipeline(false, state, R"(
#version 450
void main() {
@@ -256,13 +256,13 @@
)");
}
-// Check out of bounds condition on input stride
-TEST_F(VertexInputTest, SetInputStrideOutOfBounds) {
- // Control case, setting max input stride
- utils::ComboVertexInputDescriptor state;
- state.bufferCount = 1;
- state.cBuffers[0].stride = kMaxVertexBufferStride;
- state.cBuffers[0].attributeCount = 1;
+// Check out of bounds condition on input arrayStride
+TEST_F(VertexStateTest, SetInputStrideOutOfBounds) {
+ // Control case, setting max input arrayStride
+ utils::ComboVertexStateDescriptor state;
+ state.vertexBufferCount = 1;
+ state.cVertexBuffers[0].arrayStride = kMaxVertexBufferStride;
+ state.cVertexBuffers[0].attributeCount = 1;
CreatePipeline(true, state, R"(
#version 450
void main() {
@@ -270,8 +270,8 @@
}
)");
- // Test input stride OOB
- state.cBuffers[0].stride = kMaxVertexBufferStride + 1;
+ // Test input arrayStride OOB
+ state.cVertexBuffers[0].arrayStride = kMaxVertexBufferStride + 1;
CreatePipeline(false, state, R"(
#version 450
void main() {
@@ -280,13 +280,13 @@
)");
}
-// Check multiple of 4 bytes constraint on input stride
-TEST_F(VertexInputTest, SetInputStrideNotAligned) {
- // Control case, setting input stride 4 bytes.
- utils::ComboVertexInputDescriptor state;
- state.bufferCount = 1;
- state.cBuffers[0].stride = 4;
- state.cBuffers[0].attributeCount = 1;
+// Check multiple of 4 bytes constraint on input arrayStride
+TEST_F(VertexStateTest, SetInputStrideNotAligned) {
+ // Control case, setting input arrayStride 4 bytes.
+ utils::ComboVertexStateDescriptor state;
+ state.vertexBufferCount = 1;
+ state.cVertexBuffers[0].arrayStride = 4;
+ state.cVertexBuffers[0].attributeCount = 1;
CreatePipeline(true, state, R"(
#version 450
void main() {
@@ -294,8 +294,8 @@
}
)");
- // Test input stride not multiple of 4 bytes
- state.cBuffers[0].stride = 2;
+ // Test input arrayStride not multiple of 4 bytes
+ state.cVertexBuffers[0].arrayStride = 2;
CreatePipeline(false, state, R"(
#version 450
void main() {
@@ -305,11 +305,11 @@
}
// Test that we cannot set an already set attribute
-TEST_F(VertexInputTest, AlreadySetAttribute) {
+TEST_F(VertexStateTest, AlreadySetAttribute) {
// Control case, setting attribute 0
- utils::ComboVertexInputDescriptor state;
- state.bufferCount = 1;
- state.cBuffers[0].attributeCount = 1;
+ utils::ComboVertexStateDescriptor state;
+ state.vertexBufferCount = 1;
+ state.cVertexBuffers[0].attributeCount = 1;
state.cAttributes[0].shaderLocation = 0;
CreatePipeline(true, state, R"(
#version 450
@@ -319,7 +319,7 @@
)");
// Oh no, attribute 0 is set twice
- state.cBuffers[0].attributeCount = 2;
+ state.cVertexBuffers[0].attributeCount = 2;
state.cAttributes[0].shaderLocation = 0;
state.cAttributes[1].shaderLocation = 0;
CreatePipeline(false, state, R"(
@@ -330,12 +330,12 @@
)");
}
-// Test that a stride of 0 is valid
-TEST_F(VertexInputTest, SetSameShaderLocation) {
+// Test that a arrayStride of 0 is valid
+TEST_F(VertexStateTest, SetSameShaderLocation) {
// Control case, setting different shader locations in two attributes
- utils::ComboVertexInputDescriptor state;
- state.bufferCount = 1;
- state.cBuffers[0].attributeCount = 2;
+ utils::ComboVertexStateDescriptor state;
+ state.vertexBufferCount = 1;
+ state.cVertexBuffers[0].attributeCount = 2;
state.cAttributes[0].shaderLocation = 0;
state.cAttributes[1].shaderLocation = 1;
state.cAttributes[1].offset = sizeof(float);
@@ -356,11 +356,11 @@
)");
// Test same shader location in two attributes in different buffers
- state.bufferCount = 2;
- state.cBuffers[0].attributeCount = 1;
+ state.vertexBufferCount = 2;
+ state.cVertexBuffers[0].attributeCount = 1;
state.cAttributes[0].shaderLocation = 0;
- state.cBuffers[1].attributeCount = 1;
- state.cBuffers[1].attributes = &state.cAttributes[1];
+ state.cVertexBuffers[1].attributeCount = 1;
+ state.cVertexBuffers[1].attributes = &state.cAttributes[1];
state.cAttributes[1].shaderLocation = 0;
CreatePipeline(false, state, R"(
#version 450
@@ -371,11 +371,11 @@
}
// Check out of bounds condition on attribute shader location
-TEST_F(VertexInputTest, SetAttributeLocationOutOfBounds) {
+TEST_F(VertexStateTest, SetAttributeLocationOutOfBounds) {
// Control case, setting last attribute shader location
- utils::ComboVertexInputDescriptor state;
- state.bufferCount = 1;
- state.cBuffers[0].attributeCount = 1;
+ utils::ComboVertexStateDescriptor state;
+ state.vertexBufferCount = 1;
+ state.cVertexBuffers[0].attributeCount = 1;
state.cAttributes[0].shaderLocation = kMaxVertexAttributes - 1;
CreatePipeline(true, state, R"(
#version 450
@@ -395,11 +395,11 @@
}
// Check attribute offset out of bounds
-TEST_F(VertexInputTest, SetAttributeOffsetOutOfBounds) {
+TEST_F(VertexStateTest, SetAttributeOffsetOutOfBounds) {
// Control case, setting max attribute offset for FloatR32 vertex format
- utils::ComboVertexInputDescriptor state;
- state.bufferCount = 1;
- state.cBuffers[0].attributeCount = 1;
+ utils::ComboVertexStateDescriptor state;
+ state.vertexBufferCount = 1;
+ state.cVertexBuffers[0].attributeCount = 1;
state.cAttributes[0].offset = kMaxVertexAttributeEnd - sizeof(wgpu::VertexFormat::Float);
CreatePipeline(true, state, R"(
#version 450
@@ -419,11 +419,11 @@
}
// Check multiple of 4 bytes constraint on offset
-TEST_F(VertexInputTest, SetOffsetNotAligned) {
+TEST_F(VertexStateTest, SetOffsetNotAligned) {
// Control case, setting offset 4 bytes.
- utils::ComboVertexInputDescriptor state;
- state.bufferCount = 1;
- state.cBuffers[0].attributeCount = 1;
+ utils::ComboVertexStateDescriptor state;
+ state.vertexBufferCount = 1;
+ state.cVertexBuffers[0].attributeCount = 1;
state.cAttributes[0].offset = 4;
CreatePipeline(true, state, R"(
#version 450
@@ -443,10 +443,10 @@
}
// Check attribute offset overflow
-TEST_F(VertexInputTest, SetAttributeOffsetOverflow) {
- utils::ComboVertexInputDescriptor state;
- state.bufferCount = 1;
- state.cBuffers[0].attributeCount = 1;
+TEST_F(VertexStateTest, SetAttributeOffsetOverflow) {
+ utils::ComboVertexStateDescriptor state;
+ state.vertexBufferCount = 1;
+ state.cVertexBuffers[0].attributeCount = 1;
state.cAttributes[0].offset = std::numeric_limits<uint32_t>::max();
CreatePipeline(false, state, R"(
#version 450
@@ -457,11 +457,11 @@
}
// Check for some potential underflow in the vertex input validation
-TEST_F(VertexInputTest, VertexFormatLargerThanNonZeroStride) {
- utils::ComboVertexInputDescriptor state;
- state.bufferCount = 1;
- state.cBuffers[0].stride = 4;
- state.cBuffers[0].attributeCount = 1;
+TEST_F(VertexStateTest, VertexFormatLargerThanNonZeroStride) {
+ utils::ComboVertexStateDescriptor state;
+ state.vertexBufferCount = 1;
+ state.cVertexBuffers[0].arrayStride = 4;
+ state.cVertexBuffers[0].attributeCount = 1;
state.cAttributes[0].format = wgpu::VertexFormat::Float4;
CreatePipeline(false, state, R"(
#version 450
diff --git a/src/tests/unittests/wire/WireArgumentTests.cpp b/src/tests/unittests/wire/WireArgumentTests.cpp
index 3d7523c..f9c55b6 100644
--- a/src/tests/unittests/wire/WireArgumentTests.cpp
+++ b/src/tests/unittests/wire/WireArgumentTests.cpp
@@ -117,11 +117,11 @@
colorStateDescriptor.writeMask = WGPUColorWriteMask_All;
// Create the input state
- WGPUVertexInputDescriptor vertexInput;
- vertexInput.nextInChain = nullptr;
- vertexInput.indexFormat = WGPUIndexFormat_Uint32;
- vertexInput.bufferCount = 0;
- vertexInput.buffers = nullptr;
+ WGPUVertexStateDescriptor vertexState;
+ vertexState.nextInChain = nullptr;
+ vertexState.indexFormat = WGPUIndexFormat_Uint32;
+ vertexState.vertexBufferCount = 0;
+ vertexState.vertexBuffers = nullptr;
// Create the rasterization state
WGPURasterizationStateDescriptor rasterizationState;
@@ -179,7 +179,7 @@
pipelineDescriptor.sampleMask = 0xFFFFFFFF;
pipelineDescriptor.alphaToCoverageEnabled = false;
pipelineDescriptor.layout = layout;
- pipelineDescriptor.vertexInput = &vertexInput;
+ pipelineDescriptor.vertexState = &vertexState;
pipelineDescriptor.primitiveTopology = WGPUPrimitiveTopology_TriangleList;
pipelineDescriptor.rasterizationState = &rasterizationState;
pipelineDescriptor.depthStencilState = &depthStencilState;
diff --git a/src/tests/unittests/wire/WireOptionalTests.cpp b/src/tests/unittests/wire/WireOptionalTests.cpp
index 382985f..da888d0 100644
--- a/src/tests/unittests/wire/WireOptionalTests.cpp
+++ b/src/tests/unittests/wire/WireOptionalTests.cpp
@@ -90,11 +90,11 @@
colorStateDescriptor.writeMask = WGPUColorWriteMask_All;
// Create the input state
- WGPUVertexInputDescriptor vertexInput;
- vertexInput.nextInChain = nullptr;
- vertexInput.indexFormat = WGPUIndexFormat_Uint32;
- vertexInput.bufferCount = 0;
- vertexInput.buffers = nullptr;
+ WGPUVertexStateDescriptor vertexState;
+ vertexState.nextInChain = nullptr;
+ vertexState.indexFormat = WGPUIndexFormat_Uint32;
+ vertexState.vertexBufferCount = 0;
+ vertexState.vertexBuffers = nullptr;
// Create the rasterization state
WGPURasterizationStateDescriptor rasterizationState;
@@ -154,7 +154,7 @@
pipelineDescriptor.sampleMask = 0xFFFFFFFF;
pipelineDescriptor.alphaToCoverageEnabled = false;
pipelineDescriptor.layout = layout;
- pipelineDescriptor.vertexInput = &vertexInput;
+ pipelineDescriptor.vertexState = &vertexState;
pipelineDescriptor.primitiveTopology = WGPUPrimitiveTopology_TriangleList;
pipelineDescriptor.rasterizationState = &rasterizationState;
diff --git a/src/utils/ComboRenderPipelineDescriptor.cpp b/src/utils/ComboRenderPipelineDescriptor.cpp
index 072e216..58c0e2d 100644
--- a/src/utils/ComboRenderPipelineDescriptor.cpp
+++ b/src/utils/ComboRenderPipelineDescriptor.cpp
@@ -18,11 +18,11 @@
namespace utils {
- ComboVertexInputDescriptor::ComboVertexInputDescriptor() {
- wgpu::VertexInputDescriptor* descriptor = this;
+ ComboVertexStateDescriptor::ComboVertexStateDescriptor() {
+ wgpu::VertexStateDescriptor* descriptor = this;
descriptor->indexFormat = wgpu::IndexFormat::Uint32;
- descriptor->bufferCount = 0;
+ descriptor->vertexBufferCount = 0;
// Fill the default values for vertexBuffers and vertexAttributes in buffers.
wgpu::VertexAttributeDescriptor vertexAttribute;
@@ -33,17 +33,18 @@
cAttributes[i] = vertexAttribute;
}
for (uint32_t i = 0; i < kMaxVertexBuffers; ++i) {
- cBuffers[i].stride = 0;
- cBuffers[i].stepMode = wgpu::InputStepMode::Vertex;
- cBuffers[i].attributeCount = 0;
- cBuffers[i].attributes = nullptr;
+ cVertexBuffers[i].arrayStride = 0;
+ cVertexBuffers[i].stepMode = wgpu::InputStepMode::Vertex;
+ cVertexBuffers[i].attributeCount = 0;
+ cVertexBuffers[i].attributes = nullptr;
}
- // cBuffers[i].attributes points to somewhere in cAttributes. cBuffers[0].attributes
- // points to &cAttributes[0] by default. Assuming cBuffers[0] has two attributes, then
- // cBuffers[1].attributes should point to &cAttributes[2]. Likewise, if cBuffers[1]
- // has 3 attributes, then cBuffers[2].attributes should point to &cAttributes[5].
- cBuffers[0].attributes = &cAttributes[0];
- descriptor->buffers = &cBuffers[0];
+ // cVertexBuffers[i].attributes points to somewhere in cAttributes.
+ // cVertexBuffers[0].attributes points to &cAttributes[0] by default. Assuming
+ // cVertexBuffers[0] has two attributes, then cVertexBuffers[1].attributes should point to
+ // &cAttributes[2]. Likewise, if cVertexBuffers[1] has 3 attributes, then
+ // cVertexBuffers[2].attributes should point to &cAttributes[5].
+ cVertexBuffers[0].attributes = &cAttributes[0];
+ descriptor->vertexBuffers = &cVertexBuffers[0];
}
ComboRenderPipelineDescriptor::ComboRenderPipelineDescriptor(const wgpu::Device& device) {
@@ -62,7 +63,7 @@
}
// Set defaults for the input state descriptors.
- descriptor->vertexInput = &cVertexInput;
+ descriptor->vertexState = &cVertexState;
// Set defaults for the rasterization state descriptor.
{
diff --git a/src/utils/ComboRenderPipelineDescriptor.h b/src/utils/ComboRenderPipelineDescriptor.h
index 178f8ad..067b79e 100644
--- a/src/utils/ComboRenderPipelineDescriptor.h
+++ b/src/utils/ComboRenderPipelineDescriptor.h
@@ -23,11 +23,11 @@
namespace utils {
- class ComboVertexInputDescriptor : public wgpu::VertexInputDescriptor {
+ class ComboVertexStateDescriptor : public wgpu::VertexStateDescriptor {
public:
- ComboVertexInputDescriptor();
+ ComboVertexStateDescriptor();
- std::array<wgpu::VertexBufferDescriptor, kMaxVertexBuffers> cBuffers;
+ std::array<wgpu::VertexBufferLayoutDescriptor, kMaxVertexBuffers> cVertexBuffers;
std::array<wgpu::VertexAttributeDescriptor, kMaxVertexAttributes> cAttributes;
};
@@ -42,7 +42,7 @@
wgpu::ProgrammableStageDescriptor cFragmentStage;
- ComboVertexInputDescriptor cVertexInput;
+ ComboVertexStateDescriptor cVertexState;
wgpu::RasterizationStateDescriptor cRasterizationState;
std::array<wgpu::ColorStateDescriptor, kMaxColorAttachments> cColorStates;
wgpu::DepthStencilStateDescriptor cDepthStencilState;