blob: ef600557a1f9478ff3243a085718bcf804707c92 [file] [log] [blame]
<!DOCTYPE html>
<meta charset=utf-8>
<title>Tests for creating texture views.</title>
<meta name="timeout" content="long">
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="js/webgpu-functions.js"></script>
<script>
async function runTests() {
let tests = [
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "1d", format: "rgba8unorm", usage: 0, success: true},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: true},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "3d", format: "rgba8unorm", usage: 0, success: true},
// Test negative values
{width: -1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: -1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 1, depth: -1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 1, depth: 1, mipLevelCount: -1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: -1, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: -1, success: false},
// Test zero values
{width: 0, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 0, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 1, depth: 0, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 1, depth: 1, mipLevelCount: 0, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 0, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
// Test maximum sizes
{width: 10000, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "1d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 3000, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "1d", format: "rgba8unorm", usage: 0, success: false},
{width: 10000, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 10000, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 1, depth: 3000, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 3000, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "3d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 3000, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "3d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 1, depth: 3000, mipLevelCount: 1, sampleCount: 1, dimension: "3d", format: "rgba8unorm", usage: 0, success: false},
// Test mipmapped textures
{width: 2, height: 1, depth: 1, mipLevelCount: 2, sampleCount: 1, dimension: "1d", format: "rgba8unorm", usage: 0, success: false},
{width: 2, height: 2, depth: 1, mipLevelCount: 2, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: true},
{width: 2, height: 1, depth: 1, mipLevelCount: 2, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: true},
{width: 2, height: 2, depth: 2, mipLevelCount: 2, sampleCount: 1, dimension: "3d", format: "rgba8unorm", usage: 0, success: true},
{width: 2, height: 2, depth: 1, mipLevelCount: 3, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 2, height: 2, depth: 2, mipLevelCount: 3, sampleCount: 1, dimension: "3d", format: "rgba8unorm", usage: 0, success: false},
// Test multisampling
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 4, dimension: "1d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 4, dimension: "2d", format: "rgba8unorm", usage: 0, success: true},
{width: 2, height: 2, depth: 1, mipLevelCount: 1, sampleCount: 4, dimension: "2d", format: "rgba8unorm", usage: 0, success: true},
{width: 2, height: 2, depth: 1, mipLevelCount: 2, sampleCount: 4, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 4, dimension: "3d", format: "rgba8unorm", usage: 0, success: false},
{width: 2, height: 2, depth: 1, mipLevelCount: 1, sampleCount: 3, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 2, height: 2, depth: 1, mipLevelCount: 1, sampleCount: 300, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 2, height: 2, depth: 2, mipLevelCount: 1, sampleCount: 4, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 2, dimension: "2d", format: "rgba8unorm", usage: 0, success: false},
// Test dimension
{width: 2, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "1d", format: "rgba8unorm", usage: 0, success: true},
{width: 1, height: 2, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "1d", format: "rgba8unorm", usage: 0, success: true},
{width: 1, height: 1, depth: 2, mipLevelCount: 1, sampleCount: 1, dimension: "1d", format: "rgba8unorm", usage: 0, success: false},
{width: 2, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: true},
{width: 1, height: 2, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: true},
{width: 1, height: 1, depth: 2, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 0, success: true},
// Test depth textures
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "1d", format: "depth32float-stencil8", usage: 0, success: false},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "depth32float-stencil8", usage: 0, success: true},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 2, dimension: "2d", format: "depth32float-stencil8", usage: 0, success: false},
// Test enums
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "garbage", format: "rgba8unorm", usage: 0, success: false},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "garbage", usage: 0, success: false},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8uint", usage: 0, success: true},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "bgra8unorm", usage: 0, success: true},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "bgra8unorm-srgb", usage: 0, success: true},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba16float", usage: 0, success: true},
// Test usage
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: 1000, success: false},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 1, dimension: "2d", format: "rgba8unorm", usage: GPUTextureUsage.COPY_SRC | GPUTextureUsage.COPY_DST | GPUTextureUsage.SAMPLED | GPUTextureUsage.STORAGE | GPUTextureUsage.OUTPUT_ATTACHMENT, success: true},
{width: 1, height: 1, depth: 1, mipLevelCount: 1, sampleCount: 4, dimension: "2d", format: "rgba8unorm", usage: GPUTextureUsage.STORAGE, success: false},
];
for (let test of tests) {
promise_test(() => {
return getBasicDevice().then(async function(device) {
let caught = false;
device.pushErrorScope("validation");
try {
let texture = device.createTexture({size: {width: test.width, height: test.height, depth: test.depth}, mipLevelCount: test.mipLevelCount, sampleCount: test.sampleCount, dimension: test.dimension, format: test.format, usage: test.usage});
assert_true(texture instanceof GPUTexture, "Cannot create texture.");
} catch {
assert_true(!test.success, "Creating texture should " + (test.success ? "not " : "") + "fail.");
caught = true;
}
await device.popErrorScope().then(function(error) {
if (test.success) {
let message = "Could not create texture: ";
if (error && error.message)
message += error.message;
assert_equals(error, null, "Could not create texture: " + message);
} else if (!caught) {
let message = "Created texture: ";
if (error && error.message)
message += error.message;
assert_true(!!(caught || error), "Created texture when shouldn't have: " + message);
}
}, function() {
assert_true(false, "device lost");
});
}, function(e) {
});
}, `Creating a texture of width ${test.width} height ${test.height} depth ${test.depth} mipLevelCount ${test.mipLevelCount} sampleCount ${test.sampleCount} dimension ${test.dimension} format ${test.format} usage ${test.usage}.`);
}
}
runTests();
</script>
</body>