Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
Fixed read/write trace out of bounds
Fixed vmem stride direction
Added repoint command
  • Loading branch information
kittybupu committed Aug 19, 2022
1 parent a0bd472 commit f0c1e7a
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 19 deletions.
1 change: 1 addition & 0 deletions openVCB.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Code for mostly misc stuff.

#include "openVCB.h"

Expand Down
16 changes: 11 additions & 5 deletions openVCB.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#pragma once
/*
* This is the primary header ifle for openVCB
*/


#include <glm/glm.hpp>
#include <string>
#include <vector>
Expand All @@ -11,23 +16,24 @@
#endif

/// <summary>
/// TODO:
/// Try sorting by component as well.
/// I see it going both ways
///
/// Primary namespace for openVCB
/// </summary>

namespace openVCB {
struct LatchInterface {
glm::ivec2 pos;
glm::ivec2 stride;
glm::ivec2 size;
int numBits;
int gids[64];
};

/// <summary>
/// 8 bit state.
/// 7 bit type + 1 active bit
///
/// Add potential ink types here.
/// It is VERY important to keep components in pairs for on and off to
/// to make sure the values are aligned correctly.
/// </summary>
enum class Ink {
None = 0,
Expand Down
2 changes: 2 additions & 0 deletions openVCBExpr.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Code for instruction expression parsing.

#include "openVCBExpr.h"

#include <iostream>
Expand Down
4 changes: 4 additions & 0 deletions openVCBExpr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#pragma once
/*
* Instruction expression parsing code.
*/

#include <unordered_map>
#include <string>

Expand Down
9 changes: 5 additions & 4 deletions openVCBPreprocessing.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Code for image proprocessing and graph generation

#include "openVCB.h"
#include <unordered_set>
Expand Down Expand Up @@ -150,8 +151,8 @@ namespace openVCB {

for (int k = 0; k < 4; k++) {
ivec2 np = p + fourNeighbors[k];
if (np.x < 0 || np.x > width ||
np.y < 0 || np.y > height) continue;
if (np.x < 0 || np.x >= width ||
np.y < 0 || np.y >= height) continue;

const int dstGID = indexImage[np.x + np.y * width];
if (srcGID != dstGID && dstGID != -1 && conSet.insert(((long long)srcGID << 32) | dstGID).second)
Expand All @@ -168,8 +169,8 @@ namespace openVCB {

for (int k = 0; k < 4; k++) {
ivec2 np = p + fourNeighbors[k];
if (np.x < 0 || np.x > width ||
np.y < 0 || np.y > height) continue;
if (np.x < 0 || np.x >= width ||
np.y < 0 || np.y >= height) continue;

const int srcGID = indexImage[np.x + np.y * width];
if (srcGID != dstGID && srcGID != -1 && conSet.insert(((long long)srcGID << 32) | dstGID).second)
Expand Down
40 changes: 38 additions & 2 deletions openVCBReader.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Code for file reading

#include "openVCB.h"

Expand Down Expand Up @@ -225,6 +226,8 @@ namespace openVCB {
int vmemArr[14];
{
auto dat = split(godotObj, " ]", pos);
printf("%s dat", dat.c_str());

std::stringstream s(dat);
std::string val;
for (size_t i = 0; i < 14; i++) {
Expand All @@ -242,14 +245,18 @@ namespace openVCB {
vmAddr.numBits = std::max(0, std::min(vmemArr[0], 32));
vmAddr.pos.x = vmemArr[1];
vmAddr.pos.y = vmemArr[2];
vmAddr.stride.x = vmemArr[3];
vmAddr.stride.x = -vmemArr[3];
vmAddr.stride.y = vmemArr[4];
vmAddr.size.x = vmemArr[5];
vmAddr.size.y = vmemArr[6];

vmData.numBits = std::max(0, std::min(vmemArr[7], 32));
vmData.pos.x = vmemArr[8];
vmData.pos.y = vmemArr[9];
vmData.stride.x = vmemArr[10];
vmData.stride.x = -vmemArr[10];
vmData.stride.y = vmemArr[11];
vmData.size.x = vmemArr[12];
vmData.size.y = vmemArr[13];

if (vmemFlag) {
vmemSize = 1ull << vmAddr.numBits;
Expand All @@ -275,6 +282,35 @@ namespace openVCB {
for (int i = 0; i < imSize / 4; i++)
image[i] = color2ink(((int*)originalImage)[i]);

// Overwrite latch locations for vmem
if (vmemFlag) {
for (int i = 0; i < vmAddr.numBits; i++) {
auto start = vmAddr.pos + i * vmAddr.stride;
auto end = start + vmAddr.size;
for (auto pos = start; pos.x < end.x; pos.x++) {
for (pos.y = start.y; pos.y < end.y; pos.y++) {
if (pos.x < 0 || pos.x >= width ||
pos.y < 0 || pos.y >= height)
continue;
image[pos.x + pos.y * width] = Ink::LatchOff;
}
}
}

for (int i = 0; i < vmData.numBits; i++) {
auto start = vmData.pos + i * vmData.stride;
auto end = start + vmData.size;
for (auto pos = start; pos.x < end.x; pos.x++) {
for (pos.y = start.y; pos.y < end.y; pos.y++) {
if (pos.x < 0 || pos.x >= width ||
pos.y < 0 || pos.y >= height)
continue;
image[pos.x + pos.y * width] = Ink::LatchOff;
}
}
}
}

// printf("Loaded image %dx%d (%d bytes)\n", width, height, dSize);
}
}
Expand Down
3 changes: 1 addition & 2 deletions openVCBSim.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Code for simulations

#include "openVCB.h"



namespace openVCB {
using namespace std;
using namespace glm;
Expand Down
14 changes: 8 additions & 6 deletions opennVCBAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace openVCB {
// Parse this stuff
if (prefix(buff, "symbol") || prefix(buff, "resymb")) {}
else if (prefix(buff, "unsymb")) {}
else if (prefix(buff, "pointer")) {
else if (prefix(buff, "pointer") || prefix(buff, "repoint")) {
int k = 7;
string label = getNext(buff, k);
string addr = getNext(buff, k);
Expand Down Expand Up @@ -96,7 +96,7 @@ namespace openVCB {
string label = getNext(buff, k);
vars.erase(label);
}
else if (prefix(buff, "pointer")) {
else if (prefix(buff, "pointer") || prefix(buff, "repoint")) {
int k = 7;
string label = getNext(buff, k);
string addr = getNext(buff, k);
Expand All @@ -122,16 +122,18 @@ namespace openVCB {
for (int i = 0; i < vmAddr.numBits; i++) {
ivec2 pos = vmAddr.pos + i * vmAddr.stride;
vmAddr.gids[i] = indexImage[pos.x + pos.y * width];
if ((Ink)states[vmAddr.gids[i]].ink != Ink::LatchOff) {
printf("error: No address latch at VMem position");
if (vmAddr.gids[i] == -1 ||
setOff((Ink)states[vmAddr.gids[i]].ink) != Ink::LatchOff) {
printf("error: No address latch at VMem position %d %d\n", pos.x, pos.y);
exit(-1);
}
}
for (int i = 0; i < vmData.numBits; i++) {
ivec2 pos = vmData.pos + i * vmData.stride;
vmData.gids[i] = indexImage[pos.x + pos.y * width];
if ((Ink)states[vmData.gids[i]].ink != Ink::LatchOff) {
printf("error: No data latch at VMem position");
if (vmAddr.gids[i] == -1 ||
setOff((Ink)states[vmData.gids[i]].ink) != Ink::LatchOff) {
printf("error: No data latch at VMem position %d %d\n", pos.x, pos.y);
exit(-1);
}
}
Expand Down

0 comments on commit f0c1e7a

Please sign in to comment.