maierfelix / webgpu

WebGPU for Node [Deprecated, Unmaintained]
MIT License
244 stars 17 forks source link

Support ray query #28

Open yyc-git opened 4 years ago

yyc-git commented 4 years ago

refer to NVIDIA Vulkan Ray Tracing Tutorial -> ray query, I add ray query in .frag shader:

screen.frag

#version 460
#pragma shader_stage(fragment)

#extension GL_EXT_ray_tracing : enable
#extension GL_EXT_ray_query : enable

...

layout(binding = 0, set = 0) uniform accelerationStructureEXT topLevelAS;

...

void main() {
...

  // Ray Query
  vec3 origin = vec3(0.1);
  vec3 direction = vec3(1.0); // vector to light
  float tMin = 0.01f;
  float tMax = 100000000.0f;

  // Initializes a ray query object but does not start traversal
  rayQueryEXT rayQuery;
  rayQueryInitializeEXT(rayQuery, topLevelAS, gl_RayFlagsTerminateOnFirstHitEXT,
                        0xFF, origin, tMin, direction, tMax);

  // Start traversal: return false if traversal is complete
  while (rayQueryProceedEXT(rayQuery)) {
  }

...
}

I pass the instance accelerationContainer to render bind group: index.mjs

...

  let renderBindGroupLayout = device.createBindGroupLayout({
    entries: [
      {
        binding: 0,
        visibility: GPUShaderStage.FRAGMENT,
        type: "acceleration-container"
      },
...
    ]
  });

...

  let renderBindGroup = device.createBindGroup({
    layout: renderBindGroupLayout,
    entries: [
      {
        binding: 0,
        accelerationContainer: instanceContainer,
        offset: 0,
        size: 0
      },
...
    ]
  });

then I run the index.mjs in nodejs, it error:

Error: Validation Error: acceleration container binding is not supported in this shader
    at ValidateBindingTypeWithShaderStageVisibility (../../src/dawn_native/BindGroupLayout.cpp:67)
    at ValidateBindGroupLayoutDescriptor (../../src/dawn_native/BindGroupLayout.cpp:133)
    at CreateBindGroupLayoutInternal (../../src/dawn_native/Device.cpp:837)
    at Immediate.<anonymous> (D:\Github\WebGPU-Sample\node_modules\webgpu\index.js:41:30)
    at processImmediate (internal/timers.js:458:21)
maierfelix commented 4 years ago

When I continue working on the ray tracing extension then I'll probably add support for ray queries. Also please post issues regarding ray tracing here

yyc-git commented 4 years ago

Thanks very much~