Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/asmparser.c | 78 +++++++++++++---------- dlls/d3dcompiler_43/asmshader.y | 8 +-- dlls/d3dcompiler_43/bytecodewriter.c | 19 +++++- dlls/d3dcompiler_43/d3dcompiler_private.h | 5 +- 4 files changed, 67 insertions(+), 43 deletions(-)
diff --git a/dlls/d3dcompiler_43/asmparser.c b/dlls/d3dcompiler_43/asmparser.c index 16e86d94dab..7a901576181 100644 --- a/dlls/d3dcompiler_43/asmparser.c +++ b/dlls/d3dcompiler_43/asmparser.c @@ -125,10 +125,9 @@ static void asmparser_dcl_input(struct asm_parser *This, DWORD usage, DWORD num, struct instruction instr;
if(!This->shader) return; - if(mod != 0 && - (This->shader->version != BWRITERPS_VERSION(3, 0) || - (mod != BWRITERSPDM_MSAMPCENTROID && - mod != BWRITERSPDM_PARTIALPRECISION))) { + if (mod && (This->shader->type != ST_PIXEL || This->shader->major_version != 3 + || (mod != BWRITERSPDM_MSAMPCENTROID && mod != BWRITERSPDM_PARTIALPRECISION))) + { asmparser_message(This, "Line %u: Unsupported modifier in dcl instruction\n", This->line_no); set_parse_status(&This->status, PARSE_ERR); return; @@ -170,10 +169,9 @@ static void asmparser_dcl_sampler(struct asm_parser *This, DWORD samptype, DWORD mod, DWORD regnum, unsigned int line_no) { if(!This->shader) return; - if(mod != 0 && - (This->shader->version != BWRITERPS_VERSION(3, 0) || - (mod != BWRITERSPDM_MSAMPCENTROID && - mod != BWRITERSPDM_PARTIALPRECISION))) { + if (mod && (This->shader->type != ST_PIXEL || This->shader->major_version != 3 + || (mod != BWRITERSPDM_MSAMPCENTROID && mod != BWRITERSPDM_PARTIALPRECISION))) + { asmparser_message(This, "Line %u: Unsupported modifier in dcl instruction\n", This->line_no); set_parse_status(&This->status, PARSE_ERR); return; @@ -503,6 +501,7 @@ static void asmparser_instr(struct asm_parser *This, DWORD opcode, DWORD mod, DW enum bwriter_comparison_type comp, const struct shader_reg *dst, const struct src_regs *srcs, int expectednsrcs) { + struct bwriter_shader *shader = This->shader; struct instruction *instr; unsigned int i; BOOL firstreg = TRUE; @@ -529,8 +528,8 @@ static void asmparser_instr(struct asm_parser *This, DWORD opcode, DWORD mod, DW switch(opcode) { case BWRITERSIO_SINCOS: /* The syntax changes between vs 2 and the other shader versions */ - if(This->shader->version == BWRITERVS_VERSION(2, 0) || - This->shader->version == BWRITERVS_VERSION(2, 1)) { + if (This->shader->type == ST_VERTEX && This->shader->major_version == 2) + { asmparser_sincos(This, mod, shift, dst, srcs); return; } @@ -538,22 +537,20 @@ static void asmparser_instr(struct asm_parser *This, DWORD opcode, DWORD mod, DW break; case BWRITERSIO_TEXCOORD: /* texcoord/texcrd are two instructions present only in PS <= 1.3 and PS 1.4 respectively */ - if(This->shader->version == BWRITERPS_VERSION(1, 4)) + if (shader->type == ST_PIXEL && shader->major_version == 1 && shader->minor_version == 4) asmparser_texcrd(This, mod, shift, dst, srcs); - else asmparser_texcoord(This, mod, shift, dst, srcs); + else + asmparser_texcoord(This, mod, shift, dst, srcs); return; case BWRITERSIO_TEX: /* this encodes both the tex PS 1.x instruction and the texld 1.4/2.0+ instruction */ - if(This->shader->version == BWRITERPS_VERSION(1, 0) || - This->shader->version == BWRITERPS_VERSION(1, 1) || - This->shader->version == BWRITERPS_VERSION(1, 2) || - This->shader->version == BWRITERPS_VERSION(1, 3)) { - asmparser_tex(This, mod, shift, dst); - return; - } - else if(This->shader->version == BWRITERPS_VERSION(1, 4)) { - asmparser_texld14(This, mod, shift, dst, srcs); + if (shader->type == ST_PIXEL && shader->major_version == 1) + { + if (shader->minor_version < 4) + asmparser_tex(This, mod, shift, dst); + else + asmparser_texld14(This, mod, shift, dst, srcs); return; } /* else fallback to the standard behavior */ @@ -1355,7 +1352,8 @@ void create_vs10_parser(struct asm_parser *ret) { }
ret->shader->type = ST_VERTEX; - ret->shader->version = BWRITERVS_VERSION(1, 0); + ret->shader->major_version = 1; + ret->shader->minor_version = 0; ret->funcs = &parser_vs_1; gen_oldvs_output(ret->shader); } @@ -1371,7 +1369,8 @@ void create_vs11_parser(struct asm_parser *ret) { }
ret->shader->type = ST_VERTEX; - ret->shader->version = BWRITERVS_VERSION(1, 1); + ret->shader->major_version = 1; + ret->shader->minor_version = 1; ret->funcs = &parser_vs_1; gen_oldvs_output(ret->shader); } @@ -1387,7 +1386,8 @@ void create_vs20_parser(struct asm_parser *ret) { }
ret->shader->type = ST_VERTEX; - ret->shader->version = BWRITERVS_VERSION(2, 0); + ret->shader->major_version = 2; + ret->shader->minor_version = 0; ret->funcs = &parser_vs_2; gen_oldvs_output(ret->shader); } @@ -1403,7 +1403,8 @@ void create_vs2x_parser(struct asm_parser *ret) { }
ret->shader->type = ST_VERTEX; - ret->shader->version = BWRITERVS_VERSION(2, 1); + ret->shader->major_version = 2; + ret->shader->minor_version = 1; ret->funcs = &parser_vs_2; gen_oldvs_output(ret->shader); } @@ -1419,7 +1420,8 @@ void create_vs30_parser(struct asm_parser *ret) { }
ret->shader->type = ST_VERTEX; - ret->shader->version = BWRITERVS_VERSION(3, 0); + ret->shader->major_version = 3; + ret->shader->minor_version = 0; ret->funcs = &parser_vs_3; }
@@ -1434,7 +1436,8 @@ void create_ps10_parser(struct asm_parser *ret) { }
ret->shader->type = ST_PIXEL; - ret->shader->version = BWRITERPS_VERSION(1, 0); + ret->shader->major_version = 1; + ret->shader->minor_version = 0; ret->funcs = &parser_ps_1_0123; gen_oldps_input(ret->shader, 4); } @@ -1450,7 +1453,8 @@ void create_ps11_parser(struct asm_parser *ret) { }
ret->shader->type = ST_PIXEL; - ret->shader->version = BWRITERPS_VERSION(1, 1); + ret->shader->major_version = 1; + ret->shader->minor_version = 1; ret->funcs = &parser_ps_1_0123; gen_oldps_input(ret->shader, 4); } @@ -1466,7 +1470,8 @@ void create_ps12_parser(struct asm_parser *ret) { }
ret->shader->type = ST_PIXEL; - ret->shader->version = BWRITERPS_VERSION(1, 2); + ret->shader->major_version = 1; + ret->shader->minor_version = 2; ret->funcs = &parser_ps_1_0123; gen_oldps_input(ret->shader, 4); } @@ -1482,7 +1487,8 @@ void create_ps13_parser(struct asm_parser *ret) { }
ret->shader->type = ST_PIXEL; - ret->shader->version = BWRITERPS_VERSION(1, 3); + ret->shader->major_version = 1; + ret->shader->minor_version = 3; ret->funcs = &parser_ps_1_0123; gen_oldps_input(ret->shader, 4); } @@ -1498,7 +1504,8 @@ void create_ps14_parser(struct asm_parser *ret) { }
ret->shader->type = ST_PIXEL; - ret->shader->version = BWRITERPS_VERSION(1, 4); + ret->shader->major_version = 1; + ret->shader->minor_version = 4; ret->funcs = &parser_ps_1_4; gen_oldps_input(ret->shader, 6); } @@ -1514,7 +1521,8 @@ void create_ps20_parser(struct asm_parser *ret) { }
ret->shader->type = ST_PIXEL; - ret->shader->version = BWRITERPS_VERSION(2, 0); + ret->shader->major_version = 2; + ret->shader->minor_version = 0; ret->funcs = &parser_ps_2; gen_oldps_input(ret->shader, 8); } @@ -1530,7 +1538,8 @@ void create_ps2x_parser(struct asm_parser *ret) { }
ret->shader->type = ST_PIXEL; - ret->shader->version = BWRITERPS_VERSION(2, 1); + ret->shader->major_version = 2; + ret->shader->minor_version = 1; ret->funcs = &parser_ps_2_x; gen_oldps_input(ret->shader, 8); } @@ -1546,6 +1555,7 @@ void create_ps30_parser(struct asm_parser *ret) { }
ret->shader->type = ST_PIXEL; - ret->shader->version = BWRITERPS_VERSION(3, 0); + ret->shader->major_version = 3; + ret->shader->minor_version = 0; ret->funcs = &parser_ps_3; } diff --git a/dlls/d3dcompiler_43/asmshader.y b/dlls/d3dcompiler_43/asmshader.y index 1b7a07313fc..9e0fec618cd 100644 --- a/dlls/d3dcompiler_43/asmshader.y +++ b/dlls/d3dcompiler_43/asmshader.y @@ -591,8 +591,8 @@ instruction: INSTR_ADD omods dreg ',' sregs asm_ctx.line_no); set_parse_status(&asm_ctx.status, PARSE_ERR); } - if(asm_ctx.shader->version == BWRITERPS_VERSION(2, 0) || - asm_ctx.shader->version == BWRITERPS_VERSION(2, 1)) { + if (asm_ctx.shader->type == ST_PIXEL && asm_ctx.shader->major_version == 2) + { asmparser_message(&asm_ctx, "Line %u: Declaration not supported in PS 2\n", asm_ctx.line_no); set_parse_status(&asm_ctx.status, PARSE_ERR); @@ -614,8 +614,8 @@ instruction: INSTR_ADD omods dreg ',' sregs asm_ctx.line_no); set_parse_status(&asm_ctx.status, PARSE_ERR); } - if(asm_ctx.shader->version == BWRITERPS_VERSION(2, 0) || - asm_ctx.shader->version == BWRITERPS_VERSION(2, 1)) { + if (asm_ctx.shader->type == ST_PIXEL && asm_ctx.shader->major_version == 2) + { asmparser_message(&asm_ctx, "Line %u: Declaration not supported in PS 2\n", asm_ctx.line_no); set_parse_status(&asm_ctx.status, PARSE_ERR); diff --git a/dlls/d3dcompiler_43/bytecodewriter.c b/dlls/d3dcompiler_43/bytecodewriter.c index 5366fa589b1..8b016cd6201 100644 --- a/dlls/d3dcompiler_43/bytecodewriter.c +++ b/dlls/d3dcompiler_43/bytecodewriter.c @@ -340,6 +340,21 @@ static void put_dword(struct bytecode_buffer *buffer, DWORD value) { }
/* bwriter -> d3d9 conversion functions. */ + +static DWORD sm1_version(const struct bwriter_shader *shader) +{ + switch (shader->type) + { + case ST_VERTEX: + return D3DVS_VERSION(shader->major_version, shader->minor_version); + case ST_PIXEL: + return D3DPS_VERSION(shader->major_version, shader->minor_version); + default: + ERR("Invalid shader type %#x.\n", shader->type); + return 0; + } +} + static DWORD d3d9_swizzle(DWORD bwriter_swizzle) { DWORD ret = 0; @@ -2421,7 +2436,7 @@ HRESULT shader_write_bytecode(const struct bwriter_shader *shader, DWORD **resul ERR("NULL shader structure, aborting\n"); return E_FAIL; } - writer = create_writer(shader->version); + writer = create_writer(sm1_version(shader)); *result = NULL;
if(!writer) { @@ -2439,7 +2454,7 @@ HRESULT shader_write_bytecode(const struct bwriter_shader *shader, DWORD **resul }
/* Write shader type and version */ - put_dword(buffer, shader->version); + put_dword(buffer, sm1_version(shader));
writer->funcs->header(writer, shader, buffer); if(FAILED(writer->state)) { diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index 51cfc395524..9596c2b6b1e 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -35,6 +35,7 @@ #include "d3dcompiler.h"
#include <assert.h> +#include <stdint.h>
/* * This doesn't belong here, but for some functions it is possible to return that value, @@ -118,9 +119,7 @@ struct samplerdecl { #define INSTRARRAY_INITIAL_SIZE 8 struct bwriter_shader { enum shader_type type; - - /* Shader version selected */ - DWORD version; + uint8_t major_version, minor_version;
/* Local constants. Every constant that is not defined below is loaded from * the global constant set at shader runtime