diff --git a/test/demo.srd b/test/demo.srd index f16a03a..2b2ed6c 100644 --- a/test/demo.srd +++ b/test/demo.srd @@ -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) diff --git a/test/shaders/chunks/dof-cs.glsl b/test/shaders/chunks/dof-cs.glsl index 7cf03d0..7130d21 100644 --- a/test/shaders/chunks/dof-cs.glsl +++ b/test/shaders/chunks/dof-cs.glsl @@ -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; diff --git a/test/shaders/dof-pass1.c.glsl b/test/shaders/dof-pass1.c.glsl index fd4142c..0e9315a 100644 --- a/test/shaders/dof-pass1.c.glsl +++ b/test/shaders/dof-pass1.c.glsl @@ -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() diff --git a/test/shaders/dof-pass2.c.glsl b/test/shaders/dof-pass2.c.glsl index d1238b0..d322ce1 100644 --- a/test/shaders/dof-pass2.c.glsl +++ b/test/shaders/dof-pass2.c.glsl @@ -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() diff --git a/ui-opemu.cc b/ui-opemu.cc index 45d2597..6b99cef 100644 --- a/ui-opemu.cc +++ b/ui-opemu.cc @@ -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; } diff --git a/ui-shaders.cc b/ui-shaders.cc index e5aabe7..c400d02 100644 --- a/ui-shaders.cc +++ b/ui-shaders.cc @@ -220,6 +220,7 @@ void T_ShaderPipeline::enable( ) const if ( pl && pl->id ) { glUseProgram( 0 ); glBindProgramPipeline( pl->id ); + UI::Shaders( ).cPipeline_ = id_; } } diff --git a/ui-shaders.hh b/ui-shaders.hh index 21bbf22..5700046 100644 --- a/ui-shaders.hh +++ b/ui-shaders.hh @@ -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 ,