Added support for texture direct access.
This commit is contained in:
parent
547d1d2b11
commit
0e5f3457c3
@ -2698,6 +2698,19 @@ namespace bgfx
|
||||
, const char* _name
|
||||
);
|
||||
|
||||
/// Returns texture direct access pointer.
|
||||
///
|
||||
/// @param[in] _handle Texture handle.
|
||||
///
|
||||
/// @returns Pointer to texture memory. If pointer is `NULL` direct access is
|
||||
/// not supported. If pointer is `UINTPTR_MAX` sentinel value it means texture
|
||||
/// is pending creation.
|
||||
///
|
||||
/// @attention Availability depends on: `BGFX_CAPS_TEXTURE_DIRECT_ACCESS`.
|
||||
/// @attention C99 equivalent is `bgfx_get_direct_access_ptr`.
|
||||
///
|
||||
void* getDirectAccessPtr(TextureHandle _handle);
|
||||
|
||||
/// Destroy texture.
|
||||
///
|
||||
/// @param[in] _handle Texture handle.
|
||||
|
@ -140,6 +140,7 @@ typedef struct bgfx_interface_vtbl
|
||||
void (*update_texture_cube)(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
|
||||
uint32_t (*read_texture)(bgfx_texture_handle_t _handle, void* _data, uint8_t _mip);
|
||||
void (*set_texture_name)(bgfx_texture_handle_t _handle, const char* _name);
|
||||
void* (*get_direct_access_ptr)(bgfx_texture_handle_t _handle);
|
||||
void (*destroy_texture)(bgfx_texture_handle_t _handle);
|
||||
bgfx_frame_buffer_handle_t (*create_frame_buffer)(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint32_t _textureFlags);
|
||||
bgfx_frame_buffer_handle_t (*create_frame_buffer_scaled)(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint32_t _textureFlags);
|
||||
|
@ -6,7 +6,7 @@
|
||||
#ifndef BGFX_DEFINES_H_HEADER_GUARD
|
||||
#define BGFX_DEFINES_H_HEADER_GUARD
|
||||
|
||||
#define BGFX_API_VERSION UINT32_C(57)
|
||||
#define BGFX_API_VERSION UINT32_C(58)
|
||||
|
||||
/// Color RGB/alpha/depth write. When it's not specified write will be disabled.
|
||||
#define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write.
|
||||
@ -436,8 +436,9 @@
|
||||
#define BGFX_CAPS_TEXTURE_COMPARE_ALL UINT64_C(0x00000000000c0000) //!< All texture compare modes are supported.
|
||||
#define BGFX_CAPS_TEXTURE_COMPARE_LEQUAL UINT64_C(0x0000000000080000) //!< Texture compare less equal mode is supported.
|
||||
#define BGFX_CAPS_TEXTURE_CUBE_ARRAY UINT64_C(0x0000000000100000) //!< Cubemap texture array is supported.
|
||||
#define BGFX_CAPS_TEXTURE_READ_BACK UINT64_C(0x0000000000200000) //!< Read-back texture is supported.
|
||||
#define BGFX_CAPS_VERTEX_ATTRIB_HALF UINT64_C(0x0000000000400000) //!< Vertex attribute half-float is supported.
|
||||
#define BGFX_CAPS_TEXTURE_DIRECT_ACCESS UINT64_C(0x0000000000200000) //!< CPU direct access to GPU texture memory.
|
||||
#define BGFX_CAPS_TEXTURE_READ_BACK UINT64_C(0x0000000000400000) //!< Read-back texture is supported.
|
||||
#define BGFX_CAPS_VERTEX_ATTRIB_HALF UINT64_C(0x0000000000800000) //!< Vertex attribute half-float is supported.
|
||||
#define BGFX_CAPS_VERTEX_ATTRIB_UINT10 UINT64_C(0x0000000000800000) //!< Vertex attribute 10_10_10_2 is supported.
|
||||
|
||||
///
|
||||
|
19
src/bgfx.cpp
19
src/bgfx.cpp
@ -1160,6 +1160,7 @@ namespace bgfx
|
||||
CAPS_FLAGS(BGFX_CAPS_TEXTURE_COMPARE_ALL),
|
||||
CAPS_FLAGS(BGFX_CAPS_TEXTURE_COMPARE_LEQUAL),
|
||||
CAPS_FLAGS(BGFX_CAPS_TEXTURE_CUBE_ARRAY),
|
||||
CAPS_FLAGS(BGFX_CAPS_TEXTURE_DIRECT_ACCESS),
|
||||
CAPS_FLAGS(BGFX_CAPS_TEXTURE_READ_BACK),
|
||||
CAPS_FLAGS(BGFX_CAPS_VERTEX_ATTRIB_HALF),
|
||||
CAPS_FLAGS(BGFX_CAPS_VERTEX_ATTRIB_UINT10),
|
||||
@ -2457,7 +2458,11 @@ namespace bgfx
|
||||
uint8_t skip;
|
||||
_cmdbuf.read(skip);
|
||||
|
||||
m_renderCtx->createTexture(handle, mem, flags, skip);
|
||||
void* ptr = m_renderCtx->createTexture(handle, mem, flags, skip);
|
||||
if (NULL != ptr)
|
||||
{
|
||||
setDirectAccessPtr(handle, ptr);
|
||||
}
|
||||
|
||||
bx::MemoryReader reader(mem->data, mem->size);
|
||||
|
||||
@ -3792,6 +3797,11 @@ error:
|
||||
s_ctx->setName(_handle, _name);
|
||||
}
|
||||
|
||||
void* getDirectAccessPtr(TextureHandle _handle)
|
||||
{
|
||||
return s_ctx->getDirectAccessPtr(_handle);
|
||||
}
|
||||
|
||||
void destroy(TextureHandle _handle)
|
||||
{
|
||||
s_ctx->destroyTexture(_handle);
|
||||
@ -4982,6 +4992,12 @@ BGFX_C_API void bgfx_set_texture_name(bgfx_texture_handle_t _handle, const char*
|
||||
bgfx::setName(handle.cpp, _name);
|
||||
}
|
||||
|
||||
BGFX_C_API void* bgfx_get_direct_access_ptr(bgfx_texture_handle_t _handle)
|
||||
{
|
||||
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle };
|
||||
return bgfx::getDirectAccessPtr(handle.cpp);
|
||||
}
|
||||
|
||||
BGFX_C_API void bgfx_destroy_texture(bgfx_texture_handle_t _handle)
|
||||
{
|
||||
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle };
|
||||
@ -5652,6 +5668,7 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version)
|
||||
BGFX_IMPORT_FUNC(update_texture_cube) \
|
||||
BGFX_IMPORT_FUNC(read_texture) \
|
||||
BGFX_IMPORT_FUNC(set_texture_name) \
|
||||
BGFX_IMPORT_FUNC(get_direct_access_ptr) \
|
||||
BGFX_IMPORT_FUNC(destroy_texture) \
|
||||
BGFX_IMPORT_FUNC(create_frame_buffer) \
|
||||
BGFX_IMPORT_FUNC(create_frame_buffer_scaled) \
|
||||
|
35
src/bgfx_p.h
35
src/bgfx_p.h
@ -2547,7 +2547,7 @@ namespace bgfx
|
||||
virtual void destroyShader(ShaderHandle _handle) = 0;
|
||||
virtual void createProgram(ProgramHandle _handle, ShaderHandle _vsh, ShaderHandle _fsh) = 0;
|
||||
virtual void destroyProgram(ProgramHandle _handle) = 0;
|
||||
virtual void createTexture(TextureHandle _handle, Memory* _mem, uint32_t _flags, uint8_t _skip) = 0;
|
||||
virtual void* createTexture(TextureHandle _handle, Memory* _mem, uint32_t _flags, uint8_t _skip) = 0;
|
||||
virtual void updateTextureBegin(TextureHandle _handle, uint8_t _side, uint8_t _mip) = 0;
|
||||
virtual void updateTexture(TextureHandle _handle, uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) = 0;
|
||||
virtual void updateTextureEnd() = 0;
|
||||
@ -3768,11 +3768,7 @@ namespace bgfx
|
||||
if (isValid(handle) )
|
||||
{
|
||||
TextureRef& ref = m_textureRef[handle.idx];
|
||||
ref.m_refCount = 1;
|
||||
ref.m_bbRatio = uint8_t(_ratio);
|
||||
ref.m_format = uint8_t(_info->format);
|
||||
ref.m_numMips = imageContainer.m_numMips;
|
||||
ref.m_owned = false;
|
||||
ref.init(_ratio, _info->format, imageContainer.m_numMips, 0 != (g_caps.supported & BGFX_CAPS_TEXTURE_DIRECT_ACCESS) );
|
||||
|
||||
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateTexture);
|
||||
cmdbuf.write(handle);
|
||||
@ -3791,7 +3787,6 @@ namespace bgfx
|
||||
BGFX_API_FUNC(void setName(TextureHandle _handle, const char* _name) )
|
||||
{
|
||||
BGFX_MUTEX_SCOPE(m_resourceApiLock);
|
||||
|
||||
BGFX_CHECK_HANDLE("setName", m_textureHandle, _handle);
|
||||
|
||||
TextureRef& ref = m_textureRef[_handle.idx];
|
||||
@ -3800,6 +3795,21 @@ namespace bgfx
|
||||
setName(convert(_handle), _name);
|
||||
}
|
||||
|
||||
void setDirectAccessPtr(TextureHandle _handle, void* _ptr)
|
||||
{
|
||||
TextureRef& ref = m_textureRef[_handle.idx];
|
||||
ref.m_ptr = _ptr;
|
||||
}
|
||||
|
||||
BGFX_API_FUNC(void* getDirectAccessPtr(TextureHandle _handle) )
|
||||
{
|
||||
BGFX_MUTEX_SCOPE(m_resourceApiLock);
|
||||
BGFX_CHECK_HANDLE("getDirectAccessPtr", m_textureHandle, _handle);
|
||||
|
||||
TextureRef& ref = m_textureRef[_handle.idx];
|
||||
return ref.m_ptr;
|
||||
}
|
||||
|
||||
BGFX_API_FUNC(void destroyTexture(TextureHandle _handle) )
|
||||
{
|
||||
BGFX_MUTEX_SCOPE(m_resourceApiLock);
|
||||
@ -4524,7 +4534,18 @@ namespace bgfx
|
||||
|
||||
struct TextureRef
|
||||
{
|
||||
void init(BackbufferRatio::Enum _ratio, TextureFormat::Enum _format, uint8_t _numMips, bool _ptrPending)
|
||||
{
|
||||
m_ptr = _ptrPending ? (void*)UINTPTR_MAX : NULL;
|
||||
m_refCount = 1;
|
||||
m_bbRatio = uint8_t(_ratio);
|
||||
m_format = uint8_t(_format);
|
||||
m_numMips = _numMips;
|
||||
m_owned = false;
|
||||
}
|
||||
|
||||
String m_name;
|
||||
void* m_ptr;
|
||||
int16_t m_refCount;
|
||||
uint8_t m_bbRatio;
|
||||
uint8_t m_format;
|
||||
|
@ -493,12 +493,10 @@ namespace bgfx { namespace d3d11
|
||||
|
||||
BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
|
||||
static BX_NO_INLINE bool getIntelExtensions(ID3D11Device* _device)
|
||||
static HRESULT setIntelExtension(ID3D11Device* _device, const void* _data, uint32_t _size)
|
||||
{
|
||||
uint8_t temp[28];
|
||||
|
||||
D3D11_BUFFER_DESC desc;
|
||||
desc.ByteWidth = sizeof(temp);
|
||||
desc.ByteWidth = _size;
|
||||
desc.Usage = D3D11_USAGE_STAGING;
|
||||
desc.BindFlags = 0;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
@ -506,23 +504,56 @@ namespace bgfx { namespace d3d11
|
||||
desc.StructureByteStride = 0;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA initData;
|
||||
initData.pSysMem = &temp;
|
||||
initData.SysMemPitch = sizeof(temp);
|
||||
initData.pSysMem = _data;
|
||||
initData.SysMemPitch = _size;
|
||||
initData.SysMemSlicePitch = 0;
|
||||
|
||||
bx::StaticMemoryBlockWriter writer(&temp, sizeof(temp) );
|
||||
bx::write(&writer, "INTCEXTNCAPSFUNC", 16);
|
||||
bx::write(&writer, UINT32_C(0x00010000) );
|
||||
bx::write(&writer, UINT32_C(0) );
|
||||
bx::write(&writer, UINT32_C(0) );
|
||||
|
||||
ID3D11Buffer* buffer;
|
||||
HRESULT hr = _device->CreateBuffer(&desc, &initData, &buffer);
|
||||
|
||||
if (SUCCEEDED(hr) )
|
||||
{
|
||||
buffer->Release();
|
||||
}
|
||||
|
||||
return hr;
|
||||
};
|
||||
|
||||
static const uint32_t kIntelExtensionInterfaceVersion = UINT32_C(0x10000);
|
||||
|
||||
struct IntelExtension
|
||||
{
|
||||
char key[16];
|
||||
uint32_t version;
|
||||
uint32_t type;
|
||||
uint32_t data[16];
|
||||
};
|
||||
|
||||
static const IntelExtension s_intelDirectAccessResource =
|
||||
{
|
||||
{ 'I', 'N', 'T', 'C', 'E', 'X', 'T', 'N', 'R', 'E', 'S', 'O', 'U', 'R', 'C', 'E' },
|
||||
kIntelExtensionInterfaceVersion,
|
||||
1,
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
static HRESULT setIntelDirectAccessResource(ID3D11Device* _device)
|
||||
{
|
||||
return setIntelExtension(_device, &s_intelDirectAccessResource, sizeof(s_intelDirectAccessResource) );
|
||||
}
|
||||
|
||||
static BX_NO_INLINE bool getIntelExtensions(ID3D11Device* _device)
|
||||
{
|
||||
uint8_t temp[28];
|
||||
|
||||
bx::StaticMemoryBlockWriter writer(&temp, sizeof(temp) );
|
||||
bx::write(&writer, "INTCEXTNCAPSFUNC", 16);
|
||||
bx::write(&writer, kIntelExtensionInterfaceVersion);
|
||||
bx::write(&writer, UINT32_C(0) );
|
||||
bx::write(&writer, UINT32_C(0) );
|
||||
|
||||
if (SUCCEEDED(setIntelExtension(_device, temp, sizeof(temp) ) ) )
|
||||
{
|
||||
bx::MemoryReader reader(&temp, sizeof(temp) );
|
||||
bx::skip(&reader, 16);
|
||||
|
||||
@ -702,6 +733,7 @@ namespace bgfx { namespace d3d11
|
||||
, m_fsChanges(0)
|
||||
, m_rtMsaa(false)
|
||||
, m_timerQuerySupport(false)
|
||||
, m_directAccessSupport(false)
|
||||
{
|
||||
m_fbh.idx = kInvalidHandle;
|
||||
bx::memSet(&m_adapterDesc, 0, sizeof(m_adapterDesc) );
|
||||
@ -925,6 +957,11 @@ namespace bgfx { namespace d3d11
|
||||
|
||||
if (NULL == m_device)
|
||||
{
|
||||
if (NULL != m_renderdocdll)
|
||||
{
|
||||
setGraphicsDebuggerPresent(true);
|
||||
}
|
||||
|
||||
m_adapter = NULL;
|
||||
m_driverType = BGFX_PCI_ID_SOFTWARE_RASTERIZER == g_caps.vendorId
|
||||
? D3D_DRIVER_TYPE_WARP
|
||||
@ -1334,20 +1371,30 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
| BGFX_CAPS_VERTEX_ATTRIB_HALF
|
||||
| BGFX_CAPS_VERTEX_ATTRIB_UINT10
|
||||
| BGFX_CAPS_FRAGMENT_DEPTH
|
||||
| (getIntelExtensions(m_device) ? BGFX_CAPS_FRAGMENT_ORDERING : 0)
|
||||
| (getIntelExtensions(m_device)
|
||||
? BGFX_CAPS_FRAGMENT_ORDERING
|
||||
| BGFX_CAPS_TEXTURE_DIRECT_ACCESS
|
||||
: 0)
|
||||
| BGFX_CAPS_SWAP_CHAIN
|
||||
| (m_ovr.isInitialized() ? BGFX_CAPS_HMD : 0)
|
||||
| (m_ovr.isInitialized()
|
||||
? BGFX_CAPS_HMD
|
||||
: 0)
|
||||
| BGFX_CAPS_DRAW_INDIRECT
|
||||
| BGFX_CAPS_TEXTURE_BLIT
|
||||
| BGFX_CAPS_TEXTURE_READ_BACK
|
||||
| ( (m_featureLevel >= D3D_FEATURE_LEVEL_9_2) ? BGFX_CAPS_OCCLUSION_QUERY : 0)
|
||||
| ( (m_featureLevel >= D3D_FEATURE_LEVEL_9_2)
|
||||
? BGFX_CAPS_OCCLUSION_QUERY
|
||||
: 0)
|
||||
| BGFX_CAPS_ALPHA_TO_COVERAGE
|
||||
| ( (m_deviceInterfaceVersion >= 3) ? BGFX_CAPS_CONSERVATIVE_RASTER : 0)
|
||||
| ( (m_deviceInterfaceVersion >= 3)
|
||||
? BGFX_CAPS_CONSERVATIVE_RASTER
|
||||
: 0)
|
||||
| BGFX_CAPS_TEXTURE_2D_ARRAY
|
||||
| BGFX_CAPS_TEXTURE_CUBE_ARRAY
|
||||
);
|
||||
|
||||
m_timerQuerySupport = m_featureLevel >= D3D_FEATURE_LEVEL_10_0;
|
||||
m_timerQuerySupport = m_featureLevel >= D3D_FEATURE_LEVEL_10_0;
|
||||
m_directAccessSupport = 0 != (g_caps.supported & BGFX_CAPS_TEXTURE_DIRECT_ACCESS);
|
||||
|
||||
if (m_featureLevel <= D3D_FEATURE_LEVEL_9_2)
|
||||
{
|
||||
@ -1913,9 +1960,9 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
m_program[_handle.idx].destroy();
|
||||
}
|
||||
|
||||
void createTexture(TextureHandle _handle, Memory* _mem, uint32_t _flags, uint8_t _skip) override
|
||||
void* createTexture(TextureHandle _handle, Memory* _mem, uint32_t _flags, uint8_t _skip) override
|
||||
{
|
||||
m_textures[_handle.idx].create(_mem, _flags, _skip);
|
||||
return m_textures[_handle.idx].create(_mem, _flags, _skip);
|
||||
}
|
||||
|
||||
void updateTextureBegin(TextureHandle /*_handle*/, uint8_t /*_side*/, uint8_t /*_mip*/) override
|
||||
@ -3769,6 +3816,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
FrameBufferHandle m_fbh;
|
||||
bool m_rtMsaa;
|
||||
bool m_timerQuerySupport;
|
||||
bool m_directAccessSupport;
|
||||
|
||||
VR m_ovr;
|
||||
#if BGFX_CONFIG_USE_OVR
|
||||
@ -4531,8 +4579,70 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
}
|
||||
}
|
||||
|
||||
void TextureD3D11::create(const Memory* _mem, uint32_t _flags, uint8_t _skip)
|
||||
void* DirectAccessResourceD3D11::createTexture2D(const D3D11_TEXTURE2D_DESC* _gpuDesc, const D3D11_SUBRESOURCE_DATA* _srd, ID3D11Texture2D** _gpuTexture2d)
|
||||
{
|
||||
ID3D11Device* device = s_renderD3D11->m_device;
|
||||
DX_CHECK(setIntelDirectAccessResource(device) );
|
||||
DX_CHECK(device->CreateTexture2D(_gpuDesc, _srd, _gpuTexture2d) );
|
||||
|
||||
D3D11_TEXTURE2D_DESC cpuDesc;
|
||||
bx::memCopy(&cpuDesc, _gpuDesc, sizeof(cpuDesc) );
|
||||
cpuDesc.BindFlags = 0;
|
||||
cpuDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
|
||||
cpuDesc.Usage = D3D11_USAGE_STAGING;
|
||||
|
||||
DX_CHECK(setIntelDirectAccessResource(s_renderD3D11->m_device) );
|
||||
DX_CHECK(device->CreateTexture2D(&cpuDesc, NULL, &m_texture2d) );
|
||||
|
||||
ID3D11DeviceContext* deviceCtx = s_renderD3D11->m_deviceCtx;
|
||||
deviceCtx->CopyResource(m_texture2d, *_gpuTexture2d);
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
||||
deviceCtx->Map(m_texture2d, 0, D3D11_MAP_WRITE, NULL, &mappedResource);
|
||||
m_descriptor = reinterpret_cast<IntelDirectAccessResourceDescriptor*>(mappedResource.pData);
|
||||
|
||||
return m_descriptor->ptr;
|
||||
}
|
||||
|
||||
void* DirectAccessResourceD3D11::createTexture3D(const D3D11_TEXTURE3D_DESC* _gpuDesc, const D3D11_SUBRESOURCE_DATA* _srd, ID3D11Texture3D** _gpuTexture3d)
|
||||
{
|
||||
ID3D11Device* device = s_renderD3D11->m_device;
|
||||
DX_CHECK(setIntelDirectAccessResource(device) );
|
||||
DX_CHECK(device->CreateTexture3D(_gpuDesc, _srd, _gpuTexture3d) );
|
||||
|
||||
D3D11_TEXTURE3D_DESC cpuDesc;
|
||||
bx::memCopy(&cpuDesc, _gpuDesc, sizeof(cpuDesc) );
|
||||
cpuDesc.BindFlags = 0;
|
||||
cpuDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
|
||||
cpuDesc.Usage = D3D11_USAGE_STAGING;
|
||||
|
||||
DX_CHECK(setIntelDirectAccessResource(s_renderD3D11->m_device) );
|
||||
DX_CHECK(device->CreateTexture3D(&cpuDesc, NULL, &m_texture3d) );
|
||||
|
||||
ID3D11DeviceContext* deviceCtx = s_renderD3D11->m_deviceCtx;
|
||||
deviceCtx->CopyResource(m_texture3d, *_gpuTexture3d);
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
||||
deviceCtx->Map(m_texture3d, 0, D3D11_MAP_WRITE, NULL, &mappedResource);
|
||||
m_descriptor = reinterpret_cast<IntelDirectAccessResourceDescriptor*>(mappedResource.pData);
|
||||
|
||||
return m_descriptor->ptr;
|
||||
}
|
||||
|
||||
void DirectAccessResourceD3D11::destroy()
|
||||
{
|
||||
if (NULL != m_descriptor)
|
||||
{
|
||||
s_renderD3D11->m_deviceCtx->Unmap(m_ptr, 0);
|
||||
m_descriptor = NULL;
|
||||
DX_RELEASE(m_ptr, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void* TextureD3D11::create(const Memory* _mem, uint32_t _flags, uint8_t _skip)
|
||||
{
|
||||
void* directAccessPtr = NULL;
|
||||
|
||||
bimg::ImageContainer imageContainer;
|
||||
|
||||
if (bimg::imageParse(imageContainer, _mem->data, _mem->size) )
|
||||
@ -4678,6 +4788,13 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
srvd.Format = getSrvFormat();
|
||||
}
|
||||
|
||||
bool directAccess = s_renderD3D11->m_directAccessSupport
|
||||
&& !renderTarget
|
||||
&& !readBack
|
||||
&& !blit
|
||||
&& !writeOnly
|
||||
;
|
||||
|
||||
switch (m_type)
|
||||
{
|
||||
case Texture2D:
|
||||
@ -4774,7 +4891,14 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
desc.SampleDesc = s_msaa[0];
|
||||
}
|
||||
|
||||
DX_CHECK(s_renderD3D11->m_device->CreateTexture2D(&desc, kk == 0 ? NULL : srd, &m_texture2d) );
|
||||
if (directAccess)
|
||||
{
|
||||
directAccessPtr = m_dar.createTexture2D(&desc, kk == 0 ? NULL : srd, &m_texture2d);
|
||||
}
|
||||
else
|
||||
{
|
||||
DX_CHECK(s_renderD3D11->m_device->CreateTexture2D(&desc, kk == 0 ? NULL : srd, &m_texture2d) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@ -4816,7 +4940,14 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
|
||||
srvd.Texture3D.MipLevels = numMips;
|
||||
|
||||
DX_CHECK(s_renderD3D11->m_device->CreateTexture3D(&desc, kk == 0 ? NULL : srd, &m_texture3d) );
|
||||
if (directAccess)
|
||||
{
|
||||
directAccessPtr = m_dar.createTexture3D(&desc, kk == 0 ? NULL : srd, &m_texture3d);
|
||||
}
|
||||
else
|
||||
{
|
||||
DX_CHECK(s_renderD3D11->m_device->CreateTexture3D(&desc, kk == 0 ? NULL : srd, &m_texture3d) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -4845,10 +4976,14 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return directAccessPtr;
|
||||
}
|
||||
|
||||
void TextureD3D11::destroy()
|
||||
{
|
||||
m_dar.destroy();
|
||||
|
||||
s_renderD3D11->m_srvUavLru.invalidateWithParent(getHandle().idx);
|
||||
DX_RELEASE(m_rt, 0);
|
||||
DX_RELEASE(m_srv, 0);
|
||||
|
@ -220,6 +220,38 @@ namespace bgfx { namespace d3d11
|
||||
uint8_t m_numPredefined;
|
||||
};
|
||||
|
||||
struct IntelDirectAccessResourceDescriptor
|
||||
{
|
||||
void* ptr;
|
||||
uint32_t xoffset;
|
||||
uint32_t yoffset;
|
||||
uint32_t tileFormat;
|
||||
uint32_t pitch;
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
struct DirectAccessResourceD3D11
|
||||
{
|
||||
DirectAccessResourceD3D11()
|
||||
: m_ptr(NULL)
|
||||
, m_descriptor(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
void* createTexture2D(const D3D11_TEXTURE2D_DESC* _gpuDesc, const D3D11_SUBRESOURCE_DATA* _srd, ID3D11Texture2D** _gpuTexture2d);
|
||||
void* createTexture3D(const D3D11_TEXTURE3D_DESC* _gpuDesc, const D3D11_SUBRESOURCE_DATA* _srd, ID3D11Texture3D** _gpuTexture3d);
|
||||
void destroy();
|
||||
|
||||
union
|
||||
{
|
||||
ID3D11Resource* m_ptr;
|
||||
ID3D11Texture2D* m_texture2d;
|
||||
ID3D11Texture3D* m_texture3d;
|
||||
};
|
||||
|
||||
IntelDirectAccessResourceDescriptor* m_descriptor;
|
||||
};
|
||||
|
||||
struct TextureD3D11
|
||||
{
|
||||
enum Enum
|
||||
@ -238,7 +270,7 @@ namespace bgfx { namespace d3d11
|
||||
{
|
||||
}
|
||||
|
||||
void create(const Memory* _mem, uint32_t _flags, uint8_t _skip);
|
||||
void* create(const Memory* _mem, uint32_t _flags, uint8_t _skip);
|
||||
void destroy();
|
||||
void overrideInternal(uintptr_t _ptr);
|
||||
void update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem);
|
||||
@ -254,6 +286,8 @@ namespace bgfx { namespace d3d11
|
||||
ID3D11Texture3D* m_texture3d;
|
||||
};
|
||||
|
||||
DirectAccessResourceD3D11 m_dar;
|
||||
|
||||
union
|
||||
{
|
||||
ID3D11Resource* m_rt;
|
||||
|
@ -1086,6 +1086,7 @@ namespace bgfx { namespace d3d12
|
||||
| BGFX_CAPS_BLEND_INDEPENDENT
|
||||
| BGFX_CAPS_COMPUTE
|
||||
| (m_options.ROVsSupported ? BGFX_CAPS_FRAGMENT_ORDERING : 0)
|
||||
// | (m_architecture.UMA ? BGFX_CAPS_TEXTURE_DIRECT_ACCESS : 0)
|
||||
// | BGFX_CAPS_SWAP_CHAIN
|
||||
| BGFX_CAPS_TEXTURE_BLIT
|
||||
| BGFX_CAPS_TEXTURE_READ_BACK
|
||||
@ -1476,9 +1477,10 @@ namespace bgfx { namespace d3d12
|
||||
m_program[_handle.idx].destroy();
|
||||
}
|
||||
|
||||
void createTexture(TextureHandle _handle, Memory* _mem, uint32_t _flags, uint8_t _skip) override
|
||||
void* createTexture(TextureHandle _handle, Memory* _mem, uint32_t _flags, uint8_t _skip) override
|
||||
{
|
||||
m_textures[_handle.idx].create(_mem, _flags, _skip);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void updateTextureBegin(TextureHandle /*_handle*/, uint8_t /*_side*/, uint8_t /*_mip*/) override
|
||||
|
@ -1032,9 +1032,10 @@ namespace bgfx { namespace d3d9
|
||||
m_program[_handle.idx].destroy();
|
||||
}
|
||||
|
||||
void createTexture(TextureHandle _handle, Memory* _mem, uint32_t _flags, uint8_t _skip) override
|
||||
void* createTexture(TextureHandle _handle, Memory* _mem, uint32_t _flags, uint8_t _skip) override
|
||||
{
|
||||
m_textures[_handle.idx].create(_mem, _flags, _skip);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void updateTextureBegin(TextureHandle _handle, uint8_t _side, uint8_t _mip) override
|
||||
|
@ -2732,9 +2732,10 @@ namespace bgfx { namespace gl
|
||||
m_program[_handle.idx].destroy();
|
||||
}
|
||||
|
||||
void createTexture(TextureHandle _handle, Memory* _mem, uint32_t _flags, uint8_t _skip) override
|
||||
void* createTexture(TextureHandle _handle, Memory* _mem, uint32_t _flags, uint8_t _skip) override
|
||||
{
|
||||
m_textures[_handle.idx].create(_mem, _flags, _skip);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void updateTextureBegin(TextureHandle /*_handle*/, uint8_t /*_side*/, uint8_t /*_mip*/) override
|
||||
|
@ -783,9 +783,10 @@ namespace bgfx { namespace mtl
|
||||
m_program[_handle.idx].destroy();
|
||||
}
|
||||
|
||||
void createTexture(TextureHandle _handle, Memory* _mem, uint32_t _flags, uint8_t _skip) override
|
||||
void* createTexture(TextureHandle _handle, Memory* _mem, uint32_t _flags, uint8_t _skip) override
|
||||
{
|
||||
m_textures[_handle.idx].create(_mem, _flags, _skip);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void updateTextureBegin(TextureHandle /*_handle*/, uint8_t /*_side*/, uint8_t /*_mip*/) override
|
||||
|
@ -127,8 +127,9 @@ namespace bgfx { namespace noop
|
||||
{
|
||||
}
|
||||
|
||||
void createTexture(TextureHandle /*_handle*/, Memory* /*_mem*/, uint32_t /*_flags*/, uint8_t /*_skip*/) override
|
||||
void* createTexture(TextureHandle /*_handle*/, Memory* /*_mem*/, uint32_t /*_flags*/, uint8_t /*_skip*/) override
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void updateTextureBegin(TextureHandle /*_handle*/, uint8_t /*_side*/, uint8_t /*_mip*/) override
|
||||
|
@ -2027,8 +2027,9 @@ VK_IMPORT_DEVICE
|
||||
m_program[_handle.idx].destroy();
|
||||
}
|
||||
|
||||
void createTexture(TextureHandle /*_handle*/, Memory* /*_mem*/, uint32_t /*_flags*/, uint8_t /*_skip*/) override
|
||||
void* createTexture(TextureHandle /*_handle*/, Memory* /*_mem*/, uint32_t /*_flags*/, uint8_t /*_skip*/) override
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void updateTextureBegin(TextureHandle /*_handle*/, uint8_t /*_side*/, uint8_t /*_mip*/) override
|
||||
|
Loading…
Reference in New Issue
Block a user