mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 15:46:28 +00:00
Various cleanups for updated indexFormat handling
Addresses post-merge comments left by cwallez@ on https://dawn-review.googlesource.com/c/dawn/+/27182 BUG=dawn:502 Change-Id: I9bce09da9bb46e92a4c613df2279bdefdd06d747 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/27761 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Brandon Jones <bajones@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
be53792880
commit
ccda6a0009
@@ -15,8 +15,38 @@
|
||||
#include "tests/unittests/validation/ValidationTest.h"
|
||||
|
||||
#include "utils/ComboRenderBundleEncoderDescriptor.h"
|
||||
#include "utils/ComboRenderPipelineDescriptor.h"
|
||||
#include "utils/WGPUHelpers.h"
|
||||
|
||||
class IndexBufferValidationTest : public ValidationTest {};
|
||||
class IndexBufferValidationTest : public ValidationTest {
|
||||
protected:
|
||||
wgpu::RenderPipeline MakeTestPipeline(wgpu::IndexFormat format,
|
||||
wgpu::PrimitiveTopology primitiveTopology) {
|
||||
wgpu::ShaderModule vsModule =
|
||||
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
|
||||
#version 450
|
||||
void main() {
|
||||
gl_Position = vec4(0, 0, 0, 1);
|
||||
})");
|
||||
|
||||
wgpu::ShaderModule fsModule =
|
||||
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
|
||||
#version 450
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
void main() {
|
||||
fragColor = vec4(0.0, 1.0, 0.0, 1.0);
|
||||
})");
|
||||
|
||||
utils::ComboRenderPipelineDescriptor descriptor(device);
|
||||
descriptor.vertexStage.module = vsModule;
|
||||
descriptor.cFragmentStage.module = fsModule;
|
||||
descriptor.primitiveTopology = primitiveTopology;
|
||||
descriptor.cVertexState.indexFormat = format;
|
||||
descriptor.cColorStates[0].format = wgpu::TextureFormat::RGBA8Unorm;
|
||||
|
||||
return device.CreateRenderPipeline(&descriptor);
|
||||
}
|
||||
};
|
||||
|
||||
// Test that for OOB validation of index buffer offset and size.
|
||||
TEST_F(IndexBufferValidationTest, IndexBufferOffsetOOBValidation) {
|
||||
@@ -92,3 +122,53 @@ TEST_F(IndexBufferValidationTest, IndexBufferOffsetOOBValidation) {
|
||||
ASSERT_DEVICE_ERROR(encoder.Finish());
|
||||
}
|
||||
}
|
||||
|
||||
// Test that formats given when setting an index buffers must match the format specified on the
|
||||
// pipeline for strip primitive topologies.
|
||||
TEST_F(IndexBufferValidationTest, IndexBufferFormatMatchesPipelineStripFormat) {
|
||||
wgpu::RenderPipeline pipeline32 = MakeTestPipeline(wgpu::IndexFormat::Uint32,
|
||||
wgpu::PrimitiveTopology::TriangleStrip);
|
||||
wgpu::RenderPipeline pipeline16 = MakeTestPipeline(wgpu::IndexFormat::Uint16,
|
||||
wgpu::PrimitiveTopology::LineStrip);
|
||||
|
||||
wgpu::Buffer indexBuffer =
|
||||
utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Index, {0, 1, 2});
|
||||
|
||||
utils::ComboRenderBundleEncoderDescriptor renderBundleDesc = {};
|
||||
renderBundleDesc.colorFormatsCount = 1;
|
||||
renderBundleDesc.cColorFormats[0] = wgpu::TextureFormat::RGBA8Unorm;
|
||||
|
||||
// Expected to fail because pipeline and index formats don't match.
|
||||
{
|
||||
wgpu::RenderBundleEncoder encoder = device.CreateRenderBundleEncoder(&renderBundleDesc);
|
||||
encoder.SetIndexBufferWithFormat(indexBuffer, wgpu::IndexFormat::Uint16);
|
||||
encoder.SetPipeline(pipeline32);
|
||||
encoder.DrawIndexed(3);
|
||||
ASSERT_DEVICE_ERROR(encoder.Finish());
|
||||
}
|
||||
|
||||
{
|
||||
wgpu::RenderBundleEncoder encoder = device.CreateRenderBundleEncoder(&renderBundleDesc);
|
||||
encoder.SetIndexBufferWithFormat(indexBuffer, wgpu::IndexFormat::Uint32);
|
||||
encoder.SetPipeline(pipeline16);
|
||||
encoder.DrawIndexed(3);
|
||||
ASSERT_DEVICE_ERROR(encoder.Finish());
|
||||
}
|
||||
|
||||
// Expected to succeed because pipeline and index formats match.
|
||||
{
|
||||
wgpu::RenderBundleEncoder encoder = device.CreateRenderBundleEncoder(&renderBundleDesc);
|
||||
encoder.SetIndexBufferWithFormat(indexBuffer, wgpu::IndexFormat::Uint16);
|
||||
encoder.SetPipeline(pipeline16);
|
||||
encoder.DrawIndexed(3);
|
||||
encoder.Finish();
|
||||
}
|
||||
|
||||
{
|
||||
wgpu::RenderBundleEncoder encoder = device.CreateRenderBundleEncoder(&renderBundleDesc);
|
||||
encoder.SetIndexBufferWithFormat(indexBuffer, wgpu::IndexFormat::Uint32);
|
||||
encoder.SetPipeline(pipeline32);
|
||||
encoder.DrawIndexed(3);
|
||||
encoder.Finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -577,9 +577,16 @@ TEST_F(RenderPipelineValidationTest, StripIndexFormatRequired) {
|
||||
descriptor.primitiveTopology = primitiveTopology;
|
||||
descriptor.cVertexState.indexFormat = indexFormat;
|
||||
|
||||
// Succeeds even when the index format is undefined because the
|
||||
// primitive topology isn't a strip type.
|
||||
device.CreateRenderPipeline(&descriptor);
|
||||
if (indexFormat == wgpu::IndexFormat::Undefined) {
|
||||
// Succeeds even when the index format is undefined because the
|
||||
// primitive topology isn't a strip type.
|
||||
device.CreateRenderPipeline(&descriptor);
|
||||
} else {
|
||||
// TODO(crbug.com/dawn/502): Once setIndexBuffer requires an
|
||||
// indexFormat. this should fail. For now it succeeds to allow
|
||||
// backwards compatibility during the deprecation period.
|
||||
device.CreateRenderPipeline(&descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user