AviSynthShader

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(AviSynthShader: add documentation (WIP))
 
m
 
(4 intermediate revisions by one user not shown)
Line 1: Line 1:
{{FilterCat5|External_filters|Plugins|Plugins_x64|Other_filters|multipurpose_Filters}}
+
{{FilterCat6|External_filters|Plugins|Plugins_x64|Other_filters|multipurpose_Filters|Deep_color_tools}}
 
{{Filter3
 
{{Filter3
 
| [https://github.com/mysteryx93 mysteryx93]
 
| [https://github.com/mysteryx93 mysteryx93]
Line 20: Line 20:
 
== [[Script variables|Syntax and Parameters]] ==
 
== [[Script variables|Syntax and Parameters]] ==
  
===ConvertToShader===
+
===Shader.dll===
 +
Plugin containing <code>ConvertToShader()</code>, <code>ConvertFromShader()</code>, <code>Shader()</code>, and <code>ExecuteShader()</code> functions.
 +
<br>
 +
<br>
 +
====ConvertToShader====
 
Converts a clip into a wider frame containing UINT16 or half-float data. Clips must be converted in such a way before running any shader.
 
Converts a clip into a wider frame containing UINT16 or half-float data. Clips must be converted in such a way before running any shader.
  
Line 53: Line 57:
 
<br>
 
<br>
 
------------
 
------------
===ConvertFromShader===
+
====ConvertFromShader====
 
Convert a half-float clip into a standard clip.
 
Convert a half-float clip into a standard clip.
 
<br>
 
<br>
Line 81: Line 85:
 
::::*In AviSynth+, -1 to use the AviSynth+ code path, other values to use legacy code paths.
 
::::*In AviSynth+, -1 to use the AviSynth+ code path, other values to use legacy code paths.
 
:::*Default=-1
 
:::*Default=-1
 +
<br>
 +
------------
 +
====Shader====
 +
Runs a HLSL pixel shader on specified clip. You can either run a compiled .cso file or compile a .hlsl file.
 +
<br>
 +
<br>
 +
:{{Template:FuncDef|"Shader (clip, string "Path", string "EntryPoint", string "ShaderModel", string "Param0", ..., string "Param8", clip "Clip1", ..., clip "Clip9", int "Output", int "Width", int "Height", int "Precision", string "Defines")}}
 +
 +
<br>
 +
::{{Par2| |clip| }}
 +
:::The first input clip.
 +
<br>
 +
::{{Par2|Path|string|""}}
 +
:::The path to the HLSL pixel shader file to run. If not specified, Clip1 will be copied to Output.
 +
<br>
 +
::{{Par2|EntryPoint|string|"main"}}
 +
:::If compiling HLSL source code, specify the code entry point.
 +
<br>
 +
::{{Par2|ShaderModel|string|"ps_3_0"}}
 +
:::If compiling HLSL source code, specify the shader model. Usually PS_2_0 or PS_3_0
 +
<br>
 +
::{{Par2|Param0|string|""}}
 +
::.....
 +
::{{Par2|Param8|string|""}}
 +
:::Sets each of the shader parameters.
 +
:::Ex: "float4 p4 : register(c4);" will be set with <code>Param4="1,1,1,1f"</code>
 +
:::End each value with 'f'(float), 'i'(int) or 'b'(bool) to specify its type.
 +
:::<code>Param0</code> corresponds to c0, <code>Param1</code> corresponds to c1, etc.
 +
:::If setting float or int, you can set a vector or 2, 3 or 4 elements by separating the values with ','.
 +
:::If not specified, <code>Param0 = Width,Height</code> and <code>Param1 = 1/Width, 1/Height</code> by default.
 +
<br>
 +
::{{Par2|Clip1|clip|1}}
 +
::.....
 +
::{{Par2|Clip9|clip|0}}
 +
:::The index of the clips to set into this shader. Input clips are defined when calling ExecuteShader. Clip1 sets 's0' within the shader, while clip2-clip9 set 's1' to 's8'. The order is important.
 +
:::Default for clip1 is 1, for clip2-clip9 is 0 which means no source clip.
 +
<br>
 +
::{{Par2|Output|int|1}}
 +
:::The clip index where to write the output of this shader, between 1 and 9. Default is 1 which means it will be the output of ExecuteShader. If set to another value, you can use it as the input of another shader. The last shader in the chain must have output=1.
 +
<br>
 +
::{{Par2|Width|int|}}
 +
::{{Par2|Height|int|}}
 +
:::The size of the output texture. Default = same as input texture.
 +
<br>
 +
::{{Par2|Precision|int|-1}}
 +
:::While processing precision is set with ExecuteShader, this allows processing certain shaders with a different precision.
 +
<br>
 +
::{{Par2|Defines|string|""}}
 +
:::List of pre-compilation constants to set for HLSL files, separated by ';'. Ex: "Kb=0.114;Kr=0.299;"
 +
<br>
 +
------------
 +
====ExecuteShader====
 +
Executes the chain of commands on specified input clips.
 +
<br>
 +
<br>
 +
:{{Template:FuncDef|"ExecuteShader(clip, clip "Clip1-9", int "Clip1Precision", ..., int "Clip9Precision", int "Precision", int "OutputPrecision", bool "PlanarOut", int "Engines", bool "Resource")}}
 +
 +
<br>
 +
::{{Par2| |clip| }}
 +
:::cmd: A clip containing the commands returned by calling <code>Shader</code>.
 +
<br>
 +
::{{Par2|Clip1|clip| }}
 +
::.....
 +
::{{Par2|Clip9|clip| }}
 +
:::Clip1-Clip9: The clips on which to run the shaders.
 +
<br>
 +
::{{Par2|Clip1Precision|int| }}
 +
::.....
 +
::{{Par2|Clip9Precision|int| }}
 +
:::Clip1Precision-Clip9Precision:
 +
:::*1 if input clips is BYTE
 +
:::*2 if UINT16
 +
:::*3 if half-float.
 +
:::*Default=1 or the value of the previous clip
 +
<br>
 +
::{{Par2|Precision|int|3}}
 +
:::Precision:
 +
:::*1 to execute with 8-bit precision
 +
:::*2 to execute with 16-bit precision
 +
:::*3 to execute with half-float precision. Default=3
 +
<br>
 +
::{{Par2|OutputPrecision|int|1}}
 +
:::OutputPrecision:
 +
:::*1 to convert into BYTE (default)
 +
:::*2 to convert into UINT16
 +
:::*3 to convert into half-float
 +
<br>
 +
::{{Par2|PlanarOut|bool|true}}
 +
:::True to transfer data from the GPU back to the CPU as planar data to reduce memory transfers.
 +
:::Reading back from the GPU is a serious bottleneck and this generally gives a nice performance boost. Default=true
 +
<br>
 +
::{{Par2|Engines|int|1}}
 +
:::Engines count.
 +
<br>
 +
::{{Par2|Resource|bool|false}}
 +
:::Resource (don't search for file)
 
<br>
 
<br>
 
== Examples ==
 
== Examples ==
 
[[TODO]]
 
[[TODO]]
 
<br>
 
<br>
<>
+
<br>
 
== Changelog ==
 
== Changelog ==
 
  Version      Date            Changes<br>
 
  Version      Date            Changes<br>
Line 96: Line 196:
 
<br>
 
<br>
 
-----------------------------------------------
 
-----------------------------------------------
'''Back to [[External_filters#Averaging.2FLayering.2FMasking|External Filters]] &larr;'''
+
'''Back to [[External_filters#Multipurpose_Filters|External Filters]] &larr;'''

Latest revision as of 04:20, 21 February 2023

Abstract
Author mysteryx93
Version v1.6.5
Download AviSynthShader-1.6.5.zip
Category Multipurpose
License
Discussion Doom9 Forum

Contents

[edit] Description

This plugin allows running HLSL pixel shaders within AviSynth. This gives access to various HLSL filters that haven't been programmed in AviSynth.

[edit] Requirements


[edit] Syntax and Parameters

[edit] Shader.dll

Plugin containing ConvertToShader(), ConvertFromShader(), Shader(), and ExecuteShader() functions.

[edit] ConvertToShader

Converts a clip into a wider frame containing UINT16 or half-float data. Clips must be converted in such a way before running any shader.

16-bit-per-channel half-float data isn't natively supported by AviSynth. It is stored in a RGB32 container with a Width that is twice larger. When using Clip.Width, you must divine by 2 to get the accurate width.

ConvertToShader (clip, int "Precision", bool "lsb", bool "planar", int "opt")


clip   =
Input clip.


int  Precision = 1
Precision:
  • 0 to convert to Y8
  • 1 to convert into BYTE (default)
  • 2 to convert into UINT16
  • 3 to convert into half-float


bool  lsb = false
Whether to convert from DitherTools' Stack16 format. Only YV12 and YV24 are supported. Default=false


bool  planar = false
True to convert into YV24 planar data to reduce memory transfers. If you assign such a clip to Clip1, the shader will receive the 3 planes as Clip1, Clip2 and Clip3. Default=false


int  opt = -1
Optimization path:
  • In AviSynth 2.6, 0 for only C++, 1 for SSE2, 2 for AVX(only used with Precision=3), -1 to auto-detect.
  • In AviSynth+, -1 to use the AviSynth+ code path, other values to use legacy code paths.
  • Default=-1




[edit] ConvertFromShader

Convert a half-float clip into a standard clip.

ConvertFromShader (clip, int "Precision", string "Format", bool "lsb", int "opt")


clip   =
Input clip.


int  Precision = 1
Precision:
  • 0 to convert to Y8
  • 1 to convert into BYTE (default)
  • 2 to convert into UINT16
  • 3 to convert into half-float


string  Format = "YV12"
The video format to convert to. Valid formats are YV12, YV24 and RGB32. Default=YV12.


bool  lsb = false
Whether to convert to DitherTools' Stack16 format. Only YV12 and YV24 are supported. Default=false


int  opt = -1
Optimization path:
  • In AviSynth 2.6, 0 for only C++, 1 for SSE2, 2 for AVX(only used with Precision=3), -1 to auto-detect.
  • In AviSynth+, -1 to use the AviSynth+ code path, other values to use legacy code paths.
  • Default=-1



[edit] Shader

Runs a HLSL pixel shader on specified clip. You can either run a compiled .cso file or compile a .hlsl file.

"Shader (clip, string "Path", string "EntryPoint", string "ShaderModel", string "Param0", ..., string "Param8", clip "Clip1", ..., clip "Clip9", int "Output", int "Width", int "Height", int "Precision", string "Defines")


clip   =
The first input clip.


string  Path = ""
The path to the HLSL pixel shader file to run. If not specified, Clip1 will be copied to Output.


string  EntryPoint = "main"
If compiling HLSL source code, specify the code entry point.


string  ShaderModel = "ps_3_0"
If compiling HLSL source code, specify the shader model. Usually PS_2_0 or PS_3_0


string  Param0 = ""
.....
string  Param8 = ""
Sets each of the shader parameters.
Ex: "float4 p4 : register(c4);" will be set with Param4="1,1,1,1f"
End each value with 'f'(float), 'i'(int) or 'b'(bool) to specify its type.
Param0 corresponds to c0, Param1 corresponds to c1, etc.
If setting float or int, you can set a vector or 2, 3 or 4 elements by separating the values with ','.
If not specified, Param0 = Width,Height and Param1 = 1/Width, 1/Height by default.


clip  Clip1 = 1
.....
clip  Clip9 = 0
The index of the clips to set into this shader. Input clips are defined when calling ExecuteShader. Clip1 sets 's0' within the shader, while clip2-clip9 set 's1' to 's8'. The order is important.
Default for clip1 is 1, for clip2-clip9 is 0 which means no source clip.


int  Output = 1
The clip index where to write the output of this shader, between 1 and 9. Default is 1 which means it will be the output of ExecuteShader. If set to another value, you can use it as the input of another shader. The last shader in the chain must have output=1.


int  Width =
int  Height =
The size of the output texture. Default = same as input texture.


int  Precision = -1
While processing precision is set with ExecuteShader, this allows processing certain shaders with a different precision.


string  Defines = ""
List of pre-compilation constants to set for HLSL files, separated by ';'. Ex: "Kb=0.114;Kr=0.299;"



[edit] ExecuteShader

Executes the chain of commands on specified input clips.

"ExecuteShader(clip, clip "Clip1-9", int "Clip1Precision", ..., int "Clip9Precision", int "Precision", int "OutputPrecision", bool "PlanarOut", int "Engines", bool "Resource")


clip   =
cmd: A clip containing the commands returned by calling Shader.


clip  Clip1 =
.....
clip  Clip9 =
Clip1-Clip9: The clips on which to run the shaders.


int  Clip1Precision =
.....
int  Clip9Precision =
Clip1Precision-Clip9Precision:
  • 1 if input clips is BYTE
  • 2 if UINT16
  • 3 if half-float.
  • Default=1 or the value of the previous clip


int  Precision = 3
Precision:
  • 1 to execute with 8-bit precision
  • 2 to execute with 16-bit precision
  • 3 to execute with half-float precision. Default=3


int  OutputPrecision = 1
OutputPrecision:
  • 1 to convert into BYTE (default)
  • 2 to convert into UINT16
  • 3 to convert into half-float


bool  PlanarOut = true
True to transfer data from the GPU back to the CPU as planar data to reduce memory transfers.
Reading back from the GPU is a serious bottleneck and this generally gives a nice performance boost. Default=true


int  Engines = 1
Engines count.


bool  Resource = false
Resource (don't search for file)


[edit] Examples

TODO

[edit] Changelog

Version      Date            Changes
v1.6.5 2018/05/13 - Fixed crash on NVidia cards when PlanarOut=true


[edit] External Links

  • GitHub - Source code repository.




Back to External Filters

Personal tools