2023-11-06 01:50:25 +00:00
|
|
|
#ifdef HAVE_VULKAN_1_2
|
2023-08-21 00:18:37 +00:00
|
|
|
#extension GL_EXT_nonuniform_qualifier : enable
|
2023-11-03 06:01:52 +00:00
|
|
|
#endif
|
2023-08-21 00:18:37 +00:00
|
|
|
|
|
|
|
#include "enums.glsl"
|
|
|
|
|
|
|
|
layout(push_constant) uniform PushConstants {
|
|
|
|
mat4 mvp;
|
2023-10-05 01:17:51 +00:00
|
|
|
mat3x4 clip;
|
2023-08-21 00:18:37 +00:00
|
|
|
vec2 scale;
|
|
|
|
} push;
|
|
|
|
|
|
|
|
layout(constant_id=0) const uint GSK_SHADER_CLIP = GSK_GPU_SHADER_CLIP_NONE;
|
2023-11-03 01:30:12 +00:00
|
|
|
layout(constant_id=1) const uint GSK_N_IMMUTABLE_SAMPLERS = 8;
|
|
|
|
layout(constant_id=2) const uint GSK_N_SAMPLERS = 16;
|
|
|
|
layout(constant_id=3) const uint GSK_N_BUFFERS = 16;
|
2023-08-21 00:18:37 +00:00
|
|
|
|
2023-10-05 01:17:51 +00:00
|
|
|
#define GSK_GLOBAL_MVP push.mvp
|
|
|
|
#define GSK_GLOBAL_CLIP push.clip
|
|
|
|
#define GSK_GLOBAL_CLIP_RECT push.clip[0]
|
|
|
|
#define GSK_GLOBAL_SCALE push.scale
|
|
|
|
|
2023-08-21 00:18:37 +00:00
|
|
|
#define GSK_VERTEX_INDEX gl_VertexIndex
|
|
|
|
|
|
|
|
#ifdef GSK_VERTEX_SHADER
|
|
|
|
#define IN(_loc) layout(location = _loc) in
|
|
|
|
#define PASS(_loc) layout(location = _loc) out
|
|
|
|
#define PASS_FLAT(_loc) layout(location = _loc) flat out
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef GSK_FRAGMENT_SHADER
|
|
|
|
#define PASS(_loc) layout(location = _loc) in
|
|
|
|
#define PASS_FLAT(_loc) layout(location = _loc) flat in
|
|
|
|
|
2023-11-03 01:30:12 +00:00
|
|
|
layout(set = 0, binding = 0) uniform sampler2D immutable_textures[GSK_N_IMMUTABLE_SAMPLERS];
|
|
|
|
layout(set = 0, binding = 1) uniform sampler2D textures[GSK_N_SAMPLERS];
|
2023-08-21 00:18:37 +00:00
|
|
|
layout(set = 1, binding = 0) readonly buffer FloatBuffers {
|
|
|
|
float floats[];
|
2023-11-03 01:30:12 +00:00
|
|
|
} buffers[GSK_N_BUFFERS];
|
2023-08-21 00:18:37 +00:00
|
|
|
|
|
|
|
layout(location = 0) out vec4 out_color;
|
|
|
|
|
2023-10-19 06:00:37 +00:00
|
|
|
vec4
|
|
|
|
gsk_texture (uint id,
|
|
|
|
vec2 pos)
|
|
|
|
{
|
|
|
|
if ((id & 1) != 0)
|
2023-10-21 19:09:40 +00:00
|
|
|
{
|
|
|
|
id >>= 1;
|
|
|
|
if (id == 0)
|
|
|
|
return texture (immutable_textures[0], pos);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 1 && id == 1)
|
2023-10-21 19:09:40 +00:00
|
|
|
return texture (immutable_textures[1], pos);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 2 && id == 2)
|
2023-10-21 19:09:40 +00:00
|
|
|
return texture (immutable_textures[2], pos);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 3 && id == 3)
|
2023-10-21 19:09:40 +00:00
|
|
|
return texture (immutable_textures[3], pos);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 4 && id == 4)
|
2023-10-21 19:09:40 +00:00
|
|
|
return texture (immutable_textures[4], pos);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 5 && id == 5)
|
2023-10-21 19:09:40 +00:00
|
|
|
return texture (immutable_textures[5], pos);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 6 && id == 6)
|
2023-10-21 19:09:40 +00:00
|
|
|
return texture (immutable_textures[6], pos);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 7 && id == 7)
|
2023-10-21 19:09:40 +00:00
|
|
|
return texture (immutable_textures[7], pos);
|
|
|
|
}
|
2023-11-03 01:30:12 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
id >>= 1;
|
2023-11-06 01:50:25 +00:00
|
|
|
#ifdef HAVE_VULKAN_1_2
|
2023-11-03 06:01:52 +00:00
|
|
|
return texture (textures[nonuniformEXT (id)], pos);
|
|
|
|
#else
|
2023-11-03 01:30:12 +00:00
|
|
|
if (id == 0)
|
|
|
|
return texture (textures[0], pos);
|
|
|
|
else if (GSK_N_SAMPLERS > 1 && id == 1)
|
|
|
|
return texture (textures[1], pos);
|
|
|
|
else if (GSK_N_SAMPLERS > 2 && id == 2)
|
|
|
|
return texture (textures[2], pos);
|
|
|
|
else if (GSK_N_SAMPLERS > 3 && id == 3)
|
|
|
|
return texture (textures[3], pos);
|
|
|
|
else if (GSK_N_SAMPLERS > 4 && id == 4)
|
|
|
|
return texture (textures[4], pos);
|
|
|
|
else if (GSK_N_SAMPLERS > 5 && id == 5)
|
|
|
|
return texture (textures[5], pos);
|
|
|
|
else if (GSK_N_SAMPLERS > 6 && id == 6)
|
|
|
|
return texture (textures[6], pos);
|
|
|
|
else if (GSK_N_SAMPLERS > 7 && id == 7)
|
|
|
|
return texture (textures[7], pos);
|
2023-11-03 06:01:52 +00:00
|
|
|
#endif
|
2023-11-03 01:30:12 +00:00
|
|
|
}
|
2023-11-03 06:01:52 +00:00
|
|
|
return vec4 (1.0, 0.0, 0.8, 1.0);
|
2023-10-19 06:00:37 +00:00
|
|
|
}
|
|
|
|
|
2023-10-31 18:21:59 +00:00
|
|
|
ivec2
|
|
|
|
gsk_texture_size (uint id,
|
|
|
|
int lod)
|
|
|
|
{
|
|
|
|
if ((id & 1) != 0)
|
|
|
|
{
|
|
|
|
id >>= 1;
|
|
|
|
if (id == 0)
|
|
|
|
return textureSize (immutable_textures[0], lod);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 1 && id == 1)
|
2023-10-31 18:21:59 +00:00
|
|
|
return textureSize (immutable_textures[1], lod);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 2 && id == 2)
|
2023-10-31 18:21:59 +00:00
|
|
|
return textureSize (immutable_textures[2], lod);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 3 && id == 3)
|
2023-10-31 18:21:59 +00:00
|
|
|
return textureSize (immutable_textures[3], lod);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 4 && id == 4)
|
2023-10-31 18:21:59 +00:00
|
|
|
return textureSize (immutable_textures[4], lod);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 5 && id == 5)
|
2023-10-31 18:21:59 +00:00
|
|
|
return textureSize (immutable_textures[5], lod);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 6 && id == 6)
|
2023-10-31 18:21:59 +00:00
|
|
|
return textureSize (immutable_textures[6], lod);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 7 && id == 7)
|
2023-10-31 18:21:59 +00:00
|
|
|
return textureSize (immutable_textures[7], lod);
|
|
|
|
}
|
2023-11-03 01:30:12 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
id >>= 1;
|
2023-11-06 01:50:25 +00:00
|
|
|
#ifdef HAVE_VULKAN_1_2
|
2023-11-03 06:01:52 +00:00
|
|
|
return textureSize (textures[nonuniformEXT (id)], lod);
|
|
|
|
#else
|
2023-11-03 01:30:12 +00:00
|
|
|
if (id == 0)
|
|
|
|
return textureSize (textures[0], lod);
|
|
|
|
else if (GSK_N_SAMPLERS > 1 && id == 1)
|
|
|
|
return textureSize (textures[1], lod);
|
|
|
|
else if (GSK_N_SAMPLERS > 2 && id == 2)
|
|
|
|
return textureSize (textures[2], lod);
|
|
|
|
else if (GSK_N_SAMPLERS > 3 && id == 3)
|
|
|
|
return textureSize (textures[3], lod);
|
|
|
|
else if (GSK_N_SAMPLERS > 4 && id == 4)
|
|
|
|
return textureSize (textures[4], lod);
|
|
|
|
else if (GSK_N_SAMPLERS > 5 && id == 5)
|
|
|
|
return textureSize (textures[5], lod);
|
|
|
|
else if (GSK_N_SAMPLERS > 6 && id == 6)
|
|
|
|
return textureSize (textures[6], lod);
|
|
|
|
else if (GSK_N_SAMPLERS > 7 && id == 7)
|
|
|
|
return textureSize (textures[7], lod);
|
2023-11-03 06:01:52 +00:00
|
|
|
#endif
|
2023-11-03 01:30:12 +00:00
|
|
|
}
|
2023-11-03 06:01:52 +00:00
|
|
|
return ivec2 (1, 1);
|
2023-10-31 18:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vec4
|
|
|
|
gsk_texel_fetch (uint id,
|
|
|
|
ivec2 pos,
|
|
|
|
int lod)
|
|
|
|
{
|
|
|
|
if ((id & 1) != 0)
|
|
|
|
{
|
|
|
|
id >>= 1;
|
|
|
|
if (id == 0)
|
|
|
|
return texelFetch (immutable_textures[0], pos, lod);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 1 && id == 1)
|
2023-10-31 18:21:59 +00:00
|
|
|
return texelFetch (immutable_textures[1], pos, lod);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 2 && id == 2)
|
2023-10-31 18:21:59 +00:00
|
|
|
return texelFetch (immutable_textures[2], pos, lod);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 3 && id == 3)
|
2023-10-31 18:21:59 +00:00
|
|
|
return texelFetch (immutable_textures[3], pos, lod);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 4 && id == 4)
|
2023-10-31 18:21:59 +00:00
|
|
|
return texelFetch (immutable_textures[4], pos, lod);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 5 && id == 5)
|
2023-10-31 18:21:59 +00:00
|
|
|
return texelFetch (immutable_textures[5], pos, lod);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 6 && id == 6)
|
2023-10-31 18:21:59 +00:00
|
|
|
return texelFetch (immutable_textures[6], pos, lod);
|
2023-11-03 01:30:12 +00:00
|
|
|
else if (GSK_N_IMMUTABLE_SAMPLERS > 7 && id == 7)
|
2023-10-31 18:21:59 +00:00
|
|
|
return texelFetch (immutable_textures[7], pos, lod);
|
|
|
|
}
|
2023-11-03 01:30:12 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
id >>= 1;
|
2023-11-06 01:50:25 +00:00
|
|
|
#ifdef HAVE_VULKAN_1_2
|
2023-11-03 06:01:52 +00:00
|
|
|
return texelFetch (textures[nonuniformEXT (id)], pos, lod);
|
|
|
|
#else
|
2023-11-03 01:30:12 +00:00
|
|
|
if (id == 0)
|
|
|
|
return texelFetch (textures[0], pos, lod);
|
|
|
|
else if (GSK_N_SAMPLERS > 1 && id == 1)
|
|
|
|
return texelFetch (textures[1], pos, lod);
|
|
|
|
else if (GSK_N_SAMPLERS > 2 && id == 2)
|
|
|
|
return texelFetch (textures[2], pos, lod);
|
|
|
|
else if (GSK_N_SAMPLERS > 3 && id == 3)
|
|
|
|
return texelFetch (textures[3], pos, lod);
|
|
|
|
else if (GSK_N_SAMPLERS > 4 && id == 4)
|
|
|
|
return texelFetch (textures[4], pos, lod);
|
|
|
|
else if (GSK_N_SAMPLERS > 5 && id == 5)
|
|
|
|
return texelFetch (textures[5], pos, lod);
|
|
|
|
else if (GSK_N_SAMPLERS > 6 && id == 6)
|
|
|
|
return texelFetch (textures[6], pos, lod);
|
|
|
|
else if (GSK_N_SAMPLERS > 7 && id == 7)
|
|
|
|
return texelFetch (textures[7], pos, lod);
|
2023-11-03 06:01:52 +00:00
|
|
|
#endif
|
2023-11-03 01:30:12 +00:00
|
|
|
}
|
2023-11-03 06:01:52 +00:00
|
|
|
return vec4 (1.0, 0.0, 0.8, 1.0);
|
2023-10-31 18:21:59 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 01:50:25 +00:00
|
|
|
#ifdef HAVE_VULKAN_1_2
|
2023-08-30 19:57:41 +00:00
|
|
|
#define gsk_get_buffer(id) buffers[nonuniformEXT (id)]
|
2023-11-06 01:50:25 +00:00
|
|
|
#define gsk_get_float(id) gsk_get_buffer(id >> 22).floats[id & 0x3FFFFF]
|
2023-11-03 06:01:52 +00:00
|
|
|
#else
|
2023-11-06 01:50:25 +00:00
|
|
|
float
|
|
|
|
gsk_get_float (uint id)
|
|
|
|
{
|
|
|
|
uint buffer_id = id >> 22;
|
|
|
|
uint float_id = id & 0x3FFFFF;
|
|
|
|
if (buffer_id == 0)
|
|
|
|
return buffers[0].floats[float_id];
|
|
|
|
else if (GSK_N_BUFFERS > 1 && buffer_id == 1)
|
|
|
|
return buffers[1].floats[float_id];
|
|
|
|
else if (GSK_N_BUFFERS > 2 && buffer_id == 2)
|
|
|
|
return buffers[2].floats[float_id];
|
|
|
|
else if (GSK_N_BUFFERS > 3 && buffer_id == 3)
|
|
|
|
return buffers[3].floats[float_id];
|
|
|
|
else if (GSK_N_BUFFERS > 4 && buffer_id == 4)
|
|
|
|
return buffers[4].floats[float_id];
|
|
|
|
else if (GSK_N_BUFFERS > 5 && buffer_id == 5)
|
|
|
|
return buffers[5].floats[float_id];
|
|
|
|
else if (GSK_N_BUFFERS > 6 && buffer_id == 6)
|
|
|
|
return buffers[6].floats[float_id];
|
|
|
|
else if (GSK_N_BUFFERS > 7 && buffer_id == 7)
|
|
|
|
return buffers[7].floats[float_id];
|
|
|
|
}
|
2023-11-03 06:01:52 +00:00
|
|
|
#endif
|
2023-08-30 19:57:41 +00:00
|
|
|
#define gsk_get_int(id) (floatBitsToInt(gsk_get_float(id)))
|
|
|
|
#define gsk_get_uint(id) (floatBitsToUint(gsk_get_float(id)))
|
2023-08-21 00:18:37 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gsk_set_output_color (vec4 color)
|
|
|
|
{
|
|
|
|
out_color = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|