core: Fix parsing of PixelBender sampleNearest and sampleLinear

This fixes a panic on startup for Sniper Team
This commit is contained in:
Aaron Hill 2023-06-04 02:18:53 -05:00
parent ccb5027de0
commit d2999a2572
6 changed files with 39 additions and 4 deletions

View File

@ -212,6 +212,18 @@ pub enum Operation {
If {
src: u32,
},
SampleNearest {
dst: u16,
src: u32,
mask: u8,
tf: u8,
},
SampleLinear {
dst: u16,
src: u32,
mask: u8,
tf: u8,
},
Else,
EndIf,
}
@ -367,11 +379,30 @@ fn read_op<R: Read>(
.push(Operation::LoadFloat { dst, mask, val })
}
}
Opcode::SampleNearest | Opcode::SampleLinear => {
let dst = data.read_u16::<LittleEndian>()?;
let mask = data.read_u8()?;
let src = read_uint24(data)?;
let tf = data.read_u8()?;
match opcode {
Opcode::SampleNearest => {
shader
.operations
.push(Operation::SampleNearest { dst, mask, src, tf })
}
Opcode::SampleLinear => {
shader
.operations
.push(Operation::SampleLinear { dst, mask, src, tf })
}
_ => unreachable!(),
}
}
_ => {
let dst = data.read_u16::<LittleEndian>()?;
let mask = data.read_u8()?;
let src = read_uint24(data)?;
assert_eq!(data.read_u8()?, 0);
assert_eq!(data.read_u8()?, 0, "Unexpected u8 for opcode {opcode:?}");
shader.operations.push(Operation::Normal {
opcode,
dst,

View File

@ -183,12 +183,11 @@ fn simple_shader() {
src: 19,
other: 0,
},
Operation::Normal {
opcode: Opcode::SampleNearest,
Operation::SampleNearest {
dst: 3,
mask: 241,
src: 16,
other: 0,
tf: 0,
},
Operation::LoadFloat {
dst: 4,

View File

@ -2,6 +2,8 @@
description: A shader that does nothing, but does it well. (String)
name: DoNothing (String)
namespace: Adobe::Example (String)
otherSrc: [object ShaderInput] (flash.display::ShaderInput)
name: otherSrc (String)
radius: [object ShaderParameter] (flash.display::ShaderParameter)
defaultValue: 25 (Array)
0: 25 (int)

View File

@ -30,9 +30,12 @@
defaultValue: 25.0;
>;
input image4 otherSrc;
void evaluatePixel()
{
float2 one = (radius / radius) * (size / size);
float4 two = sampleLinear(otherSrc, float2(1.0, 2.0));
dst = sampleNearest(src, outCoord()) + float4(100.0, 0.0, 100.0, 1.0);
}
}