// Copyright (c) 2018-2020 NVIDIA Corporation
//
// SPDX-License-Identifier: CC-BY-4.0

include::{generated}/meta/{refprefix}VK_NV_ray_tracing.adoc[]

=== Other Extension Metadata

*Last Modified Date*::
    2018-11-20
*Interactions and External Dependencies*::
  - This extension requires
    {spirv}/NV/SPV_NV_ray_tracing.html[`SPV_NV_ray_tracing`]
  - This extension provides API support for
    {GLSLregistry}/nv/GLSL_NV_ray_tracing.txt[`GL_NV_ray_tracing`]
*Contributors*::
  - Eric Werness, NVIDIA
  - Ashwin Lele, NVIDIA
  - Robert Stepinski, NVIDIA
  - Nuno Subtil, NVIDIA
  - Christoph Kubisch, NVIDIA
  - Martin Stich, NVIDIA
  - Daniel Koch, NVIDIA
  - Jeff Bolz, NVIDIA
  - Joshua Barczak, Intel
  - Tobias Hector, AMD
  - Henrik Rydgard, NVIDIA
  - Pascal Gautron, NVIDIA

=== Description

Rasterization has been the dominant method to produce interactive graphics,
but increasing performance of graphics hardware has made ray tracing a
viable option for interactive rendering.
Being able to integrate ray tracing with traditional rasterization makes it
easier for applications to incrementally add ray traced effects to existing
applications or to do hybrid approaches with rasterization for primary
visibility and ray tracing for secondary queries.

To enable ray tracing, this extension adds a few different categories of new
functionality:

  * Acceleration structure objects and build commands
  * A new pipeline type with new shader domains
  * An indirection table to link shader groups with acceleration structure
    items

This extension adds support for the following SPIR-V extension in Vulkan:

  * `SPV_NV_ray_tracing`

include::{generated}/interfaces/VK_NV_ray_tracing.adoc[]

=== New or Modified Built-In Variables

  * <<interfaces-builtin-variables-launchid,code:LaunchIdNV>>
  * <<interfaces-builtin-variables-launchsize,code:LaunchSizeNV>>
  * <<interfaces-builtin-variables-worldrayorigin,code:WorldRayOriginNV>>
  * <<interfaces-builtin-variables-worldraydirection,code:WorldRayDirectionNV>>
  * <<interfaces-builtin-variables-objectrayorigin,code:ObjectRayOriginNV>>
  * <<interfaces-builtin-variables-objectraydirection,code:ObjectRayDirectionNV>>
  * <<interfaces-builtin-variables-raytmin,code:RayTminNV>>
  * <<interfaces-builtin-variables-raytmax,code:RayTmaxNV>>
  * <<interfaces-builtin-variables-instancecustomindex,code:InstanceCustomIndexNV>>
  * <<interfaces-builtin-variables-instanceid,code:InstanceId>>
  * <<interfaces-builtin-variables-objecttoworld,code:ObjectToWorldNV>>
  * <<interfaces-builtin-variables-worldtoobject,code:WorldToObjectNV>>
  * <<interfaces-builtin-variables-hitt,code:HitTNV>>
  * <<interfaces-builtin-variables-hitkind,code:HitKindNV>>
  * <<interfaces-builtin-variables-incomingrayflags,code:IncomingRayFlagsNV>>
  * (modified)code:PrimitiveId

=== New SPIR-V Capabilities

  * <<spirvenv-capabilities-table-RayTracingNV, code:RayTracingNV>>

=== Issues

1) Are there issues?

*RESOLVED*: Yes.

=== Sample Code

Example ray generation GLSL shader

[source,c]
----
#version 450 core
#extension GL_NV_ray_tracing : require
layout(set = 0, binding = 0, rgba8) uniform image2D image;
layout(set = 0, binding = 1) uniform accelerationStructureNV as;
layout(location = 0) rayPayloadNV float payload;

void main()
{
   vec4 col = vec4(0, 0, 0, 1);

   vec3 origin = vec3(float(gl_LaunchIDNV.x)/float(gl_LaunchSizeNV.x), float(gl_LaunchIDNV.y)/float(gl_LaunchSizeNV.y), 1.0);
   vec3 dir = vec3(0.0, 0.0, -1.0);

   traceNV(as, 0, 0xff, 0, 1, 0, origin, 0.0, dir, 1000.0, 0);

   col.y = payload;

   imageStore(image, ivec2(gl_LaunchIDNV.xy), col);
}
----

=== Version History

  * Revision 1, 2018-09-11 (Robert Stepinski, Nuno Subtil, Eric Werness)
  ** Internal revisions
  * Revision 2, 2018-10-19 (Eric Werness)
  ** rename to VK_NV_ray_tracing, add support for callables.
  ** too many updates to list
  * Revision 3, 2018-11-20 (Daniel Koch)
  ** update to use InstanceId instead of InstanceIndex as implemented.
