Skip to content

Commit

Permalink
Merge pull request #157 from Tobski/tobias/GLSL_EXT_spirv_intrinsics
Browse files Browse the repository at this point in the history
Added first draft of GLSL_EXT_spirv_intrinsics
  • Loading branch information
gnl21 authored Jul 11, 2024
2 parents 85c5304 + 0e4f9dc commit 75deffc
Show file tree
Hide file tree
Showing 8 changed files with 1,752 additions and 0 deletions.
1,042 changes: 1,042 additions & 0 deletions extensions/ext/GLSL_EXT_spirv_intrinsics.txt

Large diffs are not rendered by default.

Large diffs are not rendered by default.

291 changes: 291 additions & 0 deletions extensions/extension_headers/GL_AMD_shader_trinary_minmax.glsl

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#if defined(GL_FRAGMENT_SHADER)
#define GL_ARB_shader_stencil_export 1

spirv_execution_mode(extensions = ["SPV_EXT_shader_stencil_export"], capabilities = [5013], 5027);

spirv_decorate (extensions = ["SPV_EXT_shader_stencil_export"], capabilities = [5013], 11, 5014)
out int gl_FragStencilRefARB;
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#define GL_EXT_ray_flags_primitive_culling 1

const uint gl_RayFlagsSkipTrianglesEXT = 256U;
const uint gl_RayFlagsSkipAABBEXT = 512U;
145 changes: 145 additions & 0 deletions extensions/extension_headers/GL_EXT_ray_query.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#define GL_EXT_ray_query 1

#define rayQueryEXT spirv_type (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 4472)

#ifndef GL_EXT_ray_tracing
#define accelerationStructureEXT spirv_type (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 5341)

const uint gl_RayFlagsNoneEXT = 0U;
const uint gl_RayFlagsOpaqueEXT = 1U;
const uint gl_RayFlagsNoOpaqueEXT = 2U;
const uint gl_RayFlagsTerminateOnFirstHitEXT = 4U;
const uint gl_RayFlagsSkipClosestHitShaderEXT = 8U;
const uint gl_RayFlagsCullBackFacingTrianglesEXT = 16U;
const uint gl_RayFlagsCullFrontFacingTrianglesEXT = 32U;
const uint gl_RayFlagsCullOpaqueEXT = 64U;
const uint gl_RayFlagsCullNoOpaqueEXT = 128U;
#endif

const uint gl_RayQueryCommittedIntersectionNoneEXT = 0U;
const uint gl_RayQueryCommittedIntersectionTriangleEXT = 1U;
const uint gl_RayQueryCommittedIntersectionGeneratedEXT = 2U;

const uint gl_RayQueryCandidateIntersectionTriangleEXT = 0U;
const uint gl_RayQueryCandidateIntersectionAABBEXT = 1U;

spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4471,4478], id = 4473)
void rayQueryInitializeEXT(spirv_by_reference rayQueryEXT rayQuery, accelerationStructureEXT topLevel, uint rayFlags, uint cullMask, vec3 origin, float tMin, vec3 direction, float tMax);

spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 4477)
bool rayQueryProceedEXT(spirv_by_reference rayQueryEXT q);

spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 4474)
void rayQueryTerminateEXT(spirv_by_reference rayQueryEXT q);

spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 4475)
void rayQueryGenerateIntersectionEXT(spirv_by_reference rayQueryEXT q, float tHit);

spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 4476)
void rayQueryConfirmIntersectionEXT(spirv_by_reference rayQueryEXT q);

uint rayQueryGetIntersectionTypeEXT(spirv_by_reference rayQueryEXT q, bool committed) {
spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 4479)
uint rayQueryGetIntersectionTypeEXT_internal(spirv_by_reference rayQueryEXT q, uint committed);

return rayQueryGetIntersectionTypeEXT_internal(q, committed ? 1 : 0);
}

spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6016)
float rayQueryGetRayTMinEXT(spirv_by_reference rayQueryEXT q);

spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6016)
uint rayQueryGetRayFlagsEXT(spirv_by_reference rayQueryEXT q);

spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6030)
vec3 rayQueryGetWorldRayOriginEXT(spirv_by_reference rayQueryEXT q);

spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6029)
vec3 rayQueryGetWorldRayDirectionEXT(spirv_by_reference rayQueryEXT q);

float rayQueryGetIntersectionTEXT(spirv_by_reference rayQueryEXT q, bool committed) {
spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6018)
float rayQueryGetIntersectionTEXT_internal(spirv_by_reference rayQueryEXT q, uint committed);

return rayQueryGetIntersectionTEXT_internal(q, committed ? 1 : 0);
}

int rayQueryGetIntersectionInstanceCustomIndexEXT(spirv_by_reference rayQueryEXT q, bool committed) {
spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6019)
int rayQueryGetIntersectionInstanceCustomIndexEXT_internal(spirv_by_reference rayQueryEXT q, uint committed);

return rayQueryGetIntersectionInstanceCustomIndexEXT_internal(q, committed ? 1 : 0);
}

int rayQueryGetIntersectionInstanceIdEXT(spirv_by_reference rayQueryEXT q, bool committed) {
spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6020)
int rayQueryGetIntersectionInstanceIdEXT_internal(spirv_by_reference rayQueryEXT q, uint committed);

return rayQueryGetIntersectionInstanceIdEXT_internal(q, committed ? 1 : 0);
}

uint rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT(spirv_by_reference rayQueryEXT q, bool committed) {
spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6021)
uint rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT_internal(spirv_by_reference rayQueryEXT q, uint committed);

return rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT_internal(q, committed ? 1 : 0);
}

int rayQueryGetIntersectionGeometryIndexEXT(spirv_by_reference rayQueryEXT q, bool committed) {
spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6022)
int rayQueryGetIntersectionGeometryIndexEXT_internal(spirv_by_reference rayQueryEXT q, uint committed);

return rayQueryGetIntersectionGeometryIndexEXT_internal(q, committed ? 1 : 0);
}

int rayQueryGetIntersectionPrimitiveIndexEXT(spirv_by_reference rayQueryEXT q, bool committed) {
spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6023)
int rayQueryGetIntersectionPrimitiveIndexEXT_internal(spirv_by_reference rayQueryEXT q, uint committed);

return rayQueryGetIntersectionPrimitiveIndexEXT_internal(q, committed ? 1 : 0);
}

vec2 rayQueryGetIntersectionBarycentricsEXT(spirv_by_reference rayQueryEXT q, bool committed) {
spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6024)
vec2 rayQueryGetIntersectionBarycentricsEXT_internal(spirv_by_reference rayQueryEXT q, uint committed);

return rayQueryGetIntersectionBarycentricsEXT_internal(q, committed ? 1 : 0);
}

bool rayQueryGetIntersectionFrontFaceEXT(spirv_by_reference rayQueryEXT q, bool committed) {
spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6025)
bool rayQueryGetIntersectionFrontFaceEXT_internal(spirv_by_reference rayQueryEXT q, uint committed);

return rayQueryGetIntersectionFrontFaceEXT_internal(q, committed ? 1 : 0);
}

spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6026)
bool rayQueryGetIntersectionCandidateAABBOpaqueEXT(spirv_by_reference rayQueryEXT q);

vec3 rayQueryGetIntersectionObjectRayDirectionEXT(spirv_by_reference rayQueryEXT q, bool committed) {
spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6027)
vec3 rayQueryGetIntersectionObjectRayDirectionEXT_internal(spirv_by_reference rayQueryEXT q, uint committed);

return rayQueryGetIntersectionObjectRayDirectionEXT_internal(q, committed ? 1 : 0);
}

vec3 rayQueryGetIntersectionObjectRayOriginEXT(spirv_by_reference rayQueryEXT q, bool committed) {
spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6028)
vec3 rayQueryGetIntersectionObjectRayOriginEXT_internal(spirv_by_reference rayQueryEXT q, uint committed);

return rayQueryGetIntersectionObjectRayOriginEXT_internal(q, committed ? 1 : 0);
}

mat4x3 rayQueryGetIntersectionObjectToWorldEXT(spirv_by_reference rayQueryEXT q, bool committed) {
spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6031)
mat4x3 rayQueryGetIntersectionObjectToWorldEXT_internal(spirv_by_reference rayQueryEXT q, uint committed);

return rayQueryGetIntersectionObjectToWorldEXT_internal(q, committed ? 1 : 0);
}

mat4x3 rayQueryGetIntersectionWorldToObjectEXT(spirv_by_reference rayQueryEXT q, bool committed) {
spirv_instruction (extensions = ["SPV_KHR_ray_query"], capabilities = [4472], id = 6032)
mat4x3 rayQueryGetIntersectionWorldToObjectEXT_internal(spirv_by_reference rayQueryEXT q, uint committed);

return rayQueryGetIntersectionWorldToObjectEXT_internal(q, committed ? 1 : 0);
}
135 changes: 135 additions & 0 deletions extensions/extension_headers/GL_EXT_ray_tracing.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#if defined(GL_RAY_GENERATION_SHADER_EXT) || defined(GL_INTERSECTION_SHADER_EXT) || defined(GL_ANY_HIT_SHADER_EXT) || defined(GL_CLOSEST_HIT_SHADER_EXT) || defined(GL_MISS_SHADER_EXT) || defined(GL_CALLABLE_SHADER_EXT)
#define GL_EXT_ray_tracing 1

spirv_extension ("SPV_KHR_ray_tracing")
spirv_capability (5353)

#ifndef GL_EXT_ray_query
#define accelerationStructureEXT spirv_type (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], id = 5341)
#endif

#if defined(GL_RAY_GENERATION_SHADER_EXT) || defined(GL_CLOSEST_HIT_SHADER_EXT) || defined(GL_MISS_SHADER_EXT)
#define rayPayloadEXT spirv_storage_class (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 5338)
#endif
#if defined(GL_ANY_HIT_SHADER_EXT) || defined(GL_CLOSEST_HIT_SHADER_EXT) || defined(GL_MISS_SHADER_EXT)
#define rayPayloadInEXT spirv_storage_class (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 5342)
#endif
#if defined(GL_ANY_HIT_SHADER_EXT) || defined(GL_CLOSEST_HIT_SHADER_EXT) || defined(GL_INTERSECTION_SHADER_EXT)
#define hitAttributeEXT spirv_storage_class (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 5339)
#endif
#if defined(GL_RAY_GENERATION_SHADER_EXT) || defined(GL_CLOSEST_HIT_SHADER_EXT) || defined(GL_MISS_SHADER_EXT) || defined((GL_CALLABLE_SHADER)
#define callableDataEXT spirv_storage_class (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 5328)
#endif
#ifdef(GL_CALLABLE_SHADER)
#define callableDataInEXT spirv_storage_class (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 5329)
#endif
#define shaderRecordEXT spirv_storage_class (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 5343)

#ifndef GL_EXT_ray_query
const uint gl_RayFlagsNoneEXT = 0U;
const uint gl_RayFlagsOpaqueEXT = 1U;
const uint gl_RayFlagsNoOpaqueEXT = 2U;
const uint gl_RayFlagsTerminateOnFirstHitEXT = 4U;
const uint gl_RayFlagsSkipClosestHitShaderEXT = 8U;
const uint gl_RayFlagsCullBackFacingTrianglesEXT = 16U;
const uint gl_RayFlagsCullFrontFacingTrianglesEXT = 32U;
const uint gl_RayFlagsCullOpaqueEXT = 64U;
const uint gl_RayFlagsCullNoOpaqueEXT = 128U;
#endif

const uint gl_HitKindFrontFacingTriangleEXT = 0xFEU;
const uint gl_HitKindBackFacingTriangleEXT = 0xFFU;

const int gl_ScopeShaderCallEXT = 6;


spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 5319)
in uvec3 gl_LaunchIDEXT;
spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 5320)
in uvec3 gl_LaunchSizeEXT;

#if defined(GL_INTERSECTION_SHADER_EXT) || defined(GL_ANY_HIT_SHADER_EXT) || defined(GL_CLOSEST_HIT_SHADER_EXT)

spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 7)
in int gl_PrimitiveID;
spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 6)
in int gl_InstanceID;
spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 5327)
in int gl_InstanceCustomIndexEXT;
spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 5352)
in int gl_GeometryIndexEXT;
#endif

#if defined(GL_INTERSECTION_SHADER_EXT) || defined(GL_ANY_HIT_SHADER_EXT) || defined(GL_CLOSEST_HIT_SHADER_EXT) || defined(GL_MISS_SHADER_EXT)

spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 5321)
in vec3 gl_WorldRayOriginEXT;
spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 5322)
in vec3 gl_WorldRayDirectionEXT;
spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 5323)
in vec3 gl_ObjectRayOriginEXT;
spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 5324)
in vec3 gl_ObjectRayDirectionEXT;


spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 5325)
in float gl_RayTminEXT;
spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 5326)
in float gl_RayTmaxEXT;
spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 5351)
in uint gl_IncomingRayFlagsEXT;
#endif

#if defined(GL_ANY_HIT_SHADER_EXT) || defined(GL_CLOSEST_HIT_SHADER_EXT)

spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 5326)
in float gl_HitTEXT;
spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 5333)
in uint gl_HitKindEXT;
#endif

#if defined(GL_INTERSECTION_SHADER_EXT) || defined(GL_ANY_HIT_SHADER_EXT) || defined(GL_CLOSEST_HIT_SHADER_EXT)

spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 5330)
in mat4x3 gl_ObjectToWorldEXT;
#define gl_ObjectToWorld3x4EXT (transpose(gl_ObjectToWorldEXT))
spirv_decorate (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], 11, 5331)
in mat4x3 gl_WorldToObjectEXT;
#define gl_WorldToObject3x4EXT (transpose(gl_WorldToObjectEXT))
#endif

#if defined(GL_RAY_GENERATION_SHADER_EXT) || defined(GL_CLOSEST_HIT_SHADER_EXT) || defined(GL_MISS_SHADER_EXT)
spirv_instruction (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353,4478], id = 5337)
void traceRayEXT(accelerationStructureEXT topLevel,
uint rayFlags,
uint cullMask,
uint sbtRecordOffset,
uint sbtRecordStride,
uint missIndex,
vec3 origin,
float Tmin,
vec3 direction,
float Tmax,
int payload);
#endif

#ifdef GL_INTERSECTION_SHADER_EXT
spirv_instruction (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], id = 5334)
bool reportIntersectionEXT(float hitT, uint hitKind);
#endif

#ifdef GL_ANY_HIT_SHADER_EXT
spirv_instruction (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], id = 5335)
void ignoreIntersectionEXT();

spirv_instruction (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], id = 5336)
void terminateRayEXT();
#endif

#if defined(GL_RAY_GENERATION_SHADER_EXT) || defined(GL_CLOSEST_HIT_SHADER_EXT) || defined(GL_MISS_SHADER_EXT) || defined(GL_CALLABLE_SHADER_EXT)
spirv_instruction (extensions = ["SPV_KHR_ray_tracing"], capabilities = [5353], id = 5344)
void executeCallableEXT(uint sbtRecordIndex, int callable);
#endif
#endif


17 changes: 17 additions & 0 deletions extensions/extension_headers/GL_EXT_shader_realtime_clock.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#define GL_EXT_shader_realtime_clock 1

uvec2 clockRealtime2x32EXT(void) {
spirv_instruction (extensions = ["SPV_KHR_shader_clock"], capabilities = [5055], id = 5056);
uvec2 clockRealtime2x32EXT_internal(uint scope);

return clockRealtime2x32EXT_internal(1 /*Device scope*/);
}

#if defined(GL_EXT_shader_explicit_arithmetic_types_int64) || defined(GL_ARB_gpu_shader_int64) || defined(GL_AMD_gpu_shader_int64)
uint64_t clockRealtimeEXT(void) {
spirv_instruction (extensions = ["SPV_KHR_shader_clock"], capabilities = [5055], id = 5056);
uint64_t clockRealtimeEXT_internal(uint scope);

return clockRealtimeEXT_internal(1 /*Device scope*/);
}
#endif

0 comments on commit 75deffc

Please sign in to comment.