Skip to content

Commit 61716d9

Browse files
Merge pull request #416 from JingyuanZhang/master
fix(webgl): close pack_output in webgl 1.0
2 parents 1d06bec + 4527bd3 commit 61716d9

File tree

8 files changed

+12
-19
lines changed

8 files changed

+12
-19
lines changed

e2e/jest-puppeteer.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
server: {
99
command: './node_modules/ts-node/dist/bin.js e2e/server.ts',
1010
port: 9898,
11-
launchTimeout: 50000,
11+
launchTimeout: 80000,
1212
debug: true
1313
}
1414
};

packages/paddlejs-backend-webgl/src/backend.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,8 @@ export default class WebGLBackend extends PaddlejsBackend {
156156

157157
const pbo = this.createPBO();
158158
await this.createAndWaitForFence();
159-
const result = this.downloadFloat32TensorFromBuffer(pbo);
160-
161159
const shape = fetchInfo ? fetchInfo.shape : [];
162-
if (env.get('webgl_pack_output')) {
163-
return result.slice(0, getSizeFromShape(shape));
164-
}
165-
166-
return result;
160+
return this.downloadFloat32TensorFromBuffer(pbo, shape);
167161
}
168162

169163
createPBO() {
@@ -234,25 +228,23 @@ export default class WebGLBackend extends PaddlejsBackend {
234228
fn();
235229
}
236230

237-
downloadFloat32TensorFromBuffer(buffer) {
231+
downloadFloat32TensorFromBuffer(buffer, shape) {
238232
const size: number = 4 * this.width_texture_out * this.height_texture_out;
239233
if (this.glVersion === 2) {
240234
const gl2 = this.gl as WebGL2RenderingContext;
241235
const pixels = new Float32Array(size);
242236
gl2.bindBuffer(gl2.PIXEL_PACK_BUFFER, buffer);
243237
gl2.getBufferSubData(gl2.PIXEL_PACK_BUFFER, 0, pixels);
244238
gl2.bindBuffer(gl2.PIXEL_PACK_BUFFER, null);
245-
246239
const result: number[] = [];
247240
if (env.get('webgl_pack_output')) {
248-
return Array.from(pixels);
241+
return Array.from(pixels).slice(0, getSizeFromShape(shape));
249242
}
250243
for (let i = 0; i < this.width_texture_out * this.height_texture_out; i++) {
251244
result.push(pixels[4 * i]);
252245
}
253246
return result;
254247
}
255-
256248
const pixels = buffer;
257249
const result = [] as number[];
258250
for (let i = 0; i < this.width_texture_out * this.height_texture_out; i++) {

packages/paddlejs-backend-webgl/src/ops/shader/custom/imgFeed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function mainFunc() {
1010
void main(void) {
1111
vec2 outCoord = vCoord.xy;
1212
// 支持模型不按比例拉伸
13-
if (u_keep_ratio > 0) {
13+
if (u_keep_ratio == 0) {
1414
vec4 origin = TEXTURE2D(texture_origin, outCoord);
1515
setPackedOutput(origin);
1616
return;

packages/paddlejs-backend-webgl/src/webgl/WebGLTexture.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,12 @@ export class GLTexture {
176176

177177
if (
178178
data instanceof Uint8Array
179-
|| data instanceof Uint8ClampedArray
180-
|| !(data instanceof Float32Array || data instanceof Array)) {
179+
|| data instanceof Uint8ClampedArray) {
181180
// case1: 输入为0~255之间的像素数据,类型为Uint8Array 或 Uint8ClampedArray
182181
// case2: 小程序环境,输入数据可能是HTMLImageElement、HTMLVideoElement、HTMLCanvasElement、小程序中图像的临时path string。
183182
texeltype = gl.UNSIGNED_BYTE;
183+
}
184+
else if (!(data instanceof Float32Array || data instanceof Array)) {
184185
gl.texImage2D(
185186
gl.TEXTURE_2D,
186187
0,

packages/paddlejs-core/src/runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export default class Runner {
281281

282282
const {
283283
webglFeedProcess = false,
284-
keepRatio = false
284+
keepRatio = true
285285
} = this.runnerConfig;
286286
if (webglFeedProcess || env.get('webgl_gpu_pipeline')) {
287287
// support imageDataLike feed which has unit8ClampedArray data and width + height or shape

packages/paddlejs-core/src/transform/feedProcess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default class WebglFeedProcess extends Transformer {
9898
},
9999
u_keep_ratio: {
100100
type: UniformType.uniform1i,
101-
value: 0
101+
value: 1
102102
}
103103
},
104104
isPacked: true

packages/paddlejs-core/src/transform/packOutOp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default class PackOut extends Transformer {
1515
}
1616

1717
transform(...args: any) {
18-
if (!env.get('webgl_pack_output')) {
18+
if (!env.get('webgl_pack_output') || env.get('webglVersion') === 1) {
1919
return;
2020
}
2121
const [ops, vars] = args;

packages/paddlejs-models/detect/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export async function init() {
1414
mean: [0.5, 0.5, 0.5],
1515
std: [0.5, 0.5, 0.5],
1616
bgr: true,
17-
keepRatio: true,
17+
keepRatio: false,
1818
webglFeedProcess: true
1919
});
2020

0 commit comments

Comments
 (0)