<commit_before>#include "xorg_exa_tgsi.h"

/*### stupidity defined in X11/extensions/XI.h */
#undef Absolute

#include "pipe/p_format.h"
#include "pipe/p_context.h"
#include "pipe/p_state.h"
#include "pipe/p_inlines.h"
#include "pipe/p_shader_tokens.h"

#include "util/u_memory.h"
#include "util/u_simple_shaders.h"

#include "tgsi/tgsi_ureg.h"

#include "cso_cache/cso_context.h"
#include "cso_cache/cso_hash.h"

struct xorg_shaders {
   struct exa_context *exa;

   struct cso_hash *vs_hash;
   struct cso_hash *fs_hash;
};

/* SAMP[0]  = dst
 * SAMP[1]  = src
 * SAMP[2]  = mask
 * IN[0]    = pos dst
 * IN[1]    = pos src
 * IN[2]    = pos mask
 * CONST[0] = (0, 0, 0, 1)
 */

static const char over_op[] =
   "SUB TEMP[3], CONST[0].wwww, TEMP[1].wwww\n"
   "MUL TEMP[3], TEMP[0], TEMP[3]\n"
   "ADD TEMP[0], TEMP[3], TEMP[0]\n";


static INLINE void
create_preamble(struct ureg_program *ureg)
{
}


static INLINE void
src_in_mask(struct ureg_program *ureg,
            struct ureg_dst dst,
            struct ureg_src src,
            struct ureg_src mask)
{
   /* MUL dst, src, mask.wwww */
   ureg_MUL(ureg, dst, src,
            ureg_scalar(mask, TGSI_SWIZZLE_W));
}

static void *
create_vs(struct pipe_context *ctx,
          unsigned vs_traits)
{
   return NULL;
}

static void *
create_fs(struct pipe_context *ctx,
          unsigned vs_traits)
{
   return NULL;
}

static struct xorg_shader
xorg_shader_construct(struct exa_context *exa,
                      int op,
                      PicturePtr src_picture,
                      PicturePtr mask_picture,
                      PicturePtr dst_picture)
{
   struct xorg_shader shader = {0};
#if 0
   struct ureg_program *ureg;
   struct ureg_src dst_sampler, src_sampler, mask_sampler;
   struct ureg_src dst_pos, src_pos, mask_pos;
   struct ureg_src src, mask;

   ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT);
   if (ureg == NULL)
      return shader;

   if (sid.is_fill)
      return shader;

#if 0  /* unused right now */
   dst_sampler = ureg_DECL_sampler(ureg);
   dst_pos = ureg_DECL_fs_input(ureg,
                                TGSI_SEMANTIC_POSITION,
                                0,
                                TGSI_INTERPOLATE_PERSPECTIVE);
#endif

   src_sampler = ureg_DECL_sampler(ureg);
   src_pos = ureg_DECL_fs_input(ureg,
                                TGSI_SEMANTIC_POSITION,
                                1,
                                TGSI_INTERPOLATE_PERSPECTIVE);

   if (sid.mask) {
      mask_sampler = ureg_DECL_sampler(ureg);
      src_pos = ureg_DECL_fs_input(ureg,
                                   TGSI_SEMANTIC_POSITION,
                                   2,
                                   TGSI_INTERPOLATE_PERSPECTIVE);
   }

   ureg_TEX(ureg, ureg_dst(src),
            TGSI_TEXTURE_2D, src_pos, src_sampler);

   if (sid.mask) {
      ureg_TEX(ureg, ureg_dst(mask),
               TGSI_TEXTURE_2D, mask_pos, mask_sampler);
      /* src IN mask */
      src_in_mask(ureg, ureg_dst(src), src, mask);
   }

   ureg_END(ureg);

#endif
   return shader;
}

struct xorg_shaders * xorg_shaders_create(struct exa_context *exa)
{
   struct xorg_shaders *sc = CALLOC_STRUCT(xorg_shaders);

   sc->exa = exa;
   sc->vs_hash = cso_hash_create();
   sc->fs_hash = cso_hash_create();

   return sc;
}

static void
cache_destroy(struct cso_context *cso,
              struct cso_hash *hash,
              unsigned processor)
{
   struct cso_hash_iter iter = cso_hash_first_node(hash);
   while (!cso_hash_iter_is_null(iter)) {
      void *shader = (void *)cso_hash_iter_data(iter);
      if (processor == PIPE_SHADER_FRAGMENT) {
         cso_delete_fragment_shader(cso, shader);
      } else if (processor == PIPE_SHADER_VERTEX) {
         cso_delete_vertex_shader(cso, shader);<commit_msg>st/xorg: create basic fragment shader<commit_after>#include "xorg_exa_tgsi.h"

/*### stupidity defined in X11/extensions/XI.h */
#undef Absolute

#include "pipe/p_format.h"
#include "pipe/p_context.h"
#include "pipe/p_state.h"
#include "pipe/p_inlines.h"
#include "pipe/p_shader_tokens.h"

#include "util/u_memory.h"
#include "util/u_simple_shaders.h"

#include "tgsi/tgsi_ureg.h"

#include "cso_cache/cso_context.h"
#include "cso_cache/cso_hash.h"

struct xorg_shaders {
   struct exa_context *exa;

   struct cso_hash *vs_hash;
   struct cso_hash *fs_hash;
};

/* SAMP[0]  = dst
 * SAMP[1]  = src
 * SAMP[2]  = mask
 * IN[0]    = pos dst
 * IN[1]    = pos src
 * IN[2]    = pos mask
 * CONST[0] = (0, 0, 0, 1)
 */

static const char over_op[] =
   "SUB TEMP[3], CONST[0].wwww, TEMP[1].wwww\n"
   "MUL TEMP[3], TEMP[0], TEMP[3]\n"
   "ADD TEMP[0], TEMP[3], TEMP[0]\n";


static INLINE void
create_preamble(struct ureg_program *ureg)
{
}


static INLINE void
src_in_mask(struct ureg_program *ureg,
            struct ureg_dst dst,
            struct ureg_src src,
            struct ureg_src mask)
{
   /* MUL dst, src, mask.wwww */
   ureg_MUL(ureg, dst, src,
            ureg_scalar(mask, TGSI_SWIZZLE_W));
}

static void *
create_vs(struct pipe_context *ctx,
          unsigned vs_traits)
{
   return NULL;
}

static void *
create_fs(struct pipe_context *pipe,
          unsigned fs_traits)
{
   struct ureg_program *ureg;
   struct ureg_src dst_sampler, src_sampler, mask_sampler;
   struct ureg_src dst_pos, src_pos, mask_pos;
   struct ureg_src src, mask;

   ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT);
   if (ureg == NULL)
      return 0;

#if 0  /* unused right now */
   dst_sampler = ureg_DECL_sampler(ureg);
   dst_pos = ureg_DECL_fs_input(ureg,
                                TGSI_SEMANTIC_POSITION,
                                0,
                                TGSI_INTERPOLATE_PERSPECTIVE);
#endif

   src_sampler = ureg_DECL_sampler(ureg);
   src_pos = ureg_DECL_fs_input(ureg,
                                TGSI_SEMANTIC_POSITION,
                                1,
                                TGSI_INTERPOLATE_PERSPECTIVE);

   if ((fs_traits & FS_MASK)) {
      mask_sampler = ureg_DECL_sampler(ureg);
      mask_pos = ureg_DECL_fs_input(ureg,
                                    TGSI_SEMANTIC_POSITION,
                                    2,
                                    TGSI_INTERPOLATE_PERSPECTIVE);
   }

   ureg_TEX(ureg, ureg_dst(src),
            TGSI_TEXTURE_2D, src_pos, src_sampler);

   if ((fs_traits & FS_MASK)) {
      ureg_TEX(ureg, ureg_dst(mask),
               TGSI_TEXTURE_2D, mask_pos, mask_sampler);
      /* src IN mask */
      src_in_mask(ureg, ureg_dst(src), src, mask);
   }

   ureg_END(ureg);

   return ureg_create_shader_and_destroy(ureg, pipe);
}

struct xorg_shaders * xorg_shaders_create(struct exa_context *exa)
{
   struct xorg_shaders *sc = CALLOC_STRUCT(xorg_shaders);

   sc->exa = exa;
   sc->vs_hash = cso_hash_create();
   sc->fs_hash = cso_hash_create();

   return sc;
}

static void
cache_destroy(struct cso_context *cso,
              struct cso_hash *hash,
              unsigned processor)
{
   struct cso_hash_iter iter = cso_hash_first_node(hash);
   while (!cso_hash_iter_is_null(iter)) {
      void *shader = (void *)cso_hash_iter_data(iter);
      if (processor == PIPE_SHADER_FRAGMENT) {
         cso_delete_fragment_shader(cso, shader);
      } else if (processor == PIPE_SHADER_VERTEX) {
         cso_delete_vertex_shader(cso, shader);
{'fraction_non_alphanumeric': 0.10496860496860497, 'fraction_numerical': 0.008053508053508053, 'mean_word_length': 2.443139097744361, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6880916', 'n_tokens_mistral': 2832, 'n_tokens_neox': 2748, 'n_words': 521}