Skip to content

Commit

Permalink
fix texture sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Leo-Smith committed Dec 11, 2024
1 parent 9ee33ee commit d707c97
Show file tree
Hide file tree
Showing 4 changed files with 339 additions and 420 deletions.
28 changes: 14 additions & 14 deletions src/backends/fallback/fallback_device_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ void luisa_bc6h_read(const FallbackTextureView *tex, int x, int y, float4 &out)
}

[[nodiscard]] int4 luisa_fallback_texture2d_read_int(void *texture_data, uint64_t texture_data_extra, uint x, uint y) noexcept {
PackedTextureView handle{texture_data, texture_data_extra};
auto tex = reinterpret_cast<const FallbackTextureView *>(&handle);
PackedTextureView view{texture_data, texture_data_extra};
auto tex = reinterpret_cast<const FallbackTextureView *>(&view);
switch (tex->storage()) {
case PixelStorage::BC7: {
float4 out;
Expand All @@ -48,8 +48,8 @@ void luisa_bc6h_read(const FallbackTextureView *tex, int x, int y, float4 &out)
}

[[nodiscard]] uint4 luisa_fallback_texture2d_read_uint(void *texture_data, uint64_t texture_data_extra, uint x, uint y) noexcept {
PackedTextureView handle{texture_data, texture_data_extra};
auto tex = reinterpret_cast<const FallbackTextureView *>(&handle);
PackedTextureView view{texture_data, texture_data_extra};
auto tex = reinterpret_cast<const FallbackTextureView *>(&view);
switch (tex->storage()) {
case PixelStorage::BC7: {
float4 out;
Expand All @@ -75,8 +75,8 @@ void luisa_bc6h_read(const FallbackTextureView *tex, int x, int y, float4 &out)
}

[[nodiscard]] float4 luisa_fallback_texture2d_read_float(void *texture_data, uint64_t texture_data_extra, uint x, uint y) noexcept {
PackedTextureView handle{texture_data, texture_data_extra};
auto tex = reinterpret_cast<const FallbackTextureView *>(&handle);
PackedTextureView view{texture_data, texture_data_extra};
auto tex = reinterpret_cast<const FallbackTextureView *>(&view);
switch (tex->storage()) {
case PixelStorage::BC7: {
float4 out;
Expand All @@ -96,8 +96,8 @@ void luisa_bc6h_read(const FallbackTextureView *tex, int x, int y, float4 &out)
}

void luisa_fallback_texture2d_write_float(void *texture_data, uint64_t texture_data_extra, uint x, uint y, float4 value) noexcept {
PackedTextureView handle{texture_data, texture_data_extra};
auto tex = reinterpret_cast<const FallbackTextureView *>(&handle);
PackedTextureView view{texture_data, texture_data_extra};
auto tex = reinterpret_cast<const FallbackTextureView *>(&view);
switch (tex->storage()) {
case PixelStorage::BC7: {
LUISA_ERROR("cannot write to BC texture");
Expand All @@ -115,8 +115,8 @@ void luisa_fallback_texture2d_write_float(void *texture_data, uint64_t texture_d
}

void luisa_fallback_texture2d_write_uint(void *texture_data, uint64_t texture_data_extra, uint x, uint y, uint4 value) noexcept {
PackedTextureView handle{texture_data, texture_data_extra};
auto tex = reinterpret_cast<const FallbackTextureView *>(&handle);
PackedTextureView view{texture_data, texture_data_extra};
auto tex = reinterpret_cast<const FallbackTextureView *>(&view);
switch (tex->storage()) {
case PixelStorage::BC7: {
LUISA_ERROR("cannot write to BC texture");
Expand All @@ -134,8 +134,8 @@ void luisa_fallback_texture2d_write_uint(void *texture_data, uint64_t texture_da
}

void luisa_fallback_texture2d_write_int(void *texture_data, uint64_t texture_data_extra, uint x, uint y, int4 value) noexcept {
PackedTextureView handle{texture_data, texture_data_extra};
auto tex = reinterpret_cast<const FallbackTextureView *>(&handle);
PackedTextureView view{texture_data, texture_data_extra};
auto tex = reinterpret_cast<const FallbackTextureView *>(&view);
switch (tex->storage()) {
case PixelStorage::BC7: {
LUISA_ERROR("cannot write to BC texture");
Expand Down Expand Up @@ -205,7 +205,7 @@ template<typename T>
}

[[nodiscard]] float4 luisa_fallback_bindless_texture2d_sample(const Texture *handle, uint sampler, float u, float v) noexcept {
auto tex = reinterpret_cast<const FallbackTexture *>(&handle);
auto tex = reinterpret_cast<const FallbackTexture *>(handle);
auto s = Sampler::decode(sampler);
auto view = tex->view(0);
return s.filter() == Sampler::Filter::POINT ?
Expand All @@ -214,7 +214,7 @@ template<typename T>
}

[[nodiscard]] float4 luisa_fallback_bindless_texture2d_sample_level(const Texture *handle, uint sampler, float u, float v, float level) noexcept {
auto tex = reinterpret_cast<const FallbackTexture *>(&handle);
auto tex = reinterpret_cast<const FallbackTexture *>(handle);
auto s = Sampler::decode(sampler);
auto filter = s.filter();
if (level <= 0.f || tex->mip_levels() == 0u || filter == Sampler::Filter::POINT) {
Expand Down
4 changes: 2 additions & 2 deletions src/backends/fallback/fallback_device_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ struct alignas(16u) PackedTextureView {

static_assert(sizeof(TextureView) == 16 && sizeof(PackedTextureView) == 16);

struct Texture;
struct Accel;
struct alignas(16) Texture;
struct alignas(16) Accel;

struct alignas(16) BindlessSlot {
const void *buffer;
Expand Down
2 changes: 1 addition & 1 deletion src/backends/fallback/fallback_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void FallbackShader::dispatch(ThreadPool &pool, const ShaderDispatchCommand *com
break;
}
case Tag::BINDLESS_ARRAY: {
auto bindless = reinterpret_cast<FallbackBindlessArray *>(arg.buffer.handle);
auto bindless = reinterpret_cast<FallbackBindlessArray *>(arg.bindless_array.handle);
auto view = bindless->view();
auto ptr = allocate_argument(sizeof(view));
std::memcpy(ptr, &view, sizeof(view));
Expand Down
Loading

0 comments on commit d707c97

Please sign in to comment.