Shader linking i guess
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -34,3 +34,6 @@
|
||||
[submodule "external/SPIRV-Tools"]
|
||||
path = external/SPIRV-Tools
|
||||
url = https://github.com/KoT3isGood/SPIRV-Tools.git
|
||||
[submodule "external/SPIRV-Headers"]
|
||||
path = external/SPIRV-Headers
|
||||
url = https://github.com/KhronosGroup/SPIRV-Headers
|
||||
|
||||
1
external/SPIRV-Headers
vendored
Submodule
1
external/SPIRV-Headers
vendored
Submodule
Submodule external/SPIRV-Headers added at 6dd7ba9908
14
funnyassets/shaders/funny_basic_pbr.shader
Normal file
14
funnyassets/shaders/funny_basic_pbr.shader
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "macros.hlsl"
|
||||
|
||||
COMMON
|
||||
{
|
||||
|
||||
}
|
||||
CALLABLE
|
||||
{
|
||||
#include "textures.hlsl"
|
||||
float4 brdfMain()
|
||||
{
|
||||
return float4(1);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "macros.hlsl"
|
||||
|
||||
BRDF
|
||||
CALLABLE
|
||||
{
|
||||
float4 brdfMain()
|
||||
float4 CallableMain()
|
||||
{
|
||||
return float4(1);
|
||||
}
|
||||
|
||||
10
funnyassets/shaders/funny_shared.hlsl
Normal file
10
funnyassets/shaders/funny_shared.hlsl
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef FUNNY_SHARED_HLSL
|
||||
#define FUNNY_SHARED_HLSL
|
||||
|
||||
struct FunnyShaderInput_t
|
||||
{
|
||||
uint m_uInstance;
|
||||
float2 m_vTexcoord;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -16,15 +16,37 @@
|
||||
#endif
|
||||
|
||||
#ifdef RAY_SHADER
|
||||
#define RAY using namespace RAYShader; namespace RAYShader
|
||||
#define RAY using namespace RayShader; namespace RayShader
|
||||
#else
|
||||
#define RAY namespace RAYShader_DO_NOT_USE
|
||||
#define RAY namespace RayShader_DO_NOT_USE
|
||||
#endif
|
||||
|
||||
#ifdef BRDF_SHADER
|
||||
#define BRDF using namespace BRDFShader; namespace BRDFShader
|
||||
#ifdef CALLABLE_SHADER
|
||||
#define CALLABLE using namespace CallableShader; namespace CallableShader
|
||||
#else
|
||||
#define BRDF namespace BRDFShader_DO_NOT_USE
|
||||
#define CALLABLE namespace CallableShader_DO_NOT_USE
|
||||
#endif
|
||||
|
||||
float4 Test()
|
||||
{
|
||||
return float4(1,0.5,1,1);
|
||||
}
|
||||
|
||||
#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
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
#include "macros.hlsl"
|
||||
#include "funny_shared.hlsl"
|
||||
|
||||
|
||||
USE_CALLABLE_SHADERS;
|
||||
|
||||
COMMON {
|
||||
cbuffer CameraInfo
|
||||
|
||||
@@ -5,6 +5,11 @@ struct MeshPayload
|
||||
{
|
||||
float3 m_vColor;
|
||||
}
|
||||
struct RayPayload
|
||||
{
|
||||
float3 m_vOrigin;
|
||||
float3 m_vDirection;
|
||||
};
|
||||
|
||||
RAY
|
||||
{
|
||||
@@ -14,8 +19,14 @@ RAY
|
||||
RWTexture2D<float> g_tIndirectImage;
|
||||
|
||||
|
||||
|
||||
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);
|
||||
|
||||
/*
|
||||
uint2 pixel = DispatchRaysIndex().xy;
|
||||
MeshPayload p;
|
||||
|
||||
0
funnyassets/shaders/mesh_trace_gen.h
Normal file
0
funnyassets/shaders/mesh_trace_gen.h
Normal file
@@ -18,27 +18,12 @@ void C_MOBAPlayer::Spawn()
|
||||
void C_MOBAPlayer::Think( float fDelta )
|
||||
{
|
||||
|
||||
<<<<<<< HEAD
|
||||
C_MOBAPlayer *pEntity = (C_MOBAPlayer*)UTIL_GetLocalPlayer();
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
=======
|
||||
C_MOBAPlayer *pPlayerEntity = (C_MOBAPlayer*)UTIL_GetLocalPlayer();
|
||||
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> c251089 (different stuff in physics)
|
||||
>>>>>>> a2652ed (merges)
|
||||
m_vMovementVector.z = m_bIsForward - m_bIsBack;
|
||||
m_vMovementVector.x = m_bIsLeft - m_bIsRight;
|
||||
|
||||
if (pEntity == this)
|
||||
=======
|
||||
m_vMovementVector.z = m_bIsBack - m_bIsForward;
|
||||
m_vMovementVector.x = m_bIsRight - m_bIsLeft;
|
||||
|
||||
if (pPlayerEntity == this)
|
||||
>>>>>>> 83e8198 (different stuff in physics)
|
||||
{
|
||||
Vector vCameraPos;
|
||||
vCameraPos = GetAbsOrigin();
|
||||
|
||||
@@ -104,7 +104,7 @@ void CFunnyMeshInstance::Frame()
|
||||
glm_scale_make(m, v);
|
||||
glm_mat4_mul(m_data.m_matTranslation, m, m_data.m_matTranslation);
|
||||
|
||||
m_data.m_uAlbedo = 1;
|
||||
m_data.m_uAlbedo = 0;
|
||||
/*
|
||||
V_printf("AAAAA %f %f %f %f\n", m_data.m_matTranslation[0][0], m_data.m_matTranslation[0][1], m_data.m_matTranslation[0][2], m_data.m_matTranslation[0][3]);
|
||||
V_printf("AAAAA %f %f %f %f\n", m_data.m_matTranslation[1][0], m_data.m_matTranslation[1][1], m_data.m_matTranslation[1][2], m_data.m_matTranslation[1][3]);
|
||||
@@ -213,6 +213,10 @@ void CFunnyWorldRenderer::Init()
|
||||
m_pRasterCommandList = g_pRenderContext->CreateCommandList();
|
||||
m_pViewBuffer = g_pRenderContext->CreateConstantBuffer(sizeof(ViewBuffer_t));
|
||||
m_pTextures = g_pRenderContext->CreateTextureArray();
|
||||
|
||||
IRayTracingShader *prt = g_pRenderContext->CreateRayShader("game/core/shaders/mesh_trace.shader_c");
|
||||
prt->AddShader("error", "game/core/shaders/funny_error.shader_c");
|
||||
prt->Build();
|
||||
}
|
||||
|
||||
void CFunnyWorldRenderer::Tick( float fDelta )
|
||||
@@ -228,13 +232,7 @@ void CFunnyWorldRenderer::Frame( float fDelta )
|
||||
glm_mat4_identity(matCamera);
|
||||
glm_mat4_identity(matCamera2);
|
||||
glm_translate(matCamera2, m_vPos);
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
glm_mat4_inv(matCamera2, matCamera2);
|
||||
>>>>>>> c251089 (different stuff in physics)
|
||||
>>>>>>> a2652ed (merges)
|
||||
glm_perspective(glm_rad(75), uWidth/(float)uHeight, 0.01, 10000, matCamera);
|
||||
glm_mul(matCamera, matCamera2, matCamera);
|
||||
m_pViewBufferData = (ViewBuffer_t*)m_pViewBuffer->Map();
|
||||
|
||||
23
game/server/light.cpp
Normal file
23
game/server/light.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "light.h"
|
||||
|
||||
BEGIN_DATADESC(CBaseLight)
|
||||
DEFINE_KEYFIELD(m_vColor, FIELD_COLOR4, "color")
|
||||
DEFINE_KEYFIELD(m_fBrightness, FIELD_FLOAT, "brightness")
|
||||
DEFINE_KEYFIELD(m_fRadius, FIELD_FLOAT, "radius")
|
||||
DEFINE_KEYFIELD(m_eLightFlags, FIELD_INTEGER, "light_flags")
|
||||
DEFINE_KEYFIELD(m_bIsEnabled, FIELD_BOOLEAN, "enabled")
|
||||
END_DATADESC()
|
||||
|
||||
IMPLEMENT_SEND_DT(CBaseLight)
|
||||
NetPropColor4(m_vColor),
|
||||
NetPropFloat(m_fBrightness),
|
||||
NetPropFloat(m_fRadius),
|
||||
NetPropInt(m_eLightFlags),
|
||||
NetPropBool(m_bIsEnabled),
|
||||
END_SEND_DT()
|
||||
|
||||
IMPLEMENT_EMPTY_RECV_DT(CBaseLight)
|
||||
|
||||
|
||||
|
||||
LINK_ENTITY_TO_CLASS(light_point, CPointLight);
|
||||
27
game/server/light.h
Normal file
27
game/server/light.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef LIGHT_H
|
||||
#define LIGHT_H
|
||||
|
||||
#include "pointentity.h"
|
||||
#include "../shared/light.h"
|
||||
|
||||
class CBaseLight: public CPointEntity
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS(CBaseLight, CPointEntity)
|
||||
DECLARE_DATADESC()
|
||||
DECLARE_SERVERCLASS()
|
||||
|
||||
ColorAlpha m_vColor;
|
||||
float m_fBrightness;
|
||||
float m_fRadius;
|
||||
int m_eLightFlags;
|
||||
bool m_bIsEnabled;
|
||||
};
|
||||
|
||||
class CPointLight: public CBaseLight
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS(CPointLight, CBaseLight);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -5,7 +5,8 @@
|
||||
|
||||
CMOBAPlayer::CMOBAPlayer()
|
||||
{
|
||||
m_hCuboid = g_pPhysics->CreateBall({1});
|
||||
m_hCuboid = g_pPhysics->CreateCube({1,1,1});
|
||||
|
||||
}
|
||||
|
||||
CMOBAPlayer::~CMOBAPlayer()
|
||||
@@ -16,25 +17,16 @@ CMOBAPlayer::~CMOBAPlayer()
|
||||
void CMOBAPlayer::Spawn()
|
||||
{
|
||||
CBaseEntity::Spawn();
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> a2652ed (merges)
|
||||
SetPhysics(k_EPhysics_Static);
|
||||
SetModel("game/core/models/sphere.fmdl");
|
||||
SetScale(1);
|
||||
SetAbsOrigin({0,-14.5, 0});
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
=======
|
||||
SetModel("game/core/models/sphere.fmdl");
|
||||
SetScale(1);
|
||||
SetAbsOrigin({0,-11.5, 0});
|
||||
>>>>>>> c251089 (different stuff in physics)
|
||||
>>>>>>> a2652ed (merges)
|
||||
SetThink(Think);
|
||||
};
|
||||
|
||||
bool CMOBAPlayer::CheckMask( HCollider hCollider )
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
void CMOBAPlayer::Think( float fDelta )
|
||||
{
|
||||
BaseClass::Think(fDelta);
|
||||
@@ -47,18 +39,11 @@ void CMOBAPlayer::Think( float fDelta )
|
||||
|
||||
vPosition.x += m_vMovementVector.x*fDelta*5;
|
||||
vPosition.z += m_vMovementVector.z*fDelta*5;
|
||||
<<<<<<< HEAD
|
||||
SetAbsOrigin(vPosition);
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
=======
|
||||
CastResult_t result = g_pPhysicsWorld->ShapeCast(m_hCuboid, {0,0,0,1}, vPosition, {vPosition.x, vPosition.y, -100});
|
||||
CastResult_t result = g_pPhysicsWorld->ShapeCast(m_hCuboid, {0,0,0,1}, vPosition, {vPosition.x, vPosition.y, -100}, CheckMask);
|
||||
if (result.m_bIsHit)
|
||||
SetAbsOrigin(result.m_vCollisionPoint);
|
||||
else
|
||||
SetAbsOrigin(vPosition);
|
||||
>>>>>>> c251089 (different stuff in physics)
|
||||
>>>>>>> a2652ed (merges)
|
||||
};
|
||||
|
||||
LINK_ENTITY_TO_CLASS(player, CMOBAPlayer)
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
#include "physicsprop.h"
|
||||
|
||||
class CMOBAPlayer: public CPhysicsProp
|
||||
class CMOBAPlayer: public CBaseModelEntity
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS(CMOBAPlayer, CPhysicsProp);
|
||||
DECLARE_CLASS(CMOBAPlayer, CBaseModelEntity);
|
||||
DECLARE_DATADESC();
|
||||
DECLARE_SERVERCLASS()
|
||||
|
||||
@@ -14,6 +14,8 @@ public:
|
||||
virtual ~CMOBAPlayer();
|
||||
virtual void Spawn( void ) override;
|
||||
void Think( float fDelta );
|
||||
|
||||
static bool CheckMask( HCollider hCollider );
|
||||
private:
|
||||
Vector m_vMovementVector = {};
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
#include "pointentity.h"
|
||||
|
||||
|
||||
@@ -21,12 +21,14 @@ enum fieldtype_t {
|
||||
FIELD_FLOAT4,
|
||||
FIELD_QUATERNION,
|
||||
FIELD_QUATERNION_QANGLE,
|
||||
FIELD_COLOR255,
|
||||
FIELD_COLOR1,
|
||||
FIELD_COLOR3,
|
||||
FIELD_COLOR4,
|
||||
FIELD_INTEGER,
|
||||
FIELD_BOOLEAN,
|
||||
FIELD_MAT4x4,
|
||||
|
||||
FIELD_FLAGS,
|
||||
|
||||
FIELD_MATERIAL,
|
||||
FIELD_TEXTURE,
|
||||
FIELD_MODEL,
|
||||
|
||||
10
game/shared/light.h
Normal file
10
game/shared/light.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef SHARED_LIGHT_H
|
||||
#define SHARED_LIGHT_H
|
||||
|
||||
enum ELightFlags
|
||||
{
|
||||
k_ELight_Shadows = 0x1,
|
||||
k_ELight_Radiance = 0x2,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -26,7 +26,8 @@ struct netmap_t
|
||||
uint32_t m_uFieldCount;
|
||||
};
|
||||
|
||||
#define NetPropInt(name) { #name, FIELD_INT, _class_offsetof(ThisClass, name), sizeof(name)}
|
||||
#define NetPropInt(name) { #name, FIELD_INTEGER, _class_offsetof(ThisClass, name), sizeof(name)}
|
||||
#define NetPropBool(name) { #name, FIELD_BOOLEAN, _class_offsetof(ThisClass, name), sizeof(name)}
|
||||
#define NetPropString(name) { #name, FIELD_STRING, _class_offsetof(ThisClass, name), sizeof(name)}
|
||||
#define NetPropFloat(name) { #name, FIELD_FLOAT, _class_offsetof(ThisClass, name), sizeof(name)}
|
||||
#define NetPropFloat3(name) \
|
||||
@@ -37,7 +38,12 @@ struct netmap_t
|
||||
NetPropFloat(name.x), \
|
||||
NetPropFloat(name.y), \
|
||||
NetPropFloat(name.z), \
|
||||
NetPropFloat(name.w) \
|
||||
NetPropFloat(name.w)
|
||||
#define NetPropColor4(name) \
|
||||
NetPropFloat(name.r), \
|
||||
NetPropFloat(name.g), \
|
||||
NetPropFloat(name.b), \
|
||||
NetPropFloat(name.a)
|
||||
|
||||
#define __DECLARE_NETCLASS_NOBASE() \
|
||||
netmap_t *GetBaseSendMap(); \
|
||||
|
||||
@@ -9,6 +9,7 @@ ADD_DEPENDENCY_BUILD_FILE(cfg, "../buildcfg.cpp");
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier0, FUNNYSTDLIB"tier0/build.cpp");
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier1, FUNNYSTDLIB"tier1/build.cpp");
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier2, FUNNYSTDLIB"tier2/build.cpp");
|
||||
ADD_DEPENDENCY_BUILD_FILE(gen, "vulkan/generate.build.cpp");
|
||||
|
||||
CUtlVector<CUtlString> MaterialSystem_CompiledFiles = {
|
||||
"materialsystem.cpp",
|
||||
@@ -22,8 +23,11 @@ CUtlVector<CUtlString> RenderContextVulkan_CompiledFiles = {
|
||||
"vulkan/rendercommandlist.cpp",
|
||||
"vulkan/material.cpp",
|
||||
"vulkan/shader.cpp",
|
||||
"vulkan/rtshader.cpp",
|
||||
"vulkan/utils.cpp",
|
||||
"vulkan/vma.cpp",
|
||||
"vulkan/rtlinker.cpp",
|
||||
"vulkan/rtlinker_gen.cpp",
|
||||
"vulkan/commands/draw.cpp",
|
||||
"vulkan/commands/transfer.cpp",
|
||||
"vulkan/commands/base.cpp",
|
||||
|
||||
@@ -28,8 +28,12 @@ ShaderObject_t *CCompiledShader::AllocateShader()
|
||||
|
||||
ShaderObject_t *CCompiledShader::FindShaderObject( EShaderBackend eBackend, EShaderStage eStage )
|
||||
{
|
||||
V_printf("%i\n", m_objects.GetSize());
|
||||
V_printf("%i\n", m_lumps.GetSize());
|
||||
for ( auto &o: m_objects )
|
||||
{
|
||||
V_printf("%i\n", o.m_eBackend);
|
||||
V_printf("%i\n", o.m_eStage);
|
||||
if ( o.m_eBackend != eBackend )
|
||||
continue;
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
[Shaders]
|
||||
|
||||
|
||||
[Raster.Input.Triangle]
|
||||
VertexSize = 20
|
||||
Index = RGB32_UINT
|
||||
Position = RGB32_SFLOAT
|
||||
UV = RG32_SFLOAT
|
||||
|
||||
[Raster.Parameters]
|
||||
TextureAtlas = true
|
||||
|
||||
[Raster.Outputs]
|
||||
Color0 = RGBA16_SRGB
|
||||
Depth = D32_SFLOAT
|
||||
|
||||
[Shading.Parameters]
|
||||
TextureAtlas = true
|
||||
105
materialsystem/vulkan/generate.build.cpp
Normal file
105
materialsystem/vulkan/generate.build.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
#include "tier2/fileformats/json.h"
|
||||
#include "tier2/ifilesystem.h"
|
||||
#include "tier0/commandline.h"
|
||||
#include "tier0/mem.h"
|
||||
#include "helper.h"
|
||||
#define EXTERNAL "../../external/"
|
||||
#define GRAMMAR EXTERNAL"SPIRV-Headers/include/spirv/unified1/spirv.core.grammar.json"
|
||||
#define OUTPUT "rtlinker_gen.cpp"
|
||||
|
||||
DECLARE_BUILD_STAGE(SpirvOperandsGen)
|
||||
{
|
||||
if (!filesystem2->ShouldRecompile(GRAMMAR, OUTPUT))
|
||||
return 0;
|
||||
if (!filesystem2->ShouldRecompile(__FILE__, OUTPUT))
|
||||
return 0;
|
||||
|
||||
IFileHandle *pHandle = filesystem->Open(GRAMMAR, FILEMODE_READ);
|
||||
if (pHandle == NULL)
|
||||
return 0;
|
||||
|
||||
const char *szContents = filesystem->ReadString(pHandle);
|
||||
filesystem->Close(pHandle);
|
||||
pHandle = filesystem->Open(OUTPUT, FILEMODE_WRITE);
|
||||
IJSONValue *pRoot = JSONManager()->ReadString(szContents);
|
||||
IJSONArray *instructions = pRoot->GetObject()->GetValue("instructions")->GetArray();
|
||||
filesystem->PrintF( pHandle, "#include \"rtlinker_gen.h\"\n");
|
||||
filesystem->PrintF( pHandle, "int SpvGetOperandCount( int op )\n{\nswitch ( op ) {\n");
|
||||
for ( int i = 0; i < instructions->GetCount(); i++)
|
||||
{
|
||||
IJSONObject *op = instructions->GetParameter(i)->GetObject();
|
||||
if (op->GetValue("operands"))
|
||||
filesystem->PrintF( pHandle, "case %.0f: return %u;\n", op->GetValue("opcode")->GetNumberValue(), op->GetValue("operands")->GetArray()->GetCount());
|
||||
|
||||
}
|
||||
filesystem->PrintF( pHandle, "default: break;\n}\nreturn 0;\n}\n");
|
||||
filesystem->PrintF( pHandle, "void SpvGetOperands( int op, ESpirvOperandType *pTypes )\n{\nswitch ( op ) {\n");
|
||||
for ( int i = 0; i < instructions->GetCount(); i++)
|
||||
{
|
||||
IJSONObject *op = instructions->GetParameter(i)->GetObject();
|
||||
if (op->GetValue("operands"))
|
||||
{
|
||||
IJSONArray *operands = op->GetValue("operands")->GetArray();
|
||||
filesystem->PrintF( pHandle, "case %.0f:\n", op->GetValue("opcode")->GetNumberValue());
|
||||
for ( int o = 0; o < operands->GetCount(); o++ )
|
||||
{
|
||||
CUtlString type = operands->GetParameter(o)->GetObject()->GetValue("kind")->GetStringValue();
|
||||
if (type == "IdRef")
|
||||
filesystem->PrintF( pHandle, "pTypes[%u] = k_ESpirv_RefId;\n",o);
|
||||
else if (type == "IdResult")
|
||||
filesystem->PrintF( pHandle, "pTypes[%u] = k_ESpirv_ResultId;\n",o);
|
||||
else if (type == "IdResultType")
|
||||
filesystem->PrintF( pHandle, "pTypes[%u] = k_ESpirv_ResultTypeId;\n",o);
|
||||
else if (type == "IdScope")
|
||||
filesystem->PrintF( pHandle, "pTypes[%u] = k_ESpirv_ScopeId;\n",o);
|
||||
else if (type == "IdMemorySemantics")
|
||||
filesystem->PrintF( pHandle, "pTypes[%u] = k_ESpirv_MemorySemanticsId;\n",o);
|
||||
}
|
||||
filesystem->PrintF( pHandle, "break;\n");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
filesystem->PrintF( pHandle, "default: break;\n}\n");
|
||||
filesystem->PrintF( pHandle, "}\n");
|
||||
filesystem->PrintF( pHandle, "void SpvGetOperandFlags( int op, ESpirvOperandFlags *pTypes )\n{\nswitch ( op ) {\n");
|
||||
for ( int i = 0; i < instructions->GetCount(); i++)
|
||||
{
|
||||
IJSONObject *op = instructions->GetParameter(i)->GetObject();
|
||||
if (op->GetValue("operands"))
|
||||
{
|
||||
IJSONArray *operands = op->GetValue("operands")->GetArray();
|
||||
filesystem->PrintF( pHandle, "case %.0f:\n", op->GetValue("opcode")->GetNumberValue());
|
||||
for ( int o = 0; o < operands->GetCount(); o++ )
|
||||
{
|
||||
IJSONValue *q = operands->GetParameter(o)->GetObject()->GetValue("quantifier");
|
||||
if (q == 0)
|
||||
{
|
||||
filesystem->PrintF( pHandle, "pTypes[%u] = k_ESpirvOperandFlags_None;\n",o);
|
||||
continue;
|
||||
}
|
||||
|
||||
CUtlString type = q->GetStringValue();
|
||||
if (type == NULL)
|
||||
filesystem->PrintF( pHandle, "pTypes[%u] = k_ESpirvOperandFlags_None;\n",o);
|
||||
if (type == "?")
|
||||
filesystem->PrintF( pHandle, "pTypes[%u] = k_ESpirvOperandFlags_Optional;\n",o);
|
||||
else if (type == "*")
|
||||
filesystem->PrintF( pHandle, "pTypes[%u] = k_ESpirvOperandFlags_Array;\n",o);
|
||||
}
|
||||
filesystem->PrintF( pHandle, "break;\n");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
filesystem->PrintF( pHandle, "default: break;\n}\n");
|
||||
filesystem->PrintF( pHandle, "}\n");
|
||||
filesystem->Close( pHandle );
|
||||
|
||||
V_free((void*)szContents);
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ static const char *s_vkDeviceExtensions[] = {
|
||||
#undef REQUIRED_EXTENSION
|
||||
#undef OPTIONAL_EXTENSION
|
||||
|
||||
SupportedVulkanExtensions_t g_vkAvailableExtensions;
|
||||
SupportedVulkanExtensions_t g_vkAvailableExtensions = {};
|
||||
|
||||
|
||||
uint32_t g_iDrawFamily;
|
||||
@@ -458,7 +458,9 @@ public:
|
||||
IBuffer *CreateBufferAligned( uint32_t nSize, uint32_t nAlignment, VkBufferUsageFlags2 eUsage );
|
||||
|
||||
virtual IShader *CreateShader( const char *szName ) override;
|
||||
virtual void DestroyShader( IShader *pShader ) override;
|
||||
virtual IRayTracingShader *CreateRayShader( const char *szName ) override;
|
||||
virtual IComputeShader *CreateComputeShader( const char *szName ) override;
|
||||
virtual void DestroyShader( IBaseShader *pShader ) override;
|
||||
|
||||
virtual IMaterial *CreateMaterial( IShader *pShader ) override;
|
||||
virtual void DestroyMaterial( IMaterial *pMaterial ) override;
|
||||
@@ -593,7 +595,21 @@ IShader *CVkRenderContext::CreateShader( const char *szName )
|
||||
return pShader;
|
||||
}
|
||||
|
||||
void CVkRenderContext::DestroyShader( IShader *pShader )
|
||||
IRayTracingShader *CVkRenderContext::CreateRayShader( const char *szName )
|
||||
{
|
||||
CVkRayTracingShader *pShader = new CVkRayTracingShader();
|
||||
VkGraphicsPipelineCreateInfo stPipelineCreateInfo = {};
|
||||
ICompiledShaderManager *pCompiledShaderManager = (ICompiledShaderManager*)CreateInterface(COMPILED_SHADER_MANAGER_INTERFACE_VERSION, NULL);
|
||||
pCompiledShaderManager->ReadFromFile(&pShader->m_shader, szName);
|
||||
pShader->m_hDevice = s_vkDevice;
|
||||
return pShader;
|
||||
}
|
||||
|
||||
IComputeShader *CVkRenderContext::CreateComputeShader( const char *szName )
|
||||
{
|
||||
}
|
||||
|
||||
void CVkRenderContext::DestroyShader( IBaseShader *pShader )
|
||||
{
|
||||
delete pShader;
|
||||
}
|
||||
|
||||
249
materialsystem/vulkan/rtlinker.cpp
Normal file
249
materialsystem/vulkan/rtlinker.cpp
Normal file
@@ -0,0 +1,249 @@
|
||||
#include "rtlinker.h"
|
||||
#define SPV_ENABLE_UTILITY_CODE
|
||||
#include "spirv/unified1/spirv.h"
|
||||
#include "rtlinker_gen.h"
|
||||
#include "tier2/ifilesystem.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
#define MINI_SPIRV_IMPLEMENTATION
|
||||
#include "../minispv/minispv.h"
|
||||
|
||||
class CSpirvModule
|
||||
{
|
||||
CUtlVector<SpvCapability> m_capabilities;
|
||||
CUtlVector<CUtlString> m_extensions;
|
||||
CUtlVector<CUtlString> m_instructionImports;
|
||||
SpvAddressingModel m_addressingModel;
|
||||
SpvMemoryModel m_memoryModel;
|
||||
CUtlVector<CUtlString> m_entryPoints;
|
||||
|
||||
};
|
||||
|
||||
|
||||
void CVkShaderLinker::SetMainSpirv( uint32_t size, uint32_t *data )
|
||||
{
|
||||
m_main = (SpirvShader_t){size,data};
|
||||
}
|
||||
void CVkShaderLinker::AddSpirv( uint32_t size, uint32_t *data )
|
||||
{
|
||||
m_shaders.AppendTail((SpirvShader_t){size,data});
|
||||
}
|
||||
|
||||
#define SET_LAST(a) if ( a > last ) last = a;
|
||||
void CVkShaderLinker::Build()
|
||||
{
|
||||
mspv_module *mod = mspv_read_module(m_main.m_size, m_main.m_data);
|
||||
uint32_t last = 0;
|
||||
uint32_t current = 0;
|
||||
|
||||
for ( int i = 0; i < mod->types.count; i++ )
|
||||
{
|
||||
SET_LAST(mod->types.data[i].id);
|
||||
}
|
||||
|
||||
for ( int i = 0; i < mod->ext_instructions.count; i++ )
|
||||
{
|
||||
SET_LAST(mod->ext_instructions.data[i].id);
|
||||
}
|
||||
for ( int i = 0; i < mod->variables.count; i++ )
|
||||
{
|
||||
SET_LAST(mod->variables.data[i].result);
|
||||
SET_LAST(mod->variables.data[i].resulttype);
|
||||
}
|
||||
for ( int i = 0; i < mod->functions.count; i++ )
|
||||
{
|
||||
SET_LAST(mod->functions.data[i].result);
|
||||
mspv_function &f = mod->functions.data[i];
|
||||
for ( int u = 0; u < f.instructions.len; )
|
||||
{
|
||||
SpvOp op = (SpvOp)(f.instructions.data[u]&0xFFFF);
|
||||
uint32_t uOpLen = f.instructions.data[u]>>16;
|
||||
uint32_t uOpCount = SpvGetOperandCount(op);
|
||||
if (uOpCount == 0)
|
||||
{
|
||||
u+=uOpLen;
|
||||
continue;
|
||||
}
|
||||
ESpirvOperandType *peOps = (ESpirvOperandType *)V_malloc(uOpCount*sizeof(ESpirvOperandType));
|
||||
ESpirvOperandFlags *peFlags = (ESpirvOperandFlags *)V_malloc(uOpCount*sizeof(ESpirvOperandFlags));
|
||||
SpvGetOperands(op, peOps);
|
||||
SpvGetOperandFlags(op, peFlags);
|
||||
for ( int c = 0, uParam = 0; (c < uOpCount) && (c < uOpLen-1); c++ )
|
||||
{
|
||||
switch (peOps[c])
|
||||
{
|
||||
case k_ESpirv_RefId:
|
||||
case k_ESpirv_ResultId:
|
||||
case k_ESpirv_ResultTypeId:
|
||||
case k_ESpirv_ScopeId:
|
||||
case k_ESpirv_MemorySemanticsId:
|
||||
if (peFlags[uParam]==k_ESpirvOperandFlags_None)
|
||||
{
|
||||
uParam++;
|
||||
}
|
||||
SET_LAST(f.instructions.data[u+c+1]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
u+=uOpLen;
|
||||
V_free(peOps);
|
||||
|
||||
}
|
||||
}
|
||||
current = last;
|
||||
|
||||
/* now we can combine shaders*/
|
||||
CUtlVector<uint32_t> functions = {};
|
||||
for (auto &shader: m_shaders)
|
||||
{
|
||||
mspv_module *s = mspv_read_module(shader.m_size, shader.m_data);
|
||||
for ( int i = 0; i < s->capabilities.count; i++ )
|
||||
{
|
||||
mspv_array_push(mod->capabilities, s->capabilities.data[i]);
|
||||
}
|
||||
for ( int i = 0; i < s->extensions.count; i++ )
|
||||
{
|
||||
mspv_array_push(mod->extensions, s->extensions.data[i]);
|
||||
}
|
||||
|
||||
for ( int i = 0; i < s->ext_instructions.count; i++ )
|
||||
{
|
||||
SET_LAST(s->ext_instructions.data[i].id);
|
||||
}
|
||||
|
||||
for ( int i = 0; i < s->entry_points.count; i++ )
|
||||
{
|
||||
functions.AppendTail(s->entry_points.data[i].id+current);
|
||||
SET_LAST(s->entry_points.data[i].id+current);
|
||||
}
|
||||
|
||||
for ( int i = 0; i < s->variables.count; i++ )
|
||||
{
|
||||
s->variables.data[i].result+=current;
|
||||
s->variables.data[i].resulttype+=current;
|
||||
SET_LAST(s->variables.data[i].result)
|
||||
SET_LAST(s->variables.data[i].resulttype)
|
||||
mspv_array_push(mod->variables, s->variables.data[i]);
|
||||
}
|
||||
for ( int i = 0; i < s->types.count; i++ )
|
||||
{
|
||||
s->types.data[i].id+=current;
|
||||
mspv_data_view &dv = s->types.data[i].dv;
|
||||
SET_LAST(s->types.data[i].id);
|
||||
|
||||
SpvOp op = (SpvOp)(dv.data[0]&0xFFFF);
|
||||
uint32_t uOpLen = dv.data[0]>>16;
|
||||
uint32_t uOpCount = SpvGetOperandCount(op);
|
||||
if (uOpCount == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ESpirvOperandType *peOps = (ESpirvOperandType *)V_malloc(uOpCount*sizeof(ESpirvOperandType));
|
||||
ESpirvOperandFlags *peFlags = (ESpirvOperandFlags *)V_malloc(uOpCount*sizeof(ESpirvOperandFlags));
|
||||
SpvGetOperands(op, peOps);
|
||||
SpvGetOperandFlags(op, peFlags);
|
||||
/* shift the stuff */
|
||||
for ( int c = 0, uParam = 0; (c < uOpCount) && (c < uOpLen-1); c++ )
|
||||
{
|
||||
switch (peOps[uParam])
|
||||
{
|
||||
case k_ESpirv_RefId:
|
||||
case k_ESpirv_ResultId:
|
||||
case k_ESpirv_ResultTypeId:
|
||||
case k_ESpirv_ScopeId:
|
||||
case k_ESpirv_MemorySemanticsId:
|
||||
|
||||
if (peFlags[uParam]==k_ESpirvOperandFlags_None)
|
||||
{
|
||||
dv.data[c+1]+=current;
|
||||
uParam++;
|
||||
|
||||
}
|
||||
if (peFlags[uParam]==k_ESpirvOperandFlags_Array)
|
||||
{
|
||||
dv.data[c+1]+=current;
|
||||
};
|
||||
SET_LAST(dv.data[c+1]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
V_free(peFlags);
|
||||
V_free(peOps);
|
||||
mspv_array_push(mod->types, s->types.data[i]);
|
||||
}
|
||||
|
||||
for ( int i = 0; i < s->functions.count; i++ )
|
||||
{
|
||||
s->functions.data[i].result+=current;
|
||||
SET_LAST(s->functions.data[i].result);
|
||||
mspv_function &f = s->functions.data[i];
|
||||
for ( int u = 0; u < f.instructions.len; )
|
||||
{
|
||||
SpvOp op = (SpvOp)(f.instructions.data[u]&0xFFFF);
|
||||
uint32_t uOpLen = f.instructions.data[u]>>16;
|
||||
uint32_t uOpCount = SpvGetOperandCount(op);
|
||||
if (uOpCount == 0)
|
||||
{
|
||||
u+=uOpLen;
|
||||
continue;
|
||||
}
|
||||
ESpirvOperandType *peOps = (ESpirvOperandType *)V_malloc(uOpCount*sizeof(ESpirvOperandType));
|
||||
SpvGetOperands(op, peOps);
|
||||
/* shift the stuff */
|
||||
for ( int c = 0; c < uOpCount && c < (uOpLen-1); c++ )
|
||||
{
|
||||
switch (peOps[c])
|
||||
{
|
||||
case k_ESpirv_RefId:
|
||||
case k_ESpirv_ResultId:
|
||||
case k_ESpirv_ResultTypeId:
|
||||
case k_ESpirv_ScopeId:
|
||||
case k_ESpirv_MemorySemanticsId:
|
||||
|
||||
f.instructions.data[u+c+1]+=current;
|
||||
SET_LAST(f.instructions.data[u+c+1]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
u+=uOpLen;
|
||||
V_free(peOps);
|
||||
|
||||
}
|
||||
mspv_array_push(mod->functions, s->functions.data[i]);
|
||||
}
|
||||
current = last;
|
||||
}
|
||||
|
||||
mspv_spv spv = mspv_write_module(mod);
|
||||
mspv_close_module(mod);
|
||||
m_out.m_data = spv.data;
|
||||
m_out.m_size = spv.count;
|
||||
|
||||
IFileHandle *ph = filesystem->Open("a.txt", FILEMODE_WRITE);
|
||||
filesystem->Write(ph, spv.data, spv.count*4);
|
||||
filesystem->Close(ph);
|
||||
|
||||
|
||||
mspv_array_destroy(spv);
|
||||
|
||||
|
||||
}
|
||||
uint32_t CVkShaderLinker::GetSize()
|
||||
{
|
||||
return m_out.m_size;
|
||||
|
||||
}
|
||||
uint32_t *CVkShaderLinker::GetData()
|
||||
{
|
||||
return m_out.m_data;
|
||||
|
||||
}
|
||||
28
materialsystem/vulkan/rtlinker.h
Normal file
28
materialsystem/vulkan/rtlinker.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef VULKAN_RT_COMPILER_H
|
||||
#define VULKAN_RT_COMPILER_H
|
||||
|
||||
#include "tier1/utlvector.h"
|
||||
|
||||
class CVkShaderLinker
|
||||
{
|
||||
public:
|
||||
void SetMainSpirv( uint32_t size, uint32_t *data );
|
||||
void AddSpirv( uint32_t size, uint32_t *data );
|
||||
void Build();
|
||||
uint32_t GetSize();
|
||||
uint32_t *GetData();
|
||||
|
||||
private:
|
||||
|
||||
struct SpirvShader_t
|
||||
{
|
||||
uint32_t m_size;
|
||||
uint32_t *m_data;
|
||||
};
|
||||
|
||||
CUtlVector<SpirvShader_t> m_shaders;
|
||||
SpirvShader_t m_main;
|
||||
SpirvShader_t m_out;
|
||||
};
|
||||
|
||||
#endif
|
||||
11197
materialsystem/vulkan/rtlinker_gen.cpp
Normal file
11197
materialsystem/vulkan/rtlinker_gen.cpp
Normal file
File diff suppressed because it is too large
Load Diff
5
materialsystem/vulkan/rtlinker_gen.h
Normal file
5
materialsystem/vulkan/rtlinker_gen.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "rtlinker_shared.h"
|
||||
|
||||
int SpvGetOperandCount( int op );
|
||||
void SpvGetOperands( int op, ESpirvOperandType *pTypes );
|
||||
void SpvGetOperandFlags( int op, ESpirvOperandFlags *pTypes );
|
||||
25
materialsystem/vulkan/rtlinker_shared.h
Normal file
25
materialsystem/vulkan/rtlinker_shared.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef RTLINKER_SHARED_H
|
||||
#define RTLINKER_SHARED_H
|
||||
|
||||
enum ESpirvOperandType
|
||||
{
|
||||
k_ESpirv_Unknown = 0,
|
||||
k_ESpirv_ResultId,
|
||||
k_ESpirv_ResultTypeId,
|
||||
k_ESpirv_RefId,
|
||||
k_ESpirv_MemorySemanticsId,
|
||||
k_ESpirv_ScopeId,
|
||||
|
||||
k_ESpirv_LiteralBool,
|
||||
k_ESpirv_LiteralInt,
|
||||
k_ESpirv_LiteralFloat,
|
||||
};
|
||||
|
||||
enum ESpirvOperandFlags
|
||||
{
|
||||
k_ESpirvOperandFlags_None,
|
||||
k_ESpirvOperandFlags_Optional,
|
||||
k_ESpirvOperandFlags_Array,
|
||||
};
|
||||
|
||||
#endif
|
||||
68
materialsystem/vulkan/rtshader.cpp
Normal file
68
materialsystem/vulkan/rtshader.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "vulkan_state.h"
|
||||
#include "rtlinker.h"
|
||||
#include "materialsystem/compiledshadermgr.h"
|
||||
|
||||
uint32_t CVkRayTracingShader::GetMissShaderBinding( const char *szName )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
uint32_t CVkRayTracingShader::GetClosestHitShaderBinding( const char *szName )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
uint32_t CVkRayTracingShader::GetCallableShaderBinding( const char *szName )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CVkRayTracingShader::AddShader( const char *szName, const char *szPath )
|
||||
{
|
||||
ICompiledShaderManager *pCompiledShaderManager = (ICompiledShaderManager*)CreateInterface(COMPILED_SHADER_MANAGER_INTERFACE_VERSION, NULL);
|
||||
CCompiledShader shader = {};
|
||||
pCompiledShaderManager->ReadFromFile(&shader, szPath);
|
||||
m_callableShaders.AppendTail( {szName, shader} );
|
||||
}
|
||||
|
||||
void CVkRayTracingShader::RemoveShader( const char *szName )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CVkRayTracingShader::Build()
|
||||
{
|
||||
if (g_vkAvailableExtensions.bIsSupported_VK_KHR_RAY_TRACING_PIPELINE)
|
||||
BuildTrace();
|
||||
else
|
||||
BuildCompute();
|
||||
|
||||
}
|
||||
|
||||
void CVkRayTracingShader::BuildCompute()
|
||||
{
|
||||
CVkShaderLinker linker = {};
|
||||
ShaderObject_t *pShader;
|
||||
|
||||
pShader = m_shader.FindShaderObject(SHADER_BACKEND_SPIRV_VULKAN, SHADER_STAGE_RAYGEN_SOFTWARE);
|
||||
if (!pShader)
|
||||
return;
|
||||
|
||||
linker.SetMainSpirv(m_shader.GetLumpSize(pShader->m_nDataLump)/4,
|
||||
(uint32_t*)m_shader.GetLumpPtr(pShader->m_nDataLump));
|
||||
for ( auto s: m_callableShaders )
|
||||
{
|
||||
pShader = s.m_shader.FindShaderObject(SHADER_BACKEND_SPIRV_VULKAN, SHADER_STAGE_CALLABLE_SOFTWARE);
|
||||
if (!pShader)
|
||||
continue;
|
||||
linker.AddSpirv(s.m_shader.GetLumpSize(pShader->m_nDataLump)/4,
|
||||
(uint32_t*)s.m_shader.GetLumpPtr(pShader->m_nDataLump));
|
||||
}
|
||||
linker.Build();
|
||||
|
||||
}
|
||||
|
||||
void CVkRayTracingShader::BuildTrace()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "vk_mem_alloc.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier2/iappsystem.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "materialsystem/shaderinternals.h"
|
||||
@@ -285,7 +286,57 @@ private:
|
||||
EMultisampleType m_eMultiSampling;
|
||||
VkFormat m_eDepthFormat;
|
||||
bool m_bIsFragmentEnabled;
|
||||
};
|
||||
|
||||
class CVkComputeShader : public IComputeShader
|
||||
{
|
||||
public:
|
||||
virtual void Build() override;
|
||||
void BuildCompute();
|
||||
void BuildTrace();
|
||||
|
||||
VkDevice m_hDevice;
|
||||
CCompiledShader m_shader;
|
||||
|
||||
VkPipeline m_hPipeline = NULL;
|
||||
VkPipelineLayout m_hPipelineLayout;
|
||||
CUtlVector<VkDescriptorSetLayout> m_setLayouts;
|
||||
CUtlVector<VulkanDescriptor_t> m_bindings;
|
||||
private:
|
||||
struct ShaderBinding_t
|
||||
{
|
||||
CUtlString m_szName;
|
||||
CCompiledShader m_shader;
|
||||
};
|
||||
CUtlVector<ShaderBinding_t> m_callableShaders = {};
|
||||
};
|
||||
|
||||
class CVkRayTracingShader : public IRayTracingShader
|
||||
{
|
||||
public:
|
||||
virtual uint32_t GetMissShaderBinding( const char *szName ) override;
|
||||
virtual uint32_t GetClosestHitShaderBinding( const char *szName ) override;
|
||||
virtual uint32_t GetCallableShaderBinding( const char *szName ) override;
|
||||
virtual void AddShader( const char *szName, const char *szPath ) override;
|
||||
virtual void RemoveShader( const char *szName ) override;
|
||||
virtual void Build() override;
|
||||
void BuildCompute();
|
||||
void BuildTrace();
|
||||
|
||||
VkDevice m_hDevice;
|
||||
CCompiledShader m_shader;
|
||||
|
||||
VkPipeline m_hPipeline = NULL;
|
||||
VkPipelineLayout m_hPipelineLayout;
|
||||
CUtlVector<VkDescriptorSetLayout> m_setLayouts;
|
||||
CUtlVector<VulkanDescriptor_t> m_bindings;
|
||||
private:
|
||||
struct ShaderBinding_t
|
||||
{
|
||||
CUtlString m_szName;
|
||||
CCompiledShader m_shader;
|
||||
};
|
||||
CUtlVector<ShaderBinding_t> m_callableShaders = {};
|
||||
};
|
||||
|
||||
class CVkTextureArray: public ITextureArray
|
||||
|
||||
507
minispv/minispv.h
Normal file
507
minispv/minispv.h
Normal file
@@ -0,0 +1,507 @@
|
||||
#ifndef MINI_SPIRV_H
|
||||
#define MINI_SPIRV_H
|
||||
#include "stdlib.h"
|
||||
#include "stdint.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "unistd.h"
|
||||
#define SPV_ENABLE_UTILITY_CODE
|
||||
#include "spirv/unified1/spirv.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* arrays */
|
||||
|
||||
static inline uint32_t _mspvalign2( uint32_t x )
|
||||
{
|
||||
if (x <= 1) return 1;
|
||||
x--;
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
x |= x >> 8;
|
||||
x |= x >> 16;
|
||||
x++;
|
||||
return x;
|
||||
}
|
||||
|
||||
#define mspv_array(T) \
|
||||
struct \
|
||||
{ \
|
||||
size_t count; \
|
||||
size_t capacity; \
|
||||
T *data; \
|
||||
}
|
||||
|
||||
#define mspv_array_zero(array) \
|
||||
array.count = 0; \
|
||||
array.capacity = 0; \
|
||||
array.data = NULL;
|
||||
|
||||
#define mspv_array_create(array, count) \
|
||||
array.count = count; \
|
||||
array.capacity = _mspvalign2(count); \
|
||||
array.data = malloc(array.capacity * sizeof(*array.data));
|
||||
|
||||
#define mspv_array_push(array, value) \
|
||||
do { \
|
||||
if (array.count >= array.capacity) { \
|
||||
if (array.capacity == 0) array.capacity = 4; \
|
||||
else array.capacity *= 2; \
|
||||
array.data = (typeof(array.data))realloc(array.data, array.capacity * sizeof(*array.data)); \
|
||||
} \
|
||||
array.data[array.count++] = value;\
|
||||
} while(0) \
|
||||
|
||||
#define mspv_array_destroy(array) \
|
||||
if (array.data) free(array.data); \
|
||||
mspv_array_zero(array)
|
||||
|
||||
/* strings views for simplicity */
|
||||
typedef struct
|
||||
{
|
||||
const char *data;
|
||||
size_t len;
|
||||
} mspv_string_view;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t *data;
|
||||
size_t len;
|
||||
} mspv_data_view;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t id;
|
||||
mspv_string_view name;
|
||||
} mspv_ext_import;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SpvExecutionModel model;
|
||||
uint32_t id;
|
||||
mspv_string_view name;
|
||||
mspv_array(uint32_t) params;
|
||||
} mspv_entry_point;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t id;
|
||||
SpvExecutionMode mode;
|
||||
mspv_data_view dv;
|
||||
} mspv_execution_mode;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t resulttype;
|
||||
uint32_t result;
|
||||
uint32_t functionctrl;
|
||||
uint32_t functiontype;
|
||||
mspv_data_view instructions;
|
||||
} mspv_function;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t magic;
|
||||
uint32_t reserved1;
|
||||
uint32_t reserved2;
|
||||
uint32_t reserved3;
|
||||
uint32_t reserved4;
|
||||
} mspv_header;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t id;
|
||||
mspv_data_view dv;
|
||||
} mspv_type;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t resulttype;
|
||||
uint32_t result;
|
||||
uint32_t storageclass;
|
||||
uint32_t initializer;
|
||||
} mspv_variable;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t id;
|
||||
mspv_string_view name;
|
||||
} mspv_name;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
mspv_header header;
|
||||
SpvMemoryModel memory_model;
|
||||
SpvAddressingModel addressing_model;
|
||||
mspv_array(SpvCapability) capabilities;
|
||||
mspv_array(mspv_string_view) extensions;
|
||||
mspv_array(mspv_ext_import) ext_instructions;
|
||||
mspv_array(mspv_string_view) instruction_imports;
|
||||
mspv_array(mspv_entry_point) entry_points;
|
||||
mspv_array(mspv_execution_mode) execution_modes;
|
||||
mspv_array(mspv_name) names;
|
||||
mspv_array(mspv_type) types;
|
||||
mspv_array(mspv_variable) variables;
|
||||
mspv_array(mspv_function) functions;
|
||||
|
||||
uint32_t *data;
|
||||
uint32_t count;
|
||||
} mspv_module;
|
||||
|
||||
|
||||
mspv_module *mspv_read_module( uint32_t count, uint32_t *data );
|
||||
void mspv_close_module( mspv_module* module );
|
||||
|
||||
#define mspv_todo(str) printf("todo!!! " str "\n"); _exit(0)
|
||||
|
||||
#define mspv_sv_fmt "%.*s"
|
||||
#define mspv_psv(sv) sv.len, sv.data
|
||||
|
||||
//#ifdef MINI_SPIRV_IMPLEMENTATION
|
||||
static inline mspv_string_view mspv_sv_from_op( uint32_t *op )
|
||||
{
|
||||
return { (char*)op, strlen((char*)op)};
|
||||
|
||||
};
|
||||
|
||||
mspv_module *mspv_read_module( uint32_t count, uint32_t *data )
|
||||
{
|
||||
mspv_module m;
|
||||
mspv_header *h;
|
||||
int i;
|
||||
uint32_t u;
|
||||
SpvOp op;
|
||||
uint16_t instruction_size;
|
||||
uint16_t local_offset;
|
||||
mspv_string_view sv;
|
||||
mspv_data_view dv;
|
||||
mspv_entry_point ep;
|
||||
mspv_ext_import imp;
|
||||
mspv_execution_mode em;
|
||||
mspv_type type;
|
||||
mspv_variable var;
|
||||
mspv_function fn;
|
||||
mspv_name nm;
|
||||
int isfn;
|
||||
|
||||
if ( count == 0 || data == NULL)
|
||||
return 0;
|
||||
|
||||
m = {};
|
||||
m.data = data;
|
||||
m.count = count;
|
||||
|
||||
h = (mspv_header*)data;
|
||||
if ( h->magic != SpvMagicNumber )
|
||||
return 0;
|
||||
m.header = *h;
|
||||
|
||||
/* loop instrucitons */
|
||||
isfn = 0;
|
||||
|
||||
for ( u = 5; u < count; )
|
||||
{
|
||||
instruction_size = data[u] >> 16;
|
||||
op = (SpvOp)(data[u] & 0xFFFF);
|
||||
switch (op)
|
||||
{
|
||||
case SpvOpCapability:
|
||||
mspv_array_push(m.capabilities, (SpvCapability)data[u+1]);
|
||||
break;
|
||||
case SpvOpExtension:
|
||||
sv.len = strlen((char*)(data + u + 1));
|
||||
sv.data = (char*)&data[u+1];
|
||||
mspv_array_push(m.extensions, sv);
|
||||
break;
|
||||
case SpvOpExtInstImport:
|
||||
imp.id = data[u+1];
|
||||
imp.name.len = strlen((char*)(data + u + 2));
|
||||
imp.name.data = (char*)&data[u+2];
|
||||
mspv_array_push(m.ext_instructions, imp);
|
||||
break;
|
||||
case SpvOpMemoryModel:
|
||||
m.addressing_model = (SpvAddressingModel)data[u+1];
|
||||
m.memory_model = (SpvMemoryModel)data[u+2];
|
||||
break;
|
||||
case SpvOpEntryPoint:
|
||||
ep.model = (SpvExecutionModel)data[u+1];
|
||||
ep.id = (SpvExecutionModel)data[u+2];
|
||||
ep.name = mspv_sv_from_op(data+u+3);
|
||||
ep.params = {};
|
||||
for ( i = 4 + ep.name.len/4; i < instruction_size; i++ )
|
||||
{
|
||||
mspv_array_push(ep.params, data[u+i]);
|
||||
}
|
||||
mspv_array_push(m.entry_points, ep);
|
||||
break;
|
||||
case SpvOpExecutionMode:
|
||||
em.id = data[u+1];
|
||||
em.mode = (SpvExecutionMode)data[u+2];
|
||||
em.dv.data = data + u;
|
||||
em.dv.len = instruction_size - 1;
|
||||
mspv_array_push(m.execution_modes, em);
|
||||
break;
|
||||
case SpvOpString:
|
||||
case SpvOpSourceExtension:
|
||||
case SpvOpSource:
|
||||
case SpvOpSourceContinued:
|
||||
case SpvOpMemberName:
|
||||
case SpvOpModuleProcessed:
|
||||
break;
|
||||
case SpvOpName:
|
||||
nm.id = data[u+1];
|
||||
nm.name = mspv_sv_from_op(data+u+2);
|
||||
mspv_array_push(m.names, nm);
|
||||
|
||||
break;
|
||||
|
||||
case SpvOpTypeVoid:
|
||||
case SpvOpTypeBool:
|
||||
case SpvOpTypeInt:
|
||||
case SpvOpTypeFloat:
|
||||
case SpvOpTypeVector:
|
||||
case SpvOpTypeMatrix:
|
||||
case SpvOpTypeImage:
|
||||
case SpvOpTypeSampler:
|
||||
case SpvOpTypeSampledImage:
|
||||
case SpvOpTypeArray:
|
||||
case SpvOpTypeRuntimeArray:
|
||||
case SpvOpTypeStruct:
|
||||
case SpvOpTypeOpaque:
|
||||
case SpvOpTypePointer:
|
||||
case SpvOpTypeFunction:
|
||||
case SpvOpTypeEvent:
|
||||
case SpvOpTypeDeviceEvent:
|
||||
case SpvOpTypeReserveId:
|
||||
case SpvOpTypeQueue:
|
||||
case SpvOpTypePipe:
|
||||
case SpvOpTypeForwardPointer:
|
||||
type.dv.data = data+u;
|
||||
type.dv.len = instruction_size;
|
||||
type.id = data[u+1];
|
||||
mspv_array_push(m.types, type);
|
||||
break;
|
||||
|
||||
case SpvOpVariable:
|
||||
var.resulttype = data[u+1];
|
||||
var.result = data[u+2];
|
||||
var.storageclass = data[u+3];
|
||||
if (instruction_size > 4)
|
||||
var.initializer = data[u+4];
|
||||
else
|
||||
var.initializer = 0;
|
||||
if (!isfn)
|
||||
mspv_array_push(m.variables, var);
|
||||
else
|
||||
fn.instructions.len += instruction_size;
|
||||
break;
|
||||
|
||||
|
||||
case SpvOpFunction:
|
||||
fn = {};
|
||||
fn.resulttype = data[u+1];
|
||||
fn.result = data[u+2];
|
||||
fn.functionctrl = data[u+3];
|
||||
fn.functiontype = data[u+4];
|
||||
fn.instructions.data = data+u+instruction_size;
|
||||
fn.instructions.len = 0;
|
||||
isfn = 1;
|
||||
break;
|
||||
case SpvOpFunctionEnd:
|
||||
mspv_array_push(m.functions, fn);
|
||||
isfn = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
fn.instructions.len += instruction_size;
|
||||
break;
|
||||
}
|
||||
u += instruction_size;
|
||||
|
||||
};
|
||||
return (mspv_module*)memcpy(malloc(sizeof(m)),&m, sizeof(m));
|
||||
}
|
||||
|
||||
void mspv_close_module( mspv_module* m )
|
||||
{
|
||||
if (m == NULL)
|
||||
return;
|
||||
|
||||
mspv_array_destroy(m->capabilities);
|
||||
mspv_array_destroy(m->extensions);
|
||||
mspv_array_destroy(m->execution_modes);
|
||||
mspv_array_destroy(m->entry_points);
|
||||
mspv_array_destroy(m->types);
|
||||
mspv_array_destroy(m->functions);
|
||||
free(m);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SpvOp op;
|
||||
uint16_t size;
|
||||
} mspv_op;
|
||||
|
||||
|
||||
typedef mspv_array(uint32_t) mspv_spv;
|
||||
static inline void mspv_write_op( mspv_spv *as, SpvOp op, uint16_t ops )
|
||||
{
|
||||
mspv_array_push((*as), op | (ops+1) << 16);
|
||||
};
|
||||
|
||||
static inline void mspv_write_string( mspv_spv *as, mspv_string_view s )
|
||||
{
|
||||
uint32_t u;
|
||||
uint32_t val;
|
||||
char cval[4];
|
||||
for ( u = 0; u < s.len/4; u++ )
|
||||
{
|
||||
mspv_array_push((*as), *(uint32_t*)(s.data+u*4));
|
||||
}
|
||||
if (!(s.len%4))
|
||||
{
|
||||
mspv_array_push((*as), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
cval[0] = 0;
|
||||
cval[0] = 1;
|
||||
cval[0] = 2;
|
||||
cval[0] = 3;
|
||||
|
||||
for (u = 0; u < s.len%4; u++)
|
||||
{
|
||||
cval[u] = s.data[(s.len/4)*4+u];
|
||||
}
|
||||
mspv_array_push((*as), *(uint32_t*)cval);
|
||||
}
|
||||
};
|
||||
|
||||
static inline void mspv_write_dv( mspv_spv *as, mspv_data_view s )
|
||||
{
|
||||
uint32_t u;
|
||||
for ( u = 0; u < s.len; u++ )
|
||||
{
|
||||
mspv_array_push((*as), *(s.data+u));
|
||||
}
|
||||
}
|
||||
|
||||
mspv_spv mspv_write_module( mspv_module *m )
|
||||
{
|
||||
mspv_spv as;
|
||||
uint32_t u;
|
||||
uint32_t n;
|
||||
uint32_t il;
|
||||
|
||||
mspv_array_zero(as);
|
||||
|
||||
if (m == NULL)
|
||||
return as;
|
||||
|
||||
mspv_array_push(as, m->header.magic);
|
||||
mspv_array_push(as, m->header.reserved1);
|
||||
mspv_array_push(as, m->header.reserved2);
|
||||
mspv_array_push(as, m->header.reserved3);
|
||||
mspv_array_push(as, m->header.reserved4);
|
||||
|
||||
for ( u = 0; u < m->capabilities.count; u++ )
|
||||
{
|
||||
mspv_write_op(&as, SpvOpCapability, 1);
|
||||
mspv_array_push(as, m->capabilities.data[u]);
|
||||
}
|
||||
for ( u = 0; u < m->extensions.count; u++ )
|
||||
{
|
||||
il = 0;
|
||||
if (m->extensions.data[u].len%4)
|
||||
il = m->extensions.data[u].len/4+1;
|
||||
else
|
||||
il = m->extensions.data[u].len/4+2;
|
||||
mspv_write_op(&as, SpvOpExtension, il);
|
||||
mspv_write_string(&as, m->extensions.data[u]);
|
||||
}
|
||||
|
||||
for ( u = 0; u < m->ext_instructions.count; u++ )
|
||||
{
|
||||
|
||||
il = 0;
|
||||
if (m->ext_instructions.data[u].name.len%4)
|
||||
il = m->ext_instructions.data[u].name.len/4+2;
|
||||
else
|
||||
il = m->ext_instructions.data[u].name.len/4+3;
|
||||
mspv_write_op(&as, SpvOpExtInstImport, il);
|
||||
mspv_array_push(as, m->ext_instructions.data[u].id);
|
||||
mspv_write_string(&as, m->ext_instructions.data[u].name);
|
||||
}
|
||||
for ( u = 0; u < m->entry_points.count; u++ )
|
||||
{
|
||||
il = 0;
|
||||
if (m->entry_points.data[u].name.len%4)
|
||||
il = m->entry_points.data[u].name.len/4+2;
|
||||
else
|
||||
il = m->entry_points.data[u].name.len/4+3;
|
||||
il += m->entry_points.data[u].params.count;
|
||||
mspv_write_op(&as, SpvOpEntryPoint, il);
|
||||
mspv_array_push(as, m->entry_points.data[u].model);
|
||||
mspv_array_push(as, m->entry_points.data[u].id);
|
||||
mspv_write_string(&as, m->entry_points.data[u].name);
|
||||
for ( n = 0; n < m->entry_points.data[u].params.count; n++ )
|
||||
{
|
||||
mspv_array_push(as, m->entry_points.data[u].params.data[n]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
mspv_write_op(&as, SpvOpMemoryModel, 2);
|
||||
mspv_array_push(as, m->addressing_model);
|
||||
mspv_array_push(as, m->memory_model);
|
||||
|
||||
for ( u = 0; u < m->types.count; u++ )
|
||||
{
|
||||
mspv_write_op(&as, (SpvOp)m->types.data[u].dv.data[0], m->types.data[u].dv.len-1);
|
||||
mspv_array_push(as, m->types.data[u].id);
|
||||
if (m->types.data[u].dv.len-2)
|
||||
mspv_write_dv(&as, {m->types.data[u].dv.data+2, m->types.data[u].dv.len-2});
|
||||
}
|
||||
for ( u = 0; u < m->variables.count; u++ )
|
||||
{
|
||||
mspv_write_op(&as, SpvOpVariable, m->variables.data[u].initializer ? 4 : 3);
|
||||
mspv_array_push(as, m->variables.data[u].resulttype);
|
||||
mspv_array_push(as, m->variables.data[u].result);
|
||||
mspv_array_push(as, m->variables.data[u].storageclass);
|
||||
if (m->variables.data[u].initializer)
|
||||
{
|
||||
mspv_array_push(as, m->variables.data[u].initializer);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for ( u = 0; u < m->functions.count; u++ )
|
||||
{
|
||||
mspv_write_op(&as, SpvOpFunction, 4);
|
||||
mspv_array_push(as, m->functions.data[u].resulttype);
|
||||
mspv_array_push(as, m->functions.data[u].result);
|
||||
mspv_array_push(as, m->functions.data[u].functionctrl);
|
||||
mspv_array_push(as, m->functions.data[u].functiontype);
|
||||
|
||||
mspv_write_dv(&as, m->functions.data[u].instructions);
|
||||
|
||||
mspv_write_op(&as, SpvOpFunctionEnd, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return as;
|
||||
|
||||
}
|
||||
|
||||
//#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -40,6 +40,8 @@ struct CastResult_t
|
||||
float m_fTime;
|
||||
// 0 to lenght
|
||||
float m_fDistance;
|
||||
|
||||
Vector m_vNormal;
|
||||
};
|
||||
|
||||
enum EPhysicsBodyType
|
||||
@@ -65,6 +67,8 @@ public:
|
||||
virtual void SetGravityScale( float fScale ) = 0;
|
||||
};
|
||||
|
||||
typedef bool (*fnCheckCast)( HCollider hCollider );
|
||||
|
||||
abstract_class IPhysicsWorld
|
||||
{
|
||||
public:
|
||||
@@ -75,8 +79,8 @@ public:
|
||||
|
||||
virtual void SetGravity( float fGravity ) = 0;
|
||||
|
||||
virtual CastResult_t RayCast( Vector vBegin, Vector vEnd ) = 0;
|
||||
virtual CastResult_t ShapeCast( HShape hShape, Quat vOrientation, Vector vBegin, Vector vEnd ) = 0;
|
||||
virtual CastResult_t RayCast( Vector vBegin, Vector vEnd, fnCheckCast check ) = 0;
|
||||
virtual CastResult_t ShapeCast( HShape hShape, Quat vOrientation, Vector vBegin, Vector vEnd, fnCheckCast check ) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -200,6 +200,7 @@ public:
|
||||
abstract_class IBaseShader
|
||||
{
|
||||
public:
|
||||
virtual ~IBaseShader() = default;
|
||||
virtual void Build() = 0;
|
||||
};
|
||||
|
||||
@@ -219,17 +220,19 @@ public:
|
||||
virtual void DisablePixelShader( bool bDisable) = 0;
|
||||
};
|
||||
|
||||
abstract_class IComputeShader
|
||||
abstract_class IComputeShader: public IBaseShader
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
abstract_class IRayTracingShader
|
||||
abstract_class IRayTracingShader: public IBaseShader
|
||||
{
|
||||
public:
|
||||
virtual uint32_t GetMissShaderBinding( const char *szName );
|
||||
virtual uint32_t GetClosestHitShaderBinding( const char *szName );
|
||||
virtual uint32_t GetCallableShaderBinding( const char *szName );
|
||||
virtual uint32_t GetMissShaderBinding( const char *szName ) = 0;
|
||||
virtual uint32_t GetClosestHitShaderBinding( const char *szName ) = 0;
|
||||
virtual uint32_t GetCallableShaderBinding( const char *szName ) = 0;
|
||||
virtual void AddShader( const char *szName, const char *szPath ) = 0;
|
||||
virtual void RemoveShader( const char *szName ) = 0;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -299,7 +302,9 @@ public:
|
||||
virtual void DestroyImage( IImage *pImage ) = 0;
|
||||
|
||||
virtual IShader *CreateShader( const char *szName ) = 0;
|
||||
virtual void DestroyShader( IShader *pMaterial ) = 0;
|
||||
virtual IRayTracingShader *CreateRayShader( const char *szName ) = 0;
|
||||
virtual IComputeShader *CreateComputeShader( const char *szName ) = 0;
|
||||
virtual void DestroyShader( IBaseShader *pMaterial ) = 0;
|
||||
|
||||
virtual IMaterial *CreateMaterial( IShader *pShader ) = 0;
|
||||
virtual void DestroyMaterial( IMaterial *pMaterial ) = 0;
|
||||
|
||||
@@ -52,6 +52,12 @@ public:
|
||||
RapierPhysicsBody_t *m_pBody = NULL;
|
||||
|
||||
};
|
||||
|
||||
struct Option_checkCastFn
|
||||
{
|
||||
fnCheckCast c;
|
||||
};
|
||||
|
||||
class CRapierPhysicsWorld: public IPhysicsWorld
|
||||
{
|
||||
public:
|
||||
@@ -80,14 +86,14 @@ public:
|
||||
|
||||
}
|
||||
|
||||
virtual CastResult_t RayCast( Vector vBegin, Vector vEnd ) override
|
||||
virtual CastResult_t RayCast( Vector vBegin, Vector vEnd, fnCheckCast check ) override
|
||||
{
|
||||
return CRapierPhysicsWorld_RayCast(m_pWorld, vBegin, vEnd);
|
||||
return CRapierPhysicsWorld_RayCast(m_pWorld, vBegin, vEnd, (Option_checkCastFn){check} );
|
||||
}
|
||||
|
||||
virtual CastResult_t ShapeCast( HShape hShape, Quat vOrientation, Vector vBegin, Vector vEnd ) override
|
||||
virtual CastResult_t ShapeCast( HShape hShape, Quat vOrientation, Vector vBegin, Vector vEnd, fnCheckCast check ) override
|
||||
{
|
||||
return CRapierPhysicsWorld_ShapeCast(m_pWorld, (RapierShape_t*)hShape, vOrientation, vBegin, vEnd );
|
||||
return CRapierPhysicsWorld_ShapeCast(m_pWorld, (RapierShape_t*)hShape, vOrientation, vBegin, vEnd, (Option_checkCastFn){check} );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ typedef enum EPhysicsBodyType {
|
||||
k_EPhysics_KinematicVelocityBased,
|
||||
} EPhysicsBodyType;
|
||||
|
||||
typedef struct Option_checkCastFn Option_checkCastFn;
|
||||
|
||||
typedef struct RapierCollider_t RapierCollider_t;
|
||||
|
||||
typedef struct RapierPhysicsBody_t RapierPhysicsBody_t;
|
||||
@@ -39,6 +41,7 @@ typedef struct CastResult_t {
|
||||
struct Vector m_vCollisionPoint;
|
||||
float m_fTime;
|
||||
float m_fDistance;
|
||||
struct Vector m_vNormal;
|
||||
} CastResult_t;
|
||||
|
||||
typedef struct BallShape_t {
|
||||
@@ -87,13 +90,15 @@ void CRapierPhysicsWorld_Frame(struct RapierWorld_t *this_, float fDelta);
|
||||
|
||||
struct CastResult_t CRapierPhysicsWorld_RayCast(struct RapierWorld_t *this_,
|
||||
struct Vector vBegin,
|
||||
struct Vector vEnd);
|
||||
struct Vector vEnd,
|
||||
struct Option_checkCastFn checkCast);
|
||||
|
||||
struct CastResult_t CRapierPhysicsWorld_ShapeCast(struct RapierWorld_t *this_,
|
||||
struct RapierShape_t *pShape,
|
||||
struct Quat vOrientation,
|
||||
struct Vector vBegin,
|
||||
struct Vector vEnd);
|
||||
struct Vector vEnd,
|
||||
struct Option_checkCastFn checkCast);
|
||||
|
||||
struct RapierShape_t *CRapierPhysics_CreateBall(struct RapierPhysics_t *this_,
|
||||
struct BallShape_t ball);
|
||||
@@ -109,6 +114,8 @@ struct RapierShape_t *CRapierPhysics_CreateTriangleMesh(struct RapierPhysics_t *
|
||||
|
||||
struct RapierWorld_t *CRapierPhysics_CreateWorld(struct RapierPhysics_t *this_);
|
||||
|
||||
void CRapierPhysics_DestroyShape(struct RapierPhysics_t *this_, struct RapierShape_t *shape);
|
||||
|
||||
struct RapierPhysics_t *CRapierPhysics_New(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -20,6 +20,8 @@ use parry3d::{glamx::{Pose3A}, query::ShapeCastOptions};
|
||||
use rapier3d::{geometry::Ball, na::{UnitQuaternion, Vector4, coordinates::XYZ}};
|
||||
use rapier3d::prelude::*;
|
||||
use libc::{malloc, free};
|
||||
use std::ffi::c_void;
|
||||
use std::sync::Mutex;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Default, Debug)]
|
||||
@@ -95,6 +97,7 @@ pub struct CastResult_t
|
||||
m_vCollisionPoint: Vector,
|
||||
m_fTime: f32,
|
||||
m_fDistance: f32,
|
||||
m_vNormal: Vector,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -242,8 +245,12 @@ pub unsafe extern "C" fn CRapierPhysicsWorld_CreateRigidBody(
|
||||
pBody
|
||||
}
|
||||
|
||||
type checkCastFn = extern "C" fn( pCollider: *mut RapierCollider_t ) -> bool;
|
||||
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn CRapierPhysicsWorld_RayCast( this: *mut RapierWorld_t, vBegin: Vector, vEnd: Vector ) -> CastResult_t
|
||||
pub unsafe extern "C" fn CRapierPhysicsWorld_RayCast( this: *mut RapierWorld_t, vBegin: Vector, vEnd: Vector, checkCast: Option<checkCastFn> ) -> CastResult_t
|
||||
{
|
||||
let mut cast = CastResult_t::default();
|
||||
let vDir = Vector{ x: vEnd.x-vBegin.x, y:vEnd.y-vBegin.y, z:vEnd.z-vBegin.z};
|
||||
@@ -252,11 +259,22 @@ pub unsafe extern "C" fn CRapierPhysicsWorld_RayCast( this: *mut RapierWorld_t,
|
||||
let ray = Ray::new(
|
||||
Vec3 { x: vBegin.x, y: vBegin.y, z: vBegin.z },
|
||||
Vec3 { x: vNormalizedDir.x, y: vNormalizedDir.y, z: vNormalizedDir.z });
|
||||
|
||||
let mut filter = QueryFilter::default();
|
||||
|
||||
let predicate = |handle: ColliderHandle, collider: &Collider| -> bool {
|
||||
checkCast.unwrap()(collider.user_data as *mut RapierCollider_t)
|
||||
};
|
||||
if let Some(f) = checkCast
|
||||
{
|
||||
filter.predicate = Option::Some(&predicate);
|
||||
}
|
||||
|
||||
let queryPipeline = (*this).m_broadPhase.as_query_pipeline(
|
||||
(*this).m_narrowPhase.query_dispatcher(),
|
||||
&(*this).m_rigidBodies,
|
||||
&(*this).m_colliders,
|
||||
QueryFilter::default(),
|
||||
filter,
|
||||
);
|
||||
if let Some((handle, intersection)) = queryPipeline.cast_ray_and_get_normal(&ray, fMaxDistance, true)
|
||||
{
|
||||
@@ -268,25 +286,43 @@ pub unsafe extern "C" fn CRapierPhysicsWorld_RayCast( this: *mut RapierWorld_t,
|
||||
y: vBegin.y + vNormalizedDir.y * intersection.time_of_impact,
|
||||
z: vBegin.z + vNormalizedDir.z * intersection.time_of_impact,
|
||||
};
|
||||
cast.m_vNormal = Vector{
|
||||
x: intersection.normal.x,
|
||||
y: intersection.normal.y,
|
||||
z: intersection.normal.y,
|
||||
}
|
||||
|
||||
}
|
||||
cast
|
||||
}
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn CRapierPhysicsWorld_ShapeCast( this: *mut RapierWorld_t, pShape: *mut RapierShape_t, vOrientation: Quat, vBegin: Vector, vEnd: Vector ) -> CastResult_t
|
||||
pub unsafe extern "C" fn CRapierPhysicsWorld_ShapeCast( this: *mut RapierWorld_t, pShape: *mut RapierShape_t, vOrientation: Quat, vBegin: Vector, vEnd: Vector, checkCast: Option<checkCastFn> ) -> CastResult_t
|
||||
{
|
||||
let mut cast = CastResult_t::default();
|
||||
let vDir = Vector{ x: vEnd.x-vBegin.x, y:vEnd.y-vBegin.y, z:vEnd.z-vBegin.z};
|
||||
let fMaxDistance = f32::sqrt(vDir.x*vDir.x+vDir.y*vDir.y+vDir.z*vDir.z);
|
||||
let vNormalizedDir = Vector{ x: vDir.x/fMaxDistance, y:vDir.y/fMaxDistance, z:vDir.z/fMaxDistance};
|
||||
|
||||
let mut filter = QueryFilter::default();
|
||||
|
||||
let predicate = |handle: ColliderHandle, collider: &Collider| -> bool {
|
||||
checkCast.unwrap()(collider.user_data as *mut RapierCollider_t)
|
||||
};
|
||||
if let Some(f) = checkCast
|
||||
{
|
||||
filter.predicate = Option::Some(&predicate);
|
||||
}
|
||||
|
||||
let queryPipeline = (*this).m_broadPhase.as_query_pipeline(
|
||||
(*this).m_narrowPhase.query_dispatcher(),
|
||||
&(*this).m_rigidBodies,
|
||||
&(*this).m_colliders,
|
||||
QueryFilter::default(),
|
||||
filter,
|
||||
);
|
||||
let vRustDir = Vector{ x: vNormalizedDir.x, y: vNormalizedDir.y, z: vNormalizedDir.z };
|
||||
|
||||
let mut castOptions = ShapeCastOptions::default();
|
||||
castOptions.stop_at_penetration = true;
|
||||
castOptions.max_time_of_impact = fMaxDistance;
|
||||
@@ -315,6 +351,11 @@ pub unsafe extern "C" fn CRapierPhysicsWorld_ShapeCast( this: *mut RapierWorld_t
|
||||
y: vBegin.y + vNormalizedDir.y * intersection.time_of_impact,
|
||||
z: vBegin.z + vNormalizedDir.z * intersection.time_of_impact,
|
||||
};
|
||||
cast.m_vNormal = Vector{
|
||||
x: intersection.normal1.x,
|
||||
y: intersection.normal1.y,
|
||||
z: intersection.normal1.z,
|
||||
}
|
||||
|
||||
}
|
||||
cast
|
||||
@@ -394,6 +435,12 @@ pub unsafe extern "C" fn CRapierPhysics_CreateTriangleMesh( this: *mut RapierPhy
|
||||
}
|
||||
pShapeMemory
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn CRapierPhysics_DestroyShape( this: *mut RapierPhysics_t, shape: *mut RapierShape_t )
|
||||
{
|
||||
std::ptr::drop_in_place(&mut (*shape).m_sharedShape);
|
||||
free(shape as *mut c_void);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn CRapierPhysics_CreateCollider( this: *mut RapierPhysics_t, pShape: *mut RapierShape_t ) -> *mut RapierCollider_t
|
||||
@@ -401,6 +448,7 @@ pub unsafe extern "C" fn CRapierPhysics_CreateCollider( this: *mut RapierPhysics
|
||||
let shape: &SharedShape = &(*pShape).m_sharedShape;
|
||||
let pCollider = V_malloc!(RapierCollider_t, 1);
|
||||
std::ptr::write(&mut (*pCollider).m_collider, ColliderBuilder::new(shape.clone()).build());
|
||||
(*pCollider).m_collider.user_data = pCollider as u128;
|
||||
pCollider
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,9 @@ void CSlangVulkanSpirvShaderCompiler::CompileShaderStage( EShaderStage eStage, c
|
||||
case SHADER_STAGE_CALLABLE:
|
||||
eSlangStage = SLANG_STAGE_CALLABLE;
|
||||
break;
|
||||
case SHADER_STAGE_CALLABLE_SOFTWARE:
|
||||
eSlangStage = SLANG_STAGE_COMPUTE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -88,16 +91,16 @@ void CSlangVulkanSpirvShaderCompiler::CompileShaderStage( EShaderStage eStage, c
|
||||
VariableLayoutReflection *pVar = pProgramLayout->getParameterByIndex(u);
|
||||
input = {};
|
||||
input.uCount = 1;
|
||||
V_printf("%s %i\n", pVar->getName(), pVar->getType()->getKind());
|
||||
//V_printf("%s %i\n", pVar->getName(), pVar->getType()->getKind());
|
||||
TypeReflection *pType = pVar->getType();
|
||||
trygetkind:
|
||||
V_printf("%s %i\n", pType->getName(), pType->getKind());
|
||||
//V_printf("%s %i\n", pType->getName(), pType->getKind());
|
||||
switch(pType->getKind())
|
||||
{
|
||||
case slang::TypeReflection::Kind::ConstantBuffer:
|
||||
input.eDescriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
break;
|
||||
V_printf("%s: %i\n", pType->getName(), pType->getResourceShape());
|
||||
//V_printf("%s: %i\n", pType->getName(), pType->getResourceShape());
|
||||
switch(pType->getResourceShape())
|
||||
{
|
||||
case SLANG_TEXTURE_2D:
|
||||
@@ -111,7 +114,7 @@ trygetkind:
|
||||
}
|
||||
break;
|
||||
case slang::TypeReflection::Kind::Resource:
|
||||
V_printf("%s: %i\n", pType->getName(), pType->getResourceShape());
|
||||
//V_printf("%s: %i\n", pType->getName(), pType->getResourceShape());
|
||||
switch(pType->getResourceShape())
|
||||
{
|
||||
case SLANG_TEXTURE_2D:
|
||||
@@ -187,14 +190,10 @@ trygetkind:
|
||||
pShaderObject->m_nMetadataLump = pShader->AllocateLump(sizeof(VulkanInputMetaData_t));
|
||||
V_memcpy(pShader->GetLumpPtr(pShaderObject->m_nDataLump), pBinary->getBufferPointer(), pBinary->getBufferSize());
|
||||
V_memcpy(pShader->GetLumpPtr(pShaderObject->m_nMetadataLump), &stMetadata, sizeof(VulkanInputMetaData_t));
|
||||
if (eStage == SHADER_STAGE_CALLABLE)
|
||||
{
|
||||
IFileHandle *ph = filesystem->Open("a.txt", FILEMODE_WRITE);
|
||||
IFileHandle *ph = filesystem->Open(szMain, FILEMODE_WRITE);
|
||||
filesystem->Write(ph, pBinary->getBufferPointer(), pBinary->getBufferSize());
|
||||
filesystem->Close(ph);
|
||||
|
||||
}
|
||||
|
||||
pEntryPoint->release();
|
||||
}
|
||||
|
||||
@@ -246,10 +245,6 @@ void CSlangVulkanSpirvShaderCompiler::CompileShader( const char *szInput, CCompi
|
||||
szMainName = "psMain";
|
||||
stStageMacroDesc[0] = { "PS_SHADER", "Enabled" };
|
||||
break;
|
||||
case SHADER_STAGE_CALLABLE:
|
||||
szMainName = "brdfMain";
|
||||
stStageMacroDesc[0] = { "BRDF_SHADER", "Enabled" };
|
||||
break;
|
||||
case SHADER_STAGE_RAYGEN:
|
||||
szMainName = "rayMain";
|
||||
stStageMacroDesc[0] = { "RAY_SHADER", "Enabled" };
|
||||
@@ -260,6 +255,16 @@ void CSlangVulkanSpirvShaderCompiler::CompileShader( const char *szInput, CCompi
|
||||
stStageMacroDesc[1] = { "SOFTWARE_RAY_TRACING", "Enabled" };
|
||||
stSessionDesc.preprocessorMacroCount = 2;
|
||||
break;
|
||||
case SHADER_STAGE_CALLABLE:
|
||||
szMainName = "CallableMain";
|
||||
stStageMacroDesc[0] = { "CALLABLE_SHADER", "Enabled" };
|
||||
break;
|
||||
case SHADER_STAGE_CALLABLE_SOFTWARE:
|
||||
szMainName = "CallableMain";
|
||||
stStageMacroDesc[0] = { "CALLABLE_SHADER", "Enabled" };
|
||||
stStageMacroDesc[1] = { "SOFTWARE_RAY_TRACING", "Enabled" };
|
||||
stSessionDesc.preprocessorMacroCount = 2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -267,7 +272,7 @@ void CSlangVulkanSpirvShaderCompiler::CompileShader( const char *szInput, CCompi
|
||||
if ( szMainName == NULL )
|
||||
continue;
|
||||
pSession = NULL;
|
||||
V_printf("Cool\n");
|
||||
//V_printf("Cool\n");
|
||||
s_pGlobalSession->createSession(stSessionDesc, &pSession);
|
||||
|
||||
pModule = pSession->loadModuleFromSource("main", szInput, pShaderSourceBlob, &m_pDiagnostics);
|
||||
|
||||
Reference in New Issue
Block a user