brought back functionality from previous builds but now cross-platform
This commit is contained in:
85
funnyassets/gfx_shaders/shader_base.h
Normal file
85
funnyassets/gfx_shaders/shader_base.h
Normal file
@@ -0,0 +1,85 @@
|
||||
#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);
|
||||
|
||||
void _mlGetSampler()
|
||||
{
|
||||
__intrinsic_asm R"(
|
||||
constexpr sampler s(filter::linear, address::repeat);
|
||||
return s;
|
||||
)";
|
||||
}
|
||||
SamplerState mlGetSampler()
|
||||
{
|
||||
_mlGetSampler();
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
#define DECLARE_CBUFFER(b) \
|
||||
[[vk::binding(b)]] cbuffer cbuffer_##b : register(t##b)
|
||||
|
||||
#define DECLARE_CONSTANTS() \
|
||||
[[vk::push_constant]] \
|
||||
cbuffer cbuffer_constants : register(t29)
|
||||
|
||||
|
||||
#elif defined(__SPIRV__)
|
||||
|
||||
#define DECLARE_TEXTURES(b) \
|
||||
[[vk::binding(b)]] \
|
||||
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
|
||||
|
||||
#else
|
||||
#define DECLARE_TEXTURES()
|
||||
float4 SampleTexture(uint32_t binding, float2 uv);
|
||||
#define DECLARE_CBUFFER() cbuffer cbuffer_constats
|
||||
#define DECLARE_DATA() cbuffer cbuffer_constats
|
||||
#define DECLARE_CONSTANTS() cbuffer cbuffer_constats
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user