Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Somehow, I forgot to commit the texture_migrate sources.

  • Loading branch information...
commit 6d8854348876b678be893055811dc2f23fc4ee12 1 parent 3c58a8b
Alex Betts authored

Showing 2 changed files with 127 additions and 0 deletions. Show diff stats Hide diff stats

  1. +105 0 src/library/texture_migrate.cc
  2. +22 0 src/library/texture_migrate.h
105 src/library/texture_migrate.cc
... ... @@ -0,0 +1,105 @@
  1 +// RSXGL - Graphics library for the PS3 GPU.
  2 +//
  3 +// Copyright (c) 2011 Alexander Betts (alex.betts@gmail.com)
  4 +//
  5 +// texture_migrate.cc - manage the texture migration buffer
  6 +
  7 +#include "texture_migrate.h"
  8 +
  9 +#include "rsxgl_config.h"
  10 +#include "debug.h"
  11 +#include "rsxgl_assert.h"
  12 +#include "rsxgl_limits.h"
  13 +
  14 +#include <rsx/gcm_sys.h>
  15 +
  16 +#include <malloc.h>
  17 +
  18 +// Size of migration buffer:
  19 +static uint32_t rsxgl_texture_migrate_size = RSXGL_CONFIG_texture_migrate_buffer_size, rsxgl_texture_migrate_align = RSXGL_TEXTURE_MIGRATE_BUFFER_ALIGN;
  20 +
  21 +//
  22 +static void * _rsxgl_texture_migrate_buffer = 0;
  23 +static uint32_t rsxgl_texture_migrate_buffer_offset = 0;
  24 +static mspace rsxgl_texture_migrate_buffer_space = 0;
  25 +
  26 +static inline
  27 +void * rsxgl_texture_migrate_buffer()
  28 +{
  29 + if(_rsxgl_texture_migrate_buffer == 0) {
  30 + //
  31 +#if ((RSXGL_TEXTURE_MIGRATE_BUFFER_LOCATION) == RSXGL_MEMORY_LOCATION_LOCAL)
  32 + _rsxgl_texture_migrate_buffer = rsxgl_rsx_memalign(rsxgl_texture_migrate_align,rsxgl_texture_migrate_size);
  33 + if(_rsxgl_texture_migrate_buffer == 0) {
  34 + __rsxgl_assert_func(__FILE__,__LINE__,__PRETTY_FUNCTION__,"failed to allocate texture migration buffer in RSX memory");
  35 + }
  36 +
  37 + int32_t s = gcmAddressToOffset(_rsxgl_texture_migrate_buffer,rsxgl_texture_migrate_size,&rsxgl_texture_migrate_buffer_offset);
  38 + if(s != 0) {
  39 + __rsxgl_assert_func(__FILE__,__LINE__,__PRETTY_FUNCTION__,"failed to compute offset for texture migration buffer");
  40 + }
  41 +#elif ((RSXGL_TEXTURE_MIGRATE_BUFFER_LOCATION) == RSXGL_MEMORY_LOCATION_MAIN)
  42 + _rsxgl_texture_migrate_buffer = memalign(rsxgl_texture_migrate_align,rsxgl_texture_migrate_size);
  43 + if(_rsxgl_texture_migrate_buffer == 0) {
  44 + __rsxgl_assert_func(__FILE__,__LINE__,__PRETTY_FUNCTION__,"failed to allocate texture migration buffer in main memory");
  45 + }
  46 +
  47 + int32_t s = gcmMapMainMemory(_rsxgl_texture_migrate_buffer,rsxgl_texture_migrate_size,&rsxgl_texture_migrate_buffer_offset);
  48 + if(s != 0) {
  49 + __rsxgl_assert_func(__FILE__,__LINE__,__PRETTY_FUNCTION__,"failed to map texture migration buffer into RSX memory");
  50 + }
  51 +#else
  52 + rsxgl_assert(0);
  53 +#endif
  54 +
  55 + rsxgl_assert(_rsxgl_texture_migrate_buffer != 0);
  56 +
  57 + rsxgl_texture_migrate_buffer_space = create_mspace_with_base(_rsxgl_texture_migrate_buffer,rsxgl_texture_migrate_size,0);
  58 + }
  59 +
  60 + return _rsxgl_texture_migrate_buffer;
  61 +}
  62 +
  63 +void *
  64 +rsxgl_texture_migrate_memalign(const rsx_size_t align,const rsx_size_t size)
  65 +{
  66 + void * buffer = rsxgl_texture_migrate_buffer();
  67 +
  68 + rsxgl_assert(buffer != 0);
  69 +
  70 + return mspace_memalign(rsxgl_texture_migrate_buffer_space,align,size);
  71 +}
  72 +
  73 +void
  74 +rsxgl_texture_migrate_free(void * ptr)
  75 +{
  76 + rsxgl_assert(_rsxgl_texture_migrate_buffer != 0);
  77 +
  78 + mspace_free(rsxgl_texture_migrate_buffer_space,ptr);
  79 +}
  80 +
  81 +void
  82 +rsxgl_texture_migrate_reset()
  83 +{
  84 +}
  85 +
  86 +void *
  87 +rsxgl_texture_migrate_address(const uint32_t offset)
  88 +{
  89 + rsxgl_assert(_rsxgl_texture_migrate_buffer != 0);
  90 + return (uint8_t *)_rsxgl_texture_migrate_buffer + (ptrdiff_t)(offset - rsxgl_texture_migrate_buffer_offset);
  91 +}
  92 +
  93 +uint32_t
  94 +rsxgl_texture_migrate_offset(const void * ptr)
  95 +{
  96 + rsxgl_assert(_rsxgl_texture_migrate_buffer != 0);
  97 + return rsxgl_texture_migrate_buffer_offset + ((uint8_t *)ptr - (uint8_t *)_rsxgl_texture_migrate_buffer);
  98 +}
  99 +
  100 +void *
  101 +rsxgl_texture_migrate_base()
  102 +{
  103 + rsxgl_assert(_rsxgl_texture_migrate_buffer != 0);
  104 + return (uint8_t *)_rsxgl_texture_migrate_buffer;
  105 +}
22 src/library/texture_migrate.h
... ... @@ -0,0 +1,22 @@
  1 +//-*-C++-*-
  2 +// RSXGL - Graphics library for the PS3 GPU.
  3 +//
  4 +// Copyright (c) 2011 Alexander Betts (alex.betts@gmail.com)
  5 +//
  6 +// texture_migrate.h - Establish memory to migrate texture data with
  7 +
  8 +#ifndef rsxgl_texture_migrate_H
  9 +#define rsxgl_texture_migrate_H
  10 +
  11 +#include <stdint.h>
  12 +
  13 +#include "mem.h"
  14 +
  15 +void * rsxgl_texture_migrate_memalign(const rsx_size_t,const rsx_size_t);
  16 +void rsxgl_texture_migrate_free(void *);
  17 +void rsxgl_texture_migrate_reset();
  18 +void * rsxgl_texture_migrate_address(const uint32_t);
  19 +uint32_t rsxgl_texture_migrate_offset(const void *);
  20 +void * rsxgl_texture_migrate_base();
  21 +
  22 +#endif

0 comments on commit 6d88543

Please sign in to comment.
Something went wrong with that request. Please try again.