Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
angle
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
angle
Commits
e0ba27a2
Commit
e0ba27a2
authored
Jun 24, 2013
by
Nicolas Capens
Committed by
Shannon Woods
Jul 19, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Construct texture functions from stored characteristics.
TRAC #23377 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Nicolas Capens
parent
9fe6f984
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
230 additions
and
1133 deletions
+230
-1133
OutputHLSL.cpp
src/compiler/OutputHLSL.cpp
+207
-1108
OutputHLSL.h
src/compiler/OutputHLSL.h
+23
-25
No files found.
src/compiler/OutputHLSL.cpp
View file @
e0ba27a2
...
@@ -29,37 +29,63 @@ TString str(int i)
...
@@ -29,37 +29,63 @@ TString str(int i)
return
buffer
;
return
buffer
;
}
}
TString
OutputHLSL
::
TextureFunction
::
name
()
const
{
TString
name
=
"gl_texture"
;
if
(
sampler
==
EbtSampler2D
||
sampler
==
EbtISampler2D
||
sampler
==
EbtUSampler2D
)
{
name
+=
"2D"
;
}
else
if
(
sampler
==
EbtSampler3D
||
sampler
==
EbtISampler3D
||
sampler
==
EbtUSampler3D
)
{
name
+=
"3D"
;
}
else
if
(
sampler
==
EbtSamplerCube
||
sampler
==
EbtISamplerCube
||
sampler
==
EbtUSamplerCube
)
{
name
+=
"Cube"
;
}
else
UNREACHABLE
();
if
(
proj
)
{
name
+=
"Proj"
;
}
switch
(
mipmap
)
{
case
IMPLICIT
:
break
;
case
BIAS
:
break
;
case
LOD
:
name
+=
"Lod"
;
break
;
case
LOD0
:
name
+=
"Lod0"
;
break
;
default
:
UNREACHABLE
();
}
return
name
+
"("
;
}
bool
OutputHLSL
::
TextureFunction
::
operator
<
(
const
TextureFunction
&
rhs
)
const
{
if
(
sampler
<
rhs
.
sampler
)
return
true
;
if
(
coords
<
rhs
.
coords
)
return
true
;
if
(
!
proj
&&
rhs
.
proj
)
return
true
;
if
(
mipmap
<
rhs
.
mipmap
)
return
true
;
return
false
;
}
OutputHLSL
::
OutputHLSL
(
TParseContext
&
context
,
const
ShBuiltInResources
&
resources
,
ShShaderOutput
outputType
)
OutputHLSL
::
OutputHLSL
(
TParseContext
&
context
,
const
ShBuiltInResources
&
resources
,
ShShaderOutput
outputType
)
:
TIntermTraverser
(
true
,
true
,
true
),
mContext
(
context
),
mOutputType
(
outputType
)
:
TIntermTraverser
(
true
,
true
,
true
),
mContext
(
context
),
mOutputType
(
outputType
)
{
{
mUnfoldShortCircuit
=
new
UnfoldShortCircuit
(
context
,
this
);
mUnfoldShortCircuit
=
new
UnfoldShortCircuit
(
context
,
this
);
mInsideFunction
=
false
;
mInsideFunction
=
false
;
mUsesTexture2D
=
false
;
mUsesTexture2D_bias
=
false
;
mUsesTexture2DProj
=
false
;
mUsesTexture2DProj_bias
=
false
;
mUsesTexture2DProjLod
=
false
;
mUsesTexture2DLod
=
false
;
mUsesTexture3D
=
false
;
mUsesTexture3D_bias
=
false
;
mUsesTexture3DProj
=
false
;
mUsesTexture3DProj_bias
=
false
;
mUsesTexture3DProjLod
=
false
;
mUsesTexture3DLod
=
false
;
mUsesTextureCube
=
false
;
mUsesTextureCube_bias
=
false
;
mUsesTextureCubeLod
=
false
;
mUsesTexture2DLod0
=
false
;
mUsesTexture2DLod0_bias
=
false
;
mUsesTexture2DProjLod0
=
false
;
mUsesTexture2DProjLod0_bias
=
false
;
mUsesTexture3DLod0
=
false
;
mUsesTexture3DLod0_bias
=
false
;
mUsesTexture3DProjLod0
=
false
;
mUsesTexture3DProjLod0_bias
=
false
;
mUsesTextureCubeLod0
=
false
;
mUsesTextureCubeLod0_bias
=
false
;
mUsesFragColor
=
false
;
mUsesFragColor
=
false
;
mUsesFragData
=
false
;
mUsesFragData
=
false
;
mUsesDepthRange
=
false
;
mUsesDepthRange
=
false
;
...
@@ -438,7 +464,6 @@ BlockLayoutType convertBlockLayoutType(TLayoutBlockStorage blockStorage)
...
@@ -438,7 +464,6 @@ BlockLayoutType convertBlockLayoutType(TLayoutBlockStorage blockStorage)
void
OutputHLSL
::
header
()
void
OutputHLSL
::
header
()
{
{
ShShaderType
shaderType
=
mContext
.
shaderType
;
TInfoSinkBase
&
out
=
mHeader
;
TInfoSinkBase
&
out
=
mHeader
;
TString
uniforms
;
TString
uniforms
;
...
@@ -540,7 +565,7 @@ void OutputHLSL::header()
...
@@ -540,7 +565,7 @@ void OutputHLSL::header()
out
<<
*
constructor
;
out
<<
*
constructor
;
}
}
if
(
shaderType
==
SH_FRAGMENT_SHADER
)
if
(
mContext
.
shaderType
==
SH_FRAGMENT_SHADER
)
{
{
TExtensionBehavior
::
const_iterator
iter
=
mContext
.
extensionBehavior
().
find
(
"GL_EXT_draw_buffers"
);
TExtensionBehavior
::
const_iterator
iter
=
mContext
.
extensionBehavior
().
find
(
"GL_EXT_draw_buffers"
);
const
bool
usingMRTExtension
=
(
iter
!=
mContext
.
extensionBehavior
().
end
()
&&
(
iter
->
second
==
EBhEnable
||
iter
->
second
==
EBhRequire
));
const
bool
usingMRTExtension
=
(
iter
!=
mContext
.
extensionBehavior
().
end
()
&&
(
iter
->
second
==
EBhEnable
||
iter
->
second
==
EBhRequire
));
...
@@ -669,645 +694,6 @@ void OutputHLSL::header()
...
@@ -669,645 +694,6 @@ void OutputHLSL::header()
out
<<
"
\n
"
;
out
<<
"
\n
"
;
}
}
if
(
mUsesTexture2D
)
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
out
<<
"float4 gl_texture2D(sampler2D s, float2 t)
\n
"
"{
\n
"
" return tex2D(s, t);
\n
"
"}
\n
"
"
\n
"
;
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture2D(Texture2D t, SamplerState s, float2 uv)
\n
"
"{
\n
"
" return t.Sample(s, uv);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture2D(Texture2D<int4> t, SamplerState s, float2 uv)
\n
"
"{
\n
"
" return t.Sample(s, uv);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2D(Texture2D<uint4> t, SamplerState s, float2 uv)
\n
"
"{
\n
"
" return t.Sample(s, uv);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTexture2D_bias
)
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
out
<<
"float4 gl_texture2D(sampler2D s, float2 t, float bias)
\n
"
"{
\n
"
" return tex2Dbias(s, float4(t.x, t.y, 0, bias));
\n
"
"}
\n
"
"
\n
"
;
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture2D(Texture2D t, SamplerState s, float2 uv, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, uv, bias);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture2D(Texture2D<int4> t, SamplerState s, float2 uv, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, uv, bias);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2D(Texture2D<uint4> t, SamplerState s, float2 uv, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, uv, bias);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTexture2DProj
)
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
out
<<
"float4 gl_texture2DProj(sampler2D s, float3 t)
\n
"
"{
\n
"
" return tex2Dproj(s, float4(t.x, t.y, 0, t.z));
\n
"
"}
\n
"
"
\n
"
"float4 gl_texture2DProj(sampler2D s, float4 t)
\n
"
"{
\n
"
" return tex2Dproj(s, t);
\n
"
"}
\n
"
"
\n
"
;
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture2DProj(Texture2D t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.Sample(s, float2(uvw.x / uvw.z, uvw.y / uvw.z));
\n
"
"}
\n
"
"
\n
"
"float4 gl_texture2DProj(Texture2D t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.Sample(s, float2(uvw.x / uvw.w, uvw.y / uvw.w));
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture2DProj(Texture2D<int4> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.Sample(s, float2(uvw.x / uvw.z, uvw.y / uvw.z));
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture2DProj(Texture2D<int4> t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.Sample(s, float2(uvw.x / uvw.w, uvw.y / uvw.w));
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2DProj(Texture2D<uint4> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.Sample(s, float2(uvw.x / uvw.z, uvw.y / uvw.z));
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2DProj(Texture2D<uint4> t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.Sample(s, float2(uvw.x / uvw.w, uvw.y / uvw.w));
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTexture2DProj_bias
)
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
out
<<
"float4 gl_texture2DProj(sampler2D s, float3 t, float bias)
\n
"
"{
\n
"
" return tex2Dbias(s, float4(t.x / t.z, t.y / t.z, 0, bias));
\n
"
"}
\n
"
"
\n
"
"float4 gl_texture2DProj(sampler2D s, float4 t, float bias)
\n
"
"{
\n
"
" return tex2Dbias(s, float4(t.x / t.w, t.y / t.w, 0, bias));
\n
"
"}
\n
"
"
\n
"
;
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture2DProj(Texture2D t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), bias);
\n
"
"}
\n
"
"
\n
"
"float4 gl_texture2DProj(Texture2D t, SamplerState s, float4 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), bias);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture2DProj(Texture2D<int4> t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), bias);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture2DProj(Texture2D<int4> t, SamplerState s, float4 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), bias);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2DProj(Texture2D<uint4> t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), bias);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2DProj(Texture2D<uint4> t, SamplerState s, float4 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), bias);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTexture3D
)
{
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture3D(Texture3D t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.Sample(s, uvw);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture3D(Texture3D<int4> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.Sample(s, uvw);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture3D(Texture3D<uint4> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.Sample(s, uvw);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTexture3D_bias
)
{
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture3D(Texture3D t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, uvw, bias);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture3D(Texture3D<int4> t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, uvw, bias);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture3D(Texture3D<uint4> t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, uvw, bias);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTexture3DProj
)
{
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture3DProj(Texture3D t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.Sample(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w));
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture3DProj(Texture3D<int4> t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.Sample(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w));
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture3DProj(Texture3D<uint4> t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.Sample(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w));
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTexture3DProj_bias
)
{
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture3DProj(Texture3D t, SamplerState s, float4 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w), bias);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture3DProj(Texture3D<int4> t, SamplerState s, float4 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w), bias);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture3DProj(Texture3D<uint4> t, SamplerState s, float4 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w), bias);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTextureCube
)
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
out
<<
"float4 gl_textureCube(samplerCUBE s, float3 t)
\n
"
"{
\n
"
" return texCUBE(s, t);
\n
"
"}
\n
"
"
\n
"
;
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_textureCube(TextureCube t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.Sample(s, uvw);
\n
"
"}
\n
"
"
\n
"
"int4 gl_textureCube(TextureCube<int4> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.Sample(s, uvw);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_textureCube(TextureCube<uint4> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.Sample(s, uvw);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTextureCube_bias
)
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
out
<<
"float4 gl_textureCube(samplerCUBE s, float3 t, float bias)
\n
"
"{
\n
"
" return texCUBEbias(s, float4(t.x, t.y, t.z, bias));
\n
"
"}
\n
"
"
\n
"
;
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_textureCube(TextureCube t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, uvw, bias);
\n
"
"}
\n
"
"
\n
"
"int4 gl_textureCube(TextureCube<int4> t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, uvw, bias);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_textureCube(TextureCube<uint4> t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleBias(s, uvw, bias);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
// These *Lod0 intrinsics are not available in GL fragment shaders.
// They are used to sample using discontinuous texture coordinates.
if
(
mUsesTexture2DLod0
)
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
out
<<
"float4 gl_texture2DLod0(sampler2D s, float2 t)
\n
"
"{
\n
"
" return tex2Dlod(s, float4(t.x, t.y, 0, 0));
\n
"
"}
\n
"
"
\n
"
;
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture2DLod0(Texture2D t, SamplerState s, float2 uv)
\n
"
"{
\n
"
" return t.SampleLevel(s, uv, 0);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture2DLod0(Texture2D<int4> t, SamplerState s, float2 uv)
\n
"
"{
\n
"
" return t.SampleLevel(s, uv, 0);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2DLod0(Texture2D<uint4> t, SamplerState s, float2 uv)
\n
"
"{
\n
"
" return t.SampleLevel(s, uv, 0);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTexture2DLod0_bias
)
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
out
<<
"float4 gl_texture2DLod0(sampler2D s, float2 t, float bias)
\n
"
"{
\n
"
" return tex2Dlod(s, float4(t.x, t.y, 0, 0));
\n
"
"}
\n
"
"
\n
"
;
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture2DLod0(Texture2D t, SamplerState s, float2 uv, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, uv, 0);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture2DLod0(Texture2D<int4> t, SamplerState s, float2 uv, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, uv, 0);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2DLod0(Texture2D<uint4> t, SamplerState s, float2 uv, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, uv, 0);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTexture2DProjLod0
)
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
out
<<
"float4 gl_texture2DProjLod0(sampler2D s, float3 t)
\n
"
"{
\n
"
" return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, 0));
\n
"
"}
\n
"
"
\n
"
"float4 gl_texture2DProjLod(sampler2D s, float4 t)
\n
"
"{
\n
"
" return tex2Dlod(s, float4(t.x / t.w, t.y / t.w, 0, 0));
\n
"
"}
\n
"
"
\n
"
;
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture2DProjLod0(Texture2D t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), 0);
\n
"
"}
\n
"
"
\n
"
"float4 gl_texture2DProjLod0(Texture2D t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture2DProjLod0(Texture2D<int4> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), 0);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture2DProjLod0(Texture2D<int4> t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2DProjLod0(Texture2D<uint4> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), 0);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2DProjLod0(Texture2D<uint4> t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTexture2DProjLod0_bias
)
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
out
<<
"float4 gl_texture2DProjLod0_bias(sampler2D s, float3 t, float bias)
\n
"
"{
\n
"
" return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, 0));
\n
"
"}
\n
"
"
\n
"
"float4 gl_texture2DProjLod_bias(sampler2D s, float4 t, float bias)
\n
"
"{
\n
"
" return tex2Dlod(s, float4(t.x / t.w, t.y / t.w, 0, 0));
\n
"
"}
\n
"
"
\n
"
;
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture2DProjLod_bias(Texture2D t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), 0);
\n
"
"}
\n
"
"
\n
"
"float4 gl_texture2DProjLod_bias(Texture2D t, SamplerState s, float4 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture2DProjLod_bias(Texture2D<int4> t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), 0);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture2DProjLod_bias(Texture2D<int4> t, SamplerState s, float4 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2DProjLod_bias(Texture2D<uint4> t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), 0);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2DProjLod_bias(Texture2D<uint4> t, SamplerState s, float4 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTexture3DLod0
)
{
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture3DLod0(Texture3D t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture3DLod0(Texture3D<int4> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture3DLod0(Texture3D<uint4> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTexture3DLod0_bias
)
{
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture3DLod0(Texture3D t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture3DLod0(Texture3D<int4> t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture3DLod0(Texture3D<uint4> t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTexture3DProjLod0
)
{
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture3DProjLod0(Texture3D t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture3DProjLod0(Texture3D<int4> t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture3DProjLod0(Texture3D<uint4> t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTexture3DProjLod0_bias
)
{
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_texture3DProjLod_bias(Texture3D t, SamplerState s, float4 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture3DProjLod_bias(Texture3D<int4> t, SamplerState s, float4 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
"
\n
"
"uint4 gl_texture3DProjLod_bias(Texture3D<uint4> t, SamplerState s, float4 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTextureCubeLod0
)
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
out
<<
"float4 gl_textureCubeLod0(samplerCUBE s, float3 t)
\n
"
"{
\n
"
" return texCUBElod(s, float4(t.x, t.y, t.z, 0));
\n
"
"}
\n
"
"
\n
"
;
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_textureCubeLod0(TextureCube t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
"int4 gl_textureCubeLod0(TextureCube<int4> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_textureCubeLod0(TextureCube<uint4> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
mUsesTextureCubeLod0_bias
)
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
out
<<
"float4 gl_textureCubeLod0(samplerCUBE s, float3 t, float bias)
\n
"
"{
\n
"
" return texCUBElod(s, float4(t.x, t.y, t.z, 0));
\n
"
"}
\n
"
"
\n
"
;
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
out
<<
"float4 gl_textureCubeLod0(TextureCube t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
"int4 gl_textureCubeLod0(TextureCube<int4> t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_textureCubeLod0(TextureCube<uint4> t, SamplerState s, float3 uvw, float bias)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
if
(
usingMRTExtension
&&
mNumRenderTargets
>
1
)
if
(
usingMRTExtension
&&
mNumRenderTargets
>
1
)
{
{
out
<<
"#define GL_USES_MRT
\n
"
;
out
<<
"#define GL_USES_MRT
\n
"
;
...
@@ -1387,315 +773,198 @@ void OutputHLSL::header()
...
@@ -1387,315 +773,198 @@ void OutputHLSL::header()
out
<<
interfaceBlocks
;
out
<<
interfaceBlocks
;
out
<<
"
\n
"
;
out
<<
"
\n
"
;
}
}
}
if
(
mUsesTexture2D
)
for
(
TextureFunctionSet
::
const_iterator
textureFunction
=
mUsesTexture
.
begin
();
textureFunction
!=
mUsesTexture
.
end
();
textureFunction
++
)
{
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
// Return type
{
switch
(
textureFunction
->
sampler
)
out
<<
"float4 gl_texture2D(sampler2D s, float2 t)
\n
"
"{
\n
"
" return tex2Dlod(s, float4(t.x, t.y, 0, 0));
\n
"
"}
\n
"
"
\n
"
;
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
{
out
<<
"float4 gl_texture2D(Texture2D t, SamplerState s, float2 uv)
\n
"
case
EbtSampler2D
:
out
<<
"float4 "
;
break
;
"{
\n
"
case
EbtSampler3D
:
out
<<
"float4 "
;
break
;
" return t.SampleLevel(s, uv, 0);
\n
"
case
EbtSamplerCube
:
out
<<
"float4 "
;
break
;
"}
\n
"
case
EbtISampler2D
:
out
<<
"int4 "
;
break
;
"
\n
"
case
EbtISampler3D
:
out
<<
"int4 "
;
break
;
"int4 gl_texture2D(Texture2D<int> t, SamplerState s, float2 uv)
\n
"
case
EbtISamplerCube
:
out
<<
"int4 "
;
break
;
"{
\n
"
case
EbtUSampler2D
:
out
<<
"uint4 "
;
break
;
" return t.SampleLevel(s, uv, 0);
\n
"
case
EbtUSampler3D
:
out
<<
"uint4 "
;
break
;
"}
\n
"
case
EbtUSamplerCube
:
out
<<
"uint4 "
;
break
;
"
\n
"
default
:
UNREACHABLE
();
"uint4 gl_texture2D(Texture2D<uint> t, SamplerState s, float2 uv)
\n
"
"{
\n
"
" return t.SampleLevel(s, uv, 0);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
}
if
(
mUsesTexture2DLod
)
// Function name
{
out
<<
textureFunction
->
name
();
// Argument list
int
hlslCoords
=
4
;
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
{
out
<<
"float4 gl_texture2DLod(sampler2D s, float2 t, float lod)
\n
"
switch
(
textureFunction
->
sampler
)
"{
\n
"
" return tex2Dlod(s, float4(t.x, t.y, 0, lod));
\n
"
"}
\n
"
"
\n
"
;
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
{
out
<<
"float4 gl_texture2DLod(Texture2D t, SamplerState s, float2 uv, float lod)
\n
"
case
EbtSampler2D
:
out
<<
"sampler2D s"
;
hlslCoords
=
2
;
break
;
"{
\n
"
case
EbtSamplerCube
:
out
<<
"samplerCUBE s"
;
hlslCoords
=
3
;
break
;
" return t.SampleLevel(s, uv, lod);
\n
"
default
:
UNREACHABLE
();
"}
\n
"
"
\n
"
"int4 gl_texture2DLod(Texture2D<int> t, SamplerState s, float2 uv, float lod)
\n
"
"{
\n
"
" return t.SampleLevel(s, uv, lod);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2DLod(Texture2D<uint> t, SamplerState s, float2 uv, float lod)
\n
"
"{
\n
"
" return t.SampleLevel(s, uv, lod);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
}
if
(
mUsesTexture2DProj
)
switch
(
textureFunction
->
mipmap
)
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
{
out
<<
"float4 gl_texture2DProj(sampler2D s, float3 t)
\n
"
case
TextureFunction
:
:
IMPLICIT
:
break
;
"{
\n
"
case
TextureFunction
:
:
BIAS
:
hlslCoords
=
4
;
break
;
" return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, 0));
\n
"
case
TextureFunction
:
:
LOD
:
hlslCoords
=
4
;
break
;
"}
\n
"
case
TextureFunction
:
:
LOD0
:
hlslCoords
=
4
;
break
;
"
\n
"
default
:
UNREACHABLE
();
"float4 gl_texture2DProj(sampler2D s, float4 t)
\n
"
}
"{
\n
"
" return tex2Dlod(s, float4(t.x / t.w, t.y / t.w, 0, 0));
\n
"
"}
\n
"
"
\n
"
;
}
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
{
out
<<
"float4 gl_texture2DProj(Texture2D t, SamplerState s, float3 uvw)
\n
"
switch
(
textureFunction
->
sampler
)
"{
\n
"
{
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), 0);
\n
"
case
EbtSampler2D
:
out
<<
"Texture2D x, SamplerState s"
;
hlslCoords
=
2
;
break
;
"}
\n
"
case
EbtSampler3D
:
out
<<
"Texture3D x, SamplerState s"
;
hlslCoords
=
3
;
break
;
"
\n
"
case
EbtSamplerCube
:
out
<<
"TextureCube x, SamplerState s"
;
hlslCoords
=
3
;
break
;
"float4 gl_texture2DProj(Texture2D t, SamplerState s, float4 uvw)
\n
"
case
EbtISampler2D
:
out
<<
"Texture2D<int4> x, SamplerState s"
;
hlslCoords
=
2
;
break
;
"{
\n
"
case
EbtISampler3D
:
out
<<
"Texture3D<int4> x, SamplerState s"
;
hlslCoords
=
3
;
break
;
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), 0);
\n
"
case
EbtISamplerCube
:
out
<<
"TextureCube<int4> x, SamplerState s"
;
hlslCoords
=
3
;
break
;
"}
\n
"
case
EbtUSampler2D
:
out
<<
"Texture2D<uint4> x, SamplerState s"
;
hlslCoords
=
2
;
break
;
"
\n
"
case
EbtUSampler3D
:
out
<<
"Texture3D<uint4> x, SamplerState s"
;
hlslCoords
=
3
;
break
;
"int4 gl_texture2DProj(Texture2D<int4> t, SamplerState s, float3 uvw)
\n
"
case
EbtUSamplerCube
:
out
<<
"TextureCube<uint4> x, SamplerState s"
;
hlslCoords
=
3
;
break
;
"{
\n
"
default
:
UNREACHABLE
();
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), 0);
\n
"
}
"}
\n
"
"
\n
"
"int4 gl_texture2DProj(Texture2D<int4> t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2DProj(Texture2D<uint4> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), 0);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2DProj(Texture2D<uint4> t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
;
}
}
else
UNREACHABLE
();
else
UNREACHABLE
();
switch
(
textureFunction
->
coords
)
{
case
2
:
out
<<
", float2 t"
;
break
;
case
3
:
out
<<
", float3 t"
;
break
;
case
4
:
out
<<
", float4 t"
;
break
;
default
:
UNREACHABLE
();
}
}
if
(
mUsesTexture2DProjLod
)
switch
(
textureFunction
->
mipmap
)
{
{
case
TextureFunction
:
:
IMPLICIT
:
break
;
case
TextureFunction
:
:
BIAS
:
out
<<
", float bias"
;
break
;
case
TextureFunction
:
:
LOD
:
out
<<
", float lod"
;
break
;
case
TextureFunction
:
:
LOD0
:
break
;
default
:
UNREACHABLE
();
}
out
<<
")
\n
"
"{
\n
"
" return "
;
// HLSL intrinsic
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
{
out
<<
"float4 gl_texture2DProjLod(sampler2D s, float3 t, float lod)
\n
"
switch
(
textureFunction
->
sampler
)
"{
\n
"
{
" return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, lod));
\n
"
case
EbtSampler2D
:
out
<<
"tex2D"
;
break
;
"}
\n
"
case
EbtSamplerCube
:
out
<<
"texCUBE"
;
break
;
"
\n
"
default
:
UNREACHABLE
();
"float4 gl_texture2DProjLod(sampler2D s, float4 t, float lod)
\n
"
}
"{
\n
"
" return tex2Dlod(s, float4(t.x / t.w, t.y / t.w, 0, lod));
\n
"
"}
\n
"
"
\n
"
;
}
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
{
out
<<
"float4 gl_texture2DProj(Texture2D t, SamplerState s, float3 uvw, float lod)
\n
"
out
<<
"x.Sample"
;
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), lod);
\n
"
"}
\n
"
"
\n
"
"float4 gl_texture2DProj(Texture2D t, SamplerState s, float4 uvw, float lod)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), lod);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture2DProj(Texture2D<int4> t, SamplerState s, float3 uvw, float lod)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), lod);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture2DProj(Texture2D<int4> t, SamplerState s, float4 uvw, float lod)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), lod);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2DProj(Texture2D<uint4> t, SamplerState s, float3 uvw, float lod)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), lod);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture2DProj(Texture2D<uint4> t, SamplerState s, float4 uvw, float lod)
\n
"
"{
\n
"
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), lod);
\n
"
"}
\n
"
"
\n
"
;
}
}
else
UNREACHABLE
();
else
UNREACHABLE
();
}
if
(
m
UsesTexture3D
)
if
(
m
OutputType
==
SH_HLSL9_OUTPUT
)
{
{
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
switch
(
textureFunction
->
mipmap
)
{
{
out
<<
"float4 gl_texture3D(Texture3D t, SamplerState s, float3 uvw)
\n
"
case
TextureFunction
:
:
IMPLICIT
:
out
<<
"(s, "
;
break
;
"{
\n
"
case
TextureFunction
:
:
BIAS
:
out
<<
"bias(s, "
;
break
;
" return t.SampleLevel(s, uvw, 0);
\n
"
case
TextureFunction
:
:
LOD
:
out
<<
"lod(s, "
;
break
;
"}
\n
"
case
TextureFunction
:
:
LOD0
:
out
<<
"lod(s, "
;
break
;
"
\n
"
default
:
UNREACHABLE
();
"int4 gl_texture3D(Texture3D<int> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
;
}
}
else
UNREACHABLE
();
}
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
if
(
mUsesTexture3DLod
)
{
{
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
switch
(
textureFunction
->
mipmap
)
{
{
out
<<
"float4 gl_texture3DLod(Texture3D t, SamplerState s, float3 uvw, float lod)
\n
"
case
TextureFunction
:
:
IMPLICIT
:
out
<<
"(s, "
;
break
;
"{
\n
"
case
TextureFunction
:
:
BIAS
:
out
<<
"Bias(s, "
;
break
;
" return t.SampleLevel(s, uvw, lod);
\n
"
case
TextureFunction
:
:
LOD
:
out
<<
"Level(s, "
;
break
;
"}
\n
"
case
TextureFunction
:
:
LOD0
:
out
<<
"Level(s, "
;
break
;
"
\n
"
default
:
UNREACHABLE
();
"int4 gl_texture3DLod(Texture3D<int> t, SamplerState s, float3 uvw, float lod)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, lod);
\n
"
"}
\n
"
"
\n
"
;
}
}
else
UNREACHABLE
();
}
}
else
UNREACHABLE
();
if
(
mUsesTexture3DProj
)
switch
(
hlslCoords
)
{
{
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
case
2
:
out
<<
"float2("
;
break
;
{
case
3
:
out
<<
"float3("
;
break
;
out
<<
"float4 gl_texture3DProj(Texture3D t, SamplerState s, float4 uvw)
\n
"
case
4
:
out
<<
"float4("
;
break
;
"{
\n
"
default
:
UNREACHABLE
();
" return t.SampleLevel(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
"int4 gl_texture3DProj(Texture3D<int4> t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture3DProj(Texture3D<uint4> t, SamplerState s, float4 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w), 0);
\n
"
"}
\n
"
"
\n
"
;
}
else
UNREACHABLE
();
}
}
if
(
mUsesTexture3DProjLod
)
TString
proj
=
""
;
if
(
textureFunction
->
proj
)
{
{
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
switch
(
textureFunction
->
coords
)
{
{
out
<<
"float4 gl_texture3DProj(Texture3D t, SamplerState s, float4 uvw, float lod)
\n
"
case
3
:
proj
=
" / t.z"
;
break
;
"{
\n
"
case
4
:
proj
=
" / t.w"
;
break
;
" return t.SampleLevel(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w), lod);
\n
"
default
:
UNREACHABLE
();
"}
\n
"
"
\n
"
"int4 gl_texture3DProj(Texture3D<int4> t, SamplerState s, float4 uvw, float lod)
\n
"
"{
\n
"
" return t.SampleLevel(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w), lod);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_texture3DProj(Texture3D<uint4> t, SamplerState s, float4 uvw, float lod)
\n
"
"{
\n
"
" return t.SampleLevel(s, float3(uvw.x / uvw.w, uvw.y / uvw.w, uvw.z / uvw.w), lod);
\n
"
"}
\n
"
"
\n
"
;
}
}
else
UNREACHABLE
();
}
}
if
(
mUsesTextureCube
)
out
<<
"t.x"
+
proj
+
", t.y"
+
proj
;
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
{
{
out
<<
"float4 gl_textureCube(samplerCUBE s, float3 t)
\n
"
if
(
hlslCoords
>=
3
)
"{
\n
"
{
" return texCUBElod(s, float4(t.x, t.y, t.z, 0));
\n
"
if
(
textureFunction
->
coords
<
3
)
"}
\n
"
{
"
\n
"
;
out
<<
", 0
"
;
}
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
else
{
{
out
<<
"float4 gl_textureCube(TextureCube t, SamplerState s, float3 uvw)
\n
"
out
<<
", t.z"
+
proj
;
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
"int4 gl_textureCube(TextureCube<int4> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_textureCube(TextureCube<uint4> t, SamplerState s, float3 uvw)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, 0);
\n
"
"}
\n
"
"
\n
"
;
}
}
else
UNREACHABLE
();
}
}
if
(
mUsesTextureCubeLod
)
if
(
hlslCoords
==
4
)
{
{
if
(
mOutputType
==
SH_HLSL9_OUTPUT
)
switch
(
textureFunction
->
mipmap
)
{
{
out
<<
"float4 gl_textureCubeLod(samplerCUBE s, float3 t, float lod)
\n
"
case
TextureFunction
:
:
BIAS
:
out
<<
", bias"
;
break
;
"{
\n
"
case
TextureFunction
:
:
LOD
:
out
<<
", lod"
;
break
;
" return texCUBElod(s, float4(t.x, t.y, t.z, lod));
\n
"
case
TextureFunction
:
:
LOD0
:
out
<<
", 0"
;
break
;
"}
\n
"
default
:
UNREACHABLE
();
"
\n
"
;
}
}
out
<<
"));
\n
"
;
}
}
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
else
if
(
mOutputType
==
SH_HLSL11_OUTPUT
)
{
{
out
<<
"float4 gl_textureCubeLod(TextureCube t, SamplerState s, float3 uvw, float lod)
\n
"
if
(
hlslCoords
>=
3
)
"{
\n
"
{
" return t.SampleLevel(s, uvw, lod);
\n
"
out
<<
", t.z"
+
proj
;
"}
\n
"
"
\n
"
"int4 gl_textureCubeLod(TextureCube<int4> t, SamplerState s, float3 uvw, float lod)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, lod);
\n
"
"}
\n
"
"
\n
"
"uint4 gl_textureCubeLod(TextureCube<uint4> t, SamplerState s, float3 uvw, float lod)
\n
"
"{
\n
"
" return t.SampleLevel(s, uvw, lod);
\n
"
"}
\n
"
"
\n
"
;
}
}
else
UNREACHABLE
();
switch
(
textureFunction
->
mipmap
)
{
case
TextureFunction
:
:
IMPLICIT
:
out
<<
"));"
;
break
;
case
TextureFunction
:
:
BIAS
:
out
<<
"), bias);"
;
break
;
case
TextureFunction
:
:
LOD
:
out
<<
"), lod);"
;
break
;
case
TextureFunction
:
:
LOD0
:
out
<<
"), 0);"
;
break
;
default
:
UNREACHABLE
();
}
}
}
}
else
UNREACHABLE
();
out
<<
"}
\n
"
"
\n
"
;
}
if
(
mUsesFragCoord
)
if
(
mUsesFragCoord
)
{
{
...
@@ -2761,218 +2030,48 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
...
@@ -2761,218 +2030,48 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
{
{
TBasicType
samplerType
=
arguments
[
0
]
->
getAsTyped
()
->
getType
().
getBasicType
();
TBasicType
samplerType
=
arguments
[
0
]
->
getAsTyped
()
->
getType
().
getBasicType
();
if
(
name
==
"texture2D"
||
TextureFunction
textureFunction
;
(
name
==
"texture"
&&
(
samplerType
==
EbtSampler2D
||
samplerType
==
EbtISampler2D
||
samplerType
==
EbtUSampler2D
)))
textureFunction
.
sampler
=
samplerType
;
{
textureFunction
.
coords
=
arguments
[
1
]
->
getAsTyped
()
->
getNominalSize
();
if
(
!
lod0
)
textureFunction
.
mipmap
=
TextureFunction
::
IMPLICIT
;
{
if
(
arguments
.
size
()
==
2
)
{
mUsesTexture2D
=
true
;
}
else
if
(
arguments
.
size
()
==
3
)
{
mUsesTexture2D_bias
=
true
;
}
else
UNREACHABLE
();
out
<<
"gl_texture2D("
;
}
else
{
if
(
arguments
.
size
()
==
2
)
{
mUsesTexture2DLod0
=
true
;
}
else
if
(
arguments
.
size
()
==
3
)
{
mUsesTexture2DLod0_bias
=
true
;
}
else
UNREACHABLE
();
out
<<
"gl_texture2DLod0("
;
}
}
else
if
(
name
==
"texture2DProj"
||
(
name
==
"textureProj"
&&
(
samplerType
==
EbtSampler2D
||
samplerType
==
EbtISampler2D
||
samplerType
==
EbtUSampler2D
)))
{
if
(
!
lod0
)
{
if
(
arguments
.
size
()
==
2
)
{
mUsesTexture2DProj
=
true
;
}
else
if
(
arguments
.
size
()
==
3
)
{
mUsesTexture2DProj_bias
=
true
;
}
else
UNREACHABLE
();
out
<<
"gl_texture2DProj("
;
}
else
{
if
(
arguments
.
size
()
==
2
)
{
mUsesTexture2DProjLod0
=
true
;
}
else
if
(
arguments
.
size
()
==
3
)
{
mUsesTexture2DProjLod0_bias
=
true
;
}
else
UNREACHABLE
();
out
<<
"gl_texture2DProjLod0("
;
}
}
else
if
(
name
==
"texture"
&&
(
samplerType
==
EbtSampler3D
||
samplerType
==
EbtISampler3D
||
samplerType
==
EbtUSampler3D
))
{
if
(
!
lod0
)
{
if
(
arguments
.
size
()
==
2
)
{
mUsesTexture3D
=
true
;
}
else
if
(
arguments
.
size
()
==
3
)
{
mUsesTexture3D_bias
=
true
;
}
else
UNREACHABLE
();
out
<<
"gl_texture3D("
;
}
else
{
if
(
arguments
.
size
()
==
2
)
{
mUsesTexture3DLod0
=
true
;
}
else
if
(
arguments
.
size
()
==
3
)
{
mUsesTexture3DLod0_bias
=
true
;
}
else
UNREACHABLE
();
out
<<
"gl_texture3DLod0("
;
}
}
else
if
(
name
==
"textureProj"
&&
(
samplerType
==
EbtSampler3D
||
samplerType
==
EbtISampler3D
||
samplerType
==
EbtUSampler3D
))
{
if
(
!
lod0
)
{
if
(
arguments
.
size
()
==
2
)
{
mUsesTexture3DProj
=
true
;
}
else
if
(
arguments
.
size
()
==
3
)
{
mUsesTexture3DProj_bias
=
true
;
}
else
UNREACHABLE
();
out
<<
"gl_texture3DProj("
;
if
(
name
==
"texture2D"
||
name
==
"textureCube"
||
name
==
"texture"
)
}
else
{
if
(
arguments
.
size
()
==
2
)
{
{
mUsesTexture3DProjLod0
=
true
;
textureFunction
.
mipmap
=
TextureFunction
::
IMPLICIT
;
textureFunction
.
proj
=
false
;
}
}
else
if
(
arguments
.
size
()
==
3
)
else
if
(
name
==
"texture2DProj"
||
name
==
"textureProj"
)
{
{
mUsesTexture3DProjLod0_bias
=
true
;
textureFunction
.
mipmap
=
TextureFunction
::
IMPLICIT
;
}
textureFunction
.
proj
=
true
;
else
UNREACHABLE
();
out
<<
"gl_texture3DProjLod0("
;
}
}
}
else
if
(
name
==
"texture2DLod"
||
name
==
"textureCubeLod"
||
name
==
"textureLod"
)
else
if
(
name
==
"textureCube"
||
(
name
==
"texture"
&&
(
samplerType
==
EbtSamplerCube
||
samplerType
==
EbtISamplerCube
||
samplerType
==
EbtUSamplerCube
)))
{
if
(
!
lod0
)
{
{
if
(
arguments
.
size
()
==
2
)
textureFunction
.
mipmap
=
TextureFunction
::
LOD
;
{
textureFunction
.
proj
=
false
;
mUsesTextureCube
=
true
;
}
}
else
if
(
arguments
.
size
()
==
3
)
else
if
(
name
==
"texture2DProjLod"
||
name
==
"textureProjLod"
)
{
{
mUsesTextureCube_bias
=
true
;
textureFunction
.
mipmap
=
TextureFunction
::
LOD
;
textureFunction
.
proj
=
true
;
}
}
else
UNREACHABLE
();
else
UNREACHABLE
();
out
<<
"gl_textureCube("
;
if
(
textureFunction
.
mipmap
!=
TextureFunction
::
LOD
)
}
else
{
{
if
(
arguments
.
size
()
==
2
)
if
(
lod0
||
mContext
.
shaderType
==
SH_VERTEX_SHADER
)
{
{
mUsesTextureCubeLod0
=
true
;
textureFunction
.
mipmap
=
TextureFunction
::
LOD0
;
}
}
else
if
(
arguments
.
size
()
==
3
)
else
if
(
arguments
.
size
()
==
3
)
{
{
mUsesTextureCubeLod0_bias
=
true
;
textureFunction
.
mipmap
=
TextureFunction
::
BIAS
;
}
}
else
UNREACHABLE
();
out
<<
"gl_textureCubeLod0("
;
}
}
else
if
(
name
==
"texture2DLod"
||
(
name
==
"textureLod"
&&
(
samplerType
==
EbtSampler2D
||
samplerType
==
EbtISampler2D
||
samplerType
==
EbtUSampler2D
)))
{
if
(
arguments
.
size
()
==
3
)
{
mUsesTexture2DLod
=
true
;
}
else
UNREACHABLE
();
out
<<
"gl_texture2DLod("
;
}
else
if
(
name
==
"texture2DProjLod"
||
(
name
==
"textureProjLod"
&&
(
samplerType
==
EbtSampler2D
||
samplerType
==
EbtISampler2D
||
samplerType
==
EbtUSampler2D
)))
{
if
(
arguments
.
size
()
==
3
)
{
mUsesTexture2DProjLod
=
true
;
}
else
UNREACHABLE
();
out
<<
"gl_texture2DProjLod("
;
}
else
if
(
name
==
"textureLod"
&&
(
samplerType
==
EbtSampler3D
||
samplerType
==
EbtISampler3D
||
samplerType
==
EbtUSampler3D
))
{
if
(
arguments
.
size
()
==
3
)
{
mUsesTexture3DLod
=
true
;
}
else
UNREACHABLE
();
out
<<
"gl_texture3DLod("
;
}
else
if
(
name
==
"textureProjLod"
&&
(
samplerType
==
EbtSampler3D
||
samplerType
==
EbtISampler3D
||
samplerType
==
EbtUSampler3D
))
{
if
(
arguments
.
size
()
==
3
)
{
mUsesTexture3DProjLod
=
true
;
}
}
else
UNREACHABLE
();
out
<<
"gl_texture3DProjLod("
;
mUsesTexture
.
insert
(
textureFunction
);
}
else
if
(
name
==
"textureCubeLod"
||
(
name
==
"textureLod"
&&
(
samplerType
==
EbtSamplerCube
||
samplerType
==
EbtISamplerCube
||
samplerType
==
EbtUSamplerCube
)))
{
if
(
arguments
.
size
()
==
3
)
{
mUsesTextureCubeLod
=
true
;
}
else
UNREACHABLE
();
out
<<
"gl_textureCubeLod("
;
out
<<
textureFunction
.
name
();
}
else
UNREACHABLE
();
}
}
for
(
TIntermSequence
::
iterator
arg
=
arguments
.
begin
();
arg
!=
arguments
.
end
();
arg
++
)
for
(
TIntermSequence
::
iterator
arg
=
arguments
.
begin
();
arg
!=
arguments
.
end
();
arg
++
)
...
...
src/compiler/OutputHLSL.h
View file @
e0ba27a2
...
@@ -94,32 +94,30 @@ class OutputHLSL : public TIntermTraverser
...
@@ -94,32 +94,30 @@ class OutputHLSL : public TIntermTraverser
ReferencedSymbols
mReferencedVaryings
;
ReferencedSymbols
mReferencedVaryings
;
ReferencedSymbols
mReferencedOutputVariables
;
ReferencedSymbols
mReferencedOutputVariables
;
struct
TextureFunction
{
enum
Mipmap
{
IMPLICIT
,
BIAS
,
LOD
,
LOD0
};
TBasicType
sampler
;
int
coords
;
bool
proj
;
Mipmap
mipmap
;
TString
name
()
const
;
bool
operator
<
(
const
TextureFunction
&
rhs
)
const
;
};
typedef
std
::
set
<
TextureFunction
>
TextureFunctionSet
;
// Parameters determining what goes in the header output
// Parameters determining what goes in the header output
bool
mUsesTexture2D
;
TextureFunctionSet
mUsesTexture
;
bool
mUsesTexture2D_bias
;
bool
mUsesTexture2DLod
;
bool
mUsesTexture2DProj
;
bool
mUsesTexture2DProj_bias
;
bool
mUsesTexture2DProjLod
;
bool
mUsesTexture3D
;
bool
mUsesTexture3D_bias
;
bool
mUsesTexture3DLod
;
bool
mUsesTexture3DProj
;
bool
mUsesTexture3DProj_bias
;
bool
mUsesTexture3DProjLod
;
bool
mUsesTextureCube
;
bool
mUsesTextureCube_bias
;
bool
mUsesTextureCubeLod
;
bool
mUsesTexture2DLod0
;
bool
mUsesTexture2DLod0_bias
;
bool
mUsesTexture2DProjLod0
;
bool
mUsesTexture2DProjLod0_bias
;
bool
mUsesTexture3DLod0
;
bool
mUsesTexture3DLod0_bias
;
bool
mUsesTexture3DProjLod0
;
bool
mUsesTexture3DProjLod0_bias
;
bool
mUsesTextureCubeLod0
;
bool
mUsesTextureCubeLod0_bias
;
bool
mUsesFragColor
;
bool
mUsesFragColor
;
bool
mUsesFragData
;
bool
mUsesFragData
;
bool
mUsesDepthRange
;
bool
mUsesDepthRange
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment