diff --git a/ps3/gcmgl/src/include/rgl-gcm-cmds.h b/ps3/gcmgl/src/include/rgl-gcm-cmds.h index 9bde0d25f1..6659459562 100644 --- a/ps3/gcmgl/src/include/rgl-gcm-cmds.h +++ b/ps3/gcmgl/src/include/rgl-gcm-cmds.h @@ -342,10 +342,10 @@ gcm_emit_at(thisContext->current, 1, ((surface->height - (((surface->height) & 0x1000) >> 12)) | ((origin) << 12) | ((pixelCenter) << 16))); \ gcm_finish_n_commands(thisContext->current, 2); -#define rglGcmSend(dstId, dstOffset, pitch, src, size) \ +#define rglGcmSend(thisContext, dstId, dstOffset, pitch, src, size) \ GLuint id = gmmAlloc(size); \ memcpy( gmmIdToAddress(id), (src), size ); \ - rglGcmTransferData( dstId, dstOffset, size, id, 0, size, size, 1 ); \ + rglGcmTransferData(thisContext, dstId, dstOffset, size, id, 0, size, size, 1 ); \ gmmFree( id ) #define rglGcmSetUpdateFragmentProgramParameter(thisContext, offset, location) \ @@ -361,4 +361,256 @@ gcm_emit_at(thisContext->current, 1, color2); \ gcm_finish_n_commands(thisContext->current, 2); +#define rglGcmSetVertexProgramParameterBlock(thisContext, baseConst, constCount, value) \ +{ \ + uint32_t blockCount, blockRemain, i; \ + blockCount = (constCount * 4) >> 5; \ + blockRemain = (constCount * 4) & 0x1f; \ + for (i=0; i < blockCount; i++) \ + { \ + uint32_t loadAt = baseConst + i * 8; \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_CONSTANT_LOAD, 33); \ + gcm_emit_at(thisContext->current, 1, loadAt); \ + memcpy(&thisContext->current[2], value, 16 * sizeof(float)); \ + memcpy(&thisContext->current[18], &value[16], 16 * sizeof(float)); \ + gcm_finish_n_commands(thisContext->current, 34); \ + value += 32; \ + } \ + if (blockRemain == 0) \ + return; \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_CONSTANT_LOAD, blockRemain + 1); \ + gcm_emit_at(thisContext->current, 1, (baseConst + blockCount * 8)); \ + gcm_finish_n_commands(thisContext->current, 2); \ + blockRemain >>= 2; \ + for (i=0; i < blockRemain; ++i) \ + { \ + memcpy(thisContext->current, value, 4 * sizeof(float)); \ + gcm_finish_n_commands(thisContext->current, 4); \ + value += 4; \ + } \ +} + +#define rglGcmSetInlineTransfer(thisContext, dstOffset, srcAdr, sizeInWords) \ +{ \ + uint32_t *src, *srcEnd, paddedSizeInWords; \ + paddedSizeInWords = (sizeInWords + 1) & ~1; \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3062_SET_OFFSET_DESTIN, 1); \ + gcm_emit_at(thisContext->current, 1, dstOffset & ~63); \ + gcm_finish_n_commands(thisContext->current, 2); \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3062_SET_COLOR_FORMAT, 2); \ + gcm_emit_at(thisContext->current, 1, CELL_GCM_TRANSFER_SURFACE_FORMAT_Y32); \ + gcm_emit_at(thisContext->current, 2, ((0x1000) | ((0x1000) << 16))); \ + gcm_finish_n_commands(thisContext->current, 3); \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV308A_POINT, 3); \ + gcm_emit_at(thisContext->current, 1, (((0) << 16) | ((dstOffset & 63) >> 2))); \ + gcm_emit_at(thisContext->current, 2, (((1) << 16) | (sizeInWords))); \ + gcm_emit_at(thisContext->current, 3, (((1) << 16) | (sizeInWords))); \ + gcm_finish_n_commands(thisContext->current, 4); \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV308A_COLOR, paddedSizeInWords); \ + gcm_finish_n_commands(thisContext->current, 1); \ + src = (uint32_t*)srcAdr; \ + srcEnd = src + sizeInWords; \ + while(src < srcEnd) \ + { \ + gcm_emit_at(thisContext->current, 0, src[0]); \ + gcm_finish_n_commands(thisContext->current, 1); \ + src += 1; \ + } \ + if (paddedSizeInWords != sizeInWords) \ + { \ + gcm_emit_at(thisContext->current, 0, 0); \ + gcm_finish_n_commands(thisContext->current, 1); \ + } \ +} + +#define rglGcmSetFragmentProgramLoad(thisContext, conf, location) \ +{ \ + uint32_t registerCount, texMask, texMask2D, texMaskCentroid, i; \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_SHADER_PROGRAM, 1); \ + gcm_emit_at(thisContext->current, 1, ((location+1) | ((conf->offset) & 0x1fffffff))); \ + gcm_finish_n_commands(thisContext->current, 2); \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_VERTEX_ATTRIB_OUTPUT_MASK, 1); \ + gcm_emit_at(thisContext->current, 1, conf->attributeInputMask); \ + gcm_finish_n_commands(thisContext->current, 2); \ + texMask = conf->texCoordsInputMask; \ + texMask2D = conf->texCoords2D; \ + texMaskCentroid = conf->texCoordsCentroid; \ + for(i = 0; texMask; i++) \ + { \ + if (texMask & 1) \ + { \ + gcm_emit_method_at(thisContext->current, 0, (CELL_GCM_NV4097_SET_TEX_COORD_CONTROL + (i) * 4), 1); \ + gcm_emit_at(thisContext->current, 1, (texMask2D & 1) | ((texMaskCentroid & 1) << 4)); \ + gcm_finish_n_commands(thisContext->current, 2); \ + } \ + texMask >>= 1; \ + texMask2D >>= 1; \ + texMaskCentroid >>= 1; \ + } \ + registerCount = conf->registerCount; \ + if (registerCount < 2) \ + registerCount = 2; \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_SHADER_CONTROL, 1); \ + gcm_emit_at(thisContext->current, 1, conf->fragmentControl | (registerCount << 24)); \ + gcm_finish_n_commands(thisContext->current, 2); \ +} + +#define rglGcmSetDrawArrays(thisContext, mode, first, count) \ +{ \ + if ((mode) == GL_TRIANGLE_STRIP && (first) == 0 && (count) == 4) \ + { \ + gcm_emit_at(thisContext->current, 0, (((3) << (18)) | CELL_GCM_NV4097_INVALIDATE_VERTEX_FILE | (0x40000000))); \ + gcm_emit_at(thisContext->current, 1, 0); \ + gcm_emit_at(thisContext->current, 2, 0); \ + gcm_emit_at(thisContext->current, 3, 0); \ + gcm_finish_n_commands(thisContext->current, 4); \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_BEGIN_END, 1); \ + gcm_emit_at(thisContext->current, 1, (mode)); \ + gcm_finish_n_commands(thisContext->current, 2); \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_DRAW_ARRAYS, 1); \ + gcm_emit_at(thisContext->current, 1, (((first)) | (3 <<24))); \ + gcm_finish_n_commands(thisContext->current, 2); \ + (first) += 4; \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_BEGIN_END, 1); \ + gcm_emit_at(thisContext->current, 1, 0); \ + gcm_finish_n_commands(thisContext->current, 2); \ + } \ + else \ + rglGcmSetDrawArraysSlow(thisContext, (mode), (first), (count)); \ +} + +#define rglGcmSetVertexProgramLoad(thisContext, conf, ucode) \ +{ \ + uint32_t *rawData, instCount, instIndex, loop, rest, i, j; \ + rawData = (uint32_t*)(ucode); \ + instCount = conf->instructionCount; \ + instIndex = conf->instructionSlot; \ + loop = instCount / 8; \ + rest = (instCount % 8) * 4; \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_PROGRAM_LOAD, 2); \ + gcm_emit_at(thisContext->current, 1, instIndex); \ + gcm_emit_at(thisContext->current, 2, instIndex); \ + gcm_finish_n_commands(thisContext->current, 3); \ + for (i = 0; i < loop; i++) \ + { \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_PROGRAM, 32); \ + memcpy(&thisContext->current[1], &rawData[0], sizeof(uint32_t)*16); \ + memcpy(&thisContext->current[17], &rawData[16], sizeof(uint32_t)*16); \ + gcm_finish_n_commands(thisContext->current, (1 + 32)); \ + rawData += 32; \ + } \ + if (rest > 0) \ + { \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_PROGRAM, rest); \ + for (j = 0; j < rest; j++) \ + gcm_emit_at(thisContext->current, j + 1, rawData[j]); \ + gcm_finish_n_commands(thisContext->current, (1 + rest)); \ + } \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_VERTEX_ATTRIB_INPUT_MASK, 1); \ + gcm_emit_at(thisContext->current, 1, conf->attributeInputMask); \ + gcm_finish_n_commands(thisContext->current, 2); \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_TIMEOUT, 1); \ + if (conf->registerCount <= 32) \ + { \ + gcm_emit_at(thisContext->current, 1, ((0xFFFF) | ((32) << 16))); \ + } \ + else \ + { \ + gcm_emit_at(thisContext->current, 1, ((0xFFFF) | ((48) << 16))); \ + } \ + gcm_finish_n_commands(thisContext->current, 2); \ +} + +#define rglGcmFifoGlViewport(data, zNear, zFar) \ +{ \ + GLint clipY0, clipY1, clipX0, clipX1; \ + GLfloat z_scale, z_center; \ + rglGcmViewportState *vp; \ + rglGcmRenderTarget *rt; \ + vp = (rglGcmViewportState*)data; \ + rt = (rglGcmRenderTarget*)&rglGcmState_i.renderTarget; \ + clipX0 = vp->x; \ + clipX1 = vp->x + vp->w; \ + clipY0 = vp->y; \ + clipY1 = vp->y + vp->h; \ + if (rt->yInverted) \ + { \ + clipY0 = rt->gcmRenderTarget.height - (vp->y + vp->h); \ + clipY1 = rt->gcmRenderTarget.height - vp->y; \ + } \ + if (clipX0 < 0) \ + clipX0 = 0; \ + if (clipY0 < 0) \ + clipY0 = 0; \ + if (clipX1 >= CELL_GCM_MAX_RT_DIMENSION) \ + clipX1 = CELL_GCM_MAX_RT_DIMENSION; \ + if (clipY1 >= CELL_GCM_MAX_RT_DIMENSION) \ + clipY1 = CELL_GCM_MAX_RT_DIMENSION; \ + if ((clipX1 <= clipX0) || (clipY1 <= clipY0)) \ + clipX0 = clipY0 = clipX1 = clipY1 = 0; \ + vp->xScale = vp->w * 0.5f; \ + vp->xCenter = (GLfloat)(vp->x + vp->xScale + RGLGCM_SUBPIXEL_ADJUST); \ + vp->yScale = vp->h * 0.5f; \ + vp->yCenter = (GLfloat)(vp->y + vp->yScale + RGLGCM_SUBPIXEL_ADJUST); \ + if (rt->yInverted) \ + { \ + vp->yScale = vp->h * -0.5f; \ + vp->yCenter = (GLfloat)(rt->gcmRenderTarget.height - RGLGCM_VIEWPORT_EPSILON - vp->y + vp->yScale + RGLGCM_SUBPIXEL_ADJUST); \ + } \ + z_scale = (GLfloat)( 0.5f * ( (zFar) - (zNear) ) ); \ + z_center = (GLfloat)( 0.5f * ( (zFar) + (zNear) ) ); \ + float scale[4] = { vp->xScale, vp->yScale, z_scale, 0.0f}; \ + float offset[4] = { vp->xCenter, vp->yCenter, z_center, 0.0f}; \ + rglGcmSetViewport(thisContext, clipX0, clipY0, clipX1 - clipX0, clipY1 - clipY0, (zNear), (zFar), scale, offset ); \ +} + +#define rglGcmTransferData(thisContext, a,b,c,d,e,f,g,h) \ +{ \ + GLuint dstId = a; \ + GLuint dstIdOffset = b; \ + GLint dstPitch = c; \ + GLuint srcId = d; \ + GLuint srcIdOffset = e; \ + GLint srcPitch = f; \ + GLint bytesPerRow = g; \ + GLint rowCount = h; \ + uint32_t colCount, rows, cols; \ + GLuint dstOffset, srcOffset; \ + dstOffset = gmmIdToOffset(dstId) + dstIdOffset; \ + srcOffset = gmmIdToOffset(srcId) + srcIdOffset; \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV0039_SET_CONTEXT_DMA_BUFFER_IN, 2); \ + gcm_emit_at(thisContext->current, 1, CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER); \ + gcm_emit_at(thisContext->current, 2, CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER); \ + gcm_finish_n_commands(thisContext->current, 3); \ + if ((srcPitch == bytesPerRow) && (dstPitch == bytesPerRow)) \ + { \ + bytesPerRow *= rowCount; \ + rowCount = 1; \ + srcPitch = 0; \ + dstPitch = 0; \ + } \ + while(--rowCount >= 0) \ + { \ + for(colCount = bytesPerRow; colCount>0; colCount -= cols) \ + { \ + cols = (colCount > CL0039_MAX_LINES) ? CL0039_MAX_LINES : colCount; \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV0039_OFFSET_IN, 8); \ + gcm_emit_at(thisContext->current, 1, (srcOffset + (bytesPerRow - colCount))); \ + gcm_emit_at(thisContext->current, 2, (dstOffset + (bytesPerRow - colCount))); \ + gcm_emit_at(thisContext->current, 3, 0); \ + gcm_emit_at(thisContext->current, 4, 0); \ + gcm_emit_at(thisContext->current, 5, cols); \ + gcm_emit_at(thisContext->current, 6, 1); \ + gcm_emit_at(thisContext->current, 7, (((1) << 8) | (1))); \ + gcm_emit_at(thisContext->current, 8, 0); \ + gcm_finish_n_commands(thisContext->current, 9); \ + } \ + dstOffset += dstPitch; \ + srcOffset += srcPitch; \ + } \ + gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV0039_OFFSET_OUT, 1); \ + gcm_emit_at(thisContext->current, 1, 0); \ + gcm_finish_n_commands(thisContext->current, 2); \ +} + #endif diff --git a/ps3/gcmgl/src/include/rgl-inline.h b/ps3/gcmgl/src/include/rgl-inline.h index 3c8f7c21a9..bbc20c8fb6 100644 --- a/ps3/gcmgl/src/include/rgl-inline.h +++ b/ps3/gcmgl/src/include/rgl-inline.h @@ -43,87 +43,6 @@ static inline GLuint rglPlatformGetBitsPerPixel (GLenum internalFormat) } } -static inline void rglGcmSetVertexProgramParameterBlock(struct CellGcmContextData *thisContext, - uint32_t baseConst, uint32_t constCount, const float * __restrict value) -{ - uint32_t blockCount, blockRemain, i; - - blockCount = (constCount * 4) >> 5; - blockRemain = (constCount * 4) & 0x1f; - - for (i=0; i < blockCount; i++) - { - uint32_t loadAt = baseConst + i * 8; - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_CONSTANT_LOAD, 33); - gcm_emit_at(thisContext->current, 1, loadAt); - - memcpy(&thisContext->current[2], value, 16 * sizeof(float)); - memcpy(&thisContext->current[18], &value[16], 16 * sizeof(float)); - gcm_finish_n_commands(thisContext->current, 34); - value += 32; - } - - if (blockRemain == 0) - return; - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_CONSTANT_LOAD, blockRemain + 1); - gcm_emit_at(thisContext->current, 1, (baseConst + blockCount * 8)); - gcm_finish_n_commands(thisContext->current, 2); - - blockRemain >>= 2; - - for (i=0; i < blockRemain; ++i) - { - memcpy(thisContext->current, value, 4 * sizeof(float)); - gcm_finish_n_commands(thisContext->current, 4); - value += 4; - } -} - - -static inline void rglGcmSetInlineTransfer(struct CellGcmContextData *thisContext, - const uint32_t dstOffset, const void *srcAdr, const uint32_t sizeInWords) -{ - uint32_t *src, *srcEnd; - uint32_t paddedSizeInWords; - - paddedSizeInWords = (sizeInWords + 1) & ~1; - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3062_SET_OFFSET_DESTIN, 1); - gcm_emit_at(thisContext->current, 1, dstOffset & ~63); - gcm_finish_n_commands(thisContext->current, 2); - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3062_SET_COLOR_FORMAT, 2); - gcm_emit_at(thisContext->current, 1, CELL_GCM_TRANSFER_SURFACE_FORMAT_Y32); - gcm_emit_at(thisContext->current, 2, ((0x1000) | ((0x1000) << 16))); - gcm_finish_n_commands(thisContext->current, 3); - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV308A_POINT, 3); - gcm_emit_at(thisContext->current, 1, (((0) << 16) | ((dstOffset & 63) >> 2))); - gcm_emit_at(thisContext->current, 2, (((1) << 16) | (sizeInWords))); - gcm_emit_at(thisContext->current, 3, (((1) << 16) | (sizeInWords))); - gcm_finish_n_commands(thisContext->current, 4); - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV308A_COLOR, paddedSizeInWords); - gcm_finish_n_commands(thisContext->current, 1); - - src = (uint32_t*)srcAdr; - srcEnd = src + sizeInWords; - - while(src < srcEnd) - { - gcm_emit_at(thisContext->current, 0, src[0]); - gcm_finish_n_commands(thisContext->current, 1); - src += 1; - } - if (paddedSizeInWords != sizeInWords) - { - gcm_emit_at(thisContext->current, 0, 0); - gcm_finish_n_commands(thisContext->current, 1); - } -} - #define rglGcmSwap16Float32(fp, f) \ { \ union SwapF32_16 \ @@ -143,45 +62,6 @@ static inline void rglGcmSetInlineTransfer(struct CellGcmContextData *thisContex rglBuffer->bufferId = GMM_ERROR -static inline void rglGcmSetFragmentProgramLoad(struct CellGcmContextData *thisContext, const CellCgbFragmentProgramConfiguration *conf, const uint32_t location) -{ - uint32_t registerCount, texMask, texMask2D, texMaskCentroid, i; - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_SHADER_PROGRAM, 1); - gcm_emit_at(thisContext->current, 1, ((location+1) | ((conf->offset) & 0x1fffffff))); - gcm_finish_n_commands(thisContext->current, 2); - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_VERTEX_ATTRIB_OUTPUT_MASK, 1); - gcm_emit_at(thisContext->current, 1, conf->attributeInputMask); - gcm_finish_n_commands(thisContext->current, 2); - - texMask = conf->texCoordsInputMask; - texMask2D = conf->texCoords2D; - texMaskCentroid = conf->texCoordsCentroid; - - for(i = 0; texMask; i++) - { - if (texMask & 1) - { - gcm_emit_method_at(thisContext->current, 0, (CELL_GCM_NV4097_SET_TEX_COORD_CONTROL + (i) * 4), 1); - gcm_emit_at(thisContext->current, 1, (texMask2D & 1) | ((texMaskCentroid & 1) << 4)); - gcm_finish_n_commands(thisContext->current, 2); - } - texMask >>= 1; - texMask2D >>= 1; - texMaskCentroid >>= 1; - } - - registerCount = conf->registerCount; - - if (registerCount < 2) - registerCount = 2; - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_SHADER_CONTROL, 1); - gcm_emit_at(thisContext->current, 1, conf->fragmentControl | (registerCount << 24)); - gcm_finish_n_commands(thisContext->current, 2); -} - static void rglGcmSetDrawArraysSlow(struct CellGcmContextData *thisContext, uint8_t mode, uint32_t first, uint32_t count) { @@ -240,150 +120,6 @@ static void rglGcmSetDrawArraysSlow(struct CellGcmContextData *thisContext, uint gcm_finish_n_commands(thisContext->current, 2); } -static inline void rglGcmSetDrawArrays(struct CellGcmContextData *thisContext, uint8_t mode, - uint32_t first, uint32_t count) -{ - if (mode == GL_TRIANGLE_STRIP && first == 0 && count == 4) - { - gcm_emit_at(thisContext->current, 0, (((3) << (18)) | CELL_GCM_NV4097_INVALIDATE_VERTEX_FILE | (0x40000000))); - gcm_emit_at(thisContext->current, 1, 0); - gcm_emit_at(thisContext->current, 2, 0); - gcm_emit_at(thisContext->current, 3, 0); - gcm_finish_n_commands(thisContext->current, 4); - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_BEGIN_END, 1); - gcm_emit_at(thisContext->current, 1, mode); - gcm_finish_n_commands(thisContext->current, 2); - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_DRAW_ARRAYS, 1); - gcm_emit_at(thisContext->current, 1, ((first) | (3 <<24))); - gcm_finish_n_commands(thisContext->current, 2); - first += 4; - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_BEGIN_END, 1); - gcm_emit_at(thisContext->current, 1, 0); - gcm_finish_n_commands(thisContext->current, 2); - } - else - rglGcmSetDrawArraysSlow(thisContext, mode, first, count); -} - -static inline void rglGcmSetVertexProgramLoad(struct CellGcmContextData *thisContext, const CellCgbVertexProgramConfiguration *conf, const void *ucode) -{ - uint32_t *rawData, instCount, instIndex, loop, rest, i, j; - - rawData = (uint32_t*)ucode; - instCount = conf->instructionCount; - instIndex = conf->instructionSlot; - - loop = instCount / 8; - rest = (instCount % 8) * 4; - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_PROGRAM_LOAD, 2); - gcm_emit_at(thisContext->current, 1, instIndex); - gcm_emit_at(thisContext->current, 2, instIndex); - gcm_finish_n_commands(thisContext->current, 3); - - for (i = 0; i < loop; i++) - { - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_PROGRAM, 32); - memcpy(&thisContext->current[1], &rawData[0], sizeof(uint32_t)*16); - memcpy(&thisContext->current[17], &rawData[16], sizeof(uint32_t)*16); - - gcm_finish_n_commands(thisContext->current, (1 + 32)); - rawData += 32; - } - - if (rest > 0) - { - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_PROGRAM, rest); - for (j = 0; j < rest; j++) - gcm_emit_at(thisContext->current, j + 1, rawData[j]); - gcm_finish_n_commands(thisContext->current, (1 + rest)); - } - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_VERTEX_ATTRIB_INPUT_MASK, 1); - gcm_emit_at(thisContext->current, 1, conf->attributeInputMask); - gcm_finish_n_commands(thisContext->current, 2); - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_TIMEOUT, 1); - - if (conf->registerCount <= 32) - gcm_emit_at(thisContext->current, 1, ((0xFFFF) | ((32) << 16))); - else - gcm_emit_at(thisContext->current, 1, ((0xFFFF) | ((48) << 16))); - gcm_finish_n_commands(thisContext->current, 2); -} - -static inline void rglGcmFifoGlViewport(void *data, GLclampf zNear, GLclampf zFar) -{ - GLint clipY0, clipY1, clipX0, clipX1; - GLfloat z_scale, z_center; - rglGcmViewportState *vp; - rglGcmRenderTarget *rt; - CellGcmContextData *thisContext; - - thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - vp = (rglGcmViewportState*)data; - rt = (rglGcmRenderTarget*)&rglGcmState_i.renderTarget; - - clipX0 = vp->x; - clipX1 = vp->x + vp->w; - clipY0 = vp->y; - clipY1 = vp->y + vp->h; - - if (rt->yInverted) - { - clipY0 = rt->gcmRenderTarget.height - (vp->y + vp->h); - clipY1 = rt->gcmRenderTarget.height - vp->y; - } - - if (clipX0 < 0) - clipX0 = 0; - if (clipY0 < 0) - clipY0 = 0; - - if (clipX1 >= CELL_GCM_MAX_RT_DIMENSION) - clipX1 = CELL_GCM_MAX_RT_DIMENSION; - - if (clipY1 >= CELL_GCM_MAX_RT_DIMENSION) - clipY1 = CELL_GCM_MAX_RT_DIMENSION; - - if ((clipX1 <= clipX0) || (clipY1 <= clipY0)) - clipX0 = clipY0 = clipX1 = clipY1 = 0; - - // update viewport info - vp->xScale = vp->w * 0.5f; - vp->xCenter = (GLfloat)(vp->x + vp->xScale + RGLGCM_SUBPIXEL_ADJUST); - vp->yScale = vp->h * 0.5f; - vp->yCenter = (GLfloat)(vp->y + vp->yScale + RGLGCM_SUBPIXEL_ADJUST); - - if (rt->yInverted) - { - vp->yScale = vp->h * -0.5f; - vp->yCenter = (GLfloat)(rt->gcmRenderTarget.height - RGLGCM_VIEWPORT_EPSILON - vp->y + vp->yScale + RGLGCM_SUBPIXEL_ADJUST); - } - - // compute viewport values for hw [no doubles, so we might loose a few lsb] - z_scale = (GLfloat)( 0.5f * ( zFar - zNear ) ); - z_center = (GLfloat)( 0.5f * ( zFar + zNear ) ); - - // hw zNear/zFar clipper - if (zNear > zFar) - { - GLclampf tmp = zNear; - zNear = zFar; - zFar = tmp; - } - - float scale[4] = { vp->xScale, vp->yScale, z_scale, 0.0f}; - float offset[4] = { vp->xCenter, vp->yCenter, z_center, 0.0f}; - - rglGcmSetViewport(thisContext, clipX0, clipY0, clipX1 - clipX0, - clipY1 - clipY0, zNear, zFar, scale, offset ); -} - - static inline void rglGcmSetTransferImage(struct CellGcmContextData *thisContext, uint8_t mode, uint32_t dstOffset, uint32_t dstPitch, uint32_t dstX, uint32_t dstY, uint32_t srcOffset, uint32_t srcPitch, uint32_t srcX, uint32_t srcY, uint32_t width, uint32_t height, uint32_t bytesPerPixel) { uint32_t srcFormat, dstFormat, x, y, finalDstX, finalDstY; @@ -609,63 +345,4 @@ static inline void rglPrintFifoFromGet( unsigned int numWords ) rglPrintIt((( uint32_t* )rglGcmState_i.fifo.lastGetRead )[i] ); } -static inline void rglGcmTransferData -( - GLuint dstId, - GLuint dstIdOffset, - GLint dstPitch, - GLuint srcId, - GLuint srcIdOffset, - GLint srcPitch, - GLint bytesPerRow, - GLint rowCount - ) -{ - uint32_t colCount, rows, cols; - GLuint dstOffset, srcOffset; - struct CellGcmContextData *thisContext = (struct CellGcmContextData*)gCellGcmCurrentContext; - - dstOffset = gmmIdToOffset(dstId) + dstIdOffset; - srcOffset = gmmIdToOffset(srcId) + srcIdOffset; - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV0039_SET_CONTEXT_DMA_BUFFER_IN, 2); - gcm_emit_at(thisContext->current, 1, CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER); - gcm_emit_at(thisContext->current, 2, CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER); - gcm_finish_n_commands(thisContext->current, 3); - - if ((srcPitch == bytesPerRow) && (dstPitch == bytesPerRow)) - { - bytesPerRow *= rowCount; - rowCount = 1; - srcPitch = 0; - dstPitch = 0; - } - - while(--rowCount >= 0) - { - for(colCount = bytesPerRow; colCount>0; colCount -= cols) - { - cols = (colCount > CL0039_MAX_LINES) ? CL0039_MAX_LINES : colCount; - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV0039_OFFSET_IN, 8); - gcm_emit_at(thisContext->current, 1, (srcOffset + (bytesPerRow - colCount))); - gcm_emit_at(thisContext->current, 2, (dstOffset + (bytesPerRow - colCount))); - gcm_emit_at(thisContext->current, 3, 0); - gcm_emit_at(thisContext->current, 4, 0); - gcm_emit_at(thisContext->current, 5, cols); - gcm_emit_at(thisContext->current, 6, 1); - gcm_emit_at(thisContext->current, 7, (((1) << 8) | (1))); - gcm_emit_at(thisContext->current, 8, 0); - gcm_finish_n_commands(thisContext->current, 9); - } - - dstOffset += dstPitch; - srcOffset += srcPitch; - } - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV0039_OFFSET_OUT, 1); - gcm_emit_at(thisContext->current, 1, 0); - gcm_finish_n_commands(thisContext->current, 2); -} - #endif diff --git a/ps3/gcmgl/src/rgl_ps3_cg.cpp b/ps3/gcmgl/src/rgl_ps3_cg.cpp index 54db88ac4f..a6c37f7e09 100644 --- a/ps3/gcmgl/src/rgl_ps3_cg.cpp +++ b/ps3/gcmgl/src/rgl_ps3_cg.cpp @@ -33,6 +33,7 @@ static int rglGcmGenerateProgram (void *data, int profileIndex, const CgProgramH { _CGprogram *program = (_CGprogram*)data; CGprofile profile = ( CGprofile )programHeader->profile; + CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; int need_swapping = 0; @@ -168,7 +169,7 @@ static int rglGcmGenerateProgram (void *data, int profileIndex, const CgProgramH program->loadProgramOffset = 0; } - rglGcmSend( program->loadProgramId, program->loadProgramOffset, 0, ( char* )program->ucode, ucodeSize ); + rglGcmSend(thisContext, program->loadProgramId, program->loadProgramOffset, 0, ( char* )program->ucode, ucodeSize ); } program->programGroup = NULL; diff --git a/ps3/gcmgl/src/rgl_ps3_raster.cpp b/ps3/gcmgl/src/rgl_ps3_raster.cpp index e2ceb8d64d..639e047655 100644 --- a/ps3/gcmgl/src/rgl_ps3_raster.cpp +++ b/ps3/gcmgl/src/rgl_ps3_raster.cpp @@ -533,9 +533,11 @@ void rglCreatePushBuffer(void *data) if ( parameterEntry->flags & CGP_CONTIGUOUS ) { memset( rglGcmCurrent, 0, 4*( 4*registerCount + 3 ) ); - CellGcmContextData gcmContext; + CellGcmContextData gcmContext, *gcmContext_ptr; gcmContext.current = (uint32_t*)rglGcmCurrent; - rglGcmSetVertexProgramParameterBlock(&gcmContext, parameterResource->resource, registerCount, ( float* )rglGcmCurrent ); + float *v = ( float* )rglGcmCurrent; + gcmContext_ptr = &gcmContext; + rglGcmSetVertexProgramParameterBlock(gcmContext_ptr, parameterResource->resource, registerCount, v); rglGcmCurrent = (typeof(rglGcmCurrent))gcmContext.current; rtParameter->pushBufferPointer = rglGcmCurrent - 4 * registerCount; @@ -550,9 +552,11 @@ void rglCreatePushBuffer(void *data) if ( program->resources[resourceIndex] != 0xffff ) { memset( rglGcmCurrent, 0, 4*( 4*registerStride + 3 ) ); - CellGcmContextData gcmContext; + CellGcmContextData gcmContext, *gcmContext_ptr; gcmContext.current = (uint32_t*)rglGcmCurrent; - rglGcmSetVertexProgramParameterBlock(&gcmContext, program->resources[resourceIndex], registerStride, ( float* )rglGcmCurrent ); + gcmContext_ptr = &gcmContext; + float *v= (float*)rglGcmCurrent; + rglGcmSetVertexProgramParameterBlock(gcmContext_ptr, program->resources[resourceIndex], registerStride, v); rglGcmCurrent = (typeof(rglGcmCurrent))gcmContext.current; *( programPushBuffer++ ) = ( unsigned int* )( rglGcmCurrent - 4 * registerStride ); } @@ -801,6 +805,7 @@ void rglPlatformBufferObjectSetData(void *buf_data, GLintptr offset, GLsizeiptr rglBufferObject *bufferObject = (rglBufferObject*)buf_data; rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; rglGcmBufferObject *rglBuffer = ( rglGcmBufferObject * )bufferObject->platformBufferObject; + CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; if ( size == bufferObject->size && tryImmediateCopy ) memcpy( gmmIdToAddress( rglBuffer->bufferId ) + offset, data, size ); @@ -827,7 +832,8 @@ void rglPlatformBufferObjectSetData(void *buf_data, GLintptr offset, GLsizeiptr // STREAM and DYNAMIC buffers get transfer via a bounce buffer. // copy via bounce buffer // try allocating the whole block in the bounce buffer - rglGcmSend( rglBuffer->bufferId, offset, rglBuffer->pitch, ( const char * )data, size ); + const char *dat = (const char*)data; + rglGcmSend(thisContext, rglBuffer->bufferId, offset, rglBuffer->pitch, dat, size ); } } } @@ -944,6 +950,7 @@ static void rglPlatformBufferObjectSetDataTextureReference(void *buf_data, GLint rglBufferObject *bufferObject = (rglBufferObject*)buf_data; rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; rglGcmBufferObject *rglBuffer = ( rglGcmBufferObject * )bufferObject->platformBufferObject; + CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; if ( size >= bufferObject->size ) { @@ -965,7 +972,7 @@ static void rglPlatformBufferObjectSetDataTextureReference(void *buf_data, GLint // copy via bounce buffer GLuint id = gmmAlloc(size); memset(gmmIdToAddress(id), 0, size); - rglGcmTransferData(rglBuffer->bufferId, offset, rglBuffer->pitch, id, 0, size, size, 1); + rglGcmTransferData(thisContext, rglBuffer->bufferId, offset, rglBuffer->pitch, id, 0, size, size, 1); gmmFree(id); } } @@ -1358,7 +1365,7 @@ static void update_state_validation(void) __dcbt(((uint8_t*)program->ucode)+256); __dcbt(((uint8_t*)program->ucode)+384); - CellCgbVertexProgramConfiguration conf; + CellCgbVertexProgramConfiguration conf, *conf_ptr; conf.instructionSlot = program->header.vertexProgram.instructionSlot; conf.instructionCount = program->header.instructionCount; conf.registerCount = program->header.vertexProgram.registerCount; @@ -1373,7 +1380,8 @@ static void update_state_validation(void) if ( fifo->ctx.current + spaceInWords + 1024 > fifo->ctx.end ) rglOutOfSpaceCallback( fifo, spaceInWords ); - rglGcmSetVertexProgramLoad(thisContext, &conf, program->ucode ); + conf_ptr = &conf; + rglGcmSetVertexProgramLoad(thisContext, conf_ptr, program->ucode ); rglGcmSetUserClipPlaneControl(thisContext, 0, 0, 0, 0, 0, 0 ); rglGcmInterpolantState *s = &rglGcmState_i.state.interpolant; @@ -1455,7 +1463,8 @@ static void update_state_validation(void) v2[13] = value[7]; v2[14] = value[11]; v2[15] = value[15]; - rglGcmSetVertexProgramParameterBlock(gCellGcmCurrentContext, parameterResource->resource, 4, v2 ); + const float*v = v2; + rglGcmSetVertexProgramParameterBlock(gCellGcmCurrentContext, parameterResource->resource, 4, v); } break; case CG_FLOAT3x3: @@ -1478,7 +1487,8 @@ static void update_state_validation(void) v2[9] = value[5]; v2[10] = value[8]; v2[11] = 0; - rglGcmSetVertexProgramParameterBlock(gCellGcmCurrentContext, parameterResource->resource, 3, v2 ); + const float*v = v2; + rglGcmSetVertexProgramParameterBlock(gCellGcmCurrentContext, parameterResource->resource, 3, v); } break; } @@ -1520,7 +1530,7 @@ static void update_state_validation(void) _CGprogram *program = LContext->BoundFragmentProgram; // params are set directly in the GPU memory, so there is nothing to be done here. - CellCgbFragmentProgramConfiguration conf; + CellCgbFragmentProgramConfiguration conf, *conf_ptr; conf.offset = gmmIdToOffset(program->loadProgramId) + program->loadProgramOffset; @@ -1545,8 +1555,9 @@ static void update_state_validation(void) conf.fragmentControl &= ~CELL_GCM_MASK_SET_SHADER_CONTROL_CONTROL_TXP; /* TODO - look into this */ conf.fragmentControl |= 0 << CELL_GCM_SHIFT_SET_SHADER_CONTROL_CONTROL_TXP; + conf_ptr = &conf; - rglGcmSetFragmentProgramLoad(thisContext, &conf, CELL_GCM_LOCATION_LOCAL); + rglGcmSetFragmentProgramLoad(thisContext, conf_ptr, CELL_GCM_LOCATION_LOCAL); bool cullNearFarEnable = (program->header.fragmentProgram.flags & CGF_DEPTHREPLACE ) ? false : true; rglGcmSetZMinMaxControl(thisContext, cullNearFarEnable, false, false ); @@ -2081,7 +2092,7 @@ source: RGLGCM_SURFACE_SOURCE_TEXTURE, if (( srcPitch >= 0x10000 ) || ( dstPitch >= 0x10000 ) || bpp_1_transferdata ) { - rglGcmTransferData( dst.dataId, dst.dataIdOffset, dstPitch, + rglGcmTransferData(thisContext, dst.dataId, dst.dataIdOffset, dstPitch, src.dataId, src.dataIdOffset, srcPitch, width * src.bpp, height ); }