Skip to content
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

WebGPU: Swapchain getCurrentTexture #21271

Merged
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
1 change: 1 addition & 0 deletions src/library_sigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,7 @@ sigs = {
wgpuSurfaceGetPreferredFormat__sig: 'ipp',
wgpuSurfaceReference__sig: 'vp',
wgpuSurfaceRelease__sig: 'vp',
wgpuSwapChainGetCurrentTexture__sig: 'pp',
wgpuSwapChainGetCurrentTextureView__sig: 'pp',
wgpuSwapChainPresent__sig: 'vp',
wgpuSwapChainReference__sig: 'vp',
Expand Down
4 changes: 4 additions & 0 deletions src/library_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2701,6 +2701,10 @@ var LibraryWebGPU = {
return WebGPU.mgrSwapChain.create(context);
},

wgpuSwapChainGetCurrentTexture: (swapChainId) => {
var context = WebGPU.mgrSwapChain.get(swapChainId);
return WebGPU.mgrTexture.create(context["getCurrentTexture"]());
},
wgpuSwapChainGetCurrentTextureView: (swapChainId) => {
var context = WebGPU.mgrSwapChain.get(swapChainId);
return WebGPU.mgrTextureView.create(context["getCurrentTexture"]()["createView"]());
Expand Down
2 changes: 2 additions & 0 deletions system/include/webgpu/webgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,7 @@ typedef void (*WGPUProcSurfaceReference)(WGPUSurface surface) WGPU_FUNCTION_ATTR
typedef void (*WGPUProcSurfaceRelease)(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE;

// Procs of SwapChain
typedef WGPUTexture (*WGPUProcSwapChainGetCurrentTexture)(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;
typedef WGPUTextureView (*WGPUProcSwapChainGetCurrentTextureView)(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;
typedef void (*WGPUProcSwapChainPresent)(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;
typedef void (*WGPUProcSwapChainReference)(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;
Expand Down Expand Up @@ -1775,6 +1776,7 @@ WGPU_EXPORT void wgpuSurfaceReference(WGPUSurface surface) WGPU_FUNCTION_ATTRIBU
WGPU_EXPORT void wgpuSurfaceRelease(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE;

// Methods of SwapChain
WGPU_EXPORT WGPUTexture wgpuSwapChainGetCurrentTexture(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;
WGPU_EXPORT WGPUTextureView wgpuSwapChainGetCurrentTextureView(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;
WGPU_EXPORT void wgpuSwapChainPresent(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;
WGPU_EXPORT void wgpuSwapChainReference(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE;
Expand Down
1 change: 1 addition & 0 deletions system/include/webgpu/webgpu_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,7 @@ namespace wgpu {
using ObjectBase::ObjectBase;
using ObjectBase::operator=;

Texture GetCurrentTexture() const;
TextureView GetCurrentTextureView() const;
void Present() const;

Expand Down
4 changes: 4 additions & 0 deletions system/lib/webgpu/webgpu_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2585,6 +2585,10 @@ template <typename T>
static_assert(sizeof(SwapChain) == sizeof(WGPUSwapChain), "sizeof mismatch for SwapChain");
static_assert(alignof(SwapChain) == alignof(WGPUSwapChain), "alignof mismatch for SwapChain");

Texture SwapChain::GetCurrentTexture() const {
auto result = wgpuSwapChainGetCurrentTexture(Get());
return Texture::Acquire(result);
}
TextureView SwapChain::GetCurrentTextureView() const {
auto result = wgpuSwapChainGetCurrentTextureView(Get());
return TextureView::Acquire(result);
Expand Down
Loading