Skip to content

Commit

Permalink
First piece of work on nv3 profile.
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
icculus committed Jul 3, 2008
1 parent 1080fd3 commit 097a5d0
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 38 deletions.
108 changes: 72 additions & 36 deletions mojoshader.c
Expand Up @@ -419,6 +419,7 @@ struct Context
int determined_constants_arrays:1;
int predicated:1;
int support_nv2:1;
int support_nv3:1;
int support_glsl120:1;
int glsl_generated_lit_opcode:1;
};
Expand Down Expand Up @@ -3877,6 +3878,16 @@ static void emit_ARB1_start(Context *ctx, const char *profilestr)
output_line(ctx, "OPTION NV_%s_program2;", shader_full_str);
} // else if

else if (strcmp(profilestr, MOJOSHADER_PROFILE_NV3) == 0)
{
// there's no NV_fragment_program3, so just use 2.
const int ver = shader_is_pixel(ctx) ? 2 : 3;
ctx->support_nv2 = 1;
ctx->support_nv3 = 1;
output_line(ctx, "!!ARB%s1.0", shader_str);
output_line(ctx, "OPTION NV_%s_program%d;", shader_full_str, ver);
} // else if

else
{
failf(ctx, "Profile '%s' unsupported or unknown.", profilestr);
Expand Down Expand Up @@ -4815,7 +4826,66 @@ static void emit_ARB1_DP2ADD(Context *ctx)
EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(DSX)
EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(DSY)
EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXLDD)
EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXLDL)


static void arb1_texld(Context *ctx, const char *opcode)
{
// !!! FIXME: do non-RGBA textures map to same default values as D3D?
const char *dst = make_ARB1_destarg_string(ctx);
const SourceArgInfo *samp_arg = &ctx->source_args[1];
RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER,
samp_arg->regnum);
const char *ttype = NULL;
const char *src0 = make_ARB1_srcarg_string(ctx, 0);
//const char *src1 = get_ARB1_srcarg_varname(ctx, 1); // !!! FIXME: SRC_MOD?

// !!! FIXME: this should be in state_TEXLD, not in the arb1/glsl emitters.
if (sreg == NULL)
{
fail(ctx, "TEXLD using undeclared sampler");
return;
} // if

if (!no_swizzle(samp_arg->swizzle))
{
// !!! FIXME: does this ever actually happen?
fail(ctx, "BUG: can't handle TEXLD with sampler swizzle at the moment");
} // if

switch ((const TextureType) sreg->index)
{
case TEXTURE_TYPE_2D: ttype = "2D"; break; // !!! FIXME: "RECT"?
case TEXTURE_TYPE_CUBE: ttype = "CUBE"; break;
case TEXTURE_TYPE_VOLUME: ttype = "3D"; break;
default: fail(ctx, "unknown texture type"); return;
} // switch

output_line(ctx, "%s%s, %s, texture[%d], %s;", opcode, dst, src0,
samp_arg->regnum, ttype);
} // arb1_texld


static void emit_ARB1_TEXLDL(Context *ctx)
{
if ((shader_is_vertex(ctx)) && (!ctx->support_nv3))
{
failf(ctx, "Vertex shader TEXLDL unsupported in %s profile",
ctx->profile->name);
return;
} // if

else if ((shader_is_pixel(ctx)) && (!ctx->support_nv2))
{
failf(ctx, "Pixel shader TEXLDL unsupported in %s profile",
ctx->profile->name);
return;
} // if

// !!! FIXME: this doesn't map exactly to TEXLDL. Review this.
arb1_texld(ctx, "TXL");
} // emit_ARB1_TEXLDL


EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(BREAKP)
EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(BREAKC)

Expand Down Expand Up @@ -4896,48 +4966,14 @@ EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXCRD)

static void emit_ARB1_TEXLD(Context *ctx)
{
// !!! FIXME: do non-RGBA textures map to same default values as D3D?

if (!shader_version_atleast(ctx, 2, 0))
{
// ps_1_0 and ps_1_4 are both different, too!
fail(ctx, "TEXLD <= Shader Model 2.0 unimplemented."); // !!! FIXME
return;
} // if
else
{
const char *dst = make_ARB1_destarg_string(ctx);
const SourceArgInfo *samp_arg = &ctx->source_args[1];
RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER,
samp_arg->regnum);
const char *ttype = NULL;
const char *src0 = make_ARB1_srcarg_string(ctx, 0);
//const char *src1 = get_ARB1_srcarg_varname(ctx, 1); // !!! FIXME: SRC_MOD?

// !!! FIXME: this should be in state_TEXLD, not in the arb1/glsl emitters.
if (sreg == NULL)
{
fail(ctx, "TEXLD using undeclared sampler");
return;
} // if

if (!no_swizzle(samp_arg->swizzle))
{
// !!! FIXME: does this ever actually happen?
fail(ctx, "BUG: can't handle TEXLD with sampler swizzle at the moment");
} // if

switch ((const TextureType) sreg->index)
{
case TEXTURE_TYPE_2D: ttype = "2D"; break; // !!! FIXME: "RECT"?
case TEXTURE_TYPE_CUBE: ttype = "CUBE"; break;
case TEXTURE_TYPE_VOLUME: ttype = "3D"; break;
default: fail(ctx, "unknown texture type"); return;
} // switch

output_line(ctx, "TEX%s, %s, texture[%d], %s;", dst, src0,
samp_arg->regnum, ttype);
} // else
arb1_texld(ctx, "TEX");
} // emit_ARB1_TEXLD

#endif // SUPPORT_PROFILE_ARB1
Expand Down
2 changes: 1 addition & 1 deletion mojoshader.h
Expand Up @@ -357,7 +357,7 @@ typedef struct
* Profile string for OpenGL ARB 1.0 shaders with Nvidia 3.0 extensions:
* GL_NV_vertex_program3 and GL_NV_fragment_program2
*/
// Not yet. #define MOJOSHADER_PROFILE_NV3 "nv3"
#define MOJOSHADER_PROFILE_NV3 "nv3"

/*
* Profile string for OpenGL ARB 1.0 shaders with Nvidia 4.0 extensions:
Expand Down
15 changes: 14 additions & 1 deletion mojoshader_opengl.c
Expand Up @@ -141,6 +141,7 @@ struct MOJOSHADER_glContext
int have_GL_ARB_fragment_program:1;
int have_GL_NV_vertex_program2_option:1;
int have_GL_NV_fragment_program2:1;
int have_GL_NV_vertex_program3:1;
int have_GL_ARB_shader_objects:1;
int have_GL_ARB_vertex_shader:1;
int have_GL_ARB_fragment_shader:1;
Expand Down Expand Up @@ -694,6 +695,7 @@ static void load_extensions(void *(*lookup)(const char *fnname))
ctx->have_GL_ARB_fragment_program = 1;
ctx->have_GL_NV_vertex_program2_option = 1;
ctx->have_GL_NV_fragment_program2 = 1;
ctx->have_GL_NV_vertex_program3 = 1;
ctx->have_GL_ARB_shader_objects = 1;
ctx->have_GL_ARB_vertex_shader = 1;
ctx->have_GL_ARB_fragment_shader = 1;
Expand Down Expand Up @@ -724,6 +726,7 @@ static void load_extensions(void *(*lookup)(const char *fnname))
VERIFY_EXT(GL_ARB_shading_language_100, 2, 0);
VERIFY_EXT(GL_NV_vertex_program2_option, -1, -1);
VERIFY_EXT(GL_NV_fragment_program2, -1, -1);
VERIFY_EXT(GL_NV_vertex_program3, -1, -1);
VERIFY_EXT(GL_NV_half_float, -1, -1);

#undef VERIFY_EXT
Expand Down Expand Up @@ -758,6 +761,14 @@ static int valid_profile(const char *profile)
MUST_HAVE(MOJOSHADER_PROFILE_NV2, GL_NV_vertex_program2_option);
MUST_HAVE(MOJOSHADER_PROFILE_NV2, GL_NV_fragment_program2);
} // else if

else if (strcmp(profile, MOJOSHADER_PROFILE_NV3) == 0)
{
MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_ARB_vertex_program);
MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_ARB_fragment_program);
MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_NV_vertex_program3);
MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_NV_fragment_program2);
} // else if
#endif

#if SUPPORT_PROFILE_GLSL
Expand Down Expand Up @@ -808,6 +819,7 @@ const char *MOJOSHADER_glBestProfile(void *(*lookup)(const char *fnname))
static const char *priority[] = {
MOJOSHADER_PROFILE_GLSL120,
MOJOSHADER_PROFILE_GLSL,
MOJOSHADER_PROFILE_NV3,
MOJOSHADER_PROFILE_NV2,
MOJOSHADER_PROFILE_ARB1,
};
Expand Down Expand Up @@ -889,7 +901,8 @@ MOJOSHADER_glContext *MOJOSHADER_glCreateContext(const char *profile,

#if SUPPORT_PROFILE_ARB1
else if ( (strcmp(profile, MOJOSHADER_PROFILE_ARB1) == 0) ||
(strcmp(profile, MOJOSHADER_PROFILE_NV2) == 0) )
(strcmp(profile, MOJOSHADER_PROFILE_NV2) == 0) ||
(strcmp(profile, MOJOSHADER_PROFILE_NV3) == 0) )
{
ctx->profileMaxUniforms = impl_ARB1_MaxUniforms;
ctx->profileCompileShader = impl_ARB1_CompileShader;
Expand Down

0 comments on commit 097a5d0

Please sign in to comment.