Changeset 247067 in webkit
- Timestamp:
- Jul 2, 2019 12:06:44 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r247064 r247067 1 2019-07-02 Saam Barati <sbarati@apple.com> 2 3 [WHLSL] Import bitwise bool tests 4 https://bugs.webkit.org/show_bug.cgi?id=199093 5 6 Reviewed by Myles C. Maxfield. 7 8 This patch makes it so that we can mark bools as input and output types in the 9 WHLSL harness. Since bool is not something WHLSL itself allows as an entrypoint 10 input/output type (because we don't specify its bit pattern), we convert between 11 bool and int in the input and output of the function. For now, we don't support 12 a buffer of bools for the input type as a simplification, so we don't have to worry 13 about dynamically converting an int buffer to a bool buffer. We could add this 14 in the future if we found it helpful, but we don't have a strong reason for supporting 15 it right now. 16 17 This patch also starts the process of importing the WHLSL test suite by importing bool 18 bit op tests. 19 20 * webgpu/js/whlsl-test-harness.js: 21 (convertTypeToArrayType): 22 (whlslArgumentType): 23 (convertToWHLSLOutputType): 24 (convertToWHLSLInputType): 25 (Data): 26 (Harness.prototype.get isWHLSL): 27 (Harness.prototype.async.callTypedFunction): 28 (Harness.prototype._setUpArguments): 29 (callVoidFunction): 30 * webgpu/whlsl-bitwise-bool-ops-expected.txt: Added. 31 * webgpu/whlsl-bitwise-bool-ops.html: Added. 32 * webgpu/whlsl-test-harness-test-expected.txt: 33 * webgpu/whlsl-test-harness-test.html: 34 1 35 2019-07-02 Takashi Komori <Takashi.Komori@sony.com> 2 36 -
trunk/LayoutTests/webgpu/js/whlsl-test-harness.js
r246824 r247067 23 23 } 24 24 25 function convertTypeToArrayType( type)25 function convertTypeToArrayType(isWHLSL, type) 26 26 { 27 27 switch(type) { 28 28 case Types.BOOL: 29 if (isWHLSL) 30 return Int32Array; 29 31 return Uint8Array; 30 32 case Types.INT: … … 62 64 } 63 65 66 function whlslArgumentType(type) 67 { 68 if (type === Types.BOOL) 69 return "int"; 70 return convertTypeToWHLSLType(type); 71 } 72 73 function convertToWHLSLOutputType(code, type) 74 { 75 if (type !== Types.BOOL) 76 return code; 77 return `int(${code})`; 78 } 79 80 function convertToWHLSLInputType(code, type) 81 { 82 if (type !== Types.BOOL) 83 return code; 84 return `bool(${code})`; 85 } 86 64 87 /* Harness Classes */ 65 88 … … 92 115 93 116 this._type = type; 94 this._byteLength = (convertTypeToArrayType( type)).BYTES_PER_ELEMENT * values.length;117 this._byteLength = (convertTypeToArrayType(harness.isWHLSL, type)).BYTES_PER_ELEMENT * values.length; 95 118 96 119 const [buffer, arrayBuffer] = harness.device.createBufferMapped({ … … 99 122 }); 100 123 101 const typedArray = new (convertTypeToArrayType( type))(arrayBuffer);124 const typedArray = new (convertTypeToArrayType(harness.isWHLSL, type))(arrayBuffer); 102 125 typedArray.set(values); 103 126 buffer.unmap(); … … 156 179 using namespace metal; 157 180 `; 181 } 182 183 get isWHLSL() 184 { 185 return this._isWHLSL; 158 186 } 159 187 … … 197 225 let entryPointCode; 198 226 if (this._isWHLSL) { 199 argsDeclarations.unshift(`device ${convertTypeToWHLSLType(type)}[] result : register(u0)`); 227 argsDeclarations.unshift(`device ${whlslArgumentType(type)}[] result : register(u0)`); 228 let callCode = `${name}(${functionCallArgs.join(", ")})`; 229 callCode = convertToWHLSLOutputType(callCode, type); 200 230 entryPointCode = ` 201 231 [numthreads(1, 1, 1)] 202 232 compute void _compute_main(${argsDeclarations.join(", ")}) 203 233 { 204 result[0] = ${ name}(${functionCallArgs.join(", ")});234 result[0] = ${callCode}; 205 235 } 206 236 `; … … 226 256 throw new Error("Harness error: Unable to read results!"); 227 257 } 228 const array = new (convertTypeToArrayType(t ype))(result);258 const array = new (convertTypeToArrayType(this._isWHLSL, type))(result); 229 259 this._resultBuffer.unmap(); 230 260 … … 302 332 const arg = args[i - 1]; 303 333 if (this._isWHLSL) { 304 argsDeclarations.push(`device ${ convertTypeToWHLSLType(arg.type)}[] arg${i} : register(u${i})`);305 functionCallArgs.push( `arg${i}` + (arg.isBuffer ? "" : "[0]"));334 argsDeclarations.push(`device ${whlslArgumentType(arg.type)}[] arg${i} : register(u${i})`); 335 functionCallArgs.push(convertToWHLSLInputType(`arg${i}` + (arg.isBuffer ? "" : "[0]"), arg.type)); 306 336 } else { 307 337 argsDeclarations.push(`device ${convertTypeToWHLSLType(arg.type)}* arg${i} [[id(${i})]];`); -
trunk/LayoutTests/webgpu/whlsl-test-harness-test-expected.txt
r246824 r247067 1 1 2 PASS Return a literal of type bool. 2 3 PASS Return an expected float4 value. 3 4 PASS Return an expected int value. 4 5 PASS Return an expected uint value. 5 6 PASS Return an expected float value. 7 PASS Upload and return a bool value. 6 8 PASS Return an expected float4 value. 7 9 PASS Return an expected int value. 8 10 PASS Return an expected uint value. 9 11 PASS Return an expected float value. 12 PASS Upload many bool values and return a calculated result. 10 13 PASS Return an expected float4 value. 11 14 PASS Return an expected int value. -
trunk/LayoutTests/webgpu/whlsl-test-harness-test.html
r246824 r247067 59 59 whlslTests.buffersWithOneValue = () => { 60 60 const body = `return in0[0];` 61 checkBools("Access and return a single bool through a bool[].", body, [[true]]);62 61 checkFloat4s(body, [[[0, 1, 2, 3]]]); 63 62 checkNumericScalars(body, [[42]], 42); … … 65 64 66 65 whlslTests.multipleBufferArguments = () => { 67 checkBools("Access multiple bools through various buffers and return a bool.",68 "return in0[0] & in0[1] & in0[2] & in1 & in2[0];",69 [[true, true, true], true, [true]]);70 71 66 let body = ` 72 67 float x = in0[0].x + in0[1].x + in0[2].x + in1.x + in2[0].x; … … 169 164 170 165 const checkBools = (msg = "Return an expected bool value.", body, argValues = [], expected = true) => { 171 // FIXME (https://webkit.org/b/199093): Bool[] functions don't compile, so no-op for now.172 return;173 174 166 const [src, name, values] = appendScalarFunctionToSource("", "bool", body, argValues); 175 167 -
trunk/Source/WebCore/ChangeLog
r247064 r247067 1 2019-07-02 Saam Barati <sbarati@apple.com> 2 3 [WHLSL] Import bitwise bool tests 4 https://bugs.webkit.org/show_bug.cgi?id=199093 5 6 Reviewed by Myles C. Maxfield. 7 8 Add standard library functions for: 9 - bool bit ops 10 - converting from bool to number 11 - converting from number to bool 12 13 Test: webgpu/whlsl-bitwise-bool-ops.html 14 15 * Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt: 16 1 17 2019-07-02 Takashi Komori <Takashi.Komori@sony.com> 2 18 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt
r246875 r247067 744 744 return result; 745 745 } 746 747 native bool operator==(uchar, uchar); 748 native bool operator==(ushort, ushort); 749 native bool operator==(char, char); 750 native bool operator==(short, short); 751 native bool operator==(half, half); 746 752 747 753 native int operator+(int, int); … … 1173 1179 native void GetDimensions(Texture2D<float4>, uint MipLevel, threadgroup uint* Width, threadgroup uint* Height, threadgroup uint* NumberOfLevels); 1174 1180 1181 1182 native bool operator==(bool, bool); 1183 native bool operator&&(bool, bool); 1184 native bool operator||(bool, bool); 1185 bool operator&(bool a, bool b) { 1186 return a && b; 1187 } 1188 bool operator|(bool a, bool b) { 1189 return a || b; 1190 } 1191 bool operator^(bool a, bool b) { 1192 if (a) 1193 return !b; 1194 return b; 1195 } 1196 bool operator~(bool value) { 1197 return !value; 1198 } 1199 1200 operator bool(uchar x) { 1201 return x != 0; 1202 } 1203 operator bool(ushort x) { 1204 return x != 0; 1205 } 1206 operator bool(uint x) { 1207 return x != 0; 1208 } 1209 operator bool(char x) { 1210 return x != 0; 1211 } 1212 operator bool(short x) { 1213 return x != 0; 1214 } 1215 operator bool(int x) { 1216 return x != 0; 1217 } 1218 operator bool(half x) { 1219 return x != 0; 1220 } 1221 operator bool(float x) { 1222 return x != 0; 1223 } 1224 1225 operator int(bool x) { 1226 return x ? 1 : 0; 1227 } 1228 1175 1229 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=192890 Insert the rest of the standard library once the parser is fast enough
Note: See TracChangeset
for help on using the changeset viewer.