void ComputeShader(uint3 sub_pos: SV_DispatchThreadID)
results in sub_pos=(0,0,0) every time.
Therefore, replace the input with:
void ComputeShader(uint3 g:SV_GroupID,uint3 t:SV_GroupThreadID)
and then:
uint3 sub_pos = g * BLOCK_SIZE + t;
void ComputeShader(uint3 sub_pos: SV_DispatchThreadID)
void ComputeShader(uint3 g:SV_GroupID,uint3 t:SV_GroupThreadID)
#include "shader_platform.sl"
#define IMAGE_LOAD(tex,pos) imageLoad(tex,int2(pos)) #define IMAGE_LOAD_3D(tex,pos) imageLoad(tex,int3(pos)) #define IMAGE_STORE(tex,pos,value) imageStore(tex,int2(pos),value) #define IMAGE_STORE_3D(tex,pos,value) imageStore(tex,int3(pos),value)
#define IMAGE_LOAD(tex,pos) tex[pos] #define IMAGE_LOAD_3D(tex,pos) tex[pos] #define IMAGE_STORE(tex,pos,value) tex[pos]=value; #define IMAGE_STORE_3D(tex,pos,value) tex[pos]=value;
postfix_exp '[' expression ']' { $$.varName=$1.text; $$.index=$3.text; // Is it actually a texture we're indexing? GLTextureType glTextureType=GetTextureType(buildFunction,$$.varName); if(glTextureType==0) { $$.text=($$.varName+"["+)+$$.index+"]"; } else { ostringstream str; bool rw=IsRWTexture(glTextureType); if(rw) str<<"imageLoad("; else str<<"texelFetch("; } str<<$$.varName<<",ivec"<<GetTextureDimension(glTextureType)<<"("<<$$.index<<")"<<(rw?"":",0")<<")"; $$.text=str.str(); } }This looks at any expression of the form A[B] and tries to see if A is a texture or image (as GLSL calls read-write textures), and replaces the expression with an imageLoad or a texelFetch. But postfix_exp '[' expression ']' actually recognizes A[B] even if it's on the right-hand-side. So,
outputTexture[pos]=result
imageLoad(outputTexture,ivec2(pos))=result
unary_exp '=' assignment_exp- where unary_exp matches the A[B] expression, and assignment_exp matches the RHS. In this case the imageLoad is replaced with an imageStore, and the whole thing becomes:
imageStore(outputTexture,ivec2(pos),result)
#define GET_DIMENSIONS(tex,X,Y) {ivec2 iv=textureSize(tex,0); X=iv.x;Y=iv.y;} #define GET_DIMENSIONS_3D(tex,X,Y,Z) {ivec3 iv=textureSize(tex,0); X=iv.x;Y=iv.y;Z=iv.z;}
#define GET_DIMENSIONS(tex,x,y) tex.GetDimensions(x,y) #define GET_DIMENSIONS_3D(tex,x,y,z) tex.GetDimensions(x,y,z)
<in_shader>"GetDimensions" { stdReturn(GET_DIMS);
get_dims_exp: postfix_exp '.' GET_DIMS { string texture=$1.text; string command=$3.text;
}
get_dims_exp '(' assignment_exp ',' assignment_exp ')'
{ivec2 iv=textureSize(tex,0); X=iv.x;Y=iv.y;}
// Copyright (c) 2015 Simul Software Ltd. All rights reserved. #include "shader_platform.sl" #include "../../CrossPlatform/SL/common.sl" #include "../../CrossPlatform/SL/render_states.sl" #include "../../CrossPlatform/SL/states.sl" #include "../../CrossPlatform/SL/text_constants.sl" uniform Texture2D fontTexture; shader posTexVertexOutput FontVertexShader(idOnly IN) { posTexVertexOutput OUT =VS_ScreenQuad(IN,rect); OUT.texCoords =vec4(texc.xy+texc.zw*OUT.texCoords.xy,0.0,1.0).xy; return OUT; } shader vec4 FontPixelShader(posTexVertexOutput IN) : SV_TARGET { vec2 tc =IN.texCoords;
tc.y =1.0-tc.y; vec4 lookup =fontTexture.SampleLevel(samplerStateNearest,tc,0); lookup.a =lookup.r; lookup *=colour; return lookup; } VertexShader vs = CompileShader(vs_4_0, FontVertexShader()); technique text { pass p0 { SetRasterizerState( RenderNoCull ); SetDepthStencilState( DisableDepth, 0 ); SetBlendState(AlphaBlend,vec4( 0.0, 0.0, 0.0, 0.0), 0xFFFFFFFF ); SetGeometryShader(NULL);
SetVertexShader(vs);
SetPixelShader(CompileShader(ps_4_0,FontPixelShader()));
}
}
fontTexture.SampleLevel(samplerStateNearest,tc,0);
GLint effect=glfxGenEffect(); glfxParseEffectFromFile(effect, "filename.glfx");
fontTexture.SampleLevel(samplerStateNearest,tc,0);
can be automatically rewritten, not as
textureLod(fontTexture,0);
but as:glfxSetEffectSamplerState(effect,"samplerStateNearest", (GLuint)sampler);
SamplerState samplerStateNearest :register(s11) { Filter = MIN_MAG_MIP_POINT; AddressU = Clamp; AddressV = Clamp; AddressW = Clamp; };