Update VertexInput (InputState) to match the spec - Part 3
Rename num{Attribute|Buffer}s to {Attribute|Buffer}Count for VertexInput BUG=dawn:80, dawn:107 Change-Id: I7ad62f28449e6283d5c5788dfbd5df1d1e9c813e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/7861 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
67ab1ea8c7
commit
2d4b529443
|
@ -586,8 +586,8 @@
|
||||||
"members": [
|
"members": [
|
||||||
{"name": "stride", "type": "uint64_t"},
|
{"name": "stride", "type": "uint64_t"},
|
||||||
{"name": "step mode", "type": "input step mode"},
|
{"name": "step mode", "type": "input step mode"},
|
||||||
{"name": "num attributes", "type": "uint32_t"},
|
{"name": "attribute count", "type": "uint32_t"},
|
||||||
{"name": "attributes", "type": "vertex attribute descriptor", "annotation": "const*", "length": "num attributes"}
|
{"name": "attributes", "type": "vertex attribute descriptor", "annotation": "const*", "length": "attribute count"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"vertex input descriptor": {
|
"vertex input descriptor": {
|
||||||
|
@ -595,8 +595,8 @@
|
||||||
"extensible": true,
|
"extensible": true,
|
||||||
"members": [
|
"members": [
|
||||||
{"name": "index format", "type": "index format"},
|
{"name": "index format", "type": "index format"},
|
||||||
{"name": "num buffers", "type": "uint32_t"},
|
{"name": "buffer count", "type": "uint32_t"},
|
||||||
{"name": "buffers", "type": "vertex buffer descriptor", "annotation": "const*", "length": "num buffers"}
|
{"name": "buffers", "type": "vertex buffer descriptor", "annotation": "const*", "length": "buffer count"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"input step mode": {
|
"input step mode": {
|
||||||
|
|
|
@ -96,7 +96,7 @@ void init() {
|
||||||
DawnVertexInputDescriptor vertexInput;
|
DawnVertexInputDescriptor vertexInput;
|
||||||
vertexInput.nextInChain = nullptr;
|
vertexInput.nextInChain = nullptr;
|
||||||
vertexInput.indexFormat = DAWN_INDEX_FORMAT_UINT32;
|
vertexInput.indexFormat = DAWN_INDEX_FORMAT_UINT32;
|
||||||
vertexInput.numBuffers = 0;
|
vertexInput.bufferCount = 0;
|
||||||
vertexInput.buffers = nullptr;
|
vertexInput.buffers = nullptr;
|
||||||
descriptor.vertexInput = &vertexInput;
|
descriptor.vertexInput = &vertexInput;
|
||||||
|
|
||||||
|
|
|
@ -120,17 +120,17 @@ void initRender() {
|
||||||
descriptor.cVertexStage.module = vsModule;
|
descriptor.cVertexStage.module = vsModule;
|
||||||
descriptor.cFragmentStage.module = fsModule;
|
descriptor.cFragmentStage.module = fsModule;
|
||||||
|
|
||||||
descriptor.cVertexInput.numBuffers = 2;
|
descriptor.cVertexInput.bufferCount = 2;
|
||||||
descriptor.cVertexInput.cBuffers[0].stride = sizeof(Particle);
|
descriptor.cVertexInput.cBuffers[0].stride = sizeof(Particle);
|
||||||
descriptor.cVertexInput.cBuffers[0].stepMode = dawn::InputStepMode::Instance;
|
descriptor.cVertexInput.cBuffers[0].stepMode = dawn::InputStepMode::Instance;
|
||||||
descriptor.cVertexInput.cBuffers[0].numAttributes = 2;
|
descriptor.cVertexInput.cBuffers[0].attributeCount = 2;
|
||||||
descriptor.cVertexInput.cAttributes[0].offset = offsetof(Particle, pos);
|
descriptor.cVertexInput.cAttributes[0].offset = offsetof(Particle, pos);
|
||||||
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float2;
|
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float2;
|
||||||
descriptor.cVertexInput.cAttributes[1].shaderLocation = 1;
|
descriptor.cVertexInput.cAttributes[1].shaderLocation = 1;
|
||||||
descriptor.cVertexInput.cAttributes[1].offset = offsetof(Particle, vel);
|
descriptor.cVertexInput.cAttributes[1].offset = offsetof(Particle, vel);
|
||||||
descriptor.cVertexInput.cAttributes[1].format = dawn::VertexFormat::Float2;
|
descriptor.cVertexInput.cAttributes[1].format = dawn::VertexFormat::Float2;
|
||||||
descriptor.cVertexInput.cBuffers[1].stride = sizeof(glm::vec2);
|
descriptor.cVertexInput.cBuffers[1].stride = sizeof(glm::vec2);
|
||||||
descriptor.cVertexInput.cBuffers[1].numAttributes = 1;
|
descriptor.cVertexInput.cBuffers[1].attributeCount = 1;
|
||||||
descriptor.cVertexInput.cBuffers[1].attributes = &descriptor.cVertexInput.cAttributes[2];
|
descriptor.cVertexInput.cBuffers[1].attributes = &descriptor.cVertexInput.cAttributes[2];
|
||||||
descriptor.cVertexInput.cAttributes[2].shaderLocation = 2;
|
descriptor.cVertexInput.cAttributes[2].shaderLocation = 2;
|
||||||
descriptor.cVertexInput.cAttributes[2].format = dawn::VertexFormat::Float2;
|
descriptor.cVertexInput.cAttributes[2].format = dawn::VertexFormat::Float2;
|
||||||
|
|
|
@ -125,9 +125,9 @@ void init() {
|
||||||
descriptor.layout = utils::MakeBasicPipelineLayout(device, &bgl);
|
descriptor.layout = utils::MakeBasicPipelineLayout(device, &bgl);
|
||||||
descriptor.cVertexStage.module = vsModule;
|
descriptor.cVertexStage.module = vsModule;
|
||||||
descriptor.cFragmentStage.module = fsModule;
|
descriptor.cFragmentStage.module = fsModule;
|
||||||
descriptor.cVertexInput.numBuffers = 1;
|
descriptor.cVertexInput.bufferCount = 1;
|
||||||
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
|
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
|
||||||
descriptor.cVertexInput.cBuffers[0].numAttributes = 1;
|
descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
|
||||||
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4;
|
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4;
|
||||||
descriptor.depthStencilState = &descriptor.cDepthStencilState;
|
descriptor.depthStencilState = &descriptor.cDepthStencilState;
|
||||||
descriptor.cDepthStencilState.format = dawn::TextureFormat::D32FloatS8Uint;
|
descriptor.cDepthStencilState.format = dawn::TextureFormat::D32FloatS8Uint;
|
||||||
|
|
|
@ -157,13 +157,13 @@ void init() {
|
||||||
})");
|
})");
|
||||||
|
|
||||||
utils::ComboVertexInputDescriptor vertexInput;
|
utils::ComboVertexInputDescriptor vertexInput;
|
||||||
vertexInput.cBuffers[0].numAttributes = 2;
|
vertexInput.cBuffers[0].attributeCount = 2;
|
||||||
vertexInput.cAttributes[0].format = dawn::VertexFormat::Float3;
|
vertexInput.cAttributes[0].format = dawn::VertexFormat::Float3;
|
||||||
vertexInput.cAttributes[1].shaderLocation = 1;
|
vertexInput.cAttributes[1].shaderLocation = 1;
|
||||||
vertexInput.cAttributes[1].offset = 3 * sizeof(float);
|
vertexInput.cAttributes[1].offset = 3 * sizeof(float);
|
||||||
vertexInput.cAttributes[1].format = dawn::VertexFormat::Float3;
|
vertexInput.cAttributes[1].format = dawn::VertexFormat::Float3;
|
||||||
|
|
||||||
vertexInput.numBuffers = 1;
|
vertexInput.bufferCount = 1;
|
||||||
vertexInput.cBuffers[0].stride = 6 * sizeof(float);
|
vertexInput.cBuffers[0].stride = 6 * sizeof(float);
|
||||||
|
|
||||||
auto bgl = utils::MakeBindGroupLayout(
|
auto bgl = utils::MakeBindGroupLayout(
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace dawn_native {
|
||||||
return DAWN_VALIDATION_ERROR("Setting input stride out of bounds");
|
return DAWN_VALIDATION_ERROR("Setting input stride out of bounds");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < buffer->numAttributes; ++i) {
|
for (uint32_t i = 0; i < buffer->attributeCount; ++i) {
|
||||||
DAWN_TRY(ValidateVertexAttributeDescriptor(&buffer->attributes[i], buffer->stride,
|
DAWN_TRY(ValidateVertexAttributeDescriptor(&buffer->attributes[i], buffer->stride,
|
||||||
attributesSetMask));
|
attributesSetMask));
|
||||||
}
|
}
|
||||||
|
@ -74,15 +74,15 @@ namespace dawn_native {
|
||||||
}
|
}
|
||||||
DAWN_TRY(ValidateIndexFormat(descriptor->indexFormat));
|
DAWN_TRY(ValidateIndexFormat(descriptor->indexFormat));
|
||||||
|
|
||||||
if (descriptor->numBuffers > kMaxVertexBuffers) {
|
if (descriptor->bufferCount > kMaxVertexBuffers) {
|
||||||
return DAWN_VALIDATION_ERROR("Vertex Inputs number exceeds maximum");
|
return DAWN_VALIDATION_ERROR("Vertex Inputs number exceeds maximum");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t totalAttributesNum = 0;
|
uint32_t totalAttributesNum = 0;
|
||||||
for (uint32_t i = 0; i < descriptor->numBuffers; ++i) {
|
for (uint32_t i = 0; i < descriptor->bufferCount; ++i) {
|
||||||
DAWN_TRY(
|
DAWN_TRY(
|
||||||
ValidateVertexBufferDescriptor(&descriptor->buffers[i], attributesSetMask));
|
ValidateVertexBufferDescriptor(&descriptor->buffers[i], attributesSetMask));
|
||||||
totalAttributesNum += descriptor->buffers[i].numAttributes;
|
totalAttributesNum += descriptor->buffers[i].attributeCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every vertex attribute has a member called shaderLocation, and there are some
|
// Every vertex attribute has a member called shaderLocation, and there are some
|
||||||
|
@ -338,14 +338,14 @@ namespace dawn_native {
|
||||||
mFragmentModule(descriptor->fragmentStage->module),
|
mFragmentModule(descriptor->fragmentStage->module),
|
||||||
mFragmentEntryPoint(descriptor->fragmentStage->entryPoint),
|
mFragmentEntryPoint(descriptor->fragmentStage->entryPoint),
|
||||||
mIsBlueprint(blueprint) {
|
mIsBlueprint(blueprint) {
|
||||||
for (uint32_t slot = 0; slot < mVertexInput.numBuffers; ++slot) {
|
for (uint32_t slot = 0; slot < mVertexInput.bufferCount; ++slot) {
|
||||||
mInputsSetMask.set(slot);
|
mInputsSetMask.set(slot);
|
||||||
mInputInfos[slot].inputSlot = slot;
|
mInputInfos[slot].inputSlot = slot;
|
||||||
mInputInfos[slot].stride = mVertexInput.buffers[slot].stride;
|
mInputInfos[slot].stride = mVertexInput.buffers[slot].stride;
|
||||||
mInputInfos[slot].stepMode = mVertexInput.buffers[slot].stepMode;
|
mInputInfos[slot].stepMode = mVertexInput.buffers[slot].stepMode;
|
||||||
|
|
||||||
uint32_t location = 0;
|
uint32_t location = 0;
|
||||||
for (uint32_t i = 0; i < mVertexInput.buffers[slot].numAttributes; ++i) {
|
for (uint32_t i = 0; i < mVertexInput.buffers[slot].attributeCount; ++i) {
|
||||||
location = mVertexInput.buffers[slot].attributes[i].shaderLocation;
|
location = mVertexInput.buffers[slot].attributes[i].shaderLocation;
|
||||||
mAttributesSetMask.set(location);
|
mAttributesSetMask.set(location);
|
||||||
mAttributeInfos[location].shaderLocation = location;
|
mAttributeInfos[location].shaderLocation = location;
|
||||||
|
|
|
@ -46,9 +46,9 @@ class DestroyTest : public DawnTest {
|
||||||
descriptor.cVertexStage.module = vsModule;
|
descriptor.cVertexStage.module = vsModule;
|
||||||
descriptor.cFragmentStage.module = fsModule;
|
descriptor.cFragmentStage.module = fsModule;
|
||||||
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
|
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
|
||||||
descriptor.cVertexInput.numBuffers = 1;
|
descriptor.cVertexInput.bufferCount = 1;
|
||||||
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
|
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
|
||||||
descriptor.cVertexInput.cBuffers[0].numAttributes = 1;
|
descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
|
||||||
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4;
|
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4;
|
||||||
descriptor.cColorStates[0]->format = renderPass.colorFormat;
|
descriptor.cColorStates[0]->format = renderPass.colorFormat;
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,9 @@ class DrawIndexedTest : public DawnTest {
|
||||||
descriptor.cVertexStage.module = vsModule;
|
descriptor.cVertexStage.module = vsModule;
|
||||||
descriptor.cFragmentStage.module = fsModule;
|
descriptor.cFragmentStage.module = fsModule;
|
||||||
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
|
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
|
||||||
descriptor.cVertexInput.numBuffers = 1;
|
descriptor.cVertexInput.bufferCount = 1;
|
||||||
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
|
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
|
||||||
descriptor.cVertexInput.cBuffers[0].numAttributes = 1;
|
descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
|
||||||
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4;
|
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4;
|
||||||
descriptor.cColorStates[0]->format = renderPass.colorFormat;
|
descriptor.cColorStates[0]->format = renderPass.colorFormat;
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,9 @@ class DrawTest : public DawnTest {
|
||||||
descriptor.cVertexStage.module = vsModule;
|
descriptor.cVertexStage.module = vsModule;
|
||||||
descriptor.cFragmentStage.module = fsModule;
|
descriptor.cFragmentStage.module = fsModule;
|
||||||
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
|
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
|
||||||
descriptor.cVertexInput.numBuffers = 1;
|
descriptor.cVertexInput.bufferCount = 1;
|
||||||
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
|
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
|
||||||
descriptor.cVertexInput.cBuffers[0].numAttributes = 1;
|
descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
|
||||||
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4;
|
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4;
|
||||||
descriptor.cColorStates[0]->format = renderPass.colorFormat;
|
descriptor.cColorStates[0]->format = renderPass.colorFormat;
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,9 @@ class IndexFormatTest : public DawnTest {
|
||||||
descriptor.cFragmentStage.module = fsModule;
|
descriptor.cFragmentStage.module = fsModule;
|
||||||
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
|
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
|
||||||
descriptor.cVertexInput.indexFormat = format;
|
descriptor.cVertexInput.indexFormat = format;
|
||||||
descriptor.cVertexInput.numBuffers = 1;
|
descriptor.cVertexInput.bufferCount = 1;
|
||||||
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
|
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
|
||||||
descriptor.cVertexInput.cBuffers[0].numAttributes = 1;
|
descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
|
||||||
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4;
|
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4;
|
||||||
descriptor.cColorStates[0]->format = renderPass.colorFormat;
|
descriptor.cColorStates[0]->format = renderPass.colorFormat;
|
||||||
|
|
||||||
|
|
|
@ -185,9 +185,9 @@ class PrimitiveTopologyTest : public DawnTest {
|
||||||
descriptor.cVertexStage.module = vsModule;
|
descriptor.cVertexStage.module = vsModule;
|
||||||
descriptor.cFragmentStage.module = fsModule;
|
descriptor.cFragmentStage.module = fsModule;
|
||||||
descriptor.primitiveTopology = primitiveTopology;
|
descriptor.primitiveTopology = primitiveTopology;
|
||||||
descriptor.cVertexInput.numBuffers = 1;
|
descriptor.cVertexInput.bufferCount = 1;
|
||||||
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
|
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
|
||||||
descriptor.cVertexInput.cBuffers[0].numAttributes = 1;
|
descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
|
||||||
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4;
|
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4;
|
||||||
descriptor.cColorStates[0]->format = renderPass.colorFormat;
|
descriptor.cColorStates[0]->format = renderPass.colorFormat;
|
||||||
|
|
||||||
|
|
|
@ -362,9 +362,9 @@ class VertexFormatTest : public DawnTest {
|
||||||
utils::ComboRenderPipelineDescriptor descriptor(device);
|
utils::ComboRenderPipelineDescriptor descriptor(device);
|
||||||
descriptor.cVertexStage.module = vsModule;
|
descriptor.cVertexStage.module = vsModule;
|
||||||
descriptor.cFragmentStage.module = fsModule;
|
descriptor.cFragmentStage.module = fsModule;
|
||||||
descriptor.cVertexInput.numBuffers = 1;
|
descriptor.cVertexInput.bufferCount = 1;
|
||||||
descriptor.cVertexInput.cBuffers[0].stride = strideBytes;
|
descriptor.cVertexInput.cBuffers[0].stride = strideBytes;
|
||||||
descriptor.cVertexInput.cBuffers[0].numAttributes = 1;
|
descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
|
||||||
descriptor.cVertexInput.cAttributes[0].format = format;
|
descriptor.cVertexInput.cAttributes[0].format = format;
|
||||||
descriptor.cColorStates[0]->format = renderPass.colorFormat;
|
descriptor.cColorStates[0]->format = renderPass.colorFormat;
|
||||||
|
|
||||||
|
|
|
@ -150,13 +150,13 @@ class VertexInputTest : public DawnTest {
|
||||||
utils::ComboVertexInputDescriptor MakeVertexInput(
|
utils::ComboVertexInputDescriptor MakeVertexInput(
|
||||||
const std::vector<VertexBufferSpec>& buffers) {
|
const std::vector<VertexBufferSpec>& buffers) {
|
||||||
utils::ComboVertexInputDescriptor vertexInput;
|
utils::ComboVertexInputDescriptor vertexInput;
|
||||||
uint32_t numBuffers = 0;
|
uint32_t bufferCount = 0;
|
||||||
uint32_t totalNumAttributes = 0;
|
uint32_t totalNumAttributes = 0;
|
||||||
for (const VertexBufferSpec& buffer : buffers) {
|
for (const VertexBufferSpec& buffer : buffers) {
|
||||||
vertexInput.cBuffers[numBuffers].stride = buffer.stride;
|
vertexInput.cBuffers[bufferCount].stride = buffer.stride;
|
||||||
vertexInput.cBuffers[numBuffers].stepMode = buffer.step;
|
vertexInput.cBuffers[bufferCount].stepMode = buffer.step;
|
||||||
|
|
||||||
vertexInput.cBuffers[numBuffers].attributes =
|
vertexInput.cBuffers[bufferCount].attributes =
|
||||||
&vertexInput.cAttributes[totalNumAttributes];
|
&vertexInput.cAttributes[totalNumAttributes];
|
||||||
|
|
||||||
for (const VertexAttributeSpec& attribute : buffer.attributes) {
|
for (const VertexAttributeSpec& attribute : buffer.attributes) {
|
||||||
|
@ -165,13 +165,13 @@ class VertexInputTest : public DawnTest {
|
||||||
vertexInput.cAttributes[totalNumAttributes].format = attribute.format;
|
vertexInput.cAttributes[totalNumAttributes].format = attribute.format;
|
||||||
totalNumAttributes++;
|
totalNumAttributes++;
|
||||||
}
|
}
|
||||||
vertexInput.cBuffers[numBuffers].numAttributes =
|
vertexInput.cBuffers[bufferCount].attributeCount =
|
||||||
static_cast<uint32_t>(buffer.attributes.size());
|
static_cast<uint32_t>(buffer.attributes.size());
|
||||||
|
|
||||||
numBuffers++;
|
bufferCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
vertexInput.numBuffers = numBuffers;
|
vertexInput.bufferCount = bufferCount;
|
||||||
return vertexInput;
|
return vertexInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,18 +45,18 @@ class VertexBufferValidationTest : public ValidationTest {
|
||||||
return buffers;
|
return buffers;
|
||||||
}
|
}
|
||||||
|
|
||||||
dawn::ShaderModule MakeVertexShader(unsigned int numBuffers) {
|
dawn::ShaderModule MakeVertexShader(unsigned int bufferCount) {
|
||||||
std::ostringstream vs;
|
std::ostringstream vs;
|
||||||
vs << "#version 450\n";
|
vs << "#version 450\n";
|
||||||
for (unsigned int i = 0; i < numBuffers; ++i) {
|
for (unsigned int i = 0; i < bufferCount; ++i) {
|
||||||
vs << "layout(location = " << i << ") in vec3 a_position" << i << ";\n";
|
vs << "layout(location = " << i << ") in vec3 a_position" << i << ";\n";
|
||||||
}
|
}
|
||||||
vs << "void main() {\n";
|
vs << "void main() {\n";
|
||||||
|
|
||||||
vs << "gl_Position = vec4(";
|
vs << "gl_Position = vec4(";
|
||||||
for (unsigned int i = 0; i < numBuffers; ++i) {
|
for (unsigned int i = 0; i < bufferCount; ++i) {
|
||||||
vs << "a_position" << i;
|
vs << "a_position" << i;
|
||||||
if (i != numBuffers - 1) {
|
if (i != bufferCount - 1) {
|
||||||
vs << " + ";
|
vs << " + ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,19 +68,19 @@ class VertexBufferValidationTest : public ValidationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
dawn::RenderPipeline MakeRenderPipeline(const dawn::ShaderModule& vsModule,
|
dawn::RenderPipeline MakeRenderPipeline(const dawn::ShaderModule& vsModule,
|
||||||
unsigned int numBuffers) {
|
unsigned int bufferCount) {
|
||||||
utils::ComboRenderPipelineDescriptor descriptor(device);
|
utils::ComboRenderPipelineDescriptor descriptor(device);
|
||||||
descriptor.cVertexStage.module = vsModule;
|
descriptor.cVertexStage.module = vsModule;
|
||||||
descriptor.cFragmentStage.module = fsModule;
|
descriptor.cFragmentStage.module = fsModule;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < numBuffers; ++i) {
|
for (unsigned int i = 0; i < bufferCount; ++i) {
|
||||||
descriptor.cVertexInput.cBuffers[i].numAttributes = 1;
|
descriptor.cVertexInput.cBuffers[i].attributeCount = 1;
|
||||||
descriptor.cVertexInput.cBuffers[i].attributes =
|
descriptor.cVertexInput.cBuffers[i].attributes =
|
||||||
&descriptor.cVertexInput.cAttributes[i];
|
&descriptor.cVertexInput.cAttributes[i];
|
||||||
descriptor.cVertexInput.cAttributes[i].shaderLocation = i;
|
descriptor.cVertexInput.cAttributes[i].shaderLocation = i;
|
||||||
descriptor.cVertexInput.cAttributes[i].format = dawn::VertexFormat::Float3;
|
descriptor.cVertexInput.cAttributes[i].format = dawn::VertexFormat::Float3;
|
||||||
}
|
}
|
||||||
descriptor.cVertexInput.numBuffers = numBuffers;
|
descriptor.cVertexInput.bufferCount = bufferCount;
|
||||||
|
|
||||||
return device.CreateRenderPipeline(&descriptor);
|
return device.CreateRenderPipeline(&descriptor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ class VertexInputTest : public ValidationTest {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check an empty input state is valid
|
// Check an empty vertex input is valid
|
||||||
TEST_F(VertexInputTest, EmptyIsOk) {
|
TEST_F(VertexInputTest, EmptyIsOk) {
|
||||||
utils::ComboVertexInputDescriptor state;
|
utils::ComboVertexInputDescriptor state;
|
||||||
CreatePipeline(true, state, R"(
|
CreatePipeline(true, state, R"(
|
||||||
|
@ -61,9 +61,9 @@ TEST_F(VertexInputTest, EmptyIsOk) {
|
||||||
// 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) {
|
TEST_F(VertexInputTest, PipelineCompatibility) {
|
||||||
utils::ComboVertexInputDescriptor state;
|
utils::ComboVertexInputDescriptor state;
|
||||||
state.numBuffers = 1;
|
state.bufferCount = 1;
|
||||||
state.cBuffers[0].stride = 2 * sizeof(float);
|
state.cBuffers[0].stride = 2 * sizeof(float);
|
||||||
state.cBuffers[0].numAttributes = 2;
|
state.cBuffers[0].attributeCount = 2;
|
||||||
state.cAttributes[0].shaderLocation = 0;
|
state.cAttributes[0].shaderLocation = 0;
|
||||||
state.cAttributes[1].shaderLocation = 1;
|
state.cAttributes[1].shaderLocation = 1;
|
||||||
state.cAttributes[1].offset = sizeof(float);
|
state.cAttributes[1].offset = sizeof(float);
|
||||||
|
@ -87,7 +87,7 @@ TEST_F(VertexInputTest, PipelineCompatibility) {
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
|
|
||||||
// Check for an error when the pipeline uses an attribute not in the input state
|
// Check for an error when the pipeline uses an attribute not in the vertex input
|
||||||
CreatePipeline(false, state, R"(
|
CreatePipeline(false, state, R"(
|
||||||
#version 450
|
#version 450
|
||||||
layout(location = 2) in vec4 a;
|
layout(location = 2) in vec4 a;
|
||||||
|
@ -101,9 +101,9 @@ TEST_F(VertexInputTest, PipelineCompatibility) {
|
||||||
TEST_F(VertexInputTest, StrideZero) {
|
TEST_F(VertexInputTest, StrideZero) {
|
||||||
// Works ok without attributes
|
// Works ok without attributes
|
||||||
utils::ComboVertexInputDescriptor state;
|
utils::ComboVertexInputDescriptor state;
|
||||||
state.numBuffers = 1;
|
state.bufferCount = 1;
|
||||||
state.cBuffers[0].stride = 0;
|
state.cBuffers[0].stride = 0;
|
||||||
state.cBuffers[0].numAttributes = 1;
|
state.cBuffers[0].attributeCount = 1;
|
||||||
CreatePipeline(true, state, R"(
|
CreatePipeline(true, state, R"(
|
||||||
#version 450
|
#version 450
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -126,9 +126,9 @@ TEST_F(VertexInputTest, StrideZero) {
|
||||||
TEST_F(VertexInputTest, SetOffsetOutOfBounds) {
|
TEST_F(VertexInputTest, SetOffsetOutOfBounds) {
|
||||||
// Control case, setting correct stride and offset
|
// Control case, setting correct stride and offset
|
||||||
utils::ComboVertexInputDescriptor state;
|
utils::ComboVertexInputDescriptor state;
|
||||||
state.numBuffers = 1;
|
state.bufferCount = 1;
|
||||||
state.cBuffers[0].stride = 2 * sizeof(float);
|
state.cBuffers[0].stride = 2 * sizeof(float);
|
||||||
state.cBuffers[0].numAttributes = 2;
|
state.cBuffers[0].attributeCount = 2;
|
||||||
state.cAttributes[0].shaderLocation = 0;
|
state.cAttributes[0].shaderLocation = 0;
|
||||||
state.cAttributes[1].shaderLocation = 1;
|
state.cAttributes[1].shaderLocation = 1;
|
||||||
state.cAttributes[1].offset = sizeof(float);
|
state.cAttributes[1].offset = sizeof(float);
|
||||||
|
@ -162,9 +162,9 @@ TEST_F(VertexInputTest, SetOffsetOutOfBounds) {
|
||||||
TEST_F(VertexInputTest, SetVertexBuffersNumLimit) {
|
TEST_F(VertexInputTest, SetVertexBuffersNumLimit) {
|
||||||
// Control case, setting max vertex buffer number
|
// Control case, setting max vertex buffer number
|
||||||
utils::ComboVertexInputDescriptor state;
|
utils::ComboVertexInputDescriptor state;
|
||||||
state.numBuffers = kMaxVertexBuffers;
|
state.bufferCount = kMaxVertexBuffers;
|
||||||
for (uint32_t i = 0; i < kMaxVertexBuffers; ++i) {
|
for (uint32_t i = 0; i < kMaxVertexBuffers; ++i) {
|
||||||
state.cBuffers[i].numAttributes = 1;
|
state.cBuffers[i].attributeCount = 1;
|
||||||
state.cBuffers[i].attributes = &state.cAttributes[i];
|
state.cBuffers[i].attributes = &state.cAttributes[i];
|
||||||
state.cAttributes[i].shaderLocation = i;
|
state.cAttributes[i].shaderLocation = i;
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ TEST_F(VertexInputTest, SetVertexBuffersNumLimit) {
|
||||||
)");
|
)");
|
||||||
|
|
||||||
// Test vertex buffer number exceed the limit
|
// Test vertex buffer number exceed the limit
|
||||||
state.numBuffers = kMaxVertexBuffers + 1;
|
state.bufferCount = kMaxVertexBuffers + 1;
|
||||||
CreatePipeline(false, state, R"(
|
CreatePipeline(false, state, R"(
|
||||||
#version 450
|
#version 450
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -189,8 +189,8 @@ TEST_F(VertexInputTest, SetVertexBuffersNumLimit) {
|
||||||
TEST_F(VertexInputTest, SetVertexAttributesNumLimit) {
|
TEST_F(VertexInputTest, SetVertexAttributesNumLimit) {
|
||||||
// Control case, setting max vertex attribute number
|
// Control case, setting max vertex attribute number
|
||||||
utils::ComboVertexInputDescriptor state;
|
utils::ComboVertexInputDescriptor state;
|
||||||
state.numBuffers = 2;
|
state.bufferCount = 2;
|
||||||
state.cBuffers[0].numAttributes = kMaxVertexAttributes;
|
state.cBuffers[0].attributeCount = kMaxVertexAttributes;
|
||||||
for (uint32_t i = 0; i < kMaxVertexAttributes; ++i) {
|
for (uint32_t i = 0; i < kMaxVertexAttributes; ++i) {
|
||||||
state.cAttributes[i].shaderLocation = i;
|
state.cAttributes[i].shaderLocation = i;
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ TEST_F(VertexInputTest, SetVertexAttributesNumLimit) {
|
||||||
)");
|
)");
|
||||||
|
|
||||||
// Test vertex attribute number exceed the limit
|
// Test vertex attribute number exceed the limit
|
||||||
state.cBuffers[1].numAttributes = 1;
|
state.cBuffers[1].attributeCount = 1;
|
||||||
state.cBuffers[1].attributes = &state.cAttributes[kMaxVertexAttributes - 1];
|
state.cBuffers[1].attributes = &state.cAttributes[kMaxVertexAttributes - 1];
|
||||||
CreatePipeline(false, state, R"(
|
CreatePipeline(false, state, R"(
|
||||||
#version 450
|
#version 450
|
||||||
|
@ -216,9 +216,9 @@ TEST_F(VertexInputTest, SetVertexAttributesNumLimit) {
|
||||||
TEST_F(VertexInputTest, SetInputStrideOutOfBounds) {
|
TEST_F(VertexInputTest, SetInputStrideOutOfBounds) {
|
||||||
// Control case, setting max input stride
|
// Control case, setting max input stride
|
||||||
utils::ComboVertexInputDescriptor state;
|
utils::ComboVertexInputDescriptor state;
|
||||||
state.numBuffers = 1;
|
state.bufferCount = 1;
|
||||||
state.cBuffers[0].stride = kMaxVertexBufferStride;
|
state.cBuffers[0].stride = kMaxVertexBufferStride;
|
||||||
state.cBuffers[0].numAttributes = 1;
|
state.cBuffers[0].attributeCount = 1;
|
||||||
CreatePipeline(true, state, R"(
|
CreatePipeline(true, state, R"(
|
||||||
#version 450
|
#version 450
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -240,8 +240,8 @@ TEST_F(VertexInputTest, SetInputStrideOutOfBounds) {
|
||||||
TEST_F(VertexInputTest, AlreadySetAttribute) {
|
TEST_F(VertexInputTest, AlreadySetAttribute) {
|
||||||
// Control case, setting attribute 0
|
// Control case, setting attribute 0
|
||||||
utils::ComboVertexInputDescriptor state;
|
utils::ComboVertexInputDescriptor state;
|
||||||
state.numBuffers = 1;
|
state.bufferCount = 1;
|
||||||
state.cBuffers[0].numAttributes = 1;
|
state.cBuffers[0].attributeCount = 1;
|
||||||
state.cAttributes[0].shaderLocation = 0;
|
state.cAttributes[0].shaderLocation = 0;
|
||||||
CreatePipeline(true, state, R"(
|
CreatePipeline(true, state, R"(
|
||||||
#version 450
|
#version 450
|
||||||
|
@ -251,7 +251,7 @@ TEST_F(VertexInputTest, AlreadySetAttribute) {
|
||||||
)");
|
)");
|
||||||
|
|
||||||
// Oh no, attribute 0 is set twice
|
// Oh no, attribute 0 is set twice
|
||||||
state.cBuffers[0].numAttributes = 2;
|
state.cBuffers[0].attributeCount = 2;
|
||||||
state.cAttributes[0].shaderLocation = 0;
|
state.cAttributes[0].shaderLocation = 0;
|
||||||
state.cAttributes[1].shaderLocation = 0;
|
state.cAttributes[1].shaderLocation = 0;
|
||||||
CreatePipeline(false, state, R"(
|
CreatePipeline(false, state, R"(
|
||||||
|
@ -266,8 +266,8 @@ TEST_F(VertexInputTest, AlreadySetAttribute) {
|
||||||
TEST_F(VertexInputTest, SetSameShaderLocation) {
|
TEST_F(VertexInputTest, SetSameShaderLocation) {
|
||||||
// Control case, setting different shader locations in two attributes
|
// Control case, setting different shader locations in two attributes
|
||||||
utils::ComboVertexInputDescriptor state;
|
utils::ComboVertexInputDescriptor state;
|
||||||
state.numBuffers = 1;
|
state.bufferCount = 1;
|
||||||
state.cBuffers[0].numAttributes = 2;
|
state.cBuffers[0].attributeCount = 2;
|
||||||
state.cAttributes[0].shaderLocation = 0;
|
state.cAttributes[0].shaderLocation = 0;
|
||||||
state.cAttributes[1].shaderLocation = 1;
|
state.cAttributes[1].shaderLocation = 1;
|
||||||
state.cAttributes[1].offset = sizeof(float);
|
state.cAttributes[1].offset = sizeof(float);
|
||||||
|
@ -288,10 +288,10 @@ TEST_F(VertexInputTest, SetSameShaderLocation) {
|
||||||
)");
|
)");
|
||||||
|
|
||||||
// Test same shader location in two attributes in different buffers
|
// Test same shader location in two attributes in different buffers
|
||||||
state.numBuffers = 2;
|
state.bufferCount = 2;
|
||||||
state.cBuffers[0].numAttributes = 1;
|
state.cBuffers[0].attributeCount = 1;
|
||||||
state.cAttributes[0].shaderLocation = 0;
|
state.cAttributes[0].shaderLocation = 0;
|
||||||
state.cBuffers[1].numAttributes = 1;
|
state.cBuffers[1].attributeCount = 1;
|
||||||
state.cBuffers[1].attributes = &state.cAttributes[1];
|
state.cBuffers[1].attributes = &state.cAttributes[1];
|
||||||
state.cAttributes[1].shaderLocation = 0;
|
state.cAttributes[1].shaderLocation = 0;
|
||||||
CreatePipeline(false, state, R"(
|
CreatePipeline(false, state, R"(
|
||||||
|
@ -306,8 +306,8 @@ TEST_F(VertexInputTest, SetSameShaderLocation) {
|
||||||
TEST_F(VertexInputTest, SetAttributeLocationOutOfBounds) {
|
TEST_F(VertexInputTest, SetAttributeLocationOutOfBounds) {
|
||||||
// Control case, setting last attribute shader location
|
// Control case, setting last attribute shader location
|
||||||
utils::ComboVertexInputDescriptor state;
|
utils::ComboVertexInputDescriptor state;
|
||||||
state.numBuffers = 1;
|
state.bufferCount = 1;
|
||||||
state.cBuffers[0].numAttributes = 1;
|
state.cBuffers[0].attributeCount = 1;
|
||||||
state.cAttributes[0].shaderLocation = kMaxVertexAttributes - 1;
|
state.cAttributes[0].shaderLocation = kMaxVertexAttributes - 1;
|
||||||
CreatePipeline(true, state, R"(
|
CreatePipeline(true, state, R"(
|
||||||
#version 450
|
#version 450
|
||||||
|
@ -330,8 +330,8 @@ TEST_F(VertexInputTest, SetAttributeLocationOutOfBounds) {
|
||||||
TEST_F(VertexInputTest, SetAttributeOffsetOutOfBounds) {
|
TEST_F(VertexInputTest, SetAttributeOffsetOutOfBounds) {
|
||||||
// Control case, setting max attribute offset for FloatR32 vertex format
|
// Control case, setting max attribute offset for FloatR32 vertex format
|
||||||
utils::ComboVertexInputDescriptor state;
|
utils::ComboVertexInputDescriptor state;
|
||||||
state.numBuffers = 1;
|
state.bufferCount = 1;
|
||||||
state.cBuffers[0].numAttributes = 1;
|
state.cBuffers[0].attributeCount = 1;
|
||||||
state.cAttributes[0].offset = kMaxVertexAttributeEnd - sizeof(dawn::VertexFormat::Float);
|
state.cAttributes[0].offset = kMaxVertexAttributeEnd - sizeof(dawn::VertexFormat::Float);
|
||||||
CreatePipeline(true, state, R"(
|
CreatePipeline(true, state, R"(
|
||||||
#version 450
|
#version 450
|
||||||
|
@ -353,8 +353,8 @@ TEST_F(VertexInputTest, SetAttributeOffsetOutOfBounds) {
|
||||||
// Check attribute offset overflow
|
// Check attribute offset overflow
|
||||||
TEST_F(VertexInputTest, SetAttributeOffsetOverflow) {
|
TEST_F(VertexInputTest, SetAttributeOffsetOverflow) {
|
||||||
utils::ComboVertexInputDescriptor state;
|
utils::ComboVertexInputDescriptor state;
|
||||||
state.numBuffers = 1;
|
state.bufferCount = 1;
|
||||||
state.cBuffers[0].numAttributes = 1;
|
state.cBuffers[0].attributeCount = 1;
|
||||||
state.cAttributes[0].offset = std::numeric_limits<uint32_t>::max();
|
state.cAttributes[0].offset = std::numeric_limits<uint32_t>::max();
|
||||||
CreatePipeline(false, state, R"(
|
CreatePipeline(false, state, R"(
|
||||||
#version 450
|
#version 450
|
||||||
|
|
|
@ -120,7 +120,7 @@ TEST_F(WireArgumentTests, CStringArgument) {
|
||||||
DawnVertexInputDescriptor vertexInput;
|
DawnVertexInputDescriptor vertexInput;
|
||||||
vertexInput.nextInChain = nullptr;
|
vertexInput.nextInChain = nullptr;
|
||||||
vertexInput.indexFormat = DAWN_INDEX_FORMAT_UINT32;
|
vertexInput.indexFormat = DAWN_INDEX_FORMAT_UINT32;
|
||||||
vertexInput.numBuffers = 0;
|
vertexInput.bufferCount = 0;
|
||||||
vertexInput.buffers = nullptr;
|
vertexInput.buffers = nullptr;
|
||||||
|
|
||||||
// Create the rasterization state
|
// Create the rasterization state
|
||||||
|
|
|
@ -90,7 +90,7 @@ TEST_F(WireOptionalTests, OptionalStructPointer) {
|
||||||
DawnVertexInputDescriptor vertexInput;
|
DawnVertexInputDescriptor vertexInput;
|
||||||
vertexInput.nextInChain = nullptr;
|
vertexInput.nextInChain = nullptr;
|
||||||
vertexInput.indexFormat = DAWN_INDEX_FORMAT_UINT32;
|
vertexInput.indexFormat = DAWN_INDEX_FORMAT_UINT32;
|
||||||
vertexInput.numBuffers = 0;
|
vertexInput.bufferCount = 0;
|
||||||
vertexInput.buffers = nullptr;
|
vertexInput.buffers = nullptr;
|
||||||
|
|
||||||
// Create the rasterization state
|
// Create the rasterization state
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace utils {
|
||||||
dawn::VertexInputDescriptor* descriptor = this;
|
dawn::VertexInputDescriptor* descriptor = this;
|
||||||
|
|
||||||
descriptor->indexFormat = dawn::IndexFormat::Uint32;
|
descriptor->indexFormat = dawn::IndexFormat::Uint32;
|
||||||
descriptor->numBuffers = 0;
|
descriptor->bufferCount = 0;
|
||||||
|
|
||||||
// Fill the default values for vertexBuffers and vertexAttributes in buffers.
|
// Fill the default values for vertexBuffers and vertexAttributes in buffers.
|
||||||
dawn::VertexAttributeDescriptor vertexAttribute;
|
dawn::VertexAttributeDescriptor vertexAttribute;
|
||||||
|
@ -35,7 +35,7 @@ namespace utils {
|
||||||
for (uint32_t i = 0; i < kMaxVertexBuffers; ++i) {
|
for (uint32_t i = 0; i < kMaxVertexBuffers; ++i) {
|
||||||
cBuffers[i].stride = 0;
|
cBuffers[i].stride = 0;
|
||||||
cBuffers[i].stepMode = dawn::InputStepMode::Vertex;
|
cBuffers[i].stepMode = dawn::InputStepMode::Vertex;
|
||||||
cBuffers[i].numAttributes = 0;
|
cBuffers[i].attributeCount = 0;
|
||||||
cBuffers[i].attributes = nullptr;
|
cBuffers[i].attributes = nullptr;
|
||||||
}
|
}
|
||||||
// cBuffers[i].attributes points to somewhere in cAttributes. cBuffers[0].attributes
|
// cBuffers[i].attributes points to somewhere in cAttributes. cBuffers[0].attributes
|
||||||
|
|
Loading…
Reference in New Issue