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

MSL: invalid codegen, when using rayquery #1910

Closed
Try opened this issue Apr 10, 2022 · 1 comment · Fixed by #1916
Closed

MSL: invalid codegen, when using rayquery #1910

Try opened this issue Apr 10, 2022 · 1 comment · Fixed by #1916
Labels
needs triage Needs to be reproduced before it can become a different issue type.

Comments

@Try
Copy link
Contributor

Try commented Apr 10, 2022

When RQ is accessed by function:

// GLSL
#version 460

#extension GL_ARB_separate_shader_objects : enable
#extension GL_EXT_ray_query : enable

layout(location = 0) in  vec4 inPos;
layout(location = 0) out vec4 outColor;

layout(binding = 0) uniform accelerationStructureEXT topLevelAS;

uint doRay(vec3 rayOrigin, vec3 rayDirection, float rayDistance) {
  rayQueryEXT rayQuery;
  rayQueryInitializeEXT(rayQuery, topLevelAS, gl_RayFlagsTerminateOnFirstHitEXT, 0xFF,
                        rayOrigin, 0.001, rayDirection, rayDistance);

  while(rayQueryProceedEXT(rayQuery))
    ;

  return rayQueryGetIntersectionTypeEXT(rayQuery, true);
  }

void main() {
  vec3  rayOrigin    = vec3(inPos.xy*4.0-vec2(2.0),1.0);
  vec3  rayDirection = vec3(0,0,-1);
  float rayDistance  = 2.0;

  if(doRay(rayOrigin,rayDirection,rayDistance) == gl_RayQueryCommittedIntersectionNoneEXT)
    discard;

  outColor = inPos;
  }

Resulting MSL:

#pragma clang diagnostic ignored "-Wmissing-prototypes"
#include <metal_stdlib>
#include <simd/simd.h>
#if __METAL_VERSION__ >= 230
#include <metal_raytracing>
using namespace metal::raytracing;
#endif
using namespace metal;
struct main0_out
{
    float4 outColor [[color(0)]];
};
struct main0_in
{
    float4 inPos [[user(locn0)]];
};
static inline __attribute__((always_inline))
uint doRay(thread const float3& rayOrigin, thread const float3& rayDirection, thread const float& rayDistance, thread const instance_acceleration_structure& topLevelAS)
{
    // rayQuery is defined in main, but not in here
    rayQuery.reset(ray(rayOrigin, rayDirection, 0.001000000047497451305389404296875, rayDistance), topLevelAS, intersection_params());
    for (;;)
    {
        bool _36 = rayQuery.next();
        if (_36)
        {
            continue;
        }
        else
        {
            break;
        }
    }
    uint _40 = uint(rayQuery.get_committed_intersection_type());
    return _40;
}
fragment main0_out main0(main0_in in [[stage_in]], instance_acceleration_structure topLevelAS [[buffer(0)]])
{
    main0_out out = {};
    float3 rayOrigin = float3((in.inPos.xy * 4.0) - float2(2.0), 1.0);
    float3 rayDirection = float3(0.0, 0.0, -1.0);
    float rayDistance = 2.0;
    float3 param = rayOrigin;
    float3 param_1 = rayDirection;
    float param_2 = rayDistance;
    uint _70 = doRay(param, param_1, param_2, topLevelAS);
    intersection_query<instancing, triangle_data> rayQuery;
    if (_70 == 0u)
    {
        discard_fragment();
    }
    out.outColor = in.inPos;
    return out;
}

Error:

"program_source:25:5: error: use of undeclared identifier 'rayQuery'
    rayQuery.reset(ray(rayOrigin, rayDirection, 0.001000000047497451305389404296875, rayDistance), topLevelAS, intersection_params());
    ^
program_source:28:20: error: use of undeclared identifier 'rayQuery'
        bool _36 = rayQuery.next();
                   ^
program_source:38:21: error: use of undeclared identifier 'rayQuery'
    uint _40 = uint(rayQuery.get_committed_intersection_type());
@HansKristian-Work HansKristian-Work added the needs triage Needs to be reproduced before it can become a different issue type. label Apr 12, 2022
@HansKristian-Work
Copy link
Contributor

Most likely the rayquery object is promoted to a global variable and needs to be passed down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Needs to be reproduced before it can become a different issue type.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants