Skip to content

Commit

Permalink
Removed need to set texture format for compute's setImage.
Browse files Browse the repository at this point in the history
  • Loading branch information
bkaradzic committed Feb 24, 2015
1 parent 29313fa commit fb6aa4f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 42 deletions.
4 changes: 2 additions & 2 deletions include/bgfx.c99.h
Original file line number Diff line number Diff line change
Expand Up @@ -1358,12 +1358,12 @@ BGFX_C_API uint32_t bgfx_submit(uint8_t _id, int32_t _depth);
/**
*
*/
BGFX_C_API void bgfx_set_image(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_texture_format_t _format, bgfx_access_t _access);
BGFX_C_API void bgfx_set_image(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format);

/**
*
*/
BGFX_C_API void bgfx_set_image_from_frame_buffer(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, bgfx_texture_format_t _format, bgfx_access_t _access);
BGFX_C_API void bgfx_set_image_from_frame_buffer(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, bgfx_access_t _access, bgfx_texture_format_t _format);

/**
* Dispatch compute.
Expand Down
4 changes: 2 additions & 2 deletions include/bgfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -1282,10 +1282,10 @@ namespace bgfx
void setBuffer(uint8_t _stage, DynamicVertexBufferHandle _handle, Access::Enum _access);

///
void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, TextureFormat::Enum _format, Access::Enum _access);
void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, Access::Enum _access, TextureFormat::Enum _format = TextureFormat::Count);

///
void setImage(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment, TextureFormat::Enum _format, Access::Enum _access);
void setImage(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment, Access::Enum _access, TextureFormat::Enum _format = TextureFormat::Count);

/// Dispatch compute.
void dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX = 1, uint16_t _numY = 1, uint16_t _numZ = 1, uint8_t _flags = BGFX_SUBMIT_EYE_FIRST);
Expand Down
16 changes: 8 additions & 8 deletions src/bgfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2872,16 +2872,16 @@ namespace bgfx
s_ctx->setBuffer(_stage, _handle, _access);
}

void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, TextureFormat::Enum _format, Access::Enum _access)
void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, Access::Enum _access, TextureFormat::Enum _format)
{
BGFX_CHECK_MAIN_THREAD();
s_ctx->setImage(_stage, _sampler, _handle, _mip, _format, _access);
s_ctx->setImage(_stage, _sampler, _handle, _mip, _access, _format);
}

void setImage(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment, TextureFormat::Enum _format, Access::Enum _access)
void setImage(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment, Access::Enum _access, TextureFormat::Enum _format)
{
BGFX_CHECK_MAIN_THREAD();
s_ctx->setImage(_stage, _sampler, _handle, _attachment, _format, _access);
s_ctx->setImage(_stage, _sampler, _handle, _attachment, _access, _format);
}

void dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags)
Expand Down Expand Up @@ -3491,18 +3491,18 @@ BGFX_C_API uint32_t bgfx_submit(uint8_t _id, int32_t _depth)
return bgfx::submit(_id, _depth);
}

BGFX_C_API void bgfx_set_image(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_texture_format_t _format, bgfx_access_t _access)
BGFX_C_API void bgfx_set_image(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format)
{
union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } sampler = { _sampler };
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle };
bgfx::setImage(_stage, sampler.cpp, handle.cpp, _mip, bgfx::TextureFormat::Enum(_format), bgfx::Access::Enum(_access) );
bgfx::setImage(_stage, sampler.cpp, handle.cpp, _mip, bgfx::Access::Enum(_access), bgfx::TextureFormat::Enum(_format) );
}

BGFX_C_API void bgfx_set_image_from_frame_buffer(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, bgfx_texture_format_t _format, bgfx_access_t _access)
BGFX_C_API void bgfx_set_image_from_frame_buffer(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, bgfx_access_t _access, bgfx_texture_format_t _format)
{
union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } sampler = { _sampler };
union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle };
bgfx::setImage(_stage, sampler.cpp, handle.cpp, _attachment, bgfx::TextureFormat::Enum(_format), bgfx::Access::Enum(_access) );
bgfx::setImage(_stage, sampler.cpp, handle.cpp, _attachment, bgfx::Access::Enum(_access), bgfx::TextureFormat::Enum(_format) );
}

BGFX_C_API void bgfx_dispatch(uint8_t _id, bgfx_program_handle_t _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags)
Expand Down
64 changes: 35 additions & 29 deletions src/bgfx_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ namespace bgfx
bind.m_un.m_compute.m_mip = 0;
}

void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, TextureFormat::Enum _format, Access::Enum _access)
void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, Access::Enum _access, TextureFormat::Enum _format)
{
Binding& bind = m_compute.m_bind[_stage];
bind.m_idx = _handle.idx;
Expand Down Expand Up @@ -2720,31 +2720,34 @@ namespace bgfx

BGFX_API_FUNC(TextureHandle createTexture(const Memory* _mem, uint32_t _flags, uint8_t _skip, TextureInfo* _info) )
{
if (NULL != _info)
TextureInfo ti;
if (NULL == _info)
{
ImageContainer imageContainer;
if (imageParse(imageContainer, _mem->data, _mem->size) )
{
calcTextureSize(*_info
, (uint16_t)imageContainer.m_width
, (uint16_t)imageContainer.m_height
, (uint16_t)imageContainer.m_depth
, imageContainer.m_cubeMap
, imageContainer.m_numMips
, TextureFormat::Enum(imageContainer.m_format)
);
}
else
{
_info->format = TextureFormat::Unknown;
_info->storageSize = 0;
_info->width = 0;
_info->height = 0;
_info->depth = 0;
_info->numMips = 0;
_info->bitsPerPixel = 0;
_info->cubeMap = false;
}
_info = &ti;
}

ImageContainer imageContainer;
if (imageParse(imageContainer, _mem->data, _mem->size) )
{
calcTextureSize(*_info
, (uint16_t)imageContainer.m_width
, (uint16_t)imageContainer.m_height
, (uint16_t)imageContainer.m_depth
, imageContainer.m_cubeMap
, imageContainer.m_numMips
, TextureFormat::Enum(imageContainer.m_format)
);
}
else
{
_info->format = TextureFormat::Unknown;
_info->storageSize = 0;
_info->width = 0;
_info->height = 0;
_info->depth = 0;
_info->numMips = 0;
_info->bitsPerPixel = 0;
_info->cubeMap = false;
}

TextureHandle handle = { m_textureHandle.alloc() };
Expand All @@ -2753,6 +2756,7 @@ namespace bgfx
{
TextureRef& ref = m_textureRef[handle.idx];
ref.m_refCount = 1;
ref.m_format = uint8_t(_info->format);

CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateTexture);
cmdbuf.write(handle);
Expand Down Expand Up @@ -3255,12 +3259,13 @@ namespace bgfx
m_submit->setBuffer(_stage, dvb.m_handle, _access);
}

BGFX_API_FUNC(void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, TextureFormat::Enum _format, Access::Enum _access) )
BGFX_API_FUNC(void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, Access::Enum _access, TextureFormat::Enum _format) )
{
m_submit->setImage(_stage, _sampler, _handle, _mip, _format, _access);
_format = TextureFormat::Count == _format ? TextureFormat::Enum(m_textureRef[_handle.idx].m_format) : _format;
m_submit->setImage(_stage, _sampler, _handle, _mip, _access, _format);
}

BGFX_API_FUNC(void setImage(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment, TextureFormat::Enum _format, Access::Enum _access) )
BGFX_API_FUNC(void setImage(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment, Access::Enum _access, TextureFormat::Enum _format) )
{
BX_CHECK(_attachment < g_caps.maxFBAttachments, "Frame buffer attachment index %d is invalid.", _attachment);
TextureHandle textureHandle = BGFX_INVALID_HANDLE;
Expand All @@ -3272,7 +3277,7 @@ namespace bgfx
BX_CHECK(isValid(textureHandle), "Frame buffer texture %d is invalid.", _attachment);
}

setImage(_stage, _sampler, textureHandle, 0, _format, _access);
setImage(_stage, _sampler, textureHandle, 0, _access, _format);
}

BGFX_API_FUNC(uint32_t dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags) )
Expand Down Expand Up @@ -3402,6 +3407,7 @@ namespace bgfx
struct TextureRef
{
int16_t m_refCount;
uint8_t m_format;
};

struct FrameBufferRef
Expand Down
7 changes: 7 additions & 0 deletions src/bgfx_shader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ vec2 vec2_splat(float _x) { return vec2(_x, _x); }
vec3 vec3_splat(float _x) { return vec3(_x, _x, _x); }
vec4 vec4_splat(float _x) { return vec4(_x, _x, _x, _x); }

uvec2 uvec2_splat(uint _x) { return uvec2(_x, _x); }
uvec3 uvec3_splat(uint _x) { return uvec3(_x, _x, _x); }
uvec4 uvec4_splat(uint _x) { return uvec4(_x, _x, _x, _x); }

vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_mtx, _vec); }
vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_vec, _mtx); }
vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_mtx, _vec); }
Expand Down Expand Up @@ -239,6 +243,9 @@ vec4 mod(vec4 _a, vec4 _b) { return _a - _b * floor(_a / _b); }
# define vec2_splat(_x) vec2(_x)
# define vec3_splat(_x) vec3(_x)
# define vec4_splat(_x) vec4(_x)
# define uvec2_splat(_x) uvec2(_x)
# define uvec3_splat(_x) uvec3(_x)
# define uvec4_splat(_x) uvec4(_x)

vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_vec, _mtx); }
vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_mtx, _vec); }
Expand Down
2 changes: 1 addition & 1 deletion src/glimports.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ GL_IMPORT_NV___(true, PFNGLGETQUERYOBJECTUI64VPROC, glGetQueryObj

GL_IMPORT (true, PFNGLINVALIDATEFRAMEBUFFERPROC, glInvalidateFramebuffer, glDiscardFramebufferEXT);

#else
#elif !BGFX_USE_GL_DYNAMIC_LIB
GL_IMPORT______(true, PFNGLTEXIMAGE3DPROC, glTexImage3D);
GL_IMPORT______(true, PFNGLTEXSUBIMAGE3DPROC, glTexSubImage3D);
GL_IMPORT______(true, PFNGLCOMPRESSEDTEXIMAGE3DPROC, glCompressedTexImage3D);
Expand Down

0 comments on commit fb6aa4f

Please sign in to comment.