Scripting - Handle compute shader groups automatically

This commit is contained in:
Emmanuel BENOîT 2017-12-25 20:39:56 +01:00
parent c3ccc9403a
commit 6b3f9bff2a
7 changed files with 37 additions and 29 deletions

View file

@ -19,13 +19,6 @@
(set use-compute 1)
(set render-compute-size-x 8)
(set render-compute-size-y 8)
(set combine-compute-size-x 8)
(set combine-compute-size-y 32)
(set dof-compute-size-x 64)
(set dof-compute-size-y 16)
(call scene-init)
(call dof-init)
(call bloom-init)
@ -150,10 +143,7 @@
(use-pipeline pl-scene-p1)
(if $use-compute (
(image 0 tx-scene-output 0)
(compute
(add 1 (div $vp-width $render-compute-size-x))
(add 1 (div $vp-height $render-compute-size-y))
1)
(compute $vp-width $vp-height 1)
)(
(uniforms prg-scene-p1 1 $vp-width $vp-height)
(use-framebuffer rt-scene)
@ -252,11 +242,7 @@
(uniforms-i prg-dof-pass1 0 0)
(uniforms-i prg-dof-pass2 0 0)
(if $use-compute (
(locals dof-cx dof-cy)
(set dof-cx (add 1 (div $vp-width $dof-compute-size-x)))
(set dof-cy (add 1 (div $vp-height $dof-compute-size-y)))
)(
(if (not $use-compute) (
(use-texture 1 in-depth smp-dof)
(uniforms-i prg-dof-pass1 1 1)
(uniforms-i prg-dof-pass2 1 1)
@ -268,7 +254,7 @@
(use-pipeline pl-dof-pass1)
(if $use-compute (
(image 0 tx-dof-pass1 0)
(compute $dof-cx $dof-cy 1)
(compute $vp-width $vp-height 1)
)(
(use-framebuffer rt-dof-pass1)
(viewport 0 0 $vp-width $vp-height)
@ -281,7 +267,7 @@
(use-pipeline pl-dof-pass2)
(if $use-compute (
(image 0 tx-dof-pass2 0)
(compute $dof-cx $dof-cy 1)
(compute $vp-width $vp-height 1)
)(
(use-framebuffer rt-dof-pass2)
(viewport 0 0 $vp-width $vp-height)
@ -567,10 +553,7 @@
(if $use-compute (
(image 0 tx-combined 0)
(compute
(add 1 (div $vp-width $combine-compute-size-x))
(add 1 (div $vp-height $combine-compute-size-y))
1)
(compute $vp-width $vp-height 1)
)(
(viewport 0 0 $vp-width $vp-height)
(fullscreen)

View file

@ -1,10 +1,5 @@
//! type chunk
layout(
local_size_x = 64 ,
local_size_y = 16
) in;
//#define DOF_USE_RANDOM
layout( location = 0 ) uniform sampler2D u_Input;

View file

@ -1,6 +1,12 @@
#version 450 core
//! type compute
layout(
local_size_x = 8 ,
local_size_y = 64
) in;
//! include chunks/dof-cs.glsl
void main()

View file

@ -1,6 +1,12 @@
#version 450 core
//! type compute
layout(
local_size_x = 8 ,
local_size_y = 20
) in;
//! include chunks/dof-cs.glsl
void main()

View file

@ -714,8 +714,20 @@ void T_OpContext::run(
{
ensureStack( instr , 3 );
const auto ss( stack.size( ) );
glDispatchCompute( stack[ ss - 1 ].f , stack[ ss - 2 ].f ,
stack[ ss - 3 ].f );
const auto cpl{ UI::Shaders( ).currentPipeline( ) };
const auto pid{ cpl.valid( ) ? cpl.program( E_ShaderType::COMPUTE ) : 0 };
if ( pid ) {
int32_t wg[ 3 ];
glGetProgramiv( pid , GL_COMPUTE_WORK_GROUP_SIZE , wg );
int32_t ds[ 3 ];
for ( auto i = 0u ; i < 3u ; i ++ ) {
const auto sv{ uint32_t( stack[ ss - 1 - i ].f ) };
const auto m{ sv % wg[ i ] };
ds[ i ] = ( sv / wg[ i ] ) + ( m ? 1 : 0 );
}
glDispatchCompute( ds[ 0 ] , ds[ 1 ] , ds[ 2 ] );
}
stack.resize( ss - 3 );
break;
}

View file

@ -220,6 +220,7 @@ void T_ShaderPipeline::enable( ) const
if ( pl && pl->id ) {
glUseProgram( 0 );
glBindProgramPipeline( pl->id );
UI::Shaders( ).cPipeline_ = id_;
}
}

View file

@ -83,6 +83,9 @@ struct T_ShaderManager
bool& uiEnabled( )
{ return uiEnabled_; }
T_ShaderPipeline currentPipeline( ) const noexcept
{ return T_ShaderPipeline{ cPipeline_ }; }
private:
struct T_Pipeline_
{
@ -129,6 +132,8 @@ struct T_ShaderManager
T_KeyValueTable< T_String , T_Array< T_String > > missing_;
T_Array< T_String > updates_;
T_String cPipeline_{ };
// Load/use existing program for use with pipelines
void loadProgram(
T_String const& pipeline ,