Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for texture_utils.ts #3907

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,32 @@ async function initMipGradientValuesForDevice(t: GPUTest) {
@group(0) @binding(1) var smp: sampler;
@group(0) @binding(2) var<storage, read_write> result: array<f32>;

@compute @workgroup_size(1) fn cs(@builtin(global_invocation_id) id: vec3u) {
let mipLevel = f32(id.x) / ${kMipGradientSteps};
result[id.x] = textureSampleLevel(tex, smp, vec2f(0.5), mipLevel).r;
@vertex fn vs(@builtin(vertex_index) vNdx: u32) -> @builtin(position) vec4f {
let pos = array(
vec2f(-1, 3),
vec2f( 3, -1),
vec2f(-1, -1),
);
return vec4f(pos[vNdx], 0, 1);
}
@fragment fn fs(@builtin(position) pos: vec4f) -> @location(0) vec4f {
let mipLevel = floor(pos.x) / ${kMipGradientSteps};
result[u32(pos.x)] = textureSampleLevel(tex, smp, vec2f(0.5), mipLevel).r;
return vec4f(0);
}
`,
});

const pipeline = device.createComputePipeline({
const pipeline = device.createRenderPipeline({
layout: 'auto',
compute: { module },
vertex: { module },
fragment: { module, targets: [{ format: 'rgba8unorm' }] },
});

const target = t.createTextureTracked({
size: [kMipGradientSteps + 1, 1, 1],
format: 'rgba8unorm',
usage: GPUTextureUsage.RENDER_ATTACHMENT,
});

const texture = t.createTextureTracked({
Expand Down Expand Up @@ -186,10 +202,18 @@ async function initMipGradientValuesForDevice(t: GPUTest) {
});

const encoder = device.createCommandEncoder();
const pass = encoder.beginComputePass();
const pass = encoder.beginRenderPass({
colorAttachments: [
{
view: target.createView(),
loadOp: 'clear',
storeOp: 'store',
},
],
});
pass.setPipeline(pipeline);
pass.setBindGroup(0, bindGroup);
pass.dispatchWorkgroups(kMipGradientSteps + 1);
pass.draw(3);
pass.end();
encoder.copyBufferToBuffer(storageBuffer, 0, resultBuffer, 0, resultBuffer.size);
device.queue.submit([encoder.finish()]);
Expand All @@ -215,7 +239,7 @@ async function initMipGradientValuesForDevice(t: GPUTest) {
// standard
// step mipLevel gpu AMD
// ---- -------- -------- ----------
// 0: 0 0 1
// 0: 0 0 0
// 1: 0.0625 0.0625 0
// 2: 0.125 0.125 0.03125
// 3: 0.1875 0.1875 0.109375
Expand Down
Loading