mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-25 05:01:24 +00:00
[qfcc] Support marking expression for the back-end
The spir-v back-end needs to emit literal values in some places and supporting that in explicit intrinsics required marking the expression as special. Unary = seems a little odd at first, but at the same time seems to make sense, especially for marking expressions as "use literal value" (eg =ImageOperands.Lod will result in a literal 2 instead of an op id that points to the 2).
This commit is contained in:
parent
3a521ebe16
commit
16b04512cb
4 changed files with 25 additions and 10 deletions
|
@ -485,6 +485,12 @@ unary_expr (int op, const expr_t *e)
|
|||
// unary + is a no-op
|
||||
return e;
|
||||
}
|
||||
if (op == '=') {
|
||||
// unary = is a marker for special handling by the back-end
|
||||
auto new = new_unary_expr (op, e);
|
||||
new->expr.type = get_type (e);
|
||||
return edag_add_expr (new);
|
||||
}
|
||||
if (is_algebra (t)) {
|
||||
unary_type = algebra_u;
|
||||
} else if (is_enum (t)) {
|
||||
|
|
|
@ -849,17 +849,17 @@ SRC_LINE
|
|||
" gsamplerCAS=[__sampler(,Cube,,Array,Shadow)]) {" "\n"
|
||||
"gvec4 texture(gsampler sampler, gtex_coord P)" "\n"
|
||||
"= " SPV(OpImageSampleExplicitLod) "\n"
|
||||
"[sampler, P, ImageOperands.Lod, 0];" "\n"
|
||||
"[sampler, P, =ImageOperands.Lod, 0];" "\n"
|
||||
"float texture(gsamplerSh sampler, gshadow_coord P)" "\n"
|
||||
"= " SPV(OpImageSampleDrefExplicitLod) "\n"
|
||||
"[sampler, [gsamplerSh shadow_coord(P)], [gsamplerSh comp(P)]," "\n"
|
||||
" ImageOperands.Lod, 0];" "\n"
|
||||
" =ImageOperands.Lod, 0];" "\n"
|
||||
"float texture(gsamplerCAS sampler, vec4 P, float comp)" "\n"
|
||||
"= " SPV(OpImageSampleDrefExplicitLod) "[sampler, P, comp," "\n"
|
||||
" ImageOperands.Lod, 0];" "\n"
|
||||
" =ImageOperands.Lod, 0];" "\n"
|
||||
"gvec4 textureProj(gsampler sampler, gproj_coord P)" "\n"
|
||||
"= " SPV(OpImageSampleProjExplicitLod) "\n"
|
||||
"[sampler, P, ImageOperands.Lod, 0];" "\n"
|
||||
"[sampler, P, =ImageOperands.Lod, 0];" "\n"
|
||||
"};" "\n"
|
||||
"#undef __sampler" "\n"
|
||||
"#undef _sampler" "\n"
|
||||
|
@ -890,21 +890,21 @@ SRC_LINE
|
|||
" gsamplerCAS=[__sampler(,Cube,,Array,Shadow)]) {" "\n"
|
||||
"gvec4 texture(gsampler sampler, gtex_coord P, float bias)" "\n"
|
||||
"= " SPV(OpImageSampleImplicitLod) "\n"
|
||||
"[sampler, P, ImageOperands.Bias, bias];" "\n"
|
||||
"[sampler, P, =ImageOperands.Bias, bias];" "\n"
|
||||
"gvec4 texture(gsampler sampler, gtex_coord P)" "\n"
|
||||
"= " SPV(OpImageSampleImplicitLod) "[sampler, P];" "\n"
|
||||
"float texture(gsamplerSh sampler, gshadow_coord P, float bias)" "\n"
|
||||
"= " SPV(OpImageSampleDrefImplicitLod) "\n"
|
||||
"[sampler, [gsamplerSh shadow_coord(P)], [gsamplerSh comp(P)]," "\n"
|
||||
" ImageOperands.Bias, bias];" "\n"
|
||||
" =ImageOperands.Bias, bias];" "\n"
|
||||
"float texture(gsamplerSh sampler, gshadow_coord P)" "\n"
|
||||
"= " SPV(OpImageSampleDrefImplicitLod) "\n"
|
||||
"[sampler, [gsamplerSh shadow_coord(P)], [gsamplerSh comp(P)]];" "\n"
|
||||
"[sampler, [gsamplerSh shadow_coord(P)], [gsamplerSh comp(P)]];""\n"
|
||||
"float texture(gsamplerCAS sampler, vec4 P, float comp)" "\n"
|
||||
"= " SPV(OpImageSampleDrefImplicitLod) "[sampler, P, comp];" "\n"
|
||||
"gvec4 textureProj(gsampler sampler, gproj_coord P, float bias)" "\n"
|
||||
"= " SPV(OpImageSampleProjImplicitLod) "\n"
|
||||
"[sampler, P, ImageOperands.Bias, bias];" "\n"
|
||||
"[sampler, P, =ImageOperands.Bias, bias];" "\n"
|
||||
"gvec4 textureProj(gsampler sampler, gproj_coord P)" "\n"
|
||||
"= " SPV(OpImageSampleProjImplicitLod) "[sampler, P];" "\n"
|
||||
"};" "\n"
|
||||
|
@ -933,7 +933,7 @@ SRC_LINE
|
|||
" gsamplerMS=[_sampler(2D,MS,,)," "\n"
|
||||
" _sampler(2D,MS,Array,)]) {" "\n"
|
||||
"gvec4 texelFetch(gsampler sampler, gtex_coord P, int lod)" "\n"
|
||||
"= " SPV(OpImageFetch) "[sampler, P, ImageOperands.Lod, lod];" "\n"
|
||||
"= " SPV(OpImageFetch) "[sampler, P, =ImageOperands.Lod, lod];" "\n"
|
||||
"gvec4B texelFetch(gsamplerB sampler, int P)" "\n"
|
||||
"= " SPV(OpImageFetch) "[sampler, P];" "\n"
|
||||
"gvec4MS texelFetch(gsamplerMS sampler, ivec2 P, int sample)" "\n"
|
||||
|
@ -964,7 +964,7 @@ SRC_LINE
|
|||
" gtextureMS=[_texture(2D,MS,,)," "\n"
|
||||
" _texture(2D,MS,Array,)]) {" "\n"
|
||||
"gvec4 texelFetch(gtexture texture, gtex_coord P, int lod)" "\n"
|
||||
"= " SPV(OpImageFetch) "[texture, P, ImageOperands.Lod, lod];" "\n"
|
||||
"= " SPV(OpImageFetch) "[texture, P, =ImageOperands.Lod, lod];" "\n"
|
||||
"gvec4B texelFetch(gtextureB texture, int P)" "\n"
|
||||
"= " SPV(OpImageFetch) "[texture, P];" "\n"
|
||||
"gvec4MS texelFetch(gtextureMS texture, ivec2 P, int sample)" "\n"
|
||||
|
|
|
@ -2132,6 +2132,7 @@ unary_expr
|
|||
| '~' cast_expr %prec UNARY { $$ = new_unary_expr ('~', $2); }
|
||||
| '&' cast_expr %prec UNARY { $$ = new_unary_expr ('&', $2); }
|
||||
| '*' cast_expr %prec UNARY { $$ = new_unary_expr ('.', $2); }
|
||||
| '=' cast_expr %prec UNARY { $$ = new_unary_expr ('=', $2); }
|
||||
| SIZEOF unary_expr %prec UNARY { $$ = new_unary_expr ('S', $2); }
|
||||
| SIZEOF '(' typename ')' %prec HYPERUNARY
|
||||
{
|
||||
|
|
|
@ -1080,6 +1080,14 @@ spirv_uexpr (const expr_t *e, spirvctx_t *ctx)
|
|||
if (e->expr.op == 'C') {
|
||||
return spirv_cast (e, ctx);
|
||||
}
|
||||
if (e->expr.op == '=') {
|
||||
auto val = e->expr.e1;
|
||||
if (!is_integral_val (val)) {
|
||||
error (val, "not a constant integer");
|
||||
return 0;
|
||||
}
|
||||
return expr_integral (val);
|
||||
}
|
||||
auto op_name = convert_op (e->expr.op);
|
||||
if (!op_name) {
|
||||
if (e->expr.op > 32 && e->expr.op < 127) {
|
||||
|
|
Loading…
Reference in a new issue