Archive for the ‘Coding’ Category

Register assignment in HLSL

Sunday, June 27th, 2010

When you are manually assigning shader constants to registers (using a ‘register’ keyword), those registers are also taken out of the automatic assignment pool.
This means that constants that don’t have explicit registers will never overlap with ones that do even if latter are not used in the shader.
And so code like this:
float4 c0 : register(c0);
float4 c1 : register(c2);
float4 c2;
float4 main():POSITION
{
    return c2;
}

Will compile into this:
vs_2_0
mov oPos, c1

This is a pretty small thing, but still quite convenient and useful to know.

C++ gotchas

Saturday, May 2nd, 2009

Today I’m going to write about virtual function hiding.

Consider the following code:

#include <stdio.h>

class Foo
{
public:
    virtual void fun(int)
    {
        printf("A");
    }
    virtual void fun(bool)
    {
        printf("B");
        fun(int());
    }
};

class Bar : public Foo
{
public:
    virtual void fun(int)
    {
        printf("C");
    }
};

int main()
{    

    Bar b;
    b.fun(bool());    

    return 0;
}

What will be written to the console?

(more…)