90 lines
2.3 KiB
C++
90 lines
2.3 KiB
C++
#ifndef SHADER_BASE_SLANG
|
|
#define SHADER_BASE_SLANG
|
|
|
|
/*
|
|
* I hope you are not looking at these war crimes.
|
|
* They are truly horrible crimes.
|
|
* Don't even try to understand what the fuck is happening here.
|
|
*/
|
|
|
|
#if defined(__METAL__)
|
|
/* We hijack all the argument buffers, which allows to use a bit more textures at cost of buffers */
|
|
#define DECLARE_TEXTURES(b) \
|
|
struct TextureBinding {Texture2D textures[96];}; \
|
|
[[vk::binding(21)]] ParameterBlock<TextureBinding> g_textures0 : register(t21); \
|
|
ParameterBlock<TextureBinding> g_textures1 : register(t22); \
|
|
ParameterBlock<TextureBinding> g_textures2 : register(t23); \
|
|
ParameterBlock<TextureBinding> g_textures3 : register(t24); \
|
|
ParameterBlock<TextureBinding> g_textures4 : register(t25); \
|
|
ParameterBlock<TextureBinding> g_textures5 : register(t26); \
|
|
ParameterBlock<TextureBinding> g_textures6 : register(t27); \
|
|
ParameterBlock<TextureBinding> g_textures7 : register(t28); \
|
|
float4 SampleTexture(uint32_t binding, float2 uv) \
|
|
{ \
|
|
SamplerState sampler = mlGetSampler(); \
|
|
uint8_t textureArray = 0; \
|
|
uint8_t textureSamplerArray = (binding >> 16) & 0xFF; \
|
|
uint8_t textureSampler = (binding >> 8) & 0xFF; \
|
|
uint8_t textureIndex = 1; \
|
|
return g_textures0.textures[1].Sample(sampler, uv); \
|
|
};
|
|
|
|
void _mlGetSampler()
|
|
{
|
|
__intrinsic_asm R"(
|
|
constexpr sampler s(filter::linear, address::repeat);
|
|
return s;
|
|
)";
|
|
}
|
|
SamplerState mlGetSampler()
|
|
{
|
|
_mlGetSampler();
|
|
};
|
|
|
|
#define DECLARE_CBUFFER(n) \
|
|
[[vk::binding(n)]] cbuffer cbuffer_##b : register(b##n)
|
|
|
|
#define DECLARE_CONSTANTS() \
|
|
[[vk::push_constant]] \
|
|
cbuffer cbuffer_constants : register(b29)
|
|
|
|
#define FIX_VERTEX_POSITION(g) g = float4(g.x, -g.y, g.z, g.w);
|
|
|
|
#elif defined(__SPIRV__)
|
|
|
|
#define DECLARE_TEXTURES(n) \
|
|
[[vk::binding(n)]] \
|
|
Sampler2D g_textures[]; \
|
|
float4 SampleTexture(uint32_t binding, float2 uv) \
|
|
{ \
|
|
return g_textures[binding].Sample(uv); \
|
|
};
|
|
|
|
#define DECLARE_CBUFFER(b) \
|
|
[[vk::binding(b)]] \
|
|
cbuffer cbuffer_##b
|
|
|
|
|
|
#define DECLARE_DATA(b,r) \
|
|
[[vk::binding(b)]] \
|
|
r
|
|
|
|
#define DECLARE_CONSTANTS()
|
|
[[vk::push_constant]] \
|
|
cbuffer cbuffer_constants
|
|
|
|
#define FIX_VERTEX_POSITION(x)
|
|
|
|
#else
|
|
#define DECLARE_TEXTURES()
|
|
float4 SampleTexture(uint32_t binding, float2 uv);
|
|
#define DECLARE_CBUFFER() cbuffer cbuffer_constants
|
|
#define DECLARE_DATA() cbuffer cbuffer_constants
|
|
#define DECLARE_CONSTANTS() cbuffer cbuffer_constants
|
|
#define FIX_VERTEX_POSITION(x)
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|