Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Sampler.grad method for HXSL #1127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hxsl/Ast.hx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ enum TGlobal {
TextureLod;
Texel;
TextureSize;
Grad;
// ...other texture* operations
// constructors
ToInt;
Expand Down Expand Up @@ -243,6 +244,7 @@ enum TGlobal {
ChannelReadLod;
ChannelFetch;
ChannelTextureSize;
ChannelGrad;
Trace;
// instancing
VertexID;
Expand Down
15 changes: 15 additions & 0 deletions hxsl/Checker.hx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ class Checker {
{ args : [ { name: "tex", type: TSampler2D }, { name: "pos", type: ivec2 }, { name: "lod", type: TInt } ], ret: vec4 },
{ args : [ { name: "tex", type: TSampler2DArray }, { name: "pos", type: ivec3 }, { name: "lod", type: TInt } ], ret: vec4 },
];
case Grad:
[
{ args : [ { name: "tex", type: TSampler2D }, { name: "pos", type: vec2 }, { name: "dPdx", type: vec2 }, { name: "dPdy", type: vec2 } ], ret: vec4 },
{ args : [ { name: "tex", type: TSampler2DArray }, { name: "pos", type: vec3 }, { name: "dPdx", type: vec2 }, { name: "dPdy", type: vec2 } ], ret: vec4 },
{ args : [ { name: "tex", type: TSamplerCube }, { name: "pos", type: vec3 }, { name: "dPdx", type: vec3 }, { name: "dPdy", type: vec3 } ], ret: vec4 },
];
case TextureSize:
[
{ args : [ { name: "tex", type: TSampler2D } ], ret: vec2 },
Expand Down Expand Up @@ -166,6 +172,13 @@ class Checker {
{ args : [ { name : "channel", type : TChannel(3) }, { name : "pos", type : ivec2 }, { name : "lod", type : TInt } ], ret : vec3 },
{ args : [ { name : "channel", type : TChannel(4) }, { name : "pos", type : ivec2 }, { name : "lod", type : TInt } ], ret : vec4 },
];
case ChannelGrad:
[
{ args : [ { name: "channel", type: TChannel(1) }, { name: "pos", type: vec2 }, { name: "dPdx", type: vec2 }, { name: "dPdy", type: vec2 } ], ret: TFloat },
{ args : [ { name: "channel", type: TChannel(2) }, { name: "pos", type: vec2 }, { name: "dPdx", type: vec2 }, { name: "dPdy", type: vec2 } ], ret: vec2 },
{ args : [ { name: "channel", type: TChannel(3) }, { name: "pos", type: vec2 }, { name: "dPdx", type: vec2 }, { name: "dPdy", type: vec2 } ], ret: vec3 },
{ args : [ { name: "channel", type: TChannel(4) }, { name: "pos", type: vec2 }, { name: "dPdx", type: vec2 }, { name: "dPdy", type: vec2 } ], ret: vec4 },
];
case ChannelTextureSize:
[
{ args : [ { name: "channel", type: TChannel(1) } ], ret: vec2 },
Expand Down Expand Up @@ -919,6 +932,8 @@ class Checker {
case ["getLod", TChannel(_)]: ChannelReadLod;
case ["fetch"|"fetchLod", TSampler2D|TSampler2DArray]: Texel;
case ["fetch"|"fetchLod", TChannel(_)]: ChannelFetch;
case ["grad", TSampler2D|TSampler2DArray|TSamplerCube]: Grad;
case ["grad", TChannel(_)]: ChannelGrad;
case ["size", TSampler2D|TSampler2DArray|TSamplerCube]: TextureSize;
case ["size", TChannel(_)]: ChannelTextureSize;
default: null;
Expand Down
3 changes: 3 additions & 0 deletions hxsl/Dce.hx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ class Dce {
case TCall({ e : TGlobal(ChannelFetch) }, [_, pos, lod, { e : TConst(CInt(cid)) }]):
var c = channelVars[cid];
return { e : TCall({ e : TGlobal(Texel), p : e.p, t : TVoid }, [{ e : TVar(c), t : c.type, p : e.p }, mapExpr(pos,true), mapExpr(lod,true)]), t : TVoid, p : e.p };
case TCall({ e : TGlobal(ChannelGrad) }, [_, pos, dPdx, dPdy, { e: TConst(CInt(cid)) }]):
var c = channelVars[cid];
return { e : TCall({ e: TGlobal(Grad), p : e.p, t : TVoid }, [{ e : TVar(c), t : c.type, p : e.p }, mapExpr(pos,true), mapExpr(dPdx,true), mapExpr(dPdy,true)]), t : TVoid, p : e.p };
case TCall({ e : TGlobal(ChannelTextureSize) }, [_, { e : TConst(CInt(cid)) }]):
var c = channelVars[cid];
return { e : TCall({ e : TGlobal(TextureSize), p : e.p, t : TVoid }, [{ e : TVar(c), t : c.type, p : e.p }]), t : TVoid, p : e.p };
Expand Down
2 changes: 2 additions & 0 deletions hxsl/GlslOut.hx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ class GlslOut {
// return "_texelFetch";
// else
return "texelFetch";
case Grad:
return "textureGrad";
case TextureSize:
switch( args[0].t ) {
case TSampler2D, TChannel(_):
Expand Down
4 changes: 3 additions & 1 deletion hxsl/HlslOut.hx
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,15 @@ class HlslOut {
var acc = varAccess.get(v.id);
if( acc != null ) add(acc);
ident(v);
case TCall({ e : TGlobal(g = (Texture | TextureLod)) }, args):
case TCall({ e : TGlobal(g = (Texture | TextureLod | Grad)) }, args):
addValue(args[0], tabs);
switch( g ) {
case Texture:
add(isVertex ? ".SampleLevel(" : ".Sample(");
case TextureLod:
add(".SampleLevel(");
case Grad:
add(".SampleGrad(");
default:
throw "assert";
}
Expand Down