mirror of
https://github.com/OpenFusionProject/scripts.git
synced 2024-11-14 19:20:05 +00:00
dx2cg: Implement RECT, CUBE texture types
Also tried to implement 3D texture type, but that will likely require a few other instructions to get working - namely texldp and dcl_volume.
This commit is contained in:
parent
06869164a1
commit
d5b58d96da
@ -54,7 +54,7 @@ ops = {
|
|||||||
"slt": "{0} = float4(({1}.x < {2}.x) ? 1.0f : 0.0f, ({1}.y < {2}.y) ? 1.0f : 0.0f, ({1}.z < {2}.z) ? 1.0f : 0.0f, ({1}.w < {2}.w) ? 1.0f : 0.0f);",
|
"slt": "{0} = float4(({1}.x < {2}.x) ? 1.0f : 0.0f, ({1}.y < {2}.y) ? 1.0f : 0.0f, ({1}.z < {2}.z) ? 1.0f : 0.0f, ({1}.w < {2}.w) ? 1.0f : 0.0f);",
|
||||||
"sge": "{0} = float4(({1}.x >= {2}.x) ? 1.0f : 0.0f, ({1}.y >= {2}.y) ? 1.0f : 0.0f, ({1}.z >= {2}.z) ? 1.0f : 0.0f, ({1}.w >= {2}.w) ? 1.0f : 0.0f);",
|
"sge": "{0} = float4(({1}.x >= {2}.x) ? 1.0f : 0.0f, ({1}.y >= {2}.y) ? 1.0f : 0.0f, ({1}.z >= {2}.z) ? 1.0f : 0.0f, ({1}.w >= {2}.w) ? 1.0f : 0.0f);",
|
||||||
"rcp": "{0} = ({1} == 0.0f) ? FLT_MAX : (({1} == 1.0f) ? {1} : (1 / {1}));",
|
"rcp": "{0} = ({1} == 0.0f) ? FLT_MAX : (({1} == 1.0f) ? {1} : (1 / {1}));",
|
||||||
"texld": "{0} = tex2D({2}, (float2){1});",
|
"texld": "{0} = {3}({2}, (float2){1});",
|
||||||
}
|
}
|
||||||
|
|
||||||
struct_a2v = """struct a2v {
|
struct_a2v = """struct a2v {
|
||||||
@ -186,12 +186,21 @@ def process_header(prog):
|
|||||||
i = i - 1
|
i = i - 1
|
||||||
elif line.startswith("SetTexture"):
|
elif line.startswith("SetTexture"):
|
||||||
dec = line.split(' ')
|
dec = line.split(' ')
|
||||||
if dec[2] != "{2D}":
|
texture_type = None
|
||||||
|
if dec[2] == "{2D}":
|
||||||
|
texture_type = "sampler2D"
|
||||||
|
elif dec[2] == "{3D}":
|
||||||
|
texture_type = "sampler3D"
|
||||||
|
elif dec[2] == "{RECT}":
|
||||||
|
texture_type = "samplerRECT"
|
||||||
|
elif dec[2] == "{CUBE}":
|
||||||
|
texture_type = "samplerCUBE"
|
||||||
|
else:
|
||||||
raise ValueError(f"Unknown texture type {dec[2]}")
|
raise ValueError(f"Unknown texture type {dec[2]}")
|
||||||
key = f"s{textures}"
|
key = f"s{textures}"
|
||||||
val = dec[1][1:-1]
|
val = dec[1][1:-1]
|
||||||
loctab[key] = val
|
loctab[key] = val
|
||||||
locdecl.append(f"sampler2D {val};")
|
locdecl.append(f"{texture_type} {val};")
|
||||||
textures = textures + 1
|
textures = textures + 1
|
||||||
|
|
||||||
del prog[i]
|
del prog[i]
|
||||||
@ -218,7 +227,6 @@ def resolve_args(args, loctab, consts):
|
|||||||
arg = arg[:dot]
|
arg = arg[:dot]
|
||||||
else:
|
else:
|
||||||
swiz = ""
|
swiz = ""
|
||||||
|
|
||||||
if arg[0] == 'r':
|
if arg[0] == 'r':
|
||||||
pass
|
pass
|
||||||
elif arg[0] == 'v':
|
elif arg[0] == 'v':
|
||||||
@ -239,7 +247,7 @@ def resolve_args(args, loctab, consts):
|
|||||||
|
|
||||||
args[a] = neg + arg + swiz
|
args[a] = neg + arg + swiz
|
||||||
|
|
||||||
def decode(code, args):
|
def decode(code, args, locdecl):
|
||||||
if code in decls:
|
if code in decls:
|
||||||
return [decls[code].format(*args)]
|
return [decls[code].format(*args)]
|
||||||
elif code in ops:
|
elif code in ops:
|
||||||
@ -254,14 +262,31 @@ def decode(code, args):
|
|||||||
else:
|
else:
|
||||||
swiz = "xyzw"
|
swiz = "xyzw"
|
||||||
|
|
||||||
lines = [ops[code].format("tmp", *args[1:])]
|
lines = []
|
||||||
|
if code == "texld":
|
||||||
|
cg_tex_type = None
|
||||||
|
for loc in locdecl:
|
||||||
|
loc = loc.split(' ')
|
||||||
|
if args[2] == loc[1][:-1]:
|
||||||
|
if loc[0] == 'sampler2D':
|
||||||
|
cg_tex_type = "tex2D"
|
||||||
|
elif loc[0] == 'sampler3D':
|
||||||
|
cg_tex_type = "tex3D"
|
||||||
|
elif loc[0] == 'samplerCUBE':
|
||||||
|
cg_tex_type = "texCUBE"
|
||||||
|
elif loc[0] == 'samplerRECT':
|
||||||
|
cg_tex_type = "texRECT"
|
||||||
|
lines = [ops[code].format("tmp", *args[1:], cg_tex_type)]
|
||||||
|
else:
|
||||||
|
lines = [ops[code].format("tmp", *args[1:])]
|
||||||
|
|
||||||
for c in swiz:
|
for c in swiz:
|
||||||
lines.append(f"{target}.{c} = tmp.{c};")
|
lines.append(f"{target}.{c} = tmp.{c};")
|
||||||
return lines
|
return lines
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Unknown opcode {code}")
|
raise ValueError(f"Unknown opcode {code}")
|
||||||
|
|
||||||
def process_asm(asm, loctab):
|
def process_asm(asm, loctab, locdecl):
|
||||||
shadertype = ""
|
shadertype = ""
|
||||||
if asm[0] == "\"vs_1_1":
|
if asm[0] == "\"vs_1_1":
|
||||||
shadertype = "vertex"
|
shadertype = "vertex"
|
||||||
@ -294,7 +319,7 @@ def process_asm(asm, loctab):
|
|||||||
code = code[:pp]
|
code = code[:pp]
|
||||||
|
|
||||||
resolve_args(args, loctab, consts)
|
resolve_args(args, loctab, consts)
|
||||||
disasm = decode(code, args)
|
disasm = decode(code, args, locdecl)
|
||||||
# print(f"{instruction} \t==>\t{disasm}")
|
# print(f"{instruction} \t==>\t{disasm}")
|
||||||
disasm.insert(0, f"// {instruction}")
|
disasm.insert(0, f"// {instruction}")
|
||||||
translated.extend(disasm)
|
translated.extend(disasm)
|
||||||
@ -317,7 +342,7 @@ def disassemble(blocks):
|
|||||||
binds.update(bds)
|
binds.update(bds)
|
||||||
lighting |= light
|
lighting |= light
|
||||||
|
|
||||||
(shadertype, disasm) = process_asm(asm, ltab)
|
(shadertype, disasm) = process_asm(asm, ltab, locdecl)
|
||||||
shaders[shadertype] = disasm
|
shaders[shadertype] = disasm
|
||||||
|
|
||||||
text = ""
|
text = ""
|
||||||
|
Loading…
Reference in New Issue
Block a user