/** * Translate TGSI shader into an svga shader variant. */ static enum pipe_error compile_fs(struct svga_context *svga, struct svga_fragment_shader *fs, const struct svga_fs_compile_key *key, struct svga_shader_variant **out_variant) { struct svga_shader_variant *variant; enum pipe_error ret = PIPE_ERROR; variant = svga_translate_fragment_program( fs, key ); if (variant == NULL) { debug_printf("Failed to compile fragment shader," " using dummy shader instead.\n"); variant = get_compiled_dummy_shader(fs, key); if (!variant) { ret = PIPE_ERROR; goto fail; } } if (variant->nr_tokens * sizeof(variant->tokens[0]) + sizeof(SVGA3dCmdDefineShader) + sizeof(SVGA3dCmdHeader) >= SVGA_CB_MAX_COMMAND_SIZE) { /* too big, use dummy shader */ debug_printf("Shader too large (%lu bytes)," " using dummy shader instead.\n", (unsigned long ) variant->nr_tokens * sizeof(variant->tokens[0])); variant = get_compiled_dummy_shader(fs, key); if (!variant) { ret = PIPE_ERROR; goto fail; } } ret = svga_define_shader(svga, SVGA3D_SHADERTYPE_PS, variant); if (ret != PIPE_OK) goto fail; *out_variant = variant; /* insert variants at head of linked list */ variant->next = fs->base.variants; fs->base.variants = variant; return PIPE_OK; fail: if (variant) { svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_PS, variant); } return ret; }
/** * Translate TGSI shader into an svga shader variant. */ static enum pipe_error compile_fs(struct svga_context *svga, struct svga_fragment_shader *fs, const struct svga_compile_key *key, struct svga_shader_variant **out_variant) { struct svga_shader_variant *variant; enum pipe_error ret = PIPE_ERROR; variant = translate_fragment_program(svga, fs, key); if (variant == NULL) { debug_printf("Failed to compile fragment shader," " using dummy shader instead.\n"); variant = get_compiled_dummy_shader(svga, fs, key); } else if (svga_shader_too_large(svga, variant)) { /* too big, use dummy shader */ debug_printf("Shader too large (%u bytes)," " using dummy shader instead.\n", (unsigned) (variant->nr_tokens * sizeof(variant->tokens[0]))); /* Free the too-large variant */ svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_PS, variant); /* Use simple pass-through shader instead */ variant = get_compiled_dummy_shader(svga, fs, key); } if (!variant) { return PIPE_ERROR; } ret = svga_define_shader(svga, SVGA3D_SHADERTYPE_PS, variant); if (ret != PIPE_OK) { svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_PS, variant); return ret; } *out_variant = variant; /* insert variant at head of linked list */ variant->next = fs->base.variants; fs->base.variants = variant; return PIPE_OK; }