Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


jerrinx

Member Since 15 Nov 2008
Offline Last Active Aug 11 2013 07:12 PM

Topics I've Started

Bizarre placement new[] operator return address

11 April 2013 - 09:31 PM


Hey Guys,
 
I am trying to do in place initialization of an array of variables.
Essentially allocate memory. Pass in the void * into operator new[] to initialize an array of variables.
 
Now I get an address 4 bytes ahead of the allocated address !!
 
Example:
void *pMem = malloc(sizeof(A) * 4);
A *pArr = new (pMem) A[4];
 
pArr is (char *)pMem + 4 !!
 
Can anyone shed light on why ?
I noticed the first 4 bytes of pMem contains the number of elements in array. (in this case 4).
 
I could potentially move the pointer back and forth. But I want to know is this 4 Bytes same for any platform ? Is it same for 32 bit and 64 bit applications ??
Is this part of the C++ standard ?
 
Thanks !!
Jerry
 
/*********** Source Code *********/
class BaseString
{
enum EAllocationSource {AS_DATA, AS_HEAP};
 
EAllocationSource m_allocationSource;
 
union
{
const char *m_strStatic;
char *m_strDynamic;
};
 
unsigned int *m_pNumRef;
unsigned int m_len;
 
static const char m_nullString;
 
public:
 
virtual ~BaseString(){}
 
static void *operator new[] (size_t size, void *ptr)
{
printf("\nSize obtained in operator new[] function of class: %u", (unsigned int)size);
return ptr;
}
 
static void operator delete[] (void *val, void *ptr)
{
printf("\nAddress passed to delete in Class: %u", (unsigned int)val);
printf("\nIn Place Address passed in Class: %u", (unsigned int)ptr);
}
 
};
 
void main()
{
printf("\nSize to be allocated: %u", sizeof(BaseString) * 4);
void *pMem = malloc(sizeof(BaseString) * 4);
printf("\nAllocated Address: %u", (unsigned int)pMem);
 
BaseString *pArr = new (pMem) BaseString[4];
printf("\nReturned Address: %u", (unsigned int)pArr);
 
pArr->operator delete[](pArr, pMem);
 
printf("\nuint first: %u", *((unsigned int *)pMem));
 
while(true)
SwitchToThread();
}

FXAA and Color Space

29 July 2012 - 12:45 PM

Hey guys,

I know, there were a few topics on FXAA, but it didn't help me with my problem, hence the new thread.

The problem is, I don't see any difference between the FXAA and Non-FXAA Render.

Then again I am not passing a non-linear color space texture to the FXAA shader. And not sure how to.
If my understanding is correct Linear color space is the one that is got when you sample a texture (0 to 1 range or 0 - 255 range) where the colors change in a linear fashion.

I am not sure what sRGB is about ?
Currently my texture is in RGBA8 dx format.

According to Fxaa3.11 release by Timothy.
"Applying FXAA to a framebuffer with linear RGB color will look worse.
This is very counter intuitive, but happens to be true in this case.
The reason is because dithering artifacts will be more visiable
in a linear colorspace."

.

The FXAA paper mentions something about using the following in DX9 (which is what i am working on)
// sRGB->linear conversion when fetching from TEX SetSamplerState(sampler, D3DSAMP_SRGBTEXTURE, 1);
// on SetSamplerState(sampler, D3DSAMP_SRGBTEXTURE, 0); // off
// linear->sRGB conversion when writing to ROP SetRenderState(D3DRS_SRGBWRITEENABLE, 1);
// on SetRenderState(D3DRS_SRGBWRITEENABLE, 0); // off


This is what I am doing.
1. Render to texture using D3DRS_SRGBWRITEENABLE = 1, and turn it off after I am done.
When I render this texture, it looks brighter than usual.
2. Render screen quad with this texture using D3DSAMP_SRGBTEXTURE = 1, and turn it off after I am done.
When this texture renders, it looks correct.

But the aliasing still remains. I figured I shouldn't be doing step two because that would turn the non-linear color to linear while sampling.
But doing that results in the texture/scene got from the first step.

I have attached my shaders here.
Any help is greatly appreciated.

P.S, Timothy also mentioned something about pixel offset being different on dx11 w.r.t dx9 by 0.5 of a pixel.
http://timothylottes.blogspot.com/2011/07/fxaa-311-released.html

Thanks a lot !
Jerry

Attached File  FXAA.zip   15.36KB   63 downloads

Stream Multiplication Performance with Functions

08 July 2012 - 10:31 PM

Hey guys,

I made a test program to check out performance of stream multiplication using normal, virtual, inline functions, and as a single function.

These are the results when Multiplying 1000,000,000 Floats

Results


[CUtil] ## PROFILE Stream Product normal function : 6.663393837 sec(s) ##
[CUtil] ## PROFILE Stream Product virtual function : 6.608961085 sec(s) ##
[CUtil] ## PROFILE Stream Product inline function : 6.584697760 sec(s) ##
[CUtil] ## PROFILE Stream Product in function : 12.363450801 sec(s) ##

What I don't understand is why Stream Product in a function takes twice as much !!???
Maybe its just my setup or something wrong with the code... I don't know.
Can somebody try this out ?

VS 2010 Express
Release Build

Texture Sharing b/w OpenGL and DirectX

17 June 2012 - 11:30 PM

Hey Guys,

I have an abstraction library for DirectX and OpenGL.
I want to load textures from a single file and read it into memory for either rendering systems directly, without manipulations.

But I can't find an input pixel format shared by both DirectX and OpenGL.

OpenGL Supports the function glTexImage2D
on format
GL_RGBA, GL_BGRA
with type GL_UNSIGNED_INT_8_8_8_8

DirectX supports the function CreateTexture
on format
D3DFMT_A8R8G8B8

I could actually swap around the bytes when reading texture for one of the systems, but that could incur performance loss.
Asynchronous texture loading is one thing I have in mind and want it to be fast when loading.

Any solutions ?

Thanks for your help in advance !!
Jerry

Improvement in Template Compilation Time

28 May 2012 - 12:49 PM

Hey Guys,

The following works for me in Windows.
I have one header file for declaration "TemplateChk.h"
I have one header file for definition "TemplateChkDef.h"

And in your target application you could define concrete classes for the corresponding template classes in Concrete.cpp
So your header file for template classes need not contain implementation, thereby improving compilation time for template
classes, if I am not mistaken.

Just want to know if what I am doing is correct and is it supported on other Platforms like Linux and Apple IOS ?

Thanks

-------------------------------------------------
//TemplateChk.h
-------------------------------------------------

#pragma once

template <class E>
class TemplateChk
{
E val;

public:
void lama();
};

-------------------------------------------------
TemplateChkDef.h
-------------------------------------------------

#pragma once

template <class E>
class TemplateChk
{
E val;

public:
void lama()
{
}
};

-------------------------------------------------
Concrete.cpp
-------------------------------------------------
#include "TemplateChkDef.h"

template TemplateChk<int>;
template TemplateChk<float>;
.....

//Compilation time for this file is reduced since it does not include template class with function definition
-------------------------------------------------
Application.cpp
-------------------------------------------------
#include "TemplateChk.h"

void main()
{
TemplateChk<int> mamma;
mamma.lama();

TemplateChk<float> mamma;
mamma.lama();
}

PARTNERS