summaryrefslogtreecommitdiff
path: root/tools/cnn_test.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-14 14:03:58 +0100
committerskal <pascal.massimino@gmail.com>2026-02-14 14:03:58 +0100
commit61ced8aa1946cc32de4328cc75b5faf6b77723be (patch)
tree142bad05c24362d7051e80acabaddd6bac2bb753 /tools/cnn_test.cc
parent197a03c24baba3acc35327e0e126ec49754f9945 (diff)
Refactor: add gpu_create_texture_view_2d helper
Reduces WGPUTextureViewDescriptor boilerplate from 5-7 lines to 1-2. Helper supports optional mip_levels parameter (defaults to 1). Updated 17 call sites across gpu/, tests/, and tools/. Net: -82 lines. All tests passing (34/34). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/cnn_test.cc')
-rw-r--r--tools/cnn_test.cc36
1 files changed, 8 insertions, 28 deletions
diff --git a/tools/cnn_test.cc b/tools/cnn_test.cc
index b4a4bdc..1d736d9 100644
--- a/tools/cnn_test.cc
+++ b/tools/cnn_test.cc
@@ -700,15 +700,8 @@ static bool process_cnn_v2(WGPUDevice device, WGPUQueue queue,
wgpuQueueWriteBuffer(queue, weights_buffer, 0, weights_data + weights_offset, weights_only_size);
// Create input view
- const WGPUTextureViewDescriptor view_desc = {
- .format = WGPUTextureFormat_BGRA8Unorm,
- .dimension = WGPUTextureViewDimension_2D,
- .baseMipLevel = 0,
- .mipLevelCount = 1,
- .baseArrayLayer = 0,
- .arrayLayerCount = 1,
- };
- WGPUTextureView input_view = wgpuTextureCreateView(input_texture, &view_desc);
+ WGPUTextureView input_view =
+ gpu_create_texture_view_2d(input_texture, WGPUTextureFormat_BGRA8Unorm);
// Create static features texture (RGBA32Uint)
const WGPUTextureDescriptor static_desc = {
@@ -1269,15 +1262,8 @@ int main(int argc, char** argv) {
printf("Using CNN v1 (render pipeline architecture)\n");
// Create input texture view
- const WGPUTextureViewDescriptor view_desc = {
- .format = WGPUTextureFormat_BGRA8Unorm,
- .dimension = WGPUTextureViewDimension_2D,
- .baseMipLevel = 0,
- .mipLevelCount = 1,
- .baseArrayLayer = 0,
- .arrayLayerCount = 1,
- };
- WGPUTextureView input_view = wgpuTextureCreateView(input_texture, &view_desc);
+ WGPUTextureView input_view =
+ gpu_create_texture_view_2d(input_texture, WGPUTextureFormat_BGRA8Unorm);
WGPUTextureView original_view = input_view; // Keep reference to original
// Create CNN pipelines (different formats for intermediate vs final)
@@ -1333,17 +1319,11 @@ int main(int argc, char** argv) {
};
// Create views for intermediate textures (RGBA16Float)
- const WGPUTextureViewDescriptor intermediate_view_desc = {
- .format = WGPUTextureFormat_RGBA16Float,
- .dimension = WGPUTextureViewDimension_2D,
- .baseMipLevel = 0,
- .mipLevelCount = 1,
- .baseArrayLayer = 0,
- .arrayLayerCount = 1,
- };
WGPUTextureView intermediate_views[2] = {
- wgpuTextureCreateView(intermediate_textures[0], &intermediate_view_desc),
- wgpuTextureCreateView(intermediate_textures[1], &intermediate_view_desc),
+ gpu_create_texture_view_2d(intermediate_textures[0],
+ WGPUTextureFormat_RGBA16Float),
+ gpu_create_texture_view_2d(intermediate_textures[1],
+ WGPUTextureFormat_RGBA16Float),
};
// Get sampler