Split GetPointer into two versions, to help with const correctness

This commit is contained in:
Henrik Rydgård
2022-07-24 13:26:19 +02:00
parent d2a3918f5f
commit e6403d7157
43 changed files with 169 additions and 156 deletions
+3 -3
View File
@@ -192,7 +192,7 @@ u32 DrawEngineCommon::NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr,
//
// It does the simplest and safest test possible: If all points of a bbox is outside a single of
// our clipping planes, we reject the box. Tighter bounds would be desirable but would take more calculations.
bool DrawEngineCommon::TestBoundingBox(void* control_points, int vertexCount, u32 vertType, int *bytesRead) {
bool DrawEngineCommon::TestBoundingBox(const void* control_points, int vertexCount, u32 vertType, int *bytesRead) {
SimpleVertex *corners = (SimpleVertex *)(decoded + 65536 * 12);
float *verts = (float *)(decoded + 65536 * 18);
@@ -217,7 +217,7 @@ bool DrawEngineCommon::TestBoundingBox(void* control_points, int vertexCount, u3
// Simplify away bones and morph before proceeding
u8 *temp_buffer = decoded + 65536 * 24;
int vertexSize = 0;
NormalizeVertices((u8 *)corners, temp_buffer, (u8 *)control_points, 0, vertexCount, vertType, &vertexSize);
NormalizeVertices((u8 *)corners, temp_buffer, (const u8 *)control_points, 0, vertexCount, vertType, &vertexSize);
for (int i = 0; i < vertexCount; i++) {
verts[i * 3] = corners[i].pos.x;
verts[i * 3 + 1] = corners[i].pos.y;
@@ -663,7 +663,7 @@ uint64_t DrawEngineCommon::ComputeHash() {
}
// vertTypeID is the vertex type but with the UVGen mode smashed into the top bits.
void DrawEngineCommon::SubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead) {
void DrawEngineCommon::SubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead) {
if (!indexGen.PrimCompatible(prevPrim_, prim) || numDrawCalls >= MAX_DEFERRED_DRAW_CALLS || vertexCountInDrawCalls_ + vertexCount > VERTEX_BUFFER_MAX) {
DispatchFlush();
}
+6 -6
View File
@@ -69,18 +69,18 @@ public:
// This would seem to be unnecessary now, but is still required for splines/beziers to work in the software backend since SubmitPrim
// is different. Should probably refactor that.
// Note that vertTypeID should be computed using GetVertTypeID().
virtual void DispatchSubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead) {
virtual void DispatchSubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead) {
SubmitPrim(verts, inds, prim, vertexCount, vertTypeID, cullMode, bytesRead);
}
virtual void DispatchSubmitImm(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead) {
virtual void DispatchSubmitImm(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead) {
SubmitPrim(verts, inds, prim, vertexCount, vertTypeID, cullMode, bytesRead);
DispatchFlush();
}
bool TestBoundingBox(void* control_points, int vertexCount, u32 vertType, int *bytesRead);
bool TestBoundingBox(const void* control_points, int vertexCount, u32 vertType, int *bytesRead);
void SubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead);
void SubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead);
template<class Surface>
void SubmitCurve(const void *control_points, const void *indices, Surface &surface, u32 vertType, int *bytesRead, const char *scope);
void ClearSplineBezierWeights();
@@ -150,8 +150,8 @@ protected:
// Defer all vertex decoding to a "Flush" (except when software skinning)
struct DeferredDrawCall {
void *verts;
void *inds;
const void *verts;
const void *inds;
u32 vertexCount;
u8 indexType;
s8 prim;
+5 -5
View File
@@ -1694,7 +1694,7 @@ void FramebufferManagerCommon::ApplyClearToMemory(int x1, int y1, int x2, int y2
return;
}
u8 *addr = Memory::GetPointerUnchecked(gstate.getFrameBufAddress());
u8 *addr = Memory::GetPointerWriteUnchecked(gstate.getFrameBufAddress());
const int bpp = gstate_c.framebufFormat == GE_FORMAT_8888 ? 4 : 2;
u32 clearBits = clearColor;
@@ -2033,7 +2033,7 @@ bool FramebufferManagerCommon::GetFramebuffer(u32 fb_address, int fb_stride, GEB
if (!Memory::IsValidAddress(fb_address))
return false;
// If there's no vfb and we're drawing there, must be memory?
buffer = GPUDebugBuffer(Memory::GetPointer(fb_address), fb_stride, 512, format);
buffer = GPUDebugBuffer(Memory::GetPointerWriteUnchecked(fb_address), fb_stride, 512, format);
return true;
}
@@ -2090,7 +2090,7 @@ bool FramebufferManagerCommon::GetDepthbuffer(u32 fb_address, int fb_stride, u32
if (!Memory::IsValidAddress(z_address))
return false;
// If there's no vfb and we're drawing there, must be memory?
buffer = GPUDebugBuffer(Memory::GetPointer(z_address), z_stride, 512, GPU_DBG_FORMAT_16BIT);
buffer = GPUDebugBuffer(Memory::GetPointerWriteUnchecked(z_address), z_stride, 512, GPU_DBG_FORMAT_16BIT);
return true;
}
@@ -2128,7 +2128,7 @@ bool FramebufferManagerCommon::GetStencilbuffer(u32 fb_address, int fb_stride, G
return false;
// If there's no vfb and we're drawing there, must be memory?
// TODO: Actually get the stencil.
buffer = GPUDebugBuffer(Memory::GetPointer(fb_address), fb_stride, 512, GPU_DBG_FORMAT_8888);
buffer = GPUDebugBuffer(Memory::GetPointerWrite(fb_address), fb_stride, 512, GPU_DBG_FORMAT_8888);
return true;
}
@@ -2193,7 +2193,7 @@ void FramebufferManagerCommon::PackFramebufferSync_(VirtualFramebuffer *vfb, int
return;
}
u8 *destPtr = Memory::GetPointer(fb_address + dstByteOffset);
u8 *destPtr = Memory::GetPointerWriteUnchecked(fb_address + dstByteOffset);
// We always need to convert from the framebuffer native format.
// Right now that's always 8888.
+9 -9
View File
@@ -1677,8 +1677,8 @@ void GPUCommon::Execute_Prim(u32 op, u32 diff) {
return;
}
void *verts = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
void *inds = nullptr;
const void *verts = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
const void *inds = nullptr;
u32 vertexType = gstate.vertType;
if ((vertexType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
u32 indexAddr = gstate_c.indexAddr;
@@ -1886,8 +1886,8 @@ void GPUCommon::Execute_Bezier(u32 op, u32 diff) {
return;
}
void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
void *indices = NULL;
const void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
const void *indices = NULL;
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", gstate_c.indexAddr);
@@ -1956,8 +1956,8 @@ void GPUCommon::Execute_Spline(u32 op, u32 diff) {
return;
}
void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
void *indices = NULL;
const void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
const void *indices = NULL;
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", gstate_c.indexAddr);
@@ -2018,7 +2018,7 @@ void GPUCommon::Execute_BoundingBox(u32 op, u32 diff) {
return;
}
if (((count & 7) == 0) && count <= 64) { // Sanity check
void *control_points = Memory::GetPointer(gstate_c.vertexAddr);
const void *control_points = Memory::GetPointer(gstate_c.vertexAddr);
if (!control_points) {
ERROR_LOG_REPORT_ONCE(boundingbox, G3D, "Invalid verts in bounding box check");
currentList->bboxResult = true;
@@ -2795,7 +2795,7 @@ void GPUCommon::DoBlockTransfer(u32 skipDrawReason) {
u32 srcLineStartAddr = srcBasePtr + (srcY * srcStride + srcX) * bpp;
u32 dstLineStartAddr = dstBasePtr + (dstY * dstStride + dstX) * bpp;
const u8 *src = Memory::GetPointerUnchecked(srcLineStartAddr);
u8 *dst = Memory::GetPointerUnchecked(dstLineStartAddr);
u8 *dst = Memory::GetPointerWriteUnchecked(dstLineStartAddr);
memcpy(dst, src, width * height * bpp);
GPURecord::NotifyMemcpy(dstLineStartAddr, srcLineStartAddr, width * height * bpp);
} else {
@@ -2804,7 +2804,7 @@ void GPUCommon::DoBlockTransfer(u32 skipDrawReason) {
u32 dstLineStartAddr = dstBasePtr + ((y + dstY) * dstStride + dstX) * bpp;
const u8 *src = Memory::GetPointerUnchecked(srcLineStartAddr);
u8 *dst = Memory::GetPointerUnchecked(dstLineStartAddr);
u8 *dst = Memory::GetPointerWriteUnchecked(dstLineStartAddr);
memcpy(dst, src, width * bpp);
GPURecord::NotifyMemcpy(dstLineStartAddr, srcLineStartAddr, width * bpp);
}
+1 -1
View File
@@ -1412,7 +1412,7 @@ bool GetCurrentTexture(GPUDebugBuffer &buffer, int level)
Sampler::FetchFunc sampler = Sampler::GetFetchFunc(id);
u8 *texptr = Memory::GetPointer(texaddr);
u8 *texptr = Memory::GetPointerWrite(texaddr);
u32 *row = (u32 *)buffer.GetData();
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {
+1 -1
View File
@@ -40,7 +40,7 @@ struct RasterizerState {
Sampler::NearestFunc nearest;
uint32_t texaddr[8]{};
int texbufw[8]{};
u8 *texptr[8]{};
const u8 *texptr[8]{};
float textureLodSlope;
int screenOffsetX;
int screenOffsetY;
+17 -17
View File
@@ -395,8 +395,8 @@ const SoftwareCommandTableEntry softgpuCommandTable[] = {
SoftGPU::SoftGPU(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
: GPUCommon(gfxCtx, draw)
{
fb.data = Memory::GetPointer(0x44000000); // TODO: correct default address?
depthbuf.data = Memory::GetPointer(0x44000000); // TODO: correct default address?
fb.data = Memory::GetPointerWrite(0x44000000); // TODO: correct default address?
depthbuf.data = Memory::GetPointerWrite(0x44000000); // TODO: correct default address?
memset(softgpuCmdInfo, 0, sizeof(softgpuCmdInfo));
@@ -494,7 +494,7 @@ void SoftGPU::ConvertTextureDescFrom16(Draw::TextureDesc &desc, int srcwidth, in
// TODO: This should probably be converted in a shader instead..
fbTexBuffer_.resize(srcwidth * srcheight);
FormatBuffer displayBuffer;
displayBuffer.data = overrideData ? overrideData : Memory::GetPointer(displayFramebuf_);
displayBuffer.data = overrideData ? overrideData : Memory::GetPointerWrite(displayFramebuf_);
for (int y = 0; y < srcheight; ++y) {
u32 *buf_line = &fbTexBuffer_[y * srcwidth];
const u16 *fb_line = &displayBuffer.as16[y * displayStride_];
@@ -557,7 +557,7 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight) {
bool hasPostShader = presentation_ && presentation_->HasPostShader();
if (PSP_CoreParameter().compat.flags().DarkStalkersPresentHack && displayFormat_ == GE_FORMAT_5551 && g_DarkStalkerStretch != DSStretch::Off) {
u8 *data = Memory::GetPointer(0x04088000);
u8 *data = Memory::GetPointerWrite(0x04088000);
bool fillDesc = true;
if (draw_->GetDataFormatSupport(Draw::DataFormat::A1B5G5R5_UNORM_PACK16) & Draw::FMT_TEXTURE) {
// The perfect one.
@@ -586,13 +586,13 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight) {
hasImage = false;
u1 = 1.0f;
} else if (displayFormat_ == GE_FORMAT_8888) {
u8 *data = Memory::GetPointer(displayFramebuf_);
u8 *data = Memory::GetPointerWrite(displayFramebuf_);
desc.width = displayStride_ == 0 ? srcwidth : displayStride_;
desc.height = srcheight;
desc.initData.push_back(data);
desc.format = Draw::DataFormat::R8G8B8A8_UNORM;
} else if (displayFormat_ == GE_FORMAT_5551) {
u8 *data = Memory::GetPointer(displayFramebuf_);
const u8 *data = Memory::GetPointerWrite(displayFramebuf_);
bool fillDesc = true;
if (draw_->GetDataFormatSupport(Draw::DataFormat::A1B5G5R5_UNORM_PACK16) & Draw::FMT_TEXTURE) {
// The perfect one.
@@ -797,7 +797,7 @@ void SoftGPU::Execute_BlockTransferStart(u32 op, u32 diff) {
u32 dstLineStartAddr = dstBasePtr + (dstY * dstStride + dstX) * bpp;
const u8 *srcp = Memory::GetPointer(srcLineStartAddr);
u8 *dstp = Memory::GetPointer(dstLineStartAddr);
u8 *dstp = Memory::GetPointerWrite(dstLineStartAddr);
memcpy(dstp, srcp, width * height * bpp);
GPURecord::NotifyMemcpy(dstLineStartAddr, srcLineStartAddr, width * height * bpp);
} else {
@@ -806,7 +806,7 @@ void SoftGPU::Execute_BlockTransferStart(u32 op, u32 diff) {
u32 dstLineStartAddr = dstBasePtr + ((y + dstY) * dstStride + dstX) * bpp;
const u8 *srcp = Memory::GetPointer(srcLineStartAddr);
u8 *dstp = Memory::GetPointer(dstLineStartAddr);
u8 *dstp = Memory::GetPointerWrite(dstLineStartAddr);
memcpy(dstp, srcp, width * bpp);
GPURecord::NotifyMemcpy(dstLineStartAddr, srcLineStartAddr, width * bpp);
}
@@ -837,14 +837,14 @@ void SoftGPU::Execute_Prim(u32 op, u32 diff) {
return;
}
void *verts = Memory::GetPointer(gstate_c.vertexAddr);
void *indices = NULL;
const void *verts = Memory::GetPointer(gstate_c.vertexAddr);
const void *indices = NULL;
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
ERROR_LOG_REPORT(G3D, "Software: Bad index address %08x!", gstate_c.indexAddr);
return;
}
indices = Memory::GetPointer(gstate_c.indexAddr);
indices = Memory::GetPointerUnchecked(gstate_c.indexAddr);
}
cyclesExecuted += EstimatePerVertexCost() * count;
@@ -875,8 +875,8 @@ void SoftGPU::Execute_Bezier(u32 op, u32 diff) {
return;
}
void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
void *indices = NULL;
const void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
const void *indices = NULL;
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", gstate_c.indexAddr);
@@ -927,8 +927,8 @@ void SoftGPU::Execute_Spline(u32 op, u32 diff) {
return;
}
void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
void *indices = NULL;
const void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
const void *indices = NULL;
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", gstate_c.indexAddr);
@@ -1002,7 +1002,7 @@ void SoftGPU::Execute_LoadClut(u32 op, u32 diff) {
void SoftGPU::Execute_FramebufPtr(u32 op, u32 diff) {
// We assume fb.data won't change while we're drawing.
drawEngine_->transformUnit.Flush("framebuf");
fb.data = Memory::GetPointer(gstate.getFrameBufAddress());
fb.data = Memory::GetPointerWrite(gstate.getFrameBufAddress());
}
void SoftGPU::Execute_FramebufFormat(u32 op, u32 diff) {
@@ -1013,7 +1013,7 @@ void SoftGPU::Execute_FramebufFormat(u32 op, u32 diff) {
void SoftGPU::Execute_ZbufPtr(u32 op, u32 diff) {
// We assume depthbuf.data won't change while we're drawing.
drawEngine_->transformUnit.Flush("depthbuf");
depthbuf.data = Memory::GetPointer(gstate.getDepthBufAddress());
depthbuf.data = Memory::GetPointerWrite(gstate.getDepthBufAddress());
}
void SoftGPU::Execute_VertexType(u32 op, u32 diff) {
+3 -3
View File
@@ -65,12 +65,12 @@ void SoftwareDrawEngine::DispatchFlush() {
transformUnit.Flush("debug");
}
void SoftwareDrawEngine::DispatchSubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead) {
void SoftwareDrawEngine::DispatchSubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead) {
_assert_msg_(cullMode == gstate.getCullMode(), "Mixed cull mode not supported.");
transformUnit.SubmitPrimitive(verts, inds, prim, vertexCount, vertTypeID, bytesRead, this);
}
void SoftwareDrawEngine::DispatchSubmitImm(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead) {
void SoftwareDrawEngine::DispatchSubmitImm(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead) {
_assert_msg_(cullMode == gstate.getCullMode(), "Mixed cull mode not supported.");
// TODO: For now, just setting all dirty.
transformUnit.SetDirty(SoftDirty(-1));
@@ -449,7 +449,7 @@ enum class CullType {
OFF,
};
void TransformUnit::SubmitPrimitive(void* vertices, void* indices, GEPrimitiveType prim_type, int vertex_count, u32 vertex_type, int *bytesRead, SoftwareDrawEngine *drawEngine)
void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, GEPrimitiveType prim_type, int vertex_count, u32 vertex_type, int *bytesRead, SoftwareDrawEngine *drawEngine)
{
VertexDecoder &vdecoder = *drawEngine->FindVertexDecoder(vertex_type);
const DecVtxFormat &vtxfmt = vdecoder.GetDecVtxFmt();
+3 -3
View File
@@ -118,7 +118,7 @@ public:
}
static ScreenCoords DrawingToScreen(const DrawingCoords &coords, u16 z);
void SubmitPrimitive(void* vertices, void* indices, GEPrimitiveType prim_type, int vertex_count, u32 vertex_type, int *bytesRead, SoftwareDrawEngine *drawEngine);
void SubmitPrimitive(const void* vertices, const void* indices, GEPrimitiveType prim_type, int vertex_count, u32 vertex_type, int *bytesRead, SoftwareDrawEngine *drawEngine);
bool GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices);
@@ -144,8 +144,8 @@ public:
~SoftwareDrawEngine();
void DispatchFlush() override;
void DispatchSubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int cullMode, int *bytesRead) override;
void DispatchSubmitImm(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead) override;
void DispatchSubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int cullMode, int *bytesRead) override;
void DispatchSubmitImm(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead) override;
VertexDecoder *FindVertexDecoder(u32 vtype);