mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 09:22:01 +01:00
parent
fef487e09d
commit
bff760af01
@ -102,7 +102,7 @@ func compileShader(program *shaderir.Program) (vsh, psh *_ID3DBlob, ferr error)
|
|||||||
return vsh, psh, nil
|
return vsh, psh, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
vs, ps := hlsl.Compile(program)
|
vs, ps, _ := hlsl.Compile(program)
|
||||||
var flag uint32 = uint32(_D3DCOMPILE_OPTIMIZATION_LEVEL3)
|
var flag uint32 = uint32(_D3DCOMPILE_OPTIMIZATION_LEVEL3)
|
||||||
|
|
||||||
var wg errgroup.Group
|
var wg errgroup.Group
|
||||||
|
@ -41,8 +41,8 @@ func glslFragmentNormalize(str string) string {
|
|||||||
return strings.TrimSpace(str)
|
return strings.TrimSpace(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func hlslNormalize(str string) string {
|
func hlslNormalize(str string, prelude string) string {
|
||||||
str = strings.TrimPrefix(str, hlsl.Prelude)
|
str = strings.TrimPrefix(str, prelude)
|
||||||
return strings.TrimSpace(str)
|
return strings.TrimSpace(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,8 +180,8 @@ func TestCompile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if tc.HLSL != nil {
|
if tc.HLSL != nil {
|
||||||
vs, _ := hlsl.Compile(s)
|
vs, _, prelude := hlsl.Compile(s)
|
||||||
if got, want := hlslNormalize(vs), hlslNormalize(string(tc.HLSL)); got != want {
|
if got, want := hlslNormalize(vs, prelude), hlslNormalize(string(tc.HLSL), prelude); got != want {
|
||||||
compare(t, "HLSL", got, want)
|
compare(t, "HLSL", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ cbuffer Uniforms : register(b0) {
|
|||||||
float2 U0 : packoffset(c0);
|
float2 U0 : packoffset(c0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Varyings VSMain(float2 A0 : POSITION, float2 A1 : TEXCOORD, float4 A2 : COLOR) {
|
Varyings VSMain(float2 A0 : POSITION, float2 A1 : TEXCOORD, float4 A2 : COLOR0) {
|
||||||
Varyings varyings;
|
Varyings varyings;
|
||||||
float4x4 l0 = 0.0;
|
float4x4 l0 = 0.0;
|
||||||
varyings.Position = 0.0;
|
varyings.Position = 0.0;
|
||||||
|
@ -52,7 +52,7 @@ func (c *compileContext) structName(p *shaderir.Program, t *shaderir.Type) strin
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
const Prelude = `float mod(float x, float y) {
|
const utilFuncs = `float mod(float x, float y) {
|
||||||
return x - y * floor(x/y);
|
return x - y * floor(x/y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ float4x4 float4x4FromScalar(float x) {
|
|||||||
return float4x4(x, 0, 0, 0, 0, x, 0, 0, 0, 0, x, 0, 0, 0, 0, x);
|
return float4x4(x, 0, 0, 0, 0, x, 0, 0, 0, 0, x, 0, 0, 0, 0, x);
|
||||||
}`
|
}`
|
||||||
|
|
||||||
func Compile(p *shaderir.Program) (vertexShader, pixelShader string) {
|
func Compile(p *shaderir.Program) (vertexShader, pixelShader, prelude string) {
|
||||||
offsets := CalcUniformMemoryOffsets(p)
|
offsets := CalcUniformMemoryOffsets(p)
|
||||||
|
|
||||||
c := &compileContext{
|
c := &compileContext{
|
||||||
@ -88,7 +88,7 @@ func Compile(p *shaderir.Program) (vertexShader, pixelShader string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var lines []string
|
var lines []string
|
||||||
lines = append(lines, strings.Split(Prelude, "\n")...)
|
lines = append(lines, strings.Split(utilFuncs, "\n")...)
|
||||||
|
|
||||||
lines = append(lines, "", "struct Varyings {")
|
lines = append(lines, "", "struct Varyings {")
|
||||||
lines = append(lines, "\tfloat4 Position : SV_POSITION;")
|
lines = append(lines, "\tfloat4 Position : SV_POSITION;")
|
||||||
@ -96,7 +96,7 @@ func Compile(p *shaderir.Program) (vertexShader, pixelShader string) {
|
|||||||
for i, v := range p.Varyings {
|
for i, v := range p.Varyings {
|
||||||
switch i {
|
switch i {
|
||||||
case 0:
|
case 0:
|
||||||
lines = append(lines, fmt.Sprintf("\tfloat2 M%d : TEXCOORD0;", i))
|
lines = append(lines, fmt.Sprintf("\tfloat2 M%d : TEXCOORD;", i))
|
||||||
case 1:
|
case 1:
|
||||||
lines = append(lines, fmt.Sprintf("\tfloat4 M%d : COLOR0;", i))
|
lines = append(lines, fmt.Sprintf("\tfloat4 M%d : COLOR0;", i))
|
||||||
default:
|
default:
|
||||||
@ -110,6 +110,8 @@ func Compile(p *shaderir.Program) (vertexShader, pixelShader string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
lines = append(lines, "};")
|
lines = append(lines, "};")
|
||||||
|
prelude = strings.Join(lines, "\n")
|
||||||
|
|
||||||
lines = append(lines, "", "{{.Structs}}")
|
lines = append(lines, "", "{{.Structs}}")
|
||||||
|
|
||||||
if len(p.Uniforms) > 0 {
|
if len(p.Uniforms) > 0 {
|
||||||
@ -177,7 +179,7 @@ func Compile(p *shaderir.Program) (vertexShader, pixelShader string) {
|
|||||||
case 0:
|
case 0:
|
||||||
args = append(args, fmt.Sprintf("float2 A%d : POSITION", i))
|
args = append(args, fmt.Sprintf("float2 A%d : POSITION", i))
|
||||||
case 1:
|
case 1:
|
||||||
args = append(args, fmt.Sprintf("float2 A%d : TEXCOORD0", i))
|
args = append(args, fmt.Sprintf("float2 A%d : TEXCOORD", i))
|
||||||
case 2:
|
case 2:
|
||||||
args = append(args, fmt.Sprintf("float4 A%d : COLOR0", i))
|
args = append(args, fmt.Sprintf("float4 A%d : COLOR0", i))
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user