Skip to content

Commit

Permalink
Got textures working but there seems to be some bugged pixels.
Browse files Browse the repository at this point in the history
  • Loading branch information
klukaszek committed Oct 26, 2024
1 parent d0ac6f1 commit 3b0a620
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/gpu/webgpu/SDL_gpu_webgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ static WGPUTextureUsageFlags SDLToWGPUTextureUsageFlags(SDL_GPUTextureUsageFlags
WGPUTextureUsageFlags wgpuFlags;
switch (usageFlags) {
case SDL_GPU_TEXTUREUSAGE_SAMPLER:
wgpuFlags = WGPUTextureUsage_TextureBinding;
wgpuFlags = WGPUTextureUsage_TextureBinding | WGPUTextureUsage_CopyDst;
break;
case SDL_GPU_TEXTUREUSAGE_COLOR_TARGET:
case SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET:
Expand Down Expand Up @@ -2782,8 +2782,8 @@ static void WebGPU_SetTextureName(
container->debugName = SDL_strdup(name);

// Set the texture view name
wgpuTextureViewSetLabel(webgpuTexture->fullView, name);
wgpuTextureSetLabel(webgpuTexture->texture, name);
wgpuTextureViewSetLabel(webgpuTexture->fullView, name);
}

static void WebGPU_UploadToTexture(SDL_GPUCommandBuffer *commandBuffer,
Expand All @@ -2796,6 +2796,44 @@ static void WebGPU_UploadToTexture(SDL_GPUCommandBuffer *commandBuffer,
SDL_LogError(SDL_LOG_CATEGORY_GPU, "Invalid parameters for uploading to texture");
return;
}

WebGPUCommandBuffer *wgpuCmdBuf = (WebGPUCommandBuffer *)commandBuffer;
WebGPUTextureContainer *tex_container = (WebGPUTextureContainer *)destination->texture;
WebGPUTextureHandle *textureHandle = tex_container->activeTextureHandle;
WebGPUTexture *webgpuTexture = textureHandle->webgpuTexture;

// Create the texture data
WGPUTextureDataLayout dataLayout = {
.offset = source->offset,
.bytesPerRow = destination->w * sizeof(Uint32),
.rowsPerImage = destination->h,
};

WGPUImageCopyTexture copyTexture = {
.texture = webgpuTexture->texture,
.mipLevel = destination->mip_level,
.origin = (WGPUOrigin3D){
.x = destination->x,
.y = destination->y,
.z = destination->z,
},
};

WebGPUBufferContainer *buf_container = (WebGPUBufferContainer *)source->transfer_buffer;
WebGPUBufferHandle *bufferHandle = buf_container->activeBufferHandle;
WebGPUBuffer *transfer_buffer = bufferHandle->webgpuBuffer;

// Create the texture region
WGPUExtent3D extent = {
.width = destination->w,
.height = destination->h,
.depthOrArrayLayers = destination->d,
};

Uint32 size = transfer_buffer->size;
void *data = transfer_buffer->mappedData;

wgpuQueueWriteTexture(wgpuCmdBuf->renderer->queue, &copyTexture, data, size, &dataLayout, &extent);
}

static SDL_GPUSampler *WebGPU_CreateSampler(
Expand Down

0 comments on commit 3b0a620

Please sign in to comment.