prototype for spirv linking

This commit is contained in:
2026-04-30 22:03:31 +03:00
parent 9569555347
commit 386c2fc045
10 changed files with 120 additions and 34 deletions

View File

@@ -2,13 +2,18 @@
COMMON
{
struct RayPayload
{
float3 m_vOrigin;
float3 m_vDirection;
float3 m_vColor;
};
}
CALLABLE
{
#include "textures.hlsl"
float4 brdfMain()
void brdfMain( inout RayPayload payload )
{
return float4(1);
payload.m_vColor = float3(1.0,0.0,1.0);
}
}

View File

@@ -1,9 +1,19 @@
#include "macros.hlsl"
COMMON
{
struct RayPayload
{
float3 m_vOrigin;
float3 m_vDirection;
float3 m_vColor;
};
}
CALLABLE
{
float4 CallableMain()
#include "textures.hlsl"
void CallableMain( inout RayPayload payload )
{
return float4(1);
payload.m_vColor = float3(1.0,0.0,1.0);
}
}

View File

@@ -27,26 +27,29 @@
#define CALLABLE namespace CallableShader_DO_NOT_USE
#endif
float4 Test()
/*
* we kinda want to lookup OpExecuteCallableKHR inside of runtime linker
* and replace _CallShader with our own
* but stupid slangc can't do noinline
* so we have to do id += 1 and id -= 1
* overall trick 5/10
*/
[noinline]
void _CallShader2<Payload>( uint32_t id, inout Payload data )
{
return float4(1,0.5,1,1);
id -= 1;
spirv_asm
{
OpExecuteCallableKHR $id $data;
};
}
#ifndef USE_CALLABLE_SHADERS
#define USE_CALLABLE_SHADERS
#endif
struct RunShaderResult_t<A>
{
A val;
};
[noinline]
[builtin]
RunShaderResult_t<A> RunShader<A, B>( uint32_t id, B data ) where optional B
void _CallShader<Payload>( uint32_t id, inout Payload data )
{
return {};
id += 1;
_CallShader2(id, data);
}
#define CallShader _CallShader
#endif

View File

@@ -2,8 +2,6 @@
#include "funny_shared.hlsl"
USE_CALLABLE_SHADERS;
COMMON {
cbuffer CameraInfo
{

View File

@@ -3,12 +3,12 @@
struct MeshPayload
{
float3 m_vColor;
}
struct RayPayload
{
float3 m_vOrigin;
float3 m_vDirection;
float3 m_vColor;
};
RAY
@@ -23,9 +23,8 @@ RAY
void rayMain()
{
RayPayload p = {};
RunShaderResult_t<MeshPayload> m = RunShader<MeshPayload, RayPayload>(0, p);
m.val.m_vColor;
printf("%f\n", m.val.m_vColor.x);
CallShader<RayPayload>(0, p);
printf("%f\n", p.m_vColor.x);
/*
uint2 pixel = DispatchRaysIndex().xy;