summaryrefslogtreecommitdiff
path: root/nvexec_raw.cpp
blob: a55bf8d8786d1ddd43f8e5de4c8b57eb9f362ea7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "nvlib.h"
#include <fstream>
using namespace std;

int main(int argc, char** argv)
{
	unique_ptr<nv_device> dev(nv_device::open_default());
	unique_ptr<nv_gl_process> runner(new nv_gl_process(&*dev));

	int channel = nv_find_idle_channel(&*dev);
	if(channel < 0)
		throw runtime_error("Unable to find idle channel for GL process.\n");

	std::shared_ptr<nv_hwchannel> hwchan(dev->hwchannel(channel));
	unique_ptr<nv_channel> chan(new nv_channel_vram(hwchan));
	//unique_ptr<nv_channel> chan(new nv_channel_parasite(hwchan, &*runner));

	cerr << "Channel " << hwchan->channel << endl;

	unsigned grclasses[8];
	hwchan->get_grclasses(grclasses);

//	for(unsigned i = 0; i < 8; ++i)
//		cout << grclasses[i] << endl;

	vector<pair<unsigned, unsigned> > commands;
	ifstream fin;
	istream& in = argc >= 2 ? fin : cin;
	if(argc >= 2)
		fin.open(argv[1]);

	for(;;)
	{
		unsigned grclass, method, value;
		unsigned subc;
		in >> grclass >> method >> value;
		if(!in.good())
			break;

		for(subc = 0; subc < 8; ++subc) {
			if(!((grclass ^ grclasses[subc]) & 0xff))
				break;
		}
		if(subc == 8) {
			cerr << "Unable to find subchannel for grclass " << grclass << endl;
			return 1;
		}

		//cout << subc << ' ' << method << ' ' << value << endl;

		commands.push_back(make_pair(RING(subc, method, 1), value));
	}

	for(unsigned i = 0; i < commands.size(); ++i)
	{
		chan->wait(2);
		chan->out(commands[i].first);
		chan->out(commands[i].second);
	}
	os->trace_marker("nvexec: before fire");
	chan->fire();
	chan->wait_idle();
	return 0;
}