Skip to content

Commit

Permalink
kram - hlslparser update
Browse files Browse the repository at this point in the history
Just more typeName cleanup
  • Loading branch information
alecazam committed Mar 16, 2023
1 parent 8aae5c6 commit 4c0da9d
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 122 deletions.
42 changes: 28 additions & 14 deletions hlslparser/outshaders/ShaderHLSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,44 @@

// no using, so do typedef
// this is ugly syntax
//typedef int16_t short;
typedef int16_t2 short2;
typedef int16_t3 short3;
typedef int16_t4 short4;

typedef uint16_t ushort;
typedef uint16_t2 ushort2;
typedef uint16_t3 ushort3;
typedef uint16_t4 ushort4;

// TODO: double, u/char
// TODO: add double, but won't work on mobile.
//typedef int64_t long;
typedef int64_t2 long2;
typedef int64_t3 long3;
typedef int64_t4 long4;

typedef uint64_t ulong;
typedef uint64_t2 ulong2;
typedef uint64_t3 ulong3;
typedef uint64_t4 ulong4;

//typedef float64_t double;
typedef float64_t2 double2;
typedef float64_t3 double3;
typedef float64_t4 double4;

typedef float64_t2x2 double2x2;
typedef float64_t3x3 double3x3;
typedef float64_t4x4 double4x4;


// Note: no u/char
// Note: add double, but won't work on mobile (Android/MSL).
// also Intel removed fp64 GPU support. Often runs 1/64th speed.
// But may be needed for ray-tracing large worlds. Metal doesn't have double.
//
//typedef int64_t2 long2;
//typedef int64_t3 long3;
//typedef int64_t4 long4;
//
//typedef uint64_t2 ulong2;
//typedef uint64_t3 ulong3;
//typedef uint64_t4 ulong4;
//
//typedef float64_t2 double2;
//typedef float64_t3 double3;
//typedef float64_t4 double4;

// TODO: add Atomics, more atomic u/long and float in SM 6.6
// otherwise it's most atomic_u/int that is portable.
// Apple Metal 3 added atomic_float.

// 6.6 is cutting edge, want to target 6.2 for now
#define SM66 1
Expand Down
11 changes: 0 additions & 11 deletions hlslparser/shaders/Sample.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@ struct LightState
float4x4 viewProj;
};

/*
cbuffer SceneConstantBuffer : register(b0)
{
float4x4 model;
float4x4 viewProj;
float4 ambientColor;
bool sampleShadowMap;
LightState lights[NUM_LIGHTS];
};
*/

struct SceneConstantBuffer
{
float4x4 model;
Expand Down
13 changes: 7 additions & 6 deletions hlslparser/shaders/Skinning.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,31 @@
//
// https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst

// setup specialization
// HLSL: at beginning
// setup variants
// HLSL: specialization constants marked at beginning
// [[vk::constant_id(0)]] const int specConstInt = 1;
// [[vk::constant_id(1)]] const bool specConstBool = true;
//
// MSL: at end
// MSL: function constants marked at end
// constant bool a [[function_constant(0)]];
// constant int a [[function_constant(1)]]; // 0.. 64K-1

// This is for tile shaders
// subpass input, and SubpassLoad() calls
// [[vk::input_attachment_index(i)]] SubpassInput input;
// class SubpassInput<T> { T SubpassLoad(); };
// class SubpassInputMS<T> { T SubpassLoad(int sampleIndex); };

// push constants
// push constants (DONE)
// [[vk::push_constant]]

// descriptors and arg buffers
// [[vk::binding(X[, Y])]] and [[vk::counter_binding(X)]]

// tagging the format of buffers/textures, since HLSL can't represent
// [[vk::image_format("rgba8")]]
// RWBuffer<float4> Buf;


//
// [[vk::image_format("rg16f")]]
// RWTexture2D<float2> Tex;

Expand Down
51 changes: 4 additions & 47 deletions hlslparser/src/HLSLGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,54 +19,11 @@ namespace M4
const char* HLSLGenerator::GetTypeName(const HLSLType& type)
{
HLSLBaseType baseType = type.baseType;

if (baseType == HLSLBaseType_UserDefined)
return type.typeName;

// TODO: these can all just use a table entry, have another slot for MSL
const char* name = GetNumericTypeName(baseType);
if (name)
return name;


// DONE: these can all just use a table entry, have another slot for MSL
// Functions can return void, especially with compute
if (baseType == HLSLBaseType_Void)
return "void";

// TODO: pull names from table, they should be same
if (IsSamplerType(baseType))
{
switch (baseType)
{
// samplers
case HLSLBaseType_SamplerState: return "SamplerState";

// can only pair this with depth texture to match Metal
case HLSLBaseType_SamplerComparisonState: return "SamplerComparisonState";
default: break;
}
}
else if (IsTextureType(baseType))
{
switch (baseType)
{
// depth textures just use Texture2D typedef
// TODO: add ms, others
case HLSLBaseType_Texture2D: return "Texture2D";
case HLSLBaseType_Texture2DArray: return "Texture2DArray";
case HLSLBaseType_Texture3D: return "Texture3D";
case HLSLBaseType_TextureCube: return "TextureCube";
case HLSLBaseType_TextureCubeArray: return "TextureCubeArray";
case HLSLBaseType_Texture2DMS: return "Texture2DMS";

case HLSLBaseType_Depth2D: return "Depth2D";
case HLSLBaseType_Depth2DArray: return "Depth2DArray";
case HLSLBaseType_DepthCube: return "DepthCube";

case HLSLBaseType_RWTexture2D: return "RWTexture2D";

default: break;
}
}
if (IsTextureType(baseType) || IsSamplerType(baseType) || IsNumericType(baseType) || baseType == HLSLBaseType_Void || baseType == HLSLBaseType_UserDefined)
return GetTypeNameHLSL(type);

Error("Unknown type");
return NULL;
Expand Down
Loading

0 comments on commit 4c0da9d

Please sign in to comment.