Added: trunk/LayoutTests/webgpu/whlsl-read-modify-write.html (0 => 246681)
--- trunk/LayoutTests/webgpu/whlsl-read-modify-write.html (rev 0)
+++ trunk/LayoutTests/webgpu/whlsl-read-modify-write.html 2019-06-21 16:59:15 UTC (rev 246681)
@@ -0,0 +1,94 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+const shaderSource = `
+[numthreads(1, 1, 1)]
+compute void computeShader(device int[] buffer : register(u0)) {
+ buffer[0] = 1;
+ buffer[1] = buffer[0]++;
+
+ buffer[2] = 1;
+ buffer[3] = ++buffer[2];
+
+ buffer[4] = 1;
+ buffer[4] += 5;
+
+ buffer[5] = 1;
+ buffer[5] *= 7;
+
+ int total = 14;
+ for (int i = 0; i < 10; i += 2) {
+ total += i;
+ }
+ buffer[6] = total;
+
+ total = 14;
+ for (int i = 0; i < 10; ++i) {
+ total += i;
+ }
+ buffer[7] = total;
+}
+`;
+let results;
+async function start() {
+ const adapter = await navigator.gpu.requestAdapter();
+ const device = await adapter.requestDevice();
+
+ const shaderModule = device.createShaderModule({code: shaderSource, isWHLSL: true});
+ const computeStage = {module: shaderModule, entryPoint: "computeShader"};
+
+ const bindGroupLayoutDescriptor = {bindings: [{binding: 0, visibility: 7, type: "storage-buffer"}]};
+ const bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor);
+ const pipelineLayoutDescriptor = {bindGroupLayouts: [bindGroupLayout]};
+ const pipelineLayout = device.createPipelineLayout(pipelineLayoutDescriptor);
+
+ const computePipelineDescriptor = {computeStage, layout: pipelineLayout};
+ const computePipeline = device.createComputePipeline(computePipelineDescriptor);
+
+ const size = Int32Array.BYTES_PER_ELEMENT * 8;
+
+ const bufferDescriptor = {size, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.MAP_READ};
+ const buffer = device.createBuffer(bufferDescriptor);
+
+ const bufferBinding = {buffer: buffer, size};
+ const bindGroupBinding = {binding: 0, resource: bufferBinding};
+ const bindGroupDescriptor = {layout: bindGroupLayout, bindings: [bindGroupBinding]};
+ const bindGroup = device.createBindGroup(bindGroupDescriptor);
+
+ const commandEncoder = device.createCommandEncoder(); // {}
+ const computePassEncoder = commandEncoder.beginComputePass();
+ computePassEncoder.setPipeline(computePipeline);
+ computePassEncoder.setBindGroup(0, bindGroup);
+ computePassEncoder.dispatch(1, 1, 1);
+ computePassEncoder.endPass();
+ const commandBuffer = commandEncoder.finish();
+ device.getQueue().submit([commandBuffer]);
+
+ const resultsArrayBuffer = await buffer.mapReadAsync();
+ results = new Int32Array(resultsArrayBuffer);
+ shouldBe("results[0]", "2");
+ shouldBe("results[1]", "1");
+ shouldBe("results[2]", "2");
+ shouldBe("results[3]", "2");
+ shouldBe("results[4]", "6");
+ shouldBe("results[5]", "7");
+ shouldBe("results[6]", "34");
+ shouldBe("results[7]", "59");
+ buffer.unmap();
+}
+window.jsTestIsAsync = true;
+window.addEventListener("load", function() {
+ start().then(function() {
+ finishJSTest();
+ }, function() {
+ finishJSTest();
+ });
+});
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt (246680 => 246681)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt 2019-06-21 15:49:21 UTC (rev 246680)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt 2019-06-21 16:59:15 UTC (rev 246681)
@@ -310,17 +310,6 @@
native operator float(int);
native operator float(half);
-native float operator+(float, float);
-native float operator-(float, float);
-native int operator+(int, int);
-native uint operator+(uint, uint);
-native bool operator<(int, int);
-native bool operator<(uint, uint);
-native bool operator<(float, float);
-native bool operator==(float, float);
-native bool operator==(int, int);
-native float operator*(float, float);
-
// FIXME: These should be auto generated by the compiler.
// https://bugs.webkit.org/show_bug.cgi?id=198861
native bool operator==(thread int*, thread int*);
@@ -755,6 +744,55 @@
return result;
}
+native int operator+(int, int);
+native int operator-(int, int);
+native int operator*(int, int);
+native int operator/(int, int);
+native bool operator==(int, int);
+native bool operator<(int, int);
+native bool operator<=(int, int);
+native bool operator>(int, int);
+native bool operator>=(int, int);
+native uint operator+(uint, uint);
+native uint operator-(uint, uint);
+native uint operator*(uint, uint);
+native uint operator/(uint, uint);
+native bool operator==(uint, uint);
+native bool operator<(uint, uint);
+native bool operator<=(uint, uint);
+native bool operator>(uint, uint);
+native bool operator>=(uint, uint);
+
+native float operator+(float, float);
+native float operator-(float, float);
+native float operator*(float, float);
+native float operator/(float, float);
+native bool operator==(float, float);
+native bool operator<(float, float);
+native bool operator<=(float, float);
+native bool operator>(float, float);
+native bool operator>=(float, float);
+
+native int operator&(int, int);
+native int operator|(int, int);
+native int operator^(int, int);
+native int operator~(int);
+native int operator<<(int, uint);
+native int operator>>(int, uint);
+native uint operator&(uint, uint);
+native uint operator|(uint, uint);
+native uint operator^(uint, uint);
+native uint operator~(uint);
+native uint operator<<(uint, uint);
+native uint operator>>(uint, uint);
+
+int operator++(int value) {
+ return value + 1;
+}
+int operator--(int value) {
+ return value - 1;
+}
+
native ushort Sample(Texture1D<ushort>, sampler, float location);
native ushort Sample(Texture1DArray<ushort>, sampler, float2 location);
native ushort Sample(Texture2D<ushort>, sampler, float2 location);