nv2a: Merge inc and non-inc method defs

This commit is contained in:
Matt Borgerson 2022-01-11 23:18:46 -07:00 committed by mborgerson
parent a8fadd5a66
commit 909affdefe
3 changed files with 68 additions and 63 deletions

View File

@ -534,7 +534,8 @@ void pgraph_destroy(PGRAPHState *pg);
void pgraph_context_switch(NV2AState *d, unsigned int channel_id);
int pgraph_method(NV2AState *d, unsigned int subchannel, unsigned int method,
uint32_t parameter, uint32_t *parameters,
size_t num_words_available, size_t max_lookahead_words);
size_t num_words_available, size_t max_lookahead_words,
bool inc);
void pgraph_gl_sync(NV2AState *d);
void pgraph_process_pending_reports(NV2AState *d);
void pgraph_process_pending_downloads(NV2AState *d);

View File

@ -169,6 +169,7 @@ static ssize_t pfifo_run_puller(NV2AState *d, uint32_t method_entry,
uint32_t method = method_entry & 0x1FFC;
uint32_t subchannel =
GET_MASK(method_entry, NV_PFIFO_CACHE1_METHOD_SUBCHANNEL);
bool inc = !GET_MASK(method_entry, NV_PFIFO_CACHE1_METHOD_TYPE);
if (method == 0) {
RAMHTEntry entry = ramht_lookup(d, parameter);
@ -191,7 +192,7 @@ static ssize_t pfifo_run_puller(NV2AState *d, uint32_t method_entry,
if (!d->pgraph.waiting_for_context_switch) {
num_proc =
pgraph_method(d, subchannel, 0, entry.instance, parameters,
num_words_available, max_lookahead_words);
num_words_available, max_lookahead_words, inc);
}
}
@ -223,7 +224,7 @@ static ssize_t pfifo_run_puller(NV2AState *d, uint32_t method_entry,
if (pgraph_can_fifo_access(d)) {
num_proc =
pgraph_method(d, subchannel, method, parameter, parameters,
num_words_available, max_lookahead_words);
num_words_available, max_lookahead_words, inc);
}
qemu_mutex_unlock(&d->pgraph.lock);

View File

@ -659,10 +659,10 @@ void pgraph_flush(NV2AState *d)
NV2AState *d, PGRAPHState *pg, \
unsigned int subchannel, unsigned int method, \
uint32_t parameter, uint32_t *parameters, \
size_t num_words_available, size_t *num_words_consumed
size_t num_words_available, size_t *num_words_consumed, bool inc
#define METHOD_HANDLER_ARGS \
d, pg, subchannel, method, parameter, parameters, \
num_words_available, num_words_consumed
num_words_available, num_words_consumed, inc
#define DEF_METHOD_PROTO(gclass, name) \
static void METHOD_FUNC_NAME(gclass, name)(METHOD_HANDLER_ARG_DECL)
@ -736,23 +736,26 @@ static const struct {
#define METHOD_RANGE_END_NAME(gclass, name) \
pgraph_ ## gclass ## _ ## name ## __END
#define DEF_METHOD(gclass, name) /* Drop */
#define DEF_METHOD(gclass, name) \
static const size_t METHOD_RANGE_END_NAME(gclass, name) = \
METHOD_ADDR(gclass, name) + 4;
#define DEF_METHOD_RANGE(gclass, name, range) \
static const size_t METHOD_RANGE_END_NAME(gclass, name) = \
METHOD_ADDR(gclass, name) + range;
#define DEF_METHOD_CASE_4_OFFSET(gclass, name, offset, stride) /* Drop */
#define DEF_METHOD_CASE_4(gclass, name, stride) /* Drop */
#define DEF_METHOD_CASE_4_OFFSET(gclass, name, offset, stride) /* drop */
#define DEF_METHOD_CASE_4(gclass, name, stride) \
static const size_t METHOD_RANGE_END_NAME(gclass, name) = \
METHOD_ADDR(gclass, name) + 4;
#include "pgraph_methods.h"
#undef DEF_METHOD
#undef DEF_METHOD_RANGE
#undef DEF_METHOD_CASE_4_OFFSET
#undef DEF_METHOD_CASE_4
#define DEF_METHOD(gclass, name) DEF_METHOD_PROTO(gclass, name)
static void pgraph_method_inc(MethodFunc handler, uint32_t end,
METHOD_HANDLER_ARG_DECL)
{
assert(inc);
size_t i = 0;
for (; (i < num_words_available) && (method <= end); i++) {
parameter = ldl_le_p(parameters + i);
@ -768,6 +771,7 @@ static void pgraph_method_inc(MethodFunc handler, uint32_t end,
static void pgraph_method_non_inc(MethodFunc handler, METHOD_HANDLER_ARG_DECL)
{
assert(!inc);
for (size_t i = 0; i < num_words_available; i++) {
parameter = ldl_le_p(parameters + i);
if (i) {
@ -779,26 +783,25 @@ static void pgraph_method_non_inc(MethodFunc handler, METHOD_HANDLER_ARG_DECL)
*num_words_consumed = num_words_available;
}
#define METHOD_FUNC_NAME_INT(gclass, name) METHOD_FUNC_NAME(gclass, name##_int)
#define DEF_METHOD_INT(gclass, name) DEF_METHOD(gclass, name##_int)
#define METHOD_FUNC_NAME_INT(gclass, name) METHOD_FUNC_NAME(gclass, name ## _int)
#define DEF_METHOD_INT(gclass, name) DEF_METHOD_PROTO(gclass, name ## _int)
#define DEF_METHOD_INC(gclass, name) \
DEF_METHOD_INT(gclass, name); \
DEF_METHOD(gclass, name) \
{ \
pgraph_method_inc(METHOD_FUNC_NAME_INT(gclass, name), \
METHOD_RANGE_END_NAME(gclass, name), \
METHOD_HANDLER_ARGS); \
} \
DEF_METHOD_INT(gclass, name)
#define DEF_METHOD(gclass, name) \
DEF_METHOD_PROTO(gclass, name)
#define DEF_METHOD_NON_INC(gclass, name) \
DEF_METHOD_INT(gclass, name); \
DEF_METHOD(gclass, name) \
{ \
pgraph_method_non_inc(METHOD_FUNC_NAME_INT(gclass, name), \
METHOD_HANDLER_ARGS); \
} \
#define DEF_METHOD_LOOP(gclass, name) \
DEF_METHOD_INT(gclass, name); \
DEF_METHOD_PROTO(gclass, name) \
{ \
if (inc) { \
pgraph_method_inc(METHOD_FUNC_NAME_INT(gclass, name), \
METHOD_RANGE_END_NAME(gclass, name), \
METHOD_HANDLER_ARGS); \
} else { \
pgraph_method_non_inc(METHOD_FUNC_NAME_INT(gclass, name), \
METHOD_HANDLER_ARGS); \
} \
} \
DEF_METHOD_INT(gclass, name)
// TODO: Optimize. Ideally this should all be done via OpenGL.
@ -949,7 +952,7 @@ static void pgraph_image_blit(NV2AState *d)
int pgraph_method(NV2AState *d, unsigned int subchannel,
unsigned int method, uint32_t parameter,
uint32_t *parameters, size_t num_words_available,
size_t max_lookahead_words)
size_t max_lookahead_words, bool inc)
{
int num_processed = 1;
@ -1092,7 +1095,7 @@ int pgraph_method(NV2AState *d, unsigned int subchannel,
} else {
size_t num_words_consumed = 1;
handler(d, pg, subchannel, method, parameter, parameters,
num_words_available, &num_words_consumed);
num_words_available, &num_words_consumed, inc);
/* Squash repeated BEGIN,DRAW_ARRAYS,END */
#define LAM(i, mthd) ((parameters[i*2+1] & 0x31fff) == (mthd))
@ -1926,7 +1929,7 @@ DEF_METHOD(NV097, SET_POINT_SIZE)
SET_MASK(pg->regs[NV_PGRAPH_POINTSIZE], NV097_SET_POINT_SIZE_V, parameter);
}
DEF_METHOD_INC(NV097, SET_PROJECTION_MATRIX)
DEF_METHOD_LOOP(NV097, SET_PROJECTION_MATRIX)
{
int slot = (method - NV097_SET_PROJECTION_MATRIX) / 4;
// pg->projection_matrix[slot] = *(float*)&parameter;
@ -1935,7 +1938,7 @@ DEF_METHOD_INC(NV097, SET_PROJECTION_MATRIX)
pg->vsh_constants_dirty[row] = true;
}
DEF_METHOD_INC(NV097, SET_MODEL_VIEW_MATRIX)
DEF_METHOD_LOOP(NV097, SET_MODEL_VIEW_MATRIX)
{
int slot = (method - NV097_SET_MODEL_VIEW_MATRIX) / 4;
unsigned int matnum = slot / 16;
@ -1945,7 +1948,7 @@ DEF_METHOD_INC(NV097, SET_MODEL_VIEW_MATRIX)
pg->vsh_constants_dirty[row] = true;
}
DEF_METHOD_INC(NV097, SET_INVERSE_MODEL_VIEW_MATRIX)
DEF_METHOD_LOOP(NV097, SET_INVERSE_MODEL_VIEW_MATRIX)
{
int slot = (method - NV097_SET_INVERSE_MODEL_VIEW_MATRIX) / 4;
unsigned int matnum = slot / 16;
@ -1955,7 +1958,7 @@ DEF_METHOD_INC(NV097, SET_INVERSE_MODEL_VIEW_MATRIX)
pg->vsh_constants_dirty[row] = true;
}
DEF_METHOD_INC(NV097, SET_COMPOSITE_MATRIX)
DEF_METHOD_LOOP(NV097, SET_COMPOSITE_MATRIX)
{
int slot = (method - NV097_SET_COMPOSITE_MATRIX) / 4;
unsigned int row = NV_IGRAPH_XF_XFCTX_CMAT0 + slot/4;
@ -1963,7 +1966,7 @@ DEF_METHOD_INC(NV097, SET_COMPOSITE_MATRIX)
pg->vsh_constants_dirty[row] = true;
}
DEF_METHOD_INC(NV097, SET_TEXTURE_MATRIX)
DEF_METHOD_LOOP(NV097, SET_TEXTURE_MATRIX)
{
int slot = (method - NV097_SET_TEXTURE_MATRIX) / 4;
unsigned int tex = slot / 16;
@ -1973,7 +1976,7 @@ DEF_METHOD_INC(NV097, SET_TEXTURE_MATRIX)
pg->vsh_constants_dirty[row] = true;
}
DEF_METHOD_INC(NV097, SET_FOG_PARAMS)
DEF_METHOD_LOOP(NV097, SET_FOG_PARAMS)
{
int slot = (method - NV097_SET_FOG_PARAMS) / 4;
if (slot < 2) {
@ -1987,7 +1990,7 @@ DEF_METHOD_INC(NV097, SET_FOG_PARAMS)
}
/* Handles NV097_SET_TEXGEN_PLANE_S,T,R,Q */
DEF_METHOD_INC(NV097, SET_TEXGEN_PLANE_S)
DEF_METHOD_LOOP(NV097, SET_TEXGEN_PLANE_S)
{
int slot = (method - NV097_SET_TEXGEN_PLANE_S) / 4;
unsigned int tex = slot / 16;
@ -2003,14 +2006,14 @@ DEF_METHOD(NV097, SET_TEXGEN_VIEW_MODEL)
parameter);
}
DEF_METHOD_INC(NV097, SET_FOG_PLANE)
DEF_METHOD_LOOP(NV097, SET_FOG_PLANE)
{
int slot = (method - NV097_SET_FOG_PLANE) / 4;
pg->vsh_constants[NV_IGRAPH_XF_XFCTX_FOG][slot] = parameter;
pg->vsh_constants_dirty[NV_IGRAPH_XF_XFCTX_FOG] = true;
}
DEF_METHOD_INC(NV097, SET_SCENE_AMBIENT_COLOR)
DEF_METHOD_LOOP(NV097, SET_SCENE_AMBIENT_COLOR)
{
int slot = (method - NV097_SET_SCENE_AMBIENT_COLOR) / 4;
// ??
@ -2018,58 +2021,58 @@ DEF_METHOD_INC(NV097, SET_SCENE_AMBIENT_COLOR)
pg->ltctxa_dirty[NV_IGRAPH_XF_LTCTXA_FR_AMB] = true;
}
DEF_METHOD_INC(NV097, SET_VIEWPORT_OFFSET)
DEF_METHOD_LOOP(NV097, SET_VIEWPORT_OFFSET)
{
int slot = (method - NV097_SET_VIEWPORT_OFFSET) / 4;
pg->vsh_constants[NV_IGRAPH_XF_XFCTX_VPOFF][slot] = parameter;
pg->vsh_constants_dirty[NV_IGRAPH_XF_XFCTX_VPOFF] = true;
}
DEF_METHOD_INC(NV097, SET_POINT_PARAMS)
DEF_METHOD_LOOP(NV097, SET_POINT_PARAMS)
{
int slot = (method - NV097_SET_POINT_PARAMS) / 4;
pg->point_params[slot] = *(float *)&parameter; /* FIXME: Where? */
}
DEF_METHOD_INC(NV097, SET_EYE_POSITION)
DEF_METHOD_LOOP(NV097, SET_EYE_POSITION)
{
int slot = (method - NV097_SET_EYE_POSITION) / 4;
pg->vsh_constants[NV_IGRAPH_XF_XFCTX_EYEP][slot] = parameter;
pg->vsh_constants_dirty[NV_IGRAPH_XF_XFCTX_EYEP] = true;
}
DEF_METHOD_INC(NV097, SET_COMBINER_FACTOR0)
DEF_METHOD_LOOP(NV097, SET_COMBINER_FACTOR0)
{
int slot = (method - NV097_SET_COMBINER_FACTOR0) / 4;
pg->regs[NV_PGRAPH_COMBINEFACTOR0 + slot*4] = parameter;
}
DEF_METHOD_INC(NV097, SET_COMBINER_FACTOR1)
DEF_METHOD_LOOP(NV097, SET_COMBINER_FACTOR1)
{
int slot = (method - NV097_SET_COMBINER_FACTOR1) / 4;
pg->regs[NV_PGRAPH_COMBINEFACTOR1 + slot*4] = parameter;
}
DEF_METHOD_INC(NV097, SET_COMBINER_ALPHA_OCW)
DEF_METHOD_LOOP(NV097, SET_COMBINER_ALPHA_OCW)
{
int slot = (method - NV097_SET_COMBINER_ALPHA_OCW) / 4;
pg->regs[NV_PGRAPH_COMBINEALPHAO0 + slot*4] = parameter;
}
DEF_METHOD_INC(NV097, SET_COMBINER_COLOR_ICW)
DEF_METHOD_LOOP(NV097, SET_COMBINER_COLOR_ICW)
{
int slot = (method - NV097_SET_COMBINER_COLOR_ICW) / 4;
pg->regs[NV_PGRAPH_COMBINECOLORI0 + slot*4] = parameter;
}
DEF_METHOD_INC(NV097, SET_VIEWPORT_SCALE)
DEF_METHOD_LOOP(NV097, SET_VIEWPORT_SCALE)
{
int slot = (method - NV097_SET_VIEWPORT_SCALE) / 4;
pg->vsh_constants[NV_IGRAPH_XF_XFCTX_VPSCL][slot] = parameter;
pg->vsh_constants_dirty[NV_IGRAPH_XF_XFCTX_VPSCL] = true;
}
DEF_METHOD_INC(NV097, SET_TRANSFORM_PROGRAM)
DEF_METHOD_LOOP(NV097, SET_TRANSFORM_PROGRAM)
{
int slot = (method - NV097_SET_TRANSFORM_PROGRAM) / 4;
@ -2086,7 +2089,7 @@ DEF_METHOD_INC(NV097, SET_TRANSFORM_PROGRAM)
}
}
DEF_METHOD_INC(NV097, SET_TRANSFORM_CONSTANT)
DEF_METHOD_LOOP(NV097, SET_TRANSFORM_CONSTANT)
{
int slot = (method - NV097_SET_TRANSFORM_CONSTANT) / 4;
int const_load = GET_MASK(pg->regs[NV_PGRAPH_CHEOPS_OFFSET],
@ -2104,7 +2107,7 @@ DEF_METHOD_INC(NV097, SET_TRANSFORM_CONSTANT)
}
}
DEF_METHOD_INC(NV097, SET_VERTEX3F)
DEF_METHOD_LOOP(NV097, SET_VERTEX3F)
{
int slot = (method - NV097_SET_VERTEX3F) / 4;
VertexAttribute *attribute =
@ -2118,7 +2121,7 @@ DEF_METHOD_INC(NV097, SET_VERTEX3F)
}
/* Handles NV097_SET_BACK_LIGHT_* */
DEF_METHOD_INC(NV097, SET_BACK_LIGHT_AMBIENT_COLOR)
DEF_METHOD_LOOP(NV097, SET_BACK_LIGHT_AMBIENT_COLOR)
{
int slot = (method - NV097_SET_BACK_LIGHT_AMBIENT_COLOR) / 4;
unsigned int part = NV097_SET_BACK_LIGHT_AMBIENT_COLOR / 4 + slot % 16;
@ -2150,7 +2153,7 @@ DEF_METHOD_INC(NV097, SET_BACK_LIGHT_AMBIENT_COLOR)
}
/* Handles all the light source props except for NV097_SET_BACK_LIGHT_* */
DEF_METHOD_INC(NV097, SET_LIGHT_AMBIENT_COLOR)
DEF_METHOD_LOOP(NV097, SET_LIGHT_AMBIENT_COLOR)
{
int slot = (method - NV097_SET_LIGHT_AMBIENT_COLOR) / 4;
unsigned int part = NV097_SET_LIGHT_AMBIENT_COLOR / 4 + slot % 32;
@ -2217,7 +2220,7 @@ DEF_METHOD_INC(NV097, SET_LIGHT_AMBIENT_COLOR)
}
}
DEF_METHOD_INC(NV097, SET_VERTEX4F)
DEF_METHOD_LOOP(NV097, SET_VERTEX4F)
{
int slot = (method - NV097_SET_VERTEX4F) / 4;
VertexAttribute *attribute =
@ -2229,7 +2232,7 @@ DEF_METHOD_INC(NV097, SET_VERTEX4F)
}
}
DEF_METHOD_INC(NV097, SET_VERTEX_DATA_ARRAY_FORMAT)
DEF_METHOD_LOOP(NV097, SET_VERTEX_DATA_ARRAY_FORMAT)
{
int slot = (method - NV097_SET_VERTEX_DATA_ARRAY_FORMAT) / 4;
VertexAttribute *attr = &pg->vertex_attributes[slot];
@ -2296,7 +2299,7 @@ DEF_METHOD_INC(NV097, SET_VERTEX_DATA_ARRAY_FORMAT)
}
}
DEF_METHOD_INC(NV097, SET_VERTEX_DATA_ARRAY_OFFSET)
DEF_METHOD_LOOP(NV097, SET_VERTEX_DATA_ARRAY_OFFSET)
{
int slot = (method - NV097_SET_VERTEX_DATA_ARRAY_OFFSET) / 4;
@ -2892,14 +2895,14 @@ DEF_METHOD(NV097, SET_TEXTURE_SET_BUMP_ENV_OFFSET)
pg->regs[NV_PGRAPH_BUMPOFFSET1 + slot * 4] = parameter;
}
DEF_METHOD_NON_INC(NV097, ARRAY_ELEMENT16)
DEF_METHOD_LOOP(NV097, ARRAY_ELEMENT16)
{
assert(pg->inline_elements_length < NV2A_MAX_BATCH_LENGTH);
pg->inline_elements[pg->inline_elements_length++] = parameter & 0xFFFF;
pg->inline_elements[pg->inline_elements_length++] = parameter >> 16;
}
DEF_METHOD_NON_INC(NV097, ARRAY_ELEMENT32)
DEF_METHOD_LOOP(NV097, ARRAY_ELEMENT32)
{
assert(pg->inline_elements_length < NV2A_MAX_BATCH_LENGTH);
pg->inline_elements[pg->inline_elements_length++] = parameter;
@ -2933,7 +2936,7 @@ DEF_METHOD(NV097, DRAW_ARRAYS)
pg->draw_arrays_prevent_connect = false;
}
DEF_METHOD_NON_INC(NV097, INLINE_ARRAY)
DEF_METHOD_LOOP(NV097, INLINE_ARRAY)
{
assert(pg->inline_array_length < NV2A_MAX_BATCH_LENGTH);
pg->inline_array[pg->inline_array_length++] = parameter;
@ -2945,7 +2948,7 @@ DEF_METHOD(NV097, SET_EYE_VECTOR)
pg->regs[NV_PGRAPH_EYEVEC0 + slot * 4] = parameter;
}
DEF_METHOD_INC(NV097, SET_VERTEX_DATA2F_M)
DEF_METHOD_LOOP(NV097, SET_VERTEX_DATA2F_M)
{
int slot = (method - NV097_SET_VERTEX_DATA2F_M) / 4;
unsigned int part = slot % 2;
@ -2961,7 +2964,7 @@ DEF_METHOD_INC(NV097, SET_VERTEX_DATA2F_M)
}
}
DEF_METHOD_INC(NV097, SET_VERTEX_DATA4F_M)
DEF_METHOD_LOOP(NV097, SET_VERTEX_DATA4F_M)
{
int slot = (method - NV097_SET_VERTEX_DATA4F_M) / 4;
unsigned int part = slot % 4;
@ -2974,7 +2977,7 @@ DEF_METHOD_INC(NV097, SET_VERTEX_DATA4F_M)
}
}
DEF_METHOD_INC(NV097, SET_VERTEX_DATA2S)
DEF_METHOD_LOOP(NV097, SET_VERTEX_DATA2S)
{
int slot = (method - NV097_SET_VERTEX_DATA2S) / 4;
VertexAttribute *attribute = &pg->vertex_attributes[slot];
@ -2988,7 +2991,7 @@ DEF_METHOD_INC(NV097, SET_VERTEX_DATA2S)
}
}
DEF_METHOD_INC(NV097, SET_VERTEX_DATA4UB)
DEF_METHOD_LOOP(NV097, SET_VERTEX_DATA4UB)
{
int slot = (method - NV097_SET_VERTEX_DATA4UB) / 4;
VertexAttribute *attribute = &pg->vertex_attributes[slot];
@ -3002,7 +3005,7 @@ DEF_METHOD_INC(NV097, SET_VERTEX_DATA4UB)
}
}
DEF_METHOD_INC(NV097, SET_VERTEX_DATA4S_M)
DEF_METHOD_LOOP(NV097, SET_VERTEX_DATA4S_M)
{
int slot = (method - NV097_SET_VERTEX_DATA4S_M) / 4;
unsigned int part = slot % 2;