mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-08-04 14:46:03 +00:00
Wire up the backbuffer sampler
This commit is contained in:
parent
8df49c2b45
commit
7e6cd36d26
3 changed files with 39 additions and 22 deletions
|
|
@ -4,37 +4,53 @@
|
|||
|
||||
// IMPORTS
|
||||
|
||||
static const int LEFT = 0;
|
||||
static const int TOP = 1;
|
||||
static const int RIGHT = 2;
|
||||
static const int BOTTOM = 3;
|
||||
static const uint FF = 0xff;
|
||||
|
||||
static const uint2 pos_map[4] = {
|
||||
uint2(RIGHT, TOP),
|
||||
uint2(RIGHT, BOTTOM),
|
||||
uint2(LEFT, BOTTOM),
|
||||
uint2(LEFT, TOP)
|
||||
public struct BlitOutput {
|
||||
public float2 texcoord;
|
||||
public float2 position;
|
||||
};
|
||||
|
||||
#define left 0
|
||||
#define top 1
|
||||
#define right 2
|
||||
#define bottom 3
|
||||
|
||||
// Static constant array mapping vertex IDs
|
||||
static const int2 vertex_pos_map[4] = {
|
||||
{right, top},
|
||||
{right, bottom},
|
||||
{left, bottom},
|
||||
{left, top}
|
||||
};
|
||||
|
||||
public BlitOutput get_coords_for_blit(uint vertex_id, float4 src_rect, float4 dest_rect) {
|
||||
int2 pos = vertex_pos_map[vertex_id];
|
||||
BlitOutput output;
|
||||
output.texcoord = float2(src_rect[pos.x], src_rect[pos.y]);
|
||||
output.position = float2(dest_rect[pos.x], dest_rect[pos.y]);
|
||||
return output;
|
||||
}
|
||||
|
||||
struct VertexOutput {
|
||||
float2 texcoord : TEXCOORD;
|
||||
float4 position : SV_Position;
|
||||
KittyCustomShaderData d;
|
||||
};
|
||||
|
||||
|
||||
[shader("vertex")]
|
||||
VertexOutput vertex_main(float4 rect, uint vertex_id : SV_VertexID) {
|
||||
uint2 pos = pos_map[vertex_id];
|
||||
VertexOutput vo;
|
||||
vo.position = float4(rect[pos.x], rect[pos.y], 0, 1);
|
||||
return vo;
|
||||
VertexOutput vertex_main(float4 src_rect, float4 dest_rect, uint vertex_id : SV_VertexID) {
|
||||
BlitOutput ans = get_coords_for_blit(vertex_id, src_rect, dest_rect);
|
||||
return {ans.texcoord, float4(ans.position[0], ans.position[1], 0.0, 1.0)};
|
||||
}
|
||||
|
||||
uniform Sampler2D backbuffer;
|
||||
|
||||
[shader("fragment")]
|
||||
float4 pipeline_fragment_main(VertexOutput vo) : SV_Target {
|
||||
vo.d.pos = vo.position;
|
||||
float4 color = float4(1, 1, 1, 1); // TODO: load from framebuffer
|
||||
float4 pipeline_fragment_main(float2 texcoord : TEXCOORD) : SV_Target {
|
||||
KittyCustomShaderData d;
|
||||
d.backbuffer = backbuffer;
|
||||
d.texcoord = texcoord;
|
||||
d.backbuffer = backbuffer;
|
||||
float4 color = backbuffer.Sample(texcoord);
|
||||
// PIPELINE
|
||||
return color;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,6 @@
|
|||
|
||||
public struct KittyCustomShaderData {
|
||||
public uint timestamp;
|
||||
public float4 pos;
|
||||
public float2 texcoord;
|
||||
public Sampler2D backbuffer;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -968,7 +968,7 @@ def build_custom_shader_pipeline_ir(slot: str = 'after-window-background', shade
|
|||
entry_points.append(entry_point)
|
||||
mod_src = get_custom_shader_src('pipeline').decode()
|
||||
mod_src = mod_src.replace('// IMPORTS', '\n'.join(f'__include "{w}";' for w in wrappers), 1)
|
||||
mod_src = mod_src.replace('// PIPELINE', '\n'.join(f'color = {w}(color, vo.d);' for w in entry_points), 1)
|
||||
mod_src = mod_src.replace('// PIPELINE', '\n'.join(f'color = {w}(color, d);' for w in entry_points), 1)
|
||||
# subprocess.run(['bat', '-P', '-l', 'cpp'], input=mod_src.encode())
|
||||
slot_key = key(slot, mod_src, shaders_content_key)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue