diff options
Diffstat (limited to 'r600_batch.c')
-rw-r--r-- | r600_batch.c | 115 |
1 files changed, 51 insertions, 64 deletions
diff --git a/r600_batch.c b/r600_batch.c index 9e87d20..b6432d5 100644 --- a/r600_batch.c +++ b/r600_batch.c @@ -14,8 +14,8 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "radeon.h" #include "radeon_device.h" +#include "r600_atom.h" #include "r600d.h" /* state creation functions prototype */ @@ -224,7 +224,7 @@ int r600_batches_queue(struct radeon_device *rdev, struct drm_r600_batch *batch) fprintf(stderr, "invalid batch\n"); return -EINVAL; } - rbatch->shaders = radeon_bo_open(rdev->radeon->bom, 0, 4096 * 16, 0, RADEON_GEM_DOMAIN_GTT, 0); + rbatch->shaders = radeon_bo_open(rdev->bom, 0, 4096 * 16, 0, RADEON_GEM_DOMAIN_GTT, 0); if (rbatch->shaders == NULL) { free(rbatch); fprintf(stderr, "can't create buffer for shaders\n"); @@ -370,76 +370,63 @@ void r600_atoms_release(struct radeon_device *rdev) /* * r600 atom core functions */ -int r600_atom_create(struct radeon_device *rdev, struct drm_radeon_atom *patom, struct radeon_atom **atomptr) +static struct r600_atom_funcs _r600_atom_funcs[] = { + {0, 0, NULL, NULL}, + {R600_ATOM_CB, sizeof(struct drm_r600_cb), + &r600_cb_create, &r600_cb_emit}, + {R600_ATOM_PA, sizeof(struct drm_r600_pa), + &r600_pa_create, &radeon_atom_emit_default}, + {R600_ATOM_CB_CNTL, sizeof(struct drm_r600_cb_cntl), + &r600_cb_cntl_create, &radeon_atom_emit_default}, + {R600_ATOM_VPORT, sizeof(struct drm_r600_vport), + &r600_vport_create, &radeon_atom_emit_default}, + {R600_ATOM_BLEND, sizeof(struct drm_r600_blend), + &r600_blend_create, &radeon_atom_emit_default}, + {R600_ATOM_CONSTANTS, sizeof(struct drm_r600_constants), + &r600_constants_create, &radeon_atom_emit_default}, + {R600_ATOM_DB, sizeof(struct drm_r600_db), + &r600_db_create, &r600_db_emit}, + {R600_ATOM_DB_CNTL, sizeof(struct drm_r600_db_cntl), + &r600_db_cntl_create, &radeon_atom_emit_default}, + {R600_ATOM_VS_SHADER, sizeof(struct drm_r600_vs_shader), + &r600_vs_shader_create, &r600_vs_shader_emit}, + {R600_ATOM_PS_SHADER, sizeof(struct drm_r600_ps_shader), + &r600_ps_shader_create, &r600_ps_shader_emit}, +}; + + +struct radeon_atom *r600_atom_create(struct radeon_device *rdev, struct drm_radeon_atom *patom) { struct radeon_atom *atom; struct r600_state_container *cont; int r; - *atomptr = NULL; + if (!patom->type || patom->type >= R600_BATCH_NATOMS) { + fprintf(stderr, "%s %d invalid atom type %d\n", __func__, __LINE__); + return NULL; + } + if (_r600_atom_funcs[patom->type].type != patom->type) { + fprintf(stderr, "%s %d mismatch for type %d have %d\n", + __func__, __LINE__, _r600_atom_funcs[patom->type].type, patom->type); + return NULL; + } + cont = patom->data; + radeon_device_set_bo_list(rdev, cont->nbo, cont->bo); + /* create the atom */ atom = malloc(sizeof(struct radeon_atom)); if (atom == NULL) - return -ENOMEM; + return NULL; memset(atom, 0, sizeof(struct radeon_atom)); - cont = patom->data; - patom->id = 0; - radeon_device_set_bo_list(rdev, cont->nbo, cont->bo); + INIT_LIST_HEAD(&atom->list); + kref_init(&atom->kref); + atom->emit = _r600_atom_funcs[patom->type].emit; + atom->nflushes = 0; + atom->id = crc_64(cont->data, _r600_atom_funcs[patom->type].size); atom->type = patom->type; - switch (patom->type) { - case R600_ATOM_CB: - r = r600_cb_create(rdev, atom, cont->data); - if (r) - return r; - break; - case R600_ATOM_CB_CNTL: - r = r600_cb_cntl_create(rdev, atom, cont->data); - if (r) - return r; - break; - case R600_ATOM_PA: - r = r600_pa_create(rdev, atom, cont->data); - if (r) - return r; - break; - case R600_ATOM_VPORT: - r = r600_vport_create(rdev, atom, cont->data); - if (r) - return r; - break; - case R600_ATOM_BLEND: - r = r600_blend_create(rdev, atom, cont->data); - if (r) - return r; - break; - case R600_ATOM_CONSTANTS: - r = r600_constants_create(rdev, atom, cont->data); - if (r) - return r; - break; - case R600_ATOM_DB: - r = r600_db_create(rdev, atom, cont->data); - if (r) - return r; - break; - case R600_ATOM_DB_CNTL: - r = r600_db_cntl_create(rdev, atom, cont->data); - if (r) - return r; - break; - case R600_ATOM_VS_SHADER: - r = r600_vs_shader_create(rdev, atom, cont->data); - if (r) - return r; - break; - case R600_ATOM_PS_SHADER: - r = r600_ps_shader_create(rdev, atom, cont->data); - if (r) - return r; - break; - default: - return -EINVAL; + r = _r600_atom_funcs[patom->type].create(rdev, atom, cont->data); + if (r) { + radeon_atom_put(atom); + return NULL; } - patom->id = atom->id; - *atomptr = atom; - return 0; + return atom; } |