Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions src/strands/ir_builders.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,38 +344,24 @@ export function castToFloat(strandsContext, dep) {
return createStrandsNode(id, dimension, strandsContext);
}

export function structConstructorNode(strandsContext, structTypeInfo, rawUserArgs) {
export function structConstructorNode(strandsContext, structTypeInfo, dependsOn) {
const { cfg, dag } = strandsContext;
const { identifer, properties } = structTypeInfo;
const { properties } = structTypeInfo;

if (!(rawUserArgs.length === properties.length)) {
if (dependsOn.length !== properties.length) {
FES.userError('type error',
`You've tried to construct a ${structTypeInfo.typeName} struct with ${rawUserArgs.length} properties, but it expects ${properties.length} properties.\n` +
`You've tried to construct a ${structTypeInfo.typeName} struct with ${dependsOn.length} properties, but it expects ${properties.length} properties.\n` +
`The properties it expects are:\n` +
`${properties.map(prop => prop.name + ' ' + prop.DataType.baseType + prop.DataType.dimension)}`
`${properties.map(prop => `${prop.name}: ${prop.dataType.baseType}${prop.dataType.dimension}`).join(', ')}`
);
}

const dependsOn = [];
for (let i = 0; i < properties.length; i++) {
const expectedProperty = properties[i];
const { originalNodeID, mappedDependencies } = mapPrimitiveDepsToIDs(strandsContext, expectedProperty.dataType, rawUserArgs[i]);
if (originalNodeID) {
dependsOn.push(originalNodeID);
}
else {
dependsOn.push(
constructTypeFromIDs(strandsContext, expectedProperty.dataType, mappedDependencies)
);
}
}

const nodeData = DAG.createNodeData({
nodeType: NodeType.OPERATION,
opCode: OpCode.Nary.CONSTRUCTOR,
dimension: properties.length,
baseType: structTypeInfo.typeName ,
dependsOn
baseType: structTypeInfo.typeName,
dependsOn,
});
const id = DAG.getOrCreateNode(dag, nodeData);
CFG.recordInBasicBlock(cfg, cfg.currentBlock, id);
Expand Down
2 changes: 1 addition & 1 deletion src/webgl/strands_glslBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export const glslBackend = {
}
const dag = strandsContext.dag;
const rootNode = getNodeDataFromID(dag, rootNodeID);
if (isStructType(returnType)) {
if (isStructType(returnType) && rootNode.identifier) {
const structTypeInfo = returnType;
for (let i = 0; i < structTypeInfo.properties.length; i++) {
const prop = structTypeInfo.properties[i];
Expand Down
2 changes: 1 addition & 1 deletion src/webgpu/strands_wgslBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export const wgslBackend = {
}
const dag = strandsContext.dag;
const rootNode = getNodeDataFromID(dag, rootNodeID);
if (isStructType(returnType)) {
if (isStructType(returnType) && rootNode.identifier) {
const structTypeInfo = returnType;
for (let i = 0; i < structTypeInfo.properties.length; i++) {
const prop = structTypeInfo.properties[i];
Expand Down
19 changes: 19 additions & 0 deletions test/unit/visual/cases/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,25 @@ visualTest('randomGaussian() in a fragment loop averages to the mean', (p5, scre
p5.circle(0, 0, 30);
screenshot();
});

visualTest('hook returning a fresh struct (not the struct argument) applies modifications', (p5, screenshot) => {
p5.createCanvas(50, 50, p5.WEBGL);
const shader = p5.baseMaterialShader().modify(() => {
p5.worldInputs.begin();
p5.worldInputs.set({
position: p5.worldInputs.position.add([10, 0, 0]),
normal: p5.worldInputs.normal,
texCoord: p5.worldInputs.texCoord,
color: [1, 0, 0, 1],
});
p5.worldInputs.end();
}, { p5 });
p5.background(0);
p5.noStroke();
p5.shader(shader);
p5.plane(20, 20);
screenshot();
});
});

visualSuite('background()', function () {
Expand Down
19 changes: 19 additions & 0 deletions test/unit/visual/cases/webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,25 @@ visualSuite("WebGPU", function () {
p5.plane(50, 50);
await screenshot();
});

visualTest('hook returning a fresh struct (not the struct argument) applies modifications', async function(p5, screenshot) {
await p5.createCanvas(50, 50, p5.WEBGPU);
const shader = p5.baseMaterialShader().modify(() => {
p5.worldInputs.begin();
p5.worldInputs.set({
position: p5.worldInputs.position.add([10, 0, 0]),
normal: p5.worldInputs.normal,
texCoord: p5.worldInputs.texCoord,
color: [1, 0, 0, 1],
});
p5.worldInputs.end();
}, { p5 });
p5.background(0);
p5.noStroke();
p5.shader(shader);
p5.plane(20, 20);
await screenshot();
}, { focus: true });
});

visualTest('randomGaussian() colors a basic shader (WebGPU)', async function(p5, screenshot) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"numScreenshots": 1
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"numScreenshots": 1
}
Loading