Skip to content

Commit

Permalink
WebGPU: Swapchain getCurrentTexture (#21271)
Browse files Browse the repository at this point in the history
* WebGPU: added GetCurrentTexture method to swapchain.

* WebGPU: fix for GetCurrentTexture signature.
  • Loading branch information
coopersimon committed Feb 6, 2024
1 parent 288d475 commit c47d060
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
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 @@ -2710,6 +2710,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

0 comments on commit c47d060

Please sign in to comment.