-
Notifications
You must be signed in to change notification settings - Fork 2k
webgpu: Make fromPixels not so special #6549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
dc53dc9 to
ee3cb16
Compare
qjia7
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
| // Short-circuit the computation since the result is empty (has 0 in its | ||
| // shape). | ||
| const outData = this.tensorMap.get(output.dataId); | ||
| outData.values = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a situation that output is not null, but output.shape is 0, output is not recorded in tensorMap? if so, outData is null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the tensor should be recorded in tensorMap. If output is not null, then it's already recorded.
| this.device, program, pipelineLayout, inputsData, output); | ||
| }); | ||
| const pipeline = key in this.pipelineCache ? | ||
| this.pipelineCache[key] : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the place to add elements into pipelineCache?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, will fix in next update.
qjia7
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also check whether all fromPixels cases pass if set WEBGPU_USE_IMPORT to true.
| const tensorData = this.tensorMap.get(tensor.dataId); | ||
|
|
||
| if (tensorData.textureInfo) { | ||
| return (tensorData.textureInfo.texture as GPUTexture).createView(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forget the situation that tensorData.textureInfo.texture may be a GPUExternalTexture?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| const externalTextureDescriptor = {source: pixels as HTMLVideoElement}; | ||
| texture = backend.device.importExternalTexture(externalTextureDescriptor); | ||
| textureInfo = { | ||
| width: pixels.width, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you directly use the width height variables? pixels.width and pixels.height may not equal to width height in outputShape (see L57).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| format: textureFormat, | ||
| usage: textureUsage, | ||
| return { | ||
| width: externalImage.width, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be careful that externalImage.width may be not equal to outShape[1]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| }); | ||
| this.uniformDisposalQueue.forEach( | ||
| d => this.bufferManager.releaseBuffer(d.buffer, d.byteSize, d.usage)); | ||
| d => this.bufferManager.releaseBuffer(d.buffer, d.size, d.usage)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Maybe we can merge releaseResource and releaseBuffer in the next change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
releaseResource includes the buffer and texture management, so they don't need to be merged.
|
@qjia7 I enabled the fromPixels tests with both WEBGPU_USE_IMPORT true and false, and make sure the video is correctly loaded. Please take another look. Thanks! |
qjia7
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
|
@xhcao Will you take another look at this PR? |
xhcao
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
|
Has anyone encountered this error after the change? |
|
I did more tests today:
|
|
I suggest to open a separate issue for this. Like we discussed in the meeting, can you report the readyState? The Error triggered in TFJS is not necessary and wrong, maybe we can simply remove it. |
This is to unify the implementation of fromPixels with other ops for better maintenance.
Close #5536
To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.
This change is