Skip to content

fix: pass the real number of channels to rs_texture and rs_texture3d on gpu #2004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/liboslexec/optexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,15 @@ osl_texture(OpaqueExecContextPtr oec, ustringhash_pod name_, void* handle,
ustringhash name = ustringhash_from(name_);
bool ok = rs_texture(oec, name, (TextureSystem::TextureHandle*)handle,
#ifndef __CUDA_ARCH__
sg->context->texture_thread_info(),
sg->context->texture_thread_info(), *opt, s, t, dsdx,
dtdx, dsdy, dtdy, 4,
#else
nullptr,
nullptr, *opt, s, t, dsdx, dtdx, dsdy, dtdy,
chans + (alpha ? 1 : 0), // # chans we're asking
#endif
*opt, s, t, dsdx, dtdx, dsdy, dtdy, 4,
(float*)&result_simd,
derivs ? (float*)&dresultds_simd : NULL,
derivs ? (float*)&dresultdt_simd : NULL,
derivs ? (float*)&dresultds_simd : nullptr,
derivs ? (float*)&dresultdt_simd : nullptr,
errormessage ? &em : nullptr);

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

if (errormessage)
*errormessage = ok ? ustringhash {}.hash() : em.hash();
*errormessage = em.hash();
return ok;
}

Expand Down Expand Up @@ -385,11 +386,13 @@ osl_texture3d(OpaqueExecContextPtr oec, ustringhash_pod name_, void* handle,
ustringhash name = ustringhash_from(name_);
bool ok = rs_texture3d(oec, name, (TextureSystem::TextureHandle*)handle,
#ifndef __CUDA_ARCH__
sg->context->texture_thread_info(),
sg->context->texture_thread_info(), *opt, P, dPdx,
dPdy, dPdz, 4,
#else
nullptr,
nullptr, *opt, P, dPdx, dPdy, dPdz,
chans + (alpha ? 1 : 0), // # chans we're asking
#endif
*opt, P, dPdx, dPdy, dPdz, 4, (float*)&result_simd,
(float*)&result_simd,
derivs ? (float*)&dresultds_simd : nullptr,
derivs ? (float*)&dresultdt_simd : nullptr,
derivs ? (float*)&dresultdr_simd : nullptr,
Expand Down Expand Up @@ -421,7 +424,7 @@ osl_texture3d(OpaqueExecContextPtr oec, ustringhash_pod name_, void* handle,
}

if (errormessage)
*errormessage = ok ? ustringhash {}.hash() : em.hash();
*errormessage = em.hash();
return ok;
}

Expand Down Expand Up @@ -459,12 +462,14 @@ osl_environment(OpaqueExecContextPtr oec, ustringhash_pod name_, void* handle,
ustringhash name = ustringhash_from(name_);
bool ok = rs_environment(oec, name, (TextureSystem::TextureHandle*)handle,
#ifndef __CUDA_ARCH__
sg->context->texture_thread_info(),
sg->context->texture_thread_info(), *opt, R, dRdx,
dRdy, 4,
#else
nullptr,
nullptr, *opt, R, dRdx, dRdy,
chans + (alpha ? 1 : 0), // # chans we're asking
#endif
*opt, R, dRdx, dRdy, 4, (float*)&local_result,
NULL, NULL, errormessage ? &em : nullptr);
(float*)&local_result, nullptr, nullptr,
errormessage ? &em : nullptr);

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

if (errormessage)
*errormessage = ok ? ustringhash {}.hash() : em.hash();
*errormessage = em.hash();
return ok;
}

Expand Down
4 changes: 2 additions & 2 deletions src/testshade/rs_simplerend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ rs_texture(OSL::OpaqueExecContextPtr ec, OSL::ustringhash filename,
return false;
const float4 fromTexture = osl_tex2DLookup(texture_handle, s, t, dsdx, dtdx,
dsdy, dtdy);
*((float3*)result) = make_float3(fromTexture.x, fromTexture.y,
fromTexture.z);
for (int c = 0; c < nchannels; ++c)
result[c] = ((const float*)&fromTexture)[c];
return true;
#endif
}
Expand Down
Loading