From 629574bdec1eadde5dc228a6f6ec07d8b97b46cd Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 15 Apr 2012 01:08:24 -0400 Subject: [PATCH] Fail if Shader Model 1 pixel shaders don't write to r0. --- mojoshader.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/mojoshader.c b/mojoshader.c index 669395f4..05d785ff 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -563,6 +563,13 @@ static inline const RegisterList *reglist_exists(RegisterList *prev, return (reglist_find(prev, regtype, regnum)); } // reglist_exists +static inline int register_was_written(Context *ctx, const RegisterType rtype, + const int regnum) +{ + RegisterList *reg = reglist_find(&ctx->used_registers, rtype, regnum); + return (reg && reg->written); +} // register_was_written + static inline void set_used_register(Context *ctx, const RegisterType regtype, const int regnum, const int written) { @@ -8477,9 +8484,14 @@ const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile, ctx->current_position = MOJOSHADER_POSITION_AFTER; - // !!! FIXME: for ps_1_*, the output color is written to r0...throw an - // !!! FIXME: error if this register was never written. This isn't - // !!! FIXME: important for vertex shaders, or shader model 2+. + // for ps_1_*, the output color is written to r0...throw an + // error if this register was never written. This isn't + // important for vertex shaders, or shader model 2+. + if (shader_is_pixel(ctx) && !shader_version_atleast(ctx, 2, 0)) + { + if (!register_was_written(ctx, REG_TYPE_TEMP, 0)) + fail(ctx, "r0 (pixel shader 1.x color output) never written to"); + } // if if (!failed) {