mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
vulkan: add vulkan compute source
Add a source that runs a compute shader and exports the GPU buffer as a DmaBuf to the clients.
This commit is contained in:
parent
edbd9eb077
commit
9799b0e679
12 changed files with 1759 additions and 0 deletions
57
spa/plugins/vulkan/shaders/main.comp
Normal file
57
spa/plugins/vulkan/shaders/main.comp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
#define WORKGROUP_SIZE 32
|
||||
layout (local_size_x = WORKGROUP_SIZE, local_size_y = WORKGROUP_SIZE, local_size_z = 1 ) in;
|
||||
|
||||
struct Pixel{
|
||||
vec4 value;
|
||||
};
|
||||
|
||||
layout(std140, binding = 0) buffer buf
|
||||
{
|
||||
Pixel imageData[];
|
||||
};
|
||||
|
||||
layout( push_constant ) uniform Constants {
|
||||
float time;
|
||||
int frame;
|
||||
int width;
|
||||
int height;
|
||||
} PushConstant;
|
||||
|
||||
float iTime;
|
||||
int iFrame;
|
||||
vec3 iResolution;
|
||||
vec4 iMouse;
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord );
|
||||
|
||||
void main()
|
||||
{
|
||||
iTime = PushConstant.time;
|
||||
iFrame = PushConstant.frame;
|
||||
iResolution = vec3(float(PushConstant.width), float(PushConstant.height), 0.0);
|
||||
iMouse = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
vec2 coord = vec2(float(gl_GlobalInvocationID.x),
|
||||
iResolution.y - float(gl_GlobalInvocationID.y));
|
||||
vec4 outColor;
|
||||
|
||||
if(coord.x >= iResolution.x || coord.y >= iResolution.y)
|
||||
return;
|
||||
|
||||
mainImage(outColor, coord);
|
||||
|
||||
imageData[PushConstant.width * gl_GlobalInvocationID.y +
|
||||
gl_GlobalInvocationID.x].value = outColor;
|
||||
}
|
||||
|
||||
//#include "plasma-globe.comp"
|
||||
#include "mandelbrot-distance.comp"
|
||||
//#include "ring-twister.comp"
|
||||
//#include "gears.comp"
|
||||
//#include "protean-clouds.comp"
|
||||
//#include "flame.comp"
|
||||
//#include "shader.comp"
|
||||
//#include "raymarching-primitives.comp"
|
||||
//#include "3d-primitives.comp"
|
||||
BIN
spa/plugins/vulkan/shaders/main.spv
Normal file
BIN
spa/plugins/vulkan/shaders/main.spv
Normal file
Binary file not shown.
58
spa/plugins/vulkan/shaders/mandelbrot-distance.comp
Normal file
58
spa/plugins/vulkan/shaders/mandelbrot-distance.comp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
// Created by inigo quilez - iq/2013
|
||||
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
|
||||
|
||||
|
||||
// This shader computes the distance to the Mandelbrot Set for everypixel, and colorizes
|
||||
// it accoringly.
|
||||
//
|
||||
// Z -> Z²+c, Z0 = 0.
|
||||
// therefore Z' -> 2·Z·Z' + 1
|
||||
//
|
||||
// The Hubbard-Douady potential G(c) is G(c) = log Z/2^n
|
||||
// G'(c) = Z'/Z/2^n
|
||||
//
|
||||
// So the distance is |G(c)|/|G'(c)| = |Z|·log|Z|/|Z'|
|
||||
//
|
||||
// More info here: http://www.iquilezles.org/www/articles/distancefractals/distancefractals.htm
|
||||
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec2 p = -1.0 + 2.0 * fragCoord.xy / iResolution.xy;
|
||||
p.x *= iResolution.x/iResolution.y;
|
||||
|
||||
// animation
|
||||
float tz = 0.5 - 0.5*cos(0.225*iTime);
|
||||
float zoo = pow( 0.5, 13.0*tz );
|
||||
vec2 c = vec2(-0.05,.6805) + p*zoo;
|
||||
|
||||
// iterate
|
||||
float di = 1.0;
|
||||
vec2 z = vec2(0.0);
|
||||
float m2 = 0.0;
|
||||
vec2 dz = vec2(0.0);
|
||||
for( int i=0; i<300; i++ )
|
||||
{
|
||||
if( m2>1024.0 ) { di=0.0; break; }
|
||||
|
||||
// Z' -> 2·Z·Z' + 1
|
||||
dz = 2.0*vec2(z.x*dz.x-z.y*dz.y, z.x*dz.y + z.y*dz.x) + vec2(1.0,0.0);
|
||||
|
||||
// Z -> Z² + c
|
||||
z = vec2( z.x*z.x - z.y*z.y, 2.0*z.x*z.y ) + c;
|
||||
|
||||
m2 = dot(z,z);
|
||||
}
|
||||
|
||||
// distance
|
||||
// d(c) = |Z|·log|Z|/|Z'|
|
||||
float d = 0.5*sqrt(dot(z,z)/dot(dz,dz))*log(dot(z,z));
|
||||
if( di>0.5 ) d=0.0;
|
||||
|
||||
// do some soft coloring based on distance
|
||||
d = clamp( pow(4.0*d/zoo,0.2), 0.0, 1.0 );
|
||||
|
||||
vec3 col = vec3( d );
|
||||
|
||||
fragColor = vec4( col, 1.0 );
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue