Merge pull request #1369 from KhronosGroup/more-rt-tests

GLSL: Add more tests for RT.
This commit is contained in:
Hans-Kristian Arntzen 2020-05-20 17:04:27 +02:00 committed by GitHub
commit 29ad40e93e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
67 changed files with 877 additions and 5 deletions

View File

@ -0,0 +1,24 @@
#version 460
#extension GL_NV_ray_tracing : require
struct Foo
{
float a;
float b;
};
struct Foo2
{
float a;
float b;
};
layout(location = 0) rayPayloadInNV Foo payload;
hitAttributeNV Foo2 hit;
void main()
{
payload.a = hit.a;
payload.b = hit.b;
}

View File

@ -0,0 +1,24 @@
#version 460
#extension GL_NV_ray_tracing : require
struct Foo
{
float a;
float b;
};
struct Foo2
{
float a;
float b;
};
layout(location = 0) rayPayloadInNV Foo payload;
hitAttributeNV Foo2 hit;
void main()
{
payload.a = hit.a;
payload.b = hit.b;
}

View File

@ -0,0 +1,11 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec2 payload;
hitAttributeNV vec2 hit;
void main()
{
payload = hit;
}

View File

@ -0,0 +1,17 @@
#version 460
#extension GL_NV_ray_tracing : require
struct Foo
{
float a;
float b;
};
layout(location = 0) rayPayloadInNV Foo payload;
hitAttributeNV Foo hit;
void main()
{
payload = hit;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV uint payload;
void main()
{
payload = gl_HitKindNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV float payload;
void main()
{
payload = gl_HitTNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV uint payload;
void main()
{
payload = gl_IncomingRayFlagsNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV uint payload;
void main()
{
payload = uint(gl_InstanceCustomIndexNV);
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV uint payload;
void main()
{
payload = uint(gl_InstanceID);
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_ObjectRayDirectionNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_ObjectRayOriginNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_ObjectToWorldNV * vec4(payload, 1.0);
}

View File

@ -0,0 +1,15 @@
#version 460
#extension GL_NV_ray_tracing : require
struct Payload
{
vec4 a;
};
layout(location = 0) rayPayloadInNV Payload payload;
void main()
{
payload.a = vec4(10.0);
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV uint payload;
void main()
{
payload = uint(gl_PrimitiveID);
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV float payload;
void main()
{
payload = gl_RayTmaxNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV float payload;
void main()
{
payload = gl_RayTminNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_WorldRayDirectionNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_WorldRayOriginNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_WorldToObjectNV * vec4(payload, 1.0);
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(set = 0, binding = 0) uniform writeonly image2D uImage;
void main()
{
imageStore(uImage, ivec2(gl_LaunchIDNV.xy), vec4(1.0));
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(set = 0, binding = 0) uniform writeonly image2D uImage;
void main()
{
imageStore(uImage, ivec2(gl_LaunchSizeNV.xy) - ivec2(1), vec4(1.0));
}

View File

@ -0,0 +1,31 @@
#version 460
#extension GL_NV_ray_tracing : require
struct Payload
{
float a;
float b;
};
struct Block
{
float a;
float b;
Payload c;
Payload d;
};
layout(set = 0, binding = 1) uniform accelerationStructureNV as;
layout(location = 1) rayPayloadNV Payload payload2;
layout(location = 0) rayPayloadNV float payload1;
layout(location = 2) rayPayloadNV Block _71;
layout(set = 0, binding = 0, rgba8) uniform writeonly image2D image;
void main()
{
traceNV(as, 0u, 255u, 0u, 1u, 0u, vec3(1.0, 0.0, 0.0), 0.0, vec3(0.0, 1.0, 0.0), 1000.0, 0);
traceNV(as, 0u, 255u, 0u, 1u, 0u, vec3(1.0, 0.0, 0.0), 0.0, vec3(0.0, 1.0, 0.0), 1000.0, 1);
traceNV(as, 0u, 255u, 0u, 1u, 0u, vec3(1.0, 0.0, 0.0), 0.0, vec3(0.0, 1.0, 0.0), 1000.0, 2);
imageStore(image, ivec2(gl_LaunchIDNV.xy), (vec4(payload1) + (vec4(payload2.a) + vec4(payload2.b))) + vec4(((((_71.a + _71.b) + _71.c.a) + _71.c.b) + _71.d.a) + _71.d.b));
}

View File

@ -0,0 +1,24 @@
#version 460
#extension GL_NV_ray_tracing : require
struct Foo
{
float a;
float b;
};
struct Foo2
{
float a;
float b;
};
layout(location = 0) rayPayloadInNV Foo payload;
hitAttributeNV Foo2 hit;
void main()
{
payload.a = hit.a;
payload.b = hit.b;
}

View File

@ -0,0 +1,29 @@
#version 460
#extension GL_NV_ray_tracing : require
struct Foo
{
float a;
float b;
};
struct Foo2
{
float a;
float b;
};
layout(location = 0) rayPayloadInNV Foo payload;
hitAttributeNV Foo2 hit;
void in_function()
{
payload.a = hit.a;
payload.b = hit.b;
}
void main()
{
in_function();
}

View File

@ -0,0 +1,11 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec2 payload;
hitAttributeNV vec2 hit;
void main()
{
payload = hit;
}

View File

@ -0,0 +1,17 @@
#version 460
#extension GL_NV_ray_tracing : require
struct Foo
{
float a;
float b;
};
layout(location = 0) rayPayloadInNV Foo payload;
hitAttributeNV Foo hit;
void main()
{
payload = hit;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV uint payload;
void main()
{
payload = gl_HitKindNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV float payload;
void main()
{
payload = gl_HitTNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV uint payload;
void main()
{
payload = gl_IncomingRayFlagsNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV uint payload;
void main()
{
payload = uint(gl_InstanceCustomIndexNV);
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV uint payload;
void main()
{
payload = uint(gl_InstanceID);
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_ObjectRayDirectionNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_ObjectRayOriginNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_ObjectToWorldNV * vec4(payload, 1.0);
}

View File

@ -0,0 +1,20 @@
#version 460
#extension GL_NV_ray_tracing : require
struct Payload
{
vec4 a;
};
layout(location = 0) rayPayloadInNV Payload payload;
void write_incoming_payload_in_function()
{
payload.a = vec4(10.0);
}
void main()
{
write_incoming_payload_in_function();
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV uint payload;
void main()
{
payload = uint(gl_PrimitiveID);
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV float payload;
void main()
{
payload = gl_RayTmaxNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV float payload;
void main()
{
payload = gl_RayTminNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_WorldRayDirectionNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_WorldRayOriginNV;
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_WorldToObjectNV * vec4(payload, 1.0);
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(set = 0, binding = 0) uniform writeonly image2D uImage;
void main()
{
imageStore(uImage, ivec2(gl_LaunchIDNV.xy), vec4(1.0));
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(set = 0, binding = 0) uniform writeonly image2D uImage;
void main()
{
imageStore(uImage, ivec2(gl_LaunchSizeNV.xy) - ivec2(1), vec4(1.0));
}

View File

@ -0,0 +1,47 @@
#version 460
#extension GL_NV_ray_tracing : require
struct Payload
{
float a;
float b;
};
struct Block
{
float a;
float b;
Payload c;
Payload d;
};
layout(set = 0, binding = 1) uniform accelerationStructureNV as;
layout(location = 1) rayPayloadNV Payload payload2;
layout(location = 0) rayPayloadNV float payload1;
layout(location = 2) rayPayloadNV Block _71;
layout(set = 0, binding = 0, rgba8) uniform writeonly image2D image;
vec4 trace_in_function()
{
vec4 result = vec4(0.0);
vec3 origin = vec3(1.0, 0.0, 0.0);
vec3 direction = vec3(0.0, 1.0, 0.0);
traceNV(as, 0u, 255u, 0u, 1u, 0u, origin, 0.0, direction, 1000.0, 1);
result += vec4(payload2.a);
result += vec4(payload2.b);
return result;
}
void main()
{
vec3 origin = vec3(1.0, 0.0, 0.0);
vec3 direction = vec3(0.0, 1.0, 0.0);
traceNV(as, 0u, 255u, 0u, 1u, 0u, origin, 0.0, direction, 1000.0, 0);
vec4 result = vec4(payload1);
vec4 _62 = trace_in_function();
result += _62;
traceNV(as, 0u, 255u, 0u, 1u, 0u, origin, 0.0, direction, 1000.0, 2);
result += vec4(((((_71.a + _71.b) + _71.c.a) + _71.c.b) + _71.d.a) + _71.d.b);
imageStore(image, ivec2(gl_LaunchIDNV.xy), result);
}

View File

@ -0,0 +1,11 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV Foo { float a; float b; } payload;
hitAttributeNV Foo2 { float a; float b; } hit;
void main()
{
payload.a = hit.a;
payload.b = hit.b;
}

View File

@ -0,0 +1,16 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV Foo { float a; float b; } payload;
hitAttributeNV Foo2 { float a; float b; } hit;
void in_function()
{
payload.a = hit.a;
payload.b = hit.b;
}
void main()
{
in_function();
}

View File

@ -0,0 +1,10 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec2 payload;
hitAttributeNV vec2 hit;
void main()
{
payload = hit;
}

View File

@ -0,0 +1,12 @@
#version 460
#extension GL_NV_ray_tracing : require
struct Foo { float a; float b; };
layout(location = 0) rayPayloadInNV Foo payload;
hitAttributeNV Foo hit;
void main()
{
payload = hit;
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV uint payload;
void main()
{
payload = gl_HitKindNV;
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV float payload;
void main()
{
payload = gl_HitTNV;
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV uint payload;
void main()
{
payload = gl_IncomingRayFlagsNV;
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV uint payload;
void main()
{
payload = gl_InstanceCustomIndexNV;
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV uint payload;
void main()
{
payload = gl_InstanceID;
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_ObjectRayDirectionNV;
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_ObjectRayOriginNV;
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_ObjectToWorldNV * vec4(payload, 1.0);
}

View File

@ -0,0 +1,19 @@
#version 460
#extension GL_NV_ray_tracing : require
struct Payload
{
vec4 a;
};
layout(location = 0) rayPayloadInNV Payload payload;
void write_incoming_payload_in_function()
{
payload.a = vec4(10.0);
}
void main()
{
write_incoming_payload_in_function();
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV uint payload;
void main()
{
payload = gl_PrimitiveID;
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV float payload;
void main()
{
payload = gl_RayTmaxNV;
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV float payload;
void main()
{
payload = gl_RayTminNV;
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_WorldRayDirectionNV;
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_WorldRayOriginNV;
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(location = 0) rayPayloadInNV vec3 payload;
void main()
{
payload = gl_WorldToObjectNV * vec4(payload, 1.0);
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(set = 0, binding = 0) uniform writeonly image2D uImage;
void main()
{
imageStore(uImage, ivec2(gl_LaunchIDNV.xy), vec4(1.0));
}

View File

@ -0,0 +1,9 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(set = 0, binding = 0) uniform writeonly image2D uImage;
void main()
{
imageStore(uImage, ivec2(gl_LaunchSizeNV.xy) - 1, vec4(1.0));
}

View File

@ -0,0 +1,49 @@
#version 460
#extension GL_NV_ray_tracing : require
layout(set = 0, binding = 0, rgba8) uniform image2D image;
layout(set = 0, binding = 1) uniform accelerationStructureNV as;
struct Payload
{
float a, b;
};
// Plain payload
layout(location = 0) rayPayloadNV float payload1;
// Struct payload
layout(location = 1) rayPayloadNV Payload payload2;
// This is syntactic sugar with the struct formulation (pretty sure), spec is kinda vague.
layout(location = 2) rayPayloadNV Block
{
float a, b;
Payload c, d;
};
vec4 trace_in_function()
{
vec4 result = vec4(0.0);
// Test that we can write to a payload in a function.
vec3 origin = vec3(1.0, 0.0, 0.0);
vec3 direction = vec3(0.0, 1.0, 0.0);
traceNV(as, 0u, 255u, 0u, 1u, 0u, origin, 0.0, direction, 1000.0, 1);
result += payload2.a;
result += payload2.b;
return result;
}
void main()
{
vec3 origin = vec3(1.0, 0.0, 0.0);
vec3 direction = vec3(0.0, 1.0, 0.0);
traceNV(as, 0u, 255u, 0u, 1u, 0u, origin, 0.0, direction, 1000.0, 0);
vec4 result = vec4(payload1);
result += trace_in_function();
traceNV(as, 0u, 255u, 0u, 1u, 0u, origin, 0.0, direction, 1000.0, 2);
result += a + b + c.a + c.b + d.a + d.b;
imageStore(image, ivec2(gl_LaunchIDNV.xy), result);
}

View File

@ -2943,16 +2943,28 @@ void CompilerGLSL::emit_resources()
}
else if (id.get_type() == TypeType)
{
auto &type = id.get<SPIRType>();
if (type.basetype == SPIRType::Struct && type.array.empty() && !type.pointer &&
(!ir.meta[type.self].decoration.decoration_flags.get(DecorationBlock) &&
!ir.meta[type.self].decoration.decoration_flags.get(DecorationBufferBlock)))
auto *type = &id.get<SPIRType>();
bool is_natural_struct =
type->basetype == SPIRType::Struct && type->array.empty() && !type->pointer &&
(!has_decoration(type->self, DecorationBlock) && !has_decoration(type->self, DecorationBufferBlock));
// Special case, ray payload and hit attribute blocks are not really blocks, just regular structs.
if (type->basetype == SPIRType::Struct && type->pointer && has_decoration(type->self, DecorationBlock) &&
(type->storage == StorageClassRayPayloadNV || type->storage == StorageClassIncomingRayPayloadNV ||
type->storage == StorageClassHitAttributeNV))
{
type = &get<SPIRType>(type->parent_type);
is_natural_struct = true;
}
if (is_natural_struct)
{
if (emitted)
statement("");
emitted = false;
emit_struct(type);
emit_struct(*type);
}
}
}
@ -10792,21 +10804,26 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
case OpReportIntersectionNV:
statement("reportIntersectionNV(", to_expression(ops[0]), ", ", to_expression(ops[1]), ");");
flush_control_dependent_expressions(current_emitting_block->self);
break;
case OpIgnoreIntersectionNV:
statement("ignoreIntersectionNV();");
flush_control_dependent_expressions(current_emitting_block->self);
break;
case OpTerminateRayNV:
statement("terminateRayNV();");
flush_control_dependent_expressions(current_emitting_block->self);
break;
case OpTraceNV:
statement("traceNV(", to_expression(ops[0]), ", ", to_expression(ops[1]), ", ", to_expression(ops[2]), ", ",
to_expression(ops[3]), ", ", to_expression(ops[4]), ", ", to_expression(ops[5]), ", ",
to_expression(ops[6]), ", ", to_expression(ops[7]), ", ", to_expression(ops[8]), ", ",
to_expression(ops[9]), ", ", to_expression(ops[10]), ");");
flush_control_dependent_expressions(current_emitting_block->self);
break;
case OpExecuteCallableNV:
statement("executeCallableNV(", to_expression(ops[0]), ", ", to_expression(ops[1]), ");");
flush_control_dependent_expressions(current_emitting_block->self);
break;
case OpConvertUToPtr:
@ -13407,6 +13424,7 @@ void CompilerGLSL::bitcast_from_builtin_load(uint32_t source_id, std::string &ex
case BuiltInBaseInstance:
case BuiltInDrawIndex:
case BuiltInFragStencilRefEXT:
case BuiltInInstanceCustomIndexNV:
expected_type = SPIRType::Int;
break;
@ -13416,6 +13434,9 @@ void CompilerGLSL::bitcast_from_builtin_load(uint32_t source_id, std::string &ex
case BuiltInLocalInvocationIndex:
case BuiltInWorkgroupSize:
case BuiltInNumWorkgroups:
case BuiltInIncomingRayFlagsNV:
case BuiltInLaunchIdNV:
case BuiltInLaunchSizeNV:
expected_type = SPIRType::UInt;
break;