Skip to content

Commit

Permalink
Made more progess on 2D texture array blitting. Now I need to investi…
Browse files Browse the repository at this point in the history
…gate why the sampler isn't working in the Blit2DArray example.
  • Loading branch information
klukaszek committed Jan 9, 2025
1 parent dedcbf4 commit 951bce5
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/gpu/webgpu/SDL_gpu_webgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
#include <SDL3/SDL_hints.h>
#include <SDL3/SDL_mutex.h>
#include <SDL3/SDL_oldnames.h>
#include <SDL3/SDL_pixels.h>
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_render.h>
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_video.h>
#include <emscripten/emscripten.h>
#include <emscripten/html5.h>
#include <regex.h>
Expand Down Expand Up @@ -388,6 +390,7 @@ typedef struct WebGPURenderer
bool preferLowPower;

SDL_GPUDevice *sdlDevice;
SDL_PixelFormat pixelFormat;

WGPUInstance instance;
WGPUAdapter adapter;
Expand Down Expand Up @@ -442,6 +445,8 @@ static WGPULoadOp SDLToWGPULoadOp(SDL_GPULoadOp loadOp)
return WGPULoadOp_Load;
case SDL_GPU_LOADOP_CLEAR:
return WGPULoadOp_Clear;
case SDL_GPU_LOADOP_DONT_CARE:
return WGPULoadOp_Clear;
default:
return WGPULoadOp_Clear;
}
Expand Down Expand Up @@ -3424,12 +3429,19 @@ static void WebGPU_UploadToTexture(SDL_GPUCommandBuffer *commandBuffer,
}

WebGPUCommandBuffer *wgpu_cmd_buf = (WebGPUCommandBuffer *)commandBuffer;
WebGPURenderer *renderer = (WebGPURenderer *)wgpu_cmd_buf->renderer;
WebGPUTexture *webgpuTexture = (WebGPUTexture *)destination->texture;
WebGPUBuffer *transfer_buffer = (WebGPUBuffer *)source->transfer_buffer;

// TODO: Set up some HDR compatibility checks here
// For now we'll just take the PixelFormat that SDL gives us;
if (renderer->pixelFormat == SDL_PIXELFORMAT_UNKNOWN) {
renderer->pixelFormat = SDL_GetWindowPixelFormat(renderer->claimedWindows[0]->window);
}

WGPUTextureDataLayout dataLayout = {
.offset = source->offset,
.bytesPerRow = destination->w * 4, // 4 bytes per RGBA8 pixel
.bytesPerRow = destination->w * SDL_GetPixelFormatDetails(wgpu_cmd_buf->renderer->pixelFormat)->bytes_per_pixel,
.rowsPerImage = destination->h,
};

Expand All @@ -3440,21 +3452,19 @@ static void WebGPU_UploadToTexture(SDL_GPUCommandBuffer *commandBuffer,
.origin = (WGPUOrigin3D){
.x = destination->x,
.y = destination->y,
.z = destination->z,
.z = destination->layer, // layer index we are looking to transfer to
},
.aspect = WGPUTextureAspect_All,
};

WGPUExtent3D extent = {
.width = destination->w,
.height = destination->h,
.depthOrArrayLayers = destination->d,
.depthOrArrayLayers = destination->d, // total "depth" of texture
};

SDL_Log("Copy Texture depthOrArrayLayers: %u", extent.depthOrArrayLayers);

wgpuQueueWriteTexture(
wgpu_cmd_buf->renderer->queue,
renderer->queue,
&copyTexture,
transfer_buffer->mappedData,
transfer_buffer->size, // Make sure this matches exactly what we need
Expand Down Expand Up @@ -4216,9 +4226,8 @@ static void WebGPU_DestroyDevice(SDL_GPUDevice *device)

/*// Destroy the device*/
wgpuDeviceDestroy(renderer->device);

wgpuAdapterRelease(renderer->adapter);
wgpuInstanceRelease(renderer->instance);
wgpuAdapterRelease(renderer->adapter);

// Free the renderer
SDL_free(renderer);
Expand Down

0 comments on commit 951bce5

Please sign in to comment.