summaryrefslogtreecommitdiff
path: root/src/gpu/texture_manager.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/texture_manager.cc')
-rw-r--r--src/gpu/texture_manager.cc47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/gpu/texture_manager.cc b/src/gpu/texture_manager.cc
index 7889283..5bca95b 100644
--- a/src/gpu/texture_manager.cc
+++ b/src/gpu/texture_manager.cc
@@ -125,8 +125,8 @@ WGPUTextureView TextureManager::get_texture_view(const std::string& name) {
}
WGPUComputePipeline TextureManager::get_or_create_compute_pipeline(
- const std::string& func_name, const char* shader_code,
- size_t uniform_size, int num_input_textures) {
+ const std::string& func_name, const char* shader_code, size_t uniform_size,
+ int num_input_textures) {
auto it = compute_pipelines_.find(func_name);
if (it != compute_pipelines_.end()) {
return it->second.pipeline;
@@ -149,7 +149,8 @@ WGPUComputePipeline TextureManager::get_or_create_compute_pipeline(
// Binding 1: uniform buffer
// Binding 2 to (2 + num_input_textures - 1): input textures
// Binding (2 + num_input_textures): sampler (if inputs > 0)
- const int max_entries = 2 + num_input_textures + (num_input_textures > 0 ? 1 : 0);
+ const int max_entries =
+ 2 + num_input_textures + (num_input_textures > 0 ? 1 : 0);
std::vector<WGPUBindGroupLayoutEntry> bgl_entries(max_entries);
// Binding 0: Output storage texture
@@ -177,7 +178,8 @@ WGPUComputePipeline TextureManager::get_or_create_compute_pipeline(
if (num_input_textures > 0) {
bgl_entries[2 + num_input_textures].binding = 2 + num_input_textures;
bgl_entries[2 + num_input_textures].visibility = WGPUShaderStage_Compute;
- bgl_entries[2 + num_input_textures].sampler.type = WGPUSamplerBindingType_Filtering;
+ bgl_entries[2 + num_input_textures].sampler.type =
+ WGPUSamplerBindingType_Filtering;
}
WGPUBindGroupLayoutDescriptor bgl_desc = {};
@@ -205,7 +207,8 @@ WGPUComputePipeline TextureManager::get_or_create_compute_pipeline(
wgpuShaderModuleRelease(shader_module);
// Cache pipeline
- ComputePipelineInfo info = {pipeline, shader_code, uniform_size, num_input_textures};
+ ComputePipelineInfo info = {pipeline, shader_code, uniform_size,
+ num_input_textures};
compute_pipelines_[func_name] = info;
return pipeline;
@@ -318,7 +321,8 @@ void TextureManager::create_gpu_noise_texture(
};
NoiseParams uniforms = {(uint32_t)params.width, (uint32_t)params.height,
params.params[0], params.params[1]};
- dispatch_compute("gen_noise", texture, params, &uniforms, sizeof(NoiseParams));
+ dispatch_compute("gen_noise", texture, params, &uniforms,
+ sizeof(NoiseParams));
WGPUTextureView view =
gpu_create_texture_view_2d(texture, WGPUTextureFormat_RGBA8Unorm);
@@ -361,15 +365,15 @@ void TextureManager::create_gpu_perlin_texture(
uint32_t octaves;
float _pad0;
};
- PerlinParams uniforms = {
- (uint32_t)params.width,
- (uint32_t)params.height,
- params.params[0],
- params.params[1],
- params.num_params > 2 ? params.params[2] : 1.0f,
- params.num_params > 3 ? params.params[3] : 0.5f,
- params.num_params > 4 ? (uint32_t)params.params[4] : 4u,
- 0.0f};
+ PerlinParams uniforms = {(uint32_t)params.width,
+ (uint32_t)params.height,
+ params.params[0],
+ params.params[1],
+ params.num_params > 2 ? params.params[2] : 1.0f,
+ params.num_params > 3 ? params.params[3] : 0.5f,
+ params.num_params > 4 ? (uint32_t)params.params[4]
+ : 4u,
+ 0.0f};
dispatch_compute("gen_perlin", texture, params, &uniforms,
sizeof(PerlinParams));
@@ -427,8 +431,8 @@ void TextureManager::create_gpu_grid_texture(
textures_[name] = gpu_tex;
#if !defined(STRIP_ALL)
- printf("Generated GPU grid texture: %s (%dx%d)\n", name.c_str(),
- params.width, params.height);
+ printf("Generated GPU grid texture: %s (%dx%d)\n", name.c_str(), params.width,
+ params.height);
#endif
}
@@ -634,7 +638,7 @@ void TextureManager::create_gpu_composite_texture(
// Dispatch composite shader
GpuProceduralParams params = {width, height, nullptr, 0};
dispatch_composite(shader_func, texture, params, uniform_data, uniform_size,
- input_views, sampler);
+ input_views, sampler);
// Create view
WGPUTextureView view =
@@ -653,11 +657,12 @@ void TextureManager::create_gpu_composite_texture(
name.c_str(), width, height, input_names.size());
#endif
}
-#endif // !defined(STRIP_GPU_COMPOSITE)
+#endif // !defined(STRIP_GPU_COMPOSITE)
#if !defined(STRIP_ALL)
-WGPUTextureView TextureManager::get_or_generate_gpu_texture(
- const std::string& name, const GpuProceduralParams& params) {
+WGPUTextureView
+TextureManager::get_or_generate_gpu_texture(const std::string& name,
+ const GpuProceduralParams& params) {
auto it = textures_.find(name);
if (it != textures_.end()) {
return it->second.view;