Skip to content

Commit 409d4c7

Browse files
committed
🚧 First version that work for openGL and DX11. But texture array has to be treated slice by slice...
1 parent 455cba7 commit 409d4c7

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

‎Plugin/SampleBasic/include/sample_kernels.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void kernelCallerWriteTexture(const dim3 dimGrid, const dim3 dimBlock,
1111
const float t, const int width, const int height);
1212

1313
void kernelCallerWriteTextureArray(const dim3 dimGrid, const dim3 dimBlock,
14-
cudaSurfaceObject_t* inputSurfaceObj,
14+
cudaSurfaceObject_t* surfObjArray,
1515
const float time, const int width,
1616
const int height, const int depth);
1717

‎Plugin/SampleBasic/src/action_sample_texture.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ inline int ActionSampleTexture::Start()
2222
int ActionSampleTexture::Update()
2323
{
2424
kernelCallerWriteTexture(_texture->getDimGrid(), _texture->getDimBlock(),
25-
_texture->getSurfaceObject(), GetTime(), _texture->getWidth(),
26-
_texture->getHeight());
27-
// cudaDeviceSynchronize();
25+
_texture->getSurfaceObject(), GetTime(),
26+
_texture->getWidth(), _texture->getHeight());
27+
cudaDeviceSynchronize();
2828
return 0;
2929
}
3030

‎Plugin/SampleBasic/src/action_sample_texture_array.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ int ActionSampleTextureArray::Update()
2323
{
2424
kernelCallerWriteTextureArray(
2525
_texture->getDimGrid(), _texture->getDimBlock(),
26-
_texture->getSurfaceObjectArray(), GetTime(), _texture->getWidth(),
27-
_texture->getHeight(), _texture->getDepth());
26+
_texture->getSurfaceObjectArray(), GetTime(), _texture->getWidth(),
27+
_texture->getHeight(), _texture->getDepth());
2828
cudaDeviceSynchronize();
2929
return 0;
3030
}

‎Plugin/SampleBasic/src/action_sample_vertex_buffer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ namespace SampleBasic {
2828

2929

3030
_vertexBuffer->unmapResources();
31+
delete(v);
32+
3133
return 0;
3234
}
3335

‎Plugin/SampleBasic/src/sample_kernels.cu

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ __global__ void writeTex(cudaSurfaceObject_t surf, int width, int height,
1515
}
1616
}
1717

18-
__global__ void writeTexArray(cudaSurfaceObject_t* surf, int width, int height,
18+
__global__ void writeTexArray(cudaSurfaceObject_t* surfObjArray, int width, int height,
1919
int depth, float time)
2020
{
2121
const unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
2222
const unsigned int y = blockIdx.y * blockDim.y + threadIdx.y;
2323
const unsigned int z = blockIdx.z * blockDim.z + threadIdx.z;
2424

25-
if (x < width && y < height)
25+
if (x < width && y < height && z < depth)
2626
{
2727

28-
float4 t = make_float4(z % 2, abs(cos(time)), 0, 1.0f);
28+
float4 t = make_float4(z % 2, abs((z+1)*cos(time)), 0, 1.0f);
2929

30-
surf2Dwrite(t, surf[z], sizeof(float4) * x, y);
30+
surf2Dwrite(t, surfObjArray[z], sizeof(float4) * x, y);
3131
}
3232
}
3333

@@ -52,11 +52,15 @@ void kernelCallerWriteTexture(const dim3 dimGrid, const dim3 dimBlock,
5252
}
5353

5454
void kernelCallerWriteTextureArray(const dim3 dimGrid, const dim3 dimBlock,
55-
cudaSurfaceObject_t* inputSurfaceObj,
55+
cudaSurfaceObject_t* surfObjArray,
5656
const float time, const int width,
5757
const int height, const int depth)
5858
{
59-
writeTexArray<<<dimGrid, dimBlock>>>(inputSurfaceObj, width, height, depth, time);
59+
60+
writeTex<<<dimGrid, dimBlock>>>(surfObjArray[0], width, height, time);
61+
62+
writeTex<<<dimGrid, dimBlock>>>(surfObjArray[1], width, height, 2*time);
63+
// writeTexArray<<<dimGrid, dimBlock>>>(surfObjArray, width, height, depth, time);
6064
}
6165

6266
void kernelCallerWriteBuffer(const dim3 dimGrid, const dim3 dimBlock,

0 commit comments

Comments
 (0)