@antv/g-webgpu-compiler
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -24,3 +24,3 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
}; | ||
export var builtinFunctions = (_builtinFunctions = {}, _defineProperty(_builtinFunctions, Target.WebGL, "\nvec2 addrTranslation_1Dto2D(float address1D, vec2 texSize) {\n vec2 conv_const = vec2(1.0 / texSize.x, 1.0 / (texSize.x * texSize.y));\n vec2 normAddr2D = float(address1D) * conv_const;\n return vec2(fract(normAddr2D.x), normAddr2D.y);\n}\n\nvoid barrier() {}\n "), _defineProperty(_builtinFunctions, Target.WebGPU, ''), _builtinFunctions); | ||
export var builtinFunctions = (_builtinFunctions = {}, _defineProperty(_builtinFunctions, Target.WebGL, "\nfloat epsilon = 0.00001;\nvec2 addrTranslation_1Dto2D(float address1D, vec2 texSize) {\n vec2 conv_const = vec2(1.0 / texSize.x, 1.0 / (texSize.x * texSize.y));\n vec2 normAddr2D = float(address1D) * conv_const;\n return vec2(fract(normAddr2D.x + epsilon), normAddr2D.y);\n}\n\nvoid barrier() {}\n "), _defineProperty(_builtinFunctions, Target.WebGPU, ''), _builtinFunctions); | ||
export var exportFunctions = (_exportFunctions = {}, _defineProperty(_exportFunctions, Target.WebGL, { | ||
@@ -27,0 +27,0 @@ debug: { |
@@ -37,2 +37,6 @@ /// <reference types="@webgpu/types" /> | ||
/** | ||
* 是否需要 pingpong,如果存在输入和输出为同一个的情况 | ||
*/ | ||
needPingpong: boolean; | ||
/** | ||
* 目前仅支持单一输出,受限于 WebGL 实现 | ||
@@ -39,0 +43,0 @@ */ |
@@ -0,1 +1,2 @@ | ||
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; | ||
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; | ||
@@ -60,3 +61,4 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
name: '' | ||
} | ||
}, | ||
needPingpong: false | ||
}; | ||
@@ -208,3 +210,4 @@ this.generators = (_this$generators = {}, _defineProperty(_this$generators, Target.WebGPU, new WebGPUShaderGenerator()), _defineProperty(_this$generators, Target.WebGL, new WebGLShaderGenerator()), _this$generators); | ||
name: '' | ||
} | ||
}, | ||
needPingpong: false | ||
}; | ||
@@ -507,4 +510,26 @@ } | ||
} else if (node.property.type === AST_NODE_TYPES.Literal && isFinite(Number(node.property.value))) { | ||
// vec[0] | ||
return "".concat(node.object.name, "[").concat(node.property.value, "]"); | ||
var index = Number(node.property.value); | ||
var swizzlingComponent = 'x'; | ||
switch (index) { | ||
case 0: | ||
swizzlingComponent = 'x'; | ||
break; | ||
case 1: | ||
swizzlingComponent = 'y'; | ||
break; | ||
case 2: | ||
swizzlingComponent = 'z'; | ||
break; | ||
case 3: | ||
swizzlingComponent = 'w'; | ||
break; | ||
} // vec[0] | ||
// 考虑 getData()[0] 的情况,转译成 getData().x | ||
return "".concat(node.object.name, ".").concat(swizzlingComponent); | ||
} else { | ||
@@ -523,5 +548,20 @@ // data[a + b] | ||
if (_type) { | ||
var elementType = _type[0] === 'v' ? 'float' : 'number'; // vec3(1.0, 2.0, 3.0) | ||
var elementType = _type[0] === 'v' ? 'float' : 'number'; | ||
var sizePerElement = 1; | ||
return "".concat(_type, "(").concat(node.elements.map(function (e) { | ||
if (_type.endsWith('ec4')) { | ||
sizePerElement = 4; | ||
} else if (_type.endsWith('ec3')) { | ||
sizePerElement = 3; | ||
} else if (_type.endsWith('ec2')) { | ||
sizePerElement = 2; | ||
} | ||
var emptyComponents = new Array(sizePerElement - node.elements.length).fill({ | ||
type: AST_NODE_TYPES.Literal, | ||
value: 0 | ||
}); // 需要用 0 补齐缺少的分量,避免 vec4(vec2()) 报错的情况 | ||
// vec3(1.0, 2.0, 3.0) | ||
return "".concat(_type, "(").concat([].concat(_toConsumableArray(node.elements), _toConsumableArray(emptyComponents)).map(function (e) { | ||
return _this5.compileExpression(e, context, elementType, isLeft); | ||
@@ -899,2 +939,11 @@ }).join(','), ")"); | ||
}); | ||
if (analyzeDecorators.find(function (d) { | ||
return d.name === PropertyDecorator.Out; | ||
}) && analyzeDecorators.find(function (d) { | ||
return d.name === PropertyDecorator.In; | ||
})) { | ||
this.glslContext.needPingpong = true; | ||
} | ||
analyzeDecorators.forEach(function (_ref2) { | ||
@@ -901,0 +950,0 @@ var name = _ref2.name, |
@@ -39,3 +39,3 @@ "use strict"; | ||
exports.typePriority = typePriority; | ||
var builtinFunctions = (_builtinFunctions = {}, (0, _defineProperty2.default)(_builtinFunctions, Target.WebGL, "\nvec2 addrTranslation_1Dto2D(float address1D, vec2 texSize) {\n vec2 conv_const = vec2(1.0 / texSize.x, 1.0 / (texSize.x * texSize.y));\n vec2 normAddr2D = float(address1D) * conv_const;\n return vec2(fract(normAddr2D.x), normAddr2D.y);\n}\n\nvoid barrier() {}\n "), (0, _defineProperty2.default)(_builtinFunctions, Target.WebGPU, ''), _builtinFunctions); | ||
var builtinFunctions = (_builtinFunctions = {}, (0, _defineProperty2.default)(_builtinFunctions, Target.WebGL, "\nfloat epsilon = 0.00001;\nvec2 addrTranslation_1Dto2D(float address1D, vec2 texSize) {\n vec2 conv_const = vec2(1.0 / texSize.x, 1.0 / (texSize.x * texSize.y));\n vec2 normAddr2D = float(address1D) * conv_const;\n return vec2(fract(normAddr2D.x + epsilon), normAddr2D.y);\n}\n\nvoid barrier() {}\n "), (0, _defineProperty2.default)(_builtinFunctions, Target.WebGPU, ''), _builtinFunctions); | ||
exports.builtinFunctions = builtinFunctions; | ||
@@ -42,0 +42,0 @@ var exportFunctions = (_exportFunctions = {}, (0, _defineProperty2.default)(_exportFunctions, Target.WebGL, { |
@@ -10,2 +10,4 @@ "use strict"; | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
@@ -78,3 +80,4 @@ | ||
name: '' | ||
} | ||
}, | ||
needPingpong: false | ||
}; | ||
@@ -226,3 +229,4 @@ this.generators = (_this$generators = {}, (0, _defineProperty2.default)(_this$generators, Target.WebGPU, new _webgpu.WebGPUShaderGenerator()), (0, _defineProperty2.default)(_this$generators, Target.WebGL, new _webgl.WebGLShaderGenerator()), _this$generators); | ||
name: '' | ||
} | ||
}, | ||
needPingpong: false | ||
}; | ||
@@ -525,4 +529,26 @@ } | ||
} else if (node.property.type === _astNodeTypes.AST_NODE_TYPES.Literal && (0, _isFinite.default)(Number(node.property.value))) { | ||
// vec[0] | ||
return "".concat(node.object.name, "[").concat(node.property.value, "]"); | ||
var index = Number(node.property.value); | ||
var swizzlingComponent = 'x'; | ||
switch (index) { | ||
case 0: | ||
swizzlingComponent = 'x'; | ||
break; | ||
case 1: | ||
swizzlingComponent = 'y'; | ||
break; | ||
case 2: | ||
swizzlingComponent = 'z'; | ||
break; | ||
case 3: | ||
swizzlingComponent = 'w'; | ||
break; | ||
} // vec[0] | ||
// 考虑 getData()[0] 的情况,转译成 getData().x | ||
return "".concat(node.object.name, ".").concat(swizzlingComponent); | ||
} else { | ||
@@ -541,5 +567,20 @@ // data[a + b] | ||
if (_type) { | ||
var elementType = _type[0] === 'v' ? 'float' : 'number'; // vec3(1.0, 2.0, 3.0) | ||
var elementType = _type[0] === 'v' ? 'float' : 'number'; | ||
var sizePerElement = 1; | ||
return "".concat(_type, "(").concat(node.elements.map(function (e) { | ||
if (_type.endsWith('ec4')) { | ||
sizePerElement = 4; | ||
} else if (_type.endsWith('ec3')) { | ||
sizePerElement = 3; | ||
} else if (_type.endsWith('ec2')) { | ||
sizePerElement = 2; | ||
} | ||
var emptyComponents = new Array(sizePerElement - node.elements.length).fill({ | ||
type: _astNodeTypes.AST_NODE_TYPES.Literal, | ||
value: 0 | ||
}); // 需要用 0 补齐缺少的分量,避免 vec4(vec2()) 报错的情况 | ||
// vec3(1.0, 2.0, 3.0) | ||
return "".concat(_type, "(").concat([].concat((0, _toConsumableArray2.default)(node.elements), (0, _toConsumableArray2.default)(emptyComponents)).map(function (e) { | ||
return _this5.compileExpression(e, context, elementType, isLeft); | ||
@@ -917,2 +958,11 @@ }).join(','), ")"); | ||
}); | ||
if (analyzeDecorators.find(function (d) { | ||
return d.name === PropertyDecorator.Out; | ||
}) && analyzeDecorators.find(function (d) { | ||
return d.name === PropertyDecorator.In; | ||
})) { | ||
this.glslContext.needPingpong = true; | ||
} | ||
analyzeDecorators.forEach(function (_ref2) { | ||
@@ -919,0 +969,0 @@ var name = _ref2.name, |
{ | ||
"name": "@antv/g-webgpu-compiler", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "", | ||
@@ -36,3 +36,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "74fb112a31addaaee0498dce8339e6f240934e82" | ||
"gitHead": "c91fd340ae86a05d8b1009ad7447888530b26834" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2804286
29733