benma / pysph

SPH fluid simulation with advanced screen space fluid rendering, using pyopengl and pyopencl.
110 stars 18 forks source link

Can not compile blur.cg #1

Closed dancsi closed 12 years ago

dancsi commented 12 years ago

The program fails compiling blur.cg, saying that there is a syntax error

Qt: Untested Windows version 6.2 detected!
7290 particles
initial density: 1000, mass: 17.146776406035674, gas constant k: 1000, timestep: 0.004077220187839082 (20, 20, 20) 8000 cells
profile:  b'gp4vp'
vertex shader, entry = passVertex: creating program from string: b'The compile returned an error.'
b'(0) : error C0000: syntax error, unexpected $end, expecting "::" at token "<EOF>"\n'

When I try to compile it with cgc version 3.1.0013, it compiles without an error, and gives

34 lines, 0 errors.
!!NVvp4.0
# cgc version 3.1.0013, build date Apr 18 2012
# command line args: -profile gp4vp
# source file: C:\Users\Daniel\informatika\petnica\2012\simulacija fluida\pysph\
src\fluid_rendering\blur2.cg
#vendor NVIDIA Corporation
#version 3.1.0.13
#profile gp4vp
#program passVertex
#semantic texSampler : TEXUNIT0
#var float4 pos : $vin.POSITION : ATTR0 : 0 : 1
#var float2 tex : $vin.TEXCOORD0 : ATTR8 : 1 : 1
#var float4 outPos : $vout.POSITION : HPOS : 2 : 1
#var float2 outTex : $vout.TEXCOORD0 : TEX0 : 3 : 1
#var sampler2D texSampler : TEXUNIT0 : texunit 0 : -1 : 0
ATTRIB vertex_attrib1[] = { vertex.attrib[1..8] };
ATTRIB vertex_attrib[] = { vertex.attrib[0..0] };
OUTPUT result_texcoord[] = { result.texcoord[0..0] };
MOV.F result.position, vertex.attrib[0];
MOV.F result.texcoord[0].xy, vertex.attrib[8];
END
#2 instructions, 0 R-regs

I'm using a NVIDIA GeForce 9600 GT, on Windows 8 Release Preview x64, with the latest 302.8 drivers. The python (version 3.2) and all the libraries are 64bit.

benma commented 12 years ago

Could you please add the line

print source

at this position (line 17)? Then we can see what the source that is compiled actually looks like.

Also, how can you run this with Python 3.2 when it uses 2.7 syntax? Did you run 2to3?

dancsi commented 12 years ago

Yep, I ran 2to3, and made some manual corrections (changed some floats to ints, because the opencl complained about the function signatures). I have already done this and I believe that the source is fine (only the 2 template variables replaced), but I will post it anyway, in a couple of minutes

benma commented 12 years ago

I also tested it with the gp4vp profile and it worked fine here. Did you try running the original version with Python2? In the meantime, you can also use python main.py --disable-advanced-rendering 8000. The rendering will look bad, but the simulation will run.

dancsi commented 12 years ago

Here is the source:

static const float sigma = 5;
static const float radius = 20;
sampler2D texSampler : TEXUNIT0 = sampler_state {
  magfilter = LINEAR;
  minfilter = LINEAR;
  mipfilter = LINEAR;
  AddressU = clamp;
  AddressV = clamp;
};

void passVertex(float4 pos : POSITION, float2 tex : TEXCOORD0, out float4 outPos : POSITION, out float2 outTex: TEXCOORD0) {
  outPos = pos;
  outTex = tex;
}

float blurFragment(float2 uv : TEXCOORD0, uniform float2 direction, uniform float2 texelSize) : COLOR {
  float sum = 0;
  float wsum = 0;
  for(int r = -radius; r <= radius; r+=1) {
    float sample = tex2D(texSampler, uv + (float)r*direction*texelSize).x;
    float v = (float)r/sigma;
    float w = exp(-v*v/2.);
    sum += sample * w;
    wsum += w;
  }
  if(wsum > 0.) {
    sum /= wsum;
  }
  return sum;
}

No, I didn't try it with python2 yet, but will try it in a few moments. I can upload my fork, so you can try with python3. EDIT: Here is my fork

benma commented 12 years ago

Unfortunately, I can't run using Python3 because I can't manage to install pyopencl with this version. However, if I run your code with python2, there is no error.

Once this is resolved, it would be cool if you could send me a pull request for the python3 conversion. Then it will be compatible with both python2 and python3.

dancsi commented 12 years ago

That's great :) Now I'm debugging lines 163 and 164 in cg/cg_shader.py . They both seem to produce the same error.

dancsi commented 12 years ago

Ok, fixed this one in my fork. The problem was in the fact that entrypoint and code strings were of type str, so I casted all of the first to byte arrays, and then to c_char_ps

benma commented 12 years ago

Cool, so it was a 2to3 issue after all. Thanks.

benma commented 11 years ago

Just to let you know, I finally got around to making pysph Python 3 compatible.

dancsi commented 11 years ago

Yay, that is great :)