diff --git a/src/renderer/wg_engine/tvgWgBindGroups.cpp b/src/renderer/wg_engine/tvgWgBindGroups.cpp index 8c9d14df..e25e4181 100644 --- a/src/renderer/wg_engine/tvgWgBindGroups.cpp +++ b/src/renderer/wg_engine/tvgWgBindGroups.cpp @@ -141,6 +141,7 @@ void WgBindGroupLayouts::releaseBindGroup(WGPUBindGroup& bindGroup) bindGroup = nullptr; } + void WgBindGroupLayouts::releaseBindGroupLayout(WGPUBindGroupLayout& bindGroupLayout) { if (bindGroupLayout) wgpuBindGroupLayoutRelease(bindGroupLayout); @@ -160,7 +161,6 @@ void WgBindGroupLayouts::initialize(WGPUDevice device) const WGPUSamplerBindingLayout sampler = { .type = WGPUSamplerBindingType_Filtering }; const WGPUTextureBindingLayout texture = { .sampleType = WGPUTextureSampleType_Float, .viewDimension = WGPUTextureViewDimension_2D }; const WGPUStorageTextureBindingLayout storageTextureWO { .access = WGPUStorageTextureAccess_WriteOnly, .format = WGPUTextureFormat_RGBA8Unorm, .viewDimension = WGPUTextureViewDimension_2D }; - const WGPUStorageTextureBindingLayout storageTextureRO { .access = WGPUStorageTextureAccess_ReadOnly, .format = WGPUTextureFormat_RGBA8Unorm, .viewDimension = WGPUTextureViewDimension_2D }; const WGPUBufferBindingLayout bufferUniform { .type = WGPUBufferBindingType_Uniform }; // bind group layout tex sampled with buffer uniforms @@ -190,9 +190,9 @@ void WgBindGroupLayouts::initialize(WGPUDevice device) // bind group layout tex storages RO const WGPUBindGroupLayoutEntry entriesTexStoragesRO[] { - { .binding = 0, .visibility = visibility_frag, .storageTexture = storageTextureRO }, - { .binding = 1, .visibility = visibility_frag, .storageTexture = storageTextureRO }, - { .binding = 2, .visibility = visibility_frag, .storageTexture = storageTextureRO } + { .binding = 0, .visibility = visibility_frag, .texture = texture }, + { .binding = 1, .visibility = visibility_frag, .texture = texture }, + { .binding = 2, .visibility = visibility_frag, .texture = texture } }; const WGPUBindGroupLayoutDescriptor layoutDescTexStorages1RO { .entryCount = 1, .entries = entriesTexStoragesRO }; const WGPUBindGroupLayoutDescriptor layoutDescTexStorages2RO { .entryCount = 2, .entries = entriesTexStoragesRO }; diff --git a/src/renderer/wg_engine/tvgWgBindGroups.h b/src/renderer/wg_engine/tvgWgBindGroups.h index 11399f80..9bab0e77 100644 --- a/src/renderer/wg_engine/tvgWgBindGroups.h +++ b/src/renderer/wg_engine/tvgWgBindGroups.h @@ -44,6 +44,7 @@ public: WGPUBindGroup createBindGroupTexSampledBuff1Un(WGPUSampler sampler, WGPUTextureView texView, WGPUBuffer buff); WGPUBindGroup createBindGroupTexSampledBuff2Un(WGPUSampler sampler, WGPUTextureView texView, WGPUBuffer buff0, WGPUBuffer buff1); WGPUBindGroup createBindGroupStrorage1WO(WGPUTextureView texView); + // for read-only access in compute shaders, use texture_2d instead of texture_storage_2d WGPUBindGroup createBindGroupStrorage1RO(WGPUTextureView texView); WGPUBindGroup createBindGroupStrorage2RO(WGPUTextureView texView0, WGPUTextureView texView1); WGPUBindGroup createBindGroupStrorage3RO(WGPUTextureView texView0, WGPUTextureView texView1, WGPUTextureView texView2); diff --git a/src/renderer/wg_engine/tvgWgShaderSrc.cpp b/src/renderer/wg_engine/tvgWgShaderSrc.cpp index 1e53d961..53fa134a 100644 --- a/src/renderer/wg_engine/tvgWgShaderSrc.cpp +++ b/src/renderer/wg_engine/tvgWgShaderSrc.cpp @@ -709,7 +709,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4f { //************************************************************************ const char* cShaderSrc_GaussianBlur = R"( -@group(0) @binding(0) var imageSrc : texture_storage_2d; +@group(0) @binding(0) var imageSrc : texture_2d; @group(1) @binding(0) var imageDst : texture_storage_2d; @group(2) @binding(0) var settings: array; @group(3) @binding(0) var viewport: vec4f; @@ -743,9 +743,9 @@ fn cs_main_horz(@builtin(global_invocation_id) gid: vec3u, let iid = vec2i(uid); // load source to local workgroup memory - buff[lid.x + N*0] = textureLoad(imageSrc, uid - vec2u(N, 0)); - buff[lid.x + N*1] = textureLoad(imageSrc, uid + vec2u(0, 0)); - buff[lid.x + N*2] = textureLoad(imageSrc, uid + vec2u(N, 0)); + buff[lid.x + N*0] = textureLoad(imageSrc, uid - vec2u(N, 0), 0); + buff[lid.x + N*1] = textureLoad(imageSrc, uid + vec2u(0, 0), 0); + buff[lid.x + N*2] = textureLoad(imageSrc, uid + vec2u(N, 0), 0); workgroupBarrier(); // apply filter @@ -786,9 +786,9 @@ fn cs_main_vert(@builtin(global_invocation_id) gid: vec3u, let iid = vec2i(uid); // load source to local workgroup memory - buff[lid.y + N*0] = textureLoad(imageSrc, uid - vec2u(0, N)); - buff[lid.y + N*1] = textureLoad(imageSrc, uid + vec2u(0, 0)); - buff[lid.y + N*2] = textureLoad(imageSrc, uid + vec2u(0, N)); + buff[lid.y + N*0] = textureLoad(imageSrc, uid - vec2u(0, N), 0); + buff[lid.y + N*1] = textureLoad(imageSrc, uid + vec2u(0, 0), 0); + buff[lid.y + N*2] = textureLoad(imageSrc, uid + vec2u(0, N), 0); workgroupBarrier(); // apply filter @@ -812,8 +812,8 @@ fn cs_main_vert(@builtin(global_invocation_id) gid: vec3u, )"; const char* cShaderSrc_Effects = R"( -@group(0) @binding(0) var imageSrc : texture_storage_2d; -@group(0) @binding(1) var imageSdw : texture_storage_2d; +@group(0) @binding(0) var imageSrc : texture_2d; +@group(0) @binding(1) var imageSdw : texture_2d; @group(1) @binding(0) var imageTrg : texture_storage_2d; @group(2) @binding(0) var settings: array; @group(3) @binding(0) var viewport: vec4f; @@ -829,8 +829,8 @@ fn cs_main_drop_shadow(@builtin(global_invocation_id) gid: vec3u) { let uid = gid.xy + vmin; let oid = clamp(vec2u(vec2i(uid) - voff), vmin, vmax); - let orig = textureLoad(imageSrc, uid); - let blur = textureLoad(imageSdw, oid); + let orig = textureLoad(imageSrc, uid, 0); + let blur = textureLoad(imageSdw, oid, 0); let shad = settings[1] * blur.a; let color = orig + shad * (1.0 - orig.a); textureStore(imageTrg, uid.xy, color); @@ -845,7 +845,7 @@ fn cs_main_fill(@builtin(global_invocation_id) gid: vec3u) { // tex coord let uid = min(gid.xy + vmin, vmax); - let orig = textureLoad(imageSrc, uid); + let orig = textureLoad(imageSrc, uid, 0); let fill = settings[0]; let color = fill * orig.a * fill.a; textureStore(imageTrg, uid.xy, color); @@ -860,7 +860,7 @@ fn cs_main_tint(@builtin(global_invocation_id) gid: vec3u) { // tex coord let uid = min(gid.xy + vmin, vmax); - let orig = textureLoad(imageSrc, uid); + let orig = textureLoad(imageSrc, uid, 0); let luma: f32 = dot(orig.rgb, vec3f(0.2125, 0.7154, 0.0721)); let black = settings[0]; let white = settings[1]; @@ -878,7 +878,7 @@ fn cs_main_tritone(@builtin(global_invocation_id) gid: vec3u) { // tex coord let uid = min(gid.xy + vmin, vmax); - let orig = textureLoad(imageSrc, uid); + let orig = textureLoad(imageSrc, uid, 0); let luma: f32 = dot(orig.rgb, vec3f(0.2125, 0.7154, 0.0721)); let shadow = settings[0]; let midtone = settings[1];