Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 26 Jul 2009
Offline Last Active Jul 19 2013 01:09 PM

Topics I've Started

Sampling a texture in a domain shader [Cg]

30 May 2013 - 10:28 AM

This question pertains specifically to using NVidia Cg with DX11.
I'm trying to write a simple terrain tesselation shader that tesselates a quad patch and applies a heightmap in the domain shader for vertex displacent. I'm passing in the heightmap as a 2D texture and using the following line to sample the texture.
pos.z = tex2D(heightmapTexture, texUV).r;


But this doesn't compile and I get the following error.


error C1115: unable to find compatible overloaded function "Sample(sampler2D, float2)"
Is this the correct syntax for sampling a texture in the domain shader, or is this not currently supported?

GPU and system RAM

01 March 2011 - 10:52 PM

I've been trying to understand how a graphics card can use up system RAM and after reading up various resources online, I've come to understand that this can happen in the following 2 ways. I'm a little fuzzy after all the reading, and I wanted to make sure that I understand this correctly. Also, please let me know if I missed anything.

1) If you have a 32bit OS and have 4GB of system RAM installed, you will not be able to use all of the 4GB. Instead you can only address 4GB minus the amount of VRAM in your graphics card. This is because in a 32bit OS, you can address a maximum of 4GB (2^32 bytes) of memory. Since, the addresses of the local VRAM memory on graphics cards are memory mapped, they need to be within this 4GB limit. So, if a graphics card has 1GB of memory, we will only be able to use 3GB of system RAM even if we have 4GB installed. If the amount of RAM is less that 4GB, then this is not a problem because the VRAM will be mapped to the upper range of the 4GB limit which is not addressed by the system RAM. Also, this is not a problem for a 64bit OS since, the amount of addressable memory is not limited to 4GB (it can be 2^64 bytes theoretically).

The graphics card is not actually 'using' the system RAM in this case, but in fact we're losing usable RAM because of address space limitations.

2) If render resources are put into the D3D managed pool, they they are basically duplicated in memory, i.e. they exist both in VRAM and a portion of the system RAM mapped by the graphics card for its own use called AGP memory. However, this is not the case if we use the default pool.

In this case, the graphics card can use up system RAM regardless of the OS type. If however, we have a 32 bit OS with 4GB of RAM and are using the managed pool for our resources, then we have to take a double hit for the system memory.

These are the two ways that a graphics card can 'eat into' system RAM. Please correct me if I'm wrong. Also, in the second case, how large a chunk is used for the AGP memory. Is it as large as the VRAM? Thanks is advance.

Safe Array class

26 July 2009 - 03:23 PM


I am trying to create a safe array class, that mimic a C++ array as closely as possible while at the same time providing a bounds check.

This is what my class looks like

template<typename T, unsigned int size>
class SafeArray
// Ctor
SafeArray() {}

// index into array
T& operator[](const unsigned int index) {
assert(index<size && "Array index out of bounds");
return _array[index];

// print array
friend ostream& operator<<(ostream& stream, const SafeArray& arr) {
stream <<"[";

for(unsigned int i=0; i<size; i++)

stream <<"]";

// Array pointer arithmetic : +
T* const operator+(const int step) {
assert(step<size && "Array index out of bounds");
return &_array[step];

// Array pointer arithmetic : +=
T* const operator+=(const int step) {
assert(currentIndex<size && "Array index out of bounds");
return _array+=step;

// Array pointer arithmetic : ++
T* const operator++() {
assert(currentIndex<size && "Array index out of bounds");
return _array++;

// Array pointer arithmetic : -
T* const operator-(const int step) {
assert("Array index out of bounds");

// Array pointer arithmetic : -=
T* const operator-=(const int step) {
assert(currentIndex>=0 && "Array index out of bounds");
return _array-=step;

// Array pointer arithmetic : --
T* const operator--() {
assert(currentIndex>=0 && "Array index out of bounds");
return _array--;

// pointer to base pointer
unsigned int operator&() {
return &_array;

T _array[size];
unsigned int currentIndex;

What I'd like to have is to be able to initialize it with an initialization list just like C++ arrays

int c[] = {1,2,3};

SafeArray<int,3> c = {1,2,3};

But, I'm not sure how to achieve this. I tried the following

void operator=(const T copy[]) {
for(int i=0; i<size; i++)
_array[i] = copy[i];

but that gives me the following compilation error

"non-aggregates cannot be initialized with initializer list"

Can someone show me how to do it?