Skip to content

Commit 67693b9

Browse files
authored
fix: pass the real number of channels to rs_texture and rs_texture3d on gpu (#2004)
These were discovered when moving SPI's renderer to the the current release and switching to use the rs_ functions. Signed-off-by: Larry Gritz <[email protected]>
1 parent 8599942 commit 67693b9

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

src/liboslexec/optexture.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,15 @@ osl_texture(OpaqueExecContextPtr oec, ustringhash_pod name_, void* handle,
307307
ustringhash name = ustringhash_from(name_);
308308
bool ok = rs_texture(oec, name, (TextureSystem::TextureHandle*)handle,
309309
#ifndef __CUDA_ARCH__
310-
sg->context->texture_thread_info(),
310+
sg->context->texture_thread_info(), *opt, s, t, dsdx,
311+
dtdx, dsdy, dtdy, 4,
311312
#else
312-
nullptr,
313+
nullptr, *opt, s, t, dsdx, dtdx, dsdy, dtdy,
314+
chans + (alpha ? 1 : 0), // # chans we're asking
313315
#endif
314-
*opt, s, t, dsdx, dtdx, dsdy, dtdy, 4,
315316
(float*)&result_simd,
316-
derivs ? (float*)&dresultds_simd : NULL,
317-
derivs ? (float*)&dresultdt_simd : NULL,
317+
derivs ? (float*)&dresultds_simd : nullptr,
318+
derivs ? (float*)&dresultdt_simd : nullptr,
318319
errormessage ? &em : nullptr);
319320

320321
for (int i = 0; i < chans; ++i)
@@ -341,7 +342,7 @@ osl_texture(OpaqueExecContextPtr oec, ustringhash_pod name_, void* handle,
341342
}
342343

343344
if (errormessage)
344-
*errormessage = ok ? ustringhash {}.hash() : em.hash();
345+
*errormessage = em.hash();
345346
return ok;
346347
}
347348

@@ -385,11 +386,13 @@ osl_texture3d(OpaqueExecContextPtr oec, ustringhash_pod name_, void* handle,
385386
ustringhash name = ustringhash_from(name_);
386387
bool ok = rs_texture3d(oec, name, (TextureSystem::TextureHandle*)handle,
387388
#ifndef __CUDA_ARCH__
388-
sg->context->texture_thread_info(),
389+
sg->context->texture_thread_info(), *opt, P, dPdx,
390+
dPdy, dPdz, 4,
389391
#else
390-
nullptr,
392+
nullptr, *opt, P, dPdx, dPdy, dPdz,
393+
chans + (alpha ? 1 : 0), // # chans we're asking
391394
#endif
392-
*opt, P, dPdx, dPdy, dPdz, 4, (float*)&result_simd,
395+
(float*)&result_simd,
393396
derivs ? (float*)&dresultds_simd : nullptr,
394397
derivs ? (float*)&dresultdt_simd : nullptr,
395398
derivs ? (float*)&dresultdr_simd : nullptr,
@@ -421,7 +424,7 @@ osl_texture3d(OpaqueExecContextPtr oec, ustringhash_pod name_, void* handle,
421424
}
422425

423426
if (errormessage)
424-
*errormessage = ok ? ustringhash {}.hash() : em.hash();
427+
*errormessage = em.hash();
425428
return ok;
426429
}
427430

@@ -459,12 +462,14 @@ osl_environment(OpaqueExecContextPtr oec, ustringhash_pod name_, void* handle,
459462
ustringhash name = ustringhash_from(name_);
460463
bool ok = rs_environment(oec, name, (TextureSystem::TextureHandle*)handle,
461464
#ifndef __CUDA_ARCH__
462-
sg->context->texture_thread_info(),
465+
sg->context->texture_thread_info(), *opt, R, dRdx,
466+
dRdy, 4,
463467
#else
464-
nullptr,
468+
nullptr, *opt, R, dRdx, dRdy,
469+
chans + (alpha ? 1 : 0), // # chans we're asking
465470
#endif
466-
*opt, R, dRdx, dRdy, 4, (float*)&local_result,
467-
NULL, NULL, errormessage ? &em : nullptr);
471+
(float*)&local_result, nullptr, nullptr,
472+
errormessage ? &em : nullptr);
468473

469474
for (int i = 0; i < chans; ++i)
470475
result[i] = local_result[i];
@@ -492,7 +497,7 @@ osl_environment(OpaqueExecContextPtr oec, ustringhash_pod name_, void* handle,
492497
}
493498

494499
if (errormessage)
495-
*errormessage = ok ? ustringhash {}.hash() : em.hash();
500+
*errormessage = em.hash();
496501
return ok;
497502
}
498503

src/testshade/rs_simplerend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ rs_texture(OSL::OpaqueExecContextPtr ec, OSL::ustringhash filename,
211211
return false;
212212
const float4 fromTexture = osl_tex2DLookup(texture_handle, s, t, dsdx, dtdx,
213213
dsdy, dtdy);
214-
*((float3*)result) = make_float3(fromTexture.x, fromTexture.y,
215-
fromTexture.z);
214+
for (int c = 0; c < nchannels; ++c)
215+
result[c] = ((const float*)&fromTexture)[c];
216216
return true;
217217
#endif
218218
}

0 commit comments

Comments
 (0)