Skip to content

Instantly share code, notes, and snippets.

@aras-p
Created July 22, 2014 19:47
Show Gist options
  • Select an option

  • Save aras-p/20831a6fce6afe0be01a to your computer and use it in GitHub Desktop.

Select an option

Save aras-p/20831a6fce6afe0be01a to your computer and use it in GitHub Desktop.
Mojoshader DX bytecode parser fix for SM3.0 vertex textures
# HG changeset patch
# User Aras Pranckevicius <aras@unity3d.com>
# Date 1406058338 -10800
# Tue Jul 22 22:45:38 2014 +0300
# Branch graphics/hlsl-compiler-for-dx9
# Node ID bb1b3cb72364bf306984ae7ace82db713f301f43
# Parent 0d5e0c00b1dd7313f17c2d6698802dfb150a2d85
[shaders] Mojoshader, fixed lack of support for SM3.0 vertex textures.
I've no idea what I'm doing, so just copied code from pixel shader parts.
Makes unity shader compiler tests pass.
diff --git a/External/shaderlab/CGBatch/External/mojoshader/mojoshader.cpp b/External/shaderlab/CGBatch/External/mojoshader/mojoshader.cpp
--- a/External/shaderlab/CGBatch/External/mojoshader/mojoshader.cpp
+++ b/External/shaderlab/CGBatch/External/mojoshader/mojoshader.cpp
@@ -6855,7 +6855,39 @@
ctx->dwords[0] = usage;
ctx->dwords[1] = index;
} // if
- else
+ else if (regtype == REG_TYPE_TEXTURE)
+ {
+ const uint32 usage = (token & 0xF);
+ const uint32 index = ((token >> 16) & 0xF);
+ if (usage == MOJOSHADER_USAGE_TEXCOORD)
+ {
+ if (index > 7)
+ fail(ctx, "DCL texcoord usage must have 0-7 index");
+ } // if
+ else if (usage == MOJOSHADER_USAGE_COLOR)
+ {
+ if (index != 0)
+ fail(ctx, "DCL color usage must have 0 index");
+ } // else if
+ else
+ {
+ fail(ctx, "Invalid DCL texture usage");
+ } // else
+
+ reserved_mask = 0x7FF0FFE0;
+ ctx->dwords[0] = usage;
+ ctx->dwords[1] = index;
+ } // else if
+
+ else if (regtype == REG_TYPE_SAMPLER)
+ {
+ const uint32 ttype = ((token >> 27) & 0xF);
+ if (!valid_texture_type(ttype))
+ fail(ctx, "unknown sampler texture type");
+ reserved_mask = 0x7FFFFFF;
+ ctx->dwords[0] = ttype;
+ } // else if
+ else
{
unsupported = 1;
} // else
@@ -7098,14 +7130,19 @@
else if (shader_is_vertex(ctx))
{
- const MOJOSHADER_usage usage = (const MOJOSHADER_usage) ctx->dwords[0];
- const int index = ctx->dwords[1];
- if (usage >= MOJOSHADER_USAGE_TOTAL)
- {
- fail(ctx, "unknown DCL usage");
- return;
- } // if
- add_attribute_register(ctx, regtype, regnum, usage, index, wmask, mods);
+ if (regtype == REG_TYPE_SAMPLER)
+ add_sampler(ctx, regnum, (TextureType) ctx->dwords[0], 0);
+ else
+ {
+ const MOJOSHADER_usage usage = (const MOJOSHADER_usage) ctx->dwords[0];
+ const int index = ctx->dwords[1];
+ if (usage >= MOJOSHADER_USAGE_TOTAL)
+ {
+ fail(ctx, "unknown DCL usage");
+ return;
+ } // if
+ add_attribute_register(ctx, regtype, regnum, usage, index, wmask, mods);
+ }
} // if
else if (shader_is_pixel(ctx))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment