mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
Update VertexInput (InputState) to match spec - Part 1
This is only a renaming: change VertexInput to VertexBuffer, and change InputState to VertexInput. The next two patches will do as follows: 1) change the structure of vertex input descriptor related stuff. 2) change num to count. BUG=dawn:80, dawn:107 Change-Id: Ie76aa653a527759a9c3b4a4792e3254689f053b8 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/7420 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Yunchao He <yunchao.he@intel.com>
This commit is contained in:
committed by
Commit Bot service account
parent
820a04b9ce
commit
eea2091068
@@ -45,18 +45,18 @@ class VertexBufferValidationTest : public ValidationTest {
|
||||
return buffers;
|
||||
}
|
||||
|
||||
dawn::ShaderModule MakeVertexShader(unsigned int numInputs) {
|
||||
dawn::ShaderModule MakeVertexShader(unsigned int numBuffers) {
|
||||
std::ostringstream vs;
|
||||
vs << "#version 450\n";
|
||||
for (unsigned int i = 0; i < numInputs; ++i) {
|
||||
for (unsigned int i = 0; i < numBuffers; ++i) {
|
||||
vs << "layout(location = " << i << ") in vec3 a_position" << i << ";\n";
|
||||
}
|
||||
vs << "void main() {\n";
|
||||
|
||||
vs << "gl_Position = vec4(";
|
||||
for (unsigned int i = 0; i < numInputs; ++i) {
|
||||
for (unsigned int i = 0; i < numBuffers; ++i) {
|
||||
vs << "a_position" << i;
|
||||
if (i != numInputs - 1) {
|
||||
if (i != numBuffers - 1) {
|
||||
vs << " + ";
|
||||
}
|
||||
}
|
||||
@@ -68,19 +68,19 @@ class VertexBufferValidationTest : public ValidationTest {
|
||||
}
|
||||
|
||||
dawn::RenderPipeline MakeRenderPipeline(const dawn::ShaderModule& vsModule,
|
||||
unsigned int numInputs) {
|
||||
unsigned int numBuffers) {
|
||||
utils::ComboRenderPipelineDescriptor descriptor(device);
|
||||
descriptor.cVertexStage.module = vsModule;
|
||||
descriptor.cFragmentStage.module = fsModule;
|
||||
|
||||
for (unsigned int i = 0; i < numInputs; ++i) {
|
||||
descriptor.cInputState.cAttributes[i].shaderLocation = i;
|
||||
descriptor.cInputState.cAttributes[i].inputSlot = i;
|
||||
descriptor.cInputState.cAttributes[i].format = dawn::VertexFormat::Float3;
|
||||
descriptor.cInputState.cInputs[i].inputSlot = i;
|
||||
for (unsigned int i = 0; i < numBuffers; ++i) {
|
||||
descriptor.cVertexInput.cAttributes[i].shaderLocation = i;
|
||||
descriptor.cVertexInput.cAttributes[i].inputSlot = i;
|
||||
descriptor.cVertexInput.cAttributes[i].format = dawn::VertexFormat::Float3;
|
||||
descriptor.cVertexInput.cBuffers[i].inputSlot = i;
|
||||
}
|
||||
descriptor.cInputState.numInputs = numInputs;
|
||||
descriptor.cInputState.numAttributes = numInputs;
|
||||
descriptor.cVertexInput.numBuffers = numBuffers;
|
||||
descriptor.cVertexInput.numAttributes = numBuffers;
|
||||
|
||||
return device.CreateRenderPipeline(&descriptor);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ class VertexBufferValidationTest : public ValidationTest {
|
||||
dawn::ShaderModule fsModule;
|
||||
};
|
||||
|
||||
TEST_F(VertexBufferValidationTest, VertexInputsInheritedBetweenPipelines) {
|
||||
TEST_F(VertexBufferValidationTest, VertexBuffersInheritedBetweenPipelines) {
|
||||
DummyRenderPass renderPass(device);
|
||||
auto vsModule2 = MakeVertexShader(2);
|
||||
auto vsModule1 = MakeVertexShader(1);
|
||||
@@ -123,7 +123,7 @@ TEST_F(VertexBufferValidationTest, VertexInputsInheritedBetweenPipelines) {
|
||||
encoder.Finish();
|
||||
}
|
||||
|
||||
TEST_F(VertexBufferValidationTest, VertexInputsNotInheritedBetweenRendePasses) {
|
||||
TEST_F(VertexBufferValidationTest, VertexBuffersNotInheritedBetweenRendePasses) {
|
||||
DummyRenderPass renderPass(device);
|
||||
auto vsModule2 = MakeVertexShader(2);
|
||||
auto vsModule1 = MakeVertexShader(1);
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
#include "utils/ComboRenderPipelineDescriptor.h"
|
||||
#include "utils/DawnHelpers.h"
|
||||
|
||||
class InputStateTest : public ValidationTest {
|
||||
protected:
|
||||
void CreatePipeline(bool success,
|
||||
const utils::ComboInputStateDescriptor& state,
|
||||
std::string vertexSource) {
|
||||
dawn::ShaderModule vsModule =
|
||||
utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, vertexSource.c_str());
|
||||
dawn::ShaderModule fsModule =
|
||||
utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, R"(
|
||||
class VertexInputTest : public ValidationTest {
|
||||
protected:
|
||||
void CreatePipeline(bool success,
|
||||
const utils::ComboVertexInputDescriptor& state,
|
||||
std::string vertexSource) {
|
||||
dawn::ShaderModule vsModule =
|
||||
utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, vertexSource.c_str());
|
||||
dawn::ShaderModule fsModule =
|
||||
utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, R"(
|
||||
#version 450
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
void main() {
|
||||
@@ -33,23 +33,23 @@ class InputStateTest : public ValidationTest {
|
||||
}
|
||||
)");
|
||||
|
||||
utils::ComboRenderPipelineDescriptor descriptor(device);
|
||||
descriptor.cVertexStage.module = vsModule;
|
||||
descriptor.cFragmentStage.module = fsModule;
|
||||
descriptor.inputState = &state;
|
||||
descriptor.cColorStates[0]->format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
utils::ComboRenderPipelineDescriptor descriptor(device);
|
||||
descriptor.cVertexStage.module = vsModule;
|
||||
descriptor.cFragmentStage.module = fsModule;
|
||||
descriptor.vertexInput = &state;
|
||||
descriptor.cColorStates[0]->format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
|
||||
if (!success) {
|
||||
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
|
||||
} else {
|
||||
device.CreateRenderPipeline(&descriptor);
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
|
||||
} else {
|
||||
device.CreateRenderPipeline(&descriptor);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Check an empty input state is valid
|
||||
TEST_F(InputStateTest, EmptyIsOk) {
|
||||
utils::ComboInputStateDescriptor state;
|
||||
TEST_F(VertexInputTest, EmptyIsOk) {
|
||||
utils::ComboVertexInputDescriptor state;
|
||||
CreatePipeline(true, state, R"(
|
||||
#version 450
|
||||
void main() {
|
||||
@@ -58,11 +58,11 @@ TEST_F(InputStateTest, EmptyIsOk) {
|
||||
)");
|
||||
}
|
||||
|
||||
// Check validation that pipeline vertex inputs are backed by attributes in the input state
|
||||
TEST_F(InputStateTest, PipelineCompatibility) {
|
||||
utils::ComboInputStateDescriptor state;
|
||||
state.numInputs = 1;
|
||||
state.cInputs[0].stride = 2 * sizeof(float);
|
||||
// Check validation that pipeline vertex buffers are backed by attributes in the vertex input
|
||||
TEST_F(VertexInputTest, PipelineCompatibility) {
|
||||
utils::ComboVertexInputDescriptor state;
|
||||
state.numBuffers = 1;
|
||||
state.cBuffers[0].stride = 2 * sizeof(float);
|
||||
state.numAttributes = 2;
|
||||
state.cAttributes[1].shaderLocation = 1;
|
||||
state.cAttributes[1].offset = sizeof(float);
|
||||
@@ -77,7 +77,7 @@ TEST_F(InputStateTest, PipelineCompatibility) {
|
||||
}
|
||||
)");
|
||||
|
||||
// Check it is valid for the pipeline to use a subset of the InputState
|
||||
// Check it is valid for the pipeline to use a subset of the VertexInput
|
||||
CreatePipeline(true, state, R"(
|
||||
#version 450
|
||||
layout(location = 0) in vec4 a;
|
||||
@@ -97,10 +97,10 @@ TEST_F(InputStateTest, PipelineCompatibility) {
|
||||
}
|
||||
|
||||
// Test that a stride of 0 is valid
|
||||
TEST_F(InputStateTest, StrideZero) {
|
||||
TEST_F(VertexInputTest, StrideZero) {
|
||||
// Works ok without attributes
|
||||
utils::ComboInputStateDescriptor state;
|
||||
state.numInputs = 1;
|
||||
utils::ComboVertexInputDescriptor state;
|
||||
state.numBuffers = 1;
|
||||
CreatePipeline(true, state, R"(
|
||||
#version 450
|
||||
void main() {
|
||||
@@ -120,10 +120,10 @@ TEST_F(InputStateTest, StrideZero) {
|
||||
}
|
||||
|
||||
// Test that we cannot set an already set input
|
||||
TEST_F(InputStateTest, AlreadySetInput) {
|
||||
TEST_F(VertexInputTest, AlreadySetInput) {
|
||||
// Control case
|
||||
utils::ComboInputStateDescriptor state;
|
||||
state.numInputs = 1;
|
||||
utils::ComboVertexInputDescriptor state;
|
||||
state.numBuffers = 1;
|
||||
CreatePipeline(true, state, R"(
|
||||
#version 450
|
||||
void main() {
|
||||
@@ -132,7 +132,7 @@ TEST_F(InputStateTest, AlreadySetInput) {
|
||||
)");
|
||||
|
||||
// Oh no, input 0 is set twice
|
||||
state.numInputs = 2;
|
||||
state.numBuffers = 2;
|
||||
CreatePipeline(false, state, R"(
|
||||
#version 450
|
||||
void main() {
|
||||
@@ -142,11 +142,11 @@ TEST_F(InputStateTest, AlreadySetInput) {
|
||||
}
|
||||
|
||||
// Check out of bounds condition on input slot
|
||||
TEST_F(InputStateTest, SetInputSlotOutOfBounds) {
|
||||
TEST_F(VertexInputTest, SetInputSlotOutOfBounds) {
|
||||
// Control case, setting last input slot
|
||||
utils::ComboInputStateDescriptor state;
|
||||
state.numInputs = 1;
|
||||
state.cInputs[0].inputSlot = kMaxVertexInputs - 1;
|
||||
utils::ComboVertexInputDescriptor state;
|
||||
state.numBuffers = 1;
|
||||
state.cBuffers[0].inputSlot = kMaxVertexBuffers - 1;
|
||||
CreatePipeline(true, state, R"(
|
||||
#version 450
|
||||
void main() {
|
||||
@@ -155,7 +155,7 @@ TEST_F(InputStateTest, SetInputSlotOutOfBounds) {
|
||||
)");
|
||||
|
||||
// Test input slot OOB
|
||||
state.cInputs[0].inputSlot = kMaxVertexInputs;
|
||||
state.cBuffers[0].inputSlot = kMaxVertexBuffers;
|
||||
CreatePipeline(false, state, R"(
|
||||
#version 450
|
||||
void main() {
|
||||
@@ -165,11 +165,11 @@ TEST_F(InputStateTest, SetInputSlotOutOfBounds) {
|
||||
}
|
||||
|
||||
// Check out of bounds condition on input stride
|
||||
TEST_F(InputStateTest, SetInputStrideOutOfBounds) {
|
||||
TEST_F(VertexInputTest, SetInputStrideOutOfBounds) {
|
||||
// Control case, setting max input stride
|
||||
utils::ComboInputStateDescriptor state;
|
||||
state.numInputs = 1;
|
||||
state.cInputs[0].stride = kMaxVertexInputStride;
|
||||
utils::ComboVertexInputDescriptor state;
|
||||
state.numBuffers = 1;
|
||||
state.cBuffers[0].stride = kMaxVertexBufferStride;
|
||||
CreatePipeline(true, state, R"(
|
||||
#version 450
|
||||
void main() {
|
||||
@@ -178,7 +178,7 @@ TEST_F(InputStateTest, SetInputStrideOutOfBounds) {
|
||||
)");
|
||||
|
||||
// Test input stride OOB
|
||||
state.cInputs[0].stride = kMaxVertexInputStride + 1;
|
||||
state.cBuffers[0].stride = kMaxVertexBufferStride + 1;
|
||||
CreatePipeline(false, state, R"(
|
||||
#version 450
|
||||
void main() {
|
||||
@@ -188,10 +188,10 @@ TEST_F(InputStateTest, SetInputStrideOutOfBounds) {
|
||||
}
|
||||
|
||||
// Test that we cannot set an already set attribute
|
||||
TEST_F(InputStateTest, AlreadySetAttribute) {
|
||||
TEST_F(VertexInputTest, AlreadySetAttribute) {
|
||||
// Control case, setting last attribute
|
||||
utils::ComboInputStateDescriptor state;
|
||||
state.numInputs = 1;
|
||||
utils::ComboVertexInputDescriptor state;
|
||||
state.numBuffers = 1;
|
||||
state.numAttributes = 1;
|
||||
CreatePipeline(true, state, R"(
|
||||
#version 450
|
||||
@@ -211,10 +211,10 @@ TEST_F(InputStateTest, AlreadySetAttribute) {
|
||||
}
|
||||
|
||||
// Check out of bounds condition on attribute shader location
|
||||
TEST_F(InputStateTest, SetAttributeLocationOutOfBounds) {
|
||||
TEST_F(VertexInputTest, SetAttributeLocationOutOfBounds) {
|
||||
// Control case, setting last attribute shader location
|
||||
utils::ComboInputStateDescriptor state;
|
||||
state.numInputs = 1;
|
||||
utils::ComboVertexInputDescriptor state;
|
||||
state.numBuffers = 1;
|
||||
state.numAttributes = 1;
|
||||
state.cAttributes[0].shaderLocation = kMaxVertexAttributes - 1;
|
||||
CreatePipeline(true, state, R"(
|
||||
@@ -235,10 +235,10 @@ TEST_F(InputStateTest, SetAttributeLocationOutOfBounds) {
|
||||
}
|
||||
|
||||
// Check attribute offset out of bounds
|
||||
TEST_F(InputStateTest, SetAttributeOffsetOutOfBounds) {
|
||||
TEST_F(VertexInputTest, SetAttributeOffsetOutOfBounds) {
|
||||
// Control case, setting max attribute offset for FloatR32 vertex format
|
||||
utils::ComboInputStateDescriptor state;
|
||||
state.numInputs = 1;
|
||||
utils::ComboVertexInputDescriptor state;
|
||||
state.numBuffers = 1;
|
||||
state.numAttributes = 1;
|
||||
state.cAttributes[0].offset = kMaxVertexAttributeEnd - sizeof(dawn::VertexFormat::Float);
|
||||
CreatePipeline(true, state, R"(
|
||||
@@ -259,9 +259,9 @@ TEST_F(InputStateTest, SetAttributeOffsetOutOfBounds) {
|
||||
}
|
||||
|
||||
// Check attribute offset overflow
|
||||
TEST_F(InputStateTest, SetAttributeOffsetOverflow) {
|
||||
utils::ComboInputStateDescriptor state;
|
||||
state.numInputs = 1;
|
||||
TEST_F(VertexInputTest, SetAttributeOffsetOverflow) {
|
||||
utils::ComboVertexInputDescriptor state;
|
||||
state.numBuffers = 1;
|
||||
state.numAttributes = 1;
|
||||
state.cAttributes[0].offset = std::numeric_limits<uint32_t>::max();
|
||||
CreatePipeline(false, state, R"(
|
||||
@@ -273,10 +273,10 @@ TEST_F(InputStateTest, SetAttributeOffsetOverflow) {
|
||||
}
|
||||
|
||||
// Check that all attributes must be backed by an input
|
||||
TEST_F(InputStateTest, RequireInputForAttribute) {
|
||||
TEST_F(VertexInputTest, RequireInputForAttribute) {
|
||||
// Control case
|
||||
utils::ComboInputStateDescriptor state;
|
||||
state.numInputs = 1;
|
||||
utils::ComboVertexInputDescriptor state;
|
||||
state.numBuffers = 1;
|
||||
state.numAttributes = 1;
|
||||
CreatePipeline(true, state, R"(
|
||||
#version 450
|
||||
@@ -296,10 +296,10 @@ TEST_F(InputStateTest, RequireInputForAttribute) {
|
||||
}
|
||||
|
||||
// Check OOB checks for an attribute's input
|
||||
TEST_F(InputStateTest, SetAttributeOOBCheckForInputs) {
|
||||
TEST_F(VertexInputTest, SetAttributeOOBCheckForInputs) {
|
||||
// Control case
|
||||
utils::ComboInputStateDescriptor state;
|
||||
state.numInputs = 1;
|
||||
utils::ComboVertexInputDescriptor state;
|
||||
state.numBuffers = 1;
|
||||
state.numAttributes = 1;
|
||||
CreatePipeline(true, state, R"(
|
||||
#version 450
|
||||
@@ -97,13 +97,13 @@ TEST_F(WireArgumentTests, CStringArgument) {
|
||||
colorStateDescriptor.writeMask = DAWN_COLOR_WRITE_MASK_ALL;
|
||||
|
||||
// Create the input state
|
||||
DawnInputStateDescriptor inputState;
|
||||
inputState.nextInChain = nullptr;
|
||||
inputState.indexFormat = DAWN_INDEX_FORMAT_UINT32;
|
||||
inputState.numInputs = 0;
|
||||
inputState.inputs = nullptr;
|
||||
inputState.numAttributes = 0;
|
||||
inputState.attributes = nullptr;
|
||||
DawnVertexInputDescriptor vertexInput;
|
||||
vertexInput.nextInChain = nullptr;
|
||||
vertexInput.indexFormat = DAWN_INDEX_FORMAT_UINT32;
|
||||
vertexInput.numBuffers = 0;
|
||||
vertexInput.buffers = nullptr;
|
||||
vertexInput.numAttributes = 0;
|
||||
vertexInput.attributes = nullptr;
|
||||
|
||||
// Create the rasterization state
|
||||
DawnRasterizationStateDescriptor rasterizationState;
|
||||
@@ -162,7 +162,7 @@ TEST_F(WireArgumentTests, CStringArgument) {
|
||||
|
||||
pipelineDescriptor.sampleCount = 1;
|
||||
pipelineDescriptor.layout = layout;
|
||||
pipelineDescriptor.inputState = &inputState;
|
||||
pipelineDescriptor.vertexInput = &vertexInput;
|
||||
pipelineDescriptor.primitiveTopology = DAWN_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||
pipelineDescriptor.rasterizationState = &rasterizationState;
|
||||
pipelineDescriptor.depthStencilState = &depthStencilState;
|
||||
|
||||
@@ -87,13 +87,13 @@ TEST_F(WireOptionalTests, OptionalStructPointer) {
|
||||
colorStateDescriptor.writeMask = DAWN_COLOR_WRITE_MASK_ALL;
|
||||
|
||||
// Create the input state
|
||||
DawnInputStateDescriptor inputState;
|
||||
inputState.nextInChain = nullptr;
|
||||
inputState.indexFormat = DAWN_INDEX_FORMAT_UINT32;
|
||||
inputState.numInputs = 0;
|
||||
inputState.inputs = nullptr;
|
||||
inputState.numAttributes = 0;
|
||||
inputState.attributes = nullptr;
|
||||
DawnVertexInputDescriptor vertexInput;
|
||||
vertexInput.nextInChain = nullptr;
|
||||
vertexInput.indexFormat = DAWN_INDEX_FORMAT_UINT32;
|
||||
vertexInput.numBuffers = 0;
|
||||
vertexInput.buffers = nullptr;
|
||||
vertexInput.numAttributes = 0;
|
||||
vertexInput.attributes = nullptr;
|
||||
|
||||
// Create the rasterization state
|
||||
DawnRasterizationStateDescriptor rasterizationState;
|
||||
@@ -152,7 +152,7 @@ TEST_F(WireOptionalTests, OptionalStructPointer) {
|
||||
|
||||
pipelineDescriptor.sampleCount = 1;
|
||||
pipelineDescriptor.layout = layout;
|
||||
pipelineDescriptor.inputState = &inputState;
|
||||
pipelineDescriptor.vertexInput = &vertexInput;
|
||||
pipelineDescriptor.primitiveTopology = DAWN_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||
pipelineDescriptor.rasterizationState = &rasterizationState;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user